select * from t procedure analyse(); -- 通过分析select查询结果对现有的表的每一列给出优化的建议。 其中 t:表名
EXPLAIN EXTENDED
select * from c; -- 可换成任何查询语句
SHOW WARNINGS; -- EXPLAIN 加上 EXTENDED,可以用 SHOW WARNINGS 显示出MYSQL的SQL语句中间优化结果
show index from c;
show keys from c;
附:SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max_elements,[max_memory]])
max_elements (default 256) is the maximum number of distinct values that ANALYSE() notices per column. This is used by ANALYSE() to check whether the optimal data type should be of type ENUM; if there are more than max_elements distinct values, then ENUM is not a suggested type.(这个参数没得到验证,输入任何整数好像都没影响)
max_memory (default 8192) is the maximum amount of memory that ANALYSE() should allocate per column while trying to find all distinct values.(由于不理解内存最大数怎么对应,通过实验得出如下:=6+3*x+y //x 不同取值,y 总字符数)
例:
select g from enum_table procedure analyse(1,57);
建议字段:ENUM('2013-01-02','2013-01-03','time','timetimeti','TT') //取5个不同值,共36个字符,=6+3*5+36=57
select g from enum_table procedure analyse(1,56);
建议字段:VARCHAR(10)
select e from enum_table procedure analyse(1,37);
建议字段:ENUM('APPLE','DOG','FISH','HAMBURG') NOT NULL //取4个不同值,共19个字符,=6+3*4+19=37
select e from enum_table procedure analyse(1,36);
建议字段:VARCHAR(7) NOT NULL