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=10372009.04..10372011.79 rows=100 width=39) (actual time=136944.616..136945.175 rows=99 loops=1) Buffers: shared hit=1927875 read=505800 written=1 -> GroupAggregate (cost=10372009.04..11201755.26 rows=30172590 width=39) (actual time=136944.613..136945.148 rows=99 loops=1) Buffers: shared hit=1927875 read=505800 written=1 -> Sort (cost=10372009.04..10447440.51 rows=30172590 width=39) (actual time=136944.589..136944.658 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=1927875 read=505800 written=1 -> Hash Join (cost=3067232.81..5798523.26 rows=30172590 width=39) (actual time=98114.717..136939.315 rows=693 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1927861 read=505800 written=1 -> Seq Scan on lineitem (cost=0.00..1675249.80 rows=60345180 width=8) (actual time=0.039..24115.754 rows=60045826 loops=1) Buffers: shared hit=842492 read=229306 -> Hash (cost=2972920.92..2972920.92 rows=7544952 width=39) (actual time=97986.666..97986.666 rows=99 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=1085369 read=276494 written=1 -> Hash Join (cost=2187332.40..2972920.92 rows=7544952 width=39) (actual time=86321.683..97983.523 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1085369 read=276494 written=1 -> Hash Join (cost=2118304.40..2752993.88 rows=7544952 width=20) (actual time=84193.575..95851.002 rows=99 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=1050096 read=276489 written=1 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=16) (actual time=0.028..6297.792 rows=15015000 loops=1) Buffers: shared hit=254787 -> Hash (cost=2067829.87..2067829.87 rows=4037963 width=4) (actual time=83900.276..83900.276 rows=99 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=795309 read=276489 written=1 -> HashAggregate (cost=1976975.70..2027450.24 rows=4037963 width=8) (actual time=74119.159..83899.518 rows=99 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014901 Buffers: shared hit=795309 read=276489 written=1 -> Seq Scan on lineitem (cost=0.00..1675249.80 rows=60345180 width=8) (actual time=0.023..22218.837 rows=60045826 loops=1) Buffers: shared hit=795309 read=276489 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2126.600..2126.600 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35273 read=5 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.011..1285.365 rows=1500000 loops=1) Buffers: shared hit=35273 read=5 Total runtime: 137253.518 ms (39 rows) COMMIT; COMMIT