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 = 'ALGERIA' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=4832800.52..4832800.53 rows=1 width=26) (actual time=233405.504..233405.535 rows=100 loops=1) Buffers: shared hit=9466493 read=1931183 dirtied=145 written=15313, temp read=161558 written=161552 -> Sort (cost=4832800.52..4832800.53 rows=1 width=26) (actual time=233405.500..233405.510 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=9466493 read=1931183 dirtied=145 written=15313, temp read=161558 written=161552 -> HashAggregate (cost=4832800.50..4832800.51 rows=1 width=26) (actual time=233398.290..233400.572 rows=3934 loops=1) Buffers: shared hit=9466485 read=1931183 dirtied=145 written=15313, temp read=161558 written=161552 -> Nested Loop Anti Join (cost=2670358.61..4832800.50 rows=1 width=26) (actual time=73837.088..233223.997 rows=39161 loops=1) Buffers: shared hit=9466485 read=1931183 dirtied=145 written=15313, temp read=161558 written=161552 -> Nested Loop (cost=2670358.61..4832785.45 rows=1 width=34) (actual time=73832.506..198609.459 rows=694895 loops=1) Join Filter: (l1.l_orderkey = orders.o_orderkey) Buffers: shared hit=6575190 read=1332200 written=527, temp read=161558 written=161552 -> Hash Semi Join (cost=2670358.61..4832783.48 rows=1 width=38) (actual time=73832.103..164086.152 rows=1437988 loops=1) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) Rows Removed by Join Filter: 373789 Buffers: shared hit=834400 read=1313174 written=46, temp read=161558 written=161552 -> Hash Join (cost=2441.58..1913913.06 rows=805130 width=34) (actual time=80.197..76808.923 rows=1491377 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=453870 read=620848 written=46 -> Seq Scan on lineitem l1 (cost=0.00..1827914.35 rows=20134889 width=8) (actual time=0.111..54072.683 rows=37966100 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22079210 Buffers: shared hit=452021 read=620835 written=46 -> Hash (cost=2391.58..2391.58 rows=4000 width=30) (actual time=79.901..79.901 rows=3934 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 246kB Buffers: shared hit=1846 read=13 -> Nested Loop (cost=79.26..2391.58 rows=4000 width=30) (actual time=1.433..75.482 rows=3934 loops=1) Buffers: shared hit=1846 read=13 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.010..0.020 rows=1 loops=1) Filter: (n_name = 'ALGERIA'::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.416..73.880 rows=3934 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1845 read=13 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.26 rows=4000 width=0) (actual time=1.106..1.106 rows=3934 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared read=13 -> Hash (cost=1676902.68..1676902.68 rows=60404668 width=8) (actual time=73729.534..73729.534 rows=60045310 loops=1) Buckets: 4194304 Batches: 4 Memory Usage: 586609kB Buffers: shared hit=380530 read=692326, temp written=153904 -> Seq Scan on lineitem l2 (cost=0.00..1676902.68 rows=60404668 width=8) (actual time=0.021..49075.961 rows=60045310 loops=1) Buffers: shared hit=380530 read=692326 -> Index Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.96 rows=1 width=4) (actual time=0.022..0.023 rows=0 loops=1437988) Index Cond: (o_orderkey = l2.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5740790 read=19026 written=481 -> Index Scan using lineitem_l_orderkey_idx on lineitem l3 (cost=0.00..7.50 rows=5 width=8) (actual time=0.049..0.049 rows=1 loops=694895) 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=2891295 read=598983 dirtied=145 written=14786 Total runtime: 233406.957 ms (56 rows) COMMIT; COMMIT