1. Bitmap索引的使用
1.1 Bitmap索引介绍
bitmap index是一种位图索引,是一种快速数据结构,能够加快查询速度
1.2 Bitmap索引使用的注意事项
使用限制 :
bitmap索引支持的数据类型 :
1.3 Bitmap索引的使用
创建索引
mysql> create index if not exists click_bitmap_index on test_db.click (user_id) IDC.com/xtywjcwz/23035.html" target="_blank">Using bitmap comment ‘bitmap index test’;
Query OK, 0 rows affected (0.05 sec)
查看索引
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> drop index if exists click_bitmap_index on test_db.click;
Query OK, 0 rows affected (0.03 sec)
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索引也是以Block为粒度创建的。每个Block中,指定列的值作为一个集合生成一个BloomFilter索引条目,用于在查询是快速过滤不满足条件的数据
2.3 BloomFilter索引的使用
创建表使用BloomFilter索引
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)
查看BloomFilter索引
mysql> show create table order_tb;
删除BloomFilter索引
mysql> alter table test_db.order_tb set (‘bloom_filter_columns’ = ”);
Query OK, 0 rows affected (0.05 sec)
修改BloomFilter索引
mysql> alter table test_db.order_tb set (‘bloom_filter_columns’ = ‘user_id,city’);
Query OK, 0 rows affected (0.05 sec)
2.4 Doris BloomFilter使用场景
2.5 Doris BloomFilter使用注意事项
Linux技术文档操作系统
数据库运维技术服务 » apacheDoris的Bitmap索引和BloomFilter索引使用及注意事项
香港服务器首选树叶云,2H2G首月10元开通。树叶云(shuyeidc.com)提供简单好用,价格厚道的香港/美国云 服务器 和独立服务器。IDC+ISP+ICP资质。ARIN和APNIC会员。成熟技术团队15年行业经验。
发表评论