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

Commit465e09d

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 overevery basic DML statement submitted to parse analysis. If we'd had thisin place earlier, bug #14153 would have been caught by buildfarm testing.The difficulty is that raw_expression_tree_walker() is only used inlimited cases involving CTEs (particularly recursive ones), so it'svery easy for an oversight in it to not be noticed during testing of aseemingly-unrelated feature.The type of error we can expect to catch with this is complete omissionof a node type from raw_expression_tree_walker(), and perhaps alsorecursion into a field that doesn't contain a node tree, though thatwould be an unlikely mistake. It won't catch failure to add new fieldsthat need to be recursed into, unfortunately.I'll go enable this on one or two of my own buildfarm animals oncebug #14153 is dealt with.Discussion: <27861.1464040417@sss.pgh.pa.us>
1 parent8a4930e commit465e09d

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
staticvoidtransformLockingClause(ParseState*pstate,Query*qry,
7676
LockingClause*lc,boolpushedDown);
77+
#ifdefRAW_EXPRESSION_COVERAGE_TEST
78+
staticbooltest_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+
#ifdefRAW_EXPRESSION_COVERAGE_TEST
232+
switch (nodeTag(parseTree))
233+
{
234+
caseT_SelectStmt:
235+
caseT_InsertStmt:
236+
caseT_UpdateStmt:
237+
caseT_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+
#ifdefRAW_EXPRESSION_COVERAGE_TEST
2748+
2749+
staticbool
2750+
test_raw_expression_coverage(Node*node,void*context)
2751+
{
2752+
if (node==NULL)
2753+
return false;
2754+
returnraw_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)

[8]ページ先頭

©2009-2025 Movatter.jp