Skip to content

Commit ff33a8c

Browse files
committed
Remove artificial restrictions on which node types have out/read funcs.
The initial version of gen_node_support.pl manually excluded most utility statement node types from having out/read support, and also some raw-parse-tree-only node types. That was mostly to keep the output comparable to the old hand-maintained code. We'd like to have out/read support for utility statements, for debugging purposes and so that they can be included in new-style SQL functions; so it's time to lift that restriction. Most if not all of the previously-excluded raw-parse-tree-only node types can appear in expression subtrees of utility statements, so they have to be handled too. We don't quite have full read support yet; certain custom_read_write node types need to have their handwritten read functions implemented before that will work. Doing this allows us to drop the previous hack in _outQuery to not dump the utilityStmt field in most cases, which means we no longer need manually-maintained out/read functions for Query, so get rid of those in favor of auto-generating them. Fix a couple of omissions in gen_node_support.pl that are exposed through having to handle more node types. catversion bump forced because somebody was sloppy about the field order in the manually-maintained Query out/read functions. (Committers should note that almost all changes in parsenodes.h are now grounds for a catversion bump.)
1 parent 9c72736 commit ff33a8c

File tree

5 files changed

+19
-159
lines changed

5 files changed

+19
-159
lines changed

src/backend/nodes/gen_node_support.pl

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,6 @@ sub elem
166166
# currently not required.
167167
push @scalar_types, qw(QualCost);
168168

169-
# XXX various things we are not publishing right now to stay level
170-
# with the manual system
171-
push @no_read_write,
172-
qw(AccessPriv AlterTableCmd CreateOpClassItem FunctionParameter InferClause ObjectWithArgs OnConflictClause PartitionCmd RoleSpec VacuumRelation);
173-
push @no_read, qw(A_ArrayExpr A_Indices A_Indirection AlterStatsStmt
174-
CollateClause ColumnDef ColumnRef CreateForeignTableStmt CreateStatsStmt
175-
CreateStmt FuncCall ImportForeignSchemaStmt IndexElem IndexStmt
176-
JsonAggConstructor JsonArgument JsonArrayAgg JsonArrayConstructor
177-
JsonArrayQueryConstructor JsonCommon JsonFuncExpr JsonKeyValue
178-
JsonObjectAgg JsonObjectConstructor JsonOutput JsonParseExpr JsonScalarExpr
179-
JsonSerializeExpr JsonTable JsonTableColumn JsonTablePlan LockingClause
180-
MultiAssignRef PLAssignStmt ParamRef PartitionElem PartitionSpec
181-
PlaceHolderVar PublicationObjSpec PublicationTable RangeFunction
182-
RangeSubselect RangeTableFunc RangeTableFuncCol RangeTableSample RawStmt
183-
ResTarget ReturnStmt SelectStmt SortBy StatsElem TableLikeClause
184-
TriggerTransition TypeCast TypeName WindowDef WithClause XmlSerialize);
185-
186169

187170
## check that we have the expected number of files on the command line
188171
die "wrong number of input files, expected @all_input_files\n"
@@ -795,14 +778,6 @@ sub elem
795778
next if elem $n, @nodetag_only;
796779
next if elem $n, @no_read_write;
797780

798-
# XXX For now, skip all "Stmt"s except that ones that were there before.
799-
if ($n =~ /Stmt$/)
800-
{
801-
my @keep =
802-
qw(AlterStatsStmt CreateForeignTableStmt CreateStatsStmt CreateStmt DeclareCursorStmt ImportForeignSchemaStmt IndexStmt NotifyStmt PlannedStmt PLAssignStmt RawStmt ReturnStmt SelectStmt SetOperationStmt);
803-
next unless elem $n, @keep;
804-
}
805-
806781
my $no_read = (elem $n, @no_read);
807782

808783
# output format starts with upper case node type name
@@ -827,13 +802,20 @@ sub elem
827802
828803
";
829804

830-
print $rff "
805+
if (!$no_read)
806+
{
807+
my $macro =
808+
(@{ $node_type_info{$n}->{fields} } > 0)
809+
? 'READ_LOCALS'
810+
: 'READ_LOCALS_NO_FIELDS';
811+
print $rff "
831812
static $n *
832813
_read${n}(void)
833814
{
834-
\tREAD_LOCALS($n);
815+
\t$macro($n);
835816
836-
" unless $no_read;
817+
";
818+
}
837819

838820
# print instructions for each field
839821
foreach my $f (@{ $node_type_info{$n}->{fields} })
@@ -883,6 +865,7 @@ sub elem
883865
print $rff "\tREAD_LOCATION_FIELD($f);\n" unless $no_read;
884866
}
885867
elsif ($t eq 'int'
868+
|| $t eq 'int16'
886869
|| $t eq 'int32'
887870
|| $t eq 'AttrNumber'
888871
|| $t eq 'StrategyNumber')

src/backend/nodes/outfuncs.c

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -415,79 +415,6 @@ _outExtensibleNode(StringInfo str, const ExtensibleNode *node)
415415
methods->nodeOut(str, node);
416416
}
417417

418-
static void
419-
_outQuery(StringInfo str, const Query *node)
420-
{
421-
WRITE_NODE_TYPE("QUERY");
422-
423-
WRITE_ENUM_FIELD(commandType, CmdType);
424-
WRITE_ENUM_FIELD(querySource, QuerySource);
425-
/* we intentionally do not print the queryId field */
426-
WRITE_BOOL_FIELD(canSetTag);
427-
428-
/*
429-
* Hack to work around missing outfuncs routines for a lot of the
430-
* utility-statement node types. (The only one we actually *need* for
431-
* rules support is NotifyStmt.) Someday we ought to support 'em all, but
432-
* for the meantime do this to avoid getting lots of warnings when running
433-
* with debug_print_parse on.
434-
*/
435-
if (node->utilityStmt)
436-
{
437-
switch (nodeTag(node->utilityStmt))
438-
{
439-
case T_CreateStmt:
440-
case T_IndexStmt:
441-
case T_NotifyStmt:
442-
case T_DeclareCursorStmt:
443-
WRITE_NODE_FIELD(utilityStmt);
444-
break;
445-
default:
446-
appendStringInfoString(str, " :utilityStmt ?");
447-
break;
448-
}
449-
}
450-
else
451-
appendStringInfoString(str, " :utilityStmt <>");
452-
453-
WRITE_INT_FIELD(resultRelation);
454-
WRITE_BOOL_FIELD(hasAggs);
455-
WRITE_BOOL_FIELD(hasWindowFuncs);
456-
WRITE_BOOL_FIELD(hasTargetSRFs);
457-
WRITE_BOOL_FIELD(hasSubLinks);
458-
WRITE_BOOL_FIELD(hasDistinctOn);
459-
WRITE_BOOL_FIELD(hasRecursive);
460-
WRITE_BOOL_FIELD(hasModifyingCTE);
461-
WRITE_BOOL_FIELD(hasForUpdate);
462-
WRITE_BOOL_FIELD(hasRowSecurity);
463-
WRITE_BOOL_FIELD(isReturn);
464-
WRITE_NODE_FIELD(cteList);
465-
WRITE_NODE_FIELD(rtable);
466-
WRITE_NODE_FIELD(jointree);
467-
WRITE_NODE_FIELD(targetList);
468-
WRITE_ENUM_FIELD(override, OverridingKind);
469-
WRITE_NODE_FIELD(onConflict);
470-
WRITE_NODE_FIELD(returningList);
471-
WRITE_NODE_FIELD(groupClause);
472-
WRITE_BOOL_FIELD(groupDistinct);
473-
WRITE_NODE_FIELD(groupingSets);
474-
WRITE_NODE_FIELD(havingQual);
475-
WRITE_NODE_FIELD(windowClause);
476-
WRITE_NODE_FIELD(distinctClause);
477-
WRITE_NODE_FIELD(sortClause);
478-
WRITE_NODE_FIELD(limitOffset);
479-
WRITE_NODE_FIELD(limitCount);
480-
WRITE_ENUM_FIELD(limitOption, LimitOption);
481-
WRITE_NODE_FIELD(rowMarks);
482-
WRITE_NODE_FIELD(setOperations);
483-
WRITE_NODE_FIELD(constraintDeps);
484-
WRITE_NODE_FIELD(withCheckOptions);
485-
WRITE_NODE_FIELD(mergeActionList);
486-
WRITE_BOOL_FIELD(mergeUseOuterJoin);
487-
WRITE_LOCATION_FIELD(stmt_location);
488-
WRITE_INT_FIELD(stmt_len);
489-
}
490-
491418
static void
492419
_outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
493420
{

src/backend/nodes/readfuncs.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -240,56 +240,6 @@ readBitmapset(void)
240240
* special_read_write attribute
241241
*/
242242

243-
static Query *
244-
_readQuery(void)
245-
{
246-
READ_LOCALS(Query);
247-
248-
READ_ENUM_FIELD(commandType, CmdType);
249-
READ_ENUM_FIELD(querySource, QuerySource);
250-
local_node->queryId = UINT64CONST(0); /* not saved in output format */
251-
READ_BOOL_FIELD(canSetTag);
252-
READ_NODE_FIELD(utilityStmt);
253-
READ_INT_FIELD(resultRelation);
254-
READ_BOOL_FIELD(hasAggs);
255-
READ_BOOL_FIELD(hasWindowFuncs);
256-
READ_BOOL_FIELD(hasTargetSRFs);
257-
READ_BOOL_FIELD(hasSubLinks);
258-
READ_BOOL_FIELD(hasDistinctOn);
259-
READ_BOOL_FIELD(hasRecursive);
260-
READ_BOOL_FIELD(hasModifyingCTE);
261-
READ_BOOL_FIELD(hasForUpdate);
262-
READ_BOOL_FIELD(hasRowSecurity);
263-
READ_BOOL_FIELD(isReturn);
264-
READ_NODE_FIELD(cteList);
265-
READ_NODE_FIELD(rtable);
266-
READ_NODE_FIELD(jointree);
267-
READ_NODE_FIELD(targetList);
268-
READ_ENUM_FIELD(override, OverridingKind);
269-
READ_NODE_FIELD(onConflict);
270-
READ_NODE_FIELD(returningList);
271-
READ_NODE_FIELD(groupClause);
272-
READ_BOOL_FIELD(groupDistinct);
273-
READ_NODE_FIELD(groupingSets);
274-
READ_NODE_FIELD(havingQual);
275-
READ_NODE_FIELD(windowClause);
276-
READ_NODE_FIELD(distinctClause);
277-
READ_NODE_FIELD(sortClause);
278-
READ_NODE_FIELD(limitOffset);
279-
READ_NODE_FIELD(limitCount);
280-
READ_ENUM_FIELD(limitOption, LimitOption);
281-
READ_NODE_FIELD(rowMarks);
282-
READ_NODE_FIELD(setOperations);
283-
READ_NODE_FIELD(constraintDeps);
284-
READ_NODE_FIELD(withCheckOptions);
285-
READ_NODE_FIELD(mergeActionList);
286-
READ_BOOL_FIELD(mergeUseOuterJoin);
287-
READ_LOCATION_FIELD(stmt_location);
288-
READ_INT_FIELD(stmt_len);
289-
290-
READ_DONE();
291-
}
292-
293243
static Const *
294244
_readConst(void)
295245
{

src/include/catalog/catversion.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
* include/catalog is the most common kind of initdb-forcing change.
3333
* But it could be used to protect any kind of incompatible change in
3434
* database contents or layout, such as altering tuple headers.
35+
* Another common reason for a catversion update is a change in parsetree
36+
* external representation, since serialized parsetrees appear in stored
37+
* rules and new-style SQL functions. Almost any change in primnodes.h or
38+
* parsenodes.h will warrant a catversion update.
3539
*
3640
*
3741
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
@@ -53,6 +57,6 @@
5357
*/
5458

5559
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202207091
60+
#define CATALOG_VERSION_NO 202207131
5761

5862
#endif

src/include/nodes/parsenodes.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,17 @@ typedef uint32 AclMode; /* a bitmask of privilege bits */
117117
*/
118118
typedef struct Query
119119
{
120-
pg_node_attr(custom_read_write)
121-
122120
NodeTag type;
123121

124122
CmdType commandType; /* select|insert|update|delete|merge|utility */
125123

126124
QuerySource querySource; /* where did I come from? */
127125

128126
/*
129-
* query identifier (can be set by plugins); ignored for equal, might not
130-
* be set
127+
* query identifier (can be set by plugins); ignored for equal, as it
128+
* might not be set; also not stored
131129
*/
132-
uint64 queryId pg_node_attr(equal_ignore, read_as(0));
130+
uint64 queryId pg_node_attr(equal_ignore, read_write_ignore, read_as(0));
133131

134132
bool canSetTag; /* do I set the command result tag? */
135133

@@ -409,8 +407,6 @@ typedef struct FuncCall
409407
*/
410408
typedef struct A_Star
411409
{
412-
pg_node_attr(no_read)
413-
414410
NodeTag type;
415411
} A_Star;
416412

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy