fdb=> create index idx_orders_time on orders using btree (order_date); CREATE INDEX Time: 14084.416 ms
BTREE 索引大小: 29 MB
1 2 3 4 5
fdb=> /di+ idx_orders_time List of relations Schema | Name | Type | Owner | Table | Size | Description --------+-----------------+-------+-------+--------+-------+------------- fdb | idx_orders_time | index | fdb | orders | 29 MB |
Btree 索引扫描: 2.757 ms
1 2 3 4 5 6 7 8 9 10 11 12 13 14
fdb=> explain analyze select count(*) from orders WHERE order_date BETWEEN '2015-07-11 00:00:00' and '2015-07-11 01:00:00'; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=74.99..75.00 rows=1 width=0) (actual time=1.866..1.866 rows=1 loops=1) -> Index Only Scan using idx_orders_time on orders (cost=0.43..70.49 rows=1803 width=0) (actual time=0.037..1.213 rows=1801 loops=1) Index Cond: ((order_date >= '2015-07-11 00:00:00+08'::timestamp with time zone) AND (order_date <= '2015-07-11 01:00:00+08' ::timestamp with time zone)) Heap Fetches: 1801 Planning time: 0.308 ms Execution time: 1.908 ms (6 rows) Time: 2.757 ms
创建 BRIN索引
创建 BRIN 索引: 920 ms
1 2 3
fdb=> create index brin_orders_time on orders using BRIN (order_date); CREATE INDEX Time: 920.145 ms
BRIN 索引扫描: 7.816 ms ms
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fdb=> explain analyze select count(*) from orders WHERE order_date BETWEEN '2015-07-11 00:00:00'and'2015-07-11 01:00:00'; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Aggregate (cost=4334.24..4334.25rows=1 width=0) (actual time=6.948..6.949rows=1 loops=1) -> Bitmap Heap Scan on orders (cost=30.48..4329.74rows=1803 width=0) (actual time=4.761..6.295rows=1801 loops=1) Recheck Cond: ((order_date >= '2015-07-11 00:00:00+08'::timestampwith time zone) AND (order_date <= '2015-07-11 01:00:00+0 8'::timestampwith time zone)) Rows Removed by Index Recheck: 19959 Heap Blocks: lossy=128 -> Bitmap Index Scan on idx_orders_time (cost=0.00..30.03rows=1803 width=0) (actual time=0.090..0.090rows=1280 loops=1) Index Cond: ((order_date >= '2015-07-11 00:00:00+08'::timestampwith time zone) AND (order_date <= '2015-07-11 01:00: 00+08'::timestampwith time zone)) Planning time: 0.210 ms Execution time: 7.010 ms (9rows) Time: 7.816 ms
BRIN 索引大小: 48 kB
fdb=> /di+ brin_orders_time
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+-----------------+-------+-------+--------+-------+-------------
fdb | brin_orders_time | index | fdb | orders | 48 kB |
(1 row)