mirror of
https://github.com/postgres/postgres.git
synced 2025-11-01 21:31:19 +03:00
Improve parse representation for MERGE
Separation of parser data structures from executor, as requested by Tom Lane. Further improvements possible. While there, implement error for multiple VALUES clauses via parser to allow line number of error, as requested by Andres Freund. Author: Pavan Deolasee Discussion: https://www.postgresql.org/message-id/CABOikdPpqjectFchg0FyTOpsGXyPoqwgC==OLKWuxgBOsrDDZw@mail.gmail.com
This commit is contained in:
@@ -2136,6 +2136,20 @@ _copyOnConflictExpr(const OnConflictExpr *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static MergeAction *
|
||||
_copyMergeAction(const MergeAction *from)
|
||||
{
|
||||
MergeAction *newnode = makeNode(MergeAction);
|
||||
|
||||
COPY_SCALAR_FIELD(matched);
|
||||
COPY_SCALAR_FIELD(commandType);
|
||||
COPY_SCALAR_FIELD(override);
|
||||
COPY_NODE_FIELD(qual);
|
||||
COPY_NODE_FIELD(targetList);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* ****************************************************************
|
||||
* relation.h copy functions
|
||||
*
|
||||
@@ -3054,24 +3068,24 @@ _copyMergeStmt(const MergeStmt *from)
|
||||
COPY_NODE_FIELD(relation);
|
||||
COPY_NODE_FIELD(source_relation);
|
||||
COPY_NODE_FIELD(join_condition);
|
||||
COPY_NODE_FIELD(mergeActionList);
|
||||
COPY_NODE_FIELD(mergeWhenClauses);
|
||||
COPY_NODE_FIELD(withClause);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static MergeAction *
|
||||
_copyMergeAction(const MergeAction *from)
|
||||
static MergeWhenClause *
|
||||
_copyMergeWhenClause(const MergeWhenClause *from)
|
||||
{
|
||||
MergeAction *newnode = makeNode(MergeAction);
|
||||
MergeWhenClause *newnode = makeNode(MergeWhenClause);
|
||||
|
||||
COPY_SCALAR_FIELD(matched);
|
||||
COPY_SCALAR_FIELD(commandType);
|
||||
COPY_NODE_FIELD(condition);
|
||||
COPY_NODE_FIELD(qual);
|
||||
COPY_NODE_FIELD(stmt);
|
||||
COPY_NODE_FIELD(targetList);
|
||||
|
||||
COPY_NODE_FIELD(cols);
|
||||
COPY_NODE_FIELD(values);
|
||||
COPY_SCALAR_FIELD(override);
|
||||
return newnode;
|
||||
}
|
||||
|
||||
@@ -5059,6 +5073,9 @@ copyObjectImpl(const void *from)
|
||||
case T_OnConflictExpr:
|
||||
retval = _copyOnConflictExpr(from);
|
||||
break;
|
||||
case T_MergeAction:
|
||||
retval = _copyMergeAction(from);
|
||||
break;
|
||||
|
||||
/*
|
||||
* RELATION NODES
|
||||
@@ -5140,8 +5157,8 @@ copyObjectImpl(const void *from)
|
||||
case T_MergeStmt:
|
||||
retval = _copyMergeStmt(from);
|
||||
break;
|
||||
case T_MergeAction:
|
||||
retval = _copyMergeAction(from);
|
||||
case T_MergeWhenClause:
|
||||
retval = _copyMergeWhenClause(from);
|
||||
break;
|
||||
case T_SelectStmt:
|
||||
retval = _copySelectStmt(from);
|
||||
|
||||
@@ -812,6 +812,18 @@ _equalOnConflictExpr(const OnConflictExpr *a, const OnConflictExpr *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
_equalMergeAction(const MergeAction *a, const MergeAction *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(matched);
|
||||
COMPARE_SCALAR_FIELD(commandType);
|
||||
COMPARE_SCALAR_FIELD(override);
|
||||
COMPARE_NODE_FIELD(qual);
|
||||
COMPARE_NODE_FIELD(targetList);
|
||||
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* Stuff from relation.h
|
||||
*/
|
||||
@@ -1050,21 +1062,22 @@ _equalMergeStmt(const MergeStmt *a, const MergeStmt *b)
|
||||
COMPARE_NODE_FIELD(relation);
|
||||
COMPARE_NODE_FIELD(source_relation);
|
||||
COMPARE_NODE_FIELD(join_condition);
|
||||
COMPARE_NODE_FIELD(mergeActionList);
|
||||
COMPARE_NODE_FIELD(mergeWhenClauses);
|
||||
COMPARE_NODE_FIELD(withClause);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalMergeAction(const MergeAction *a, const MergeAction *b)
|
||||
_equalMergeWhenClause(const MergeWhenClause *a, const MergeWhenClause *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(matched);
|
||||
COMPARE_SCALAR_FIELD(commandType);
|
||||
COMPARE_NODE_FIELD(condition);
|
||||
COMPARE_NODE_FIELD(qual);
|
||||
COMPARE_NODE_FIELD(stmt);
|
||||
COMPARE_NODE_FIELD(targetList);
|
||||
COMPARE_NODE_FIELD(cols);
|
||||
COMPARE_NODE_FIELD(values);
|
||||
COMPARE_SCALAR_FIELD(override);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -3192,6 +3205,9 @@ equal(const void *a, const void *b)
|
||||
case T_OnConflictExpr:
|
||||
retval = _equalOnConflictExpr(a, b);
|
||||
break;
|
||||
case T_MergeAction:
|
||||
retval = _equalMergeAction(a, b);
|
||||
break;
|
||||
case T_JoinExpr:
|
||||
retval = _equalJoinExpr(a, b);
|
||||
break;
|
||||
@@ -3263,8 +3279,8 @@ equal(const void *a, const void *b)
|
||||
case T_MergeStmt:
|
||||
retval = _equalMergeStmt(a, b);
|
||||
break;
|
||||
case T_MergeAction:
|
||||
retval = _equalMergeAction(a, b);
|
||||
case T_MergeWhenClause:
|
||||
retval = _equalMergeWhenClause(a, b);
|
||||
break;
|
||||
case T_SelectStmt:
|
||||
retval = _equalSelectStmt(a, b);
|
||||
|
||||
@@ -3444,19 +3444,23 @@ raw_expression_tree_walker(Node *node,
|
||||
return true;
|
||||
if (walker(stmt->join_condition, context))
|
||||
return true;
|
||||
if (walker(stmt->mergeActionList, context))
|
||||
if (walker(stmt->mergeWhenClauses, context))
|
||||
return true;
|
||||
if (walker(stmt->withClause, context))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case T_MergeAction:
|
||||
case T_MergeWhenClause:
|
||||
{
|
||||
MergeAction *action = (MergeAction *) node;
|
||||
MergeWhenClause *mergeWhenClause = (MergeWhenClause *) node;
|
||||
|
||||
if (walker(action->targetList, context))
|
||||
if (walker(mergeWhenClause->condition, context))
|
||||
return true;
|
||||
if (walker(action->qual, context))
|
||||
if (walker(mergeWhenClause->targetList, context))
|
||||
return true;
|
||||
if (walker(mergeWhenClause->cols, context))
|
||||
return true;
|
||||
if (walker(mergeWhenClause->values, context))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -396,16 +396,17 @@ _outModifyTable(StringInfo str, const ModifyTable *node)
|
||||
}
|
||||
|
||||
static void
|
||||
_outMergeAction(StringInfo str, const MergeAction *node)
|
||||
_outMergeWhenClause(StringInfo str, const MergeWhenClause *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("MERGEACTION");
|
||||
WRITE_NODE_TYPE("MERGEWHENCLAUSE");
|
||||
|
||||
WRITE_BOOL_FIELD(matched);
|
||||
WRITE_ENUM_FIELD(commandType, CmdType);
|
||||
WRITE_NODE_FIELD(condition);
|
||||
WRITE_NODE_FIELD(qual);
|
||||
WRITE_NODE_FIELD(stmt);
|
||||
WRITE_NODE_FIELD(targetList);
|
||||
WRITE_NODE_FIELD(cols);
|
||||
WRITE_NODE_FIELD(values);
|
||||
WRITE_ENUM_FIELD(override, OverridingKind);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1724,6 +1725,17 @@ _outOnConflictExpr(StringInfo str, const OnConflictExpr *node)
|
||||
WRITE_NODE_FIELD(exclRelTlist);
|
||||
}
|
||||
|
||||
static void
|
||||
_outMergeAction(StringInfo str, const MergeAction *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("MERGEACTION");
|
||||
|
||||
WRITE_BOOL_FIELD(matched);
|
||||
WRITE_ENUM_FIELD(commandType, CmdType);
|
||||
WRITE_NODE_FIELD(qual);
|
||||
WRITE_NODE_FIELD(targetList);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Stuff from relation.h.
|
||||
@@ -3679,8 +3691,8 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_ModifyTable:
|
||||
_outModifyTable(str, obj);
|
||||
break;
|
||||
case T_MergeAction:
|
||||
_outMergeAction(str, obj);
|
||||
case T_MergeWhenClause:
|
||||
_outMergeWhenClause(str, obj);
|
||||
break;
|
||||
case T_Append:
|
||||
_outAppend(str, obj);
|
||||
@@ -3958,6 +3970,9 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_OnConflictExpr:
|
||||
_outOnConflictExpr(str, obj);
|
||||
break;
|
||||
case T_MergeAction:
|
||||
_outMergeAction(str, obj);
|
||||
break;
|
||||
case T_Path:
|
||||
_outPath(str, obj);
|
||||
break;
|
||||
|
||||
@@ -1331,6 +1331,22 @@ _readOnConflictExpr(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readMergeAction
|
||||
*/
|
||||
static MergeAction *
|
||||
_readMergeAction(void)
|
||||
{
|
||||
READ_LOCALS(MergeAction);
|
||||
|
||||
READ_BOOL_FIELD(matched);
|
||||
READ_ENUM_FIELD(commandType, CmdType);
|
||||
READ_NODE_FIELD(qual);
|
||||
READ_NODE_FIELD(targetList);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* Stuff from parsenodes.h.
|
||||
*/
|
||||
@@ -1602,19 +1618,20 @@ _readModifyTable(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* _readMergeAction
|
||||
* _readMergeWhenClause
|
||||
*/
|
||||
static MergeAction *
|
||||
_readMergeAction(void)
|
||||
static MergeWhenClause *
|
||||
_readMergeWhenClause(void)
|
||||
{
|
||||
READ_LOCALS(MergeAction);
|
||||
READ_LOCALS(MergeWhenClause);
|
||||
|
||||
READ_BOOL_FIELD(matched);
|
||||
READ_ENUM_FIELD(commandType, CmdType);
|
||||
READ_NODE_FIELD(condition);
|
||||
READ_NODE_FIELD(qual);
|
||||
READ_NODE_FIELD(stmt);
|
||||
READ_NODE_FIELD(targetList);
|
||||
READ_NODE_FIELD(cols);
|
||||
READ_NODE_FIELD(values);
|
||||
READ_ENUM_FIELD(override, OverridingKind);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
@@ -2596,6 +2613,8 @@ parseNodeString(void)
|
||||
return_value = _readFromExpr();
|
||||
else if (MATCH("ONCONFLICTEXPR", 14))
|
||||
return_value = _readOnConflictExpr();
|
||||
else if (MATCH("MERGEACTION", 11))
|
||||
return_value = _readMergeAction();
|
||||
else if (MATCH("RTE", 3))
|
||||
return_value = _readRangeTblEntry();
|
||||
else if (MATCH("RANGETBLFUNCTION", 16))
|
||||
@@ -2618,8 +2637,8 @@ parseNodeString(void)
|
||||
return_value = _readProjectSet();
|
||||
else if (MATCH("MODIFYTABLE", 11))
|
||||
return_value = _readModifyTable();
|
||||
else if (MATCH("MERGEACTION", 11))
|
||||
return_value = _readMergeAction();
|
||||
else if (MATCH("MERGEWHENCLAUSE", 15))
|
||||
return_value = _readMergeWhenClause();
|
||||
else if (MATCH("APPEND", 6))
|
||||
return_value = _readAppend();
|
||||
else if (MATCH("MERGEAPPEND", 11))
|
||||
|
||||
Reference in New Issue
Block a user