一. 索引概述
目前Doris只支持bitmap 索引
BITMAP 索引仅在单列上创建
bitmap index:位图索引,是一种快速数据结构,能够加快查询速度
语法:
index 创建和修改相关语法有两种形式,一种集成与 alter table 语句中,另一种是使用单独的 create/drop index 语法
-
创建索引
创建索引的的语法可以参见 CREATE INDEX 或 ALTER TABLE 中bitmap 索引相关的操作, 也可以通过在创建表时指定bitmap 索引,参见CREATE TABLE -
查看索引
参照SHOW INDEX -
删除索引
参照DROP INDEX 或者 ALTER TABLE 中bitmap 索引相关的操作
注意事项:
-
目前索引仅支持 bitmap 类型的索引。
-
bitmap 索引仅在单列上创建。
-
bitmap 索引能够应用在 Duplicate 数据模型的所有列和 Aggregate, Uniq 模型的key列上。
-
bitmap 索引支持的数据类型如下:
TINYINT
SMALLINT
INT
UNSIGNEDINT
BIGINT
CHAR
VARCHAR
DATE
DATETIME
LARGEINT
DECIMAL
BOOL -
bitmap索引仅在 Segment V2 下生效。当创建 index 时,表的存储格式将默认转换为 V2 格式。
二. 案例
代码:
CREATE INDEX b_odsfactsale_prodname ON ods_fact_sale(prod_name) USING BITMAP COMMENT '产品名称';
SHOW ALTER TABLE COLUMN ;
show index from example_db.ods_fact_sale;
测试过程:
mysql> CREATE INDEX b_odsfactsale_prodname ON ods_fact_sale(prod_name) USING BITMAP COMMENT '产品名称';
Query OK, 0 rows affected (0.01 sec)
mysql> SHOW ALTER TABLE COLUMN;
+-------+---------------------+---------------------+---------------------+---------------------+---------+---------------+---------------+---------------+----------+------+----------+---------+
| JobId | TableName | CreateTime | FinishTime | IndexName | IndexId | OriginIndexId | SchemaVersion | TransactionId | State | Msg | Progress | Timeout |
+-------+---------------------+---------------------+---------------------+---------------------+---------+---------------+---------------+---------------+----------+------+----------+---------+
| 13977 | ods_fact_sale_doris | 2021-12-14 09:26:26 | 2021-12-14 09:26:27 | ods_fact_sale_doris | 13978 | 13891 | 1:1492711822 | 2114 | FINISHED | | NULL | 86400 |
| 14019 | ods_fact_sale_doris | 2021-12-14 09:57:22 | 2021-12-14 10:15:58 | ods_fact_sale_doris | 14020 | 13978 | 2:2147194682 | 2115 | FINISHED | | NULL | 86400 |
| 14245 | ods_fact_sale | 2021-12-16 12:14:17 | NULL | ods_fact_sale | 14246 | 14063 | 1:390355267 | 111856 | RUNNING | | 0/10 | 86400 |
+-------+---------------------+---------------------+---------------------+---------------------+---------+---------------+---------------+---------------+----------+------+----------+---------+
3 rows in set (0.00 sec)
mysql>
mysql> show index from example_db.ods_fact_sale;
Empty set (0.01 sec)
mysql> show index from example_db.ods_fact_sale;
+------------------------------------------+------------+------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+--------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+------------------------------------------+------------+------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+--------------+
| default_cluster:example_db.ods_fact_sale | | b_odsfactsale_prodname | | prod_name | | | | | | BITMAP | 产品名称 |
+------------------------------------------+------------+------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+--------------+
1 row in set (0.01 sec)
网友评论