创建BLOOMFILTER索引
功能
布隆过滤器(Bloom Filter)是一种概率型数据结构,用于判断一个元素是否属于某个集合。本功能允许用户在表中创建布隆过滤器索引,以提高查询效率。具体介绍参考Bloomfilter Index
语法
CREATE BLOOMFILTER INDEX [IF NOT EXISTS] index_name ON TABLE
[schema].table_name(column_name)
[COMMENT 'comment']
[PROPERTIES ('key'='value')]
bloomfilter:索引类型,使用布隆过滤器算法。
index_name:要创建的索引名称,需位于指定的schema下,且在同一schema下不能重复。
schema:可选参数,用于指定表的schema名称。
table_name:要创建索引的表名称。
column_name:要创建索引的列名称,目前仅支持单列索引。
COMMENT:可选参数,用于添加关于索引的描述信息。
PROPERTIES:可选参数,Lakehouse保留属性,方便之后扩展添加属性。
参考文档
使用注意事项
- BLOOMFILTER INDEX添加完成后只有新写入的数据才会生效。老数据不会生效。如果老数据需要生效必须重写数据
- 一张表可以创建多个布隆过滤器索引。
- 类型限制:不支持interval、struct、map、array等类型。如果尝试使用不支持的类型,系统将报错。
使用说明
BLOOMFILTER INDEX使用说明
示例
-
建表时指定BLOOMFILTER索引
DROP TABLE IF EXISTS t;
CREATE TABLE t (
order_id INT,
customer_id INT,
amount DOUBLE,
order_year string,
order_month string,
INDEX order_id_index (order_id) BLOOMFILTER COMMENT 'BLOOMFILTER'
);
INSERT INTO t
VALUES (1, 101, 100.0, '2023','01'),
(2, 102, 200.0, '2023','02'),
(3, 103, 300.0, '2023','03'),
(4, 104, 400.0, '2023','04'),
(5, 105, 500.0, '2023','04');
SHOW INDEX FROM t;
+----------------+--------------+
| index_name | index_type |
+----------------+--------------+
| order_id_index | bloom_filter |
+----------------+--------------+
DESC INDEX order_id_index;
+--------------------+-------------------------+
| info_name | info_value |
+--------------------+-------------------------+
| name | order_id_index |
| creator | UAT_TEST |
| created_time | 2024-12-26 21:20:43.914 |
| last_modified_time | 2024-12-26 21:20:43.914 |
| comment | BLOOMFILTER |
| index_type | bloom_filter |
| table_name | t |
| table_column | order_id |
+--------------------+-------------------------+
DROP INDEX order_id_index;
-
给已有的列添加BLOOMFILTER索引
CREATE BLOOMFILTER INDEX customer_id_index
ON TABLE public.t (customer_id)
COMMENT 'xx';
--BLOOMFILTER INDEX添加完成后只有新写入的数据才会生效。老数据不会生效。如果老数据需要生效必须重写数据
INSERT OVERWRTE t SELECT * FROM t;
DESC INDEX customer_id_index;
+--------------------+-------------------------+
| info_name | info_value |
+--------------------+-------------------------+
| name | customer_id_index |
| creator | UAT_TEST |
| created_time | 2024-12-26 21:24:57.649 |
| last_modified_time | 2024-12-26 21:24:57.649 |
| comment | xx |
| index_type | bloom_filter |
| table_name | t |
| table_column | customer_id |
+--------------------+-------------------------+
DROP INDEX customer_id_index;