mysql中group by实现原理是什么
CREATE TABLE `tb` (
`c` INT(11) DEFAULT NULL,
`d` INT(4) DEFAULT NULL,
`e` VARCHAR(1000) DEFAULT NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8;
INSERT INTO tb VALUES(2,20,'b');
INSERT INTO tb VALUES(1,10,'a');
INSERT INTO tb VALUES(2,20,'b');
INSERT INTO tb VALUES(1,10,'a');
INSERT INTO tb VALUES(3,30,'c');
EXPLAIN SELECT c,COUNT(*) FROM tb GROUP BY c
在这个语句的explain结果中有Using temporary; Using filesort,需要用到排序。
难道group by的实现,是“先排序,后分组”,还是什么样子的?
西瓦的守护
12 years, 4 months ago