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-22' and l_shipdate > date '1995-03-22' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2742645.98..2742646.00 rows=10 width=20) (actual time=143918.570..143918.575 rows=10 loops=1) Buffers: shared hit=1042447 read=315312 written=21 -> Sort (cost=2742645.98..2750503.49 rows=3143005 width=20) (actual time=143918.567..143918.570 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=1042447 read=315312 written=21 -> HashAggregate (cost=2643296.72..2674726.77 rows=3143005 width=20) (actual time=143806.138..143895.974 rows=114063 loops=1) Buffers: shared hit=1042441 read=315312 written=21 -> Hash Join (cost=625377.38..2596151.64 rows=3143005 width=20) (actual time=41824.213..143019.300 rows=301899 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1042441 read=315312 written=21 -> Seq Scan on lineitem (cost=0.00..1818861.39 rows=32128753 width=12) (actual time=0.040..70703.259 rows=32158497 loops=1) Filter: (l_shipdate > '1995-03-22'::date) Rows Removed by Filter: 27827055 Buffers: shared hit=753689 read=313857 written=5 -> Hash (cost=606998.50..606998.50 rows=1470311 width=12) (actual time=41822.646..41822.646 rows=1470648 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 63192kB Buffers: shared hit=288752 read=1455 written=16 -> Hash Join (cost=49758.64..606998.50 rows=1470311 width=12) (actual time=1927.794..40741.118 rows=1470648 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=288752 read=1455 written=16 -> Seq Scan on orders (cost=0.00..441649.60 rows=7337247 width=16) (actual time=0.015..15897.869 rows=7333453 loops=1) Filter: (o_orderdate < '1995-03-22'::date) Rows Removed by Filter: 7666547 Buffers: shared hit=253475 read=300 written=16 -> Hash (cost=46001.33..46001.33 rows=300585 width=4) (actual time=1927.497..1927.497 rows=300276 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 10557kB Buffers: shared hit=35277 read=1155 -> Bitmap Heap Scan on customer (cost=6966.01..46001.33 rows=300585 width=4) (actual time=211.311..1761.105 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..6890.87 rows=300585 width=0) (actual time=195.400..195.400 rows=300276 loops=1) Index Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared read=1155 Total runtime: 143982.440 ms (35 rows) COMMIT; COMMIT