- 论坛徽章:
- 0
|
root@localhost[test] 11:40>create table cu2 like cu;
Query OK, 0 rows affected (0.03 sec)
root@localhost[test] 11:41>show create table cu2\G
*************************** 1. row ***************************
Table: cu2
Create Table: CREATE TABLE `cu2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`cid` int(11) DEFAULT NULL,
`time` int(11) DEFAULT NULL,
`ip` varchar(45) DEFAULT NULL,
`state` int(11) DEFAULT NULL,
`admin_id` double DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_cu_cid_uid_time` (`cid`,`uid`,`time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
root@localhost[test] 11:42>insert into cu2 select * from cu;
Query OK, 6966 rows affected (0.03 sec)
Records: 6966 Duplicates: 0 Warnings: 0
两个几乎一样的表,一样的sql执行计划却不同
root@localhost[test] 11:42>explain select uid,max(time) from cu where cid<4 group by cid,uid\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: cu
type: range
possible_keys: index_cu_cid_uid_time
key: index_cu_cid_uid_time
key_len: 10
ref: NULL
rows: 2
Extra: Using where; Using index for group-by
1 row in set (0.00 sec)
root@localhost[test] 11:46>explain select uid,max(time) from cu2 where cid<4 group by cid,uid\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: cu2
type: range
possible_keys: index_cu_cid_uid_time
key: index_cu_cid_uid_time
key_len: 5
ref: NULL
rows: 1511
Extra: Using where; Using index
1 row in set (0.00 sec)
???这是为什么呢... |
|