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=10260841.53..10260844.28 rows=100 width=39) (actual time=85888.385..85888.654 rows=86 loops=1) Buffers: shared hit=1427039 read=1020934 dirtied=453 written=280 -> GroupAggregate (cost=10260841.53..11095537.54 rows=30352582 width=39) (actual time=85888.382..85888.642 rows=86 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1427039 read=1020934 dirtied=453 written=280 -> Sort (cost=10260841.53..10336722.99 rows=30352582 width=39) (actual time=85888.370..85888.406 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=1427039 read=1020934 dirtied=453 written=280 -> Hash Join (cost=2911191.41..5658771.46 rows=30352582 width=39) (actual time=62599.403..85887.237 rows=602 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1427027 read=1020934 dirtied=453 written=280 -> Seq Scan on lineitem (cost=0.00..1685239.65 rows=60705165 width=8) (actual time=0.021..12947.704 rows=60044994 loops=1) Buffers: shared hit=746394 read=331794 written=2 -> Hash (cost=2816316.86..2816316.86 rows=7589964 width=39) (actual time=62112.158..62112.158 rows=86 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65543kB Buffers: shared hit=680633 read=689140 dirtied=453 written=278 -> Hash Join (cost=2197515.75..2816316.86 rows=7589964 width=39) (actual time=54919.884..62111.963 rows=86 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=680633 read=689140 dirtied=453 written=278 -> Hash Join (cost=2128487.75..2633439.40 rows=7589964 width=20) (actual time=53473.118..60664.934 rows=86 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=680630 read=653865 dirtied=453 written=202 -> Seq Scan on orders (cost=0.00..408106.27 rows=15179927 width=16) (actual time=0.010..4056.894 rows=15015000 loops=1) Buffers: shared hit=137785 read=118522 written=196 -> Hash (cost=2078586.94..2078586.94 rows=3992065 width=4) (actual time=53081.152..53081.152 rows=86 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=542845 read=535343 dirtied=453 written=6 -> HashAggregate (cost=1988765.48..2038666.29 rows=3992065 width=8) (actual time=46411.080..53080.844 rows=86 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 314::double precision) Rows Removed by Filter: 15014914 Buffers: shared hit=542845 read=535343 dirtied=453 written=6 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1685239.65 rows=60705165 width=8) (actual time=0.038..14121.308 rows=60044994 loops=1) Buffers: shared hit=542845 read=535343 dirtied=453 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1429.610..1429.610 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=3 read=35275 written=76 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..830.798 rows=1500000 loops=1) Buffers: shared hit=3 read=35275 written=76 Planning time: 4.464 ms Execution time: 86056.822 ms (42 rows) COMMIT; COMMIT