mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Support VERBOSE option in REINDEX command.
When this option is specified, a progress report is printed as each index is reindexed. Per discussion, we agreed on the following syntax for the extensibility of the options. REINDEX (flexible options) { INDEX | ... } name Sawada Masahiko. Reviewed by Robert Haas, Fabrízio Mello, Alvaro Herrera, Kyotaro Horiguchi, Jim Nasby and me. Discussion: CAD21AoA0pK3YcOZAFzMae+2fcc3oGp5zoRggDyMNg5zoaWDhdQ@mail.gmail.com
This commit is contained in:
@@ -1532,7 +1532,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
|
||||
else if (newrelpersistence == RELPERSISTENCE_PERMANENT)
|
||||
reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT;
|
||||
|
||||
reindex_relation(OIDOldHeap, reindex_flags);
|
||||
reindex_relation(OIDOldHeap, reindex_flags, 0);
|
||||
|
||||
/*
|
||||
* If the relation being rebuild is pg_class, swap_relation_files()
|
||||
|
@@ -1681,7 +1681,7 @@ ChooseIndexColumnNames(List *indexElems)
|
||||
* Recreate a specific index.
|
||||
*/
|
||||
Oid
|
||||
ReindexIndex(RangeVar *indexRelation)
|
||||
ReindexIndex(RangeVar *indexRelation, int options)
|
||||
{
|
||||
Oid indOid;
|
||||
Oid heapOid = InvalidOid;
|
||||
@@ -1706,7 +1706,7 @@ ReindexIndex(RangeVar *indexRelation)
|
||||
persistence = irel->rd_rel->relpersistence;
|
||||
index_close(irel, NoLock);
|
||||
|
||||
reindex_index(indOid, false, persistence);
|
||||
reindex_index(indOid, false, persistence, options);
|
||||
|
||||
return indOid;
|
||||
}
|
||||
@@ -1775,7 +1775,7 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation,
|
||||
* Recreate all indexes of a table (and of its toast table, if any)
|
||||
*/
|
||||
Oid
|
||||
ReindexTable(RangeVar *relation)
|
||||
ReindexTable(RangeVar *relation, int options)
|
||||
{
|
||||
Oid heapOid;
|
||||
|
||||
@@ -1785,7 +1785,8 @@ ReindexTable(RangeVar *relation)
|
||||
|
||||
if (!reindex_relation(heapOid,
|
||||
REINDEX_REL_PROCESS_TOAST |
|
||||
REINDEX_REL_CHECK_CONSTRAINTS))
|
||||
REINDEX_REL_CHECK_CONSTRAINTS,
|
||||
options))
|
||||
ereport(NOTICE,
|
||||
(errmsg("table \"%s\" has no indexes",
|
||||
relation->relname)));
|
||||
@@ -1802,7 +1803,8 @@ ReindexTable(RangeVar *relation)
|
||||
* That means this must not be called within a user transaction block!
|
||||
*/
|
||||
void
|
||||
ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind)
|
||||
ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
|
||||
int options)
|
||||
{
|
||||
Oid objectOid;
|
||||
Relation relationRelation;
|
||||
@@ -1938,11 +1940,14 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind)
|
||||
PushActiveSnapshot(GetTransactionSnapshot());
|
||||
if (reindex_relation(relid,
|
||||
REINDEX_REL_PROCESS_TOAST |
|
||||
REINDEX_REL_CHECK_CONSTRAINTS))
|
||||
ereport(DEBUG1,
|
||||
(errmsg("table \"%s.%s\" was reindexed",
|
||||
get_namespace_name(get_rel_namespace(relid)),
|
||||
get_rel_name(relid))));
|
||||
REINDEX_REL_CHECK_CONSTRAINTS,
|
||||
options))
|
||||
|
||||
if (options & REINDEXOPT_VERBOSE)
|
||||
ereport(INFO,
|
||||
(errmsg("table \"%s.%s\" was reindexed",
|
||||
get_namespace_name(get_rel_namespace(relid)),
|
||||
get_rel_name(relid))));
|
||||
PopActiveSnapshot();
|
||||
CommitTransactionCommand();
|
||||
}
|
||||
|
@@ -1234,7 +1234,7 @@ ExecuteTruncate(TruncateStmt *stmt)
|
||||
/*
|
||||
* Reconstruct the indexes to match, and we're done.
|
||||
*/
|
||||
reindex_relation(heap_relid, REINDEX_REL_PROCESS_TOAST);
|
||||
reindex_relation(heap_relid, REINDEX_REL_PROCESS_TOAST, 0);
|
||||
}
|
||||
|
||||
pgstat_count_truncate(rel);
|
||||
|
Reference in New Issue
Block a user