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 1o8XHW-00053d-5L for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Jul 2022 01:23:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o8XHV-0006vq-28 for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Jul 2022 01:23:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o8XHU-0006ux-PE for pgsql-hackers@lists.postgresql.org; Tue, 05 Jul 2022 01:23:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o8XHS-0000vD-CB for pgsql-hackers@lists.postgresql.org; Tue, 05 Jul 2022 01:23:11 +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 2651N8jM1794156 for ; Mon, 4 Jul 2022 21:23:08 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Bugs in copyfuncs/equalfuncs support for JSON node types MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1794114.1656984156.0@sss.pgh.pa.us> Date: Mon, 04 Jul 2022 21:23:08 -0400 Message-ID: <1794155.1656984188@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1794114.1656984156.1@sss.pgh.pa.us> In reviewing Peter's patch to auto-generate the backend/nodes support files, I compared what the patch's script produces to what is in the code now. I found several discrepancies in the recently-added parse node types for JSON functions, and as far as I can see every one of those discrepancies is an error in the existing code. Some of them are relatively harmless (e.g. COPY_LOCATION_FIELD isn't really different from COPY_SCALAR_FIELD), but some of them definitely are live bugs. I propose the attached patch. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="fix-json-copy-equal-bugs.patch"; charset="us-ascii" Content-ID: <1794114.1656984156.2@sss.pgh.pa.us> Content-Description: fix-json-copy-equal-bugs.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 51d630fa89..706d283a92 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -2703,7 +2703,8 @@ _copyJsonTable(const JsonTable *from) COPY_NODE_FIELD(plan); COPY_NODE_FIELD(on_error); COPY_NODE_FIELD(alias); - COPY_SCALAR_FIELD(location); + COPY_SCALAR_FIELD(lateral); + COPY_LOCATION_FIELD(location); = return newnode; } @@ -2721,13 +2722,13 @@ _copyJsonTableColumn(const JsonTableColumn *from) COPY_NODE_FIELD(typeName); COPY_STRING_FIELD(pathspec); COPY_STRING_FIELD(pathname); - COPY_SCALAR_FIELD(format); + COPY_NODE_FIELD(format); COPY_SCALAR_FIELD(wrapper); COPY_SCALAR_FIELD(omit_quotes); COPY_NODE_FIELD(columns); COPY_NODE_FIELD(on_empty); COPY_NODE_FIELD(on_error); - COPY_SCALAR_FIELD(location); + COPY_LOCATION_FIELD(location); = return newnode; } @@ -2742,10 +2743,10 @@ _copyJsonTablePlan(const JsonTablePlan *from) = COPY_SCALAR_FIELD(plan_type); COPY_SCALAR_FIELD(join_type); - COPY_STRING_FIELD(pathname); COPY_NODE_FIELD(plan1); COPY_NODE_FIELD(plan2); - COPY_SCALAR_FIELD(location); + COPY_STRING_FIELD(pathname); + COPY_LOCATION_FIELD(location); = return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs= .c index e747e1667d..fccc0b4a18 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -147,14 +147,29 @@ _equalTableFunc(const TableFunc *a, const TableFunc = *b) return true; } = +static bool +_equalJsonTablePlan(const JsonTablePlan *a, const JsonTablePlan *b) +{ + COMPARE_SCALAR_FIELD(plan_type); + COMPARE_SCALAR_FIELD(join_type); + COMPARE_NODE_FIELD(plan1); + COMPARE_NODE_FIELD(plan2); + COMPARE_STRING_FIELD(pathname); + COMPARE_LOCATION_FIELD(location); + + return true; +} + static bool _equalJsonTable(const JsonTable *a, const JsonTable *b) { COMPARE_NODE_FIELD(common); COMPARE_NODE_FIELD(columns); + COMPARE_NODE_FIELD(plan); COMPARE_NODE_FIELD(on_error); COMPARE_NODE_FIELD(alias); - COMPARE_SCALAR_FIELD(location); + COMPARE_SCALAR_FIELD(lateral); + COMPARE_LOCATION_FIELD(location); = return true; } @@ -166,13 +181,14 @@ _equalJsonTableColumn(const JsonTableColumn *a, cons= t JsonTableColumn *b) COMPARE_STRING_FIELD(name); COMPARE_NODE_FIELD(typeName); COMPARE_STRING_FIELD(pathspec); - COMPARE_SCALAR_FIELD(format); + COMPARE_STRING_FIELD(pathname); + COMPARE_NODE_FIELD(format); COMPARE_SCALAR_FIELD(wrapper); COMPARE_SCALAR_FIELD(omit_quotes); COMPARE_NODE_FIELD(columns); COMPARE_NODE_FIELD(on_empty); COMPARE_NODE_FIELD(on_error); - COMPARE_SCALAR_FIELD(location); + COMPARE_LOCATION_FIELD(location); = return true; } @@ -4405,6 +4421,9 @@ equal(const void *a, const void *b) case T_JsonArgument: retval =3D _equalJsonArgument(a, b); break; + case T_JsonTablePlan: + retval =3D _equalJsonTablePlan(a, b); + break; case T_JsonTable: retval =3D _equalJsonTable(a, b); break; ------- =_aaaaaaaaaa0--