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=4866411.73..4866411.73 rows=1 width=26) (actual time=177919.135..177919.154 rows=100 loops=1) Buffers: shared hit=10156369 read=1247934 dirtied=55 written=1497, temp read=161560 written=161554 -> Sort (cost=4866411.73..4866411.73 rows=1 width=26) (actual time=177919.131..177919.137 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=10156369 read=1247934 dirtied=55 written=1497, temp read=161560 written=161554 -> HashAggregate (cost=4866411.71..4866411.72 rows=1 width=26) (actual time=177914.072..177916.209 rows=3924 loops=1) Buffers: shared hit=10156361 read=1247934 dirtied=55 written=1497, temp read=161560 written=161554 -> Nested Loop Anti Join (cost=2688919.64..4866411.70 rows=1 width=26) (actual time=55598.658..177747.126 rows=38595 loops=1) Buffers: shared hit=10156361 read=1247934 dirtied=55 written=1497, temp read=161560 written=161554 -> Nested Loop (cost=2688919.64..4866396.49 rows=1 width=34) (actual time=55595.422..156253.614 rows=693338 loops=1) Join Filter: (l1.l_orderkey = orders.o_orderkey) Buffers: shared hit=7226413 read=695370 dirtied=44 written=441, temp read=161560 written=161554 -> Hash Semi Join (cost=2688919.64..4866394.49 rows=1 width=38) (actual time=55594.289..133406.958 rows=1437842 loops=1) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) Rows Removed by Join Filter: 373028 Buffers: shared hit=1604227 read=558281 written=17, temp read=161560 written=161554 -> Hash Join (cost=2441.58..1927213.44 rows=810999 width=34) (actual time=56.034..62160.934 rows=1491102 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=646311 read=435878 written=17 -> Seq Scan on lineitem l1 (cost=0.00..1840630.70 rows=20274979 width=8) (actual time=0.034..41167.865 rows=37966096 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22078937 Buffers: shared hit=644452 read=435867 written=17 -> Hash (cost=2391.58..2391.58 rows=4000 width=30) (actual time=55.855..55.855 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=2.699..53.710 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.009..0.016 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=2.682..52.233 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=2.282..2.282 rows=3924 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=2 read=11 -> Hash (cost=1688568.36..1688568.36 rows=60824936 width=8) (actual time=55503.057..55503.057 rows=60045033 loops=1) Buckets: 4194304 Batches: 4 Memory Usage: 586575kB Buffers: shared hit=957916 read=122403, temp written=153905 -> Seq Scan on lineitem l2 (cost=0.00..1688568.36 rows=60824936 width=8) (actual time=0.018..28435.427 rows=60045033 loops=1) Buffers: shared hit=957916 read=122403 -> Index Scan using pk_orders on orders (cost=0.00..1.98 rows=1 width=4) (actual time=0.015..0.015 rows=0 loops=1437842) Index Cond: (o_orderkey = l2.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5622186 read=137089 dirtied=44 written=424 -> Index Scan using lineitem_l_orderkey_idx on lineitem l3 (cost=0.00..7.58 rows=5 width=8) (actual time=0.030..0.030 rows=1 loops=693338) 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=2929948 read=552564 dirtied=11 written=1056 Total runtime: 177920.490 ms (56 rows) COMMIT; COMMIT