Aggregate (cost=87597.84..89421.82 rows=2702 width=484) (actual time=22727.88..28164.74 rows=12040 loops=1) Filter: ((((sum(qty_on_hand) + sum(qty_in_goods)) - sum(qty_dp)) - sum(qty_out_goods)) < 0::numeric) -> Group (cost=87597.84..88003.17 rows=27022 width=484) (actual time=22727.45..23242.01 rows=42705 loops=1) -> Sort (cost=87597.84..87665.40 rows=27022 width=484) (actual time=22727.43..22756.74 rows=42705 loops=1) Sort Key: s.sku, s.stktype_code, i.sku_descr, br.cluster_code, br.cluster_descr -> Merge Join (cost=84388.96..85608.78 rows=27022 width=484) (actual time=20303.41..21814.25 rows=42705 loops=1) Merge Cond: (("outer".group_code = "inner".group_code) AND ("outer".sku = "inner".sku)) -> Sort (cost=64472.34..64489.67 rows=6930 width=388) (actual time=16503.56..16530.23 rows=42705 loops=1) Sort Key: s.group_code, os.sku -> Merge Join (cost=63006.13..64030.25 rows=6930 width=388) (actual time=14394.48..15794.71 rows=42705 loops=1) Merge Cond: (("outer".cluster_brn = "inner".cluster_code) AND ("outer".sku = "inner".sku)) -> Index Scan using old_sku_uidx1 on old_sku os (cost=0.00..797.79 rows=17799 width=64) (actual time=0.02..47.66 rows=17799 loops=1) -> Sort (cost=63006.13..63045.07 rows=15574 width=324) (actual time=14393.77..14556.50 rows=132703 loops=1) Sort Key: br.cluster_code, s.sku -> Merge Join (cost=61645.75..61921.64 rows=15574 width=324) (actual time=4862.56..6078.94 rows=132703 loops=1) Merge Cond: ("outer".brn_code = "inner".brn_code) -> Sort (cost=61587.79..61626.73 rows=15574 width=228) (actual time=4859.23..5043.43 rows=132703 loops=1) Sort Key: s.brn_code -> Index Scan using stmst_sku_idx4 on stmst_sku s (cost=0.00..60503.30 rows=15574 width=228) (actual time=0.07..1078.30 rows=132703 loops=1) Index Cond: (fpp_code = '200408'::text) -> Sort (cost=57.96..59.62 rows=667 width=96) (actual time=3.26..91.93 rows=133005 loops=1) Sort Key: br.brn_code -> Seq Scan on master_branch_descr br (cost=0.00..26.67 rows=667 width=96) (actual time=0.02..1.13 rows=667 loops=1) -> Sort (cost=19916.61..20306.53 rows=155968 width=96) (actual time=3797.71..3914.26 rows=184223 loops=1) Sort Key: i.group_code, i.sku -> Seq Scan on master_sku_descr i (cost=0.00..6463.68 rows=155968 width=96) (actual time=0.01..293.74 rows=155968 loops=1) SubPlan -> Aggregate (cost=6.02..6.02 rows=1 width=8) (actual time=0.04..0.04 rows=1 loops=14456) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..6.01 rows=1 width=8) (actual time=0.03..0.03 rows=0 loops=14456) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=6.02..6.02 rows=1 width=8) (actual time=0.04..0.04 rows=1 loops=14456) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..6.01 rows=1 width=8) (actual time=0.03..0.03 rows=0 loops=14456) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=6.02..6.02 rows=1 width=8) (actual time=0.03..0.03 rows=1 loops=12031) -> Index Scan using gir_oustanding_idx1 on gir_outstanding (cost=0.00..6.01 rows=1 width=8) (actual time=0.03..0.03 rows=0 loops=12031) Index Cond: ((cluster_brn = $0) AND (sku = $1) AND (stktype_code = $2)) -> Aggregate (cost=11.96..11.96 rows=1 width=82) (actual time=0.16..0.16 rows=1 loops=14456) -> Nested Loop (cost=0.00..11.95 rows=1 width=82) (actual time=0.08..0.15 rows=3 loops=14456) -> Index Scan using stmst_sku_idx3 on stmst_sku k (cost=0.00..6.02 rows=1 width=50) (actual time=0.06..0.08 rows=3 loops=14456) Index Cond: ((fpp_code = '200408'::text) AND (sku = $1) AND (stktype_code = $2)) -> Index Scan using master_branch_descr_pkey on master_branch_descr b (cost=0.00..5.92 rows=1 width=32) (actual time=0.02..0.02 rows=1 loops=42705) Index Cond: ("outer".brn_code = b.brn_code) Filter: ((brn_code <> cluster_code) AND (cluster_code = $0)) Total runtime: 28255.12 msec (44 rows)