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

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

Hi!

I ran into a problem with PG 9.1 and bug is observed even in master. After
simplifying a query (original was 9Kb long!) it's possible to reproduce it easily:

CREATE TABLE wow (t1 text, t2 text);
CREATE INDEX idx ON wow (t1,t2);

SET enable_seqscan=off;
SET enable_bitmapscan=off;

EXPLAIN
SELECT
t1, t2
FROM (
SELECT t1, t2 FROM wow
UNION ALL
SELECT 'a', 'a' FROM wow
) t
ORDER BY t1, t2;

if second 'a' constant is changed to something else then it works fine.

The root of problem is that tlist_member() (called in
create_merge_append_plan()) for second constant returns TargetEntry for first
constant because they are equal. And the same problem is observed if second
select is replaced by "SELECT t1, t1 FROM wow".

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");

Although I think, that more accurate check will repeat work done in
prepare_sort_from_pathkeys().

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2011-11-08 17:53:03 Re: DatumGetInetP buggy
Previous Message Dimitri Fontaine 2011-11-08 17:47:13 Command Triggers