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

Commit96a25d3

Browse files
committed
Fix more problems with rewriter failing to set Query.hasSubLinks when inserting
a SubLink expression into a rule query. We missed cases where the originalquery contained a sub-SELECT in a function in FROM, a multi-row VALUES list,or a RETURNING list. Per bug #4434 from Dean Rasheed and subsequentinvestigation.Back-patch to 8.1; older releases don't have the issue because they didn'ttry to be smart about setting hasSubLinks only when needed.
1 parent93eab31 commit96a25d3

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.179 2008/08/28 23:09:48 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.180 2008/09/24 16:52:46 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -346,6 +346,37 @@ rewriteRuleAction(Query *parsetree,
346346
sub_action->rtable=list_concat((List*)copyObject(parsetree->rtable),
347347
sub_action->rtable);
348348

349+
/*
350+
* There could have been some SubLinks in parsetree's rtable, in which
351+
* case we'd better mark the sub_action correctly.
352+
*/
353+
if (parsetree->hasSubLinks&& !sub_action->hasSubLinks)
354+
{
355+
ListCell*lc;
356+
357+
foreach(lc,parsetree->rtable)
358+
{
359+
RangeTblEntry*rte= (RangeTblEntry*)lfirst(lc);
360+
361+
switch (rte->rtekind)
362+
{
363+
caseRTE_FUNCTION:
364+
sub_action->hasSubLinks=
365+
checkExprHasSubLink(rte->funcexpr);
366+
break;
367+
caseRTE_VALUES:
368+
sub_action->hasSubLinks=
369+
checkExprHasSubLink((Node*)rte->values_lists);
370+
break;
371+
default:
372+
/* other RTE types don't contain bare expressions */
373+
break;
374+
}
375+
if (sub_action->hasSubLinks)
376+
break;/* no need to keep scanning rtable */
377+
}
378+
}
379+
349380
/*
350381
* Each rule action's jointree should be the main parsetree's jointree
351382
* plus that rule's jointree, but usually *without* the original rtindex
@@ -455,6 +486,14 @@ rewriteRuleAction(Query *parsetree,
455486
rule_action->returningList,
456487
CMD_SELECT,
457488
0);
489+
490+
/*
491+
* There could have been some SubLinks in parsetree's returningList,
492+
* in which case we'd better mark the rule_action correctly.
493+
*/
494+
if (parsetree->hasSubLinks&& !rule_action->hasSubLinks)
495+
rule_action->hasSubLinks=
496+
checkExprHasSubLink((Node*)rule_action->returningList);
458497
}
459498

460499
returnrule_action;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp