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-15' and l_shipdate > date '1995-03-15' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2698398.16..2698398.19 rows=10 width=20) (actual time=37736.793..37736.798 rows=10 loops=1) Buffers: shared hit=637976 read=734283 written=83 -> Sort (cost=2698398.16..2706333.98 rows=3174326 width=20) (actual time=37736.789..37736.791 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=637976 read=734283 written=83 -> HashAggregate (cost=2598058.86..2629802.12 rows=3174326 width=20) (actual time=37670.255..37717.341 rows=114097 loops=1) Group Key: lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority Buffers: shared hit=637970 read=734283 written=83 -> Hash Join (cost=556887.31..2550443.97 rows=3174326 width=20) (actual time=12361.257..37411.747 rows=302381 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=637970 read=734283 written=83 -> Seq Scan on lineitem (cost=0.00..1838829.90 rows=32795600 width=12) (actual time=0.074..17780.789 rows=32364828 loops=1) Filter: (l_shipdate > '1995-03-15'::date) Rows Removed by Filter: 27680469 Buffers: shared hit=463797 read=615465 written=1 -> Hash (cost=538503.14..538503.14 rows=1470734 width=12) (actual time=12340.466..12340.466 rows=1463251 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 79259kB Buffers: shared hit=174173 read=118818 written=82 -> Hash Join (cost=49736.01..538503.14 rows=1470734 width=12) (actual time=1258.768..11618.621 rows=1463251 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=174173 read=118818 written=82 -> Seq Scan on orders (cost=0.00..446496.39 rows=7350239 width=16) (actual time=0.027..6332.385 rows=7297127 loops=1) Filter: (o_orderdate < '1995-03-15'::date) Rows Removed by Filter: 7717873 Buffers: shared hit=173809 read=82751 written=44 -> Hash (cost=45984.26..45984.26 rows=300140 width=4) (actual time=1253.874..1253.874 rows=300276 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 14653kB Buffers: shared hit=364 read=36067 written=38 -> Bitmap Heap Scan on customer (cost=6954.51..45984.26 rows=300140 width=4) (actual time=120.650..1084.565 rows=300276 loops=1) Recheck Cond: (c_mktsegment = 'BUILDING'::bpchar) Heap Blocks: exact=35277 Buffers: shared hit=364 read=36067 written=38 -> Bitmap Index Scan on customer_c_mktsegment_c_custkey_idx (cost=0.00..6879.48 rows=300140 width=0) (actual time=107.541..107.541 rows=300276 loops=1) Index Cond: (c_mktsegment = 'BUILDING'::bpchar) Buffers: shared read=1154 written=1 Planning time: 6.766 ms Execution time: 37766.215 ms (38 rows) COMMIT; COMMIT