Aggregate (cost=316107.28..316114.91 rows=11 width=322) Filter: ((((sum(qty_on_hand) + sum(qty_in_goods)) - sum(qty_dp)) - sum(qty_out_goods)) < 0::numeric) -> Group (cost=316107.28..316108.98 rows=113 width=322) -> Sort (cost=316107.28..316107.57 rows=113 width=322) Sort Key: s.sku, s.stktype_code, i.sku_descr, br.cluster_code, br.cluster_descr -> Hash Join (cost=308622.49..316103.43 rows=113 width=322) Hash Cond: ("outer".sku = "inner".sku) Join Filter: ("inner".group_code = "outer".group_code) -> Seq Scan on master_sku_descr i (cost=0.00..6467.08 rows=156008 width=96) -> Hash (cost=308618.04..308618.04 rows=1781 width=226) -> Hash Join (cost=1698.78..308618.04 rows=1781 width=226) Hash Cond: ("outer".sku = "inner".sku) Join Filter: ("outer".brn_code = "inner".brn_code) -> Seq Scan on stmst_sku s (cost=0.00..284677.69 rows=356150 width=106) Filter: (fpp_code = '200408'::text) -> Hash (cost=1550.41..1550.41 rows=59347 width=120) -> Merge Join (cost=57.89..1550.41 rows=59347 width=120) Merge Cond: ("outer".cluster_brn = "inner".cluster_code) -> Index Scan using old_sku_uidx1 on old_sku os (cost=0.00..702.79 rows=17822 width=24) -> Sort (cost=57.89..59.56 rows=666 width=96) Sort Key: br.cluster_code -> Seq Scan on master_branch_descr br (cost=0.00..26.66 rows=666 width=96) SubPlan -> Aggregate (cost=23.73..23.73 rows=1 width=8) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..23.70 rows=6 width=8) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=23.73..23.73 rows=1 width=8) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..23.70 rows=6 width=8) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=23.73..23.73 rows=1 width=8) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..23.70 rows=6 width=8) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=32.16..32.16 rows=1 width=50) -> Merge Join (cost=32.11..32.15 rows=1 width=50) Merge Cond: ("outer".brn_code = "inner".brn_code) -> Sort (cost=14.38..14.39 rows=3 width=32) Sort Key: b.brn_code -> Index Scan using master_branch_descr_idx6 on master_branch_descr b (cost=0.00..14.35 rows=3 width=32) Index Cond: (cluster_code = $0) Filter: (brn_code <> cluster_code) -> Sort (cost=17.73..17.74 rows=4 width=18) Sort Key: k.brn_code -> Index Scan using stmst_sku_idx3 on stmst_sku k (cost=0.00..17.69 rows=4 width=18) Index Cond: ((fpp_code = '200408'::text) AND (sku = $1) AND (stktype_code = $2)) (44 rows)