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=10171464.88..10171467.63 rows=100 width=39) (actual time=73747.507..73747.747 rows=75 loops=1) Buffers: shared hit=1541752 read=884782 dirtied=1426 written=6366 -> GroupAggregate (cost=10171464.88..10998741.30 rows=30082779 width=39) (actual time=73747.503..73747.735 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1541752 read=884782 dirtied=1426 written=6366 -> Sort (cost=10171464.88..10246671.82 rows=30082779 width=39) (actual time=73747.480..73747.517 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=1541752 read=884782 dirtied=1426 written=6366 -> Hash Join (cost=2889079.70..5612240.54 rows=30082779 width=39) (actual time=54774.757..73746.105 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1541740 read=884782 dirtied=1426 written=6366 -> Seq Scan on lineitem (cost=0.00..1670263.58 rows=60165558 width=8) (actual time=0.026..10330.434 rows=60045379 loops=1) Buffers: shared hit=686088 read=382520 dirtied=398 written=395 -> Hash (cost=2795048.75..2795048.75 rows=7522476 width=39) (actual time=54663.750..54663.750 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=855652 read=502262 dirtied=1028 written=5971 -> Hash Join (cost=2181049.71..2795048.75 rows=7522476 width=39) (actual time=46875.151..54663.101 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=855652 read=502262 dirtied=1028 written=5971 -> Hash Join (cost=2112021.71..2613183.60 rows=7522476 width=20) (actual time=45682.864..53463.866 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=855650 read=466986 dirtied=1028 written=136 -> Seq Scan on orders (cost=0.00..404477.52 rows=15044952 width=16) (actual time=0.009..2911.419 rows=15015000 loops=1) Buffers: shared hit=226986 read=27042 dirtied=17 -> Hash (cost=2061689.44..2061689.44 rows=4026581 width=4) (actual time=45514.054..45514.054 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=628664 read=439944 dirtied=1011 written=136 -> HashAggregate (cost=1971091.37..2021423.63 rows=4026581 width=8) (actual time=39073.559..45510.506 rows=75 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=628664 read=439944 dirtied=1011 written=136 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1670263.58 rows=60165558 width=8) (actual time=0.009..11483.902 rows=60045379 loops=1) Buffers: shared hit=628664 read=439944 dirtied=1011 written=136 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1178.442..1178.442 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 written=5835 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.014..692.039 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=5835 Planning time: 3.577 ms Execution time: 74049.336 ms (42 rows) COMMIT; COMMIT