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=10230376.82..10230379.57 rows=100 width=39) (actual time=93804.595..93804.830 rows=75 loops=1) Buffers: shared hit=1423342 read=1017448 written=500 -> GroupAggregate (cost=10230376.82..11062586.22 rows=30262160 width=39) (actual time=93804.591..93804.815 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1423342 read=1017448 written=500 -> Sort (cost=10230376.82..10306032.22 rows=30262160 width=39) (actual time=93804.579..93804.604 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=1423342 read=1017448 written=500 -> Hash Join (cost=2903271.55..5642666.37 rows=30262160 width=39) (actual time=71572.763..93803.638 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1423330 read=1017448 written=500 -> Seq Scan on lineitem (cost=0.00..1680219.20 rows=60524320 width=8) (actual time=0.027..12803.093 rows=59983922 loops=1) Buffers: shared hit=653729 read=421247 -> Hash (cost=2808677.95..2808677.95 rows=7567488 width=39) (actual time=71481.201..71481.201 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=769601 read=596201 written=500 -> Hash Join (cost=2191591.08..2808677.95 rows=7567488 width=39) (actual time=64782.929..71480.799 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=769601 read=596201 written=500 -> Hash Join (cost=2122563.08..2626137.63 rows=7567488 width=20) (actual time=63255.380..69949.307 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=769599 read=560925 written=75 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=16) (actual time=0.010..3790.842 rows=15000000 loops=1) Buffers: shared hit=198173 read=57375 written=66 -> Hash (cost=2072662.26..2072662.26 rows=3992065 width=4) (actual time=63110.667..63110.667 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=571426 read=503550 written=9 -> HashAggregate (cost=1982840.80..2032741.61 rows=3992065 width=8) (actual time=54942.846..63110.205 rows=75 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 315::double precision) Rows Removed by Filter: 14999925 Buffers: shared hit=571426 read=503550 written=9 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1680219.20 rows=60524320 width=8) (actual time=0.011..14200.733 rows=59983922 loops=1) Buffers: shared hit=571426 read=503550 written=9 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1508.881..1508.881 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 written=425 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.016..845.941 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=425 Planning time: 5.284 ms Execution time: 93996.223 ms (42 rows) COMMIT; COMMIT