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) > 314 ) 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=10405176.35..10405179.10 rows=100 width=39) (actual time=98981.627..98982.145 rows=85 loops=1) Buffers: shared hit=1566473 read=874319 dirtied=1074 written=1 -> GroupAggregate (cost=10405176.35..11237377.55 rows=30261862 width=39) (actual time=98981.621..98982.123 rows=85 loops=1) Buffers: shared hit=1566473 read=874319 dirtied=1074 written=1 -> Sort (cost=10405176.35..10480831.00 rows=30261862 width=39) (actual time=98981.592..98981.668 rows=595 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 71kB Buffers: shared hit=1566473 read=874319 dirtied=1074 written=1 -> Hash Join (cost=3078137.18..5817515.58 rows=30261862 width=39) (actual time=69771.700..98977.126 rows=595 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1566459 read=874319 dirtied=1074 written=1 -> Seq Scan on lineitem (cost=0.00..1680213.23 rows=60523723 width=8) (actual time=0.079..16575.355 rows=60044082 loops=1) Buffers: shared hit=436651 read=638325 -> Hash (cost=2983543.58..2983543.58 rows=7567488 width=39) (actual time=69641.967..69641.967 rows=85 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=1129808 read=235994 dirtied=1074 written=1 -> Hash Join (cost=2195164.65..2983543.58 rows=7567488 width=39) (actual time=60855.391..69641.533 rows=85 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1129808 read=235994 dirtied=1074 written=1 -> Hash Join (cost=2126136.65..2763165.82 rows=7567488 width=20) (actual time=59540.375..68324.990 rows=85 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=1094625 read=235899 dirtied=1074 written=1 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=16) (actual time=0.019..4436.951 rows=15015000 loops=1) Buffers: shared hit=251349 read=4199 dirtied=4 written=1 -> Hash (cost=2074956.36..2074956.36 rows=4094423 width=4) (actual time=59427.452..59427.452 rows=85 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=843276 read=231700 dirtied=1070 -> HashAggregate (cost=1982831.85..2034012.13 rows=4094423 width=8) (actual time=52794.870..59426.778 rows=85 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014915 Buffers: shared hit=843276 read=231700 dirtied=1070 -> Seq Scan on lineitem (cost=0.00..1680213.23 rows=60523723 width=8) (actual time=0.014..15708.869 rows=60044082 loops=1) Buffers: shared hit=843276 read=231700 dirtied=1070 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1312.988..1312.988 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35183 read=95 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.018..691.814 rows=1500000 loops=1) Buffers: shared hit=35183 read=95 Total runtime: 99150.150 ms (39 rows) COMMIT; COMMIT