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 = 'INDONESIA' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=4855190.91..4855190.91 rows=1 width=26) (actual time=218155.158..218155.179 rows=100 loops=1) Buffers: shared hit=10321377 read=1175509 dirtied=204 written=953, temp read=161483 written=161477 -> Sort (cost=4855190.91..4855190.91 rows=1 width=26) (actual time=218155.154..218155.161 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=10321377 read=1175509 dirtied=204 written=953, temp read=161483 written=161477 -> HashAggregate (cost=4855190.89..4855190.90 rows=1 width=26) (actual time=218150.104..218152.025 rows=3974 loops=1) Buffers: shared hit=10321369 read=1175509 dirtied=204 written=953, temp read=161483 written=161477 -> Nested Loop Anti Join (cost=2682725.45..4855190.88 rows=1 width=26) (actual time=77624.963..217976.475 rows=39327 loops=1) Buffers: shared hit=10321369 read=1175509 dirtied=204 written=953, temp read=161483 written=161477 -> Nested Loop (cost=2682725.45..4855175.73 rows=1 width=34) (actual time=77568.492..186417.016 rows=701397 loops=1) Join Filter: (l1.l_orderkey = orders.o_orderkey) Buffers: shared hit=7171009 read=802804 dirtied=204 written=243, temp read=161483 written=161477 -> Hash Semi Join (cost=2682725.45..4855173.74 rows=1 width=38) (actual time=77564.635..151329.393 rows=1452131 loops=1) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) Rows Removed by Join Filter: 376435 Buffers: shared hit=1365422 read=792094 dirtied=204 written=225, temp read=161483 written=161477 -> Hash Join (cost=2441.58..1922773.28 rows=808862 width=34) (actual time=78.224..57919.352 rows=1505813 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=775284 read=304403 written=20 -> Seq Scan on lineitem l1 (cost=0.00..1836387.26 rows=20228220 width=8) (actual time=0.035..39262.276 rows=37927978 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22056848 Buffers: shared hit=773438 read=304391 written=18 -> Hash (cost=2391.58..2391.58 rows=4000 width=30) (actual time=78.136..78.136 rows=3974 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 249kB Buffers: shared hit=1843 read=12 written=2 -> Nested Loop (cost=79.26..2391.58 rows=4000 width=30) (actual time=1.771..75.625 rows=3974 loops=1) Buffers: shared hit=1843 read=12 written=2 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.008..0.016 rows=1 loops=1) Filter: (n_name = 'INDONESIA'::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.758..74.039 rows=3974 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1842 read=12 written=2 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.26 rows=4000 width=0) (actual time=1.358..1.358 rows=3974 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=2 read=12 written=2 -> Hash (cost=1684675.61..1684675.61 rows=60684661 width=8) (actual time=77459.337..77459.337 rows=59984826 loops=1) Buckets: 4194304 Batches: 4 Memory Usage: 585983kB Buffers: shared hit=590138 read=487691 dirtied=204 written=205, temp written=153751 -> Seq Scan on lineitem l2 (cost=0.00..1684675.61 rows=60684661 width=8) (actual time=0.021..50905.657 rows=59984826 loops=1) Buffers: shared hit=590138 read=487691 dirtied=204 written=205 -> Index Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.97 rows=1 width=4) (actual time=0.023..0.023 rows=0 loops=1452131) Index Cond: (o_orderkey = l2.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5805587 read=10710 written=18 -> Index Scan using lineitem_l_orderkey_idx on lineitem l3 (cost=0.00..7.55 rows=5 width=8) (actual time=0.044..0.044 rows=1 loops=701397) 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=3150360 read=372705 written=710 Total runtime: 218158.142 ms (56 rows) COMMIT; COMMIT