QUERY PLAN
Aggregate (cost=2404.35..2404.36 rows=1 width=8)
-> Sort (cost=2389.35..2391.85 rows=1000 width=1688)
Sort Key: (date(tt.dt)) DESC
-> HashAggregate (cost=2327.02..2339.52 rows=1000 width=1688)
Group Key: tt.dt, p.day_at, p.user_id
-> Nested Loop Left Join (cost=0.43..2319.52 rows=1000 width=16)
-> Function Scan on generate_series tt (cost=0.02..10.02 rows=1000 width=8)
-> Index Only Scan using tbl_punch_pkey on tbl_punch p (cost=0.42..2.31 rows=1 width=8)
Index Cond: ((day_at = date(tt.dt)) AND (user_id = 1000))