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

Commit2d3320d

Browse files
committed
Simplify reindex_relation's API.
For what seem entirely historical reasons, a bitmask "flags" argument wasrecently added to reindex_relation without subsuming its existing booleanargument into that bitmask. This seems a bit bizarre, so fold themtogether.
1 parent121f49a commit2d3320d

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

‎src/backend/catalog/index.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,29 +2841,33 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
28412841
* reindex_relation - This routine is used to recreate all indexes
28422842
* of a relation (and optionally its toast relation too, if any).
28432843
*
2844-
* "flags" can includeREINDEX_SUPPRESS_INDEX_USE and REINDEX_CHECK_CONSTRAINTS.
2844+
* "flags"is a bitmask thatcan includeany combination of these bits:
28452845
*
2846-
* If flags has REINDEX_SUPPRESS_INDEX_USE, the relation was just completely
2846+
* REINDEX_REL_PROCESS_TOAST: if true, process the toast table too (if any).
2847+
*
2848+
* REINDEX_REL_SUPPRESS_INDEX_USE: if true, the relation was just completely
28472849
* rebuilt by an operation such as VACUUM FULL or CLUSTER, and therefore its
28482850
* indexes are inconsistent with it. This makes things tricky if the relation
28492851
* is a system catalog that we might consult during the reindexing. To deal
28502852
* with that case, we mark all of the indexes as pending rebuild so that they
28512853
* won't be trusted until rebuilt. The caller is required to call us *without*
2852-
* having made the rebuiltversions visible by doing CommandCounterIncrement;
2854+
* having made the rebuilttable visible by doing CommandCounterIncrement;
28532855
* we'll do CCI after having collected the index list. (This way we can still
28542856
* use catalog indexes while collecting the list.)
28552857
*
2856-
* To avoid deadlocks, VACUUM FULL or CLUSTER on a system catalog must omit the
2857-
* REINDEX_CHECK_CONSTRAINTS flag.REINDEX should be used to rebuild an index
2858-
* if constraint inconsistency is suspected. For optimal performance, other
2859-
* callers should include the flag only after transforming the data in a manner
2860-
* that risks a change in constraint validity.
2858+
* REINDEX_REL_CHECK_CONSTRAINTS: if true, recheck unique and exclusion
2859+
* constraint conditions, else don't. To avoid deadlocks, VACUUM FULL or
2860+
* CLUSTER on a system catalog must omit this flag. REINDEX should be used to
2861+
* rebuild an index if constraint inconsistency is suspected. For optimal
2862+
* performance, other callers should include the flag only after transforming
2863+
* the data in a manner that risks a change in constraint validity.
28612864
*
2862-
* Returns true if any indexes were rebuilt. Note that a
2863-
* CommandCounterIncrement will occur after each index rebuild.
2865+
* Returns true if any indexes were rebuilt (including toast table's index
2866+
* when relevant). Note that a CommandCounterIncrement will occur after each
2867+
* index rebuild.
28642868
*/
28652869
bool
2866-
reindex_relation(Oidrelid,booltoast_too,intflags)
2870+
reindex_relation(Oidrelid,intflags)
28672871
{
28682872
Relationrel;
28692873
Oidtoast_relid;
@@ -2919,7 +2923,7 @@ reindex_relation(Oid relid, bool toast_too, int flags)
29192923
List*doneIndexes;
29202924
ListCell*indexId;
29212925

2922-
if (flags&REINDEX_SUPPRESS_INDEX_USE)
2926+
if (flags&REINDEX_REL_SUPPRESS_INDEX_USE)
29232927
{
29242928
/* Suppress use of all the indexes until they are rebuilt */
29252929
SetReindexPending(indexIds);
@@ -2940,11 +2944,11 @@ reindex_relation(Oid relid, bool toast_too, int flags)
29402944
if (is_pg_class)
29412945
RelationSetIndexList(rel,doneIndexes,InvalidOid);
29422946

2943-
reindex_index(indexOid, !(flags&REINDEX_CHECK_CONSTRAINTS));
2947+
reindex_index(indexOid, !(flags&REINDEX_REL_CHECK_CONSTRAINTS));
29442948

29452949
CommandCounterIncrement();
29462950

2947-
if (flags&REINDEX_SUPPRESS_INDEX_USE)
2951+
if (flags&REINDEX_REL_SUPPRESS_INDEX_USE)
29482952
RemoveReindexPending(indexOid);
29492953

29502954
if (is_pg_class)
@@ -2972,12 +2976,10 @@ reindex_relation(Oid relid, bool toast_too, int flags)
29722976

29732977
/*
29742978
* If the relation has a secondary toast rel, reindex that too while we
2975-
* still hold the lock on the master table. There's never a reason to
2976-
* reindex the toast table right after rebuilding the heap.
2979+
* still hold the lock on the master table.
29772980
*/
2978-
Assert(!(toast_too&& (flags&REINDEX_SUPPRESS_INDEX_USE)));
2979-
if (toast_too&&OidIsValid(toast_relid))
2980-
result |=reindex_relation(toast_relid, false,flags);
2981+
if ((flags&REINDEX_REL_PROCESS_TOAST)&&OidIsValid(toast_relid))
2982+
result |=reindex_relation(toast_relid,flags);
29812983

29822984
returnresult;
29832985
}

‎src/backend/commands/cluster.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,10 +1399,10 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
13991399
* so no chance to reclaim disk space before commit. We do not need a
14001400
* final CommandCounterIncrement() because reindex_relation does it.
14011401
*/
1402-
reindex_flags=REINDEX_SUPPRESS_INDEX_USE;
1402+
reindex_flags=REINDEX_REL_SUPPRESS_INDEX_USE;
14031403
if (check_constraints)
1404-
reindex_flags |=REINDEX_CHECK_CONSTRAINTS;
1405-
reindex_relation(OIDOldHeap,false,reindex_flags);
1404+
reindex_flags |=REINDEX_REL_CHECK_CONSTRAINTS;
1405+
reindex_relation(OIDOldHeap,reindex_flags);
14061406

14071407
/* Destroy new heap with old filenode */
14081408
object.classId=RelationRelationId;

‎src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ ReindexTable(RangeVar *relation)
15661566

15671567
ReleaseSysCache(tuple);
15681568

1569-
if (!reindex_relation(heapOid,true,0))
1569+
if (!reindex_relation(heapOid,REINDEX_REL_PROCESS_TOAST))
15701570
ereport(NOTICE,
15711571
(errmsg("table \"%s\" has no indexes",
15721572
relation->relname)));
@@ -1679,7 +1679,7 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
16791679
StartTransactionCommand();
16801680
/* functions in indexes may want a snapshot set */
16811681
PushActiveSnapshot(GetTransactionSnapshot());
1682-
if (reindex_relation(relid,true,0))
1682+
if (reindex_relation(relid,REINDEX_REL_PROCESS_TOAST))
16831683
ereport(NOTICE,
16841684
(errmsg("table \"%s.%s\" was reindexed",
16851685
get_namespace_name(get_rel_namespace(relid)),

‎src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ ExecuteTruncate(TruncateStmt *stmt)
10801080
/*
10811081
* Reconstruct the indexes to match, and we're done.
10821082
*/
1083-
reindex_relation(heap_relid,true,0);
1083+
reindex_relation(heap_relid,REINDEX_REL_PROCESS_TOAST);
10841084
}
10851085
}
10861086

‎src/include/catalog/index.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
8888

8989
externvoidreindex_index(OidindexId,boolskip_constraint_checks);
9090

91-
#defineREINDEX_CHECK_CONSTRAINTS0x1
92-
#defineREINDEX_SUPPRESS_INDEX_USE0x2
93-
externboolreindex_relation(Oidrelid,booltoast_too,intflags);
91+
/* Flag bits for reindex_relation(): */
92+
#defineREINDEX_REL_PROCESS_TOAST0x01
93+
#defineREINDEX_REL_SUPPRESS_INDEX_USE0x02
94+
#defineREINDEX_REL_CHECK_CONSTRAINTS0x04
95+
96+
externboolreindex_relation(Oidrelid,intflags);
9497

9598
externboolReindexIsProcessingHeap(OidheapOid);
9699
externboolReindexIsProcessingIndex(OidindexOid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp