On 12th of December, Tom Lane committed patch:

Improve EXPLAIN to print the grouping columns in Agg and Group nodes.
 
Per request from Kevin Grittner.

Well, the description is pretty simple, so let's just see it in some example:

Before:

                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
 GroupAggregate  (cost=63239.58..65800.66 rows=102443 width=887) (actual time=3749.183..19549.198 rows=117 loops=1)
   ->  Sort  (cost=63239.58..63495.69 rows=102443 width=887) (actual time=3457.795..3542.012 rows=105676 loops=1)
         Sort Key: (date_trunc('month'::text, entered_on)), is_public
         Sort Method: external merge  Disk: 91672kB
         ->  Seq Scan on plans  (cost=0.00..14796.54 rows=102443 width=887) (actual time=12.963..3139.596 rows=105676 loops=1)
 Total runtime: 19569.330 ms
(6 rows)

Now:

                                                         QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
 GroupAggregate  (cost=144020.88..146662.33 rows=105658 width=871) (actual time=469.468..4484.059 rows=117 loops=1)
   Group Key: (date_trunc('month'::text, entered_on)), is_public
   ->  Sort  (cost=144020.88..144285.02 rows=105658 width=871) (actual time=464.047..524.744 rows=105658 loops=1)
         Sort Key: (date_trunc('month'::text, entered_on)), is_public
         Sort Method: external merge  Disk: 91384kB
         ->  Seq Scan on plans  (cost=0.00..13855.73 rows=105658 width=871) (actual time=7.182..109.704 rows=105658 loops=1)
 Total runtime: 4598.598 ms
(7 rows)

The change is rather simple, but I like that it's more information to user, and it's symmetrical to, already present, key info for sort nodes.

Cool stuff, thanks Tom.

Leave a comment