BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) from customer, orders, lineitem where o_orderkey in ( select l_orderkey from lineitem group by l_orderkey having sum(l_quantity) > 313 ) and c_custkey = o_custkey and o_orderkey = l_orderkey group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice order by o_totalprice desc, o_orderdate LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=10318542.79..10318545.54 rows=100 width=39) (actual time=64569.069..64569.355 rows=99 loops=1) Buffers: shared hit=1736830 read=684934 dirtied=254 -> GroupAggregate (cost=10318542.79..11144167.04 rows=30022700 width=39) (actual time=64569.064..64569.340 rows=99 loops=1) Buffers: shared hit=1736830 read=684934 dirtied=254 -> Sort (cost=10318542.79..10393599.54 rows=30022700 width=39) (actual time=64569.024..64569.064 rows=693 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1736830 read=684934 dirtied=254 -> Hash Join (cost=3051131.94..5768855.45 rows=30022700 width=39) (actual time=47571.780..64565.248 rows=693 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1736816 read=684934 dirtied=254 -> Seq Scan on lineitem (cost=0.00..1666929.00 rows=60045400 width=8) (actual time=0.014..10009.474 rows=60045669 loops=1) Buffers: shared hit=754584 read=311891 -> Hash (cost=2957288.29..2957288.29 rows=7507492 width=39) (actual time=47194.502..47194.502 rows=99 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=982232 read=373043 dirtied=254 -> Hash Join (cost=2175869.25..2957288.29 rows=7507492 width=39) (actual time=41675.701..47193.791 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=982232 read=373043 dirtied=254 -> Hash Join (cost=2106841.25..2738110.46 rows=7507492 width=20) (actual time=40716.309..46233.925 rows=99 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=982230 read=337767 dirtied=254 -> Seq Scan on orders (cost=0.00..403671.84 rows=15014984 width=16) (actual time=0.007..3366.290 rows=15015000 loops=1) Buffers: shared hit=802 read=252720 dirtied=254 -> Hash (cost=2056953.66..2056953.66 rows=3991007 width=4) (actual time=40584.185..40584.185 rows=99 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=981428 read=85047 -> HashAggregate (cost=1967156.00..2017043.59 rows=3991007 width=8) (actual time=35069.198..40583.066 rows=99 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014901 Buffers: shared hit=981428 read=85047 -> Seq Scan on lineitem (cost=0.00..1666929.00 rows=60045400 width=8) (actual time=0.009..11950.431 rows=60045669 loops=1) Buffers: shared hit=981428 read=85047 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=957.278..957.278 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=2 read=35276 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.011..556.033 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 Total runtime: 64635.044 ms (39 rows) COMMIT; COMMIT