mirror of
https://github.com/postgres/postgres.git
synced 2025-06-22 02:52:08 +03:00
Fix confusing NOTICE text in REINDEX CONCURRENTLY
When performing REINDEX TABLE CONCURRENTLY, if all of the table's indexes could not be reindexed, a NOTICE message claimed that the table had no indexes. This was confusing, so let's change the NOTICE text to something less confusing. In passing, also mention in the comment before ReindexRelationConcurrently that materialized views are supported too and also explain what the return value of the function means. Author: Ashwin Agrawal Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/CALfoeithHvi13p_VyR8kt9o6Pa7Z=Smi6Nfc2anHnQx5Lj8bTQ@mail.gmail.com
This commit is contained in:
@ -2444,17 +2444,25 @@ ReindexTable(RangeVar *relation, int options, bool concurrent)
|
||||
RangeVarCallbackOwnsTable, NULL);
|
||||
|
||||
if (concurrent)
|
||||
{
|
||||
result = ReindexRelationConcurrently(heapOid, options);
|
||||
|
||||
if (!result)
|
||||
ereport(NOTICE,
|
||||
(errmsg("table \"%s\" has no indexes that can be reindexed concurrently",
|
||||
relation->relname)));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = reindex_relation(heapOid,
|
||||
REINDEX_REL_PROCESS_TOAST |
|
||||
REINDEX_REL_CHECK_CONSTRAINTS,
|
||||
options);
|
||||
|
||||
if (!result)
|
||||
ereport(NOTICE,
|
||||
(errmsg("table \"%s\" has no indexes",
|
||||
relation->relname)));
|
||||
if (!result)
|
||||
ereport(NOTICE,
|
||||
(errmsg("table \"%s\" has no indexes to reindex",
|
||||
relation->relname)));
|
||||
}
|
||||
|
||||
return heapOid;
|
||||
}
|
||||
@ -2636,7 +2644,6 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
|
||||
foreach(l, relids)
|
||||
{
|
||||
Oid relid = lfirst_oid(l);
|
||||
bool result;
|
||||
|
||||
StartTransactionCommand();
|
||||
/* functions in indexes may want a snapshot set */
|
||||
@ -2644,11 +2651,13 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
|
||||
|
||||
if (concurrent)
|
||||
{
|
||||
result = ReindexRelationConcurrently(relid, options);
|
||||
(void) ReindexRelationConcurrently(relid, options);
|
||||
/* ReindexRelationConcurrently() does the verbose output */
|
||||
}
|
||||
else
|
||||
{
|
||||
bool result;
|
||||
|
||||
result = reindex_relation(relid,
|
||||
REINDEX_REL_PROCESS_TOAST |
|
||||
REINDEX_REL_CHECK_CONSTRAINTS,
|
||||
@ -2675,13 +2684,19 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
|
||||
* ReindexRelationConcurrently - process REINDEX CONCURRENTLY for given
|
||||
* relation OID
|
||||
*
|
||||
* The relation can be either an index or a table. If it is a table, all its
|
||||
* valid indexes will be rebuilt, including its associated toast table
|
||||
* indexes. If it is an index, this index itself will be rebuilt.
|
||||
* 'relationOid' can either belong to an index, a table or a materialized
|
||||
* view. For tables and materialized views, all its indexes will be rebuilt,
|
||||
* excluding invalid indexes and any indexes used in exclusion constraints,
|
||||
* but including its associated toast table indexes. For indexes, the index
|
||||
* itself will be rebuilt. If 'relationOid' belongs to a partitioned table
|
||||
* then we issue a warning to mention these are not yet supported.
|
||||
*
|
||||
* The locks taken on parent tables and involved indexes are kept until the
|
||||
* transaction is committed, at which point a session lock is taken on each
|
||||
* relation. Both of these protect against concurrent schema changes.
|
||||
*
|
||||
* Returns true if any indexes have been rebuilt (including toast table's
|
||||
* indexes, when relevant), otherwise returns false.
|
||||
*/
|
||||
static bool
|
||||
ReindexRelationConcurrently(Oid relationOid, int options)
|
||||
|
Reference in New Issue
Block a user