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=10404118.21..10404120.96 rows=100 width=39) (actual time=120999.333..121000.000 rows=100 loops=1) Buffers: shared hit=1726622 read=714170 dirtied=135 written=80 -> GroupAggregate (cost=10404118.21..11236324.17 rows=30262035 width=39) (actual time=120999.330..120999.977 rows=100 loops=1) Buffers: shared hit=1726622 read=714170 dirtied=135 written=80 -> Sort (cost=10404118.21..10479773.30 rows=30262035 width=39) (actual time=120999.298..120999.442 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: 86kB Buffers: shared hit=1726622 read=714170 dirtied=135 written=80 -> Hash Join (cost=3077039.75..5816427.69 rows=30262035 width=39) (actual time=89255.587..120993.693 rows=784 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1726608 read=714170 dirtied=135 written=80 -> Seq Scan on lineitem (cost=0.00..1680216.70 rows=60524070 width=8) (actual time=0.048..18591.180 rows=60044082 loops=1) Buffers: shared hit=832442 read=242534 written=36 -> Hash (cost=2982446.15..2982446.15 rows=7567488 width=39) (actual time=89232.144..89232.144 rows=112 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=894166 read=471636 dirtied=135 written=44 -> Hash Join (cost=2194312.25..2982446.15 rows=7567488 width=39) (actual time=76682.354..89231.632 rows=112 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=894166 read=471636 dirtied=135 written=44 -> Hash Join (cost=2125284.25..2762068.39 rows=7567488 width=20) (actual time=75017.469..87564.523 rows=112 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=859003 read=471521 dirtied=135 written=44 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=16) (actual time=0.011..6743.005 rows=15015000 loops=1) Buffers: shared hit=141544 read=114004 dirtied=45 written=44 -> Hash (cost=2074410.25..2074410.25 rows=4069920 width=4) (actual time=74849.960..74849.960 rows=112 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=717459 read=357517 dirtied=90 -> HashAggregate (cost=1982837.05..2033711.05 rows=4069920 width=8) (actual time=66191.192..74849.047 rows=112 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 15014888 Buffers: shared hit=717459 read=357517 dirtied=90 -> Seq Scan on lineitem (cost=0.00..1680216.70 rows=60524070 width=8) (actual time=0.021..20161.486 rows=60044082 loops=1) Buffers: shared hit=717459 read=357517 dirtied=90 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1662.806..1662.806 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35163 read=115 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.021..915.895 rows=1500000 loops=1) Buffers: shared hit=35163 read=115 Total runtime: 121274.511 ms (39 rows) COMMIT; COMMIT