Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69e8f9d

Browse files
committed
Revert "Fix parallel-safety check of expressions and predicate for index builds"
This reverts commiteae7be6, following a discussion with Tom Lane,due to concerns that this impacts the decisions made by the planner forthe number of workers spawned based on the inlining and const-folding ofindex expressions and predicate for cases that would have worked untilthis commit.Discussion:https://postgr.es/m/162802.1709746091@sss.pgh.pa.usBackpatch-through: 12
1 parent466376c commit69e8f9d

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
gotodone;

‎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
returnopclass;
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(Oidindex_oid)
3265-
{
3266-
List*result;
3267-
HeapTupletuple;
3268-
DatumexprDatum;
3269-
boolisnull;
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-
returnNIL;
3282-
}
3283-
3284-
exprString=TextDatumGetCString(exprDatum);
3285-
result= (List*)stringToNode(exprString);
3286-
pfree(exprString);
3287-
ReleaseSysCache(tuple);
3288-
3289-
returnresult;
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(Oidindex_oid)
3299-
{
3300-
List*result;
3301-
HeapTupletuple;
3302-
DatumpredDatum;
3303-
boolisnull;
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-
returnNIL;
3316-
}
3317-
3318-
predString=TextDatumGetCString(predDatum);
3319-
result= (List*)stringToNode(predString);
3320-
pfree(predString);
3321-
ReleaseSysCache(tuple);
3322-
3323-
returnresult;
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
externOidget_range_subtype(OidrangeOid);
183183
externOidget_range_collation(OidrangeOid);
184184
externOidget_index_column_opclass(Oidindex_oid,intattno);
185-
externList*get_index_expressions(Oidindex_oid);
186-
externList*get_index_predicate(Oidindex_oid);
187185
externboolget_index_isreplident(Oidindex_oid);
188186
externboolget_index_isvalid(Oidindex_oid);
189187
externboolget_index_isclustered(Oidindex_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_tableSELECT i,1,2,3FROM generate_series(1,1000) i;
163-
164-
-- Test with index expression and predicate that include a parallel unsafe
165-
-- function.
166-
CREATEFUNCTIONpara_unsafe_f() RETURNSint IMMUTABLE PARALLEL UNSAFE
167-
AS $$
168-
BEGIN
169-
RETURN0;
170-
EXCEPTION WHEN OTHERS THEN
171-
RETURN1;
172-
END$$ LANGUAGE plpgsql;
173-
174-
CREATETABLEbtree_para_bld(iint);
175-
ALTERTABLE btree_para_bldSET (parallel_workers=4);
176-
SET max_parallel_maintenance_workers TO4;
177-
-- With parallel-unsafe expression
178-
CREATEINDEXON btree_para_bld((i+ para_unsafe_f()));
179-
-- With parallel-unsafe predicate
180-
CREATEINDEXON btree_para_bld(i)WHERE i> para_unsafe_f();
181-
182-
RESET max_parallel_maintenance_workers;
183-
DROPTABLE btree_para_bld;
184-
DROPFUNCTION para_unsafe_f;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp