diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c index ac84af294c9..f203ed85f50 100644 --- a/src/backend/executor/execParallel.c +++ b/src/backend/executor/execParallel.c @@ -212,6 +212,13 @@ ExecSerializePlan(Plan *plan, EState *estate) pstmt->rewindPlanIDs = NULL; pstmt->rowMarks = NIL; + + /* + * Pass the row mark and result relation relids to parallel workers. They + * may need to check them to inform heuristics. + */ + pstmt->rowMarkRelids = estate->es_plannedstmt->rowMarkRelids; + pstmt->resultRelationRelids = estate->es_plannedstmt->resultRelationRelids; pstmt->relationOids = NIL; pstmt->invalItems = NIL; /* workers can't replan anyway... */ pstmt->paramExecTypes = estate->es_plannedstmt->paramExecTypes; diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index d19800ad6a5..c81eb76ad75 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -341,7 +341,8 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions, Path *best_path; Plan *top_plan; ListCell *lp, - *lr; + *lr, + *lc; /* * Set up global state for this planner invocation. This data is needed @@ -661,6 +662,18 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions, result->subplans = glob->subplans; result->rewindPlanIDs = glob->rewindPlanIDs; result->rowMarks = glob->finalrowmarks; + + /* + * Compute resultRelationRelids and rowMarkRelids from resultRelations and + * rowMarks. These can be used for cheap membership checks. + */ + foreach(lc, glob->resultRelations) + result->resultRelationRelids = bms_add_member(result->resultRelationRelids, + lfirst_int(lc)); + foreach(lc, glob->finalrowmarks) + result->rowMarkRelids = bms_add_member(result->rowMarkRelids, + ((PlanRowMark *) lfirst(lc))->rti); + result->relationOids = glob->relationOids; result->invalItems = glob->invalItems; result->paramExecTypes = glob->paramExecTypes; diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index b6185825fcb..ca61ecfc132 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -121,6 +121,9 @@ typedef struct PlannedStmt /* integer list of RT indexes, or NIL */ List *resultRelations; + /* RT indexes of relations targeted by INSERT/UPDATE/DELETE/MERGE */ + Bitmapset *resultRelationRelids; + /* list of AppendRelInfo nodes */ List *appendRelations; @@ -138,6 +141,9 @@ typedef struct PlannedStmt /* a list of PlanRowMark's */ List *rowMarks; + /* RT indexes of relations with row marks */ + Bitmapset *rowMarkRelids; + /* OIDs of relations the plan depends on */ List *relationOids;