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=10169939.56..10169942.31 rows=100 width=39) (actual time=75777.399..75777.741 rows=100 loops=1) Buffers: shared hit=1702594 read=723940 written=34 -> GroupAggregate (cost=10169939.56..10997219.09 rows=30082892 width=39) (actual time=75777.396..75777.730 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1702594 read=723940 written=34 -> Sort (cost=10169939.56..10245146.79 rows=30082892 width=39) (actual time=75777.382..75777.419 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=1702594 read=723940 written=34 -> Hash Join (cost=2887529.85..5610696.88 rows=30082892 width=39) (actual time=55235.377..75775.990 rows=777 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1702582 read=723940 written=34 -> Seq Scan on lineitem (cost=0.00..1670265.83 rows=60165783 width=8) (actual time=0.045..12603.825 rows=60045379 loops=1) Buffers: shared hit=651817 read=416791 written=2 -> Hash (cost=2793498.90..2793498.90 rows=7522476 width=39) (actual time=55018.960..55018.960 rows=111 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=1050765 read=307149 written=32 -> Hash Join (cost=2179845.02..2793498.90 rows=7522476 width=39) (actual time=48489.457..55018.643 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1050765 read=307149 written=32 -> Hash Join (cost=2110817.02..2611633.76 rows=7522476 width=20) (actual time=47438.445..53967.296 rows=111 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=1022447 read=300189 written=32 -> Seq Scan on orders (cost=0.00..404477.52 rows=15044952 width=16) (actual time=0.009..3656.169 rows=15015000 loops=1) Buffers: shared hit=162032 read=91996 written=22 -> Hash (cost=2060916.21..2060916.21 rows=3992065 width=4) (actual time=47285.564..47285.564 rows=111 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=860415 read=208193 written=10 -> HashAggregate (cost=1971094.75..2020995.56 rows=3992065 width=8) (actual time=41704.901..47285.116 rows=111 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 15014889 Buffers: shared hit=860415 read=208193 written=10 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1670265.83 rows=60165783 width=8) (actual time=0.012..14152.642 rows=60045379 loops=1) Buffers: shared hit=860415 read=208193 written=10 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1043.712..1043.712 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=28318 read=6960 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.012..594.392 rows=1500000 loops=1) Buffers: shared hit=28318 read=6960 Planning time: 4.468 ms Execution time: 75900.119 ms (42 rows) COMMIT; COMMIT