QUERY PLAN
Aggregate (cost=2412.35..2412.36 rows=1 width=8)
-> Sort (cost=2397.35..2399.85 rows=1000 width=1688)
Sort Key: (date(tt.dt)) DESC
-> HashAggregate (cost=2335.02..2347.52 rows=1000 width=1688)
Group Key: tt.dt, p.day_at, p.user_id
-> Nested Loop Left Join (cost=0.43..2327.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.32 rows=1 width=8)
Index Cond: ((day_at = date(tt.dt)) AND (user_id = 1000))