HashAggregate (cost=21527635.27..21527801.32 rows=11070 width=51) (actual time=1578174.649..1578174.744 rows=30 loops=1) -> Nested Loop Left Join (cost=0.00..20776009.06 rows=724459 width=51) (actual time=598.332..54815.039 rows=662583 loops=1) -> Nested Loop (cost=0.00..1376086.06 rows=147475 width=45) (actual time=558.022..13917.873 rows=662583 loops=1) Join Filter: (a.product_operation = o.id) Rows Removed by Join Filter: 26503320 -> Append (cost=0.00..1285387.42 rows=147475 width=34) (actual time=550.779..5709.779 rows=662583 loops=1) -> Seq Scan on public.table_a a (cost=0.00..0.00 rows=1 width=60) (actual time=0.002..0.002 rows=0 lo ops=1) Filter: ((a.twin_id IS NULL) AND (a.transaction_date >= '2012-11-01 00:00:00+00'::timestamp with time zone) A ND (a.transaction_date < '2012-12-01 00:00:00+00'::timestamp with time zone) AND (a.product_id = 2) AND ((a.trans_type_id = ANY ('{2,3,4 }'::integer[])) OR (a.trans_type_id IS NULL))) -> Bitmap Heap Scan on public.table_a_2 a (cost=16549.24..1285387.42 rows=147474 width=34) (actual ti me=550.775..5551.190 rows=662583 loops=1) t_operation Recheck Cond: ((a.transaction_date >= '2012-11-01 00:00:00+00'::timestamp with time zone) AND (a.transaction_ date < '2012-12-01 00:00:00+00'::timestamp with time zone)) Filter: ((a.twin_id IS NULL) AND (a.product_id = 2) AND ((a.trans_type_id = ANY ('{2,3,4}'::integer[])) OR (a .trans_type_id IS NULL))) Rows Removed by Filter: 411920 -> Bitmap Index Scan on table_a_2_trans_date_idx (cost=0.00..16512.37 rows=1065722 width=0) (actual ti me=386.455..386.455 rows=1074503 loops=1) Index Cond: ((a.transaction_date >= '2012-11-01 00:00:00+00'::timestamp with time zone) AND (a.transact ion_date < '2012-12-01 00:00:00+00'::timestamp with time zone)) -> Materialize (cost=0.00..1.62 rows=41 width=19) (actual time=0.000..0.005 rows=41 loops=662583) -> Seq Scan on public.product_operations o (cost=0.00..1.41 rows=41 width=19) (actual time=7.207..7.214 rows=41 l oops=1) -> Append (cost=0.00..131.48 rows=7 width=12) (actual time=0.058..0.060 rows=1 loops=662583) -> Seq Scan on public.table_b b (cost=0.00..0.00 rows=1 width=22) (actual time=0.000..0.000 rows=0 loops=662 583) Filter: ((b.product_id = 2) AND (b.organization_id = 3) AND (b.year = 2013) AND (b.month = 3) AND (a.id = b.a_id)) -> Index Scan using table_b_ptid_orgid_ym_unq on public.table_b_2 b (cost=0.00..131.48 rows=6 width=10) (a ctual time=0.055..0.056 rows=1 loops=662583) Index Cond: ((a.id = b.a_id) AND (b.organization_id = 3) AND (b.year = 2013) AND (b.month = 3)) Filter: (b.product_id = 2) Total runtime: 1578194.532 ms (32 rows)