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 'chocolate%' and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= '1995-01-01' and l_shipdate < cast(date '1995-01-01' + interval '1 year' as date) ) ) and s_nationkey = n_nationkey and n_name = 'ALGERIA' order by s_name; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=14274841.83..14274845.02 rows=1275 width=51) (actual time=40741.439..40741.669 rows=1789 loops=1) Sort Key: supplier.s_name Sort Method: quicksort Memory: 254kB Buffers: shared hit=2762259 read=375496 dirtied=5824 written=117 -> Hash Semi Join (cost=14270307.53..14274776.06 rows=1275 width=51) (actual time=40633.112..40727.905 rows=1789 loops=1) Hash Cond: (supplier.s_suppkey = partsupp.ps_suppkey) Buffers: shared hit=2762254 read=375496 dirtied=5824 written=117 -> Nested Loop (cost=0.00..4430.31 rows=4000 width=55) (actual time=1.772..87.253 rows=3934 loops=1) Join Filter: (supplier.s_nationkey = nation.n_nationkey) Rows Removed by Join Filter: 96066 Buffers: shared hit=2180 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.013..0.028 rows=1 loops=1) Filter: (n_name = 'ALGERIA'::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=1.732..62.209 rows=100000 loops=1) Buffers: shared hit=2179 -> Hash (cost=14269909.14..14269909.14 rows=31871 width=4) (actual time=40631.267..40631.267 rows=45003 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 1583kB Buffers: shared hit=2760074 read=375496 dirtied=5824 written=117 -> HashAggregate (cost=14269271.72..14269590.43 rows=31871 width=4) (actual time=40590.171..40614.871 rows=45003 loops=1) Buffers: shared hit=2760074 read=375496 dirtied=5824 written=117 -> Nested Loop (cost=0.00..14269192.04 rows=31871 width=4) (actual time=5.570..40428.744 rows=59457 loops=1) Buffers: shared hit=2760074 read=375496 dirtied=5824 written=117 -> Seq Scan on part (cost=0.00..65522.00 rows=24024 width=4) (actual time=0.023..1308.507 rows=21890 loops=1) Filter: ((p_name)::text ~~ 'chocolate%'::text) Rows Removed by Filter: 1978110 Buffers: shared hit=40522 -> Index Scan using pk_partsupp on partsupp (cost=0.00..591.22 rows=1 width=8) (actual time=1.209..1.783 rows=3 loops=21890) Index Cond: (ps_partkey = part.p_partkey) Filter: ((ps_availqty)::double precision > (SubPlan 1)) Rows Removed by Filter: 1 Buffers: shared hit=2719552 read=375496 dirtied=5824 written=117 SubPlan 1 -> Aggregate (cost=144.95..144.96 rows=1 width=4) (actual time=0.424..0.424 rows=1 loops=87560) Buffers: shared hit=2646688 read=358018 dirtied=5824 written=114 -> 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.265..0.421 rows=1 loops=87560) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate < '1996-01-01'::date) AND (l_suppkey = partsupp.ps_suppkey)) Rows Removed by Filter: 29 Buffers: shared hit=2646688 read=358018 dirtied=5824 written=114 Total runtime: 40744.468 ms (42 rows) COMMIT; COMMIT