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 = 'RUSSIA' 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 = 'RUSSIA' ) order by value desc; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=614384.02..615183.97 rows=319981 width=12) (actual time=8868.498..8869.543 rows=9062 loops=1) Sort Key: (sum((partsupp.ps_supplycost * (partsupp.ps_availqty)::double precision))) Sort Method: quicksort Memory: 809kB Buffers: shared hit=29525 read=316758 written=10344 InitPlan 1 (returns $1) -> Aggregate (cost=288962.98..288962.99 rows=1 width=8) (actual time=4259.760..4259.760 rows=1 loops=1) Buffers: shared hit=12556 read=160584 written=1044 -> Hash Join (cost=2405.31..286563.12 rows=319981 width=8) (actual time=28.056..4154.781 rows=321680 loops=1) Hash Cond: (partsupp_1.ps_suppkey = supplier_1.s_suppkey) Buffers: shared hit=12556 read=160584 written=1044 -> Seq Scan on partsupp partsupp_1 (cost=0.00..250958.00 rows=8000000 width=12) (actual time=0.015..2756.807 rows=8000000 loops=1) Buffers: shared hit=10375 read=160583 written=1044 -> Hash (cost=2355.31..2355.31 rows=4000 width=4) (actual time=27.990..27.990 rows=4021 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 174kB Buffers: shared hit=2181 read=1 -> Nested Loop (cost=43.00..2355.31 rows=4000 width=4) (actual time=0.303..27.010 rows=4021 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.010..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 supplier_1 (cost=43.00..2314.00 rows=4000 width=8) (actual time=0.273..26.306 rows=4021 loops=1) Recheck Cond: (s_nationkey = nation_1.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.255..0.255 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=8787.784..8863.515 rows=9062 loops=1) Group Key: partsupp.ps_partkey Filter: (sum((partsupp.ps_supplycost * (partsupp.ps_availqty)::double precision)) > $1) Rows Removed by Filter: 293861 Buffers: shared hit=29522 read=316758 written=10344 -> Hash Join (cost=2405.31..286563.12 rows=319981 width=12) (actual time=41.493..4275.914 rows=321680 loops=1) Hash Cond: (partsupp.ps_suppkey = supplier.s_suppkey) Buffers: shared hit=16966 read=156174 written=9300 -> Seq Scan on partsupp (cost=0.00..250958.00 rows=8000000 width=16) (actual time=0.029..2895.228 rows=8000000 loops=1) Buffers: shared hit=14786 read=156172 written=9300 -> Hash (cost=2355.31..2355.31 rows=4000 width=4) (actual time=41.428..41.428 rows=4021 loops=1) Buckets: 4096 Batches: 1 Memory Usage: 174kB Buffers: shared hit=2180 read=2 -> Nested Loop (cost=43.00..2355.31 rows=4000 width=4) (actual time=0.303..40.402 rows=4021 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.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=8) (actual time=0.283..39.714 rows=4021 loops=1) Recheck Cond: (s_nationkey = nation.n_nationkey) Rows Removed by Index Recheck: 95979 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.267..0.267 rows=23040 loops=1) Index Cond: (s_nationkey = nation.n_nationkey) Buffers: shared read=2 Planning time: 2.634 ms Execution time: 8873.292 ms (58 rows) COMMIT; COMMIT