1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

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.
This commit is contained in:
Robert Haas
2016-02-12 09:31:16 -05:00
parent 63461a63f9
commit bcac23de73
8 changed files with 313 additions and 1 deletions

View File

@ -26,6 +26,7 @@
#include <ctype.h>
#include "lib/stringinfo.h"
#include "nodes/extensible.h"
#include "nodes/plannodes.h"
#include "nodes/relation.h"
#include "utils/datum.h"
@ -140,6 +141,13 @@ _outToken(StringInfo str, const char *s)
}
}
/* for use by extensions which define extensible nodes */
void
outToken(StringInfo str, const char *s)
{
_outToken(str, s);
}
static void
_outList(StringInfo str, const List *node)
{
@ -196,6 +204,13 @@ _outBitmapset(StringInfo str, const Bitmapset *bms)
appendStringInfoChar(str, ')');
}
/* for use by extensions which define extensible nodes */
void
outBitmapset(StringInfo str, const Bitmapset *bms)
{
_outBitmapset(str, bms);
}
/*
* Print the value of a Datum given its type.
*/
@ -2112,6 +2127,27 @@ _outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
WRITE_INT_FIELD(paramId);
}
/*****************************************************************************
*
* Stuff from extensible.h
*
*****************************************************************************/
static void
_outExtensibleNode(StringInfo str, const ExtensibleNode *node)
{
const ExtensibleNodeMethods *methods;
methods = GetExtensibleNodeMethods(node->extnodename, false);
WRITE_NODE_TYPE("EXTENSIBLENODE");
WRITE_STRING_FIELD(extnodename);
/* serialize the private fields */
methods->nodeOut(str, node);
}
/*****************************************************************************
*
* Stuff from parsenodes.h.
@ -3367,6 +3403,10 @@ _outNode(StringInfo str, const void *obj)
_outPlannerParamItem(str, obj);
break;
case T_ExtensibleNode:
_outExtensibleNode(str, obj);
break;
case T_CreateStmt:
_outCreateStmt(str, obj);
break;