MySQL 5.5 模式匹配LIKE
mysql> select * from t_test;
+--------+-------------+---------+
| deptno | dname | loc |
+--------+-------------+---------+
| 10 | Research | Beijing |
| 20 | Maintenance | Huludao |
| 30 | Market | Tianjin |
| 40 | Leader | Qingdao |
+--------+-------------+---------+
4 rows in set (0.00 sec)
mysql> create index idx_test_dname on t_test(dname);
Query OK, 0 rows affected (0.31 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show keys from t_test\G
*************************** 1. row ***************************
Table: t_test
Non_unique: 1
Key_name: idx_test_dname
Seq_in_index: 1
Column_name: dname
Collation: A
Cardinality: 4
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
1 row in set (0.00 sec)
%Lea%沒有使用索引掃描
mysql> explain select * from t_test where dname like '%Lea%';
+----+-------------+--------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t_test | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
+----+-------------+--------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
Lea%使用索引掃描
mysql> explain select * from t_test where dname like 'Lea%';
+----+-------------+--------+-------+----------------+----------------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+-------------+
| 1 | SIMPLE | t_test | range | idx_test_dname | idx_test_dname | 47 | NULL | 1 | Using where |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+-------------+
1 row in set (0.12 sec)
mysql> explain select dname from t_test where dname like 'Lea%';
+----+-------------+--------+-------+----------------+----------------+---------+------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+--------------------------+
| 1 | SIMPLE | t_test | index | idx_test_dname | idx_test_dname | 47 | NULL | 4 | Using where; Using index |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+--------------------------+
1 row in set (0.00 sec)
+--------+-------------+---------+
| deptno | dname | loc |
+--------+-------------+---------+
| 10 | Research | Beijing |
| 20 | Maintenance | Huludao |
| 30 | Market | Tianjin |
| 40 | Leader | Qingdao |
+--------+-------------+---------+
4 rows in set (0.00 sec)
mysql> create index idx_test_dname on t_test(dname);
Query OK, 0 rows affected (0.31 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show keys from t_test\G
*************************** 1. row ***************************
Table: t_test
Non_unique: 1
Key_name: idx_test_dname
Seq_in_index: 1
Column_name: dname
Collation: A
Cardinality: 4
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
1 row in set (0.00 sec)
%Lea%沒有使用索引掃描
mysql> explain select * from t_test where dname like '%Lea%';
+----+-------------+--------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t_test | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
+----+-------------+--------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
Lea%使用索引掃描
mysql> explain select * from t_test where dname like 'Lea%';
+----+-------------+--------+-------+----------------+----------------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+-------------+
| 1 | SIMPLE | t_test | range | idx_test_dname | idx_test_dname | 47 | NULL | 1 | Using where |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+-------------+
1 row in set (0.12 sec)
mysql> explain select dname from t_test where dname like 'Lea%';
+----+-------------+--------+-------+----------------+----------------+---------+------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+--------------------------+
| 1 | SIMPLE | t_test | index | idx_test_dname | idx_test_dname | 47 | NULL | 4 | Using where; Using index |
+----+-------------+--------+-------+----------------+----------------+---------+------+------+--------------------------+
1 row in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2112954/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 老生常談:MYSQL模式匹配 REGEXP和like的用法MySql模式
- Mysql利用Like支援根據匹配度進行查詢MySql
- mysql like查詢 - 根據多個條件的模糊匹配查詢MySql
- 資料庫like匹配的實現猜測資料庫
- 如何(rhel4 mysql 5.5)在命令列模式中操作mysql(一)MySql命令列模式
- New in Mysql 5.5MySql
- 《MySQL 入門教程》第 09 篇 字串模式匹配MySql字串模式
- Scala模式匹配模式
- Rust -- 模式與匹配Rust模式
- 4-模式匹配模式
- C# 模式匹配C#模式
- MySQL用LIKE特殊字元搜尋MySql字元
- MySQL 中文 like 問題解決MySql
- Elasticsearch實現Mysql的Like效果ElasticsearchMySql
- mysql 資料庫部署(google like?)MySql資料庫Go
- MySQL 5.5 mysqlimport介紹MySqlImport
- mysql5.5安裝MySql
- 安裝mysql5.5MySql
- MySQL 5.5 Master/Slave 配置MySqlAST
- 【Tip】解決like中無法匹配下劃線的問題
- Oracle 解決like中無法匹配下劃線的問題Oracle
- MySQL的create table as 與 like區別MySql
- Swift中的模式匹配Swift模式
- 聊聊 scala 的模式匹配模式
- Glob Patterns匹配模式使用模式
- Scala模式匹配詳解模式
- 字串匹配模式問題字串匹配模式
- Mysql 5.5 重置root密碼MySql密碼
- MySQL 5.5 複製搭建流程MySql
- MySQL 5.5 mysqlbinlog 介紹MySql
- MySQL 5.5 統計資訊收集MySql
- CentOS升級MySQL到5.5CentOSMySql
- CMAKE安裝mysql5.5MySql
- MySQL 5.5新特性詳解MySql
- MySQL 5.5常用資訊函式MySql函式
- Index of /Downloads/MySQL-5.5/IndexMySql
- Centos5.5中安裝Mysql5.5過程分享CentOSMySql
- Ubuntu14.04LAMP搭建(Apache2.47+MySQL5.5+PHP5.5)UbuntuLAMPApacheMySqlPHP