Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6121539

Browse files
committed
Fix SPI documentation for new handling of ExecutorRun's count parameter.
Since 9.0, the count parameter has only limited the number of tuplesactually returned by the executor. It doesn't affect the behavior ofINSERT/UPDATE/DELETE unless RETURNING is specified, because withoutRETURNING, the ModifyTable plan node doesn't return control to execMain.cfor each tuple. And we only check the limit at the top level.While this behavioral change was unintentional at the time, discussion ofbug #6572 led us to the conclusion that we prefer the new behavior anyway,and so we should just adjust the docs to match rather than change the code.Accordingly, do that. Back-patch as far as 9.0 so that the docs match thecode in each branch.
1 parent474cfc3 commit6121539

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

‎doc/src/sgml/spi.sgml

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,24 @@ int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>rea
316316
<para>
317317
If <parameter>count</parameter> is zero then the command is executed
318318
for all rows that it applies to. If <parameter>count</parameter>
319-
is greater than 0, then the number of rows for which the command
320-
will be executed is restricted (much like a
321-
<literal>LIMIT</literal> clause). For example:
319+
is greater than zero, then no more than <parameter>count</parameter> rows
320+
will be retrieved; execution stops when the count is reached, much like
321+
adding a <literal>LIMIT</literal> clause to the query. For example,
322+
<programlisting>
323+
SPI_execute("SELECT * FROM foo", true, 5);
324+
</programlisting>
325+
will retrieve at most 5 rows from the table. Note that such a limit
326+
is only effective when the command actually returns rows. For example,
322327
<programlisting>
323328
SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
324329
</programlisting>
325-
will allow at most 5 rows to be inserted into the table.
330+
inserts all rows from <structname>bar</>, ignoring the
331+
<parameter>count</parameter> parameter. However, with
332+
<programlisting>
333+
SPI_execute("INSERT INTO foo SELECT * FROM bar RETURNING *", false, 5);
334+
</programlisting>
335+
at most 5 rows would be inserted, since execution would stop after the
336+
fifth <literal>RETURNING</> result row is retrieved.
326337
</para>
327338

328339
<para>
@@ -331,7 +342,8 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
331342
whole string will be parsed and planned before execution begins.
332343
<function>SPI_execute</function> returns the
333344
result for the command executed last. The <parameter>count</parameter>
334-
limit applies to each command separately, but it is not applied to
345+
limit applies to each command separately (even though only the last
346+
result will actually be returned). The limit is not applied to any
335347
hidden commands generated by rules.
336348
</para>
337349

@@ -435,7 +447,8 @@ typedef struct
435447
<term><literal>long <parameter>count</parameter></literal></term>
436448
<listitem>
437449
<para>
438-
maximum number of rows to process or return
450+
maximum number of rows to return,
451+
or <literal>0</> for no limit
439452
</para>
440453
</listitem>
441454
</varlistentry>
@@ -611,15 +624,12 @@ typedef struct
611624
<title>Notes</title>
612625

613626
<para>
614-
The functions <function>SPI_execute</function>,
615-
<function>SPI_exec</function>,
616-
<function>SPI_execute_plan</function>, and
617-
<function>SPI_execp</function> change both
627+
All SPI query-execution functions set both
618628
<varname>SPI_processed</varname> and
619629
<varname>SPI_tuptable</varname> (just the pointer, not the contents
620630
of the structure). Save these two global variables into local
621631
procedure variables if you need to access the result table of
622-
<function>SPI_execute</function> ora related function
632+
<function>SPI_execute</function> oranother query-execution function
623633
across later calls.
624634
</para>
625635
</refsect1>
@@ -674,7 +684,8 @@ int SPI_exec(const char * <parameter>command</parameter>, long <parameter>count<
674684
<term><literal>long <parameter>count</parameter></literal></term>
675685
<listitem>
676686
<para>
677-
maximum number of rows to process or return
687+
maximum number of rows to return,
688+
or <literal>0</> for no limit
678689
</para>
679690
</listitem>
680691
</varlistentry>
@@ -813,7 +824,8 @@ int SPI_execute_with_args(const char *<parameter>command</parameter>,
813824
<term><literal>long <parameter>count</parameter></literal></term>
814825
<listitem>
815826
<para>
816-
maximum number of rows to process or return
827+
maximum number of rows to return,
828+
or <literal>0</> for no limit
817829
</para>
818830
</listitem>
819831
</varlistentry>
@@ -1431,7 +1443,8 @@ int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>
14311443
<term><literal>long <parameter>count</parameter></literal></term>
14321444
<listitem>
14331445
<para>
1434-
maximum number of rows to process or return
1446+
maximum number of rows to return,
1447+
or <literal>0</> for no limit
14351448
</para>
14361449
</listitem>
14371450
</varlistentry>
@@ -1550,7 +1563,8 @@ int SPI_execute_plan_with_paramlist(SPIPlanPtr <parameter>plan</parameter>,
15501563
<term><literal>long <parameter>count</parameter></literal></term>
15511564
<listitem>
15521565
<para>
1553-
maximum number of rows to process or return
1566+
maximum number of rows to return,
1567+
or <literal>0</> for no limit
15541568
</para>
15551569
</listitem>
15561570
</varlistentry>
@@ -1650,7 +1664,8 @@ int SPI_execp(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>values<
16501664
<term><literal>long <parameter>count</parameter></literal></term>
16511665
<listitem>
16521666
<para>
1653-
maximum number of rows to process or return
1667+
maximum number of rows to return,
1668+
or <literal>0</> for no limit
16541669
</para>
16551670
</listitem>
16561671
</varlistentry>

‎src/backend/executor/execMain.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ standard_ExecutorStart(QueryDesc *queryDesc, int eflags)
207207
*we retrieve up to 'count' tuples in the specified direction.
208208
*
209209
*Note: count = 0 is interpreted as no portal limit, i.e., run to
210-
*completion.
210+
*completion. Also note that the count limit is only applied to
211+
*retrieved tuples, not for instance to those inserted/updated/deleted
212+
*by a ModifyTable plan node.
211213
*
212214
*There is no return value, but output tuples (if any) are sent to
213215
*the destination receiver specified in the QueryDesc; and the number
@@ -1184,7 +1186,7 @@ ExecEndPlan(PlanState *planstate, EState *estate)
11841186
/* ----------------------------------------------------------------
11851187
*ExecutePlan
11861188
*
1187-
*Processes the query plan until we haveprocessed 'numberTuples' tuples,
1189+
*Processes the query plan until we haveretrieved 'numberTuples' tuples,
11881190
*moving in the specified direction.
11891191
*
11901192
*Runs to completion if numberTuples is 0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp