linux
主页 > 服务器 > linux >

Apache Doris的Bitmap索引和BloomFilter索引使用及注意事项

2022-09-27 | 佚名 | 点击:

1. Bitmap索引的使用

1.1 Bitmap索引介绍

bitmap index是一种位图索引,是一种快速数据结构,能够加快查询速度

1.2 Bitmap索引使用的注意事项

使用限制:

bitmap索引支持的数据类型:

1.3 Bitmap索引的使用

创建索引

1

2

3

4

mysql> create index if not exists click_bitmap_index on test_db.click (user_id) using bitmap comment 'bitmap index test';

Query OK, 0 rows affected (0.05 sec)

 

mysql>

查看索引

1

2

3

4

5

6

7

8

9

mysql> show index from test_db.click;

+-------------------------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-------------------+

| Table                         | Non_unique | Key_name           | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment           |

+-------------------------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-------------------+

| default_cluster:test_db.click |            | click_bitmap_index |              | user_id     |           |             |          |        |      | BITMAP     | bitmap index test |

+-------------------------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-------------------+

1 row in set (0.04 sec)

 

mysql>

删除索引

1

2

3

4

mysql> drop index if exists click_bitmap_index on test_db.click;

Query OK, 0 rows affected (0.03 sec)

 

mysql>

2. BloomFilter索引

2.1 BloomFilter索引介绍

是一种多哈希函数映射的快速查找算法,本质上是一种位图结构。通常应用在一些需要快速判断某个元素是否属于集合,但是并不严格要求100%正确的场合,因为BloomFilter会告诉调用者一个元素存在或不存在一个集合。但存在不一定准确

2.2 BloomFilter原理

实际上是由一个超长的二进制位数组和一系列的哈希函数组成。二进制位数组初始全部为0,当给定一个元素时,这个元素会被一系列哈希函数计算映射出一系列的值,所有的值在位数组的偏移量处置为1。而对于一个待查询的元素,也会用相同的哈希函数映射到位数组上,只要有一个哈希函数映射没有命中之前的元素的偏移量,则不存在于集合中

下图所示出一个m=18, k=3(m是该Bit数组的大小,k是Hash函数的个数)的Bloom Filter示例。集合中的x、y、z三个元素通过3个不同的哈希函数散列到位数组中。当查询元素w时,通过Hash函数计算之后因为有一个比特为0,因此w不在该集合中

BloomFilter

BloomFilter索引也是以Block为粒度创建的。每个Block中,指定列的值作为一个集合生成一个BloomFilter索引条目,用于在查询是快速过滤不满足条件的数据

2.3 BloomFilter索引的使用

创建表使用BloomFilter索引

1

2

3

4

5

6

7

8

9

10

11

12

mysql> create table order_tb(

    -> user_id bigint,

    -> order_date date,

    -> city varchar(32),

    -> url varchar(512)

    -> ) distributed by hash(user_id, city) buckets 8

    -> properties(

    -> 'bloom_filter_columns'='user_id,order_date'

    -> );

Query OK, 0 rows affected (0.07 sec)

 

mysql>

查看BloomFilter索引

1

mysql> show create table order_tb;

删除BloomFilter索引

1

2

3

4

mysql> alter table test_db.order_tb set ('bloom_filter_columns' = '');

Query OK, 0 rows affected (0.05 sec)

 

mysql>

修改BloomFilter索引

1

2

3

4

mysql> alter table test_db.order_tb set ('bloom_filter_columns' = 'user_id,city');

Query OK, 0 rows affected (0.05 sec)

 

mysql>

2.4 Doris BloomFilter使用场景

2.5 Doris BloomFilter使用注意事项

原文链接:https://blog.csdn.net/yy8623977/article/details/126211770
相关文章
最新更新