diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-06-28 10:43:11 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-06-28 10:43:11 -0400 |
commit | c12f02ffc94faac09eae254b3bf114c153f116f6 (patch) | |
tree | 24cc94264d9210751042ef9901ef69d0f85698f7 /src/backend/optimizer/plan/createplan.c | |
parent | 957616dbaef0e7f182e6260483bca79a38ae247f (diff) | |
download | postgresql-c12f02ffc94faac09eae254b3bf114c153f116f6.tar.gz postgresql-c12f02ffc94faac09eae254b3bf114c153f116f6.zip |
Don't apply sortgroupref labels to a tlist that might not match.
If we need to use a gating Result node for pseudoconstant quals,
create_scan_plan() intentionally suppresses use_physical_tlist's checks
on whether there are matches for sortgroupref labels, on the grounds that
we don't need matches because we can label the Result's projection output
properly. However, it then called apply_pathtarget_labeling_to_tlist
anyway. This oversight was harmless when written, but in commit aeb9ae645
I made that function throw an error if there was no match. Thus, the
combination of a table scan, pseudoconstant quals, and a non-simple-Var
sortgroupref column threw the dreaded "ORDER/GROUP BY expression not found
in targetlist" error. To fix, just skip applying the labeling in this
case. Per report from Rushabh Lathia.
Report: <CAGPqQf2iLB8t6t-XrL-zR233DFTXxEsfVZ4WSqaYfLupEoDxXA@mail.gmail.com>
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r-- | src/backend/optimizer/plan/createplan.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 58bfd491307..f98cce49c7e 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -544,8 +544,13 @@ create_scan_plan(PlannerInfo *root, Path *best_path, int flags) { /* For index-only scan, the preferred tlist is the index's */ tlist = copyObject(((IndexPath *) best_path)->indexinfo->indextlist); - /* Transfer any sortgroupref data to the replacement tlist */ - apply_pathtarget_labeling_to_tlist(tlist, best_path->pathtarget); + + /* + * Transfer any sortgroupref data to the replacement tlist, unless + * we don't care because the gating Result will handle it. + */ + if (!gating_clauses) + apply_pathtarget_labeling_to_tlist(tlist, best_path->pathtarget); } else { @@ -557,8 +562,9 @@ create_scan_plan(PlannerInfo *root, Path *best_path, int flags) } else { - /* Transfer any sortgroupref data to the replacement tlist */ - apply_pathtarget_labeling_to_tlist(tlist, best_path->pathtarget); + /* As above, transfer sortgroupref data to replacement tlist */ + if (!gating_clauses) + apply_pathtarget_labeling_to_tlist(tlist, best_path->pathtarget); } } } |