BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select s_name, count(*) as numwait from supplier, lineitem l1, orders, nation where s_suppkey = l1.l_suppkey and o_orderkey = l1.l_orderkey and o_orderstatus = 'F' and l1.l_receiptdate > l1.l_commitdate and exists ( select * from lineitem l2 where l2.l_orderkey = l1.l_orderkey and l2.l_suppkey <> l1.l_suppkey ) and not exists ( select * from lineitem l3 where l3.l_orderkey = l1.l_orderkey and l3.l_suppkey <> l1.l_suppkey and l3.l_receiptdate > l3.l_commitdate ) and s_nationkey = n_nationkey and n_name = 'MOZAMBIQUE' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=4851961.56..4851961.56 rows=1 width=26) (actual time=133069.873..133069.893 rows=100 loops=1) Buffers: shared hit=10104925 read=1293582 dirtied=152 written=17534, temp read=161561 written=161555 -> Sort (cost=4851961.56..4851961.56 rows=1 width=26) (actual time=133069.869..133069.876 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=10104925 read=1293582 dirtied=152 written=17534, temp read=161561 written=161555 -> HashAggregate (cost=4851961.54..4851961.55 rows=1 width=26) (actual time=133064.840..133066.845 rows=3924 loops=1) Buffers: shared hit=10104917 read=1293582 dirtied=152 written=17534, temp read=161561 written=161555 -> Nested Loop Anti Join (cost=2680954.36..4851961.53 rows=1 width=26) (actual time=45390.065..132849.541 rows=38588 loops=1) Buffers: shared hit=10104917 read=1293582 dirtied=152 written=17534, temp read=161561 written=161555 -> Nested Loop (cost=2680954.36..4851946.39 rows=1 width=34) (actual time=45387.441..116911.784 rows=693373 loops=1) Join Filter: (l1.l_orderkey = orders.o_orderkey) Buffers: shared hit=7074432 read=841386 dirtied=3 written=55, temp read=161561 written=161555 -> Hash Semi Join (cost=2680954.36..4851944.40 rows=1 width=38) (actual time=45387.374..100980.589 rows=1437940 loops=1) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) Rows Removed by Join Filter: 373021 Buffers: shared hit=1328928 read=827182 written=6, temp read=161561 written=161555 -> Hash Join (cost=2441.58..1921497.99 rows=807543 width=34) (actual time=32.939..42231.362 rows=1491220 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=358877 read=720113 written=6 -> Seq Scan on lineitem l1 (cost=0.00..1835175.44 rows=20214812 width=8) (actual time=0.034..28610.817 rows=37965800 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22079072 Buffers: shared hit=357018 read=720102 written=6 -> Hash (cost=2391.58..2391.58 rows=4000 width=30) (actual time=32.827..32.827 rows=3924 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 246kB Buffers: shared hit=1856 read=11 -> Nested Loop (cost=79.26..2391.58 rows=4000 width=30) (actual time=1.697..30.883 rows=3924 loops=1) Buffers: shared hit=1856 read=11 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.010..0.015 rows=1 loops=1) Filter: (n_name = 'MOZAMBIQUE'::bpchar) Rows Removed by Filter: 24 Buffers: shared hit=1 -> Bitmap Heap Scan on supplier (cost=79.26..2350.26 rows=4000 width=34) (actual time=1.681..29.427 rows=3924 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1855 read=11 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.26 rows=4000 width=0) (actual time=1.312..1.312 rows=3924 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=2 read=11 -> Hash (cost=1683564.35..1683564.35 rows=60644435 width=8) (actual time=45321.594..45321.594 rows=60044872 loops=1) Buckets: 4194304 Batches: 4 Memory Usage: 586575kB Buffers: shared hit=970051 read=107069, temp written=153905 -> Seq Scan on lineitem l2 (cost=0.00..1683564.35 rows=60644435 width=8) (actual time=0.016..23448.799 rows=60044872 loops=1) Buffers: shared hit=970051 read=107069 -> Index Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.97 rows=1 width=4) (actual time=0.010..0.010 rows=0 loops=1437940) Index Cond: (o_orderkey = l2.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5745504 read=14204 dirtied=3 written=49 -> Index Scan using lineitem_l_orderkey_idx on lineitem l3 (cost=0.00..7.55 rows=5 width=8) (actual time=0.022..0.022 rows=1 loops=693373) Index Cond: (l_orderkey = l1.l_orderkey) Filter: ((l_receiptdate > l_commitdate) AND (l_suppkey <> l1.l_suppkey)) Rows Removed by Filter: 1 Buffers: shared hit=3030485 read=452196 dirtied=149 written=17479 Total runtime: 133071.373 ms (56 rows) COMMIT; COMMIT