Re: ERROR: MergeAppend child's targetlist doesn't match MergeAppend

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Gregory Stark <stark(at)enterprisedb(dot)com>, Hans-Jürgen Schönig <hs(at)cybertec(dot)at>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: ERROR: MergeAppend child's targetlist doesn't match MergeAppend
Date: 2011-11-08 19:27:02
Message-ID: 25728.1320780422@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Teodor Sigaev <teodor(at)sigaev(dot)ru> writes:
> SELECT
> t1, t2
> FROM (
> SELECT t1, t2 FROM wow
> UNION ALL
> SELECT 'a', 'a' FROM wow
> ) t
> ORDER BY t1, t2;

Hmm, interesting.

> It's seems to me that check in create_merge_append_plan() is too restrictive:
> if (memcmp(sortColIdx, node->sortColIdx,
> numsortkeys * sizeof(AttrNumber)) != 0)
> elog(ERROR, "MergeAppend child's targetlist doesn't match
> MergeAppend");

No, it isn't. That code is fine; the problem is that
add_child_rel_equivalences is generating an invalid state of the
EquivalenceClass structures by adding equal items to two different
EquivalenceClasses. We need to rethink what that routine is doing.
It's definitely wrong for it to add constant items; here, that would
imply injecting t1 = 'a' and t2 = 'a' conditions, which is not correct.

> And the same problem is observed if second
> select is replaced by "SELECT t1, t1 FROM wow".

And this one is a bit nasty too, since it would still add equal items
to two different ECs, leading to the conclusion that they should be
merged, ie t1 = t2, which is likewise wrong.

Not immediately sure what to do about this. The quick-and-dirty fix
would be to only apply add_child_rel_equivalences to simple inheritance
child relations, for which the added items must be Vars and must be
different (which is what that code is expecting). Seems like a bit of a
shame to lobotomize planning for UNION cases, though. Maybe we need a
more complicated representation of child EquivalenceClass members.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2011-11-08 19:39:12 Re: unite recovery.conf and postgresql.conf
Previous Message Stephen Frost 2011-11-08 18:46:46 Re: Disable OpenSSL compression