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

Commit4bc9f5e

Browse files
committed
Fix brokenness of nested EXCEPT/INTERSECT queries. prepunion was being
a tad sloppy about generating the targetlist for some nodes, by generatinga tlist entry that claimed to be a constant when the value wasn't actuallyconstant. This caused setrefs.c to do the wrong thing later on.
1 parentee8ed85 commit4bc9f5e

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

‎src/backend/optimizer/prep/prepunion.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.65 2001/06/05 05:26:04 tgl Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.66 2001/08/14 17:12:57 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -275,12 +275,14 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
275275
*
276276
* The tlist for an Append plan isn't important as far as the Append is
277277
* concerned, but we must make it look real anyway for the benefit of
278-
* the next plan level up.
278+
* the next plan level up. In fact, it has to be real enough that the
279+
* flag column is shown as a variable not a constant, else setrefs.c
280+
* will get confused.
279281
*/
280282
plan= (Plan*)
281283
make_append(makeList2(lplan,rplan),
282284
false,
283-
generate_setop_tlist(op->colTypes,0, false,
285+
generate_setop_tlist(op->colTypes,2, false,
284286
lplan->targetlist,
285287
refnames_tlist));
286288

@@ -353,6 +355,13 @@ recurse_union_children(Node *setOp, Query *parse,
353355

354356
/*
355357
* Generate targetlist for a set-operation plan node
358+
*
359+
* colTypes: column datatypes for non-junk columns
360+
* flag: -1 if no flag column needed, 0 or 1 to create a const flag column,
361+
* 2 to create a variable flag column
362+
* hack_constants: true to copy up constants (see comments in code)
363+
* input_tlist: targetlist of this node's input node
364+
* refnames_tlist: targetlist to take column names from
356365
*/
357366
staticList*
358367
generate_setop_tlist(List*colTypes,intflag,
@@ -414,19 +423,32 @@ generate_setop_tlist(List *colTypes, int flag,
414423

415424
if (flag >=0)
416425
{
417-
/* Add a resjunkcolumn yielding specifiedflagvalue */
426+
/* Add a resjunk flagcolumn */
418427
resdom=makeResdom((AttrNumber)resno++,
419428
INT4OID,
420429
-1,
421430
pstrdup("flag"),
422431
true);
423-
expr= (Node*)makeConst(INT4OID,
424-
sizeof(int4),
425-
Int32GetDatum(flag),
426-
false,
427-
true,
428-
false,
429-
false);
432+
if (flag <=1)
433+
{
434+
/* flag value is the given constant */
435+
expr= (Node*)makeConst(INT4OID,
436+
sizeof(int4),
437+
Int32GetDatum(flag),
438+
false,
439+
true,
440+
false,
441+
false);
442+
}
443+
else
444+
{
445+
/* flag value is being copied up from subplan */
446+
expr= (Node*)makeVar(0,
447+
resdom->resno,
448+
INT4OID,
449+
-1,
450+
0);
451+
}
430452
tlist=lappend(tlist,makeTargetEntry(resdom,expr));
431453
}
432454

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp