Re: BUG #15577: Query returns different results when executed multiple times

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, Bartosz Polnik <bartoszpolnik(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15577: Query returns different results when executed multiple times
Date: 2019-01-09 21:04:05
Message-ID: 87k1jdpniz.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>>>>> "Thomas" == Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> 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)

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas Munro 2019-01-09 21:46:25 Re: BUG #15577: Query returns different results when executed multiple times
Previous Message Thomas Munro 2019-01-09 20:31:57 Re: BUG #15577: Query returns different results when executed multiple times