mysql布隆过滤器源码_查询 - MySQL的按位运算,布隆过滤器

查询 - MySQL的按位运算,布隆过滤器

I'd like to implement a bloom filter using MySQL (other a suggested alternative).我想实现一个布隆过滤器使用MySQL(另外一个建议的替代)。

The problem is as follows:问题是如下:

Suppose I have a table that stores 8 bit integers, with these following values:假设我有一个表,用于存储8位整数,以下值:

1: 10011010 2: 00110101 3: 10010100 4: 00100110 5: 00111011 6: 01101010

I'd like to find all results that are bitwise AND to this:我想找到的所有结果按位与此:

00011000

The results should be rows 1 and 5.结果应该是1行和第5行。

However, in my problem, they aren't 8 bit integers, but rather n-bit integers.然而,在我的问题,他们是不是8位整数,而是n位整数。 How do I store this, and how do I query?我如何保存这一点,我怎么查询呢? Speed is key.速度是关键。来源:http://stackoverflow.com/questions/360844/mysql-bitwise-operations-bloom-filter

Create a table with int field for value, no need to store numbers as sequence of 0 and 1.创建一个表整型字段值,没有必要存储0和1的序列号。 For you data it will look like this:你的数据,它看起来像这样:

number 154 53 148 38 59 106

and you need to find all entries matching 24.你需要找到所有的匹配项24。

Then you can run a query like然后,您可以执行这样的查询

SELECT * FROM test WHERE number & 24 = 24

If you want to avoid convertion into 10 base numbers in your application you can hand it over to mysql:如果你想避免皈依为10个基数,在您的应用程序,你可以把它交给到MySQL:

INSERT INTO test SET number = b'00110101';

and search like this和搜索这样的

SELECT bin(number) FROM test WHERE number & b'00011000' = b'00011000'

Consider not using MySQL for this.考虑不使用MySQL的这个。

First off, there probably isn't a built-in way for more than 64-bit tables.首先,有可能不是一个内置的方式,超过64位的表。 You'd have to resort to user-defined functions written in C.你不得不求助于C语言编写的用户定义函数

Second, each query is going to require a full table scan, because MySQL can't use an index for your query.其次,每个查询需要进行全表扫描,因为MySQL不能使用索引查询。 So, unless your table is very small, this will not be fast.所以,除非你的表是非常小的,这不会是快。

原文链接:http://www.16kan.com/question/detail/275365.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值