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
This commit is contained in:
Sven Klemm 2021-06-04 17:13:55 +02:00 committed by Sven Klemm
parent dae4a904ea
commit 044441e02a
3 changed files with 71 additions and 19 deletions

View File

@ -7,6 +7,7 @@
#define TIMESCALEDB_COMPAT_H
#include <postgres.h>
#include <commands/cluster.h>
#include <commands/explain.h>
#include <commands/trigger.h>
#include <executor/executor.h>
@ -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 <catalog/index.h>
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

View File

@ -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();
}

View File

@ -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,