Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzQ5Y-0003DV-Tk for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Dec 2021 21:20:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mzQ51-0004h9-8Q for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Dec 2021 21:20:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzQ50-0004h0-W0 for pgsql-hackers@lists.postgresql.org; Mon, 20 Dec 2021 21:20:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzQ4t-0007Ui-6a for pgsql-hackers@lists.postgresql.org; Mon, 20 Dec 2021 21:20:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1BKLKBOa2657968; Mon, 20 Dec 2021 16:20:12 -0500 From: Tom Lane To: Robert Haas cc: Justin Pryzby , PostgreSQL Hackers Subject: Re: sqlsmith: ERROR: XX000: bogus varno: 2 In-reply-to: References: <20211219205422.GT17618@telsasoft.com> <2209221.1639948636@sss.pgh.pa.us> <2445883.1640017555@sss.pgh.pa.us> <2524668.1640024031@sss.pgh.pa.us> <2598851.1640028995@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Mon, 20 Dec 2021 15:17:01 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2657966.1640035211.1@sss.pgh.pa.us> Date: Mon, 20 Dec 2021 16:20:11 -0500 Message-ID: <2657967.1640035211@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > OK ... but my point is that dump and restore does work. So whatever > cases pg_get_expr() doesn't work must be cases that aren't needed for > that to happen. Otherwise this problem would have been found long ago. pg_get_expr doesn't (or didn't) depend on expression_tree_walker, so there wasn't a problem there before. I am worried that there might be other code paths, now or in future, that could try to apply expression_tree_walker/mutator to relpartbound trees, which is why I think it's a reasonable idea to teach them about such trees. >> It does fall over if you try to apply it to stored rules: >> regression=# select pg_get_expr(ev_action, 0) from pg_rewrite; >> ERROR: unrecognized node type: 232 >> I'm not terribly excited about that, but maybe we should try to >> improve it while we're here. > In my view, the lack of excitement about sanity checks in functions > that deal with node trees in the catalogs is the root of this problem. It's only a problem if you hold the opinion that there should be no user-reachable ERRCODE_INTERNAL_ERROR errors. Which is a fine ideal, but I fear we're a pretty long way off from that. > I realize that's a deep hole out of which we're unlikely to be able to > climb in the short or even medium term, but we don't have to keep > digging. We either make a rule that pg_get_expr() can apply to > everything stored in the catalogs and produce sensible answers, which > seems to be what you prefer, or we make it return nice errors for the > cases that it can't handle nicely, or some combination of the two. And > whatever we decide, we also document and enforce everywhere. I think having pg_get_expr throw an error for a query, as opposed to an expression, is fine. What I don't want to do is subdivide things a lot more finely than that; thus lumping "relpartbound" into "expression" seems like a reasonable thing to do. Especially since we already did it six years ago. In a quick check of catalogs with pg_node_tree columns, I find these other columns that pg_get_expr can fail on (at least with the examples available in the regression DB): regression=# select count(pg_get_expr(prosqlbody,0)) from pg_proc; ERROR: unrecognized node type: 232 regression=# select count(pg_get_expr(tgqual,tgrelid)) from pg_trigger ; ERROR: bogus varno: 2 So that looks like the same cases we already knew about: input is a querytree not an expression, or it contains Vars for more than one relation. regards, tom lane