]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix parallel-safety check of expressions and predicate for index builds
authorMichael Paquier <michael@paquier.xyz>
Wed, 6 Mar 2024 08:24:14 +0000 (17:24 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 6 Mar 2024 08:24:14 +0000 (17:24 +0900)
commitc0e0174c216bedcd3cfeb6b0bb5eead50713c772
tree36118161908ae2436fe652b9633d4cb7cb8e8f70
parent94246405d5d7cb90fc2eff12d9c42b38070fb970
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
src/backend/optimizer/plan/planner.c
src/backend/utils/cache/lsyscache.c
src/include/utils/lsyscache.h
src/test/regress/expected/btree_index.out
src/test/regress/sql/btree_index.sql