Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit db1071d

Browse files
committed
Fix some minor issues exposed by outfuncs/readfuncs testing.
A test patch to pass parse and plan trees through outfuncs + readfuncs exposed several issues that need to be fixed to get clean matches: Query.withCheckOptions failed to get copied; it's intentionally ignored by outfuncs/readfuncs on the grounds that it'd always be NIL anyway in stored rules. This seems less than future-proof, and it's not even saving very much, so just undo the decision and treat the field like all others. Several places that convert a view RTE into a subquery RTE, or similar manipulations, failed to clear out fields that were specific to the original RTE type and should be zero in a subquery RTE. Since readfuncs.c will leave such fields as zero, equalfuncs.c thinks the nodes are different leading to a reported mismatch. It seems like a good idea to clear out the no-longer-needed fields, even though in principle nothing should look at them; the node ought to be indistinguishable from how it would look if we'd built a new node instead of scribbling on the old one. BuildOnConflictExcludedTargetlist randomly set the resname of some TargetEntries to "" not NULL. outfuncs/readfuncs don't distinguish those cases, and so the string will read back in as NULL ... but equalfuncs.c does distinguish. Perhaps we ought to try to make things more consistent in this area --- but it's just useless extra code space for BuildOnConflictExcludedTargetlist to not use NULL here, so I fixed it for now by making it do that. catversion bumped because the change in handling of Query.withCheckOptions affects stored rules. Discussion: https://postgr.es/m/17114.1537138992@sss.pgh.pa.us
1 parent 09991e5 commit db1071d

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

src/backend/nodes/outfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,7 @@ _outQuery(StringInfo str, const Query *node)
30033003
WRITE_NODE_FIELD(rowMarks);
30043004
WRITE_NODE_FIELD(setOperations);
30053005
WRITE_NODE_FIELD(constraintDeps);
3006-
/* withCheckOptions intentionally omitted, see comment in parsenodes.h */
3006+
WRITE_NODE_FIELD(withCheckOptions);
30073007
WRITE_LOCATION_FIELD(stmt_location);
30083008
WRITE_LOCATION_FIELD(stmt_len);
30093009
}

src/backend/nodes/readfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ _readQuery(void)
269269
READ_NODE_FIELD(rowMarks);
270270
READ_NODE_FIELD(setOperations);
271271
READ_NODE_FIELD(constraintDeps);
272-
/* withCheckOptions intentionally omitted, see comment in parsenodes.h */
272+
READ_NODE_FIELD(withCheckOptions);
273273
READ_LOCATION_FIELD(stmt_location);
274274
READ_LOCATION_FIELD(stmt_len);
275275

src/backend/optimizer/prep/prepjointree.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,13 @@ inline_set_returning_functions(PlannerInfo *root)
586586
funcquery = inline_set_returning_function(root, rte);
587587
if (funcquery)
588588
{
589-
/* Successful expansion, replace the rtable entry */
589+
/* Successful expansion, convert the RTE to a subquery */
590590
rte->rtekind = RTE_SUBQUERY;
591591
rte->subquery = funcquery;
592+
rte->security_barrier = false;
593+
/* Clear fields that should not be set in a subquery RTE */
592594
rte->functions = NIL;
595+
rte->funcordinality = false;
593596
}
594597
}
595598
}

src/backend/parser/analyze.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ BuildOnConflictExcludedTargetlist(Relation targetrel,
11161116
* the Const claims to be.
11171117
*/
11181118
var = (Var *) makeNullConst(INT4OID, -1, InvalidOid);
1119-
name = "";
1119+
name = NULL;
11201120
}
11211121
else
11221122
{

src/backend/rewrite/rewriteHandler.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -1582,15 +1582,18 @@ ApplyRetrieveRule(Query *parsetree,
15821582
rule_action = fireRIRrules(rule_action, activeRIRs);
15831583

15841584
/*
1585-
* Now, plug the view query in as a subselect, replacing the relation's
1586-
* original RTE.
1585+
* Now, plug the view query in as a subselect, converting the relation's
1586+
* original RTE to a subquery RTE.
15871587
*/
15881588
rte = rt_fetch(rt_index, parsetree->rtable);
15891589

15901590
rte->rtekind = RTE_SUBQUERY;
1591-
rte->relid = InvalidOid;
1592-
rte->security_barrier = RelationIsSecurityView(relation);
15931591
rte->subquery = rule_action;
1592+
rte->security_barrier = RelationIsSecurityView(relation);
1593+
/* Clear fields that should not be set in a subquery RTE */
1594+
rte->relid = InvalidOid;
1595+
rte->relkind = 0;
1596+
rte->tablesample = NULL;
15941597
rte->inh = false; /* must not be set for a subquery */
15951598

15961599
/*

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201809052
56+
#define CATALOG_VERSION_NO 201809181
5757

5858
#endif

src/include/nodes/parsenodes.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ typedef struct Query
168168
List *constraintDeps; /* a list of pg_constraint OIDs that the query
169169
* depends on to be semantically valid */
170170

171-
List *withCheckOptions; /* a list of WithCheckOption's, which are
172-
* only added during rewrite and therefore
173-
* are not written out as part of Query. */
171+
List *withCheckOptions; /* a list of WithCheckOption's (added
172+
* during rewrite) */
174173

175174
/*
176175
* The following two fields identify the portion of the source text string

0 commit comments

Comments
 (0)