diff options
author | Pavan Deolasee | 2017-06-16 07:07:03 +0000 |
---|---|---|
committer | Pavan Deolasee | 2017-06-16 07:07:03 +0000 |
commit | 0e9d70f6fbc88867960ec907e223201b638ec512 (patch) | |
tree | a161e64e819dd4876520a5c7af8b50c113b41d9b | |
parent | 45bf5f09260f4db988b0479179682a7e97cebd9e (diff) |
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.
-rw-r--r-- | src/backend/nodes/outfuncs.c | 19 | ||||
-rw-r--r-- | src/backend/nodes/readfuncs.c | 23 | ||||
-rw-r--r-- | src/backend/optimizer/util/pgxcship.c | 8 | ||||
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 16 |
4 files changed, 66 insertions, 0 deletions
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 @@ -2533,6 +2533,22 @@ _outSQLValueFunction(StringInfo str, const SQLValueFunction *node) } 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) { WRITE_NODE_TYPE("XMLEXPR"); @@ -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 @@ -1668,6 +1668,27 @@ _readSQLValueFunction(void) } /* + * _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 */ static XmlExpr * @@ -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; |