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) > 313 ) 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=121849.358..121849.658 rows=100 loops=1) Buffers: shared hit=1197943 read=1254800 dirtied=2 written=10 -> GroupAggregate (cost=10456704.98..11293042.48 rows=30412273 width=39) (actual time=121849.354..121849.638 rows=100 loops=1) Buffers: shared hit=1197943 read=1254800 dirtied=2 written=10 -> Sort (cost=10456704.98..10532735.66 rows=30412273 width=39) (actual time=121849.337..121849.380 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: 80kB Buffers: shared hit=1197943 read=1254800 dirtied=2 written=10 -> Hash Join (cost=3092160.67..5845154.71 rows=30412273 width=39) (actual time=93751.909..121846.211 rows=707 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1197929 read=1254800 dirtied=2 written=10 -> Seq Scan on lineitem (cost=0.00..1688564.46 rows=60824546 width=8) (actual time=0.056..15761.970 rows=60045033 loops=1) Buffers: shared hit=535189 read=545130 -> Hash (cost=2997098.82..2997098.82 rows=7604948 width=39) (actual time=93706.779..93706.779 rows=101 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=662740 read=709670 dirtied=2 written=10 -> Hash Join (cost=2205020.00..2997098.82 rows=7604948 width=39) (actual time=82290.395..93706.277 rows=101 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=662740 read=709670 dirtied=2 written=10 -> Hash Join (cost=2135992.00..2775971.86 rows=7604948 width=20) (actual time=81088.091..92494.215 rows=101 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=627545 read=709587 dirtied=2 written=10 -> Seq Scan on orders (cost=0.00..408911.95 rows=15209895 width=16) (actual time=0.011..5607.639 rows=15015000 loops=1) Buffers: shared hit=194119 read=62694 written=2 -> Hash (cost=2084811.71..2084811.71 rows=4094423 width=4) (actual time=80914.919..80914.919 rows=101 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=433426 read=646893 dirtied=2 written=8 -> HashAggregate (cost=1992687.19..2043867.48 rows=4094423 width=8) (actual time=72275.769..80914.085 rows=101 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014899 Buffers: shared hit=433426 read=646893 dirtied=2 written=8 -> Seq Scan on lineitem (cost=0.00..1688564.46 rows=60824546 width=8) (actual time=0.038..21129.301 rows=60045033 loops=1) Buffers: shared hit=433426 read=646893 dirtied=2 written=8 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1199.666..1199.666 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35195 read=83 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..627.599 rows=1500000 loops=1) Buffers: shared hit=35195 read=83 Total runtime: 122033.225 ms (39 rows) COMMIT; COMMIT