Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 1. mine:
- EXPLAIN ANALYZE
- SELECT DISTINCT EXTRACT(WEEK FROM creation_date) week_number,
- MAX(creation_date) OVER (PARTITION BY EXTRACT(WEEK FROM creation_date))
- FROM stackoverflow.posts pp
- JOIN (SELECT user_id,
- COUNT(id)
- FROM stackoverflow.posts
- GROUP BY 1
- ORDER BY 2 DESC
- LIMIT 1) tt ON pp.user_id = tt.user_id
- AND DATE_TRUNC('month', creation_date)::date = '2008-10-01';
- Unique (cost=13788.52..13788.53 rows=1 width=16) (actual time=109.211..113.660 rows=5 loops=1)
- -> Sort (cost=13788.52..13788.53 rows=1 width=16) (actual time=109.211..113.626 rows=440 loops=1)
- Sort Key: (date_part('week'::text, pp.creation_date)), (max(pp.creation_date) OVER (?))
- Sort Method: quicksort Memory: 45kB
- -> WindowAgg (cost=13788.49..13788.51 rows=1 width=16) (actual time=109.000..113.548 rows=440 loops=1)
- -> Sort (cost=13788.49..13788.50 rows=1 width=16) (actual time=108.980..113.415 rows=440 loops=1)
- Sort Key: (date_part('week'::text, pp.creation_date))
- Sort Method: quicksort Memory: 45kB
- -> Hash Join (cost=8412.70..13788.48 rows=1 width=16) (actual time=87.264..113.314 rows=440 loops=1)
- Hash Cond: (pp.user_id = tt.user_id)
- -> Gather (cost=1000.00..6372.58 rows=1219 width=12) (actual time=10.144..31.411 rows=63102 loops=1)
- Workers Planned: 2
- Workers Launched: 2
- -> Parallel Seq Scan on posts pp (cost=0.00..5250.68 rows=508 width=12) (actual time=6.403..19.387 rows=21034 loops=3)
- Filter: ((date_trunc('month'::text, creation_date))::date = '2008-10-01'::date)
- Rows Removed by Filter: 60231
- -> Hash (cost=7412.69..7412.69 rows=1 width=4) (actual time=77.027..77.030 rows=1 loops=1)
- Buckets: 1024 Batches: 1 Memory Usage: 9kB
- -> Subquery Scan on tt (cost=7412.67..7412.69 rows=1 width=4) (actual time=77.019..77.023 rows=1 loops=1)
- -> Limit (cost=7412.67..7412.68 rows=1 width=12) (actual time=77.016..77.018 rows=1 loops=1)
- -> Sort (cost=7412.67..7459.80 rows=18849 width=12) (actual time=77.014..77.016 rows=1 loops=1)
- Sort Key: (count(posts.id)) DESC
- Sort Method: top-N heapsort Memory: 25kB
- -> HashAggregate (cost=7129.94..7318.43 rows=18849 width=12) (actual time=72.184..75.242 rows=18849 loops=1)
- Group Key: posts.user_id
- -> Seq Scan on posts (cost=0.00..5910.96 rows=243796 width=8) (actual time=0.010..23.391 rows=243796 loops=1)
- Planning Time: 0.231 ms
- Execution Time: 113.873 ms
- -- 2. not mine:
- EXPLAIN ANALYZE
- WITH best_user AS
- (SELECT user_id,
- COUNT(id) AS post_cnt
- FROM stackoverflow.posts
- GROUP BY user_id
- ORDER BY post_cnt DESC
- LIMIT 1),
- post_weekly AS
- (SELECT EXTRACT(WEEK FROM p.creation_date) AS week_nmb,
- p.creation_date AS post_dt
- FROM stackoverflow.posts p
- JOIN best_user bu ON p.user_id=bu.user_id
- WHERE DATE_TRUNC('month', p.creation_date)::date='2008-10-01'
- GROUP BY week_nmb, p.creation_date
- ORDER BY p.creation_date)
- SELECT DISTINCT week_nmb,
- LAST_VALUE(post_dt) OVER(PARTITION BY week_nmb ORDER BY post_dt ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
- FROM post_weekly;
- HashAggregate (cost=13789.95..13789.96 rows=1 width=24) (actual time=122.397..126.800 rows=5 loops=1)
- Group Key: post_weekly.week_nmb, last_value(post_weekly.post_dt) OVER (?)
- CTE best_user
- -> Limit (cost=7412.67..7412.68 rows=1 width=12) (actual time=81.892..81.894 rows=1 loops=1)
- -> Sort (cost=7412.67..7459.80 rows=18849 width=12) (actual time=81.890..81.892 rows=1 loops=1)
- Sort Key: (count(posts.id)) DESC
- Sort Method: top-N heapsort Memory: 25kB
- -> HashAggregate (cost=7129.94..7318.43 rows=18849 width=12) (actual time=76.946..80.090 rows=18849 loops=1)
- Group Key: posts.user_id
- -> Seq Scan on posts (cost=0.00..5910.96 rows=243796 width=8) (actual time=0.013..25.162 rows=243796 loops=1)
- CTE post_weekly
- -> Group (cost=6377.21..6377.22 rows=1 width=16) (actual time=121.883..126.389 rows=440 loops=1)
- Group Key: p.creation_date, (date_part('week'::text, p.creation_date))
- -> Sort (cost=6377.21..6377.21 rows=1 width=16) (actual time=121.880..126.305 rows=440 loops=1)
- Sort Key: p.creation_date, (date_part('week'::text, p.creation_date))
- Sort Method: quicksort Memory: 45kB
- -> Hash Join (cost=1000.03..6377.20 rows=1 width=16) (actual time=94.096..126.181 rows=440 loops=1)
- Hash Cond: (p.user_id = bu.user_id)
- -> Gather (cost=1000.00..6372.58 rows=1219 width=12) (actual time=12.049..38.862 rows=63102 loops=1)
- Workers Planned: 2
- Workers Launched: 2
- -> Parallel Seq Scan on posts p (cost=0.00..5250.68 rows=508 width=12) (actual time=7.209..23.672 rows=21034 loops=3)
- Filter: ((date_trunc('month'::text, creation_date))::date = '2008-10-01'::date)
- Rows Removed by Filter: 60231
- -> Hash (cost=0.02..0.02 rows=1 width=4) (actual time=81.902..81.903 rows=1 loops=1)
- Buckets: 1024 Batches: 1 Memory Usage: 9kB
- -> CTE Scan on best_user bu (cost=0.00..0.02 rows=1 width=4) (actual time=81.896..81.897 rows=1 loops=1)
- -> WindowAgg (cost=0.03..0.05 rows=1 width=24) (actual time=122.153..122.324 rows=440 loops=1)
- -> Sort (cost=0.03..0.04 rows=1 width=16) (actual time=122.140..122.163 rows=440 loops=1)
- Sort Key: post_weekly.week_nmb, post_weekly.post_dt
- Sort Method: quicksort Memory: 45kB
- -> CTE Scan on post_weekly (cost=0.00..0.02 rows=1 width=16) (actual time=121.885..122.090 rows=440 loops=1)
- Planning Time: 0.227 ms
- Execution Time: 127.054 ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement