Skip to content

Instantly share code, notes, and snippets.

@gingerwizard
Last active December 20, 2022 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gingerwizard/1488c3e9701e0ff4f952bfff9250e656 to your computer and use it in GitHub Desktop.
Save gingerwizard/1488c3e9701e0ff4f952bfff9250e656 to your computer and use it in GitHub Desktop.
Explain - Average price per year for flats in the UK
postgres=> EXPLAIN SELECT
       extract(year from date) as year,
       round(avg(price)) AS price
FROM uk_price_paid
WHERE type = 'flat'
GROUP BY year
ORDER BY year;
                                               QUERY PLAN
----------------------------------------------------------------------------------------------------------
Finalize GroupAggregate  (cost=726068.63..726072.48 rows=28 width=64)
  Group Key: (EXTRACT(year FROM date))
  ->  Gather Merge  (cost=726068.63..726071.85 rows=28 width=64)
        Workers Planned: 1
        ->  Sort  (cost=725068.62..725068.69 rows=28 width=64)
              Sort Key: (EXTRACT(year FROM date))
              ->  Partial HashAggregate  (cost=725067.60..725067.95 rows=28 width=64)
                    Group Key: EXTRACT(year FROM date)
                    ->  Parallel Seq Scan on uk_price_paid  (cost=0.00..709209.49 rows=3171621 width=36)
                          Filter: ((type)::text = 'flat'::text)
(10 rows)   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment