找到网上一大神方法(头晕了, 准备明天测试吧):
http://stackoverflow.com/questions/4777070/hamming-distance-on-binary-strings-in-sql
这种是32位, 分成4分, 保存在bigint类型里,
The only fast way to get decent performance is to split the content of the BINARY column in multiple BIGINT columns, each containing an 8-byte substring of the original data.
但迷惑的是, bigint远不止保存2的8次方那么大, 为什么只保存8位. 如果是非得是8位, 那我岂不是要建8个bigint类型来储存64个bit. 求大大们解惑.

解决方案 »

  1.   

    感觉这种重计算应用不应该用数据库  至少应该用内存数据库可以试试
    CREATE TABLE `pictures` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
       `filename` varchar(255) DEFAULT NULL 
      `time_added` varchar(255) DEFAULT NULL,
      `time_update` varchar(255) DEFAULT NULL,
      `hash` bit(64) DEFAULT NULL,
      `hash2` bit(64) DEFAULT NULL COMMENT 'hash 180',
      
      PRIMARY KEY (`id`),
      
      KEY `hash` (`hash`)
    ) ENGINE=memory DEFAULT CHARSET=utf8;
      

  2.   

    感谢提醒, 这也是一种解决方法, 但事实上我的picture是有近600w的记录, 40w只是其中一个分类, 而且图片的数量在不断的增长中, 内存表只能一时治标.
    大大们能否帮我解惑:
     bigint远不止保存2的8次方那么大, 为什么只保存8位. 如果是非得是8位, 那我岂不是要建8个bigint类型来储存64个bit. 求大大们解惑.