Skip to content

Instantly share code, notes, and snippets.

@peterbe
Last active January 12, 2018 20:53
Show Gist options
  • Save peterbe/585e6fe5ab3838860e71e25e2d7c9f9b to your computer and use it in GitHub Desktop.
Save peterbe/585e6fe5ab3838860e71e25e2d7c9f9b to your computer and use it in GitHub Desktop.
explain analyze SELECT
COUNT("upload_upload"."id") FILTER (WHERE ("upload_upload"."created_at" >= '2018-01-12T00:00:00.081739+00:00'::timestamptz AND "upload_upload"."created_at" < '2018-01-12T20:08:11.081739+00:00'::timestamptz)) AS "today_count",
SUM("upload_upload"."size") FILTER (WHERE ("upload_upload"."created_at" >= '2018-01-12T00:00:00.081739+00:00'::timestamptz AND "upload_upload"."created_at" < '2018-01-12T20:08:11.081739+00:00'::timestamptz)) AS "today_total_size"
FROM "upload_upload";
explain analyze SELECT COUNT("upload_upload"."id") AS "count", SUM("upload_upload"."size") AS "total_size" FROM "upload_upload" WHERE ("upload_upload"."created_at" >= '2018-01-12T00:00:00.481487+00:00'::timestamptz AND "upload_upload"."created_at" < '2018-01-12T19:24:31.481487+00:00'::timestamptz);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
Aggregate (cost=74.33..74.34 rows=1 width=16) (actual time=0.587..0.587 rows=1 loops=1)
-> Seq Scan on upload_upload (cost=0.00..62.13 rows=813 width=16) (actual time=0.012..0.210 rows=813 loops=1)
Planning time: 0.427 ms
Execution time: 0.674 ms
(4 rows)
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=11.26..11.27 rows=1 width=8) (actual time=0.012..0.012 rows=1 loops=1)
-> Index Scan using upload_upload_created_at_8a54a254 on upload_upload (cost=0.28..11.22 rows=8 width=8) (actual time=0.005..0.009 rows=16 loops=1)
Index Cond: ((created_at >= '2018-01-11 19:00:00.481487-05'::timestamp with time zone) AND (created_at < '2018-01-12 14:24:31.481487-05'::timestamp with time zone))
Planning time: 0.227 ms
Execution time: 0.034 ms
(5 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment