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=10445914.58..10445917.33 rows=100 width=39) (actual time=239035.994..239036.470 rows=86 loops=1) Buffers: shared hit=1049407 read=1400969 dirtied=1 written=1 -> GroupAggregate (cost=10445914.58..11281431.52 rows=30382434 width=39) (actual time=239035.990..239036.449 rows=86 loops=1) Buffers: shared hit=1049407 read=1400969 dirtied=1 written=1 -> Sort (cost=10445914.58..10521870.67 rows=30382434 width=39) (actual time=239035.967..239036.039 rows=602 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 72kB Buffers: shared hit=1049407 read=1400969 dirtied=1 written=1 -> Hash Join (cost=3088807.75..5839103.67 rows=30382434 width=39) (actual time=158536.846..239031.562 rows=602 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1049393 read=1400969 dirtied=1 written=1 -> Seq Scan on lineitem (cost=0.00..1686910.69 rows=60764869 width=8) (actual time=0.046..65036.190 rows=60045297 loops=1) Buffers: shared hit=294658 read=784604 -> Hash (cost=2993839.55..2993839.55 rows=7597456 width=39) (actual time=157928.377..157928.377 rows=86 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=754735 read=616365 dirtied=1 written=1 -> Hash Join (cost=2202626.74..2993839.55 rows=7597456 width=39) (actual time=140867.358..157927.774 rows=86 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=754735 read=616365 dirtied=1 written=1 -> Hash Join (cost=2133598.74..2772862.43 rows=7597456 width=20) (actual time=135864.909..152923.684 rows=86 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=754732 read=581090 dirtied=1 written=1 -> Seq Scan on orders (cost=0.00..408509.11 rows=15194911 width=16) (actual time=0.017..10719.113 rows=15015000 loops=1) Buffers: shared hit=238778 read=17782 -> Hash (cost=2082575.99..2082575.99 rows=4081820 width=4) (actual time=135464.816..135464.816 rows=86 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=515954 read=563308 dirtied=1 written=1 -> HashAggregate (cost=1990735.04..2041757.79 rows=4081820 width=8) (actual time=126850.537..135463.637 rows=86 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014914 Buffers: shared hit=515954 read=563308 dirtied=1 written=1 -> Seq Scan on lineitem (cost=0.00..1686910.69 rows=60764869 width=8) (actual time=0.030..70121.994 rows=60045297 loops=1) Buffers: shared hit=515954 read=563308 dirtied=1 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=5000.810..5000.810 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=3 read=35275 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.009..4096.831 rows=1500000 loops=1) Buffers: shared hit=3 read=35275 Total runtime: 239285.886 ms (39 rows) COMMIT; COMMIT