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) > 312 ) 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=10217159.84..10217162.59 rows=100 width=39) (actual time=84862.667..84863.108 rows=100 loops=1) Buffers: shared hit=1444825 read=991646 written=2811 -> GroupAggregate (cost=10217159.84..11047890.90 rows=30208402 width=39) (actual time=84862.664..84863.090 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1444825 read=991646 written=2811 -> Sort (cost=10217159.84..10292680.85 rows=30208402 width=39) (actual time=84862.648..84862.706 rows=701 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 85kB Buffers: shared hit=1444825 read=991646 written=2811 -> Hash Join (cost=2903454.40..5637986.53 rows=30208402 width=39) (actual time=63964.418..84860.972 rows=777 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1444813 read=991646 written=2811 -> Seq Scan on lineitem (cost=0.00..1677238.05 rows=60416805 width=8) (actual time=0.025..12201.014 rows=59984909 loops=1) Buffers: shared hit=637367 read=435703 -> Hash (cost=2809048.47..2809048.47 rows=7552474 width=39) (actual time=63744.961..63744.961 rows=111 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=807446 read=555943 written=2811 -> Hash Join (cost=2191987.94..2809048.47 rows=7552474 width=39) (actual time=53624.207..63744.558 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=807446 read=555943 written=2811 -> Hash Join (cost=2122959.94..2626733.36 rows=7552474 width=20) (actual time=52600.968..62720.874 rows=111 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=772171 read=555940 written=2810 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=16) (actual time=0.010..4199.473 rows=15000000 loops=1) Buffers: shared hit=149120 read=105921 written=2808 -> Hash (cost=2071660.70..2071660.70 rows=4103939 width=4) (actual time=52354.838..52354.838 rows=111 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=623051 read=450019 written=2 -> HashAggregate (cost=1979322.07..2030621.31 rows=4103939 width=8) (actual time=45186.487..52354.417 rows=111 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 14999889 Buffers: shared hit=623051 read=450019 written=2 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1677238.05 rows=60416805 width=8) (actual time=0.010..14319.678 rows=59984909 loops=1) Buffers: shared hit=623051 read=450019 written=2 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1011.188..1011.188 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35275 read=3 written=1 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.018..527.568 rows=1500000 loops=1) Buffers: shared hit=35275 read=3 written=1 Planning time: 4.278 ms Execution time: 85071.970 ms (42 rows) COMMIT; COMMIT