Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL bitwise operations, bloom filter

I'd like to implement a bloom filter using MySQL (other a suggested alternative).

The problem is as follows:

Suppose I have a table that stores 8 bit integers, with these following values:

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.

However, in my problem, they aren't 8 bit integers, but rather n-bit integers. How do I store this, and how do I query? Speed is key.

like image 564
Sam Avatar asked Dec 11 '08 20:12

Sam


1 Answers

Consider not using MySQL for this.

First off, there probably isn't a built-in way for more than 64-bit tables. You'd have to resort to user-defined functions written in C.

Second, each query is going to require a full table scan, because MySQL can't use an index for your query. So, unless your table is very small, this will not be fast.

like image 138
derobert Avatar answered Sep 23 '22 17:09

derobert