From 044441e02a3a95b5630584991f6ff656f8f74f59 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Fri, 4 Jun 2021 17:13:55 +0200 Subject: [PATCH] Adjust code to CLUSTER and REINDEX refactoring PG14 refactors CLUSTER and REINDEX option handling. https://github.com/postgres/postgres/commit/b5913f6120 https://github.com/postgres/postgres/commit/a3dc926009 --- src/compat/compat.h | 64 +++++++++++++++++++++++++++++++++++++++++++ src/process_utility.c | 23 +++++----------- tsl/src/reorder.c | 3 -- 3 files changed, 71 insertions(+), 19 deletions(-) diff --git a/src/compat/compat.h b/src/compat/compat.h index fc06d6a59..f37c0c530 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -7,6 +7,7 @@ #define TIMESCALEDB_COMPAT_H #include +#include #include #include #include @@ -206,6 +207,69 @@ get_vacuum_options(const VacuumStmt *stmt) (analyze ? VACOPT_ANALYZE : 0); } +#if PG14_LT +static inline int +get_cluster_options(const ClusterStmt *stmt) +{ + return stmt->options; +} +#else +static inline ClusterParams * +get_cluster_options(const ClusterStmt *stmt) +{ + ListCell *lc; + ClusterParams *params = palloc0(sizeof(ClusterParams)); + 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(NULL, opt->location))); + } + + params->options = (verbose ? CLUOPT_VERBOSE : 0); + + return params; +} +#endif + +#include + +static inline int +get_reindex_options(ReindexStmt *stmt) +{ +#if PG14_LT + return stmt->options; +#else + ListCell *lc; + bool concurrently = false; + 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 if (strcmp(opt->defname, "concurrently") == 0) + concurrently = defGetBoolean(opt); + else + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("unrecognized REINDEX option \"%s\"", opt->defname), + parser_errposition(NULL, opt->location))); + } + return (verbose ? REINDEXOPT_VERBOSE : 0) | (concurrently ? REINDEXOPT_CONCURRENTLY : 0); +#endif +} + /* PG14 splits Copy code into separate code for COPY FROM and COPY TO * since we were only interested in the COPY FROM parts we macro CopyFromState * to CopyState for versions < 14 diff --git a/src/process_utility.c b/src/process_utility.c index be7b41026..a0683a38d 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -1488,16 +1488,14 @@ reindex_chunk(Hypertable *ht, Oid chunk_relid, void *arg) case REINDEX_OBJECT_TABLE: stmt->relation->relname = NameStr(chunk->fd.table_name); stmt->relation->schemaname = NameStr(chunk->fd.schema_name); - ReindexTable(stmt->relation, - stmt->options #if PG14_LT - , + ReindexTable(stmt->relation, + get_reindex_options(stmt), stmt->concurrent /* should test for deadlocks */ -#elif PG14_GE - , - false /* isTopLevel */ -#endif ); +#elif PG14_GE + ExecReindex(NULL, stmt, false); +#endif break; case REINDEX_OBJECT_INDEX: /* Not supported, a.t.m. See note in process_reindex(). */ @@ -1543,7 +1541,7 @@ process_reindex(ProcessUtilityArgs *args) #if PG14_LT if (stmt->concurrent) #else - if (stmt->options & REINDEXOPT_CONCURRENTLY) + if (get_reindex_options(stmt) & REINDEXOPT_CONCURRENTLY) #endif ereport(ERROR, (errmsg("concurrent index creation on hypertables is not supported"))); @@ -2645,14 +2643,7 @@ process_cluster_start(ProcessUtilityArgs *args) * Since we keep OIDs between transactions, there is a potential * issue if an OID gets reassigned between two subtransactions */ - cluster_rel(cim->chunkoid, - cim->indexoid, - stmt->options -#if PG14_GE - , - args->context == PROCESS_UTILITY_TOPLEVEL -#endif - ); + cluster_rel(cim->chunkoid, cim->indexoid, get_cluster_options(stmt)); PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/tsl/src/reorder.c b/tsl/src/reorder.c index 5f12dd6b7..2bfc27aae 100644 --- a/tsl/src/reorder.c +++ b/tsl/src/reorder.c @@ -717,9 +717,6 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose, 0, 0, 0, -#if PG14_GE - true, -#endif &OldestXmin, &FreezeXid, NULL,