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=10223989.50..10223992.25 rows=100 width=39) (actual time=98041.154..98041.416 rows=84 loops=1) Buffers: shared hit=1213294 read=1225127 written=200 -> GroupAggregate (cost=10223989.50..11055381.27 rows=30232428 width=39) (actual time=98041.151..98041.403 rows=84 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1213294 read=1225127 written=200 -> Sort (cost=10223989.50..10299570.57 rows=30232428 width=39) (actual time=98041.134..98041.168 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=1213294 read=1225127 written=200 -> Hash Join (cost=2904301.71..5641003.27 rows=30232428 width=39) (actual time=75167.071..98039.913 rows=588 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1213282 read=1225127 written=200 -> Seq Scan on lineitem (cost=0.00..1678566.56 rows=60464856 width=8) (actual time=0.052..12043.676 rows=60044664 loops=1) Buffers: shared hit=405580 read=668338 -> Hash (cost=2809801.76..2809801.76 rows=7559996 width=39) (actual time=74885.033..74885.033 rows=84 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=807702 read=556789 written=200 -> Hash Join (cost=2192476.26..2809801.76 rows=7559996 width=39) (actual time=64960.390..74880.911 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=807702 read=556789 written=200 -> Hash Join (cost=2123448.26..2627373.82 rows=7559996 width=20) (actual time=63692.503..73607.111 rows=84 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=807700 read=521513 written=145 -> Seq Scan on orders (cost=0.00..406494.91 rows=15119991 width=16) (actual time=0.010..3997.500 rows=15015000 loops=1) Buffers: shared hit=139070 read=116225 written=144 -> Hash (cost=2072534.89..2072534.89 rows=4073069 width=4) (actual time=63554.168..63554.168 rows=84 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=668630 read=405288 written=1 -> HashAggregate (cost=1980890.84..2031804.20 rows=4073069 width=8) (actual time=50684.867..63552.229 rows=84 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=668630 read=405288 written=1 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1678566.56 rows=60464856 width=8) (actual time=0.013..14101.319 rows=60044664 loops=1) Buffers: shared hit=668630 read=405288 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1254.880..1254.880 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 written=55 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..788.471 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=55 Planning time: 4.726 ms Execution time: 98296.773 ms (42 rows) COMMIT; COMMIT