mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Fix set_subquery_pathlist() to copy the RTE's subquery before it gets mangled
by the planning process. This prevents the "failed to locate grouping columns" error recently reported by Dickson Guedes. That happens because planning replaces SubLinks by SubPlans in the subquery's targetlist, and exprTypmod() is smarter about the former than the latter, causing the apparent type of the subquery's output columns to change. This seems to be a deficiency we should fix in exprTypmod(), but that will be a much more invasive patch with possible side-effects elsewhere, so I'll do that only in HEAD. Back-patch to 8.3. Arguably the lack of a copying step is broken/dangerous all the way back, but in the absence of known problems I'll refrain from making the older branches pay the extra cost. (The reason this particular symptom didn't appear before is that exprTypmod() wasn't smart about SubLinks either, until 8.3.)
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.180 2009/02/15 20:16:21 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.181 2009/03/10 20:58:26 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -523,6 +523,13 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
|
|||||||
PlannerInfo *subroot;
|
PlannerInfo *subroot;
|
||||||
List *pathkeys;
|
List *pathkeys;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Must copy the Query so that planning doesn't mess up the RTE contents
|
||||||
|
* (really really need to fix the planner to not scribble on its input,
|
||||||
|
* someday).
|
||||||
|
*/
|
||||||
|
subquery = copyObject(subquery);
|
||||||
|
|
||||||
/* We need a workspace for keeping track of set-op type coercions */
|
/* We need a workspace for keeping track of set-op type coercions */
|
||||||
differentTypes = (bool *)
|
differentTypes = (bool *)
|
||||||
palloc0((list_length(subquery->targetList) + 1) * sizeof(bool));
|
palloc0((list_length(subquery->targetList) + 1) * sizeof(bool));
|
||||||
|
@ -465,3 +465,15 @@ from tc;
|
|||||||
3
|
3
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Test case for 8.3 "failed to locate grouping columns" bug
|
||||||
|
--
|
||||||
|
create temp table t1 (f1 numeric(14,0), f2 varchar(30));
|
||||||
|
select * from
|
||||||
|
(select distinct f1, f2, (select f2 from t1 x where x.f1 = up.f1) as fs
|
||||||
|
from t1 up) ss
|
||||||
|
group by f1,f2,fs;
|
||||||
|
f1 | f2 | fs
|
||||||
|
----+----+----
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
|
@ -298,3 +298,14 @@ select
|
|||||||
( select min(tb.id) from tb
|
( select min(tb.id) from tb
|
||||||
where tb.aval = (select ta.val from ta where ta.id = tc.aid) ) as min_tb_id
|
where tb.aval = (select ta.val from ta where ta.id = tc.aid) ) as min_tb_id
|
||||||
from tc;
|
from tc;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Test case for 8.3 "failed to locate grouping columns" bug
|
||||||
|
--
|
||||||
|
|
||||||
|
create temp table t1 (f1 numeric(14,0), f2 varchar(30));
|
||||||
|
|
||||||
|
select * from
|
||||||
|
(select distinct f1, f2, (select f2 from t1 x where x.f1 = up.f1) as fs
|
||||||
|
from t1 up) ss
|
||||||
|
group by f1,f2,fs;
|
||||||
|
Reference in New Issue
Block a user