Handle NextValueExpr node correctly at various places.
authorPavan Deolasee <[email protected]>
Fri, 16 Jun 2017 07:07:03 +0000 (12:37 +0530)
committerPavan Deolasee <[email protected]>
Fri, 16 Jun 2017 07:07:03 +0000 (12:37 +0530)
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.

src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/util/pgxcship.c
src/backend/utils/adt/ruleutils.c

index b56b04a82fd0abbf23dd8c6b92192b2728b8ba36..1e1377f7b5712b237601630308ff46bc66ab38fb 100644 (file)
@@ -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;
index 935bb196f7bbf7bfcc410ac5cbdea242b143228d..3219d00240272e29ebfdfff2afaf031fcd4fb027 100644 (file)
@@ -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))
index aee3197ac38efb012a6c1cb6f0ead1fe4f97a6e3..6f26ec02647e2a35d058a2d7176607e1ed176b02 100644 (file)
@@ -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;
index f5631e512e7a5f2dbd4b11e9aa2f167b8fbb3475..a1a7edd58940376363456e28bdb00e5e8124d08a 100644 (file)
@@ -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;