MySQL-Cluster-gpl-7.4.12-1.el6.x86_64
查询 1
select
userinfo.username,
userinfo.firstname,
userinfo.lastname,
userinfo.email,
radcheck.attribute,
radcheck.`value`,
radusergroup.groupname,
userinfo.id,
userinfo.account_type,
userinfo.workphone,
userinfo.homephone,
userinfo.mobilephone,
userinfo.address,
userinfo.zone,
userinfo.account_state,
userinfo.link_type,
userinfo.device_owner,
userinfo.email
FROM
userinfo
INNER JOIN radcheck ON userinfo.username = radcheck.username
INNER JOIN radusergroup ON userinfo.username = radusergroup.username
WHERE
radcheck.attribute='Expiration' AND userinfo.mobilephone LIKE '9876543210%'
此查询大约需要8 秒才能完成以下是explain
查询的输出
+----+-------------+--------------+------+----------------------+-----------+---------+----------------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+------+----------------------+-----------+---------+----------------------------+------+-------------+
| 1 | SIMPLE | radcheck | ref | username,attribute | attribute | 34 | const | 9 | Using where |
| 1 | SIMPLE | userinfo | ref | username,mobilephone | username | 131 | ctradius.radcheck.username | 13 | Using where |
| 1 | SIMPLE | radusergroup | ref | username | username | 66 | ctradius.userinfo.username | 10 | Using where |
+----+-------------+--------------+------+----------------------+-----------+---------+----------------------------+------+-------------+
查询 2
以下是在< 0.005s内完成的查询
select
userinfo.username,
userinfo.firstname,
userinfo.lastname,
userinfo.email,
radcheck.attribute,
radcheck.`value`,
radusergroup.groupname,
userinfo.id,
userinfo.account_type,
userinfo.workphone,
userinfo.homephone,
userinfo.mobilephone,
userinfo.address,
userinfo.zone,
userinfo.account_state,
userinfo.link_type,
userinfo.device_owner,
userinfo.email
FROM
userinfo
INNER JOIN radcheck ON userinfo.username = radcheck.username
INNER JOIN radusergroup ON userinfo.username = radusergroup.username
WHERE
radcheck.attribute like 'Expiration%' AND userinfo.mobilephone LIKE '9876543210%'
以下是查询的解释
+----+-------------+--------------+-------+----------------------+-------------+---------+----------------------------+------+------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+-------+----------------------+-------------+---------+----------------------------+------+------------------------+
| 1 | SIMPLE | userinfo | range | username,mobilephone | mobilephone | 203 | NULL | 585 | Using where; Using MRR |
| 1 | SIMPLE | radusergroup | ref | username | username | 66 | ctradius.userinfo.username | 10 | Using where |
| 1 | SIMPLE | radcheck | ref | username,attribute | username | 66 | ctradius.userinfo.username | 17 | Using where |
+----+-------------+--------------+-------+----------------------+-------------+---------+----------------------------+------+------------------------+
问题
为什么like
使用运算符(第二个查询)而不是=
(第一个查询)时查询执行速度更快?