diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-03-07 08:31:07 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-03-07 08:31:07 +0900 |
commit | 49b971298a9b4271a9d5f91dcc969c5cb1acfbc1 (patch) | |
tree | 69ae1bcbcbd9d56f77f308ce673299e271edf6a8 | |
parent | a595c3075fb4b8ab4211b074485eb0a17062ec7f (diff) | |
download | postgresql-49b971298a9b4271a9d5f91dcc969c5cb1acfbc1.tar.gz postgresql-49b971298a9b4271a9d5f91dcc969c5cb1acfbc1.zip |
Revert "Fix parallel-safety check of expressions and predicate for index builds"
This reverts commit eae7be600be7, following a discussion with Tom Lane,
due to concerns that this impacts the decisions made by the planner for
the number of workers spawned based on the inlining and const-folding of
index expressions and predicate for cases that would have worked until
this commit.
Discussion: https://postgr.es/m/162802.1709746091@sss.pgh.pa.us
Backpatch-through: 12
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 12 | ||||
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 68 | ||||
-rw-r--r-- | src/include/utils/lsyscache.h | 2 | ||||
-rw-r--r-- | src/test/regress/expected/btree_index.out | 19 | ||||
-rw-r--r-- | src/test/regress/sql/btree_index.sql | 22 |
5 files changed, 2 insertions, 121 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 88cb97f445f..5da863d85de 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -5911,18 +5911,10 @@ 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 *) get_index_expressions(indexOid)) || - !is_parallel_safe(root, (Node *) get_index_predicate(indexOid))) + !is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index)) || + !is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index))) { parallel_workers = 0; goto done; diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 3c232aa960f..5564b53f257 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -3511,74 +3511,6 @@ get_index_column_opclass(Oid index_oid, int attno) } /* - * get_index_expressions - * - * Given the index OID, its a List of its expressions or NIL if none. - */ -List * -get_index_expressions(Oid index_oid) -{ - List *result; - HeapTuple tuple; - Datum exprDatum; - bool isnull; - char *exprString; - - tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid)); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for index %u", index_oid); - - exprDatum = SysCacheGetAttr(INDEXRELID, tuple, - Anum_pg_index_indexprs, &isnull); - if (isnull) - { - ReleaseSysCache(tuple); - return NIL; - } - - exprString = TextDatumGetCString(exprDatum); - result = (List *) stringToNode(exprString); - pfree(exprString); - ReleaseSysCache(tuple); - - return result; -} - -/* - * get_index_predicate - * - * Given the index OID, return a List of its predicate or NIL if none. - */ -List * -get_index_predicate(Oid index_oid) -{ - List *result; - HeapTuple tuple; - Datum predDatum; - bool isnull; - char *predString; - - tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid)); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for index %u", index_oid); - - predDatum = SysCacheGetAttr(INDEXRELID, tuple, - Anum_pg_index_indpred, &isnull); - if (isnull) - { - ReleaseSysCache(tuple); - return NIL; - } - - predString = TextDatumGetCString(predDatum); - result = (List *) stringToNode(predString); - pfree(predString); - ReleaseSysCache(tuple); - - return result; -} - -/* * get_index_isreplident * * Given the index OID, return pg_index.indisreplident. diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 704543fa07c..77871aaefc3 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -195,8 +195,6 @@ extern Oid get_range_collation(Oid rangeOid); extern Oid get_range_multirange(Oid rangeOid); extern Oid get_multirange_range(Oid multirangeOid); extern Oid get_index_column_opclass(Oid index_oid, int attno); -extern List *get_index_expressions(Oid index_oid); -extern List *get_index_predicate(Oid index_oid); extern bool get_index_isreplident(Oid index_oid); extern bool get_index_isvalid(Oid index_oid); extern bool get_index_isclustered(Oid index_oid); diff --git a/src/test/regress/expected/btree_index.out b/src/test/regress/expected/btree_index.out index 0463d72faa7..c7328b1dc4f 100644 --- a/src/test/regress/expected/btree_index.out +++ b/src/test/regress/expected/btree_index.out @@ -341,22 +341,3 @@ CREATE INDEX btree_part_idx ON btree_part(id); ALTER INDEX btree_part_idx ALTER COLUMN id SET (n_distinct=100); ERROR: "btree_part_idx" is not a table, materialized view, or foreign table DROP TABLE btree_part; --- Test with index expression and predicate that include a parallel unsafe --- function. -CREATE FUNCTION para_unsafe_f() RETURNS int IMMUTABLE PARALLEL UNSAFE -AS $$ -BEGIN - RETURN 0; -EXCEPTION WHEN OTHERS THEN - RETURN 1; -END$$ LANGUAGE plpgsql; -CREATE TABLE btree_para_bld(i int); -ALTER TABLE btree_para_bld SET (parallel_workers = 4); -SET max_parallel_maintenance_workers TO 4; --- With parallel-unsafe expression -CREATE INDEX ON btree_para_bld((i + para_unsafe_f())); --- With parallel-unsafe predicate -CREATE INDEX ON btree_para_bld(i) WHERE i > para_unsafe_f(); -RESET max_parallel_maintenance_workers; -DROP TABLE btree_para_bld; -DROP FUNCTION para_unsafe_f; diff --git a/src/test/regress/sql/btree_index.sql b/src/test/regress/sql/btree_index.sql index 71d816223da..c34502249f3 100644 --- a/src/test/regress/sql/btree_index.sql +++ b/src/test/regress/sql/btree_index.sql @@ -183,25 +183,3 @@ CREATE TABLE btree_part (id int4) PARTITION BY RANGE (id); CREATE INDEX btree_part_idx ON btree_part(id); ALTER INDEX btree_part_idx ALTER COLUMN id SET (n_distinct=100); DROP TABLE btree_part; - --- Test with index expression and predicate that include a parallel unsafe --- function. -CREATE FUNCTION para_unsafe_f() RETURNS int IMMUTABLE PARALLEL UNSAFE -AS $$ -BEGIN - RETURN 0; -EXCEPTION WHEN OTHERS THEN - RETURN 1; -END$$ LANGUAGE plpgsql; - -CREATE TABLE btree_para_bld(i int); -ALTER TABLE btree_para_bld SET (parallel_workers = 4); -SET max_parallel_maintenance_workers TO 4; --- With parallel-unsafe expression -CREATE INDEX ON btree_para_bld((i + para_unsafe_f())); --- With parallel-unsafe predicate -CREATE INDEX ON btree_para_bld(i) WHERE i > para_unsafe_f(); - -RESET max_parallel_maintenance_workers; -DROP TABLE btree_para_bld; -DROP FUNCTION para_unsafe_f; |