以下是我与mysql的互动。我有一个简单的查询和该列的索引;但它只说使用where而不是index。表中有超过500行。
[root@php-pos-db ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4085957
Server version: 5.5.42-log Distributed by The IUS Community Project
Copyright (c) 2000, 2015, 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> use phppoint_site;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show create table subscriptions;
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| subscriptions | CREATE TABLE `subscriptions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`name` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`country` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`address_1` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`address_2` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`city` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`state` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`zip` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`email` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`phone` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`username` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`subscr_id` varchar(19) COLLATE utf8_unicode_ci NOT NULL,
`subscr_status` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`quantity` int(10) NOT NULL,
`auth` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`is_installed` int(1) NOT NULL DEFAULT '0',
`cancel_date` timestamp NULL DEFAULT NULL,
`viewed` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=897 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from subscriptions where username ='me';
+-----+---------+--------------+---------+-----------+-----------+------+-------+-----+--------------------+-------+----------+----------+-----------+---------------+----------+------+--------------+-------------+--------+
| id | company | name | country | address_1 | address_2 | city | state | zip | email | phone | username | password | subscr_id | subscr_status | quantity | auth | is_installed | cancel_date | viewed |
+-----+---------+--------------+---------+-----------+-----------+------+-------+-----+--------------------+-------+----------+----------+-----------+---------------+----------+------+--------------+-------------+--------+
| 418 | | Chris Muench | | | | | | | me@chrismuench.com | | me | | | payment | 1 | | 1 | NULL | 0 |
+-----+---------+--------------+---------+-----------+-----------+------+-------+-----+--------------------+-------+----------+----------+-----------+---------------+----------+------+--------------+-------------+--------+
1 row in set (0.00 sec)
mysql> explain select * from subscriptions where username ='me';
+----+-------------+---------------+------+---------------+----------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------------+------+---------------+----------+---------+-------+------+-------------+
| 1 | SIMPLE | subscriptions | ref | username | username | 92 | const | 1 | Using where |
+----+-------------+---------------+------+---------------+----------+---------+-------+------+-------------+
1 row in set (0.00 sec)
mysql>