diff options
author | Michael Paquier <michael@paquier.xyz> | 2020-12-03 10:13:21 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2020-12-03 10:13:21 +0900 |
commit | b5913f6120792465f4394b93c15c2e2ac0c08376 (patch) | |
tree | 2b1f33655d3b7f1888487b87ad467483a5b57cbd /src/backend/commands/cluster.c | |
parent | dc11f31a1a891f8aa8890644e837556bcc5a75e7 (diff) | |
download | postgresql-b5913f6120792465f4394b93c15c2e2ac0c08376.tar.gz postgresql-b5913f6120792465f4394b93c15c2e2ac0c08376.zip |
Refactor CLUSTER and REINDEX grammar to use DefElem for option lists
This changes CLUSTER and REINDEX so as a parenthesized grammar becomes
possible for options, while unifying the grammar parsing rules for
option lists with the existing ones.
This is a follow-up of the work done in 873ea9e for VACUUM, ANALYZE and
EXPLAIN. This benefits REINDEX for a potential backend-side filtering
for collatable-sensitive indexes and TABLESPACE, while CLUSTER would
benefit from the latter.
Author: Alexey Kondratov, Justin Pryzby
Discussion: https://postgr.es/m/8a8f5f73-00d3-55f8-7583-1375ca8f6a91@postgrespro.ru
Diffstat (limited to 'src/backend/commands/cluster.c')
-rw-r--r-- | src/backend/commands/cluster.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 04d12a7ece6..fd5a6eec862 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -35,6 +35,7 @@ #include "catalog/pg_am.h" #include "catalog/toasting.h" #include "commands/cluster.h" +#include "commands/defrem.h" #include "commands/progress.h" #include "commands/tablecmds.h" #include "commands/vacuum.h" @@ -99,8 +100,29 @@ static List *get_tables_to_cluster(MemoryContext cluster_context); *--------------------------------------------------------------------------- */ void -cluster(ClusterStmt *stmt, bool isTopLevel) +cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) { + ListCell *lc; + int options = 0; + bool verbose = false; + + /* Parse option list */ + foreach(lc, stmt->params) + { + DefElem *opt = (DefElem *) lfirst(lc); + + if (strcmp(opt->defname, "verbose") == 0) + verbose = defGetBoolean(opt); + else + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("unrecognized CLUSTER option \"%s\"", + opt->defname), + parser_errposition(pstate, opt->location))); + } + + options = (verbose ? CLUOPT_VERBOSE : 0); + if (stmt->relation != NULL) { /* This is the single-relation case. */ @@ -170,7 +192,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) table_close(rel, NoLock); /* Do the job. */ - cluster_rel(tableOid, indexOid, stmt->options); + cluster_rel(tableOid, indexOid, options); } else { @@ -219,7 +241,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) PushActiveSnapshot(GetTransactionSnapshot()); /* Do the job. */ cluster_rel(rvtc->tableOid, rvtc->indexOid, - stmt->options | CLUOPT_RECHECK); + options | CLUOPT_RECHECK); PopActiveSnapshot(); CommitTransactionCommand(); } |