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 1o96KP-00048E-Mp for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Jul 2022 14:48:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o96KO-0007Jd-Ag for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Jul 2022 14:48:32 +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 1o96KO-0006tD-0p for pgsql-hackers@lists.postgresql.org; Wed, 06 Jul 2022 14:48:32 +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 1o96KE-0002OB-Ve for pgsql-hackers@lists.postgresql.org; Wed, 06 Jul 2022 14:48:28 +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 266EmL032195796; Wed, 6 Jul 2022 10:48:21 -0400 From: Tom Lane To: Richard Guo cc: Pg Hackers Subject: Re: Use outerPlanState macro instead of referring to leffttree In-reply-to: References: <95731.1656711122@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Wed, 06 Jul 2022 17:41:44 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2195794.1657118901.1@sss.pgh.pa.us> Date: Wed, 06 Jul 2022 10:48:21 -0400 Message-ID: <2195795.1657118901@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Sat, Jul 2, 2022 at 5:32 AM Tom Lane wrote: >> 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: > Your concern makes sense. I think outerPlan and innerPlan macros share > the same issue. Not sure if there is a way to do the type check. Yeah, I don't know of one either. It needn't hold up this patch. >> Would it make sense to try to use the local-variable style everywhere? > Do you mean the pattern like below? > outerPlanState(hashstate) = ExecInitNode(outerPlan(node), estate, eflags); > It seems that this pattern is mostly used when initializing child nodes > with ExecInitNode(), and most calls to ExecInitNode() are using this > pattern as a convention. Not sure if it's better to change them to > local-variable style. That's probably fine, especially if it's a commonly used pattern. Typically, if one applies outerPlan() or outerPlanState() to the wrong pointer, the mistake will become obvious upon even minimal testing. My concern here is more about usages in edge cases that perhaps escape testing, for instance in the arguments of an elog() for some nearly-can't-happen case. regards, tom lane