QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=1514.75..1514.76 rows=1 width=8) -> Hash Left Join (cost=895.41..1514.49 rows=102 width=0) Hash Cond: (a.tran_det_row_id = x.row_id) Filter: (CASE WHEN ((a.tran_type)::text = 'ar_rec'::text) THEN y.posted WHEN ((a.tran_type)::text = 'cb_rec'::text) THEN w.posted ELSE NULL::boolean END AND (CASE WHEN ((a.tran_type)::text = 'ar_rec'::text) THEN y.tran_date WHEN ((a.tran_type)::text = 'cb_rec'::text) THEN w.tran_date ELSE NULL::date END >= '2015-05-01'::date) AND (CASE WHEN ((a.tran_type)::text = 'ar_rec'::text) THEN y.tran_date WHEN ((a.tran_type)::text = 'cb_rec'::text) THEN w.tran_date ELSE NULL::date END <= '2015-05-31'::date)) -> Hash Right Join (cost=893.05..1505.23 rows=1835 width=16) Hash Cond: (y.row_id = z.tran_row_id) -> Seq Scan on ar_tran_rec y (cost=0.00..511.25 rows=22025 width=9) -> Hash (cost=870.12..870.12 rows=1835 width=15) -> Hash Right Join (cost=343.97..870.12 rows=1835 width=15) Hash Cond: (z.row_id = a.tran_det_row_id) -> Seq Scan on ar_tran_rec_det z (cost=0.00..397.53 rows=22053 width=8) -> Hash (cost=321.03..321.03 rows=1835 width=11) -> Bitmap Heap Scan on ar_rec_subtran a (cost=38.51..321.03 rows=1835 width=11) Recheck Cond: (cust_row_id = 4) Filter: (deleted_id = 0) -> Bitmap Index Scan on ar_sub_cust (cost=0.00..38.05 rows=1835 width=0) Index Cond: (cust_row_id = 4) -> Hash (cost=2.23..2.23 rows=10 width=9) -> Hash Left Join (cost=1.04..2.23 rows=10 width=9) Hash Cond: (x.tran_row_id = w.row_id) -> Seq Scan on cb_tran_rec_det x (cost=0.00..1.10 rows=10 width=8) -> Hash (cost=1.02..1.02 rows=2 width=9) -> Seq Scan on cb_tran_rec w (cost=0.00..1.02 rows=2 width=9)