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 = 'ETHIOPIA' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2877569.97..2877569.97 rows=1 width=26) (actual time=41555.288..41555.304 rows=100 loops=1) Buffers: shared hit=13510623 read=677298 written=369 -> Sort (cost=2877569.97..2877569.97 rows=1 width=26) (actual time=41555.286..41555.292 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=13510623 read=677298 written=369 -> HashAggregate (cost=2877569.95..2877569.96 rows=1 width=26) (actual time=41553.044..41554.140 rows=3945 loops=1) Group Key: supplier.s_name Buffers: shared hit=13510615 read=677298 written=369 -> Nested Loop Anti Join (cost=2406.88..2877569.94 rows=1 width=26) (actual time=43.478..41497.902 rows=38931 loops=1) Buffers: shared hit=13510615 read=677298 written=369 -> Nested Loop Semi Join (cost=2406.31..2877568.16 rows=1 width=34) (actual time=42.143..38679.494 rows=696735 loops=1) Join Filter: (orders.o_orderkey = l2.l_orderkey) Buffers: shared hit=10014350 read=674838 written=363 -> Nested Loop (cost=2405.75..2351156.45 rows=393906 width=38) (actual time=42.114..33735.093 rows=722872 loops=1) Buffers: shared hit=6537442 read=531807 written=53 -> Hash Join (cost=2405.31..1925281.11 rows=808881 width=34) (actual time=41.990..26262.993 rows=1494939 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=567387 read=514058 written=15 -> Seq Scan on lineitem l1 (cost=0.00..1838829.99 rows=20255200 width=8) (actual time=0.014..19100.564 rows=37928434 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22057104 Buffers: shared hit=565202 read=514058 written=15 -> Hash (cost=2355.31..2355.31 rows=4000 width=30) (actual time=41.931..41.931 rows=3945 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 279kB Buffers: shared hit=2182 -> Nested Loop (cost=43.00..2355.31 rows=4000 width=30) (actual time=0.286..40.726 rows=3945 loops=1) Buffers: shared hit=2182 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.005..0.010 rows=1 loops=1) Filter: (n_name = 'ETHIOPIA'::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.275..40.095 rows=3945 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Rows Removed by Index Recheck: 96055 Heap Blocks: lossy=2179 Buffers: shared hit=2181 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_brin_idx (cost=0.00..42.00 rows=4000 width=0) (actual time=0.258..0.258 rows=23040 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=2 -> 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=1494939) Index Cond: (o_orderkey = l1.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=5970055 read=17749 written=38 -> 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=722872) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) Rows Removed by Filter: 0 Buffers: shared hit=3476908 read=143031 written=310 -> Index Scan using pk_lineitem on lineitem l3 (cost=0.56..1.15 rows=5 width=8) (actual time=0.004..0.004 rows=1 loops=696735) 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=3496265 read=2460 written=6 Planning time: 9.034 ms Execution time: 41555.609 ms (57 rows) COMMIT; COMMIT