Skip to content

Commit 96a25d3

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 original query 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 subsequent investigation. Back-patch to 8.1; older releases don't have the issue because they didn't try to be smart about setting hasSubLinks only when needed.
1 parent 93eab31 commit 96a25d3

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+
case RTE_FUNCTION:
364+
sub_action->hasSubLinks =
365+
checkExprHasSubLink(rte->funcexpr);
366+
break;
367+
case RTE_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
return rule_action;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy