Fix compiler errors

pull/7781/head
Teja Mupparti 2024-12-06 14:08:05 -08:00 committed by naisila
parent 5e23685f42
commit fd1b475542
5 changed files with 71 additions and 24 deletions

View File

@ -157,6 +157,32 @@ CreateMergePlan(uint64 planId, Query *originalQuery, Query *query,
} }
/*
* GetMergeJoinConditionList returns all the Join conditions from the ON clause
*/
List *
GetMergeJoinConditionList(Query *mergeQuery)
{
#if PG_VERSION_NUM >= PG_VERSION_17
List *mergeJoinConditionList = NIL;
if (IsA(mergeQuery->mergeJoinCondition, List))
{
mergeJoinConditionList = (List *) mergeQuery->mergeJoinCondition;
}
else
{
Node *joinClause =
eval_const_expressions(NULL, mergeQuery->mergeJoinCondition);
joinClause = (Node *) canonicalize_qual((Expr *) joinClause, false);
mergeJoinConditionList = make_ands_implicit((Expr *) joinClause);
}
#else
List *mergeJoinConditionList = WhereClauseList(mergeQuery->jointree);
#endif
return mergeJoinConditionList;
}
#if PG_VERSION_NUM >= PG_VERSION_15 #if PG_VERSION_NUM >= PG_VERSION_15
/* /*
@ -563,7 +589,6 @@ MergeQualAndTargetListFunctionsSupported(Oid resultRelationId, Query *query,
List *targetList, CmdType commandType) List *targetList, CmdType commandType)
{ {
uint32 targetRangeTableIndex = query->resultRelation; uint32 targetRangeTableIndex = query->resultRelation;
FromExpr *joinTree = query->jointree;
Var *distributionColumn = NULL; Var *distributionColumn = NULL;
if (IsCitusTable(resultRelationId) && HasDistributionKey(resultRelationId)) if (IsCitusTable(resultRelationId) && HasDistributionKey(resultRelationId))
{ {
@ -601,7 +626,8 @@ MergeQualAndTargetListFunctionsSupported(Oid resultRelationId, Query *query,
} }
if (targetEntryDistributionColumn && if (targetEntryDistributionColumn &&
TargetEntryChangesValue(targetEntry, distributionColumn, joinTree)) TargetEntryChangesValue(targetEntry, distributionColumn, (Node *) query,
CMD_MERGE))
{ {
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED, return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"updating the distribution column is not " "updating the distribution column is not "
@ -723,8 +749,13 @@ ErrorIfRepartitionMergeNotSupported(Oid targetRelationId, Query *mergeQuery,
/* /*
* Sub-queries and CTEs are not allowed in actions and ON clause * Sub-queries and CTEs are not allowed in actions and ON clause
*/ */
if (FindNodeMatchingCheckFunction((Node *) mergeQuery->mergeJoinCondition, #if PG_VERSION_NUM >= PG_VERSION_17
IsNodeSubquery)) Node *joinCondition = (Node *) mergeQuery->mergeJoinCondition;
#else
Node *joinCondition = (Node *) mergeQuery->jointree->quals;
#endif
if (FindNodeMatchingCheckFunction(joinCondition, IsNodeSubquery))
{ {
ereport(ERROR, ereport(ERROR,
(errmsg("Sub-queries and CTEs are not allowed in ON clause for MERGE " (errmsg("Sub-queries and CTEs are not allowed in ON clause for MERGE "
@ -1224,11 +1255,17 @@ ErrorIfMergeQueryQualAndTargetListNotSupported(Oid targetRelationId, Query *orig
"supported in MERGE sql with distributed tables"))); "supported in MERGE sql with distributed tables")));
} }
#if PG_VERSION_NUM >= PG_VERSION_17
Node *joinCondition = (Node *) originalQuery->mergeJoinCondition;
#else
Node *joinCondition = (Node *) originalQuery->jointree->quals;
#endif
DeferredErrorMessage *deferredError = DeferredErrorMessage *deferredError =
MergeQualAndTargetListFunctionsSupported( MergeQualAndTargetListFunctionsSupported(
targetRelationId, targetRelationId,
originalQuery, originalQuery,
originalQuery->mergeJoinCondition, joinCondition,
originalQuery->targetList, originalQuery->targetList,
originalQuery->commandType); originalQuery->commandType);
@ -1304,20 +1341,7 @@ static int
SourceResultPartitionColumnIndex(Query *mergeQuery, List *sourceTargetList, SourceResultPartitionColumnIndex(Query *mergeQuery, List *sourceTargetList,
CitusTableCacheEntry *targetRelation) CitusTableCacheEntry *targetRelation)
{ {
/* Get all the Join conditions from the ON clause */ List *mergeJoinConditionList = GetMergeJoinConditionList(mergeQuery);
List *mergeJoinConditionList = NIL;
if (IsA(mergeQuery->mergeJoinCondition, List))
{
mergeJoinConditionList = (List *) mergeQuery->mergeJoinCondition;
}
else
{
Node *joinClause =
eval_const_expressions(NULL, mergeQuery->mergeJoinCondition);
joinClause = (Node *) canonicalize_qual((Expr *) joinClause, false);
mergeJoinConditionList = make_ands_implicit((Expr *) joinClause);
}
Var *targetColumn = targetRelation->partitionColumn; Var *targetColumn = targetRelation->partitionColumn;
Var *sourceRepartitionVar = NULL; Var *sourceRepartitionVar = NULL;
bool foundTypeMismatch = false; bool foundTypeMismatch = false;

View File

@ -597,9 +597,9 @@ TargetlistAndFunctionsSupported(Oid resultRelationId, FromExpr *joinTree, Node *
NULL, NULL); NULL, NULL);
} }
if (commandType == CMD_UPDATE && targetEntryPartitionColumn && if (targetEntryPartitionColumn &&
TargetEntryChangesValue(targetEntry, partitionColumn, TargetEntryChangesValue(targetEntry, partitionColumn,
joinTree)) (Node *) joinTree, commandType))
{ {
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED, return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"modifying the partition value of rows is not " "modifying the partition value of rows is not "
@ -1611,8 +1611,15 @@ MasterIrreducibleExpressionFunctionChecker(Oid func_id, void *context)
* tree, or the target entry sets a different column. * tree, or the target entry sets a different column.
*/ */
bool bool
TargetEntryChangesValue(TargetEntry *targetEntry, Var *column, FromExpr *joinTree) TargetEntryChangesValue(TargetEntry *targetEntry, Var *column, Node *node, CmdType
commandType)
{ {
if (commandType != CMD_UPDATE && commandType != CMD_MERGE)
{
/* no-op */
return false;
}
bool isColumnValueChanged = true; bool isColumnValueChanged = true;
Expr *setExpr = targetEntry->expr; Expr *setExpr = targetEntry->expr;
@ -1628,7 +1635,6 @@ TargetEntryChangesValue(TargetEntry *targetEntry, Var *column, FromExpr *joinTre
else if (IsA(setExpr, Const)) else if (IsA(setExpr, Const))
{ {
Const *newValue = (Const *) setExpr; Const *newValue = (Const *) setExpr;
List *restrictClauseList = WhereClauseList(joinTree);
OpExpr *equalityExpr = MakeOpExpression(column, BTEqualStrategyNumber); OpExpr *equalityExpr = MakeOpExpression(column, BTEqualStrategyNumber);
Node *rightOp = get_rightop((Expr *) equalityExpr); Node *rightOp = get_rightop((Expr *) equalityExpr);
@ -1640,6 +1646,16 @@ TargetEntryChangesValue(TargetEntry *targetEntry, Var *column, FromExpr *joinTre
rightConst->constisnull = newValue->constisnull; rightConst->constisnull = newValue->constisnull;
rightConst->constbyval = newValue->constbyval; rightConst->constbyval = newValue->constbyval;
List *restrictClauseList = NIL;
if (commandType == CMD_UPDATE)
{
restrictClauseList = WhereClauseList((FromExpr *) node);
}
else
{
restrictClauseList = GetMergeJoinConditionList((Query *) node);
}
bool predicateIsImplied = predicate_implied_by(list_make1(equalityExpr), bool predicateIsImplied = predicate_implied_by(list_make1(equalityExpr),
restrictClauseList, false); restrictClauseList, false);
if (predicateIsImplied) if (predicateIsImplied)

View File

@ -32,6 +32,7 @@ extern void NonPushableMergeCommandExplainScan(CustomScanState *node, List *ance
struct ExplainState *es); struct ExplainState *es);
extern Var * FetchAndValidateInsertVarIfExists(Oid targetRelationId, Query *query); extern Var * FetchAndValidateInsertVarIfExists(Oid targetRelationId, Query *query);
extern RangeTblEntry * ExtractMergeSourceRangeTableEntry(Query *query, bool joinSourceOk); extern RangeTblEntry * ExtractMergeSourceRangeTableEntry(Query *query, bool joinSourceOk);
extern List * GetMergeJoinConditionList(Query *mergeQuery);
#endif /* MERGE_PLANNER_H */ #endif /* MERGE_PLANNER_H */

View File

@ -111,7 +111,7 @@ extern DeferredErrorMessage * TargetlistAndFunctionsSupported(Oid resultRelation
List *returningList); List *returningList);
extern bool NodeIsFieldStore(Node *node); extern bool NodeIsFieldStore(Node *node);
extern bool TargetEntryChangesValue(TargetEntry *targetEntry, Var *column, extern bool TargetEntryChangesValue(TargetEntry *targetEntry, Var *column,
FromExpr *joinTree); Node *node, CmdType commandType);
extern bool MasterIrreducibleExpression(Node *expression, bool *varArgument, extern bool MasterIrreducibleExpression(Node *expression, bool *varArgument,
bool *badCoalesce); bool *badCoalesce);
extern bool HasDangerousJoinUsing(List *rtableList, Node *jtnode); extern bool HasDangerousJoinUsing(List *rtableList, Node *jtnode);

View File

@ -0,0 +1,6 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 15 AS server_version_ge_15
\gset
\if :server_version_ge_15
\else
\q