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-31' and l_shipdate > date '1995-03-31' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate LIMIT 10; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2744874.93..2744874.95 rows=10 width=20) (actual time=71311.710..71311.713 rows=10 loops=1) Buffers: shared hit=596324 read=761435 written=7 -> Sort (cost=2744874.93..2752779.81 rows=3161953 width=20) (actual time=71311.705..71311.705 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=596324 read=761435 written=7 -> HashAggregate (cost=2644926.73..2676546.26 rows=3161953 width=20) (actual time=71208.514..71289.966 rows=113862 loops=1) Buffers: shared hit=596318 read=761435 written=7 -> Hash Join (cost=626852.12..2597497.43 rows=3161953 width=20) (actual time=25807.074..70835.338 rows=301583 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=596318 read=761435 written=7 -> Seq Scan on lineitem (cost=0.00..1818864.55 rows=32042996 width=12) (actual time=0.049..23658.285 rows=31965617 loops=1) Filter: (l_shipdate > '1995-03-31'::date) Rows Removed by Filter: 28079986 Buffers: shared hit=419429 read=648117 -> Hash (cost=608312.94..608312.94 rows=1483134 width=12) (actual time=25804.785..25804.785 rows=1483208 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 63732kB Buffers: shared hit=176889 read=113318 written=7 -> Hash Join (cost=49708.25..608312.94 rows=1483134 width=12) (actual time=607.552..23830.013 rows=1483208 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=176889 read=113318 written=7 -> Seq Scan on orders (cost=0.00..441649.60 rows=7427182 width=16) (actual time=0.015..5818.739 rows=7396516 loops=1) Filter: (o_orderdate < '1995-03-31'::date) Rows Removed by Filter: 7618484 Buffers: shared hit=141612 read=112163 written=7 -> Hash (cost=45964.06..45964.06 rows=299535 width=4) (actual time=607.297..607.297 rows=300276 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 10557kB Buffers: shared hit=35277 read=1155 -> Bitmap Heap Scan on customer (cost=6941.88..45964.06 rows=299535 width=4) (actual time=87.586..487.399 rows=300276 loops=1) Recheck Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared hit=35277 read=1155 -> Bitmap Index Scan on customer_c_mktsegment_c_custkey_idx (cost=0.00..6866.99 rows=299535 width=0) (actual time=69.836..69.836 rows=300276 loops=1) Index Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared read=1155 Total runtime: 71365.050 ms (35 rows) COMMIT; COMMIT