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=4804074.34..4804074.35 rows=1 width=26) (actual time=80132.492..80132.508 rows=100 loops=1) Buffers: shared hit=10099134 read=1365524, temp read=161624 written=161618 -> Sort (cost=4804074.34..4804074.35 rows=1 width=26) (actual time=80132.482..80132.485 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=10099134 read=1365524, temp read=161624 written=161618 -> HashAggregate (cost=4804074.32..4804074.33 rows=1 width=26) (actual time=80127.724..80129.783 rows=3960 loops=1) Buffers: shared hit=10099126 read=1365524, temp read=161624 written=161618 -> Nested Loop Anti Join (cost=2654504.08..4804074.32 rows=1 width=26) (actual time=29724.258..80055.573 rows=39274 loops=1) Buffers: shared hit=10099126 read=1365524, temp read=161624 written=161618 -> Nested Loop (cost=2654504.08..4804059.42 rows=1 width=34) (actual time=29708.113..72775.273 rows=700562 loops=1) Join Filter: (l1.l_orderkey = orders.o_orderkey) Buffers: shared hit=6991358 read=954493, temp read=161624 written=161618 -> Hash Semi Join (cost=2654504.08..4804057.46 rows=1 width=38) (actual time=29708.025..65635.673 rows=1450782 loops=1) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) Rows Removed by Join Filter: 376708 Buffers: shared hit=1281845 read=852952, temp read=161624 written=161618 -> Hash Join (cost=2441.58..1902544.79 rows=799724 width=34) (actual time=18.869..25368.230 rows=1504530 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=568489 read=499833 -> Seq Scan on lineitem l1 (cost=0.00..1817048.61 rows=20015296 width=8) (actual time=0.016..18377.191 rows=37967116 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22078553 Buffers: shared hit=566657 read=499818 -> Hash (cost=2391.58..2391.58 rows=4000 width=30) (actual time=18.833..18.833 rows=3961 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 248kB Buffers: shared hit=1829 read=15 -> Nested Loop (cost=79.26..2391.58 rows=4000 width=30) (actual time=1.199..17.477 rows=3961 loops=1) Buffers: shared hit=1829 read=15 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.007..0.012 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.187..16.571 rows=3961 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1828 read=15 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.26 rows=4000 width=0) (actual time=0.852..0.852 rows=3961 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared read=14 -> Hash (cost=1666933.89..1666933.89 rows=60045889 width=8) (actual time=29658.333..29658.333 rows=60045669 loops=1) Buckets: 4194304 Batches: 4 Memory Usage: 586630kB Buffers: shared hit=713356 read=353119, temp written=153903 -> Seq Scan on lineitem l2 (cost=0.00..1666933.89 rows=60045889 width=8) (actual time=0.011..16438.874 rows=60045669 loops=1) Buffers: shared hit=713356 read=353119 -> Index Scan using pk_orders on orders (cost=0.00..1.94 rows=1 width=4) (actual time=0.004..0.004 rows=0 loops=1450782) Index Cond: (o_orderkey = l2.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5709513 read=101541 -> Index Scan using lineitem_l_orderkey_idx on lineitem l3 (cost=0.00..7.42 rows=5 width=8) (actual time=0.010..0.010 rows=1 loops=700562) 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=3107768 read=411031 Total runtime: 80133.402 ms (56 rows) COMMIT; COMMIT