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: teo...@sigaev.ru
                                                   WWW: http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to