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-02' and l_shipdate > date '1995-03-02' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2774926.38..2774926.40 rows=10 width=20) (actual time=110892.880..110892.882 rows=10 loops=1) Buffers: shared hit=840951 read=532619 dirtied=202 written=6 -> Sort (cost=2774926.38..2782873.82 rows=3178977 width=20) (actual time=110892.876..110892.877 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=840951 read=532619 dirtied=202 written=6 -> HashAggregate (cost=2674440.06..2706229.83 rows=3178977 width=20) (actual time=110797.588..110867.180 rows=114034 loops=1) Buffers: shared hit=840945 read=532619 dirtied=202 written=6 -> Hash Join (cost=629927.03..2626755.40 rows=3178977 width=20) (actual time=35915.462..110195.563 rows=301791 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=840945 read=532619 dirtied=202 written=6 -> Seq Scan on lineitem (cost=0.00..1840629.69 rows=33175709 width=12) (actual time=0.041..47347.346 rows=32690033 loops=1) Filter: (l_shipdate > '1995-03-02'::date) Rows Removed by Filter: 27355000 Buffers: shared hit=610646 read=469673 -> Hash (cost=611708.92..611708.92 rows=1457449 width=12) (actual time=35913.564..35913.564 rows=1446924 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 62173kB Buffers: shared hit=230299 read=62946 dirtied=202 written=6 -> Hash Join (cost=49684.86..611708.92 rows=1457449 width=12) (actual time=2578.082..33921.467 rows=1446924 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=230299 read=62946 dirtied=202 written=6 -> Seq Scan on orders (cost=0.00..446936.69 rows=7310028 width=16) (actual time=0.016..11079.129 rows=7215550 loops=1) Filter: (o_orderdate < '1995-03-02'::date) Rows Removed by Filter: 7799450 Buffers: shared hit=209496 read=47317 dirtied=202 written=6 -> Hash (cost=45946.55..45946.55 rows=299065 width=4) (actual time=2577.831..2577.831 rows=300276 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 10557kB Buffers: shared hit=20803 read=15629 -> Bitmap Heap Scan on customer (cost=6930.23..45946.55 rows=299065 width=4) (actual time=208.498..2376.751 rows=300276 loops=1) Recheck Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared hit=20803 read=15629 -> Bitmap Index Scan on customer_c_mktsegment_c_custkey_idx (cost=0.00..6855.47 rows=299065 width=0) (actual time=197.498..197.498 rows=300276 loops=1) Index Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared hit=3 read=1152 Total runtime: 110935.354 ms (35 rows) COMMIT; COMMIT