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=10456704.98..10456707.73 rows=100 width=39) (actual time=121084.357..121084.979 rows=100 loops=1) Buffers: shared hit=1128080 read=1324663 dirtied=87 written=4609 -> GroupAggregate (cost=10456704.98..11293042.48 rows=30412273 width=39) (actual time=121084.352..121084.954 rows=100 loops=1) Buffers: shared hit=1128080 read=1324663 dirtied=87 written=4609 -> Sort (cost=10456704.98..10532735.66 rows=30412273 width=39) (actual time=121084.319..121084.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=1128080 read=1324663 dirtied=87 written=4609 -> Hash Join (cost=3092160.67..5845154.71 rows=30412273 width=39) (actual time=87016.905..121078.890 rows=791 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1128066 read=1324663 dirtied=87 written=4609 -> Seq Scan on lineitem (cost=0.00..1688564.46 rows=60824546 width=8) (actual time=0.029..19673.663 rows=60045033 loops=1) Buffers: shared hit=502830 read=577489 written=12 -> Hash (cost=2997098.82..2997098.82 rows=7604948 width=39) (actual time=86940.405..86940.405 rows=113 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=625236 read=747174 dirtied=87 written=4597 -> Hash Join (cost=2205020.00..2997098.82 rows=7604948 width=39) (actual time=76259.391..86939.776 rows=113 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=625236 read=747174 dirtied=87 written=4597 -> Hash Join (cost=2135992.00..2775971.86 rows=7604948 width=20) (actual time=74618.009..85295.304 rows=113 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=589958 read=747174 dirtied=87 written=4597 -> Seq Scan on orders (cost=0.00..408911.95 rows=15209895 width=16) (actual time=0.011..5689.487 rows=15015000 loops=1) Buffers: shared hit=184089 read=72724 dirtied=87 written=4597 -> Hash (cost=2084811.71..2084811.71 rows=4094423 width=4) (actual time=74482.817..74482.817 rows=113 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=405869 read=674450 -> HashAggregate (cost=1992687.19..2043867.48 rows=4094423 width=8) (actual time=65823.475..74481.961 rows=113 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 15014887 Buffers: shared hit=405869 read=674450 -> Seq Scan on lineitem (cost=0.00..1688564.46 rows=60824546 width=8) (actual time=0.025..20385.959 rows=60045033 loops=1) Buffers: shared hit=405869 read=674450 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1639.363..1639.363 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.015..846.227 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 121266.531 ms (39 rows) COMMIT; COMMIT