]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Revert "Fix parallel-safety check of expressions and predicate for index builds"
authorMichael Paquier <michael@paquier.xyz>
Wed, 6 Mar 2024 23:31:11 +0000 (08:31 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 6 Mar 2024 23:31:11 +0000 (08:31 +0900)
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

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

index db00a593a65ad63bdb21b59a375f04153305dfaf..65a9b0d802ac3a5c8ee403e47668cd088b5afe67 100644 (file)
@@ -6306,18 +6306,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;
index db6b8a36ec94964744e128286f4d7fa9e2038e32..13f8dafa3081bce635a6042e0544dbdbf6d59533 100644 (file)
@@ -3255,74 +3255,6 @@ get_index_column_opclass(Oid index_oid, int attno)
        return opclass;
 }
 
-/*
- * 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
  *
index 32ca83736eb857558e1633ee513773fae8ed02d1..53d4a2d1093469e6cf97f9c576d3ba8a814b987e 100644 (file)
@@ -182,8 +182,6 @@ extern char *get_namespace_name_or_temp(Oid nspid);
 extern Oid     get_range_subtype(Oid rangeOid);
 extern Oid     get_range_collation(Oid rangeOid);
 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);
index 8d0240f79beae9180f98127a95a0ccfe216aa467..f567117a4662780d17449e8c69ea7ba999394e12 100644 (file)
@@ -330,22 +330,3 @@ VACUUM delete_test_table;
 -- The vacuum above should've turned the leaf page into a fast root. We just
 -- need to insert some rows to cause the fast root page to split.
 INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,1000) i;
--- 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;
index c80165c6ee784749b487a4baa01a285a8597df2b..558dcae0ec7c5f9c4632f3a6417e7058927db48e 100644 (file)
@@ -160,25 +160,3 @@ VACUUM delete_test_table;
 -- The vacuum above should've turned the leaf page into a fast root. We just
 -- need to insert some rows to cause the fast root page to split.
 INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,1000) i;
-
--- 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;