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-08' and l_shipdate > date '1995-03-08' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2690835.89..2690835.91 rows=10 width=20) (actual time=37381.075..37381.078 rows=10 loops=1) Buffers: shared hit=929026 read=439258 dirtied=229 written=50 -> Sort (cost=2690835.89..2698747.38 rows=3164597 width=20) (actual time=37381.071..37381.072 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=929026 read=439258 dirtied=229 written=50 -> HashAggregate (cost=2590804.12..2622450.09 rows=3164597 width=20) (actual time=37279.562..37359.289 rows=114091 loops=1) Group Key: lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority Buffers: shared hit=929020 read=439258 dirtied=229 written=50 -> Hash Join (cost=555054.65..2543335.16 rows=3164597 width=20) (actual time=10046.005..37001.213 rows=301962 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=929020 read=439258 dirtied=229 written=50 -> Seq Scan on lineitem (cost=0.00..1833350.52 rows=32875738 width=12) (actual time=0.042..19668.236 rows=32539137 loops=1) Filter: (l_shipdate > '1995-03-08'::date) Rows Removed by Filter: 27505039 Buffers: shared hit=688635 read=387411 written=2 -> Hash (cost=536825.59..536825.59 rows=1458325 width=12) (actual time=10025.079..10025.079 rows=1454415 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 78879kB Buffers: shared hit=240385 read=51847 dirtied=229 written=48 -> Hash Join (cost=49736.01..536825.59 rows=1458325 width=12) (actual time=890.703..9319.830 rows=1454415 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=240385 read=51847 dirtied=229 written=48 -> Seq Scan on orders (cost=0.00..445175.49 rows=7288223 width=16) (actual time=0.028..5189.990 rows=7253508 loops=1) Filter: (o_orderdate < '1995-03-08'::date) Rows Removed by Filter: 7761492 Buffers: shared hit=217263 read=38538 dirtied=229 written=32 -> Hash (cost=45984.26..45984.26 rows=300140 width=4) (actual time=885.934..885.934 rows=300276 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 14653kB Buffers: shared hit=23122 read=13309 written=16 -> Bitmap Heap Scan on customer (cost=6954.51..45984.26 rows=300140 width=4) (actual time=115.698..733.034 rows=300276 loops=1) Recheck Cond: (c_mktsegment = 'BUILDING'::bpchar) Heap Blocks: exact=35277 Buffers: shared hit=23122 read=13309 written=16 -> Bitmap Index Scan on customer_c_mktsegment_c_custkey_idx (cost=0.00..6879.48 rows=300140 width=0) (actual time=102.905..102.905 rows=300276 loops=1) Index Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared read=1154 written=1 Planning time: 6.205 ms Execution time: 37414.590 ms (38 rows) COMMIT; COMMIT