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=10441886.44..10441889.19 rows=100 width=39) (actual time=170768.099..170768.571 rows=76 loops=1) Buffers: shared hit=1524137 read=926239 written=103 -> GroupAggregate (cost=10441886.44..11277409.92 rows=30382672 width=39) (actual time=170768.095..170768.556 rows=76 loops=1) Buffers: shared hit=1524137 read=926239 written=103 -> Sort (cost=10441886.44..10517843.12 rows=30382672 width=39) (actual time=170768.070..170768.146 rows=532 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=1524137 read=926239 written=103 -> Hash Join (cost=3084728.28..5835037.23 rows=30382672 width=39) (actual time=110196.017..170764.198 rows=532 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1524123 read=926239 written=103 -> Seq Scan on lineitem (cost=0.00..1686915.43 rows=60765343 width=8) (actual time=0.038..44582.307 rows=60045297 loops=1) Buffers: shared hit=416537 read=662725 -> Hash (cost=2989760.08..2989760.08 rows=7597456 width=39) (actual time=109866.695..109866.695 rows=76 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=1107586 read=263514 written=103 -> Hash Join (cost=2199455.39..2989760.08 rows=7597456 width=39) (actual time=96901.042..109863.412 rows=76 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1107586 read=263514 written=103 -> Hash Join (cost=2130427.39..2768782.96 rows=7597456 width=20) (actual time=94972.663..107932.506 rows=76 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=1074250 read=261572 written=103 -> Seq Scan on orders (cost=0.00..408509.11 rows=15194911 width=16) (actual time=0.029..6871.646 rows=15015000 loops=1) Buffers: shared hit=254224 read=2336 written=103 -> Hash (cost=2080539.80..2080539.80 rows=3991007 width=4) (actual time=94888.897..94888.897 rows=76 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=820026 read=259236 -> HashAggregate (cost=1990742.15..2040629.73 rows=3991007 width=8) (actual time=85952.245..94888.240 rows=76 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014924 Buffers: shared hit=820026 read=259236 -> Seq Scan on lineitem (cost=0.00..1686915.43 rows=60765343 width=8) (actual time=0.032..32275.642 rows=60045297 loops=1) Buffers: shared hit=820026 read=259236 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1926.407..1926.407 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=33336 read=1942 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.014..1184.908 rows=1500000 loops=1) Buffers: shared hit=33336 read=1942 Total runtime: 171001.388 ms (39 rows) COMMIT; COMMIT