Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PG17 compatibility: Resolve compilation issues #7699

Merged
merged 26 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fb4efeb
Enable configure
naisila Jul 8, 2024
4685be7
Remove ExecFreeExprContext call
naisila Jul 8, 2024
b4d36f6
PG17 uses streaming IO in analyze, fix scan_analyze_next_block function
naisila Jul 8, 2024
56f85a1
Define ObjectClass for PG17+ only since it's removed
naisila Jul 8, 2024
f5c3b0a
Remove ReorderBufferTupleBuf structure.
naisila Jul 8, 2024
ad8eaf7
Define colliculocale and daticulocale since they have been renamed
naisila Jul 8, 2024
b81c8c8
makeStringConst defined in PG17
naisila Jul 8, 2024
0608538
RangeVarCallbackOwnsTable was replaced by RangeVarCallbackMaintainsTable
naisila Jul 9, 2024
8ea510b
attstattarget is nullable, define pg compatible functions for it
naisila Jul 9, 2024
8513145
stxstattarget is nullable in PG17, write compat functions for it
naisila Jul 9, 2024
7ac4794
Use ResourceOwner to track WaitEventSet in PG17
naisila Jul 10, 2024
55f7671
getIdentitySequence now uses Relation instead of relation_id
naisila Jul 10, 2024
363c8aa
Remove no-op tuplestore_donestoring function
naisila Jul 10, 2024
0694250
MergeAction can have 3 merge kinds (now enum) in PG17, write compat
naisila Jul 10, 2024
5446088
EXPLAIN (MEMORY) is added, make changes to ExplainOnePlan
naisila Jul 10, 2024
6bffd8a
LIMIT_OPTION_DEFAULT has been removed as it's useless, use LIMIT_OPTI…
naisila Jul 10, 2024
c23c61d
write compat for create_foreignscan_path bcs of more arguments in PG17
naisila Jul 10, 2024
6616f1f
pgprocno and lxid have been combined into a struct in PGPROC
naisila Jul 10, 2024
f6e2d01
Simplify CitusNewNode (#7434)
zhjwpku Jan 22, 2024
7497419
add pg17 build test
naisila Jul 25, 2024
ef60a25
Address review on attstattarget is nullable, define pg compatible fun…
naisila Oct 16, 2024
06727b6
Address review on Define colliculocale and daticulocale since they ha…
naisila Oct 16, 2024
cd76567
Address review use int instead of int16 and int32
naisila Oct 16, 2024
980a425
Address reviews
naisila Oct 17, 2024
532cc95
Revert "Enable configure"
naisila Oct 17, 2024
c3e0bc8
Revert "add pg17 build test"
naisila Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/backend/columnar/columnar_customscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1924,11 +1924,6 @@ ColumnarScan_EndCustomScan(CustomScanState *node)
*/
TableScanDesc scanDesc = node->ss.ss_currentScanDesc;

/*
* Free the exprcontext
*/
ExecFreeExprContext(&node->ss.ps);

/*
* clean out the tuple table
*/
Expand Down
7 changes: 6 additions & 1 deletion src/backend/columnar/columnar_tableam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,13 @@ ConditionalLockRelationWithTimeout(Relation rel, LOCKMODE lockMode, int timeout,


static bool
columnar_scan_analyze_next_block(TableScanDesc scan, BlockNumber blockno,
columnar_scan_analyze_next_block(TableScanDesc scan,
#if PG_VERSION_NUM >= PG_VERSION_17
ReadStream *stream)
#else
BlockNumber blockno,
BufferAccessStrategy bstrategy)
#endif
{
/*
* Our access method is not pages based, i.e. tuples are not confined
Expand Down
71 changes: 71 additions & 0 deletions src/backend/distributed/cdc/cdc_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "utils/rel.h"
#include "utils/typcache.h"

#include "pg_version_constants.h"

PG_MODULE_MAGIC;

extern void _PG_output_plugin_init(OutputPluginCallbacks *cb);
Expand Down Expand Up @@ -435,6 +437,74 @@ TranslateChangesIfSchemaChanged(Relation sourceRelation, Relation targetRelation
return;
}

#if PG_VERSION_NUM >= PG_VERSION_17

/* Check the ReorderBufferChange's action type and handle them accordingly.*/
switch (change->action)
{
case REORDER_BUFFER_CHANGE_INSERT:
{
/* For insert action, only new tuple should always be translated*/
HeapTuple sourceRelationNewTuple = change->data.tp.newtuple;
HeapTuple targetRelationNewTuple = GetTupleForTargetSchemaForCdc(
sourceRelationNewTuple, sourceRelationDesc, targetRelationDesc);
change->data.tp.newtuple = targetRelationNewTuple;
break;
}

/*
* For update changes both old and new tuples need to be translated for target relation
* if the REPLICA IDENTITY is set to FULL. Otherwise, only the new tuple needs to be
* translated for target relation.
*/
case REORDER_BUFFER_CHANGE_UPDATE:
{
/* For update action, new tuple should always be translated*/
/* Get the new tuple from the ReorderBufferChange, and translate it to target relation. */
HeapTuple sourceRelationNewTuple = change->data.tp.newtuple;
HeapTuple targetRelationNewTuple = GetTupleForTargetSchemaForCdc(
sourceRelationNewTuple, sourceRelationDesc, targetRelationDesc);
change->data.tp.newtuple = targetRelationNewTuple;

/*
* Format oldtuple according to the target relation. If the column values of replica
* identiy change, then the old tuple is non-null and needs to be formatted according
* to the target relation schema.
*/
if (change->data.tp.oldtuple != NULL)
{
HeapTuple sourceRelationOldTuple = change->data.tp.oldtuple;
HeapTuple targetRelationOldTuple = GetTupleForTargetSchemaForCdc(
sourceRelationOldTuple,
sourceRelationDesc,
targetRelationDesc);

change->data.tp.oldtuple = targetRelationOldTuple;
}
break;
}

case REORDER_BUFFER_CHANGE_DELETE:
{
/* For delete action, only old tuple should be translated*/
HeapTuple sourceRelationOldTuple = change->data.tp.oldtuple;
HeapTuple targetRelationOldTuple = GetTupleForTargetSchemaForCdc(
sourceRelationOldTuple,
sourceRelationDesc,
targetRelationDesc);

change->data.tp.oldtuple = targetRelationOldTuple;
break;
}

default:
{
/* Do nothing for other action types. */
break;
}
}
#else

/* Check the ReorderBufferChange's action type and handle them accordingly.*/
switch (change->action)
{
Expand Down Expand Up @@ -499,4 +569,5 @@ TranslateChangesIfSchemaChanged(Relation sourceRelation, Relation targetRelation
break;
}
}
#endif
}
16 changes: 8 additions & 8 deletions src/backend/distributed/commands/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CreateCollationDDLInternal(Oid collationId, Oid *collowner, char **quotedCollati
* ICU-related field. Only the libc-related fields or the ICU-related field
* is set, never both.
*/
char *colliculocale;
char *colllocale;
bool isnull;

Datum datum = SysCacheGetAttr(COLLOID, heapTuple, Anum_pg_collation_collcollate,
Expand All @@ -101,17 +101,17 @@ CreateCollationDDLInternal(Oid collationId, Oid *collowner, char **quotedCollati
collctype = NULL;
}

datum = SysCacheGetAttr(COLLOID, heapTuple, Anum_pg_collation_colliculocale, &isnull);
datum = SysCacheGetAttr(COLLOID, heapTuple, Anum_pg_collation_colllocale, &isnull);
if (!isnull)
{
colliculocale = TextDatumGetCString(datum);
colllocale = TextDatumGetCString(datum);
}
else
{
colliculocale = NULL;
colllocale = NULL;
}

Assert((collcollate && collctype) || colliculocale);
Assert((collcollate && collctype) || colllocale);
#else

/*
Expand Down Expand Up @@ -147,12 +147,12 @@ CreateCollationDDLInternal(Oid collationId, Oid *collowner, char **quotedCollati
*quotedCollationName, providerString);

#if PG_VERSION_NUM >= PG_VERSION_15
if (colliculocale)
if (colllocale)
{
appendStringInfo(&collationNameDef,
", locale = %s",
quote_literal_cstr(colliculocale));
pfree(colliculocale);
quote_literal_cstr(colllocale));
pfree(colllocale);
}
else
{
Expand Down
7 changes: 7 additions & 0 deletions src/backend/distributed/commands/role.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static char * GetRoleNameFromDbRoleSetting(HeapTuple tuple,
TupleDesc DbRoleSettingDescription);
static char * GetDatabaseNameFromDbRoleSetting(HeapTuple tuple,
TupleDesc DbRoleSettingDescription);
#if PG_VERSION_NUM < PG_VERSION_17
static Node * makeStringConst(char *str, int location);
#endif
static Node * makeIntConst(int val, int location);
static Node * makeFloatConst(char *str, int location);
static const char * WrapQueryInAlterRoleIfExistsCall(const char *query, RoleSpec *role);
Expand Down Expand Up @@ -949,6 +951,8 @@ PreprocessCreateRoleStmt(Node *node, const char *queryString,
}


#if PG_VERSION_NUM < PG_VERSION_17

/*
* makeStringConst creates a Const Node that stores a given string
*
Expand All @@ -972,6 +976,9 @@ makeStringConst(char *str, int location)
}


#endif


/*
* makeIntConst creates a Const Node that stores a given integer
*
Expand Down
11 changes: 7 additions & 4 deletions src/backend/distributed/commands/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,15 @@ GetAlterIndexStatisticsCommands(Oid indexOid)
}

Form_pg_attribute targetAttr = (Form_pg_attribute) GETSTRUCT(attTuple);
if (targetAttr->attstattarget != DEFAULT_STATISTICS_TARGET)
int32 targetAttstattarget = getAttstattarget_compat(attTuple);
if (targetAttstattarget != DEFAULT_STATISTICS_TARGET)
{
char *indexNameWithSchema = generate_qualified_relation_name(indexOid);

char *command =
GenerateAlterIndexColumnSetStatsCommand(indexNameWithSchema,
targetAttr->attnum,
targetAttr->attstattarget);
targetAttstattarget);

alterIndexStatisticsCommandList =
lappend(alterIndexStatisticsCommandList,
Expand Down Expand Up @@ -773,9 +774,10 @@ CreateAlterCommandIfTargetNotDefault(Oid statsOid)
}

Form_pg_statistic_ext statisticsForm = (Form_pg_statistic_ext) GETSTRUCT(tup);
int16 currentStxstattarget = getStxstattarget_compat(tup);
ReleaseSysCache(tup);

if (statisticsForm->stxstattarget == -1)
if (currentStxstattarget == -1)
{
return NULL;
}
Expand All @@ -785,7 +787,8 @@ CreateAlterCommandIfTargetNotDefault(Oid statsOid)
char *schemaName = get_namespace_name(statisticsForm->stxnamespace);
char *statName = NameStr(statisticsForm->stxname);

alterStatsStmt->stxstattarget = statisticsForm->stxstattarget;
alterStatsStmt->stxstattarget = getAlterStatsStxstattarget_compat(
currentStxstattarget);
alterStatsStmt->defnames = list_make2(makeString(schemaName), makeString(statName));

return DeparseAlterStatisticsStmt((Node *) alterStatsStmt);
Expand Down
3 changes: 2 additions & 1 deletion src/backend/distributed/connection/connection_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,8 @@ WaitEventSetFromMultiConnectionStates(List *connections, int *waitCount)
*waitCount = 0;
}

WaitEventSet *waitEventSet = CreateWaitEventSet(CurrentMemoryContext, eventSetSize);
WaitEventSet *waitEventSet = CreateWaitEventSet(WaitEventSetTracker_compat,
eventSetSize);
EnsureReleaseResource((MemoryContextCallbackFunction) (&FreeWaitEventSet),
waitEventSet);

Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/connection/remote_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ BuildWaitEventSet(MultiConnection **allConnections, int totalConnectionCount,

/* allocate pending connections + 2 for the signal latch and postmaster death */
/* (CreateWaitEventSet makes room for pgwin32_signal_event automatically) */
WaitEventSet *waitEventSet = CreateWaitEventSet(CurrentMemoryContext,
WaitEventSet *waitEventSet = CreateWaitEventSet(WaitEventSetTracker_compat,
pendingConnectionCount + 2);

for (int connectionIndex = 0; connectionIndex < pendingConnectionCount;
Expand Down
18 changes: 15 additions & 3 deletions src/backend/distributed/deparser/citus_ruleutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@
if (attributeForm->attidentity && includeIdentityDefaults)
{
bool missing_ok = false;
Oid seqOid = getIdentitySequence(RelationGetRelid(relation),
Oid seqOid = getIdentitySequence(identitySequenceRelation_compat(
relation),
attributeForm->attnum, missing_ok);

if (includeIdentityDefaults == INCLUDE_IDENTITY)
Expand Down Expand Up @@ -738,15 +739,26 @@
* If the user changed the column's statistics target, create
* alter statement and add statement to a list for later processing.
*/
if (attributeForm->attstattarget >= 0)
HeapTuple atttuple = SearchSysCache2(ATTNUM,
ObjectIdGetDatum(tableRelationId),
Int16GetDatum(attributeForm->attnum));
if (!HeapTupleIsValid(atttuple))
{
elog(ERROR, "cache lookup failed for attribute %d of relation %u",

Check warning on line 747 in src/backend/distributed/deparser/citus_ruleutils.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/deparser/citus_ruleutils.c#L747

Added line #L747 was not covered by tests
attributeForm->attnum, tableRelationId);
}

int32 targetAttstattarget = getAttstattarget_compat(atttuple);
ReleaseSysCache(atttuple);
if (targetAttstattarget >= 0)
{
StringInfoData statement = { NULL, 0, 0, 0 };
initStringInfo(&statement);

appendStringInfo(&statement, "ALTER COLUMN %s ",
quote_identifier(attributeName));
appendStringInfo(&statement, "SET STATISTICS %d",
attributeForm->attstattarget);
targetAttstattarget);

columnOptionList = lappend(columnOptionList, statement.data);
}
Expand Down
5 changes: 3 additions & 2 deletions src/backend/distributed/deparser/deparse_statistics_stmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ AppendAlterStatisticsSchemaStmt(StringInfo buf, AlterObjectSchemaStmt *stmt)
static void
AppendAlterStatisticsStmt(StringInfo buf, AlterStatsStmt *stmt)
{
appendStringInfo(buf, "ALTER STATISTICS %s SET STATISTICS %d", NameListToQuotedString(
stmt->defnames), stmt->stxstattarget);
appendStringInfo(buf, "ALTER STATISTICS %s SET STATISTICS %d",
NameListToQuotedString(stmt->defnames),
getIntStxstattarget_compat(stmt->stxstattarget));
}


Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/executor/adaptive_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -4740,7 +4740,7 @@ BuildWaitEventSet(List *sessionList)
int eventSetSize = GetEventSetSize(sessionList);

WaitEventSet *waitEventSet =
CreateWaitEventSet(CurrentMemoryContext, eventSetSize);
CreateWaitEventSet(WaitEventSetTracker_compat, eventSetSize);

WorkerSession *session = NULL;
foreach_declared_ptr(session, sessionList)
Expand Down
3 changes: 0 additions & 3 deletions src/backend/distributed/executor/query_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,6 @@ citus_query_stats(PG_FUNCTION_ARGS)

LWLockRelease(queryStats->lock);

/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);

return (Datum) 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/planner/merge_planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ FetchAndValidateInsertVarIfExists(Oid targetRelationId, Query *query)
foreach_declared_ptr(action, query->mergeActionList)
{
/* Skip MATCHED clause as INSERTS are not allowed in it */
if (action->matched)
if (matched_compat(action))
{
continue;
}
Expand Down
Loading
Loading