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 = 'FRANCE' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=4828045.74..4828045.75 rows=1 width=26) (actual time=169307.115..169307.147 rows=100 loops=1) Buffers: shared hit=9427551 read=2048752 dirtied=2056 written=15050, temp read=161628 written=161622 -> Sort (cost=4828045.74..4828045.75 rows=1 width=26) (actual time=169307.111..169307.125 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=9427551 read=2048752 dirtied=2056 written=15050, temp read=161628 written=161622 -> HashAggregate (cost=4828045.72..4828045.73 rows=1 width=26) (actual time=169299.132..169301.839 rows=3960 loops=1) Buffers: shared hit=9427543 read=2048752 dirtied=2056 written=15050, temp read=161628 written=161622 -> Nested Loop Anti Join (cost=2667729.23..4828045.72 rows=1 width=26) (actual time=59118.977..169138.591 rows=39339 loops=1) Buffers: shared hit=9427543 read=2048752 dirtied=2056 written=15050, temp read=161628 written=161622 -> Nested Loop (cost=2667729.23..4828030.70 rows=1 width=34) (actual time=59114.521..147298.661 rows=700767 loops=1) Join Filter: (l1.l_orderkey = orders.o_orderkey) Buffers: shared hit=6550166 read=1407469 dirtied=2054 written=5194, temp read=161628 written=161622 -> Hash Semi Join (cost=2667729.23..4828028.73 rows=1 width=38) (actual time=59114.427..126397.881 rows=1451071 loops=1) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) Rows Removed by Join Filter: 376730 Buffers: shared hit=853648 read=1291795 dirtied=2054 written=1893, temp read=161628 written=161622 -> Hash Join (cost=2441.58..1912031.27 rows=804602 width=34) (actual time=35.096..47768.864 rows=1504823 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=664233 read=409412 dirtied=1059 written=1056 -> Seq Scan on lineitem l1 (cost=0.00..1826112.25 rows=20115047 width=8) (actual time=0.048..32259.471 rows=37966560 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22079266 Buffers: shared hit=662400 read=409398 dirtied=1059 written=1056 -> Hash (cost=2391.58..2391.58 rows=4000 width=30) (actual time=34.934..34.934 rows=3961 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 248kB Buffers: shared hit=1830 read=14 -> Nested Loop (cost=79.26..2391.58 rows=4000 width=30) (actual time=2.000..32.925 rows=3961 loops=1) Buffers: shared hit=1830 read=14 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.013..0.022 rows=1 loops=1) Filter: (n_name = 'FRANCE'::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.982..31.558 rows=3961 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1829 read=14 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.26 rows=4000 width=0) (actual time=1.594..1.594 rows=3961 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared read=14 -> Hash (cost=1675249.40..1675249.40 rows=60345140 width=8) (actual time=59052.642..59052.642 rows=60045826 loops=1) Buckets: 4194304 Batches: 4 Memory Usage: 586621kB Buffers: shared hit=189415 read=882383 dirtied=995 written=837, temp written=153905 -> Seq Scan on lineitem l2 (cost=0.00..1675249.40 rows=60345140 width=8) (actual time=0.050..28980.411 rows=60045826 loops=1) Buffers: shared hit=189415 read=882383 dirtied=995 written=837 -> Index Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.96 rows=1 width=4) (actual time=0.013..0.013 rows=0 loops=1451071) Index Cond: (o_orderkey = l2.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5696518 read=115674 written=3301 -> Index Scan using pk_lineitem on lineitem l3 (cost=0.00..7.48 rows=5 width=8) (actual time=0.030..0.030 rows=1 loops=700767) 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=2877377 read=641283 dirtied=2 written=9856 Total runtime: 169308.928 ms (56 rows) COMMIT; COMMIT