diff --git a/doc/src/sgml/ref/reindex.sgml b/doc/src/sgml/ref/reindex.sgml
index 998340c5db2..703b7609cfe 100644
--- a/doc/src/sgml/ref/reindex.sgml
+++ b/doc/src/sgml/ref/reindex.sgml
@@ -21,7 +21,7 @@ PostgreSQL documentation
-REINDEX { INDEX | TABLE | SCHEMA | DATABASE | SYSTEM } name
+REINDEX [ ( { VERBOSE } [, ...] ) ] { INDEX | TABLE | SCHEMA | DATABASE | SYSTEM } name
@@ -150,6 +150,15 @@ REINDEX { INDEX | TABLE | SCHEMA | DATABASE | SYSTEM } 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();
}
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 0a6b0690657..33ea387d62f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -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);
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 76b63afe897..25839eed945 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -3856,6 +3856,7 @@ _copyReindexStmt(const ReindexStmt *from)
COPY_SCALAR_FIELD(kind);
COPY_NODE_FIELD(relation);
COPY_STRING_FIELD(name);
+ COPY_SCALAR_FIELD(options);
return newnode;
}
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index e032142b509..c4b3615caf3 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -1935,6 +1935,7 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b)
COMPARE_SCALAR_FIELD(kind);
COMPARE_NODE_FIELD(relation);
COMPARE_STRING_FIELD(name);
+ COMPARE_SCALAR_FIELD(options);
return true;
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index e71d9262caa..2dce87879e7 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -463,6 +463,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
%type explain_option_arg
%type explain_option_elem
%type explain_option_list
+
+%type reindex_target_type reindex_target_multitable
+%type reindex_option_list reindex_option_elem
+
%type copy_generic_opt_arg copy_generic_opt_arg_list_item
%type copy_generic_opt_elem
%type copy_generic_opt_list copy_generic_opt_arg_list
@@ -7387,52 +7391,63 @@ DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_d
*
* QUERY:
*
- * REINDEX type
+ * REINDEX [ (options) ] type
*****************************************************************************/
ReindexStmt:
- REINDEX INDEX qualified_name
+ REINDEX reindex_target_type qualified_name
{
ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_OBJECT_INDEX;
+ n->kind = $2;
n->relation = $3;
n->name = NULL;
+ n->options = 0;
$$ = (Node *)n;
}
- | REINDEX TABLE qualified_name
+ | REINDEX reindex_target_multitable name
{
ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_OBJECT_TABLE;
- n->relation = $3;
+ n->kind = $2;
+ n->name = $3;
+ n->relation = NULL;
+ n->options = 0;
+ $$ = (Node *)n;
+ }
+ | REINDEX '(' reindex_option_list ')' reindex_target_type qualified_name
+ {
+ ReindexStmt *n = makeNode(ReindexStmt);
+ n->kind = $5;
+ n->relation = $6;
n->name = NULL;
+ n->options = $3;
$$ = (Node *)n;
}
- | REINDEX SCHEMA name
+ | REINDEX '(' reindex_option_list ')' reindex_target_multitable name
{
ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_OBJECT_SCHEMA;
- n->name = $3;
- n->relation = NULL;
- $$ = (Node *)n;
- }
- | REINDEX SYSTEM_P name
- {
- ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_OBJECT_SYSTEM;
- n->name = $3;
- n->relation = NULL;
- $$ = (Node *)n;
- }
- | REINDEX DATABASE name
- {
- ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_OBJECT_DATABASE;
- n->name = $3;
+ n->kind = $5;
+ n->name = $6;
n->relation = NULL;
+ n->options = $3;
$$ = (Node *)n;
}
;
-
+reindex_target_type:
+ INDEX { $$ = REINDEX_OBJECT_INDEX; }
+ | TABLE { $$ = REINDEX_OBJECT_TABLE; }
+ ;
+reindex_target_multitable:
+ SCHEMA { $$ = REINDEX_OBJECT_SCHEMA; }
+ | SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
+ | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
+ ;
+reindex_option_list:
+ reindex_option_elem { $$ = $1; }
+ | reindex_option_list ',' reindex_option_elem { $$ = $1 | $3; }
+ ;
+reindex_option_elem:
+ VERBOSE { $$ = REINDEXOPT_VERBOSE; }
+ ;
/*****************************************************************************
*
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 78bfd349a77..a95eff16cc5 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -762,10 +762,10 @@ standard_ProcessUtility(Node *parsetree,
switch (stmt->kind)
{
case REINDEX_OBJECT_INDEX:
- ReindexIndex(stmt->relation);
+ ReindexIndex(stmt->relation, stmt->options);
break;
case REINDEX_OBJECT_TABLE:
- ReindexTable(stmt->relation);
+ ReindexTable(stmt->relation, stmt->options);
break;
case REINDEX_OBJECT_SCHEMA:
case REINDEX_OBJECT_SYSTEM:
@@ -781,7 +781,7 @@ standard_ProcessUtility(Node *parsetree,
(stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
(stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
"REINDEX DATABASE");
- ReindexMultipleTables(stmt->name, stmt->kind);
+ ReindexMultipleTables(stmt->name, stmt->kind, stmt->options);
break;
default:
elog(ERROR, "unrecognized object type: %d",
diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h
index 06f38202a5f..e961d37172c 100644
--- a/src/include/catalog/index.h
+++ b/src/include/catalog/index.h
@@ -115,7 +115,7 @@ extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action);
extern void reindex_index(Oid indexId, bool skip_constraint_checks,
- char relpersistence);
+ char relpersistence, int options);
/* Flag bits for reindex_relation(): */
#define REINDEX_REL_PROCESS_TOAST 0x01
@@ -124,7 +124,7 @@ extern void reindex_index(Oid indexId, bool skip_constraint_checks,
#define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
#define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
-extern bool reindex_relation(Oid relid, int flags);
+extern bool reindex_relation(Oid relid, int flags, int options);
extern bool ReindexIsProcessingHeap(Oid heapOid);
extern bool ReindexIsProcessingIndex(Oid indexOid);
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index c3a1748e00f..d6257250cbe 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -29,9 +29,10 @@ extern ObjectAddress DefineIndex(Oid relationId,
bool check_rights,
bool skip_build,
bool quiet);
-extern Oid ReindexIndex(RangeVar *indexRelation);
-extern Oid ReindexTable(RangeVar *relation);
-extern void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind);
+extern Oid ReindexIndex(RangeVar *indexRelation, int options);
+extern Oid ReindexTable(RangeVar *relation, int options);
+extern void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
+ int options);
extern char *makeObjectName(const char *name1, const char *name2,
const char *label);
extern char *ChooseRelationName(const char *name1, const char *name2,
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 556c1c5d9da..053f1b01213 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -2782,6 +2782,10 @@ typedef struct ConstraintsSetStmt
* REINDEX Statement
* ----------------------
*/
+
+/* Reindex options */
+#define REINDEXOPT_VERBOSE 1 << 0 /* print progress info */
+
typedef enum ReindexObjectType
{
REINDEX_OBJECT_INDEX, /* index */
@@ -2797,6 +2801,7 @@ typedef struct ReindexStmt
ReindexObjectType kind; /* REINDEX_OBJECT_INDEX, REINDEX_OBJECT_TABLE, etc. */
RangeVar *relation; /* Table or index to reindex */
const char *name; /* name of database to reindex */
+ int options; /* Reindex options flags */
} ReindexStmt;
/* ----------------------
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index abe64e597c7..a98b10520d5 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2831,6 +2831,14 @@ explain (costs off)
Index Cond: ((thousand = 1) AND (tenthous = 1001))
(2 rows)
+--
+-- REINDEX (VERBOSE)
+--
+CREATE TABLE reindex_verbose(id integer primary key);
+\set VERBOSITY terse
+REINDEX (VERBOSE) TABLE reindex_verbose;
+INFO: index "reindex_verbose_pkey" was reindexed
+DROP TABLE reindex_verbose;
--
-- REINDEX SCHEMA
--
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index f779fa0de17..6333a30bf6d 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -965,6 +965,14 @@ RESET enable_indexscan;
explain (costs off)
select * from tenk1 where (thousand, tenthous) in ((1,1001), (null,null));
+--
+-- REINDEX (VERBOSE)
+--
+CREATE TABLE reindex_verbose(id integer primary key);
+\set VERBOSITY terse
+REINDEX (VERBOSE) TABLE reindex_verbose;
+DROP TABLE reindex_verbose;
+
--
-- REINDEX SCHEMA
--