Skip to content

Commit 71132d4

Browse files
committed
pathman: disable constraint exclusion mechanism for subselects
1 parent acafdea commit 71132d4

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

contrib/pg_pathman/pg_pathman.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static int append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
8181
RangeTblEntry *rte, int index, Oid childOID, List *wrappers);
8282
static Node *wrapper_make_expression(WrapperNode *wrap, int index, bool *alwaysTrue);
8383
static void disable_inheritance(Query *parse);
84+
static void disable_inheritance_cte(Query *parse);
85+
static void disable_inheritance_subselect(Query *parse);
8486
bool inheritance_disabled;
8587

8688
/* Expression tree handlers */
@@ -254,7 +256,6 @@ PlannedStmt *
254256
pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
255257
{
256258
PlannedStmt *result;
257-
ListCell *lc;
258259

259260
if (pg_pathman_enable)
260261
{
@@ -266,20 +267,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
266267
break;
267268
case CMD_UPDATE:
268269
case CMD_DELETE:
270+
disable_inheritance_cte(parse);
271+
disable_inheritance_subselect(parse);
269272
handle_modification_query(parse);
270273
break;
271274
default:
272275
break;
273276
}
274-
275-
/* If query contains CTE (WITH statement) then handle subqueries too */
276-
foreach(lc, parse->cteList)
277-
{
278-
CommonTableExpr *cte = (CommonTableExpr*) lfirst(lc);
279-
280-
if (IsA(cte->ctequery, Query))
281-
disable_inheritance((Query *)cte->ctequery);
282-
}
283277
}
284278

285279
/* Invoke original hook */
@@ -298,10 +292,16 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
298292
static void
299293
disable_inheritance(Query *parse)
300294
{
301-
RangeTblEntry *rte;
302-
ListCell *lc;
295+
ListCell *lc;
296+
RangeTblEntry *rte;
303297
PartRelationInfo *prel;
304-
bool found;
298+
bool found;
299+
300+
/* If query contains CTE (WITH statement) then handle subqueries too */
301+
disable_inheritance_cte(parse);
302+
303+
/* If query contains subselects */
304+
disable_inheritance_subselect(parse);
305305

306306
foreach(lc, parse->rtable)
307307
{
@@ -336,6 +336,35 @@ disable_inheritance(Query *parse)
336336
}
337337
}
338338

339+
static void
340+
disable_inheritance_cte(Query *parse)
341+
{
342+
ListCell *lc;
343+
344+
foreach(lc, parse->cteList)
345+
{
346+
CommonTableExpr *cte = (CommonTableExpr*) lfirst(lc);
347+
348+
if (IsA(cte->ctequery, Query))
349+
disable_inheritance((Query *) cte->ctequery);
350+
}
351+
}
352+
353+
static void
354+
disable_inheritance_subselect(Query *parse)
355+
{
356+
SubLink *sublink;
357+
358+
if (!parse->jointree || !parse->jointree->quals)
359+
return;
360+
361+
sublink = (SubLink *) parse->jointree->quals;
362+
if (!IsA(sublink->subselect, Query))
363+
return;
364+
365+
disable_inheritance((Query *) sublink->subselect);
366+
}
367+
339368
/*
340369
* Checks if query is affects only one partition. If true then substitute
341370
*/

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