diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-02-12 09:31:16 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-02-12 09:38:11 -0500 |
commit | bcac23de73b89b001fbc628d84471a392e928d1c (patch) | |
tree | 91e5ec8553f54fbeef109eff48f86f8d47dfcf2a /src/include/nodes/extensible.h | |
parent | 63461a63f94a333eae272be3d44ae1602cda75cb (diff) | |
download | postgresql-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/include/nodes/extensible.h')
-rw-r--r-- | src/include/nodes/extensible.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/include/nodes/extensible.h b/src/include/nodes/extensible.h new file mode 100644 index 00000000000..96ae7bc9291 --- /dev/null +++ b/src/include/nodes/extensible.h @@ -0,0 +1,72 @@ +/*------------------------------------------------------------------------- + * + * extensible.h + * Definitions for extensible node type + * + * + * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/extensible.h + * + *------------------------------------------------------------------------- + */ +#ifndef EXTENSIBLE_H +#define EXTENSIBLE_H + +#include "nodes/nodes.h" + +#define EXTNODENAME_MAX_LEN 64 + +/* + * An extensible node is a new type of node defined by an extension. The + * type is always T_ExtensibleNode, while the extnodename identifies the + * specific type of node. extnodename can be looked up to find the + * ExtensibleNodeMethods for this node type. + */ +typedef struct ExtensibleNode +{ + NodeTag type; + const char *extnodename; /* identifier of ExtensibleNodeMethods */ +} ExtensibleNode; + +/* + * node_size is the size of an extensible node of this type in bytes. + * + * nodeCopy is a function which performs a deep copy from oldnode to newnode. + * It does not need to copy type or extnodename, which are copied by the + * core system. + * + * nodeEqual is a function which performs a deep equality comparison between + * a and b and returns true or false accordingly. It does not need to compare + * type or extnodename, which are compared by the core system. + * + * nodeOut is a serialization function for the node type. It should use the + * output conventions typical for outfuncs.c. It does not need to output + * type or extnodename; the core system handles those. + * + * nodeRead is a deserialization function for the node type. It does not need + * to read type or extnodename; the core system handles those. It should fetch + * the next token using pg_strtok() from the current input stream, and then + * reconstruct the private fields according to the manner in readfuncs.c. + * + * All callbacks are mandatory. + */ +typedef struct ExtensibleNodeMethods +{ + const char *extnodename; + Size node_size; + void (*nodeCopy)(struct ExtensibleNode *newnode, + const struct ExtensibleNode *oldnode); + bool (*nodeEqual)(const struct ExtensibleNode *a, + const struct ExtensibleNode *b); + void (*nodeOut)(struct StringInfoData *str, + const struct ExtensibleNode *node); + void (*nodeRead)(struct ExtensibleNode *node); +} ExtensibleNodeMethods; + +extern void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods *method); +extern const ExtensibleNodeMethods *GetExtensibleNodeMethods(const char *name, + bool missing_ok); + +#endif /* EXTENSIBLE_H */ |