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 = 'RUSSIA' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2851853.10..2851853.11 rows=1 width=26) (actual time=38561.709..38561.724 rows=100 loops=1) Buffers: shared hit=14016768 read=428659 dirtied=1 written=506 -> Sort (cost=2851853.10..2851853.11 rows=1 width=26) (actual time=38561.708..38561.715 rows=100 loops=1) Sort Key: (count(*)), supplier.s_name Sort Method: top-N heapsort Memory: 32kB Buffers: shared hit=14016768 read=428659 dirtied=1 written=506 -> HashAggregate (cost=2851853.08..2851853.09 rows=1 width=26) (actual time=38559.555..38560.587 rows=4021 loops=1) Group Key: supplier.s_name Buffers: shared hit=14016760 read=428659 dirtied=1 written=506 -> Nested Loop Anti Join (cost=2406.88..2851853.08 rows=1 width=26) (actual time=45.556..38509.690 rows=39448 loops=1) Buffers: shared hit=14016760 read=428659 dirtied=1 written=506 -> Nested Loop Semi Join (cost=2406.31..2851851.30 rows=1 width=34) (actual time=41.800..35748.011 rows=710216 loops=1) Join Filter: (orders.o_orderkey = l2.l_orderkey) Buffers: shared hit=10451961 read=427437 dirtied=1 written=494 -> Nested Loop (cost=2405.75..2330215.11 rows=390404 width=38) (actual time=41.700..31785.610 rows=737149 loops=1) Buffers: shared hit=6801854 read=386366 dirtied=1 written=370 -> Hash Join (cost=2405.31..1908184.29 rows=801689 width=34) (actual time=41.653..24496.888 rows=1527002 loops=1) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) Buffers: shared hit=721558 read=350291 dirtied=1 written=40 -> Seq Scan on lineitem l1 (cost=0.00..1822480.44 rows=20075105 width=8) (actual time=0.014..18079.803 rows=37966584 loops=1) Filter: (l_receiptdate > l_commitdate) Rows Removed by Filter: 22078719 Buffers: shared hit=719374 read=350290 dirtied=1 written=40 -> Hash (cost=2355.31..2355.31 rows=4000 width=30) (actual time=41.542..41.542 rows=4021 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 284kB Buffers: shared hit=2181 read=1 -> Nested Loop (cost=43.00..2355.31 rows=4000 width=30) (actual time=0.347..40.356 rows=4021 loops=1) Buffers: shared hit=2181 read=1 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.009..0.012 rows=1 loops=1) Filter: (n_name = 'RUSSIA'::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.332..39.701 rows=4021 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Rows Removed by Index Recheck: 95979 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.314..0.314 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=1527002) Index Cond: (o_orderkey = l1.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) Rows Removed by Filter: 1 Buffers: shared hit=6080296 read=36075 written=330 -> 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=737149) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) Rows Removed by Filter: 0 Buffers: shared hit=3650107 read=41071 written=124 -> 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=710216) 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=3564799 read=1222 written=12 Planning time: 8.650 ms Execution time: 38562.034 ms (57 rows) COMMIT; COMMIT