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 = 'IRAQ' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2846169.14..2846169.14 rows=1 width=26) (actual time=39843.522..39843.538 rows=100 loops=1) Buffers: shared hit=14161369 read=546079 dirtied=1321 written=3301 -> Sort (cost=2846169.14..2846169.14 rows=1 width=26) (actual time=39843.520..39843.526 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=14161369 read=546079 dirtied=1321 written=3301 -> HashAggregate (cost=2846169.12..2846169.13 rows=1 width=26) (actual time=39841.319..39842.411 rows=4095 loops=1) Group Key: supplier.s_name Buffers: shared hit=14161361 read=546079 dirtied=1321 written=3301 -> Nested Loop Anti Join (cost=2406.88..2846169.11 rows=1 width=26) (actual time=32.352..39789.548 rows=40955 loops=1) Buffers: shared hit=14161361 read=546079 dirtied=1321 written=3301 -> Nested Loop Semi Join (cost=2406.31..2846167.33 rows=1 width=34) (actual time=32.284..36931.498 rows=724776 loops=1) Join Filter: (orders.o_orderkey = l2.l_orderkey) Buffers: shared hit=10523618 read=544455 dirtied=1318 written=3289 -> Nested Loop (cost=2405.75..2325586.21 rows=389630 width=38) (actual time=32.243..32540.225 rows=752178 loops=1) Buffers: shared hit=6817913 read=483565 dirtied=1316 written=1560 -> Hash Join (cost=2405.31..1904405.39 rows=800100 width=34) (actual time=32.199..24851.407 rows=1555822 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=643032 read=426696 dirtied=1064 written=1045 -> Seq Scan on lineitem l1 (cost=0.00..1818866.70 rows=20035299 width=8) (actual time=0.013..18346.140 rows=37966905 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22078698 Buffers: shared hit=640848 read=426695 dirtied=1064 written=1045 -> Hash (cost=2355.31..2355.31 rows=4000 width=30) (actual time=32.147..32.147 rows=4095 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 288kB Buffers: shared hit=2181 read=1 -> Nested Loop (cost=43.00..2355.31 rows=4000 width=30) (actual time=0.304..30.957 rows=4095 loops=1) Buffers: shared hit=2181 read=1 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.006..0.010 rows=1 loops=1) Filter: (n_name = 'IRAQ'::bpchar) Rows Removed by Filter: 24 Buffers: shared hit=1 -> Bitmap Heap Scan on supplier (cost=43.00..2314.00 rows=4000 width=34) (actual time=0.290..30.289 rows=4095 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Rows Removed by Index Recheck: 95905 Heap Blocks: lossy=2179 Buffers: shared hit=2180 read=1 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_brin_idx (cost=0.00..42.00 rows=4000 width=0) (actual time=0.269..0.269 rows=23040 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1 read=1 -> Index Scan using pk_orders on orders (cost=0.43..0.52 rows=1 width=4) (actual time=0.004..0.004 rows=0 loops=1555822) Index Cond: (o_orderkey = l1.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=6174881 read=56869 dirtied=252 written=515 -> Index Scan using pk_lineitem on lineitem l2 (cost=0.56..1.15 rows=15 width=8) (actual time=0.005..0.005 rows=1 loops=752178) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) Rows Removed by Filter: 0 Buffers: shared hit=3705705 read=60890 dirtied=2 written=1729 -> Index Scan using pk_lineitem on lineitem l3 (cost=0.56..1.15 rows=5 width=8) (actual time=0.003..0.003 rows=1 loops=724776) 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=3637743 read=1624 dirtied=3 written=12 Planning time: 8.744 ms Execution time: 39843.869 ms (57 rows) COMMIT; COMMIT