From a8f92eec97e7d3d6afc2cdfd5982b3300de9f45b Mon Sep 17 00:00:00 2001 From: "houzj.fnst" Date: Wed, 28 Jul 2021 19:05:34 +0800 Subject: [PATCH] hack the rewriter bug --- src/backend/optimizer/util/clauses.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 09c7e92..9195ae4 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -941,6 +941,27 @@ max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context) } /* + * ModifyingCTE expressions are treated as parallel-unsafe. + * + * XXX Normally, if the Query has a modifying CTE, the hasModifyingCTE + * flag is set in the Query tree, and the query will be regarded as + * parallel-usafe. However, in some cases, a re-written query with a + * modifying CTE does not have that flag set, due to a bug in the query + * rewriter. + */ + else if (IsA(node, CommonTableExpr)) + { + CommonTableExpr *cte = (CommonTableExpr *) node; + Query *ctequery = castNode(Query, cte->ctequery); + + if (ctequery->commandType != CMD_SELECT) + { + context->max_hazard = PROPARALLEL_UNSAFE; + return true; + } + } + + /* * As a notational convenience for callers, look through RestrictInfo. */ else if (IsA(node, RestrictInfo)) -- 2.7.2.windows.1