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 1o7OFF-0006Nz-B2 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 21:32:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7OFD-0007Xk-Qh for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 21:32:07 +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 1o7OFD-0007W2-Hb for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 21:32:07 +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 1o7OFB-0002Mf-CO for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 21:32:07 +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 261LW2RF095732; Fri, 1 Jul 2022 17:32:02 -0400 From: Tom Lane To: Richard Guo cc: pgsql-hackers@lists.postgresql.org Subject: Re: Use outerPlanState macro instead of referring to leffttree In-reply-to: References: Comments: In-reply-to Richard Guo message dated "Thu, 14 Apr 2022 14:49:23 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <95730.1656711122.1@sss.pgh.pa.us> Date: Fri, 01 Jul 2022 17:32:02 -0400 Message-ID: <95731.1656711122@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > In the executor code, we mix use outerPlanState macro and referring to > leffttree. Commit 40f42d2a tried to keep the code consistent by > replacing referring to lefftree with outerPlanState macro, but there are > still some outliers. This patch tries to clean them up. Seems generally reasonable, but what about righttree? I find a few of those too with "grep". Backing up a little bit, one thing not to like about the outerPlanState and innerPlanState macros is that they lose all semblance of type safety: #define innerPlanState(node) (((PlanState *)(node))->righttree) #define outerPlanState(node) (((PlanState *)(node))->lefttree) You can pass any pointer you want, and the compiler will not complain. I wonder if there's any trick (even a gcc-only one) that could improve on that. In the absence of such a check, people might feel that increasing our reliance on these macros isn't such a hot idea. Now, the typical coding pattern you've used: ExecReScanHash(HashState *node) { + PlanState *outerPlan = outerPlanState(node); is probably reasonably secure against wrong-pointer slip-ups. But I'm less convinced about that for in-line usages in the midst of a function, particularly in the common case that the function has a variable pointing to its Plan node as well as PlanState node. Would it make sense to try to use the local-variable style everywhere? regards, tom lane