Sort keys are omitted incorrectly after grouping sets - Mailing list pgsql-hackers

From Richard Guo
Subject Sort keys are omitted incorrectly after grouping sets
Date
Msg-id CAMbWs48AtQTQGk37MSyDk_EAgDO3Y0iA_LzvuvGQ2uO_Wh2muw@mail.gmail.com
Whole thread Raw
Responses Re: Sort keys are omitted incorrectly after grouping sets  (Greg Stark <stark@mit.edu>)
List pgsql-hackers
Hi hackers,

In each PathKey we have an EC representing the value being sorted on.
This works correctly and efficiently in scan/join planning since the
members in an EC are always equal to each other.

However, after applying GROUP BY grouping sets, the members in an EC may
not be that equivalent any more, because NULLS may be emitted by
grouping sets. As a result, we may lose some sort keys incorrectly.

# explain (costs off) select a, b from foo where a = b group by cube(a, b) order by a, b;
          QUERY PLAN
-------------------------------
 Sort
   Sort Key: a
   ->  MixedAggregate
         Hash Key: a, b
         Hash Key: a
         Hash Key: b
         Group Key: ()
         ->  Seq Scan on foo
               Filter: (a = b)
(9 rows)

I believe we should not ignore sort key 'b' in the query above.

Is this a problem we should be worried about?

Thanks
Richard

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Remove unused 'len' from pg_stat_recv_* functions
Next
From: Soumyadeep Chakraborty
Date:
Subject: Changes to recovery_min_apply_delay are ignored while waiting for delay