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) > 313 ) 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=10151768.36..10151771.11 rows=100 width=39) (actual time=79872.345..79872.627 rows=99 loops=1) Buffers: shared hit=1664653 read=757109 dirtied=316 written=3 -> GroupAggregate (cost=10151768.36..10977390.85 rows=30022636 width=39) (actual time=79872.341..79872.612 rows=99 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1664653 read=757109 dirtied=316 written=3 -> Sort (cost=10151768.36..10226824.95 rows=30022636 width=39) (actual time=79872.320..79872.353 rows=693 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1664653 read=757109 dirtied=316 written=3 -> Hash Join (cost=2884372.94..5602092.92 rows=30022636 width=39) (actual time=60670.924..79870.459 rows=693 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1664641 read=757109 dirtied=316 written=3 -> Seq Scan on lineitem (cost=0.00..1666927.72 rows=60045272 width=8) (actual time=0.017..11163.731 rows=60045669 loops=1) Buffers: shared hit=740267 read=326208 -> Hash (cost=2790529.29..2790529.29 rows=7507492 width=39) (actual time=60200.372..60200.372 rows=99 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65543kB Buffers: shared hit=924374 read=430901 dirtied=316 written=3 -> Hash Join (cost=2177548.48..2790529.29 rows=7507492 width=39) (actual time=52577.567..60199.744 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=924374 read=430901 dirtied=316 written=3 -> Hash Join (cost=2108520.48..2608888.91 rows=7507492 width=20) (actual time=51461.778..59083.556 rows=99 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=924372 read=395625 dirtied=316 written=3 -> Seq Scan on orders (cost=0.00..403671.84 rows=15014984 width=16) (actual time=0.007..3952.931 rows=15015000 loops=1) Buffers: shared hit=1532 read=251990 dirtied=254 -> Hash (cost=2058032.48..2058032.48 rows=4039040 width=4) (actual time=51256.369..51256.369 rows=99 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=922840 read=143635 dirtied=62 written=3 -> HashAggregate (cost=1967154.08..2017642.08 rows=4039040 width=8) (actual time=42838.857..51255.312 rows=99 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 313::double precision) Rows Removed by Filter: 15014901 Buffers: shared hit=922840 read=143635 dirtied=62 written=3 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1666927.72 rows=60045272 width=8) (actual time=0.007..13653.424 rows=60045669 loops=1) Buffers: shared hit=922840 read=143635 dirtied=62 written=3 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1092.643..1092.643 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.032..648.747 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 Planning time: 3.951 ms Execution time: 80202.049 ms (42 rows) COMMIT; COMMIT