QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=6780.04..6780.42 rows=1 width=182) (actual time=629.652..629.653 rows=1 loops=1) -> Nested Loop (cost=1053.78..6779.62 rows=1 width=182) (actual time=160.662..595.059 rows=969 loops=1) -> Hash Join (cost=1053.78..6688.46 rows=21 width=186) (actual time=160.493..545.222 rows=3522 loops=1) Hash Cond: ("outer".property_id = "inner".property_id) -> GroupAggregate (cost=0.00..5581.97 rows=3500 width=12) (actual time=0.159..363.108 rows=3522 loops=1) -> Index Scan using fewo_property_availability_month_country_property_idx on fewo_property_availability_month property_availability_month (cost=0.00..3893.52 rows=34992 width=12) (actual time=0.023..147.269 rows=37316 loops=1) Index Cond: (300 = country_id) -> Hash (cost=1053.16..1053.16 rows=250 width=86) (actual time=160.277..160.277 rows=3522 loops=1) -> Hash Join (cost=825.03..1053.16 rows=250 width=86) (actual time=115.767..147.429 rows=3522 loops=1) Hash Cond: ("outer".property_id = "inner".property_id) -> HashAggregate (cost=338.96..488.83 rows=2141 width=12) (actual time=64.207..77.280 rows=3522 loops=1) -> Bitmap Heap Scan on fewo_period_type_property period_type_property (cost=23.03..253.01 rows=3438 width=12) (actual time=0.625..27.199 rows=3522 loops=1) Recheck Cond: (300 = country_id) -> Bitmap Index Scan on fewo_period_type_property_country_property_idx (cost=0.00..23.03 rows=3438 width=0) (actual time=0.605..0.605 rows=3522 loops=1) Index Cond: (300 = country_id) -> Hash (cost=473.87..473.87 rows=4881 width=18) (actual time=51.496..51.496 rows=4873 loops=1) -> Bitmap Heap Scan on fewo_property_location property_location (cost=50.19..473.87 rows=4881 width=18) (actual time=0.974..24.530 rows=4873 loops=1) Recheck Cond: (country_id = 300) Filter: (property_state_id = 3) -> Bitmap Index Scan on fewo_property_location_country_property_idx (cost=0.00..50.19 rows=4912 width=0) (actual time=0.939..0.939 rows=4873 loops=1) Index Cond: (country_id = 300) -> Index Scan using fewo_location_ancestry_ancestor_child_idx on fewo_location_ancestry ancestor (cost=0.00..4.33 rows=1 width=4) (actual time=0.007..0.008 rows=0 loops=3522) Index Cond: ((ancestor.ancestor_id = 309) AND (ancestor.child_id = "outer".location_id)) Total runtime: 631.858 ms (24 rows)