Aggregate (cost=354420.02..354427.65 rows=11 width=322) (actual time=246825.06..316125.53 rows=12050 loops=1) Filter: ((((sum(qty_on_hand) + sum(qty_in_goods)) - sum(qty_dp)) - sum(qty_out_goods)) < 0::numeric) -> Group (cost=354420.02..354421.72 rows=113 width=322) (actual time=246701.96..247283.96 rows=42930 loops=1) -> Sort (cost=354420.02..354420.30 rows=113 width=322) (actual time=246701.94..246736.97 rows=42930 loops=1) Sort Key: s.sku, s.stktype_code, i.sku_descr, br.cluster_code, br.cluster_descr -> Merge Join (cost=354298.16..354416.17 rows=113 width=322) (actual time=245205.55..245634.53 rows=42930 loops=1) Merge Cond: (("outer".brn_code = "inner".brn_code) AND ("outer".cluster_brn = "inner".cluster_code)) -> Sort (cost=354240.27..354296.76 rows=22595 width=226) (actual time=245179.07..245205.75 rows=42930 loops=1) Sort Key: s.brn_code, os.cluster_brn -> Merge Join (cost=348924.92..352606.20 rows=22595 width=226) (actual time=241551.96..244357.21 rows=42930 loops=1) Merge Cond: ("outer".sku = "inner".sku) -> Merge Join (cost=348924.92..351824.65 rows=22595 width=202) (actual time=241500.21..243397.42 rows=132883 loops=1) Merge Cond: (("outer".sku = "inner".sku) AND ("outer".group_code = "inner".group_code)) -> Sort (cost=329001.17..329891.54 rows=356150 width=106) (actual time=238575.25..238742.16 rows=132883 loops=1) Sort Key: s.sku, s.group_code -> Seq Scan on stmst_sku s (cost=0.00..284677.69 rows=356150 width=106) (actual time=219190.28..235315.66 rows=132883 loops=1) Filter: (fpp_code = '200408'::text) -> Sort (cost=19923.75..20313.77 rows=156008 width=96) (actual time=2924.57..3048.34 rows=185259 loops=1) Sort Key: i.sku, i.group_code -> Seq Scan on master_sku_descr i (cost=0.00..6467.08 rows=156008 width=96) (actual time=1.62..976.63 rows=156008 loops=1) -> Index Scan using old_sku_idx1 on old_sku os (cost=0.00..398.04 rows=17822 width=24) (actual time=49.45..209.45 rows=46294 loops=1) -> Sort (cost=57.89..59.56 rows=666 width=96) (actual time=26.41..54.70 rows=43232 loops=1) Sort Key: br.brn_code, br.cluster_code -> Seq Scan on master_branch_descr br (cost=0.00..26.66 rows=666 width=96) (actual time=8.04..24.21 rows=666 loops=1) SubPlan -> Aggregate (cost=23.73..23.73 rows=1 width=8) (actual time=0.06..0.06 rows=1 loops=14481) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..23.70 rows=6 width=8) (actual time=0.04..0.05 rows=0 loops=14481) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=23.73..23.73 rows=1 width=8) (actual time=0.04..0.04 rows=1 loops=14481) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..23.70 rows=6 width=8) (actual time=0.03..0.03 rows=0 loops=14481) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=23.73..23.73 rows=1 width=8) (actual time=0.03..0.03 rows=1 loops=12042) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..23.70 rows=6 width=8) (actual time=0.03..0.03 rows=0 loops=12042) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=32.16..32.16 rows=1 width=50) (actual time=4.53..4.53 rows=1 loops=14481) -> Merge Join (cost=32.11..32.15 rows=1 width=50) (actual time=4.45..4.52 rows=3 loops=14481) Merge Cond: ("outer".brn_code = "inner".brn_code) -> Sort (cost=14.38..14.39 rows=3 width=32) (actual time=3.84..4.01 rows=271 loops=14481) 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) (actual time=0.02..2.14 rows=564 loops=14481) Index Cond: (cluster_code = $0) Filter: (brn_code <> cluster_code) -> Sort (cost=17.73..17.74 rows=4 width=18) (actual time=0.14..0.14 rows=3 loops=14481) Sort Key: k.brn_code -> Index Scan using stmst_sku_idx3 on stmst_sku k (cost=0.00..17.69 rows=4 width=18) (actual time=0.08..0.11 rows=3 loops=14481) Index Cond: ((fpp_code = '200408'::text) AND (sku = $1) AND (stktype_code = $2)) Total runtime: 316245.16 msec (47 rows)