BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select ps_partkey, sum(ps_supplycost * ps_availqty) as value from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'GERMANY' group by ps_partkey having sum(ps_supplycost * ps_availqty) > ( select sum(ps_supplycost * ps_availqty) * 0.0000100000 from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'GERMANY' ) order by value desc; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=614384.02..615183.97 rows=319981 width=12) (actual time=8381.146..8382.150 rows=8685 loops=1) Sort Key: (sum((partsupp.ps_supplycost * (partsupp.ps_availqty)::double precision))) Sort Method: quicksort Memory: 792kB Buffers: shared hit=28486 read=317797 written=673 InitPlan 1 (returns $1) -> Aggregate (cost=288962.98..288962.99 rows=1 width=8) (actual time=3970.017..3970.017 rows=1 loops=1) Buffers: shared hit=14564 read=158576 written=410 -> Hash Join (cost=2405.31..286563.12 rows=319981 width=8) (actual time=26.294..3869.794 rows=323920 loops=1) Hash Cond: (partsupp_1.ps_suppkey = supplier_1.s_suppkey) Buffers: shared hit=14564 read=158576 written=410 -> Seq Scan on partsupp partsupp_1 (cost=0.00..250958.00 rows=8000000 width=12) (actual time=0.015..2498.004 rows=8000000 loops=1) Buffers: shared hit=12383 read=158575 written=410 -> Hash (cost=2355.31..2355.31 rows=4000 width=4) (actual time=26.164..26.164 rows=4049 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 175kB Buffers: shared hit=2181 read=1 -> Nested Loop (cost=43.00..2355.31 rows=4000 width=4) (actual time=0.295..25.292 rows=4049 loops=1) Buffers: shared hit=2181 read=1 -> Seq Scan on nation nation_1 (cost=0.00..1.31 rows=1 width=4) (actual time=0.007..0.013 rows=1 loops=1) Filter: (n_name = 'GERMANY'::bpchar) Rows Removed by Filter: 24 Buffers: shared hit=1 -> Bitmap Heap Scan on supplier supplier_1 (cost=43.00..2314.00 rows=4000 width=8) (actual time=0.270..24.625 rows=4049 loops=1) Recheck Cond: (s_nationkey = nation_1.n_nationkey) Rows Removed by Index Recheck: 95951 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.249..0.249 rows=23040 loops=1) Index Cond: (s_nationkey = nation_1.n_nationkey) Buffers: shared hit=1 read=1 -> HashAggregate (cost=292162.79..296162.55 rows=319981 width=12) (actual time=8293.424..8376.334 rows=8685 loops=1) Group Key: partsupp.ps_partkey Filter: (sum((partsupp.ps_supplycost * (partsupp.ps_availqty)::double precision)) > $1) Rows Removed by Filter: 296089 Buffers: shared hit=28483 read=317797 written=673 -> Hash Join (cost=2405.31..286563.12 rows=319981 width=12) (actual time=41.815..4060.211 rows=323920 loops=1) Hash Cond: (partsupp.ps_suppkey = supplier.s_suppkey) Buffers: shared hit=13919 read=159221 written=263 -> Seq Scan on partsupp (cost=0.00..250958.00 rows=8000000 width=16) (actual time=0.035..2675.219 rows=8000000 loops=1) Buffers: shared hit=11739 read=159219 written=263 -> Hash (cost=2355.31..2355.31 rows=4000 width=4) (actual time=41.662..41.662 rows=4049 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 175kB Buffers: shared hit=2180 read=2 -> Nested Loop (cost=43.00..2355.31 rows=4000 width=4) (actual time=0.331..40.618 rows=4049 loops=1) Buffers: shared hit=2180 read=2 -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) (actual time=0.010..0.015 rows=1 loops=1) Filter: (n_name = 'GERMANY'::bpchar) Rows Removed by Filter: 24 Buffers: shared hit=1 -> Bitmap Heap Scan on supplier (cost=43.00..2314.00 rows=4000 width=8) (actual time=0.311..39.920 rows=4049 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Rows Removed by Index Recheck: 95951 Heap Blocks: lossy=2179 Buffers: shared hit=2179 read=2 -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_brin_idx (cost=0.00..42.00 rows=4000 width=0) (actual time=0.288..0.288 rows=23040 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared read=2 Planning time: 2.587 ms Execution time: 8387.924 ms (58 rows) COMMIT; COMMIT