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) > 312 ) 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=10333047.66..10333050.41 rows=100 width=39) (actual time=117331.248..117331.591 rows=100 loops=1) Buffers: shared hit=1246913 read=1177246 dirtied=656 written=336 -> GroupAggregate (cost=10333047.66..11159498.07 rows=30052742 width=39) (actual time=117331.243..117331.572 rows=100 loops=1) Buffers: shared hit=1246913 read=1177246 dirtied=656 written=336 -> Sort (cost=10333047.66..10408179.52 rows=30052742 width=39) (actual time=117331.221..117331.269 rows=701 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 85kB Buffers: shared hit=1246913 read=1177246 dirtied=656 written=336 -> Hash Join (cost=3058143.04..5778589.85 rows=30052742 width=39) (actual time=88995.984..117327.137 rows=777 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1246899 read=1177246 dirtied=656 written=336 -> Seq Scan on lineitem (cost=0.00..1668600.84 rows=60105484 width=8) (actual time=0.030..15893.453 rows=60045603 loops=1) Buffers: shared hit=688928 read=378618 -> Hash (cost=2964205.74..2964205.74 rows=7514984 width=39) (actual time=88827.846..88827.846 rows=111 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=557971 read=798628 dirtied=656 written=336 -> Hash Join (cost=2181112.22..2964205.74 rows=7514984 width=39) (actual time=77992.288..88826.754 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=557971 read=798628 dirtied=656 written=336 -> Hash Join (cost=2112084.22..2744878.06 rows=7514984 width=20) (actual time=76501.280..87328.967 rows=111 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=522786 read=798535 dirtied=656 written=336 -> Seq Scan on orders (cost=0.00..404074.68 rows=15029968 width=16) (actual time=0.010..5645.545 rows=15015000 loops=1) Buffers: shared hit=61787 read=191988 dirtied=1 written=2 -> Hash (cost=2061028.52..2061028.52 rows=4084456 width=4) (actual time=76339.128..76339.128 rows=111 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=460999 read=606547 dirtied=655 written=334 -> HashAggregate (cost=1969128.26..2020183.96 rows=4084456 width=8) (actual time=65308.037..76338.192 rows=111 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 15014889 Buffers: shared hit=460999 read=606547 dirtied=655 written=334 -> Seq Scan on lineitem (cost=0.00..1668600.84 rows=60105484 width=8) (actual time=0.027..16782.922 rows=60045603 loops=1) Buffers: shared hit=460999 read=606547 dirtied=655 written=334 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1489.181..1489.181 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35185 read=93 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..600.845 rows=1500000 loops=1) Buffers: shared hit=35185 read=93 Total runtime: 117701.356 ms (39 rows) COMMIT; COMMIT