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=10149706.53..10149709.28 rows=100 width=39) (actual time=62122.398..62122.645 rows=84 loops=1) Buffers: shared hit=1665385 read=756377 dirtied=316 -> GroupAggregate (cost=10149706.53..10975334.74 rows=30022844 width=39) (actual time=62122.395..62122.630 rows=84 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1665385 read=756377 dirtied=316 -> Sort (cost=10149706.53..10224763.64 rows=30022844 width=39) (actual time=62122.379..62122.409 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=1665385 read=756377 dirtied=316 -> Hash Join (cost=2882265.32..5599996.76 rows=30022844 width=39) (actual time=45743.756..62120.840 rows=588 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1665373 read=756377 dirtied=316 -> Seq Scan on lineitem (cost=0.00..1666931.89 rows=60045689 width=8) (actual time=0.018..9576.321 rows=60045669 loops=1) Buffers: shared hit=740197 read=326278 -> Hash (cost=2788421.67..2788421.67 rows=7507492 width=39) (actual time=45352.160..45352.160 rows=84 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=925176 read=430099 dirtied=316 -> Hash Join (cost=2175910.61..2788421.67 rows=7507492 width=39) (actual time=39529.126..45351.708 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=925176 read=430099 dirtied=316 -> Hash Join (cost=2106882.61..2606781.29 rows=7507492 width=20) (actual time=38587.479..44409.705 rows=84 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=925174 read=394823 dirtied=316 -> Seq Scan on orders (cost=0.00..403671.84 rows=15014984 width=16) (actual time=0.004..3311.186 rows=15015000 loops=1) Buffers: shared hit=1361 read=252161 dirtied=254 -> Hash (cost=2056981.80..2056981.80 rows=3992065 width=4) (actual time=38437.427..38437.427 rows=84 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=923813 read=142662 dirtied=62 -> HashAggregate (cost=1967160.33..2017061.15 rows=3992065 width=8) (actual time=33709.285..38436.720 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=923813 read=142662 dirtied=62 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1666931.89 rows=60045689 width=8) (actual time=0.010..11411.627 rows=60045669 loops=1) Buffers: shared hit=923813 read=142662 dirtied=62 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=932.536..932.536 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.009..533.005 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 Planning time: 7.285 ms Execution time: 62169.670 ms (42 rows) COMMIT; COMMIT