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) > 315 ) 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=10404591.11..10404593.86 rows=100 width=39) (actual time=224824.127..224824.569 rows=75 loops=1) Buffers: shared hit=1333659 read=1107133 written=4 -> GroupAggregate (cost=10404591.11..11236790.01 rows=30261778 width=39) (actual time=224824.124..224824.554 rows=75 loops=1) Buffers: shared hit=1333659 read=1107133 written=4 -> Sort (cost=10404591.11..10480245.56 rows=30261778 width=39) (actual time=224824.099..224824.180 rows=525 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 66kB Buffers: shared hit=1333659 read=1107133 written=4 -> Hash Join (cost=3077567.55..5816941.38 rows=30261778 width=39) (actual time=150138.122..224820.156 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1333645 read=1107133 written=4 -> Seq Scan on lineitem (cost=0.00..1680211.57 rows=60523557 width=8) (actual time=0.072..59178.296 rows=60044082 loops=1) Buffers: shared hit=396477 read=678499 written=1 -> Hash (cost=2982973.95..2982973.95 rows=7567488 width=39) (actual time=149858.124..149858.124 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=937168 read=428634 written=3 -> Hash Join (cost=2194721.06..2982973.95 rows=7567488 width=39) (actual time=131365.526..149857.563 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=937168 read=428634 written=3 -> Hash Join (cost=2125693.06..2762596.19 rows=7567488 width=20) (actual time=128789.894..147280.334 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=901993 read=428531 written=3 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=16) (actual time=0.012..12284.659 rows=15015000 loops=1) Buffers: shared hit=245906 read=9642 written=3 -> Hash (cost=2074670.31..2074670.31 rows=4081820 width=4) (actual time=128372.483..128372.483 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=656087 read=418889 -> HashAggregate (cost=1982829.36..2033852.11 rows=4081820 width=8) (actual time=118835.220..128371.626 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=656087 read=418889 -> Seq Scan on lineitem (cost=0.00..1680211.57 rows=60523557 width=8) (actual time=0.009..65264.744 rows=60044082 loops=1) Buffers: shared hit=656087 read=418889 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2574.000..2574.000 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35175 read=103 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.013..1724.613 rows=1500000 loops=1) Buffers: shared hit=35175 read=103 Total runtime: 225127.001 ms (39 rows) COMMIT; COMMIT