aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planner.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2024-03-06 17:24:06 +0900
committerMichael Paquier <michael@paquier.xyz>2024-03-06 17:24:06 +0900
commit50b5913a87c9c2d67330d82429f6dda61441d40c (patch)
treef84a64aa5d9519703e5c86715e361b8c543dbb8d /src/backend/optimizer/plan/planner.c
parent164fe7a6e1f34a56d91c0130daddbbe6a8e8392f (diff)
downloadpostgresql-50b5913a87c9c2d67330d82429f6dda61441d40c.tar.gz
postgresql-50b5913a87c9c2d67330d82429f6dda61441d40c.zip
Fix parallel-safety check of expressions and predicate for index builds
As coded, the planner logic that calculates the number of parallel workers to use for a parallel index build uses expressions and predicates from the relcache, which are flattened for the planner by eval_const_expressions(). As reported in the bug, an immutable parallel-unsafe function flattened in the relcache would become a Const, which would be considered as parallel-safe, even if the predicate or the expressions including the function are not safe in parallel workers. Depending on the expressions or predicate used, this could cause the parallel build to fail. Tests are included that check parallel index builds with parallel-unsafe predicate and expressions. Two routines are added to lsyscache.h to be able to retrieve expressions and predicate of an index from its pg_index data. Reported-by: Alexander Lakhin Author: Tender Wang Reviewed-by: Jian He, Michael Paquier Discussion: https://postgr.es/m/CAHewXN=UaAaNn9ruHDH3Os8kxLVmtWqbssnf=dZN_s9=evHUFA@mail.gmail.com Backpatch-through: 12
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r--src/backend/optimizer/plan/planner.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index bd4e4ceeca5..d833b23c47e 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -6143,10 +6143,18 @@ plan_create_index_workers(Oid tableOid, Oid indexOid)
* Currently, parallel workers can't access the leader's temporary tables.
* Furthermore, any index predicate or index expressions must be parallel
* safe.
+ *
+ * Fetch the list of expressions and predicates directly from the
+ * catalogs. Retrieving this information from the relcache would cause
+ * the expressions and predicates to be flattened, losing properties that
+ * can be important to check if parallel workers can be used. For
+ * example, immutable parallel-unsafe functions, that cannot be used in
+ * parallel workers, would be changed to Const nodes, that are safe in
+ * parallel workers.
*/
if (heap->rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
- !is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index)) ||
- !is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index)))
+ !is_parallel_safe(root, (Node *) get_index_expressions(indexOid)) ||
+ !is_parallel_safe(root, (Node *) get_index_predicate(indexOid)))
{
parallel_workers = 0;
goto done;