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=10402684.47..10402687.22 rows=100 width=39) (actual time=136057.351..136057.893 rows=85 loops=1) Buffers: shared hit=1420492 read=1020300 dirtied=987 written=775 -> GroupAggregate (cost=10402684.47..11234890.99 rows=30262055 width=39) (actual time=136057.347..136057.871 rows=85 loops=1) Buffers: shared hit=1420492 read=1020300 dirtied=987 written=775 -> Sort (cost=10402684.47..10478339.61 rows=30262055 width=39) (actual time=136057.315..136057.437 rows=595 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 71kB Buffers: shared hit=1420492 read=1020300 dirtied=987 written=775 -> Hash Join (cost=3075602.28..5814991.33 rows=30262055 width=39) (actual time=96184.783..136052.719 rows=595 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1420478 read=1020300 dirtied=987 written=775 -> Seq Scan on lineitem (cost=0.00..1680217.10 rows=60524110 width=8) (actual time=0.041..25650.454 rows=60044082 loops=1) Buffers: shared hit=522475 read=552501 -> Hash (cost=2981008.68..2981008.68 rows=7567488 width=39) (actual time=94550.939..94550.939 rows=85 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=898003 read=467799 dirtied=987 written=775 -> Hash Join (cost=2193194.35..2981008.68 rows=7567488 width=39) (actual time=82154.136..94550.329 rows=85 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=898003 read=467799 dirtied=987 written=775 -> Hash Join (cost=2124166.35..2760630.92 rows=7567488 width=20) (actual time=80349.688..92735.580 rows=85 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=862725 read=467799 dirtied=987 written=775 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=16) (actual time=0.024..6370.805 rows=15015000 loops=1) Buffers: shared hit=225063 read=30485 -> Hash (cost=2073691.82..2073691.82 rows=4037963 width=4) (actual time=80121.342..80121.342 rows=85 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=637662 read=437314 dirtied=987 written=775 -> HashAggregate (cost=1982837.65..2033312.19 rows=4037963 width=8) (actual time=71091.258..80120.769 rows=85 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014915 Buffers: shared hit=637662 read=437314 dirtied=987 written=775 -> Seq Scan on lineitem (cost=0.00..1680217.10 rows=60524110 width=8) (actual time=0.038..22849.708 rows=60044082 loops=1) Buffers: shared hit=637662 read=437314 dirtied=987 written=775 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1802.394..1802.394 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.021..1024.464 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 136347.209 ms (39 rows) COMMIT; COMMIT