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=10351561.51..10351564.26 rows=100 width=39) (actual time=130617.893..130618.451 rows=99 loops=1) Buffers: shared hit=1483888 read=945017 written=62 -> GroupAggregate (cost=10351561.51..11179664.61 rows=30112840 width=39) (actual time=130617.889..130618.434 rows=99 loops=1) Buffers: shared hit=1483888 read=945017 written=62 -> Sort (cost=10351561.51..10426843.61 rows=30112840 width=39) (actual time=130617.779..130617.884 rows=693 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1483888 read=945017 written=62 -> Hash Join (cost=3061691.56..5787563.78 rows=30112840 width=39) (actual time=96614.146..130612.772 rows=693 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1483874 read=945017 written=62 -> Seq Scan on lineitem (cost=0.00..1671922.81 rows=60225681 width=8) (actual time=0.054..19934.420 rows=60045303 loops=1) Buffers: shared hit=637499 read=432167 -> Hash (cost=2967566.96..2967566.96 rows=7529968 width=39) (actual time=95987.845..95987.845 rows=99 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=846375 read=512850 written=62 -> Hash Join (cost=2183447.19..2967566.96 rows=7529968 width=39) (actual time=84809.897..95983.992 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=846375 read=512850 written=62 -> Hash Join (cost=2114419.19..2747939.60 rows=7529968 width=20) (actual time=82766.620..93933.686 rows=99 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=811122 read=512825 written=62 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.012..5535.112 rows=15015000 loops=1) Buffers: shared hit=248094 read=6187 written=62 -> Hash (cost=2063930.63..2063930.63 rows=4039085 width=4) (actual time=82560.006..82560.006 rows=99 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=563028 read=506638 -> HashAggregate (cost=1973051.22..2023539.78 rows=4039085 width=8) (actual time=73531.116..82559.261 rows=99 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014901 Buffers: shared hit=563028 read=506638 -> Seq Scan on lineitem (cost=0.00..1671922.81 rows=60225681 width=8) (actual time=0.017..23413.817 rows=60045303 loops=1) Buffers: shared hit=563028 read=506638 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2041.002..2041.002 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35253 read=25 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.019..880.623 rows=1500000 loops=1) Buffers: shared hit=35253 read=25 Total runtime: 130936.918 ms (39 rows) COMMIT; COMMIT