在MySQL中经常用到大对象对于如歌提高它的查询性能.这里提供一种方式,利用合成索引提高大字段的查询性能,模糊匹配还是会产生全表扫描的效果 什么是合成索引呢? 简单来说就是根据大字段的内容建立一个散列值,并把值单独存储在数据列中,接下来通过检索散列值找到数据. 例: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.14 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> mysql> mysql> mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | test | | world | +--------------------+ 6 rows in set (0.00 sec)
mysql> use test; Database changed
mysql> create table test (id varchar(100),con blob ,hash_value varchar(50)); ERROR 1050 (42S01): Table 'test' already exists
mysql> create table test (id varchar(100),con blob ,hash_value varchar(50)); Query OK, 0 rows affected (0.69 sec)
mysql> insert into test values (1,repeat('shanghai',10),md5(con)); Query OK, 1 row affected (0.07 sec)
mysql> insert into test values (2,repeat('shanghai',10),md5(con)); Query OK, 1 row affected (0.05 sec)
mysql> insert into test values (3,repeat('shanghai',10),md5(con)); Query OK, 1 row affected (0.20 sec)
mysql> insert into test values (3,repeat('shanghai shibohui',10),md5(con)); Query OK, 1 row affected (0.06 sec)
mysql> select * from test; +------+------------------------------------------------------------------------ -------------------------------------------------------------------------------- --------------------+----------------------------------+ | id | con
如果要查询shanghai shibohui,那么可以通过散列值来查询 mysql> select * from test where hash_value=md5(repeat('shanghai shibohui',10)); +------+------------------------------------------------------------------------ -------------------------------------------------------------------------------- --------------------+----------------------------------+ | id | con