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=10349324.09..10349326.84 rows=100 width=39) (actual time=183740.738..183741.321 rows=100 loops=1) Buffers: shared hit=1072721 read=1356184 written=3 -> GroupAggregate (cost=10349324.09..11177418.69 rows=30112531 width=39) (actual time=183740.735..183741.297 rows=100 loops=1) Buffers: shared hit=1072721 read=1356184 written=3 -> Sort (cost=10349324.09..10424605.42 rows=30112531 width=39) (actual time=183740.712..183740.790 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=1072721 read=1356184 written=3 -> Hash Join (cost=3059518.77..5785373.97 rows=30112531 width=39) (actual time=127588.029..183734.872 rows=777 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1072707 read=1356184 written=3 -> Seq Scan on lineitem (cost=0.00..1671916.62 rows=60225062 width=8) (actual time=0.034..41590.586 rows=60045303 loops=1) Buffers: shared hit=302562 read=767104 -> Hash (cost=2965394.17..2965394.17 rows=7529968 width=39) (actual time=126606.352..126606.352 rows=111 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=770145 read=589080 written=3 -> Hash Join (cost=2181755.18..2965394.17 rows=7529968 width=39) (actual time=115598.337..126605.679 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=770145 read=589080 written=3 -> Hash Join (cost=2112727.18..2745766.81 rows=7529968 width=20) (actual time=113236.542..124241.595 rows=111 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=734867 read=589080 written=3 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.014..6222.577 rows=15015000 loops=1) Buffers: shared hit=253994 read=287 -> Hash (cost=2062839.59..2062839.59 rows=3991007 width=4) (actual time=112987.848..112987.848 rows=111 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=480873 read=588793 written=3 -> HashAggregate (cost=1973041.93..2022929.52 rows=3991007 width=8) (actual time=104980.589..112986.498 rows=111 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 15014889 Buffers: shared hit=480873 read=588793 written=3 -> Seq Scan on lineitem (cost=0.00..1671916.62 rows=60225062 width=8) (actual time=0.132..46539.128 rows=60045303 loops=1) Buffers: shared hit=480873 read=588793 written=3 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2360.175..2360.175 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.191..1514.776 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 184023.109 ms (39 rows) COMMIT; COMMIT