ERROR: MergeAppend child's targetlist doesn't match MergeAppend - Mailing list pgsql-hackers

From Teodor Sigaev
Subject ERROR: MergeAppend child's targetlist doesn't match MergeAppend
Date
Msg-id 4EB96BA8.60603@sigaev.ru
Whole thread Raw
Responses Re: ERROR: MergeAppend child's targetlist doesn't match MergeAppend
List 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
targetlistdoesn't match 
 
MergeAppend");

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

-- 
Teodor Sigaev                                   E-mail: teodor@sigaev.ru
  WWW: http://www.sigaev.ru/
 


pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: DatumGetInetP buggy
Next
From: Greg Smith
Date:
Subject: Re: Measuring relation free space