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

Commit48c348f

Browse files
committed
Dept of second thoughts: don't try to push LIMIT below a SRF.
If we have Limit->Result->Sort, the Result might be projecting a tlistthat contains a set-returning function. If so, it's possible for theSRF to sometimes return zero rows, which means we could need to fetchmore than N rows from the Sort in order to satisfy LIMIT N.So top-N sorting cannot be used in this scenario.
1 parent1fc2d60 commit48c348f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

‎src/backend/executor/nodeLimit.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include"executor/executor.h"
2525
#include"executor/nodeLimit.h"
26+
#include"nodes/nodeFuncs.h"
2627

2728
staticvoidrecompute_limits(LimitState*node);
2829
staticvoidpass_down_bound(LimitState*node,PlanState*child_node);
@@ -344,7 +345,19 @@ pass_down_bound(LimitState *node, PlanState *child_node)
344345
}
345346
elseif (IsA(child_node,ResultState))
346347
{
347-
if (outerPlanState(child_node))
348+
/*
349+
* An extra consideration here is that if the Result is projecting
350+
* a targetlist that contains any SRFs, we can't assume that every
351+
* input tuple generates an output tuple, so a Sort underneath
352+
* might need to return more than N tuples to satisfy LIMIT N.
353+
* So we cannot use bounded sort.
354+
*
355+
* If Result supported qual checking, we'd have to punt on seeing
356+
* a qual, too. Note that having a resconstantqual is not a
357+
* showstopper: if that fails we're not getting any rows at all.
358+
*/
359+
if (outerPlanState(child_node)&&
360+
!expression_returns_set((Node*)child_node->plan->targetlist))
348361
pass_down_bound(node,outerPlanState(child_node));
349362
}
350363
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp