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) > 315 ) 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=10372124.93..10372127.68 rows=100 width=39) (actual time=119698.044..119698.444 rows=75 loops=1) Buffers: shared hit=1867129 read=566546 -> GroupAggregate (cost=10372124.93..11201878.58 rows=30172860 width=39) (actual time=119698.041..119698.429 rows=75 loops=1) Buffers: shared hit=1867129 read=566546 -> Sort (cost=10372124.93..10447557.08 rows=30172860 width=39) (actual time=119698.015..119698.083 rows=525 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 66kB Buffers: shared hit=1867129 read=566546 -> Hash Join (cost=3067291.39..5798596.67 rows=30172860 width=39) (actual time=86116.214..119694.232 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1867115 read=566546 -> Seq Scan on lineitem (cost=0.00..1675255.19 rows=60345719 width=8) (actual time=0.031..19946.196 rows=60045826 loops=1) Buffers: shared hit=696217 read=375581 -> Hash (cost=2972979.49..2972979.49 rows=7544952 width=39) (actual time=85662.291..85662.291 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=1170898 read=190965 -> Hash Join (cost=2187379.76..2972979.49 rows=7544952 width=39) (actual time=76948.185..85661.462 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1170898 read=190965 -> Hash Join (cost=2118351.76..2753052.45 rows=7544952 width=20) (actual time=75080.880..83791.087 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=1135620 read=190965 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=16) (actual time=0.016..4115.217 rows=15015000 loops=1) Buffers: shared hit=254787 -> Hash (cost=2067863.20..2067863.20 rows=4039085 width=4) (actual time=74857.743..74857.743 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=880833 read=190965 -> HashAggregate (cost=1976983.79..2027472.35 rows=4039085 width=8) (actual time=64853.424..74857.276 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=880833 read=190965 -> Seq Scan on lineitem (cost=0.00..1675255.19 rows=60345719 width=8) (actual time=0.044..18860.824 rows=60045826 loops=1) Buffers: shared hit=880833 read=190965 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1865.735..1865.735 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.014..954.713 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 120078.564 ms (39 rows) COMMIT; COMMIT