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=10322098.21..10322100.96 rows=100 width=39) (actual time=128074.591..128075.084 rows=84 loops=1) Buffers: shared hit=1225864 read=1195900 dirtied=209 written=3 -> GroupAggregate (cost=10322098.21..11147723.01 rows=30022720 width=39) (actual time=128074.587..128075.066 rows=84 loops=1) Buffers: shared hit=1225864 read=1195900 dirtied=209 written=3 -> Sort (cost=10322098.21..10397155.01 rows=30022720 width=39) (actual time=128074.551..128074.640 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=1225864 read=1195900 dirtied=209 written=3 -> Hash Join (cost=3054683.63..5772408.23 rows=30022720 width=39) (actual time=91943.253..128070.243 rows=588 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1225850 read=1195900 dirtied=209 written=3 -> Seq Scan on lineitem (cost=0.00..1666929.40 rows=60045440 width=8) (actual time=0.109..22223.020 rows=59985329 loops=1) Buffers: shared hit=160869 read=905606 written=1 -> Hash (cost=2960839.98..2960839.98 rows=7507492 width=39) (actual time=91186.375..91186.375 rows=84 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=1064981 read=290294 dirtied=209 written=2 -> Hash Join (cost=2178631.80..2960839.98 rows=7507492 width=39) (actual time=82699.346..91185.885 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1064981 read=290294 dirtied=209 written=2 -> Hash Join (cost=2109603.80..2741662.14 rows=7507492 width=20) (actual time=80976.051..89437.904 rows=84 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=1029886 read=290111 dirtied=209 written=2 -> Seq Scan on orders (cost=0.00..403671.84 rows=15014984 width=16) (actual time=0.011..3994.707 rows=15000000 loops=1) Buffers: shared hit=253522 -> Hash (cost=2058729.80..2058729.80 rows=4069920 width=4) (actual time=80848.786..80848.786 rows=84 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=776364 read=290111 dirtied=209 written=2 -> HashAggregate (cost=1967156.60..2018030.60 rows=4069920 width=8) (actual time=70774.279..80848.165 rows=84 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 14999916 Buffers: shared hit=776364 read=290111 dirtied=209 written=2 -> Seq Scan on lineitem (cost=0.00..1666929.40 rows=60045440 width=8) (actual time=0.014..20246.981 rows=59985329 loops=1) Buffers: shared hit=776364 read=290111 dirtied=209 written=2 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1721.178..1721.178 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35095 read=183 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.015..638.711 rows=1500000 loops=1) Buffers: shared hit=35095 read=183 Total runtime: 128406.934 ms (39 rows) COMMIT; COMMIT