46
loading...
This website collects cookies to deliver better user experience
aurora=> select count(*) from posts_by_user;
count
----------
42670000
(1 row)
Time: 13444.326 ms (00:13.444)
aurora=> explain analyze
select posts_by_user.*
from posts_by_user where user_id=1
and created_date > now() - 2*interval '1 day'
order by created_date desc;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------
Index Scan Backward using posts_by_user_pkey on posts_by_user (cost=0.57..8607.81 rows=2141 width=405) (actual time=0.045..2.536 rows=1847 loops=1)
Index Cond: ((user_id = 1) AND (created_date > (now() - '2 days'::interval)))
Planning Time: 0.140 ms
Execution Time: 2.664 ms
(4 rows)
aurora=> explain analyze
select posts_by_user.*
from posts_by_user
join posts_by_tag
using(user_id, created_date, post_id)
where posts_by_tag.created_date
> now() - interval '1 month'
and tag_id =1
order by created_date desc limit 100
;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=1.15..315.72 rows=31 width=405) (actual time=0.068..0.229 rows=18 loops=1)
-> Nested Loop (cost=1.15..315.72 rows=31 width=405) (actual time=0.067..0.225 rows=18 loops=1)
-> Index Only Scan Backward using posts_by_tag_pkey on posts_by_tag (cost=0.58..49.20 rows=31 width=24) (actual time=0.047..0.050 rows=18 loops=1)
Index Cond: ((tag_id = 1) AND (created_date > (now() - '1 mon'::interval)))
Heap Fetches: 0
-> Index Scan using posts_by_user_user_id_post_id_key on posts_by_user (cost=0.56..8.59 rows=1 width=405) (actual time=0.008..0.008 rows=1 loops=18)
Index Cond: ((user_id = posts_by_tag.user_id) AND (post_id = posts_by_tag.post_id))
Filter: (posts_by_tag.created_date = created_date)
Planning Time: 0.372 ms
Execution Time: 0.270 ms
(10 rows)
aurora=> explain analyze
select *
from posts_by_user
where created_date > now() - interval '1 month'
and tag_ids @>'{1}'
order by created_date desc limit 100;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=1600106.71..1600106.96 rows=100 width=405) (actual time=2302.013..2302.019 rows=18 loops=1)
-> Sort (cost=1600106.71..1600112.21 rows=2201 width=405) (actual time=2302.012..2302.015 rows=18 loops=1)
Sort Key: created_date DESC
Sort Method: quicksort Memory: 34kB
-> Bitmap Heap Scan on posts_by_user (cost=1591353.62..1600022.59 rows=2201 width=405) (actual time=2301.754..2301.998 rows=18 loops=1)
Recheck Cond: ((tag_ids @> '{1}'::bigint[]) AND (created_date > (now() - '1 mon'::interval)))
Rows Removed by Index Recheck: 284
Heap Blocks: exact=17
-> BitmapAnd (cost=1591353.62..1591353.62 rows=2201 width=0) (actual time=2301.724..2301.726 rows=0 loops=1)
-> Bitmap Index Scan on posts_by_user_tag_ids (cost=0.00..3098.15 rows=269086 width=0) (actual time=3.280..3.280 rows=2000 loops=1)
Index Cond: (tag_ids @> '{1}'::bigint[])
-> Bitmap Index Scan on posts_by_user_pkey (cost=0.00..1588254.12 rows=440229 width=0) (actual time=2297.828..2297.828 rows=360584 loops=1)
Index Cond: (created_date > (now() - '1 mon'::interval))
Planning Time: 0.132 ms
Execution Time: 2302.057 ms
(15 rows)