Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL: an efficient binary value comparison
    primarykey
    data
    text
    <p>My table has 8 VARCHAR fields of binary strings of 64bits each one. My goal is to get <a href="http://en.wikipedia.org/wiki/Hamming_distance" rel="nofollow">Hamming distance</a> for each register. I was doing it with the next query :</p> <pre><code>SELECT BIT_COUNT(CONV(fp.bin_str0, 2, 10 ) ^ CONV('0000000001101111000000000101011100000000001010100000000001111101', 2, 10 )) + BIT_COUNT(CONV(fp.bin_str1, 2, 10 ) ^ CONV('0000000010110001000000001000000000000000011000010000000011110100', 2, 10 )) + BIT_COUNT(CONV(fp.bin_str2, 2, 10 ) ^ CONV('0000000010010100000000000010101100000000110001000000000011100100', 2, 10 )) + BIT_COUNT(CONV(fp.bin_str3, 2, 10 ) ^ CONV('0000000011101011000000000001110000000000101100010000000000011001', 2, 10 )) + BIT_COUNT(CONV(fp.bin_str4, 2, 10 ) ^ CONV('0000000000010000000000000011010100000000111011100000000001001101', 2, 10 )) + BIT_COUNT(CONV(fp.bin_str5, 2, 10 ) ^ CONV('0000000000101111000000000110101000000000000010100000000000101101', 2, 10 )) + BIT_COUNT(CONV(fp.bin_str6, 2, 10 ) ^ CONV('0000000000011000000000000101011000000000001010000000000000001011', 2, 10 )) + BIT_COUNT(CONV(fp.bin_str7, 2, 10 ) ^ CONV('0000000000101011000000000011100100000000000100000000000000111010', 2, 10 )) from mytable fp </code></pre> <p>So this query is extremely slow. There are some reasons: mytable has 3M registers and the field <code>fp.bin_stri</code> is of VARCHAR type.</p> <p><em>As MySQL has BINARY type, can I execute the same query over <code>fp.bin_stri</code> of BINARY type? An how?</em> </p> <p>I'm confused because, when I have changed <code>fp.bin_stri</code> to BINARY, the data of this field has appeared as BLOB and now I don't know how the query should look like. Should it use <code>CONV</code>? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload