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 'forest%' and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= '1996-01-01' and l_shipdate < cast(date '1996-01-01' + interval '1 year' as date) ) ) and s_nationkey = n_nationkey and n_name = 'CANADA' order by s_name; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=11590321.29..11590323.95 rows=1063 width=51) (actual time=14883.753..14883.923 rows=1830 loops=1) Sort Key: supplier.s_name Sort Method: quicksort Memory: 261kB Buffers: shared hit=2715389 read=369134 dirtied=4400 written=72 -> Hash Semi Join (cost=11587924.74..11590267.86 rows=1063 width=51) (actual time=14824.084..14851.507 rows=1830 loops=1) Hash Cond: (supplier.s_suppkey = partsupp.ps_suppkey) Buffers: shared hit=2715384 read=369134 dirtied=4400 written=72 -> Nested Loop (cost=79.26..2391.58 rows=4000 width=55) (actual time=1.737..17.805 rows=4054 loops=1) Buffers: shared hit=1856 read=12 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.015..0.024 rows=1 loops=1) Filter: (n_name = 'CANADA'::bpchar) Rows Removed by Filter: 24 Buffers: shared hit=1 -> Bitmap Heap Scan on supplier (cost=79.26..2350.26 rows=4000 width=59) (actual time=1.715..16.325 rows=4054 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=1855 read=12 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..78.26 rows=4000 width=0) (actual time=1.332..1.332 rows=4054 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared hit=2 read=12 -> Hash (cost=11587513.26..11587513.26 rows=26577 width=4) (actual time=14822.265..14822.265 rows=44389 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 1561kB Buffers: shared hit=2713528 read=369122 dirtied=4400 written=72 -> HashAggregate (cost=11586981.72..11587247.49 rows=26577 width=4) (actual time=14775.725..14805.192 rows=44389 loops=1) Buffers: shared hit=2713528 read=369122 dirtied=4400 written=72 -> Nested Loop (cost=0.00..11586915.28 rows=26577 width=4) (actual time=0.958..14658.902 rows=58485 loops=1) Buffers: shared hit=2713528 read=369122 dirtied=4400 written=72 -> Seq Scan on part (cost=0.00..65522.00 rows=20019 width=4) (actual time=0.013..1329.727 rows=21551 loops=1) Filter: ((p_name)::text ~~ 'forest%'::text) Rows Removed by Filter: 1978449 Buffers: shared hit=1 read=40521 written=9 -> Index Scan using pk_partsupp on partsupp (cost=0.00..575.51 rows=1 width=8) (actual time=0.477..0.615 rows=3 loops=21551) Index Cond: (ps_partkey = part.p_partkey) Filter: ((ps_availqty)::double precision > (SubPlan 1)) Rows Removed by Filter: 1 Buffers: shared hit=2713527 read=328601 dirtied=4400 written=63 SubPlan 1 -> Aggregate (cost=140.92..140.94 rows=1 width=4) (actual time=0.142..0.143 rows=1 loops=86204) Buffers: shared hit=2648682 read=304374 dirtied=4400 written=55 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.00..140.92 rows=1 width=4) (actual time=0.089..0.140 rows=1 loops=86204) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1997-01-01'::date) AND (l_suppkey = partsupp.ps_suppkey)) Rows Removed by Filter: 29 Buffers: shared hit=2648682 read=304374 dirtied=4400 written=55 Total runtime: 14885.537 ms (44 rows) COMMIT; COMMIT