Now compiles for 11 & 12, but 12 crashes on missing symbol we're supposed to get from ruleutils

read_write_etc
Philip Dubé 2019-07-12 19:22:28 +00:00
parent 86b30ee094
commit 44fa6cc2db
57 changed files with 11798 additions and 152 deletions

1
.gitattributes vendored
View File

@ -28,4 +28,5 @@ configure -whitespace
src/backend/distributed/utils/citus_outfuncs.c -citus-style src/backend/distributed/utils/citus_outfuncs.c -citus-style
src/backend/distributed/utils/ruleutils_10.c -citus-style src/backend/distributed/utils/ruleutils_10.c -citus-style
src/backend/distributed/utils/ruleutils_11.c -citus-style src/backend/distributed/utils/ruleutils_11.c -citus-style
src/backend/distributed/utils/ruleutils_12.c -citus-style
src/include/distributed/citus_nodes.h -citus-style src/include/distributed/citus_nodes.h -citus-style

2
configure vendored
View File

@ -2531,7 +2531,7 @@ if test -z "$version_num"; then
as_fn_error $? "Could not detect PostgreSQL version from pg_config." "$LINENO" 5 as_fn_error $? "Could not detect PostgreSQL version from pg_config." "$LINENO" 5
fi fi
if test "$version_num" != '10' -a "$version_num" != '11'; then if test "$version_num" != '10' -a "$version_num" != '11' -a "$version_num" != '12'; then
as_fn_error $? "Citus is not compatible with the detected PostgreSQL version ${version_num}." "$LINENO" 5 as_fn_error $? "Citus is not compatible with the detected PostgreSQL version ${version_num}." "$LINENO" 5
else else
{ $as_echo "$as_me:${as_lineno-$LINENO}: building against PostgreSQL $version_num" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: building against PostgreSQL $version_num" >&5

View File

@ -74,7 +74,7 @@ if test -z "$version_num"; then
AC_MSG_ERROR([Could not detect PostgreSQL version from pg_config.]) AC_MSG_ERROR([Could not detect PostgreSQL version from pg_config.])
fi fi
if test "$version_num" != '10' -a "$version_num" != '11'; then if test "$version_num" != '10' -a "$version_num" != '11' -a "$version_num" != '12'; then
AC_MSG_ERROR([Citus is not compatible with the detected PostgreSQL version ${version_num}.]) AC_MSG_ERROR([Citus is not compatible with the detected PostgreSQL version ${version_num}.])
else else
AC_MSG_NOTICE([building against PostgreSQL $version_num]) AC_MSG_NOTICE([building against PostgreSQL $version_num])

View File

@ -645,6 +645,8 @@ EnsureRelationCanBeDistributed(Oid relationId, Var *distributionColumn,
relationDesc = RelationGetDescr(relation); relationDesc = RelationGetDescr(relation);
relationName = RelationGetRelationName(relation); relationName = RelationGetRelationName(relation);
#if PG_VERSION_NUM < 120000
/* verify target relation does not use WITH (OIDS) PostgreSQL feature */ /* verify target relation does not use WITH (OIDS) PostgreSQL feature */
if (relationDesc->tdhasoid) if (relationDesc->tdhasoid)
{ {
@ -653,6 +655,7 @@ EnsureRelationCanBeDistributed(Oid relationId, Var *distributionColumn,
errdetail("Distributed relations must not specify the WITH " errdetail("Distributed relations must not specify the WITH "
"(OIDS) option in their definitions."))); "(OIDS) option in their definitions.")));
} }
#endif
/* verify target relation does not use identity columns */ /* verify target relation does not use identity columns */
if (RelationUsesIdentityColumns(relationDesc)) if (RelationUsesIdentityColumns(relationDesc))
@ -1196,7 +1199,11 @@ CopyLocalDataIntoShards(Oid distributedRelationId)
bool stopOnFailure = true; bool stopOnFailure = true;
EState *estate = NULL; EState *estate = NULL;
#if PG_VERSION_NUM >= 120000
TableScanDesc scan = NULL;
#else
HeapScanDesc scan = NULL; HeapScanDesc scan = NULL;
#endif
HeapTuple tuple = NULL; HeapTuple tuple = NULL;
ExprContext *econtext = NULL; ExprContext *econtext = NULL;
MemoryContext oldContext = NULL; MemoryContext oldContext = NULL;
@ -1230,7 +1237,7 @@ CopyLocalDataIntoShards(Oid distributedRelationId)
/* get the table columns */ /* get the table columns */
tupleDescriptor = RelationGetDescr(distributedRelation); tupleDescriptor = RelationGetDescr(distributedRelation);
slot = MakeSingleTupleTableSlot(tupleDescriptor); slot = MakeSingleTupleTableSlotCompat(tupleDescriptor);
columnNameList = TupleDescColumnNameList(tupleDescriptor); columnNameList = TupleDescColumnNameList(tupleDescriptor);
/* determine the partition column in the tuple descriptor */ /* determine the partition column in the tuple descriptor */
@ -1256,7 +1263,11 @@ CopyLocalDataIntoShards(Oid distributedRelationId)
copyDest->rStartup(copyDest, 0, tupleDescriptor); copyDest->rStartup(copyDest, 0, tupleDescriptor);
/* begin reading from local table */ /* begin reading from local table */
#if PG_VERSION_NUM >= 120000
scan = table_beginscan(distributedRelation, GetActiveSnapshot(), 0, NULL);
#else
scan = heap_beginscan(distributedRelation, GetActiveSnapshot(), 0, NULL); scan = heap_beginscan(distributedRelation, GetActiveSnapshot(), 0, NULL);
#endif
oldContext = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); oldContext = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
@ -1293,7 +1304,11 @@ CopyLocalDataIntoShards(Oid distributedRelationId)
MemoryContextSwitchTo(oldContext); MemoryContextSwitchTo(oldContext);
/* finish reading from the local table */ /* finish reading from the local table */
#if PG_VERSION_NUM >= 120000
table_endscan(scan);
#else
heap_endscan(scan); heap_endscan(scan);
#endif
/* finish writing into the shards */ /* finish writing into the shards */
copyDest->rShutdown(copyDest); copyDest->rShutdown(copyDest);

View File

@ -15,6 +15,9 @@
#include "access/htup_details.h" #include "access/htup_details.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/pg_constraint.h" #include "catalog/pg_constraint.h"
#if (PG_VERSION_NUM >= 120000)
#include "access/genam.h"
#endif
#if (PG_VERSION_NUM < 110000) #if (PG_VERSION_NUM < 110000)
#include "catalog/pg_constraint_fn.h" #include "catalog/pg_constraint_fn.h"
#endif #endif

View File

@ -10,6 +10,9 @@
#include "postgres.h" #include "postgres.h"
#if PG_VERSION_NUM > 12000
#include "access/genam.h"
#endif
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/xact.h" #include "access/xact.h"
#include "catalog/catalog.h" #include "catalog/catalog.h"

View File

@ -463,7 +463,7 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
columnNulls = palloc0(columnCount * sizeof(bool)); columnNulls = palloc0(columnCount * sizeof(bool));
/* set up a virtual tuple table slot */ /* set up a virtual tuple table slot */
tupleTableSlot = MakeSingleTupleTableSlot(tupleDescriptor); tupleTableSlot = MakeSingleTupleTableSlotCompat(tupleDescriptor);
tupleTableSlot->tts_nvalid = columnCount; tupleTableSlot->tts_nvalid = columnCount;
tupleTableSlot->tts_values = columnValues; tupleTableSlot->tts_values = columnValues;
tupleTableSlot->tts_isnull = columnNulls; tupleTableSlot->tts_isnull = columnNulls;
@ -561,8 +561,8 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
oldContext = MemoryContextSwitchTo(executorTupleContext); oldContext = MemoryContextSwitchTo(executorTupleContext);
/* parse a row from the input */ /* parse a row from the input */
nextRowFound = NextCopyFrom(copyState, executorExpressionContext, nextRowFound = NextCopyFromCompat(copyState, executorExpressionContext,
columnValues, columnNulls, NULL); columnValues, columnNulls);
if (!nextRowFound) if (!nextRowFound)
{ {
@ -681,8 +681,8 @@ CopyToNewShards(CopyStmt *copyStatement, char *completionTag, Oid relationId)
oldContext = MemoryContextSwitchTo(executorTupleContext); oldContext = MemoryContextSwitchTo(executorTupleContext);
/* parse a row from the input */ /* parse a row from the input */
nextRowFound = NextCopyFrom(copyState, executorExpressionContext, nextRowFound = NextCopyFromCompat(copyState, executorExpressionContext,
columnValues, columnNulls, NULL); columnValues, columnNulls);
if (!nextRowFound) if (!nextRowFound)
{ {

View File

@ -10,6 +10,9 @@
#include "postgres.h" #include "postgres.h"
#if PG_VERSION_NUM >= 120000
#include "access/genam.h"
#endif
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/xact.h" #include "access/xact.h"
#include "catalog/index.h" #include "catalog/index.h"

View File

@ -46,6 +46,7 @@ RedirectCopyDataToRegularFile(const char *filename)
File fileDesc = -1; File fileDesc = -1;
const int fileFlags = (O_APPEND | O_CREAT | O_RDWR | O_TRUNC | PG_BINARY); const int fileFlags = (O_APPEND | O_CREAT | O_RDWR | O_TRUNC | PG_BINARY);
const int fileMode = (S_IRUSR | S_IWUSR); const int fileMode = (S_IRUSR | S_IWUSR);
off_t offset = 0;
fileDesc = FileOpenForTransmit(filename, fileFlags, fileMode); fileDesc = FileOpenForTransmit(filename, fileFlags, fileMode);
@ -57,14 +58,16 @@ RedirectCopyDataToRegularFile(const char *filename)
/* if received data has contents, append to regular file */ /* if received data has contents, append to regular file */
if (copyData->len > 0) if (copyData->len > 0)
{ {
int appended = FileWrite(fileDesc, copyData->data, copyData->len, int appended = FileWriteCompat(fileDesc, copyData->data, copyData->len,
PG_WAIT_IO); offset, PG_WAIT_IO);
if (appended != copyData->len) if (appended != copyData->len)
{ {
ereport(ERROR, (errcode_for_file_access(), ereport(ERROR, (errcode_for_file_access(),
errmsg("could not append to received file: %m"))); errmsg("could not append to received file: %m")));
} }
offset += appended;
} }
resetStringInfo(copyData); resetStringInfo(copyData);
@ -90,6 +93,7 @@ SendRegularFile(const char *filename)
const uint32 fileBufferSize = 32768; /* 32 KB */ const uint32 fileBufferSize = 32768; /* 32 KB */
const int fileFlags = (O_RDONLY | PG_BINARY); const int fileFlags = (O_RDONLY | PG_BINARY);
const int fileMode = 0; const int fileMode = 0;
off_t offset = 0;
/* we currently do not check if the caller has permissions for this file */ /* we currently do not check if the caller has permissions for this file */
fileDesc = FileOpenForTransmit(filename, fileFlags, fileMode); fileDesc = FileOpenForTransmit(filename, fileFlags, fileMode);
@ -103,7 +107,8 @@ SendRegularFile(const char *filename)
SendCopyOutStart(); SendCopyOutStart();
readBytes = FileRead(fileDesc, fileBuffer->data, fileBufferSize, PG_WAIT_IO); readBytes = FileReadCompat(fileDesc, fileBuffer->data, fileBufferSize, offset,
PG_WAIT_IO);
while (readBytes > 0) while (readBytes > 0)
{ {
fileBuffer->len = readBytes; fileBuffer->len = readBytes;
@ -111,8 +116,9 @@ SendRegularFile(const char *filename)
SendCopyData(fileBuffer); SendCopyData(fileBuffer);
resetStringInfo(fileBuffer); resetStringInfo(fileBuffer);
readBytes = FileRead(fileDesc, fileBuffer->data, fileBufferSize, readBytes = FileReadCompat(fileDesc, fileBuffer->data, fileBufferSize,
PG_WAIT_IO); offset, PG_WAIT_IO);
offset += readBytes;
} }
SendCopyDone(); SendCopyDone();

View File

@ -22,9 +22,162 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#if PG_VERSION_NUM >= 120000
#include "commands/vacuum.h"
#include "commands/defrem.h"
/*
* This is mostly ExecVacuum from Postgres's commands/vacuum.c
*/
/*
* A wrapper function of defGetBoolean().
*
* This function returns VACOPT_TERNARY_ENABLED and VACOPT_TERNARY_DISABLED
* instead of true and false.
*/
static VacOptTernaryValue
get_vacopt_ternary_value(DefElem *def)
{
return defGetBoolean(def) ? VACOPT_TERNARY_ENABLED : VACOPT_TERNARY_DISABLED;
}
static int
VacuumStmt_options(VacuumStmt *vacstmt)
{
VacuumParams params;
bool verbose = false;
bool skip_locked = false;
bool analyze = false;
bool freeze = false;
bool full = false;
bool disable_page_skipping = false;
ListCell *lc;
/* Set default value */
params.index_cleanup = VACOPT_TERNARY_DEFAULT;
params.truncate = VACOPT_TERNARY_DEFAULT;
/* Parse options list */
foreach(lc, vacstmt->options)
{
DefElem *opt = (DefElem *) lfirst(lc);
/* Parse common options for VACUUM and ANALYZE */
if (strcmp(opt->defname, "verbose") == 0)
{
verbose = defGetBoolean(opt);
}
else if (strcmp(opt->defname, "skip_locked") == 0)
{
skip_locked = defGetBoolean(opt);
}
/* Parse options available on VACUUM */
else if (strcmp(opt->defname, "analyze") == 0)
{
analyze = defGetBoolean(opt);
}
else if (strcmp(opt->defname, "freeze") == 0)
{
freeze = defGetBoolean(opt);
}
else if (strcmp(opt->defname, "full") == 0)
{
full = defGetBoolean(opt);
}
else if (strcmp(opt->defname, "disable_page_skipping") == 0)
{
disable_page_skipping = defGetBoolean(opt);
}
else if (strcmp(opt->defname, "index_cleanup") == 0)
{
params.index_cleanup = get_vacopt_ternary_value(opt);
}
else if (strcmp(opt->defname, "truncate") == 0)
{
params.truncate = get_vacopt_ternary_value(opt);
}
}
/* Set vacuum options */
params.options =
(vacstmt->is_vacuumcmd ? VACOPT_VACUUM : VACOPT_ANALYZE) |
(verbose ? VACOPT_VERBOSE : 0) |
(skip_locked ? VACOPT_SKIP_LOCKED : 0) |
(analyze ? VACOPT_ANALYZE : 0) |
(freeze ? VACOPT_FREEZE : 0) |
(full ? VACOPT_FULL : 0) |
(disable_page_skipping ? VACOPT_DISABLE_PAGE_SKIPPING : 0);
/* sanity checks on options */
Assert(params.options & (VACOPT_VACUUM | VACOPT_ANALYZE));
Assert((params.options & VACOPT_VACUUM) ||
!(params.options & (VACOPT_FULL | VACOPT_FREEZE)));
Assert(!(params.options & VACOPT_SKIPTOAST));
/*
* Make sure VACOPT_ANALYZE is specified if any column lists are present.
*/
if (!(params.options & VACOPT_ANALYZE))
{
foreach(lc, vacstmt->rels)
{
VacuumRelation *vrel = lfirst_node(VacuumRelation, lc);
if (vrel->va_cols != NIL)
{
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg(
"ANALYZE option must be specified when a column list is provided")));
}
}
}
/*
* All freeze ages are zero if the FREEZE option is given; otherwise pass
* them as -1 which means to use the default values.
*/
if (params.options & VACOPT_FREEZE)
{
params.freeze_min_age = 0;
params.freeze_table_age = 0;
params.multixact_freeze_min_age = 0;
params.multixact_freeze_table_age = 0;
}
else
{
params.freeze_min_age = -1;
params.freeze_table_age = -1;
params.multixact_freeze_min_age = -1;
params.multixact_freeze_table_age = -1;
}
/* user-invoked vacuum is never "for wraparound" */
params.is_wraparound = false;
/* user-invoked vacuum never uses this parameter */
params.log_min_duration = -1;
return params.options;
}
#else
static int
VacuumStmt_options(VacuumStmt *vacuumStmt)
{
return vacuumStmt->options;
}
#endif
/* Local functions forward declarations for processing distributed table commands */ /* Local functions forward declarations for processing distributed table commands */
static bool IsDistributedVacuumStmt(VacuumStmt *vacuumStmt, List *vacuumRelationIdList); static bool IsDistributedVacuumStmt(int vacuumOptions, List *vacuumRelationIdList);
static List * VacuumTaskList(Oid relationId, int vacuumOptions, List *vacuumColumnList); static List * VacuumTaskList(Oid relationId, int vacuumOptions, List *vacuumColumnList);
static StringInfo DeparseVacuumStmtPrefix(int vacuumFlags); static StringInfo DeparseVacuumStmtPrefix(int vacuumFlags);
static char * DeparseVacuumColumnNames(List *columnNameList); static char * DeparseVacuumColumnNames(List *columnNameList);
@ -49,7 +202,8 @@ ProcessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand)
ListCell *vacuumRelationCell = NULL; ListCell *vacuumRelationCell = NULL;
List *relationIdList = NIL; List *relationIdList = NIL;
ListCell *relationIdCell = NULL; ListCell *relationIdCell = NULL;
LOCKMODE lockMode = (vacuumStmt->options & VACOPT_FULL) ? AccessExclusiveLock : int vacuumOptions = VacuumStmt_options(vacuumStmt);
LOCKMODE lockMode = (vacuumOptions & VACOPT_FULL) ? AccessExclusiveLock :
ShareUpdateExclusiveLock; ShareUpdateExclusiveLock;
int executedVacuumCount = 0; int executedVacuumCount = 0;
@ -60,7 +214,7 @@ ProcessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand)
relationIdList = lappend_oid(relationIdList, relationId); relationIdList = lappend_oid(relationIdList, relationId);
} }
distributedVacuumStmt = IsDistributedVacuumStmt(vacuumStmt, relationIdList); distributedVacuumStmt = IsDistributedVacuumStmt(vacuumOptions, relationIdList);
if (!distributedVacuumStmt) if (!distributedVacuumStmt)
{ {
return; return;
@ -82,7 +236,7 @@ ProcessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand)
* commands can run inside a transaction block. Notice that we do this * commands can run inside a transaction block. Notice that we do this
* once even if there are multiple distributed tables to be vacuumed. * once even if there are multiple distributed tables to be vacuumed.
*/ */
if (executedVacuumCount == 0 && (vacuumStmt->options & VACOPT_VACUUM) != 0) if (executedVacuumCount == 0 && (vacuumOptions & VACOPT_VACUUM) != 0)
{ {
/* save old commit protocol to restore at xact end */ /* save old commit protocol to restore at xact end */
Assert(SavedMultiShardCommitProtocol == COMMIT_PROTOCOL_BARE); Assert(SavedMultiShardCommitProtocol == COMMIT_PROTOCOL_BARE);
@ -91,7 +245,7 @@ ProcessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand)
} }
vacuumColumnList = VacuumColumnList(vacuumStmt, relationIndex); vacuumColumnList = VacuumColumnList(vacuumStmt, relationIndex);
taskList = VacuumTaskList(relationId, vacuumStmt->options, vacuumColumnList); taskList = VacuumTaskList(relationId, vacuumOptions, vacuumColumnList);
/* use adaptive executor when enabled */ /* use adaptive executor when enabled */
ExecuteUtilityTaskListWithoutResults(taskList, targetPoolSize, false); ExecuteUtilityTaskListWithoutResults(taskList, targetPoolSize, false);
@ -111,9 +265,9 @@ ProcessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand)
* false otherwise. * false otherwise.
*/ */
static bool static bool
IsDistributedVacuumStmt(VacuumStmt *vacuumStmt, List *vacuumRelationIdList) IsDistributedVacuumStmt(int vacuumOptions, List *vacuumRelationIdList)
{ {
const char *stmtName = (vacuumStmt->options & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE"; const char *stmtName = (vacuumOptions & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE";
bool distributeStmt = false; bool distributeStmt = false;
ListCell *relationIdCell = NULL; ListCell *relationIdCell = NULL;
int distributedRelationCount = 0; int distributedRelationCount = 0;

View File

@ -27,6 +27,7 @@
#include "distributed/remote_commands.h" #include "distributed/remote_commands.h"
#include "distributed/transmit.h" #include "distributed/transmit.h"
#include "distributed/transaction_identifier.h" #include "distributed/transaction_identifier.h"
#include "distributed/version_compat.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -413,7 +414,8 @@ RemoteFileDestReceiverReceive(TupleTableSlot *slot, DestReceiver *dest)
static void static void
WriteToLocalFile(StringInfo copyData, File fileDesc) WriteToLocalFile(StringInfo copyData, File fileDesc)
{ {
int bytesWritten = FileWrite(fileDesc, copyData->data, copyData->len, PG_WAIT_IO); int bytesWritten = FileWriteCompat(fileDesc, copyData->data, copyData->len, 0,
PG_WAIT_IO);
if (bytesWritten < 0) if (bytesWritten < 0)
{ {
ereport(ERROR, (errcode_for_file_access(), ereport(ERROR, (errcode_for_file_access(),

View File

@ -138,7 +138,9 @@ CitusExecutorRun(QueryDesc *queryDesc,
EState *estate = queryDesc->estate; EState *estate = queryDesc->estate;
estate->es_processed = 0; estate->es_processed = 0;
#if PG_VERSION_NUM < 120000
estate->es_lastoid = InvalidOid; estate->es_lastoid = InvalidOid;
#endif
/* start and shutdown tuple receiver to simulate empty result */ /* start and shutdown tuple receiver to simulate empty result */
dest->rStartup(queryDesc->dest, CMD_SELECT, queryDesc->tupDesc); dest->rStartup(queryDesc->dest, CMD_SELECT, queryDesc->tupDesc);
@ -351,8 +353,8 @@ ReadFileIntoTupleStore(char *fileName, char *copyFormat, TupleDesc tupleDescript
ResetPerTupleExprContext(executorState); ResetPerTupleExprContext(executorState);
oldContext = MemoryContextSwitchTo(executorTupleContext); oldContext = MemoryContextSwitchTo(executorTupleContext);
nextRowFound = NextCopyFrom(copyState, executorExpressionContext, nextRowFound = NextCopyFromCompat(copyState, executorExpressionContext,
columnValues, columnNulls, NULL); columnValues, columnNulls);
if (!nextRowFound) if (!nextRowFound)
{ {
MemoryContextSwitchTo(oldContext); MemoryContextSwitchTo(oldContext);

View File

@ -704,7 +704,7 @@ SortTupleStore(CitusScanState *scanState)
/* iterate over all the sorted tuples, add them to original tuplestore */ /* iterate over all the sorted tuples, add them to original tuplestore */
while (true) while (true)
{ {
TupleTableSlot *newSlot = MakeSingleTupleTableSlot(tupleDescriptor); TupleTableSlot *newSlot = MakeSingleTupleTableSlotCompat(tupleDescriptor);
bool found = tuplesort_gettupleslot(tuplesortstate, true, false, newSlot, NULL); bool found = tuplesort_gettupleslot(tuplesortstate, true, false, newSlot, NULL);
if (!found) if (!found)

View File

@ -42,13 +42,16 @@
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#if PG_VERSION_NUM >= 120000
#include "nodes/nodeFuncs.h"
#endif
#include "nodes/nodes.h" #include "nodes/nodes.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "nodes/primnodes.h" #include "nodes/primnodes.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/predtest.h" #include "compat/optimizer/predtest.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"
#include "storage/lock.h" #include "storage/lock.h"
#include "storage/lmgr.h" #include "storage/lmgr.h"

View File

@ -15,6 +15,9 @@
#include "libpq-fe.h" #include "libpq-fe.h"
#include "miscadmin.h" #include "miscadmin.h"
#if PG_VERSION_NUM >= 120000
#include "access/genam.h"
#endif
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/sysattr.h" #include "access/sysattr.h"
#include "access/xact.h" #include "access/xact.h"
@ -53,7 +56,6 @@
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/tqual.h"
/* Local functions forward declarations */ /* Local functions forward declarations */

View File

@ -47,9 +47,9 @@
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/predtest.h" #include "compat/optimizer/predtest.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
#include "utils/builtins.h" #include "utils/builtins.h"

View File

@ -60,7 +60,6 @@
#include "utils/palloc.h" #include "utils/palloc.h"
#include "utils/relcache.h" #include "utils/relcache.h"
#include "utils/ruleutils.h" #include "utils/ruleutils.h"
#include "utils/tqual.h"
#include "utils/varlena.h" #include "utils/varlena.h"
@ -472,7 +471,6 @@ master_get_active_worker_nodes(PG_FUNCTION_ARGS)
MemoryContext oldContext = NULL; MemoryContext oldContext = NULL;
List *workerNodeList = NIL; List *workerNodeList = NIL;
TupleDesc tupleDescriptor = NULL; TupleDesc tupleDescriptor = NULL;
bool hasOid = false;
/* create a function context for cross-call persistence */ /* create a function context for cross-call persistence */
functionContext = SRF_FIRSTCALL_INIT(); functionContext = SRF_FIRSTCALL_INIT();
@ -490,7 +488,11 @@ master_get_active_worker_nodes(PG_FUNCTION_ARGS)
* This tuple descriptor must match the output parameters declared for * This tuple descriptor must match the output parameters declared for
* the function in pg_proc. * the function in pg_proc.
*/ */
tupleDescriptor = CreateTemplateTupleDesc(WORKER_NODE_FIELDS, hasOid); #if PG_VERSION_NUM < 120000
tupleDescriptor = CreateTemplateTupleDesc(WORKER_NODE_FIELDS, false);
#else
tupleDescriptor = CreateTemplateTupleDesc(WORKER_NODE_FIELDS);
#endif
TupleDescInitEntry(tupleDescriptor, (AttrNumber) 1, "node_name", TupleDescInitEntry(tupleDescriptor, (AttrNumber) 1, "node_name",
TEXTOID, -1, 0); TEXTOID, -1, 0);
TupleDescInitEntry(tupleDescriptor, (AttrNumber) 2, "node_port", TupleDescInitEntry(tupleDescriptor, (AttrNumber) 2, "node_port",

View File

@ -55,7 +55,6 @@
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/tqual.h"
/* Local functions forward declarations */ /* Local functions forward declarations */

View File

@ -48,7 +48,6 @@
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/tqual.h"
static char * LocalGroupIdUpdateCommand(int32 groupId); static char * LocalGroupIdUpdateCommand(int32 groupId);

View File

@ -35,7 +35,11 @@
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
#include "parser/parse_type.h" #include "parser/parse_type.h"
#if PG_VERSION_NUM >= 120000
#include "optimizer/optimizer.h"
#else
#include "optimizer/cost.h" #include "optimizer/cost.h"
#endif
#include "optimizer/pathnode.h" #include "optimizer/pathnode.h"
#include "optimizer/planner.h" #include "optimizer/planner.h"
#include "utils/builtins.h" #include "utils/builtins.h"

View File

@ -14,7 +14,7 @@
#include "distributed/metadata_cache.h" #include "distributed/metadata_cache.h"
#include "distributed/multi_logical_optimizer.h" #include "distributed/multi_logical_optimizer.h"
#include "distributed/pg_dist_partition.h" #include "distributed/pg_dist_partition.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"

View File

@ -26,6 +26,7 @@
#include "distributed/query_pushdown_planning.h" #include "distributed/query_pushdown_planning.h"
#include "distributed/recursive_planning.h" #include "distributed/recursive_planning.h"
#include "distributed/resource_lock.h" #include "distributed/resource_lock.h"
#include "distributed/version_compat.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -33,7 +34,7 @@
#include "optimizer/planner.h" #include "optimizer/planner.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h" #include "optimizer/tlist.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
#include "parser/parse_coerce.h" #include "parser/parse_coerce.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"

View File

@ -24,7 +24,7 @@
#include "distributed/pg_dist_partition.h" #include "distributed/pg_dist_partition.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/datum.h" #include "utils/datum.h"

View File

@ -35,12 +35,13 @@
#include "distributed/multi_physical_planner.h" #include "distributed/multi_physical_planner.h"
#include "distributed/pg_dist_partition.h" #include "distributed/pg_dist_partition.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "distributed/version_compat.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "nodes/print.h" #include "nodes/print.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/tlist.h" #include "optimizer/tlist.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "parser/parse_agg.h" #include "parser/parse_agg.h"
#include "parser/parse_coerce.h" #include "parser/parse_coerce.h"
#include "parser/parse_oper.h" #include "parser/parse_oper.h"
@ -49,7 +50,6 @@
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/tqual.h"
/* Config variable managed via guc.c */ /* Config variable managed via guc.c */
@ -2962,7 +2962,11 @@ AggregateFunctionOid(const char *functionName, Oid inputType)
/* check if input type and found value type match */ /* check if input type and found value type match */
if (procForm->proargtypes.values[0] == inputType) if (procForm->proargtypes.values[0] == inputType)
{ {
#if PG_VERSION_NUM < 120000
functionOid = HeapTupleGetOid(heapTuple); functionOid = HeapTupleGetOid(heapTuple);
#else
functionOid = procForm->oid;
#endif
break; break;
} }
} }
@ -2992,8 +2996,9 @@ TypeOid(Oid schemaId, const char *typeName)
{ {
Oid typeOid; Oid typeOid;
typeOid = GetSysCacheOid2(TYPENAMENSP, PointerGetDatum(typeName), typeOid = GetSysCacheOid2Compat(TYPENAMENSP, Anum_pg_type_oid, PointerGetDatum(
ObjectIdGetDatum(schemaId)); typeName),
ObjectIdGetDatum(schemaId));
return typeOid; return typeOid;
} }

View File

@ -33,11 +33,11 @@
#include "distributed/version_compat.h" #include "distributed/version_compat.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "optimizer/tlist.h" #include "optimizer/tlist.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
#include "utils/datum.h" #include "utils/datum.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"

View File

@ -21,6 +21,7 @@
#include "distributed/multi_physical_planner.h" #include "distributed/multi_physical_planner.h"
#include "distributed/distributed_planner.h" #include "distributed/distributed_planner.h"
#include "distributed/multi_server_executor.h" #include "distributed/multi_server_executor.h"
#include "distributed/version_compat.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
@ -29,7 +30,7 @@
#include "optimizer/cost.h" #include "optimizer/cost.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
#include "optimizer/tlist.h" #include "optimizer/tlist.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/guc.h" #include "utils/guc.h"
#include "utils/memutils.h" #include "utils/memutils.h"
@ -356,10 +357,12 @@ BuildAggregatePlan(Query *masterQuery, Plan *subPlan)
} }
/* finally create the plan */ /* finally create the plan */
aggregatePlan = make_agg(aggregateTargetList, (List *) havingQual, aggregateStrategy, /* TODO no nulls */
AGGSPLIT_SIMPLE, groupColumnCount, groupColumnIdArray, aggregatePlan = make_aggCompat(aggregateTargetList, (List *) havingQual,
groupColumnOpArray, NIL, NIL, aggregateStrategy,
rowEstimate, subPlan); AGGSPLIT_SIMPLE, groupColumnCount, groupColumnIdArray,
groupColumnOpArray, NULL, NIL, NIL,
rowEstimate, subPlan);
/* just for reproducible costs between different PostgreSQL versions */ /* just for reproducible costs between different PostgreSQL versions */
aggregatePlan->plan.startup_cost = 0; aggregatePlan->plan.startup_cost = 0;
@ -529,11 +532,13 @@ BuildDistinctPlan(Query *masterQuery, Plan *subPlan)
Oid *distinctColumnOpArray = extract_grouping_ops(distinctClauseList); Oid *distinctColumnOpArray = extract_grouping_ops(distinctClauseList);
uint32 distinctClauseCount = list_length(distinctClauseList); uint32 distinctClauseCount = list_length(distinctClauseList);
distinctPlan = (Plan *) make_agg(targetList, NIL, AGG_HASHED, /* TODO no nulls */
AGGSPLIT_SIMPLE, distinctClauseCount, distinctPlan = (Plan *) make_aggCompat(targetList, NIL, AGG_HASHED,
distinctColumnIdArray, AGGSPLIT_SIMPLE, distinctClauseCount,
distinctColumnOpArray, NIL, NIL, distinctColumnIdArray,
rowEstimate, subPlan); distinctColumnOpArray,
NULL, NIL, NIL,
rowEstimate, subPlan);
} }
else else
{ {

View File

@ -54,9 +54,9 @@
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/predtest.h" #include "compat/optimizer/predtest.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
#include "utils/builtins.h" #include "utils/builtins.h"

View File

@ -57,9 +57,9 @@
#include "optimizer/joininfo.h" #include "optimizer/joininfo.h"
#include "optimizer/pathnode.h" #include "optimizer/pathnode.h"
#include "optimizer/paths.h" #include "optimizer/paths.h"
#include "optimizer/predtest.h" #include "compat/optimizer/predtest.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
#include "parser/parse_oper.h" #include "parser/parse_oper.h"
#include "storage/lock.h" #include "storage/lock.h"

View File

@ -31,10 +31,14 @@
#include "distributed/pg_dist_partition.h" #include "distributed/pg_dist_partition.h"
#include "distributed/query_pushdown_planning.h" #include "distributed/query_pushdown_planning.h"
#include "distributed/relation_restriction_equivalence.h" #include "distributed/relation_restriction_equivalence.h"
#include "distributed/version_compat.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#if PG_VERSION_NUM >= 120000
#include "nodes/makefuncs.h"
#endif
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/var.h" #include "compat/optimizer/var.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"

View File

@ -78,7 +78,7 @@
#include "nodes/nodes.h" #include "nodes/nodes.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "nodes/primnodes.h" #include "nodes/primnodes.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/guc.h" #include "utils/guc.h"

View File

@ -19,7 +19,7 @@
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "nodes/primnodes.h" #include "nodes/primnodes.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
#include "optimizer/pathnode.h" #include "optimizer/pathnode.h"

View File

@ -59,6 +59,7 @@
#include "distributed/multi_physical_planner.h" #include "distributed/multi_physical_planner.h"
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "distributed/pg_dist_partition.h" #include "distributed/pg_dist_partition.h"
#include "distributed/version_compat.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
@ -138,6 +139,17 @@ typedef struct PendingPruningInstance
Node *continueAt; Node *continueAt;
} PendingPruningInstance; } PendingPruningInstance;
#if PG_VERSION_NUM >= 120000
typedef union \
{ \
FunctionCallInfoBaseData fcinfo; \
/* ensure enough space for nargs args is available */ \
char fcinfo_data[SizeForFunctionCallInfo(2)]; \
} FunctionCall2InfoData;
#else
typedef FunctionCallInfoData FunctionCall2InfoData;
typedef FunctionCallInfoData *FunctionCallInfo;
#endif
/* /*
* Data necessary to perform a single PruneShards(). * Data necessary to perform a single PruneShards().
@ -161,11 +173,11 @@ typedef struct ClauseWalkerContext
/* /*
* Information about function calls we need to perform. Re-using the same * Information about function calls we need to perform. Re-using the same
* FunctionCallInfoData, instead of using FunctionCall2Coll, is often * FunctionCall2InfoData, instead of using FunctionCall2Coll, is often
* cheaper. * cheaper.
*/ */
FunctionCallInfoData compareValueFunctionCall; FunctionCall2InfoData compareValueFunctionCall;
FunctionCallInfoData compareIntervalFunctionCall; FunctionCall2InfoData compareIntervalFunctionCall;
} ClauseWalkerContext; } ClauseWalkerContext;
static void PrunableExpressions(Node *originalNode, ClauseWalkerContext *context); static void PrunableExpressions(Node *originalNode, ClauseWalkerContext *context);
@ -184,9 +196,9 @@ static void AddNewConjuction(ClauseWalkerContext *context, OpExpr *op);
static PruningInstance * CopyPartialPruningInstance(PruningInstance *sourceInstance); static PruningInstance * CopyPartialPruningInstance(PruningInstance *sourceInstance);
static List * ShardArrayToList(ShardInterval **shardArray, int length); static List * ShardArrayToList(ShardInterval **shardArray, int length);
static List * DeepCopyShardIntervalList(List *originalShardIntervalList); static List * DeepCopyShardIntervalList(List *originalShardIntervalList);
static int PerformValueCompare(FunctionCallInfoData *compareFunctionCall, Datum a, static int PerformValueCompare(FunctionCallInfo compareFunctionCall, Datum a,
Datum b); Datum b);
static int PerformCompare(FunctionCallInfoData *compareFunctionCall); static int PerformCompare(FunctionCallInfo compareFunctionCall);
static List * PruneOne(DistTableCacheEntry *cacheEntry, ClauseWalkerContext *context, static List * PruneOne(DistTableCacheEntry *cacheEntry, ClauseWalkerContext *context,
PruningInstance *prune); PruningInstance *prune);
@ -201,11 +213,11 @@ static bool ExhaustivePruneOne(ShardInterval *curInterval,
PruningInstance *prune); PruningInstance *prune);
static int UpperShardBoundary(Datum partitionColumnValue, static int UpperShardBoundary(Datum partitionColumnValue,
ShardInterval **shardIntervalCache, ShardInterval **shardIntervalCache,
int shardCount, FunctionCallInfoData *compareFunction, int shardCount, FunctionCallInfo compareFunction,
bool includeMin); bool includeMin);
static int LowerShardBoundary(Datum partitionColumnValue, static int LowerShardBoundary(Datum partitionColumnValue,
ShardInterval **shardIntervalCache, ShardInterval **shardIntervalCache,
int shardCount, FunctionCallInfoData *compareFunction, int shardCount, FunctionCallInfo compareFunction,
bool includeMax); bool includeMax);
@ -261,9 +273,10 @@ PruneShards(Oid relationId, Index rangeTableId, List *whereClauseList,
if (cacheEntry->shardIntervalCompareFunction) if (cacheEntry->shardIntervalCompareFunction)
{ {
/* initiate function call info once (allows comparators to cache metadata) */ /* initiate function call info once (allows comparators to cache metadata) */
InitFunctionCallInfoData(context.compareIntervalFunctionCall, InitFunctionCallInfoDataCompat(*(FunctionCallInfo) &
cacheEntry->shardIntervalCompareFunction, context.compareIntervalFunctionCall,
2, DEFAULT_COLLATION_OID, NULL, NULL); cacheEntry->shardIntervalCompareFunction,
2, DEFAULT_COLLATION_OID, NULL, NULL);
} }
else else
{ {
@ -274,9 +287,10 @@ PruneShards(Oid relationId, Index rangeTableId, List *whereClauseList,
if (cacheEntry->shardColumnCompareFunction) if (cacheEntry->shardColumnCompareFunction)
{ {
/* initiate function call info once (allows comparators to cache metadata) */ /* initiate function call info once (allows comparators to cache metadata) */
InitFunctionCallInfoData(context.compareValueFunctionCall, InitFunctionCallInfoDataCompat(*(FunctionCallInfo) &
cacheEntry->shardColumnCompareFunction, context.compareValueFunctionCall,
2, DEFAULT_COLLATION_OID, NULL, NULL); cacheEntry->shardColumnCompareFunction,
2, DEFAULT_COLLATION_OID, NULL, NULL);
} }
else else
{ {
@ -753,7 +767,8 @@ AddPartitionKeyRestrictionToInstance(ClauseWalkerContext *context, OpExpr *opCla
case BTLessStrategyNumber: case BTLessStrategyNumber:
{ {
if (!prune->lessConsts || if (!prune->lessConsts ||
PerformValueCompare(&context->compareValueFunctionCall, PerformValueCompare((FunctionCallInfo) &
context->compareValueFunctionCall,
constantClause->constvalue, constantClause->constvalue,
prune->lessConsts->constvalue) < 0) prune->lessConsts->constvalue) < 0)
{ {
@ -766,7 +781,8 @@ AddPartitionKeyRestrictionToInstance(ClauseWalkerContext *context, OpExpr *opCla
case BTLessEqualStrategyNumber: case BTLessEqualStrategyNumber:
{ {
if (!prune->lessEqualConsts || if (!prune->lessEqualConsts ||
PerformValueCompare(&context->compareValueFunctionCall, PerformValueCompare((FunctionCallInfo) &
context->compareValueFunctionCall,
constantClause->constvalue, constantClause->constvalue,
prune->lessEqualConsts->constvalue) < 0) prune->lessEqualConsts->constvalue) < 0)
{ {
@ -782,7 +798,8 @@ AddPartitionKeyRestrictionToInstance(ClauseWalkerContext *context, OpExpr *opCla
{ {
prune->equalConsts = constantClause; prune->equalConsts = constantClause;
} }
else if (PerformValueCompare(&context->compareValueFunctionCall, else if (PerformValueCompare((FunctionCallInfo) &
context->compareValueFunctionCall,
constantClause->constvalue, constantClause->constvalue,
prune->equalConsts->constvalue) != 0) prune->equalConsts->constvalue) != 0)
{ {
@ -796,7 +813,8 @@ AddPartitionKeyRestrictionToInstance(ClauseWalkerContext *context, OpExpr *opCla
case BTGreaterEqualStrategyNumber: case BTGreaterEqualStrategyNumber:
{ {
if (!prune->greaterEqualConsts || if (!prune->greaterEqualConsts ||
PerformValueCompare(&context->compareValueFunctionCall, PerformValueCompare((FunctionCallInfo) &
context->compareValueFunctionCall,
constantClause->constvalue, constantClause->constvalue,
prune->greaterEqualConsts->constvalue) > 0 prune->greaterEqualConsts->constvalue) > 0
) )
@ -810,7 +828,8 @@ AddPartitionKeyRestrictionToInstance(ClauseWalkerContext *context, OpExpr *opCla
case BTGreaterStrategyNumber: case BTGreaterStrategyNumber:
{ {
if (!prune->greaterConsts || if (!prune->greaterConsts ||
PerformValueCompare(&context->compareValueFunctionCall, PerformValueCompare((FunctionCallInfo) &
context->compareValueFunctionCall,
constantClause->constvalue, constantClause->constvalue,
prune->greaterConsts->constvalue) > 0) prune->greaterConsts->constvalue) > 0)
{ {
@ -1133,7 +1152,7 @@ PruneOne(DistTableCacheEntry *cacheEntry, ClauseWalkerContext *context,
* unexpected NULL returns. * unexpected NULL returns.
*/ */
static int static int
PerformCompare(FunctionCallInfoData *compareFunctionCall) PerformCompare(FunctionCallInfo compareFunctionCall)
{ {
Datum result = FunctionCallInvoke(compareFunctionCall); Datum result = FunctionCallInvoke(compareFunctionCall);
@ -1151,12 +1170,10 @@ PerformCompare(FunctionCallInfoData *compareFunctionCall)
* NULL returns. * NULL returns.
*/ */
static int static int
PerformValueCompare(FunctionCallInfoData *compareFunctionCall, Datum a, Datum b) PerformValueCompare(FunctionCallInfo compareFunctionCall, Datum a, Datum b)
{ {
compareFunctionCall->arg[0] = a; fcSetArg(compareFunctionCall, 0, a);
compareFunctionCall->argnull[0] = false; fcSetArg(compareFunctionCall, 1, b);
compareFunctionCall->arg[1] = b;
compareFunctionCall->argnull[1] = false;
return PerformCompare(compareFunctionCall); return PerformCompare(compareFunctionCall);
} }
@ -1168,7 +1185,7 @@ PerformValueCompare(FunctionCallInfoData *compareFunctionCall, Datum a, Datum b)
*/ */
static int static int
LowerShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCache, LowerShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCache,
int shardCount, FunctionCallInfoData *compareFunction, bool includeMax) int shardCount, FunctionCallInfo compareFunction, bool includeMax)
{ {
int lowerBoundIndex = 0; int lowerBoundIndex = 0;
int upperBoundIndex = shardCount; int upperBoundIndex = shardCount;
@ -1176,8 +1193,7 @@ LowerShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCach
Assert(shardCount != 0); Assert(shardCount != 0);
/* setup partitionColumnValue argument once */ /* setup partitionColumnValue argument once */
compareFunction->arg[0] = partitionColumnValue; fcSetArg(compareFunction, 0, partitionColumnValue);
compareFunction->argnull[0] = false;
while (lowerBoundIndex < upperBoundIndex) while (lowerBoundIndex < upperBoundIndex)
{ {
@ -1186,8 +1202,7 @@ LowerShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCach
int minValueComparison = 0; int minValueComparison = 0;
/* setup minValue as argument */ /* setup minValue as argument */
compareFunction->arg[1] = shardIntervalCache[middleIndex]->minValue; fcSetArg(compareFunction, 1, shardIntervalCache[middleIndex]->minValue);
compareFunction->argnull[1] = false;
/* execute cmp(partitionValue, lowerBound) */ /* execute cmp(partitionValue, lowerBound) */
minValueComparison = PerformCompare(compareFunction); minValueComparison = PerformCompare(compareFunction);
@ -1201,8 +1216,7 @@ LowerShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCach
} }
/* setup maxValue as argument */ /* setup maxValue as argument */
compareFunction->arg[1] = shardIntervalCache[middleIndex]->maxValue; fcSetArg(compareFunction, 1, shardIntervalCache[middleIndex]->maxValue);
compareFunction->argnull[1] = false;
/* execute cmp(partitionValue, upperBound) */ /* execute cmp(partitionValue, upperBound) */
maxValueComparison = PerformCompare(compareFunction); maxValueComparison = PerformCompare(compareFunction);
@ -1249,7 +1263,7 @@ LowerShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCach
*/ */
static int static int
UpperShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCache, UpperShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCache,
int shardCount, FunctionCallInfoData *compareFunction, bool includeMin) int shardCount, FunctionCallInfo compareFunction, bool includeMin)
{ {
int lowerBoundIndex = 0; int lowerBoundIndex = 0;
int upperBoundIndex = shardCount; int upperBoundIndex = shardCount;
@ -1257,8 +1271,7 @@ UpperShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCach
Assert(shardCount != 0); Assert(shardCount != 0);
/* setup partitionColumnValue argument once */ /* setup partitionColumnValue argument once */
compareFunction->arg[0] = partitionColumnValue; fcSetArg(compareFunction, 0, partitionColumnValue);
compareFunction->argnull[0] = false;
while (lowerBoundIndex < upperBoundIndex) while (lowerBoundIndex < upperBoundIndex)
{ {
@ -1267,8 +1280,7 @@ UpperShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCach
int minValueComparison = 0; int minValueComparison = 0;
/* setup minValue as argument */ /* setup minValue as argument */
compareFunction->arg[1] = shardIntervalCache[middleIndex]->minValue; fcSetArg(compareFunction, 1, shardIntervalCache[middleIndex]->minValue);
compareFunction->argnull[1] = false;
/* execute cmp(partitionValue, lowerBound) */ /* execute cmp(partitionValue, lowerBound) */
minValueComparison = PerformCompare(compareFunction); minValueComparison = PerformCompare(compareFunction);
@ -1283,8 +1295,7 @@ UpperShardBoundary(Datum partitionColumnValue, ShardInterval **shardIntervalCach
} }
/* setup maxValue as argument */ /* setup maxValue as argument */
compareFunction->arg[1] = shardIntervalCache[middleIndex]->maxValue; fcSetArg(compareFunction, 1, shardIntervalCache[middleIndex]->maxValue);
compareFunction->argnull[1] = false;
/* execute cmp(partitionValue, upperBound) */ /* execute cmp(partitionValue, upperBound) */
maxValueComparison = PerformCompare(compareFunction); maxValueComparison = PerformCompare(compareFunction);
@ -1345,7 +1356,8 @@ PruneWithBoundaries(DistTableCacheEntry *cacheEntry, ClauseWalkerContext *contex
int lowerBoundIdx = -1; int lowerBoundIdx = -1;
int upperBoundIdx = -1; int upperBoundIdx = -1;
int curIdx = 0; int curIdx = 0;
FunctionCallInfo compareFunctionCall = &context->compareIntervalFunctionCall; FunctionCallInfo compareFunctionCall = (FunctionCallInfo) &
context->compareIntervalFunctionCall;
if (prune->greaterEqualConsts) if (prune->greaterEqualConsts)
{ {
@ -1476,7 +1488,8 @@ ExhaustivePruneOne(ShardInterval *curInterval,
ClauseWalkerContext *context, ClauseWalkerContext *context,
PruningInstance *prune) PruningInstance *prune)
{ {
FunctionCallInfo compareFunctionCall = &context->compareIntervalFunctionCall; FunctionCallInfo compareFunctionCall = (FunctionCallInfo) &
context->compareIntervalFunctionCall;
Datum compareWith = 0; Datum compareWith = 0;
/* NULL boundaries can't be compared to */ /* NULL boundaries can't be compared to */

View File

@ -13,6 +13,7 @@
#include "distributed/function_utils.h" #include "distributed/function_utils.h"
#include "distributed/multi_progress.h" #include "distributed/multi_progress.h"
#include "distributed/version_compat.h"
#include "storage/dsm.h" #include "storage/dsm.h"
#include "utils/builtins.h" #include "utils/builtins.h"
@ -155,7 +156,7 @@ ProgressMonitorList(uint64 commandTypeMagicNumber, List **attachedDSMSegments)
getProgressInfoFunctionOid, getProgressInfoFunctionOid,
commandTypeDatum); commandTypeDatum);
tupleTableSlot = MakeSingleTupleTableSlot(progressResultSet->setDesc); tupleTableSlot = MakeSingleTupleTableSlotCompat(progressResultSet->setDesc);
/* iterate over tuples in tuple store, and send them to destination */ /* iterate over tuples in tuple store, and send them to destination */
for (;;) for (;;)

View File

@ -15,6 +15,7 @@
#include "postgres.h" #include "postgres.h"
#include "c.h" #include "c.h"
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -755,8 +756,10 @@ AppendShardIdToName(char **name, uint64 shardId)
neededBytes = snprintf((*name), NAMEDATALEN, "%s", extendedName); neededBytes = snprintf((*name), NAMEDATALEN, "%s", extendedName);
if (neededBytes < 0) if (neededBytes < 0)
{ {
char *strerrno = strerror(errno);
ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory: %s", strerror(errno)))); errmsg("out of memory: %s", strerrno)));
} }
else if (neededBytes >= NAMEDATALEN) else if (neededBytes >= NAMEDATALEN)
{ {

View File

@ -22,7 +22,7 @@
#include "nodes/nodes.h" #include "nodes/nodes.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "nodes/plannodes.h" #include "nodes/plannodes.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
#include "optimizer/pathnode.h" #include "optimizer/pathnode.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"

View File

@ -19,6 +19,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#if PG_VERSION_NUM >= 120000
#include "access/genam.h"
#endif
#include "access/heapam.h" #include "access/heapam.h"
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/relscan.h" #include "access/relscan.h"

View File

@ -30,7 +30,7 @@
#include "distributed/master_metadata_utility.h" #include "distributed/master_metadata_utility.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/plannodes.h" #include "nodes/plannodes.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
#include "utils/datum.h" #include "utils/datum.h"

View File

@ -45,9 +45,15 @@ CitusSetTag(Node *node, int tag)
nodeTypeName *local_node = (nodeTypeName *) CitusSetTag((Node *) node, T_##nodeTypeName) nodeTypeName *local_node = (nodeTypeName *) CitusSetTag((Node *) node, T_##nodeTypeName)
/* And a few guys need only the pg_strtok support fields */ /* And a few guys need only the pg_strtok support fields */
#if PG_VERSION_NUM >= 120000
#define READ_TEMP_LOCALS() \ #define READ_TEMP_LOCALS() \
char *token; \ const char *token; \
int length int length
#else
#define READ_TEMP_LOCALS() \
char *token; \
int length
#endif
/* ... but most need both */ /* ... but most need both */
#define READ_LOCALS(nodeTypeName) \ #define READ_LOCALS(nodeTypeName) \

View File

@ -128,7 +128,11 @@ get_extension_schema(Oid ext_oid)
rel = heap_open(ExtensionRelationId, AccessShareLock); rel = heap_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0], ScanKeyInit(&entry[0],
#if PG_VERSION_NUM >= 120000
Anum_pg_extension_oid,
#else
ObjectIdAttributeNumber, ObjectIdAttributeNumber,
#endif
BTEqualStrategyNumber, F_OIDEQ, BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(ext_oid)); ObjectIdGetDatum(ext_oid));

View File

@ -12,6 +12,9 @@
#include "postgres.h" #include "postgres.h"
#if PG_VERSION_NUM >= 120000
#include "access/genam.h"
#endif
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/stratnum.h" #include "access/stratnum.h"
#include "catalog/pg_constraint.h" #include "catalog/pg_constraint.h"

View File

@ -11,11 +11,10 @@
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "distributed/function_utils.h" #include "distributed/function_utils.h"
#include "distributed/version_compat.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#if (PG_VERSION_NUM >= 100000)
#include "utils/regproc.h" #include "utils/regproc.h"
#endif
/* /*
* FunctionOid searches for a function that has the given name and the given * FunctionOid searches for a function that has the given name and the given
@ -83,7 +82,7 @@ FunctionOidExtended(const char *schemaName, const char *functionName, int argume
ReturnSetInfo * ReturnSetInfo *
FunctionCallGetTupleStore1(PGFunction function, Oid functionId, Datum argument) FunctionCallGetTupleStore1(PGFunction function, Oid functionId, Datum argument)
{ {
FunctionCallInfoData fcinfo; LOCAL_FCINFO(fcinfo, 1);
FmgrInfo flinfo; FmgrInfo flinfo;
ReturnSetInfo *rsinfo = makeNode(ReturnSetInfo); ReturnSetInfo *rsinfo = makeNode(ReturnSetInfo);
EState *estate = CreateExecutorState(); EState *estate = CreateExecutorState();
@ -91,12 +90,11 @@ FunctionCallGetTupleStore1(PGFunction function, Oid functionId, Datum argument)
rsinfo->allowedModes = SFRM_Materialize; rsinfo->allowedModes = SFRM_Materialize;
fmgr_info(functionId, &flinfo); fmgr_info(functionId, &flinfo);
InitFunctionCallInfoData(fcinfo, &flinfo, 1, InvalidOid, NULL, (Node *) rsinfo); InitFunctionCallInfoData(*fcinfo, &flinfo, 1, InvalidOid, NULL, (Node *) rsinfo);
fcinfo.arg[0] = argument; fcSetArg(fcinfo, 0, argument);
fcinfo.argnull[0] = false;
(*function)(&fcinfo); (*function)(fcinfo);
return rsinfo; return rsinfo;
} }

View File

@ -20,6 +20,7 @@
#include "access/sysattr.h" #include "access/sysattr.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/pg_am.h" #include "catalog/pg_am.h"
#include "catalog/pg_enum.h"
#include "catalog/pg_extension.h" #include "catalog/pg_extension.h"
#include "catalog/pg_namespace.h" #include "catalog/pg_namespace.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
@ -43,6 +44,7 @@
#include "distributed/pg_dist_placement.h" #include "distributed/pg_dist_placement.h"
#include "distributed/shared_library_init.h" #include "distributed/shared_library_init.h"
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "distributed/version_compat.h"
#include "distributed/worker_manager.h" #include "distributed/worker_manager.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "executor/executor.h" #include "executor/executor.h"
@ -1616,9 +1618,8 @@ AvailableExtensionVersion(void)
{ {
ReturnSetInfo *extensionsResultSet = NULL; ReturnSetInfo *extensionsResultSet = NULL;
TupleTableSlot *tupleTableSlot = NULL; TupleTableSlot *tupleTableSlot = NULL;
FunctionCallInfoData *fcinfo = NULL; LOCAL_FCINFO(fcinfo, 0);
FmgrInfo *flinfo = NULL; FmgrInfo flinfo;
int argumentCount = 0;
EState *estate = NULL; EState *estate = NULL;
bool hasTuple = false; bool hasTuple = false;
@ -1633,17 +1634,14 @@ AvailableExtensionVersion(void)
extensionsResultSet->econtext = GetPerTupleExprContext(estate); extensionsResultSet->econtext = GetPerTupleExprContext(estate);
extensionsResultSet->allowedModes = SFRM_Materialize; extensionsResultSet->allowedModes = SFRM_Materialize;
fcinfo = palloc0(sizeof(FunctionCallInfoData)); fmgr_info(F_PG_AVAILABLE_EXTENSIONS, &flinfo);
flinfo = palloc0(sizeof(FmgrInfo)); InitFunctionCallInfoData(*fcinfo, &flinfo, 0, InvalidOid, NULL,
fmgr_info(F_PG_AVAILABLE_EXTENSIONS, flinfo);
InitFunctionCallInfoData(*fcinfo, flinfo, argumentCount, InvalidOid, NULL,
(Node *) extensionsResultSet); (Node *) extensionsResultSet);
/* pg_available_extensions returns result set containing all available extensions */ /* pg_available_extensions returns result set containing all available extensions */
(*pg_available_extensions)(fcinfo); (*pg_available_extensions)(fcinfo);
tupleTableSlot = MakeSingleTupleTableSlot(extensionsResultSet->setDesc); tupleTableSlot = MakeSingleTupleTableSlotCompat(extensionsResultSet->setDesc);
hasTuple = tuplestore_gettupleslot(extensionsResultSet->setResult, goForward, doCopy, hasTuple = tuplestore_gettupleslot(extensionsResultSet->setResult, goForward, doCopy,
tupleTableSlot); tupleTableSlot);
while (hasTuple) while (hasTuple)
@ -1984,9 +1982,10 @@ CitusCopyFormatTypeId(void)
if (MetadataCache.copyFormatTypeId == InvalidOid) if (MetadataCache.copyFormatTypeId == InvalidOid)
{ {
char *typeName = "citus_copy_format"; char *typeName = "citus_copy_format";
MetadataCache.copyFormatTypeId = GetSysCacheOid2(TYPENAMENSP, MetadataCache.copyFormatTypeId = GetSysCacheOid2Compat(TYPENAMENSP,
PointerGetDatum(typeName), Anum_pg_enum_oid,
PG_CATALOG_NAMESPACE); PointerGetDatum(typeName),
PG_CATALOG_NAMESPACE);
} }
return MetadataCache.copyFormatTypeId; return MetadataCache.copyFormatTypeId;
@ -2248,7 +2247,11 @@ LookupNodeRoleTypeOid()
return InvalidOid; return InvalidOid;
} }
#if PG_VERSION_NUM >= 120000
nodeRoleTypId = ((Form_pg_type) GETSTRUCT(tup))->oid;
#else
nodeRoleTypId = HeapTupleGetOid(tup); nodeRoleTypId = HeapTupleGetOid(tup);
#endif
ReleaseSysCache(tup); ReleaseSysCache(tup);
return nodeRoleTypId; return nodeRoleTypId;

View File

@ -24,6 +24,9 @@
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#if PG_VERSION_NUM >= 120000
#include "partitioning/partdesc.h"
#endif
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/fmgroids.h" #include "utils/fmgroids.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"

View File

@ -17,7 +17,7 @@
#include "postgres.h" #include "postgres.h"
#if (PG_VERSION_NUM >= 110000) #if (PG_VERSION_NUM >= 110000) && (PG_VERSION_NUM < 120000)
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
@ -7909,4 +7909,4 @@ get_range_partbound_string(List *bound_datums)
return buf->data; return buf->data;
} }
#endif /* (PG_VERSION_NUM >= 110000) */ #endif /* (PG_VERSION_NUM >= 110000) && (PG_VERSION_NUM < 120000) */

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,6 @@
#include "citus_version.h" #include "citus_version.h"
#include "fmgr.h" #include "fmgr.h"
#include "utils/uuid.h" #include "utils/uuid.h"
#include "utils/backend_random.h"
bool EnableStatisticsCollection = true; /* send basic usage statistics to Citus */ bool EnableStatisticsCollection = true; /* send basic usage statistics to Citus */
@ -600,11 +599,11 @@ citus_server_id(PG_FUNCTION_ARGS)
uint8 *buf = (uint8 *) palloc(UUID_LEN); uint8 *buf = (uint8 *) palloc(UUID_LEN);
/* /*
* If pg_backend_random() fails, fall-back to using random(). In previous * If pg_strong_random() fails, fall-back to using random(). In previous
* versions of postgres we don't have pg_backend_random(), so use it by * versions of postgres we don't have pg_strong_random(), so use it by
* default in that case. * default in that case.
*/ */
if (!pg_backend_random((char *) buf, UUID_LEN)) if (!pg_strong_random((char *) buf, UUID_LEN))
{ {
int bufIdx = 0; int bufIdx = 0;
for (bufIdx = 0; bufIdx < UUID_LEN; bufIdx++) for (bufIdx = 0; bufIdx < UUID_LEN; bufIdx++)

View File

@ -17,6 +17,9 @@
#include "funcapi.h" #include "funcapi.h"
#include "miscadmin.h" #include "miscadmin.h"
#if PG_VERSION_NUM >= 120000
#include "access/genam.h"
#endif
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/xact.h" #include "access/xact.h"
#include "catalog/dependency.h" #include "catalog/dependency.h"
@ -35,7 +38,6 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/tqual.h"
/* Local functions forward declarations */ /* Local functions forward declarations */
@ -362,7 +364,8 @@ RemoveJobSchema(StringInfo schemaName)
Datum schemaNameDatum = CStringGetDatum(schemaName->data); Datum schemaNameDatum = CStringGetDatum(schemaName->data);
Oid schemaId = InvalidOid; Oid schemaId = InvalidOid;
schemaId = GetSysCacheOid(NAMESPACENAME, schemaNameDatum, 0, 0, 0); schemaId = GetSysCacheOid1Compat(NAMESPACENAME, Anum_pg_namespace_oid,
schemaNameDatum);
if (OidIsValid(schemaId)) if (OidIsValid(schemaId))
{ {
ObjectAddress schemaObject = { 0, 0, 0 }; ObjectAddress schemaObject = { 0, 0, 0 };

View File

@ -65,8 +65,8 @@ static uint32 FileBufferSize(int partitionBufferSizeInKB, uint32 fileCount);
static FileOutputStream * OpenPartitionFiles(StringInfo directoryName, uint32 fileCount); static FileOutputStream * OpenPartitionFiles(StringInfo directoryName, uint32 fileCount);
static void ClosePartitionFiles(FileOutputStream *partitionFileArray, uint32 fileCount); static void ClosePartitionFiles(FileOutputStream *partitionFileArray, uint32 fileCount);
static void RenameDirectory(StringInfo oldDirectoryName, StringInfo newDirectoryName); static void RenameDirectory(StringInfo oldDirectoryName, StringInfo newDirectoryName);
static void FileOutputStreamWrite(FileOutputStream file, StringInfo dataToWrite); static void FileOutputStreamWrite(FileOutputStream *file, StringInfo dataToWrite);
static void FileOutputStreamFlush(FileOutputStream file); static void FileOutputStreamFlush(FileOutputStream *file);
static void FilterAndPartitionTable(const char *filterQuery, static void FilterAndPartitionTable(const char *filterQuery,
const char *columnName, Oid columnType, const char *columnName, Oid columnType,
uint32 (*PartitionIdFunction)(Datum, const void *), uint32 (*PartitionIdFunction)(Datum, const void *),
@ -500,13 +500,13 @@ ClosePartitionFiles(FileOutputStream *partitionFileArray, uint32 fileCount)
uint32 fileIndex = 0; uint32 fileIndex = 0;
for (fileIndex = 0; fileIndex < fileCount; fileIndex++) for (fileIndex = 0; fileIndex < fileCount; fileIndex++)
{ {
FileOutputStream partitionFile = partitionFileArray[fileIndex]; FileOutputStream *partitionFile = &partitionFileArray[fileIndex];
FileOutputStreamFlush(partitionFile); FileOutputStreamFlush(partitionFile);
FileClose(partitionFile.fileDescriptor); FileClose(partitionFile->fileDescriptor);
FreeStringInfo(partitionFile.fileBuffer); FreeStringInfo(partitionFile->fileBuffer);
FreeStringInfo(partitionFile.filePath); FreeStringInfo(partitionFile->filePath);
} }
pfree(partitionFileArray); pfree(partitionFileArray);
@ -829,9 +829,9 @@ RenameDirectory(StringInfo oldDirectoryName, StringInfo newDirectoryName)
* if so, the function flushes the buffer to the underlying file. * if so, the function flushes the buffer to the underlying file.
*/ */
static void static void
FileOutputStreamWrite(FileOutputStream file, StringInfo dataToWrite) FileOutputStreamWrite(FileOutputStream *file, StringInfo dataToWrite)
{ {
StringInfo fileBuffer = file.fileBuffer; StringInfo fileBuffer = file->fileBuffer;
uint32 newBufferSize = fileBuffer->len + dataToWrite->len; uint32 newBufferSize = fileBuffer->len + dataToWrite->len;
appendBinaryStringInfo(fileBuffer, dataToWrite->data, dataToWrite->len); appendBinaryStringInfo(fileBuffer, dataToWrite->data, dataToWrite->len);
@ -847,20 +847,23 @@ FileOutputStreamWrite(FileOutputStream file, StringInfo dataToWrite)
/* Flushes data buffered in the file stream object to the underlying file. */ /* Flushes data buffered in the file stream object to the underlying file. */
static void static void
FileOutputStreamFlush(FileOutputStream file) FileOutputStreamFlush(FileOutputStream *file)
{ {
StringInfo fileBuffer = file.fileBuffer; StringInfo fileBuffer = file->fileBuffer;
int written = 0; int written = 0;
errno = 0; errno = 0;
written = FileWrite(file.fileDescriptor, fileBuffer->data, fileBuffer->len, written = FileWriteCompat(file->fileDescriptor, fileBuffer->data, fileBuffer->len,
PG_WAIT_IO); file->offset,
PG_WAIT_IO);
if (written != fileBuffer->len) if (written != fileBuffer->len)
{ {
ereport(ERROR, (errcode_for_file_access(), ereport(ERROR, (errcode_for_file_access(),
errmsg("could not write %d bytes to partition file \"%s\"", errmsg("could not write %d bytes to partition file \"%s\"",
fileBuffer->len, file.filePath->data))); fileBuffer->len, file->filePath->data)));
} }
file->offset += written;
} }
@ -946,7 +949,7 @@ FilterAndPartitionTable(const char *filterQuery,
{ {
HeapTuple row = SPI_tuptable->vals[rowIndex]; HeapTuple row = SPI_tuptable->vals[rowIndex];
TupleDesc rowDescriptor = SPI_tuptable->tupdesc; TupleDesc rowDescriptor = SPI_tuptable->tupdesc;
FileOutputStream partitionFile = { 0, 0, 0 }; FileOutputStream *partitionFile = NULL;
StringInfo rowText = NULL; StringInfo rowText = NULL;
Datum partitionKey = 0; Datum partitionKey = 0;
bool partitionKeyNull = false; bool partitionKeyNull = false;
@ -978,7 +981,7 @@ FilterAndPartitionTable(const char *filterQuery,
rowText = rowOutputState->fe_msgbuf; rowText = rowOutputState->fe_msgbuf;
partitionFile = partitionFileArray[partitionId]; partitionFile = &partitionFileArray[partitionId];
FileOutputStreamWrite(partitionFile, rowText); FileOutputStreamWrite(partitionFile, rowText);
resetStringInfo(rowText); resetStringInfo(rowText);
@ -1136,7 +1139,7 @@ OutputBinaryHeaders(FileOutputStream *partitionFileArray, uint32 fileCount)
AppendCopyBinaryHeaders(headerOutputState); AppendCopyBinaryHeaders(headerOutputState);
partitionFile = partitionFileArray[fileIndex]; partitionFile = partitionFileArray[fileIndex];
FileOutputStreamWrite(partitionFile, headerOutputState->fe_msgbuf); FileOutputStreamWrite(&partitionFile, headerOutputState->fe_msgbuf);
} }
} }
@ -1162,7 +1165,7 @@ OutputBinaryFooters(FileOutputStream *partitionFileArray, uint32 fileCount)
AppendCopyBinaryFooters(footerOutputState); AppendCopyBinaryFooters(footerOutputState);
partitionFile = partitionFileArray[fileIndex]; partitionFile = partitionFileArray[fileIndex];
FileOutputStreamWrite(partitionFile, footerOutputState->fe_msgbuf); FileOutputStreamWrite(&partitionFile, footerOutputState->fe_msgbuf);
} }
} }

View File

@ -16,6 +16,7 @@
#include "distributed/commands/multi_copy.h" #include "distributed/commands/multi_copy.h"
#include "distributed/multi_executor.h" #include "distributed/multi_executor.h"
#include "distributed/transmit.h" #include "distributed/transmit.h"
#include "distributed/version_compat.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/memutils.h" #include "utils/memutils.h"
@ -251,7 +252,8 @@ TaskFileDestReceiverReceive(TupleTableSlot *slot, DestReceiver *dest)
static void static void
WriteToLocalFile(StringInfo copyData, File fileDesc) WriteToLocalFile(StringInfo copyData, File fileDesc)
{ {
int bytesWritten = FileWrite(fileDesc, copyData->data, copyData->len, PG_WAIT_IO); int bytesWritten = FileWriteCompat(fileDesc, copyData->data, copyData->len, 0,
PG_WAIT_IO);
if (bytesWritten < 0) if (bytesWritten < 0)
{ {
ereport(ERROR, (errcode_for_file_access(), ereport(ERROR, (errcode_for_file_access(),

View File

@ -0,0 +1,5 @@
#if PG_VERSION_NUM >= 120000
#include "nodes/pathnodes.h"
#else
#include "nodes/relation.h"
#endif

View File

@ -0,0 +1,5 @@
#if PG_VERSION_NUM >= 120000
#include "optimizer/optimizer.h"
#else
#include "optimizer/predtest.h"
#endif

View File

@ -0,0 +1,5 @@
#if PG_VERSION_NUM >= 120000
#include "optimizer/optimizer.h"
#else
#include "optimizer/var.h"
#endif

View File

@ -11,7 +11,7 @@
#define DISTRIBUTED_PLANNER_H #define DISTRIBUTED_PLANNER_H
#include "nodes/plannodes.h" #include "nodes/plannodes.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
#include "distributed/citus_nodes.h" #include "distributed/citus_nodes.h"
#include "distributed/errormessage.h" #include "distributed/errormessage.h"

View File

@ -11,6 +11,8 @@
#include "utils/hsearch.h" #include "utils/hsearch.h"
#if PG_VERSION_NUM < 120000
/* /*
* Combine two hash values, resulting in another hash value, with decent bit * Combine two hash values, resulting in another hash value, with decent bit
* mixing. * mixing.
@ -25,6 +27,9 @@ hash_combine(uint32 a, uint32 b)
} }
#endif
extern void hash_delete_all(HTAB *htab); extern void hash_delete_all(HTAB *htab);
#endif #endif

View File

@ -15,7 +15,7 @@
#include "distributed/relation_restriction_equivalence.h" #include "distributed/relation_restriction_equivalence.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "nodes/primnodes.h" #include "nodes/primnodes.h"
#include "nodes/relation.h" #include "compat/nodes/relation.h"
extern List * GenerateSubplansForSubqueriesAndCTEs(uint64 planId, Query *originalQuery, extern List * GenerateSubplansForSubqueriesAndCTEs(uint64 planId, Query *originalQuery,

View File

@ -16,6 +16,10 @@
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#if (PG_VERSION_NUM >= 120000)
#include "optimizer/optimizer.h"
#endif
#if (PG_VERSION_NUM >= 100000 && PG_VERSION_NUM < 110000) #if (PG_VERSION_NUM >= 100000 && PG_VERSION_NUM < 110000)
#include "access/hash.h" #include "access/hash.h"
@ -240,5 +244,67 @@ RangeVarGetRelidInternal(const RangeVar *relation, LOCKMODE lockmode, uint32 fla
#endif #endif
#if PG_VERSION_NUM >= 120000
#define NextCopyLastParam
#define MakeSingleTupleTableSlotCompat(tupleDesc) \
MakeSingleTupleTableSlot(tupleDesc, &TTSOpsHeapTuple)
#define AllocSetContextCreateExtended AllocSetContextCreateInternal
#define ExecStoreTuple(tuple, slot, buffer, shouldFree) \
ExecStoreHeapTuple(tuple, slot, shouldFree)
#define NextCopyFromCompat NextCopyFrom
#define QTW_EXAMINE_RTES QTW_EXAMINE_RTES_BEFORE
#define ArrayRef SubscriptingRef
#define T_ArrayRef T_SubscriptingRef
#define or_clause is_orclause
#define GetSysCacheOid1Compat GetSysCacheOid1
#define GetSysCacheOid2Compat GetSysCacheOid2
#define GetSysCacheOid3Compat GetSysCacheOid3
#define GetSysCacheOid4Compat GetSysCacheOid4
#define make_aggCompat make_agg
#define FileReadCompat FileRead
#define FileWriteCompat FileWrite
#define fcSetArg(fc, n, argval) \
((fc)->args[n].isnull = false, (fc)->args[n].value = (argval))
#define fcSetArgNull(fc, n) \
((fc)->args[n].isnull = true, (fc)->args[n].value = (Datum) 0)
#define InitFunctionCallInfoDataCompat InitFunctionCallInfoData
#else /* pre PG12 */
#define MakeSingleTupleTableSlotCompat MakeSingleTupleTableSlot
#define NextCopyFromCompat(cstate, econtext, values, nulls) \
NextCopyFrom(cstate, econtext, values, nulls, NULL)
#define GetSysCacheOid1Compat(cacheId, oidcol, key1) \
GetSysCacheOid1(cacheId, key1)
#define GetSysCacheOid2Compat(cacheId, oidcol, key1, key2) \
GetSysCacheOid2(cacheId, key1, key2)
#define GetSysCacheOid3Compat(cacheId, oidcol, key1, key2, key3) \
GetSysCacheOid3(cacheId, key1, key2, key3)
#define GetSysCacheOid4Compat(cacheId, oidcol, key1, key2, key3, key4) \
GetSysCacheOid4(cacheId, key1, key2, key3, key4)
#define LOCAL_FCINFO(name, nargs) \
FunctionCallInfoData name ## data; \
FunctionCallInfoData *name = &name ## data
#define make_aggCompat(tlist, qual, aggstrategy, aggsplit, numGroupCols, grpColIdx, \
grpOperators, grpCollations, groupingSets, chain, dNumGrous, \
lefttree) \
make_agg(tlist, qual, aggstrategy, aggsplit, numGroupCols, grpColIdx, grpOperators, \
groupingSets, chain, dNumGrous, lefttree)
#define fcSetArg(fc, n, value) \
(((fc)->argnull[n] = false), ((fc)->arg[n] = (value)))
#define fcSetArgNull(fc, n) \
(((fc)->argnull[n] = true), ((fc)->arg[n] = (Datum) 0))
#define InitFunctionCallInfoDataCompat(fc, fn, nargs, collation, ctx, result) \
InitFunctionCallInfoData(fc, fn, nargs, collation, ctx, result)
#define FileReadCompat(file, buffer, amount, offset, wait_event_info) \
FileRead(file, buffer, amount, wait_event_info)
#define FileWriteCompat(file, buffer, amount, offset, wait_event_info) \
FileWrite(file, buffer, amount, wait_event_info)
#endif /* PG12 */
#endif /* VERSION_COMPAT_H */ #endif /* VERSION_COMPAT_H */

View File

@ -92,6 +92,7 @@ typedef struct HashPartitionContext
typedef struct FileOutputStream typedef struct FileOutputStream
{ {
File fileDescriptor; File fileDescriptor;
off_t offset;
StringInfo fileBuffer; StringInfo fileBuffer;
StringInfo filePath; StringInfo filePath;
} FileOutputStream; } FileOutputStream;