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=10333047.66..10333050.41 rows=100 width=39) (actual time=114213.377..114213.875 rows=84 loops=1) Buffers: shared hit=1631508 read=792651 -> GroupAggregate (cost=10333047.66..11159498.07 rows=30052742 width=39) (actual time=114213.374..114213.857 rows=84 loops=1) Buffers: shared hit=1631508 read=792651 -> Sort (cost=10333047.66..10408179.52 rows=30052742 width=39) (actual time=114213.349..114213.450 rows=588 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 70kB Buffers: shared hit=1631508 read=792651 -> Hash Join (cost=3058143.04..5778589.85 rows=30052742 width=39) (actual time=86325.951..114209.090 rows=588 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1631494 read=792651 -> Seq Scan on lineitem (cost=0.00..1668600.84 rows=60105484 width=8) (actual time=0.050..15688.530 rows=60045603 loops=1) Buffers: shared hit=668837 read=398709 -> Hash (cost=2964205.74..2964205.74 rows=7514984 width=39) (actual time=85904.473..85904.473 rows=84 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=962657 read=393942 -> Hash Join (cost=2181112.22..2964205.74 rows=7514984 width=39) (actual time=76930.504..85903.942 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=962657 read=393942 -> Hash Join (cost=2112084.22..2744878.06 rows=7514984 width=20) (actual time=74539.647..83507.308 rows=84 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=927379 read=393942 -> Seq Scan on orders (cost=0.00..404074.68 rows=15029968 width=16) (actual time=0.011..3987.818 rows=15015000 loops=1) Buffers: shared hit=253775 -> Hash (cost=2061028.52..2061028.52 rows=4084456 width=4) (actual time=74377.719..74377.719 rows=84 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=673604 read=393942 -> HashAggregate (cost=1969128.26..2020183.96 rows=4084456 width=8) (actual time=63656.897..74376.911 rows=84 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=673604 read=393942 -> Seq Scan on lineitem (cost=0.00..1668600.84 rows=60105484 width=8) (actual time=0.022..16484.086 rows=60045603 loops=1) Buffers: shared hit=673604 read=393942 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2389.133..2389.133 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.016..633.914 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 114596.750 ms (39 rows) COMMIT; COMMIT