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=10177591.19..10177593.94 rows=100 width=39) (actual time=109376.314..109376.589 rows=84 loops=1) Buffers: shared hit=1419902 read=1007228 written=18 -> GroupAggregate (cost=10177591.19..11005098.64 rows=30091180 width=39) (actual time=109376.310..109376.572 rows=84 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1419902 read=1007228 written=18 -> Sort (cost=10177591.19..10252819.14 rows=30091180 width=39) (actual time=109376.288..109376.329 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=1419902 read=1007228 written=18 -> Hash Join (cost=2893110.83..5617031.73 rows=30091180 width=39) (actual time=84888.289..109374.758 rows=588 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1419890 read=1007228 written=18 -> Seq Scan on lineitem (cost=0.00..1670729.60 rows=60182360 width=8) (actual time=0.031..14383.628 rows=59985653 loops=1) Buffers: shared hit=548385 read=520521 -> Hash (cost=2799079.88..2799079.88 rows=7522476 width=39) (actual time=84692.734..84692.734 rows=84 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=871505 read=486707 written=18 -> Hash Join (cost=2184307.26..2799079.88 rows=7522476 width=39) (actual time=74998.519..84692.100 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=871505 read=486707 written=18 -> Hash Join (cost=2115279.26..2617214.74 rows=7522476 width=20) (actual time=73145.854..82831.965 rows=84 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=836228 read=486706 written=18 -> Seq Scan on orders (cost=0.00..404477.52 rows=15044952 width=16) (actual time=0.016..3965.472 rows=15000000 loops=1) Buffers: shared hit=211197 read=42831 written=12 -> Hash (cost=2063980.03..2063980.03 rows=4103939 width=4) (actual time=72937.195..72937.195 rows=84 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=625031 read=443875 written=6 -> HashAggregate (cost=1971641.40..2022940.64 rows=4103939 width=8) (actual time=63503.027..72936.408 rows=84 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 314::double precision) Rows Removed by Filter: 14999916 Buffers: shared hit=625031 read=443875 written=6 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1670729.60 rows=60182360 width=8) (actual time=0.017..16837.186 rows=59985653 loops=1) Buffers: shared hit=625031 read=443875 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1830.466..1830.466 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35277 read=1 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.020..959.515 rows=1500000 loops=1) Buffers: shared hit=35277 read=1 Planning time: 6.360 ms Execution time: 109602.843 ms (42 rows) COMMIT; COMMIT