BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select l_orderkey, sum(l_extendedprice * (1 - l_discount)) as revenue, o_orderdate, o_shippriority from customer, orders, lineitem where c_mktsegment = 'BUILDING' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < date '1995-03-11' and l_shipdate > date '1995-03-11' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate LIMIT 10; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2685901.83..2685901.85 rows=10 width=20) (actual time=39173.840..39173.846 rows=10 loops=1) Buffers: shared hit=659822 read=704512 dirtied=721 written=66 -> Sort (cost=2685901.83..2693888.69 rows=3194744 width=20) (actual time=39173.835..39173.838 rows=10 loops=1) Sort Key: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount)))), orders.o_orderdate Sort Method: top-N heapsort Memory: 25kB Buffers: shared hit=659822 read=704512 dirtied=721 written=66 -> HashAggregate (cost=2584917.12..2616864.56 rows=3194744 width=20) (actual time=39084.433..39153.343 rows=114121 loops=1) Group Key: lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority Buffers: shared hit=659816 read=704512 dirtied=721 written=66 -> Hash Join (cost=554243.47..2536995.96 rows=3194744 width=20) (actual time=10305.977..38759.921 rows=302059 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=659816 read=704512 dirtied=721 written=66 -> Seq Scan on lineitem (cost=0.00..1827917.98 rows=32769885 width=12) (actual time=0.029..19969.759 rows=32465755 loops=1) Filter: (l_shipdate > '1995-03-11'::date) Rows Removed by Filter: 27579555 Buffers: shared hit=507196 read=565660 dirtied=214 written=7 -> Hash (cost=535836.16..535836.16 rows=1472585 width=12) (actual time=10297.942..10297.942 rows=1458145 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 79039kB Buffers: shared hit=152620 read=138852 dirtied=507 written=59 -> Hash Join (cost=49816.18..535836.16 rows=1472585 width=12) (actual time=501.258..9702.707 rows=1458145 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=152620 read=138852 dirtied=507 written=59 -> Seq Scan on orders (cost=0.00..443852.85 rows=7317675 width=16) (actual time=0.021..5527.547 rows=7271831 loops=1) Filter: (o_orderdate < '1995-03-11'::date) Rows Removed by Filter: 7743169 Buffers: shared hit=117343 read=137698 dirtied=507 written=58 -> Hash (cost=46042.99..46042.99 rows=301855 width=4) (actual time=498.723..498.723 rows=300276 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 14653kB Buffers: shared hit=35277 read=1154 written=1 -> Bitmap Heap Scan on customer (cost=6991.80..46042.99 rows=301855 width=4) (actual time=74.580..409.621 rows=300276 loops=1) Recheck Cond: (c_mktsegment = 'BUILDING'::bpchar) Heap Blocks: exact=35277 Buffers: shared hit=35277 read=1154 written=1 -> Bitmap Index Scan on customer_c_mktsegment_c_custkey_idx (cost=0.00..6916.34 rows=301855 width=0) (actual time=64.964..64.964 rows=300276 loops=1) Index Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared read=1154 written=1 Planning time: 3.555 ms Execution time: 39196.742 ms (38 rows) COMMIT; COMMIT