aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes/readfuncs.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2016-02-12 09:31:16 -0500
committerRobert Haas <rhaas@postgresql.org>2016-02-12 09:38:11 -0500
commitbcac23de73b89b001fbc628d84471a392e928d1c (patch)
tree91e5ec8553f54fbeef109eff48f86f8d47dfcf2a /src/backend/nodes/readfuncs.c
parent63461a63f94a333eae272be3d44ae1602cda75cb (diff)
downloadpostgresql-bcac23de73b89b001fbc628d84471a392e928d1c.tar.gz
postgresql-bcac23de73b89b001fbc628d84471a392e928d1c.zip
Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodename field identifies it more specifically; it may also include arbitrary private data. Extensible nodes can be copied, tested for equality, serialized, and deserialized, but the core system doesn't know anything about them otherwise. Some extensions may find it useful to include these nodes in fdw_private or custom_private lists in lieu of arm-wrestling their data into a format that the core code can understand. Along the way, so as not to burden the authors of such extensible node types too much, expose the functions for writing serialized tokens, and for serializing and deserializing bitmapsets. KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freund and by me, and further edited by me.
Diffstat (limited to 'src/backend/nodes/readfuncs.c')
-rw-r--r--src/backend/nodes/readfuncs.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index e4d41ee95b2..e6e6f2981c2 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -29,6 +29,7 @@
#include <math.h>
#include "fmgr.h"
+#include "nodes/extensible.h"
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h"
#include "nodes/readfuncs.h"
@@ -218,6 +219,14 @@ _readBitmapset(void)
return result;
}
+/*
+ * for use by extensions which define extensible nodes
+ */
+Bitmapset *
+readBitmapset(void)
+{
+ return _readBitmapset();
+}
/*
* _readQuery
@@ -2220,6 +2229,35 @@ _readAlternativeSubPlan(void)
}
/*
+ * _readExtensibleNode
+ */
+static ExtensibleNode *
+_readExtensibleNode(void)
+{
+ const ExtensibleNodeMethods *methods;
+ ExtensibleNode *local_node;
+ const char *extnodename;
+ READ_TEMP_LOCALS();
+
+ token = pg_strtok(&length); /* skip: extnodename */
+ token = pg_strtok(&length); /* get extnodename */
+
+ extnodename = nullable_string(token, length);
+ if (!extnodename)
+ elog(ERROR, "extnodename has to be supplied");
+ methods = GetExtensibleNodeMethods(extnodename, false);
+
+ local_node = (ExtensibleNode *) newNode(methods->node_size,
+ T_ExtensibleNode);
+ local_node->extnodename = extnodename;
+
+ /* deserialize the private fields */
+ methods->nodeRead(local_node);
+
+ READ_DONE();
+}
+
+/*
* parseNodeString
*
* Given a character string representing a node tree, parseNodeString creates
@@ -2447,6 +2485,8 @@ parseNodeString(void)
return_value = _readSubPlan();
else if (MATCH("ALTERNATIVESUBPLAN", 18))
return_value = _readAlternativeSubPlan();
+ else if (MATCH("EXTENSIBLENODE", 14))
+ return_value = _readExtensibleNode();
else
{
elog(ERROR, "badly formatted node string \"%.32s\"...", token);