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 = 'CANADA' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=1970662.34..1970662.35 rows=1 width=26) (actual time=44268.355..44268.376 rows=100 loops=1) Buffers: shared hit=14068298 read=697556 dirtied=184 written=10615 -> Sort (cost=1970662.34..1970662.35 rows=1 width=26) (actual time=44268.351..44268.358 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=14068298 read=697556 dirtied=184 written=10615 -> HashAggregate (cost=1970662.32..1970662.33 rows=1 width=26) (actual time=44265.042..44267.106 rows=4054 loops=1) Group Key: supplier.s_name Buffers: shared hit=14068290 read=697556 dirtied=184 written=10615 -> Nested Loop Anti Join (cost=2443.74..1970662.32 rows=1 width=26) (actual time=22.424..44193.042 rows=40204 loops=1) Buffers: shared hit=14068290 read=697556 dirtied=184 written=10615 -> Nested Loop Semi Join (cost=2443.17..1970661.01 rows=1 width=34) (actual time=15.404..41163.423 rows=716635 loops=1) Join Filter: (orders.o_orderkey = l2.l_orderkey) Buffers: shared hit=10478705 read=695752 dirtied=184 written=10593 -> Nested Loop (cost=2442.61..1446119.35 rows=392522 width=38) (actual time=15.350..35807.773 rows=743939 loops=1) Buffers: shared hit=6886522 read=562633 dirtied=184 written=8224 -> Hash Join (cost=2442.17..1020844.81 rows=807763 width=34) (actual time=15.216..27137.198 rows=1538034 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=758551 read=530100 dirtied=4 written=8034 -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem l1 (cost=0.56..934519.81 rows=20214871 width=8) (actual time=0.063..19053.190 rows=37965800 loops=1) Buffers: shared hit=756693 read=530088 dirtied=4 written=8034 -> Hash (cost=2391.61..2391.61 rows=4000 width=30) (actual time=15.046..15.046 rows=4054 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 286kB Buffers: shared hit=1855 read=12 -> Nested Loop (cost=79.29..2391.61 rows=4000 width=30) (actual time=1.257..13.942 rows=4054 loops=1) Buffers: shared hit=1855 read=12 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.011..0.021 rows=1 loops=1) Filter: (n_name = 'CANADA'::bpchar) Rows Removed by Filter: 24 Buffers: shared hit=1 -> Bitmap Heap Scan on supplier (cost=79.29..2350.29 rows=4000 width=34) (actual time=1.240..13.163 rows=4054 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Heap Blocks: exact=1853 Buffers: shared hit=1854 read=12 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.29 rows=4000 width=0) (actual time=0.942..0.942 rows=4054 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1 read=12 -> Index Scan using pk_orders on orders (cost=0.43..0.52 rows=1 width=4) (actual time=0.005..0.005 rows=0 loops=1538034) Index Cond: (o_orderkey = l1.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=6127971 read=32533 dirtied=180 written=190 -> Index Scan using pk_lineitem on lineitem l2 (cost=0.56..1.15 rows=15 width=8) (actual time=0.006..0.006 rows=1 loops=743939) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) Rows Removed by Filter: 0 Buffers: shared hit=3592183 read=133119 written=2369 -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem l3 (cost=0.56..0.91 rows=5 width=8) (actual time=0.004..0.004 rows=1 loops=716635) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) Rows Removed by Filter: 0 Buffers: shared hit=3589585 read=1804 written=22 Planning time: 9.779 ms Execution time: 44268.796 ms (54 rows) COMMIT; COMMIT