Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghgMh-0003DW-Vc for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2019 19:51:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghgMg-0007Pd-2j for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2019 19:51:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghgMf-0007PW-PE for pgsql-bugs@lists.postgresql.org; Thu, 10 Jan 2019 19:51:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghgMd-0007nq-C6 for pgsql-bugs@lists.postgresql.org; Thu, 10 Jan 2019 19:51:40 +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 x0AJpXQ1013256; Thu, 10 Jan 2019 14:51:33 -0500 From: Tom Lane To: Thomas Munro cc: Robert Haas , David Rowley , Bartosz Polnik , PostgreSQL mailing lists Subject: Re: BUG #15577: Query returns different results when executed multiple times In-reply-to: References: <15577-ca61ab18904af852@postgresql.org> <18883.1547071723@sss.pgh.pa.us> <5725.1547090985@sss.pgh.pa.us> <2887.1547141893@sss.pgh.pa.us> Comments: In-reply-to Thomas Munro message dated "Fri, 11 Jan 2019 08:17:03 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13254.1547149893.1@sss.pgh.pa.us> Date: Thu, 10 Jan 2019 14:51:33 -0500 Message-ID: <13255.1547149893@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro writes: > On Fri, Jan 11, 2019 at 6:38 AM Tom Lane wrote: >> At this point assign_nestloop_param_var and >> assign_nestloop_param_placeholdervar are dead code, and there's a bunch >> of incorrect comments in subselect.c, and I really need to refactor >> the division of labor between createplan.c and subselect.c (for one >> thing, this is an abuse of the documented purpose of >> SS_make_initplan_output_param). But functionally I think it does the >> right thing. Please test and verify that you no longer see the race >> condition. > I no longer see it here. Thanks for checking! I'm having some difficulty choosing what to do refactoring-wise. There are a couple of conflicting considerations: * Currently, subselect.c is in charge of assigning PARAM_EXEC slots; in particular, nothing else touches root->glob->paramExecTypes. I'm kind of loath to give that up. * On the other hand, root->curOuterParams is currently only manipulated by createplan.c, and if we could keep that as a local data structure, that'd be nice too. * However, if we stick to both of those constraints then we're forced into more or less what the POC patch does. We could provide another subselect.c function, say SS_make_nestloop_param, which'd just wrap generate_new_param the same as SS_make_initplan_output_param, but we still have a pretty weird division of labor IMO. The fundamental issue here is that it's now going to be the state of the curOuterParams list that determines whether a new PARAM_EXEC slot is needed. Really that list serves the same sort of purpose as the root->plan_params list, but its entries have very different lifespans than the entries in plan_params. So there's a reasonable case to be made that we should put management of curOuterParams into subselect.c, except that (a) it's a bit far afield from sub-selects, and (b) I'm not sure how completely it could be decoupled from createplan.c. If this were a HEAD-only patch I'd be tempted to do like Alvaro just did and move all the PARAM_EXEC assignment logic and root->plan_params and root->curOuterParams manipulation into a new file, say optimizer/util/paramassign.c. But that would be a little invasive for a back-patch. Thoughts? regards, tom lane