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

Commit57cd2b6

Browse files
committed
Fix create_scan_plan's handling of sortgrouprefs for physical tlists.
We should only run apply_pathtarget_labeling_to_tlist if CP_LABEL_TLISTwas specified, because only in that case has use_physical_tlist checkedthat the labeling will succeed; otherwise we may get an "ORDER/GROUP BYexpression not found in targetlist" error. (This subsumes the previoustest about gating_clauses, because we reset "flags" to zero earlierif there are gating clauses to apply.)The only known case in which a failure can occur is with a ProjectSetpath directly atop a table scan path, although it seems likely that thereare other cases or will be such in future. This means that the failureis currently only visible in the v10 branch: 9.6 didn't have ProjectSet,while in v11 and HEAD, apply_scanjoin_target_to_paths for some weirdreason is using create_projection_path not apply_projection_to_path,masking the problem because there's a ProjectionPath in between.Nonetheless this code is clearly wrong on its own terms, so back-patchto 9.6 where this logic was introduced.Per report from Regina Obe.Discussion:https://postgr.es/m/001501d40f88$75186950$5f493bf0$@pcorp.us
1 parentff4f889 commit57cd2b6

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

‎src/backend/optimizer/plan/createplan.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,10 @@ create_scan_plan(PlannerInfo *root, Path *best_path, int flags)
579579
tlist=copyObject(((IndexPath*)best_path)->indexinfo->indextlist);
580580

581581
/*
582-
* Transferanysortgroupref data to the replacement tlist,unless
583-
*we don't care because the gating Resultwillhandle it.
582+
* Transfer sortgroupref data to the replacement tlist,if
583+
*requested (use_physical_tlist checked that thiswillwork).
584584
*/
585-
if (!gating_clauses)
585+
if (flags&CP_LABEL_TLIST)
586586
apply_pathtarget_labeling_to_tlist(tlist,best_path->pathtarget);
587587
}
588588
else
@@ -596,7 +596,7 @@ create_scan_plan(PlannerInfo *root, Path *best_path, int flags)
596596
else
597597
{
598598
/* As above, transfer sortgroupref data to replacement tlist */
599-
if (!gating_clauses)
599+
if (flags&CP_LABEL_TLIST)
600600
apply_pathtarget_labeling_to_tlist(tlist,best_path->pathtarget);
601601
}
602602
}
@@ -1639,7 +1639,7 @@ create_projection_plan(PlannerInfo *root, ProjectionPath *best_path, int flags)
16391639
*/
16401640
subplan=create_plan_recurse(root,best_path->subpath,0);
16411641
tlist=subplan->targetlist;
1642-
if ((flags&CP_LABEL_TLIST)!=0)
1642+
if (flags&CP_LABEL_TLIST)
16431643
apply_pathtarget_labeling_to_tlist(tlist,
16441644
best_path->path.pathtarget);
16451645
}

‎src/test/regress/expected/tsrf.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,28 @@ SELECT dataa, datab b, generate_series(1,2) g, count(*) FROM few GROUP BY CUBE(d
421421
(24 rows)
422422

423423
reset enable_hashagg;
424+
-- case with degenerate ORDER BY
425+
explain (verbose, costs off)
426+
select 'foo' as f, generate_series(1,2) as g from few order by 1;
427+
QUERY PLAN
428+
----------------------------------------------
429+
ProjectSet
430+
Output: 'foo'::text, generate_series(1, 2)
431+
-> Seq Scan on public.few
432+
Output: id, dataa, datab
433+
(4 rows)
434+
435+
select 'foo' as f, generate_series(1,2) as g from few order by 1;
436+
f | g
437+
-----+---
438+
foo | 1
439+
foo | 2
440+
foo | 1
441+
foo | 2
442+
foo | 1
443+
foo | 2
444+
(6 rows)
445+
424446
-- data modification
425447
CREATE TABLE fewmore AS SELECT generate_series(1,3) AS data;
426448
INSERT INTO fewmore VALUES(generate_series(4,5));

‎src/test/regress/sql/tsrf.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ SELECT dataa, datab b, generate_series(1,2) g, count(*) FROM few GROUP BY CUBE(d
8888
SELECT dataa, datab b, generate_series(1,2) g,count(*)FROM fewGROUP BY CUBE(dataa, datab, g)ORDER BY g;
8989
reset enable_hashagg;
9090

91+
-- case with degenerate ORDER BY
92+
explain (verbose, costs off)
93+
select'foo'as f, generate_series(1,2)as gfrom feworder by1;
94+
select'foo'as f, generate_series(1,2)as gfrom feworder by1;
95+
9196
-- data modification
9297
CREATETABLEfewmoreASSELECT generate_series(1,3)AS data;
9398
INSERT INTO fewmoreVALUES(generate_series(4,5));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp