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 1ghL1M-0000cJ-CB for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Jan 2019 21:04:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghL1K-00006M-Ql for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Jan 2019 21:04:14 +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 1ghL1K-00006E-Gt for pgsql-bugs@lists.postgresql.org; Wed, 09 Jan 2019 21:04:14 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghL1H-0002Ac-AQ for pgsql-bugs@lists.postgresql.org; Wed, 09 Jan 2019 21:04:13 +0000 Received: from [192.168.127.1] (port=22009 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1ghL1D-000H3Q-Cg; Wed, 09 Jan 2019 21:04:07 +0000 Received: from [127.0.0.1] (port=27146 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1ghL1C-000IPt-Hy; Wed, 09 Jan 2019 21:04:06 +0000 From: Andrew Gierth To: Thomas Munro Cc: David Rowley , Bartosz Polnik , PostgreSQL mailing lists Subject: Re: BUG #15577: Query returns different results when executed multiple times In-Reply-To: (Thomas Munro's message of "Thu, 10 Jan 2019 09:20:42 +1300") Message-ID: <87k1jdpniz.fsf@news-spur.riddles.org.uk> References: <15577-ca61ab18904af852@postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Wed, 09 Jan 2019 21:04:05 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Thomas" == Thomas Munro writes: Thomas> So it's not the reading of the tuple queue per se, but the Thomas> resulting visit to a higher part of the plan when the Gather Thomas> node emits a tuple. It can't be right that plan id 2 and plan Thomas> id 0 are both using paramno 0, can it? I'm not too familiar Thomas> with the planner code that allocates those but will go and poke Thomas> at it. Looks like this isn't a new bug, either; I can reproduce it on 10.x. So I think you're right to finger the planner's allocation of params as the culprit. Looking at replace_nestloop_params_mutator, it's keeping a list of nestloop params in root->curOuterParams (thus, globally to the whole subquery being planned), and it assumes that if equal() is true between the value of an existing nestloop param (which must be a Var) and the Var for the one it's trying to create, then it's ok to use the existing one. But clearly this can't work if one param is referenced both inside and outside a Gather, because while they will compare equal for Vars, they won't actually have the same value thanks to rows coming in from workers. -- Andrew (irc:RhodiumToad)