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 1ghR2f-0001vu-US for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2019 03:30:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghR2e-0004SW-6V for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2019 03:30:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghR2e-0004SP-0O for pgsql-bugs@lists.postgresql.org; Thu, 10 Jan 2019 03:30:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghR2X-0002fS-8W for pgsql-bugs@lists.postgresql.org; Thu, 10 Jan 2019 03:29:59 +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 x0A3TjqT005726; Wed, 9 Jan 2019 22:29:45 -0500 From: Tom Lane To: Robert Haas cc: Thomas Munro , 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> Comments: In-reply-to Robert Haas message dated "Wed, 09 Jan 2019 21:06:23 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5724.1547090985.1@sss.pgh.pa.us> Date: Wed, 09 Jan 2019 22:29:45 -0500 Message-ID: <5725.1547090985@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas writes: > On Wed, Jan 9, 2019 at 5:08 PM Tom Lane wrote: >> One way we could deal with this, perhaps, is to decide that NestLoopParams >> above and below a Gather can't share PARAM_EXEC slots. I'm not sure how >> we'd mechanize that, other than not allowing NestLoopParams to share >> PARAM_EXEC slots *ever*, which might not really be that much of a cost. >> >> But TBH the whole thing frightens me quite a lot as to what other >> serial-processing assumptions are getting broken by plopping Gather >> into the middle of a plan tree. I wonder whether we'd not be best >> off disallowing this sort of plan shape, and/or forbidding the leader >> from also executing the parallelized subplan. > FWIW, I would be inclined to blame this on me not really understanding > the Param machinery very well rather than any more general brand of > insanity. I wouldn't be a bit shocked if this is not the last bit > Param-related dumbness than parallel query has. I did *try* to get it > right, but I find that stuff to be pretty arcane and not entirely > well-documented. Well, if we posit that the problems are limited to false Param-sharing, my inclination is to fix it by simplifying rather than adding complexity. To wit, let's just assign a new PARAM_EXEC slot for every NestLoopParam and never try to share them. The argument that sharing them would work for NLPs representing the same Var hinged on the assumption that nested NestLoops would necessarily execute "in sync", which we now see is false at least when Gathers are in between. This'll cost some more PARAM_EXEC slots, of course, but AFAICS the cost of that is trivial, just a few more bytes per slot. It's arguable that the cost of trying to de-duplicate them at plan time is more than we can save at execution :-( I'm about fried for tonight, but I can take a look at this tomorrow. regards, tom lane