Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b4xnG-00084u-7l for pgsql-hackers@arkaria.postgresql.org; Mon, 23 May 2016 21:53:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b4xnF-0008AY-PQ for pgsql-hackers@arkaria.postgresql.org; Mon, 23 May 2016 21:53:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b4xnD-00089b-IA for pgsql-hackers@postgresql.org; Mon, 23 May 2016 21:53:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b4xnA-0002xx-TZ for pgsql-hackers@postgresql.org; Mon, 23 May 2016 21:53:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u4NLrb4Q027862; Mon, 23 May 2016 17:53:37 -0400 From: Tom Lane To: Peter Geoghegan cc: Thomas Alton , Pg Hackers Subject: Re: Re: [BUGS] BUG #14153: Unrecognized node type error when upsert is present in recursive CTE In-reply-to: References: <20160521232802.22598.13537@wrigleys.postgresql.org> <18383.1464031327@sss.pgh.pa.us> <20096.1464032918@sss.pgh.pa.us> <22866.1464036949@sss.pgh.pa.us> Comments: In-reply-to Peter Geoghegan message dated "Mon, 23 May 2016 14:07:20 -0700" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <27799.1464040302.0@sss.pgh.pa.us> Date: Mon, 23 May 2016 17:53:37 -0400 Message-ID: <27861.1464040417@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27799.1464040302.1@sss.pgh.pa.us> Peter Geoghegan writes: > What I meant is that I think naively adding the choke-point for a > top-level SelectStmt would do the job (although perhaps we could do > better). I wasn't suggesting that we'd avoid recursing from there; > only that we could reasonably avoid recursing from someplace else > (e.g. InsertStmt) in the hope of finding a SelectStmt to test. > Offhand, I don't imagine that that would offer better coverage. I think it would. The attached patch shows nearly 150 failures in the current regression tests. If I remove "case T_InsertStmt" that drops to two failures: there are two cases in with.sgml that almost manage to exercise the bug, but not quite because they are not WITH RECURSIVE. That doesn't leave me with any warm feeling about being able to find other similar oversights if we apply this testing only to top-level SelectStmts. >> If that sounds like a plausible choke-point, the next question is what >> to use to enable the debug test. I propose "#ifdef COPY_PARSE_PLAN_TREES" >> since that enables similar sanity checking for other parts of >> backend/nodes/, and we do have at least one buildfarm member using it. > That's what I was thinking, too. No need to keep it separate. After cogitating, I did it as attached just for readability's sake. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="raw-expression-coverage-test.patch"; charset="us-ascii" Content-ID: <27799.1464040302.2@sss.pgh.pa.us> Content-Description: raw-expression-coverage-test.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index 7bc5be1..92f3276 100644 *** a/src/backend/nodes/nodeFuncs.c --- b/src/backend/nodes/nodeFuncs.c *************** query_or_expression_tree_mutator(Node *n *** 2991,2998 **** * Unlike expression_tree_walker, there is no special rule about query * boundaries: we descend to everything that's possibly interesting. * ! * Currently, the node type coverage extends to SelectStmt and everything ! * that could appear under it, but not other statement types. */ bool raw_expression_tree_walker(Node *node, --- 2991,3000 ---- * Unlike expression_tree_walker, there is no special rule about query * boundaries: we descend to everything that's possibly interesting. * ! * Currently, the node type coverage here extends only to DML statements ! * (SELECT/INSERT/UPDATE/DELETE) and nodes that can appear in them, becau= se ! * this is used mainly during analysis of CTEs, and only DML statements c= an ! * appear in CTEs. */ bool raw_expression_tree_walker(Node *node, diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 7d2fedf..5979e76 100644 *** a/src/backend/parser/analyze.c --- b/src/backend/parser/analyze.c *************** *** 45,50 **** --- 45,55 ---- #include "utils/rel.h" =20=20 =20=20 + /* Use RAW_EXPRESSION_COVERAGE_TEST in COPY_PARSE_PLAN_TREES builds */ + #ifdef COPY_PARSE_PLAN_TREES + #define RAW_EXPRESSION_COVERAGE_TEST + #endif +=20 /* Hook for plugins to get control at end of parse analysis */ post_parse_analyze_hook_type post_parse_analyze_hook =3D NULL; =20=20 *************** static Query *transformCreateTableAsStmt *** 74,79 **** --- 79,87 ---- CreateTableAsStmt *stmt); static void transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc, bool pushedDown); + #ifdef RAW_EXPRESSION_COVERAGE_TEST + static bool test_raw_expression_coverage(Node *node, void *context); + #endif =20=20 =20=20 /* *************** transformStmt(ParseState *pstate, Node * *** 220,225 **** --- 228,252 ---- { Query *result; =20=20 + /* + * We apply RAW_EXPRESSION_COVERAGE_TEST testing to basic DML statements; + * we can't just run it on everything because raw_expression_tree_walker= () + * doesn't claim to handle utility statements. + */ + #ifdef RAW_EXPRESSION_COVERAGE_TEST + switch (nodeTag(parseTree)) + { + case T_SelectStmt: + case T_InsertStmt: + case T_UpdateStmt: + case T_DeleteStmt: + (void) test_raw_expression_coverage(parseTree, NULL); + break; + default: + break; + } + #endif /* RAW_EXPRESSION_COVERAGE_TEST */ +=20 switch (nodeTag(parseTree)) { /* *************** applyLockingClause(Query *qry, Index rti *** 2713,2715 **** --- 2740,2764 ---- rc->pushedDown =3D pushedDown; qry->rowMarks =3D lappend(qry->rowMarks, rc); } +=20 + /* + * Coverage testing for raw_expression_tree_walker(). + * + * When enabled, we run raw_expression_tree_walker() over every DML state= ment + * submitted to parse analysis. Without this provision, that function is= only + * applied in limited cases involving CTEs, and we don't really want to h= ave + * to test everything inside as well as outside a CTE. + */ + #ifdef RAW_EXPRESSION_COVERAGE_TEST +=20 + static bool + test_raw_expression_coverage(Node *node, void *context) + { + if (node =3D=3D NULL) + return false; + return raw_expression_tree_walker(node, + test_raw_expression_coverage, + context); + } +=20 + #endif /* RAW_EXPRESSION_COVERAGE_TEST */ ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--