Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 69e8f9d

Browse files
committed
Revert "Fix parallel-safety check of expressions and predicate for index builds"
This reverts commit eae7be6, 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
1 parent 466376c commit 69e8f9d

File tree

5 files changed

+2
-121
lines changed

5 files changed

+2
-121
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6306,18 +6306,10 @@ plan_create_index_workers(Oid tableOid, Oid indexOid)
63066306
* Currently, parallel workers can't access the leader's temporary tables.
63076307
* Furthermore, any index predicate or index expressions must be parallel
63086308
* safe.
6309-
*
6310-
* Fetch the list of expressions and predicates directly from the
6311-
* catalogs. Retrieving this information from the relcache would cause
6312-
* the expressions and predicates to be flattened, losing properties that
6313-
* can be important to check if parallel workers can be used. For
6314-
* example, immutable parallel-unsafe functions, that cannot be used in
6315-
* parallel workers, would be changed to Const nodes, that are safe in
6316-
* parallel workers.
63176309
*/
63186310
if (heap->rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
6319-
!is_parallel_safe(root, (Node *) get_index_expressions(indexOid)) ||
6320-
!is_parallel_safe(root, (Node *) get_index_predicate(indexOid)))
6311+
!is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index)) ||
6312+
!is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index)))
63216313
{
63226314
parallel_workers = 0;
63236315
goto done;

src/backend/utils/cache/lsyscache.c

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,74 +3255,6 @@ get_index_column_opclass(Oid index_oid, int attno)
32553255
return opclass;
32563256
}
32573257

3258-
/*
3259-
* get_index_expressions
3260-
*
3261-
* Given the index OID, its a List of its expressions or NIL if none.
3262-
*/
3263-
List *
3264-
get_index_expressions(Oid index_oid)
3265-
{
3266-
List *result;
3267-
HeapTuple tuple;
3268-
Datum exprDatum;
3269-
bool isnull;
3270-
char *exprString;
3271-
3272-
tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid));
3273-
if (!HeapTupleIsValid(tuple))
3274-
elog(ERROR, "cache lookup failed for index %u", index_oid);
3275-
3276-
exprDatum = SysCacheGetAttr(INDEXRELID, tuple,
3277-
Anum_pg_index_indexprs, &isnull);
3278-
if (isnull)
3279-
{
3280-
ReleaseSysCache(tuple);
3281-
return NIL;
3282-
}
3283-
3284-
exprString = TextDatumGetCString(exprDatum);
3285-
result = (List *) stringToNode(exprString);
3286-
pfree(exprString);
3287-
ReleaseSysCache(tuple);
3288-
3289-
return result;
3290-
}
3291-
3292-
/*
3293-
* get_index_predicate
3294-
*
3295-
* Given the index OID, return a List of its predicate or NIL if none.
3296-
*/
3297-
List *
3298-
get_index_predicate(Oid index_oid)
3299-
{
3300-
List *result;
3301-
HeapTuple tuple;
3302-
Datum predDatum;
3303-
bool isnull;
3304-
char *predString;
3305-
3306-
tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid));
3307-
if (!HeapTupleIsValid(tuple))
3308-
elog(ERROR, "cache lookup failed for index %u", index_oid);
3309-
3310-
predDatum = SysCacheGetAttr(INDEXRELID, tuple,
3311-
Anum_pg_index_indpred, &isnull);
3312-
if (isnull)
3313-
{
3314-
ReleaseSysCache(tuple);
3315-
return NIL;
3316-
}
3317-
3318-
predString = TextDatumGetCString(predDatum);
3319-
result = (List *) stringToNode(predString);
3320-
pfree(predString);
3321-
ReleaseSysCache(tuple);
3322-
3323-
return result;
3324-
}
3325-
33263258
/*
33273259
* get_index_isreplident
33283260
*

src/include/utils/lsyscache.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ extern char *get_namespace_name_or_temp(Oid nspid);
182182
extern Oid get_range_subtype(Oid rangeOid);
183183
extern Oid get_range_collation(Oid rangeOid);
184184
extern Oid get_index_column_opclass(Oid index_oid, int attno);
185-
extern List *get_index_expressions(Oid index_oid);
186-
extern List *get_index_predicate(Oid index_oid);
187185
extern bool get_index_isreplident(Oid index_oid);
188186
extern bool get_index_isvalid(Oid index_oid);
189187
extern bool get_index_isclustered(Oid index_oid);

src/test/regress/expected/btree_index.out

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -330,22 +330,3 @@ VACUUM delete_test_table;
330330
-- The vacuum above should've turned the leaf page into a fast root. We just
331331
-- need to insert some rows to cause the fast root page to split.
332332
INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,1000) i;
333-
-- Test with index expression and predicate that include a parallel unsafe
334-
-- function.
335-
CREATE FUNCTION para_unsafe_f() RETURNS int IMMUTABLE PARALLEL UNSAFE
336-
AS $$
337-
BEGIN
338-
RETURN 0;
339-
EXCEPTION WHEN OTHERS THEN
340-
RETURN 1;
341-
END$$ LANGUAGE plpgsql;
342-
CREATE TABLE btree_para_bld(i int);
343-
ALTER TABLE btree_para_bld SET (parallel_workers = 4);
344-
SET max_parallel_maintenance_workers TO 4;
345-
-- With parallel-unsafe expression
346-
CREATE INDEX ON btree_para_bld((i + para_unsafe_f()));
347-
-- With parallel-unsafe predicate
348-
CREATE INDEX ON btree_para_bld(i) WHERE i > para_unsafe_f();
349-
RESET max_parallel_maintenance_workers;
350-
DROP TABLE btree_para_bld;
351-
DROP FUNCTION para_unsafe_f;

src/test/regress/sql/btree_index.sql

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,25 +160,3 @@ VACUUM delete_test_table;
160160
-- The vacuum above should've turned the leaf page into a fast root. We just
161161
-- need to insert some rows to cause the fast root page to split.
162162
INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,1000) i;
163-
164-
-- Test with index expression and predicate that include a parallel unsafe
165-
-- function.
166-
CREATE FUNCTION para_unsafe_f() RETURNS int IMMUTABLE PARALLEL UNSAFE
167-
AS $$
168-
BEGIN
169-
RETURN 0;
170-
EXCEPTION WHEN OTHERS THEN
171-
RETURN 1;
172-
END$$ LANGUAGE plpgsql;
173-
174-
CREATE TABLE btree_para_bld(i int);
175-
ALTER TABLE btree_para_bld SET (parallel_workers = 4);
176-
SET max_parallel_maintenance_workers TO 4;
177-
-- With parallel-unsafe expression
178-
CREATE INDEX ON btree_para_bld((i + para_unsafe_f()));
179-
-- With parallel-unsafe predicate
180-
CREATE INDEX ON btree_para_bld(i) WHERE i > para_unsafe_f();
181-
182-
RESET max_parallel_maintenance_workers;
183-
DROP TABLE btree_para_bld;
184-
DROP FUNCTION para_unsafe_f;

0 commit comments

Comments
 (0)