BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select s_name, s_address from supplier, nation where s_suppkey in ( select distinct (ps_suppkey) from partsupp, part where ps_partkey=p_partkey and p_name like 'khaki%' and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= '1997-01-01' and l_shipdate < cast(date '1997-01-01' + interval '1 year' as date) ) ) and s_nationkey = n_nationkey and n_name = 'VIETNAM' order by s_name; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=14274841.83..14274845.02 rows=1275 width=51) (actual time=37815.545..37815.733 rows=1789 loops=1) Sort Key: supplier.s_name Sort Method: quicksort Memory: 256kB Buffers: shared hit=2719747 read=415107 dirtied=6270 written=574 -> Hash Semi Join (cost=14270307.53..14274776.06 rows=1275 width=51) (actual time=37684.206..37798.692 rows=1789 loops=1) Hash Cond: (supplier.s_suppkey = partsupp.ps_suppkey) Buffers: shared hit=2719742 read=415107 dirtied=6270 written=574 -> Nested Loop (cost=0.00..4430.31 rows=4000 width=55) (actual time=0.051..102.826 rows=3987 loops=1) Join Filter: (supplier.s_nationkey = nation.n_nationkey) Rows Removed by Join Filter: 96013 Buffers: shared hit=2180 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.016..0.024 rows=1 loops=1) Filter: (n_name = 'VIETNAM'::bpchar) Rows Removed by Filter: 24 Buffers: shared hit=1 -> Seq Scan on supplier (cost=0.00..3179.00 rows=100000 width=59) (actual time=0.025..80.031 rows=100000 loops=1) Buffers: shared hit=2179 -> Hash (cost=14269909.14..14269909.14 rows=31871 width=4) (actual time=37684.066..37684.066 rows=44855 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 1577kB Buffers: shared hit=2717562 read=415107 dirtied=6270 written=574 -> HashAggregate (cost=14269271.72..14269590.43 rows=31871 width=4) (actual time=37641.363..37670.425 rows=44855 loops=1) Buffers: shared hit=2717562 read=415107 dirtied=6270 written=574 -> Nested Loop (cost=0.00..14269192.04 rows=31871 width=4) (actual time=9.267..37466.549 rows=59380 loops=1) Buffers: shared hit=2717562 read=415107 dirtied=6270 written=574 -> Seq Scan on part (cost=0.00..65522.00 rows=24024 width=4) (actual time=0.010..2049.337 rows=21869 loops=1) Filter: ((p_name)::text ~~ 'khaki%'::text) Rows Removed by Filter: 1978131 Buffers: shared hit=9319 read=31203 written=13 -> Index Scan using pk_partsupp on partsupp (cost=0.00..591.22 rows=1 width=8) (actual time=1.122..1.615 rows=3 loops=21869) Index Cond: (ps_partkey = part.p_partkey) Filter: ((ps_availqty)::double precision > (SubPlan 1)) Rows Removed by Filter: 1 Buffers: shared hit=2708243 read=383904 dirtied=6270 written=561 SubPlan 1 -> Aggregate (cost=144.95..144.96 rows=1 width=4) (actual time=0.382..0.382 rows=1 loops=87476) Buffers: shared hit=2639632 read=362258 dirtied=6270 written=540 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.00..144.94 rows=1 width=4) (actual time=0.241..0.379 rows=1 loops=87476) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: ((l_shipdate >= '1997-01-01'::date) AND (l_shipdate < '1998-01-01'::date) AND (l_suppkey = partsupp.ps_suppkey)) Rows Removed by Filter: 29 Buffers: shared hit=2639632 read=362258 dirtied=6270 written=540 Total runtime: 37817.924 ms (42 rows) COMMIT; COMMIT