我将哈希值存储在bit(64)
类型的表上。其中一些哈希记录无法通过select
直接匹配来检索
的说明:
我使用命令
在数据库中插入每个哈希insert into hashes (id, hash) values (0, 0xad66f2f8f3815456);
然后,我用
检索记录select id from hashes where hex(hash) = 'ad66f2f8f3815456';
+------+
| id |
+------+
| 0 |
+------+
只要散列不是零填充,这就可以工作:
insert into hashes (id, hash) values (1, 0x0d66f2f8f3815456);
select id from hashes where hex(hash) = '0d66f2f8f3815456';
Empty set (0.00 sec)
通过匹配ID来检索记录会导致:
select id, hex(hash) from hashes where id = 1;
+------+-----------------+
| id | hex(hash) |
+------+-----------------+
| 1 | D66F2F8F3815456 |
+------+-----------------+
所以我想我无法在存储的哈希和提示的哈希之间进行数字匹配,无论填充零。我正在使用的表是:
describe hashes;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(4) | YES | | NULL | |
| hash | bit(64) | YES | MUL | NULL | |
+-------+---------+------+-----+---------+-------+
这怎么解决?这是处理需要进行数值比较的64位哈希记录的正确方法吗? 我有几千条这样的记录,因此它们不应该被存储为繁琐的varchars。