现有表,主要字段 id cname ename lastModifyTime 数据量300W行,要过滤 重复 cname&ename 并且可以having cname ename 模糊查找 ,而且 可以 order by lastModifyTime, 最后order by lastModifyTime 没办法使用上 索引,据说是原因是group by [col1],[col2] 两列.
id int(11) NO PRI auto_increment
version int(11) YES
createByUserCode varchar(50) YES
createByUserName varchar(50) YES
createTime datetime YES
lastModifyByUserCode varchar(50) YES
lastModifyByUserName varchar(50) YES
lastModifyTime datetime YES MUL
status varchar(10) YES
seq int(11) YES
cname varchar(50) YES MUL
ename varchar(50) YES MUL
value varchar(255) YES
productCode varchar(50) YES MUL
id int(11) NO PRI auto_increment
version int(11) YES
createByUserCode varchar(50) YES
createByUserName varchar(50) YES
createTime datetime YES
lastModifyByUserCode varchar(50) YES
lastModifyByUserName varchar(50) YES
lastModifyTime datetime YES MUL
status varchar(10) YES
seq int(11) YES
cname varchar(50) YES MUL
ename varchar(50) YES MUL
value varchar(255) YES
productCode varchar(50) YES MUL
SELECT * FROM b_common_product_param a GROUP BY a.cname,a.ename HAVING a.cname LIKE "-3db Bandw%" LIMIT 10
使用时间 :
受影响的行: 0
时间: 686.169s
EXPLAIN SELECT * FROM b_common_product_param a GROUP BY a.cname,a.ename HAVING a.cname LIKE "-3db Bandw%" LIMIT 10
1 SIMPLE a index idx_cname_ename idx_cname_ename 306 32855876
show index FROM b_common_product_param
b_common_product_param 0 PRIMARY 1 id A 32855876 BTREE
b_common_product_param 1 idx_ename 1 ename A 83816 YES BTREE
b_common_product_param 1 idx_productcode 1 productCode A 4693696 YES BTREE
b_common_product_param 1 idx_lastmodifytime 1 lastModifyTime A 126856 YES BTREE
b_common_product_param 1 idx_cname 1 cname A 54487 7 YES BTREE
b_common_product_param 1 idx_cname_ename 1 cname A 109519 YES BTREE
b_common_product_param 1 idx_cname_ename 2 ename A 109519 YES BTREE
除了 用临时表,各位高手还有其他办法吗?
解决方案
40
SELECT * FROM b_common_product_param a where a.cname LIKE “-3db Bandw%” GROUP BY a.cname,a.ename LIMIT 10