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

Commit4886dc9

Browse files
committed
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 planningreplaces SubLinks by SubPlans in the subquery's targetlist, and exprTypmod()is smarter about the former than the latter, causing the apparent type ofthe subquery's output columns to change. This seems to be a deficiency weshould fix in exprTypmod(), but that will be a much more invasive patchwith 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/dangerousall the way back, but in the absence of known problems I'll refrain frommaking the older branches pay the extra cost. (The reason this particularsymptom didn't appear before is that exprTypmod() wasn't smart about SubLinkseither, until 8.3.)
1 parent4283172 commit4886dc9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

‎src/backend/optimizer/path/allpaths.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.180 2009/02/15 20:16:21 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.181 2009/03/10 20:58:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -523,6 +523,13 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
523523
PlannerInfo*subroot;
524524
List*pathkeys;
525525

526+
/*
527+
* Must copy the Query so that planning doesn't mess up the RTE contents
528+
* (really really need to fix the planner to not scribble on its input,
529+
* someday).
530+
*/
531+
subquery=copyObject(subquery);
532+
526533
/* We need a workspace for keeping track of set-op type coercions */
527534
differentTypes= (bool*)
528535
palloc0((list_length(subquery->targetList)+1)*sizeof(bool));

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,15 @@ from tc;
465465
3
466466
(2 rows)
467467

468+
--
469+
-- Test case for 8.3 "failed to locate grouping columns" bug
470+
--
471+
create temp table t1 (f1 numeric(14,0), f2 varchar(30));
472+
select * from
473+
(select distinct f1, f2, (select f2 from t1 x where x.f1 = up.f1) as fs
474+
from t1 up) ss
475+
group by f1,f2,fs;
476+
f1 | f2 | fs
477+
----+----+----
478+
(0 rows)
479+

‎src/test/regress/sql/subselect.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,14 @@ select
298298
(selectmin(tb.id)from tb
299299
wheretb.aval= (selectta.valfrom tawhereta.id=tc.aid) )as min_tb_id
300300
from tc;
301+
302+
--
303+
-- Test case for 8.3 "failed to locate grouping columns" bug
304+
--
305+
306+
create temp table t1 (f1numeric(14,0), f2varchar(30));
307+
308+
select*from
309+
(select distinct f1, f2, (select f2from t1 xwherex.f1=up.f1)as fs
310+
from t1 up) ss
311+
group by f1,f2,fs;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp