Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbcac23d

Browse files
committed
Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodenamefield identifies it more specifically; it may also include arbitraryprivate data. Extensible nodes can be copied, tested for equality,serialized, and deserialized, but the core system doesn't knowanything about them otherwise. Some extensions may find it useful toinclude these nodes in fdw_private or custom_private lists in lieu ofarm-wrestling their data into a format that the core code canunderstand.Along the way, so as not to burden the authors of such extensiblenode types too much, expose the functions for writing serializedtokens, and for serializing and deserializing bitmapsets.KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freundand by me, and further edited by me.
1 parent63461a6 commitbcac23d

File tree

8 files changed

+313
-1
lines changed

8 files changed

+313
-1
lines changed

‎src/backend/nodes/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ top_builddir = ../../..
1313
include$(top_builddir)/src/Makefile.global
1414

1515
OBJS = nodeFuncs.o nodes.o list.o bitmapset.o tidbitmap.o\
16-
copyfuncs.o equalfuncs.o makefuncs.o\
16+
copyfuncs.o equalfuncs.oextensible.omakefuncs.o\
1717
outfuncs.o readfuncs.o print.o read.o params.o value.o
1818

1919
include$(top_srcdir)/src/backend/common.mk

‎src/backend/nodes/copyfuncs.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"postgres.h"
2424

2525
#include"miscadmin.h"
26+
#include"nodes/extensible.h"
2627
#include"nodes/plannodes.h"
2728
#include"nodes/relation.h"
2829
#include"utils/datum.h"
@@ -4165,6 +4166,27 @@ _copyList(const List *from)
41654166
returnnew;
41664167
}
41674168

4169+
/* ****************************************************************
4170+
*extensible.h copy functions
4171+
* ****************************************************************
4172+
*/
4173+
staticExtensibleNode*
4174+
_copyExtensibleNode(constExtensibleNode*from)
4175+
{
4176+
ExtensibleNode*newnode;
4177+
constExtensibleNodeMethods*methods;
4178+
4179+
methods=GetExtensibleNodeMethods(from->extnodename, false);
4180+
newnode= (ExtensibleNode*)newNode(methods->node_size,
4181+
T_ExtensibleNode);
4182+
COPY_STRING_FIELD(extnodename);
4183+
4184+
/* copy the private fields */
4185+
methods->nodeCopy(newnode,from);
4186+
4187+
returnnewnode;
4188+
}
4189+
41684190
/* ****************************************************************
41694191
*value.h copy functions
41704192
* ****************************************************************
@@ -4544,6 +4566,13 @@ copyObject(const void *from)
45444566
retval=list_copy(from);
45454567
break;
45464568

4569+
/*
4570+
* EXTENSIBLE NODES
4571+
*/
4572+
caseT_ExtensibleNode:
4573+
retval=_copyExtensibleNode(from);
4574+
break;
4575+
45474576
/*
45484577
* PARSE NODES
45494578
*/

‎src/backend/nodes/equalfuncs.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include"postgres.h"
3131

32+
#include"nodes/extensible.h"
3233
#include"nodes/relation.h"
3334
#include"utils/datum.h"
3435

@@ -871,6 +872,25 @@ _equalPlaceHolderInfo(const PlaceHolderInfo *a, const PlaceHolderInfo *b)
871872
return true;
872873
}
873874

875+
/*
876+
* Stuff from extensible.h
877+
*/
878+
staticbool
879+
_equalExtensibleNode(constExtensibleNode*a,constExtensibleNode*b)
880+
{
881+
constExtensibleNodeMethods*methods;
882+
883+
COMPARE_STRING_FIELD(extnodename);
884+
885+
/* At this point, we know extnodename is the same for both nodes. */
886+
methods=GetExtensibleNodeMethods(a->extnodename, false);
887+
888+
/* compare the private fields */
889+
if (!methods->nodeEqual(a,b))
890+
return false;
891+
892+
return true;
893+
}
874894

875895
/*
876896
* Stuff from parsenodes.h
@@ -2873,6 +2893,13 @@ equal(const void *a, const void *b)
28732893
retval=_equalValue(a,b);
28742894
break;
28752895

2896+
/*
2897+
* EXTENSIBLE NODES
2898+
*/
2899+
caseT_ExtensibleNode:
2900+
retval=_equalExtensibleNode(a,b);
2901+
break;
2902+
28762903
/*
28772904
* PARSE NODES
28782905
*/

‎src/backend/nodes/extensible.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* extensible.c
4+
* Support for extensible node types
5+
*
6+
* Loadable modules can define what are in effect new types of nodes using
7+
* the routines in this file. All such nodes are flagged T_ExtensibleNode,
8+
* with the extnodename field distinguishing the specific type. Use
9+
* RegisterExtensibleNodeMethods to register a new type of extensible node,
10+
* and GetExtensibleNodeMethods to get information about a previously
11+
* registered type of extensible node.
12+
*
13+
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
14+
* Portions Copyright (c) 1994, Regents of the University of California
15+
*
16+
* IDENTIFICATION
17+
* src/backend/nodes/extensible.c
18+
*
19+
*-------------------------------------------------------------------------
20+
*/
21+
#include"postgres.h"
22+
23+
#include"nodes/extensible.h"
24+
#include"utils/hsearch.h"
25+
26+
staticHTAB*extensible_node_methods=NULL;
27+
28+
typedefstruct
29+
{
30+
charextnodename[EXTNODENAME_MAX_LEN];
31+
constExtensibleNodeMethods*methods;
32+
}ExtensibleNodeEntry;
33+
34+
/*
35+
* Register a new type of extensible node.
36+
*/
37+
void
38+
RegisterExtensibleNodeMethods(constExtensibleNodeMethods*methods)
39+
{
40+
ExtensibleNodeEntry*entry;
41+
boolfound;
42+
43+
if (extensible_node_methods==NULL)
44+
{
45+
HASHCTLctl;
46+
47+
memset(&ctl,0,sizeof(HASHCTL));
48+
ctl.keysize=NAMEDATALEN;
49+
ctl.entrysize=sizeof(ExtensibleNodeEntry);
50+
extensible_node_methods=hash_create("Extensible Node Methods",
51+
100,&ctl,HASH_ELEM);
52+
}
53+
54+
Assert(strlen(methods->extnodename) <=EXTNODENAME_MAX_LEN);
55+
56+
entry= (ExtensibleNodeEntry*)hash_search(extensible_node_methods,
57+
methods->extnodename,
58+
HASH_ENTER,&found);
59+
if (found)
60+
ereport(ERROR,
61+
(errcode(ERRCODE_DUPLICATE_OBJECT),
62+
errmsg("extensible node type \"%s\" already exists",
63+
methods->extnodename)));
64+
65+
entry->methods=methods;
66+
}
67+
68+
/*
69+
* Get the methods for a given type of extensible node.
70+
*/
71+
constExtensibleNodeMethods*
72+
GetExtensibleNodeMethods(constchar*extnodename,boolmissing_ok)
73+
{
74+
ExtensibleNodeEntry*entry=NULL;
75+
76+
if (extensible_node_methods!=NULL)
77+
entry= (ExtensibleNodeEntry*)hash_search(extensible_node_methods,
78+
extnodename,
79+
HASH_FIND,NULL);
80+
81+
if (!entry)
82+
{
83+
if (missing_ok)
84+
returnNULL;
85+
ereport(ERROR,
86+
(errcode(ERRCODE_UNDEFINED_OBJECT),
87+
errmsg("ExtensibleNodeMethods \"%s\" was not registered",
88+
extnodename)));
89+
}
90+
91+
returnentry->methods;
92+
}

‎src/backend/nodes/outfuncs.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include<ctype.h>
2727

2828
#include"lib/stringinfo.h"
29+
#include"nodes/extensible.h"
2930
#include"nodes/plannodes.h"
3031
#include"nodes/relation.h"
3132
#include"utils/datum.h"
@@ -140,6 +141,13 @@ _outToken(StringInfo str, const char *s)
140141
}
141142
}
142143

144+
/* for use by extensions which define extensible nodes */
145+
void
146+
outToken(StringInfostr,constchar*s)
147+
{
148+
_outToken(str,s);
149+
}
150+
143151
staticvoid
144152
_outList(StringInfostr,constList*node)
145153
{
@@ -196,6 +204,13 @@ _outBitmapset(StringInfo str, const Bitmapset *bms)
196204
appendStringInfoChar(str,')');
197205
}
198206

207+
/* for use by extensions which define extensible nodes */
208+
void
209+
outBitmapset(StringInfostr,constBitmapset*bms)
210+
{
211+
_outBitmapset(str,bms);
212+
}
213+
199214
/*
200215
* Print the value of a Datum given its type.
201216
*/
@@ -2112,6 +2127,27 @@ _outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
21122127
WRITE_INT_FIELD(paramId);
21132128
}
21142129

2130+
/*****************************************************************************
2131+
*
2132+
*Stuff from extensible.h
2133+
*
2134+
*****************************************************************************/
2135+
2136+
staticvoid
2137+
_outExtensibleNode(StringInfostr,constExtensibleNode*node)
2138+
{
2139+
constExtensibleNodeMethods*methods;
2140+
2141+
methods=GetExtensibleNodeMethods(node->extnodename, false);
2142+
2143+
WRITE_NODE_TYPE("EXTENSIBLENODE");
2144+
2145+
WRITE_STRING_FIELD(extnodename);
2146+
2147+
/* serialize the private fields */
2148+
methods->nodeOut(str,node);
2149+
}
2150+
21152151
/*****************************************************************************
21162152
*
21172153
*Stuff from parsenodes.h.
@@ -3367,6 +3403,10 @@ _outNode(StringInfo str, const void *obj)
33673403
_outPlannerParamItem(str,obj);
33683404
break;
33693405

3406+
caseT_ExtensibleNode:
3407+
_outExtensibleNode(str,obj);
3408+
break;
3409+
33703410
caseT_CreateStmt:
33713411
_outCreateStmt(str,obj);
33723412
break;

‎src/backend/nodes/readfuncs.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include<math.h>
3030

3131
#include"fmgr.h"
32+
#include"nodes/extensible.h"
3233
#include"nodes/parsenodes.h"
3334
#include"nodes/plannodes.h"
3435
#include"nodes/readfuncs.h"
@@ -218,6 +219,14 @@ _readBitmapset(void)
218219
returnresult;
219220
}
220221

222+
/*
223+
* for use by extensions which define extensible nodes
224+
*/
225+
Bitmapset*
226+
readBitmapset(void)
227+
{
228+
return_readBitmapset();
229+
}
221230

222231
/*
223232
* _readQuery
@@ -2219,6 +2228,35 @@ _readAlternativeSubPlan(void)
22192228
READ_DONE();
22202229
}
22212230

2231+
/*
2232+
* _readExtensibleNode
2233+
*/
2234+
staticExtensibleNode*
2235+
_readExtensibleNode(void)
2236+
{
2237+
constExtensibleNodeMethods*methods;
2238+
ExtensibleNode*local_node;
2239+
constchar*extnodename;
2240+
READ_TEMP_LOCALS();
2241+
2242+
token=pg_strtok(&length);/* skip: extnodename */
2243+
token=pg_strtok(&length);/* get extnodename */
2244+
2245+
extnodename=nullable_string(token,length);
2246+
if (!extnodename)
2247+
elog(ERROR,"extnodename has to be supplied");
2248+
methods=GetExtensibleNodeMethods(extnodename, false);
2249+
2250+
local_node= (ExtensibleNode*)newNode(methods->node_size,
2251+
T_ExtensibleNode);
2252+
local_node->extnodename=extnodename;
2253+
2254+
/* deserialize the private fields */
2255+
methods->nodeRead(local_node);
2256+
2257+
READ_DONE();
2258+
}
2259+
22222260
/*
22232261
* parseNodeString
22242262
*
@@ -2447,6 +2485,8 @@ parseNodeString(void)
24472485
return_value=_readSubPlan();
24482486
elseif (MATCH("ALTERNATIVESUBPLAN",18))
24492487
return_value=_readAlternativeSubPlan();
2488+
elseif (MATCH("EXTENSIBLENODE",14))
2489+
return_value=_readExtensibleNode();
24502490
else
24512491
{
24522492
elog(ERROR,"badly formatted node string \"%.32s\"...",token);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp