8000 Add support for more extensive testing of raw_expression_tree_walker(). · prmdeveloper/postgres@465e09d · GitHub
[go: up one dir, main page]

Skip to content

Commit 465e09d

Browse files
committed
Add support for more extensive testing of raw_expression_tree_walker().
If RAW_EXPRESSION_COVERAGE_TEST is defined, do a no-op tree walk over every basic DML statement submitted to parse analysis. If we'd had this in place earlier, bug #14153 would have been caught by buildfarm testing. The difficulty is that raw_expression_tree_walker() is only used in limited cases involving CTEs (particularly recursive ones), so it's very easy for an oversight in it to not be noticed during testing of a seemingly-unrelated feature. The type of error we can expect to catch with this is complete omission of a node type from raw_expression_tree_walker(), and perhaps also recursion into a field that doesn't contain a node tree, though that would be an unlikely mistake. It won't catch failure to add new fields that need to be recursed into, unfortunately. I'll go enable this on one or two of my own buildfarm animals once bug #14153 is dealt with. Discussion: <27861.1464040417@sss.pgh.pa.us>
1 parent 8a4930e commit 465e09d

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

src/backend/nodes/nodeFuncs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,8 +2991,10 @@ query_or_expression_tree_mutator(Node *node,
29912991
* Unlike expression_tree_walker, there is no special rule about query
29922992
* boundaries: we descend to everything that's possibly interesting.
29932993
*
2994-
* Currently, the node type coverage extends to SelectStmt and everything
2995-
* that could appear under it, but not other statement types.
2994+
* Currently, the node type coverage here extends only to DML statements
2995+
* (SELECT/INSERT/UPDATE/DELETE) and nodes that can appear in them, because
2996+
* this is used mainly during analysis of CTEs, and only DML statements can
2997+
* appear in CTEs.
29962998
*/
29972999
bool
29983000
raw_expression_tree_walker(Node *node,

src/backend/parser/analyze.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ static Query *transformCreateTableAsStmt(ParseState *pstate,
7474
CreateTableAsStmt *stmt);
7575
static void transformLockingClause(ParseState *pstate, Query *qry,
7676
LockingClause *lc, bool pushedDown);
77+
#ifdef RAW_EXPRESSION_COVERAGE_TEST
78+
static bool test_raw_expression_coverage(Node *node, void *context);
79+
#endif
7780

7881

7982
/*
@@ -220,6 +223,25 @@ transformStmt(ParseState *pstate, Node *parseTree)
220223
{
221224
Query *result;
222225

226+
/*
227+
* We apply RAW_EXPRESSION_COVERAGE_TEST testing to basic DML statements;
228+
* we can't just run it on everything because raw_expression_tree_walker()
229+
* doesn't claim to handle utility statements.
230+
*/
231+
#ifdef RAW_EXPRESSION_COVERAGE_TEST
232+
switch (nodeTag(parseTree))
233+
{
234+
case T_SelectStmt:
235+
case T_InsertStmt:
236+
case T_UpdateStmt:
237+
case T_DeleteStmt:
238+
(void) test_raw_expression_coverage(parseTree, NULL);
239+
break;
240+
default:
241+
break;
242+
}
243+
#endif /* RAW_EXPRESSION_COVERAGE_TEST */
244+
223245
switch (nodeTag(parseTree))
224246
{
225247
/*
@@ -2713,3 +2735,25 @@ applyLockingClause(Query *qry, Index rtindex,
27132735
rc->pushedDown = pushedDown;
27142736
qry->rowMarks = lappend(qry->rowMarks, rc);
27152737
}
2738+
2739+
/*
2740+
* Coverage testing for raw_expression_tree_walker().
2741+
*
2742+
* When enabled, we run raw_expression_tree_walker() over every DML statement
2743+
* submitted to parse analysis. Without this provision, that function is only
2744+
* applied in limited cases involving CTEs, and we don't really want to have
2745+
* to test everything inside as well as outside a CTE.
2746+
*/
2747+
#ifdef RAW_EXPRESSION_COVERAGE_TEST
2748+
2749+
static bool
2750+
test_raw_expression_coverage(Node *node, void *context)
2751+
{
2752+
if (node == NULL)
2753+
return false;
2754+
return raw_expression_tree_walker(node,
2755+
test_raw_expression_coverage,
2756+
context);
2757+
}
2758+
2759+
#endif /* RAW_EXPRESSION_COVERAGE_TEST */

src/include/pg_config_manual.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@
273273
*/
274274
/* #define COPY_PARSE_PLAN_TREES */
275275

276+
/*
277+
* Define this to force all raw parse trees for DML statements to be scanned
278+
* by raw_expression_tree_walker(), to facilitate catching errors and
279+
* omissions in that function.
280+
*/
281+
/* #define RAW_EXPRESSION_COVERAGE_TEST */
282+
276283
/*
277284
* Enable debugging print statements for lock-related operations.
278285
*/

0 commit comments

Comments
 (0)
0