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=4856807.14..4856807.15 rows=1 width=26) (actual time=216186.868..216186.888 rows=100 loops=1) Buffers: shared hit=10178893 read=1221933 dirtied=1070 written=12499, temp read=161561 written=161555 -> Sort (cost=4856807.14..4856807.15 rows=1 width=26) (actual time=216186.865..216186.872 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=10178893 read=1221933 dirtied=1070 written=12499, temp read=161561 written=161555 -> HashAggregate (cost=4856807.12..4856807.13 rows=1 width=26) (actual time=216181.928..216183.900 rows=3924 loops=1) Buffers: shared hit=10178885 read=1221933 dirtied=1070 written=12499, temp read=161561 written=161555 -> Nested Loop Anti Join (cost=2683618.24..4856807.12 rows=1 width=26) (actual time=57252.333..216006.502 rows=38602 loops=1) Buffers: shared hit=10178885 read=1221933 dirtied=1070 written=12499, temp read=161561 written=161555 -> Nested Loop (cost=2683618.24..4856791.95 rows=1 width=34) (actual time=57251.298..175418.559 rows=693400 loops=1) Join Filter: (l1.l_orderkey = orders.o_orderkey) Buffers: shared hit=7327699 read=590301 dirtied=1069 written=350, temp read=161561 written=161555 -> Hash Semi Join (cost=2683618.24..4856789.96 rows=1 width=38) (actual time=57251.238..133918.390 rows=1437951 loops=1) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) Rows Removed by Join Filter: 373039 Buffers: shared hit=1657515 read=500731 dirtied=1069, temp read=161561 written=161555 -> Hash Join (cost=2441.58..1923412.90 rows=809131 width=34) (actual time=44.300..59640.962 rows=1491227 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=910783 read=169275 -> Seq Scan on lineitem l1 (cost=0.00..1836998.93 rows=20234958 width=8) (actual time=0.049..40588.876 rows=37966174 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22078820 Buffers: shared hit=908926 read=169262 -> Hash (cost=2391.58..2391.58 rows=4000 width=30) (actual time=44.183..44.183 rows=3924 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 246kB Buffers: shared hit=1854 read=13 -> Nested Loop (cost=79.26..2391.58 rows=4000 width=30) (actual time=1.882..41.640 rows=3924 loops=1) Buffers: shared hit=1854 read=13 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.013..0.023 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.862..40.036 rows=3924 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1853 read=13 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.26 rows=4000 width=0) (actual time=1.474..1.474 rows=3924 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared read=13 -> Hash (cost=1685236.74..1685236.74 rows=60704874 width=8) (actual time=57182.054..57182.054 rows=60044994 loops=1) Buckets: 4194304 Batches: 4 Memory Usage: 586568kB Buffers: shared hit=746732 read=331456 dirtied=1069, temp written=153905 -> Seq Scan on lineitem l2 (cost=0.00..1685236.74 rows=60704874 width=8) (actual time=0.023..32165.515 rows=60044994 loops=1) Buffers: shared hit=746732 read=331456 dirtied=1069 -> Index Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.98 rows=1 width=4) (actual time=0.027..0.028 rows=0 loops=1437951) Index Cond: (o_orderkey = l2.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5670184 read=89570 written=350 -> Index Scan using lineitem_l_orderkey_idx on lineitem l3 (cost=0.00..7.56 rows=5 width=8) (actual time=0.057..0.057 rows=1 loops=693400) 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=2851186 read=631632 dirtied=1 written=12149 Total runtime: 216188.236 ms (56 rows) COMMIT; COMMIT