Skip to content

Commit 1dd543c

Browse files
committed
disable constraint exclusion for subselects
1 parent 524baca commit 1dd543c

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

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 */
@@ -240,7 +242,6 @@ PlannedStmt *
240242
pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
241243
{
242244
PlannedStmt *result;
243-
ListCell *lc;
244245

245246
if (pg_pathman_enable)
246247
{
@@ -252,20 +253,13 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
252253
break;
253254
case CMD_UPDATE:
254255
case CMD_DELETE:
256+
disable_inheritance_cte(parse);
257+
disable_inheritance_subselect(parse);
255258
handle_modification_query(parse);
256259
break;
257260
default:
258261
break;
259262
}
260-
261-
/* If query contains CTE (WITH statement) then handle subqueries too */
262-
foreach(lc, parse->cteList)
263-
{
264-
CommonTableExpr *cte = (CommonTableExpr*) lfirst(lc);
265-
266-
if (IsA(cte->ctequery, Query))
267-
disable_inheritance((Query *)cte->ctequery);
268-
}
269263
}
270264

271265
/* Invoke original hook */
@@ -284,10 +278,16 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
284278
static void
285279
disable_inheritance(Query *parse)
286280
{
287-
RangeTblEntry *rte;
288-
ListCell *lc;
281+
ListCell *lc;
282+
RangeTblEntry *rte;
289283
PartRelationInfo *prel;
290-
bool found;
284+
bool found;
285+
286+
/* If query contains CTE (WITH statement) then handle subqueries too */
287+
disable_inheritance_cte(parse);
288+
289+
/* If query contains subselects */
290+
disable_inheritance_subselect(parse);
291291

292292
foreach(lc, parse->rtable)
293293
{
@@ -322,6 +322,35 @@ disable_inheritance(Query *parse)
322322
}
323323
}
324324

325+
static void
326+
disable_inheritance_cte(Query *parse)
327+
{
328+
ListCell *lc;
329+
330+
foreach(lc, parse->cteList)
331+
{
332+
CommonTableExpr *cte = (CommonTableExpr*) lfirst(lc);
333+
334+
if (IsA(cte->ctequery, Query))
335+
disable_inheritance((Query *) cte->ctequery);
336+
}
337+
}
338+
339+
static void
340+
disable_inheritance_subselect(Query *parse)
341+
{
342+
SubLink *sublink;
343+
344+
if (!parse->jointree || !parse->jointree->quals)
345+
return;
346+
347+
sublink = (SubLink *) parse->jointree->quals;
348+
if (!IsA(sublink->subselect, Query))
349+
return;
350+
351+
disable_inheritance((Query *) sublink->subselect);
352+
}
353+
325354
/*
326355
* Checks if query is affects only one partition. If true then substitute
327356
*/

0 commit comments

Comments
 (0)