From: Pavan Deolasee Date: Fri, 16 Jun 2017 07:07:03 +0000 (+0530) Subject: Handle NextValueExpr node correctly at various places. X-Git-Tag: XL_10_R1BETA1~270 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=0e9d70f6fbc88867960ec907e223201b638ec512;p=postgres-xl.git Handle NextValueExpr node correctly at various places. read/out functions for this node type were missing. So implement those functions. In addition, the FQS code path was not recongnizing this new node type correctly. Fix that too. The ruleutils also missed ability to deparse this expression. For now we just emit a DEFAULT clause while deparsing NextValueExpr and assume that the remote node will do the necessary lookups to find the correct sequence and invoke nextval() on the sequence. --- diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index b56b04a82f..1e1377f7b5 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -2532,6 +2532,22 @@ _outSQLValueFunction(StringInfo str, const SQLValueFunction *node) WRITE_LOCATION_FIELD(location); } +static void +_outNextValueExpr(StringInfo str, const NextValueExpr *node) +{ + WRITE_NODE_TYPE("NEXTVALUEEXPR"); + + if (portable_output) + { + WRITE_RELID_FIELD(seqid); + WRITE_TYPID_FIELD(typeId); + } + else + { + WRITE_OID_FIELD(seqid); + WRITE_OID_FIELD(typeId); + } +} static void _outXmlExpr(StringInfo str, const XmlExpr *node) { @@ -4959,6 +4975,9 @@ outNode(StringInfo str, const void *obj) case T_SQLValueFunction: _outSQLValueFunction(str, obj); break; + case T_NextValueExpr: + _outNextValueExpr(str, obj); + break; case T_XmlExpr: _outXmlExpr(str, obj); break; diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 935bb196f7..3219d00240 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -1667,6 +1667,27 @@ _readSQLValueFunction(void) READ_DONE(); } +/* + * _readNextValueExpr + */ +static NextValueExpr * +_readNextValueExpr(void) +{ + READ_LOCALS(NextValueExpr); + + if (portable_input) + { + READ_RELID_FIELD(seqid); + READ_TYPID_FIELD(typeId); + } + else + { + READ_OID_FIELD(seqid); + READ_OID_FIELD(typeId); + } + READ_DONE(); +} + /* * _readXmlExpr */ @@ -3888,6 +3909,8 @@ parseNodeString(void) return_value = _readMinMaxExpr(); else if (MATCH("SQLVALUEFUNCTION", 16)) return_value = _readSQLValueFunction(); + else if (MATCH("NEXTVALUEEXPR", 13)) + return_value = _readNextValueExpr(); else if (MATCH("XMLEXPR", 7)) return_value = _readXmlExpr(); else if (MATCH("NULLTEST", 8)) diff --git a/src/backend/optimizer/util/pgxcship.c b/src/backend/optimizer/util/pgxcship.c index aee3197ac3..6f26ec0264 100644 --- a/src/backend/optimizer/util/pgxcship.c +++ b/src/backend/optimizer/util/pgxcship.c @@ -815,6 +815,14 @@ pgxc_shippability_walker(Node *node, Shippability_context *sc_context) pgxc_set_exprtype_shippability(exprType(node), sc_context); break; + case T_NextValueExpr: + /* + * XXX PG10MERGE: Is it Ok to ship nextval when it's used for + * replica identity? + */ + pgxc_set_exprtype_shippability(exprType(node), sc_context); + break; + case T_Aggref: { Aggref *aggref = (Aggref *)node; diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index f5631e512e..a1a7edd589 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -8859,6 +8859,22 @@ get_rule_expr(Node *node, deparse_context *context, } break; + case T_NextValueExpr: + { + /* + * This gets invoked by Fast Query Shipping code to deparse a + * query. It seems enough to just generate a "DEFAULT" clause + * and let the remote datanode handle finding the correct + * sequence for replica identity. + * + * XXX PG10MERGE: If we do see issues with this, it might be + * worthwhile to consider generating an expression such as, + * nextval('sequence_name'::regclass) + */ + appendStringInfoString(buf, "DEFAULT"); + } + break; + case T_XmlExpr: { XmlExpr *xexpr = (XmlExpr *) node;