SELECT DISTINCT id,一些COALESCE(CONVERT(),CONVERT())函数 FROM p JOIN b LEFT JOIN 翻译表 x1 ON x1.xid = p.Name LEFT JOIN 翻译表 x2 ON x2.xid = p.Number LEFT JOIN 翻译表 x3 ON x3.xid = b.Code WHERE b.id = p.bID AND p.bID > 0 AND COALESCE(CONVERT(),CONVERT())函数 LIKE '%xxxx%' ORDER BY p.name LIMIT 15;当有order by 的时候 show processlist显示创建临时表, 删掉orderby显示send data 没有order by和模糊查询时候就1S内查完 都有用的只有主键索引,innodb不能创建全文索引
p.name 上建个索引试试
试过了 用了name索引 除非把模糊查询 和distinct去掉 不然还是建临时表 很慢
以文本方式贴出 explain select ... show index from .. 以供分析。
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE p ALL \N \N \N \N 299070 Using where; Using temporary; Using filesort 1 SIMPLE b eq_ref PRIMARY PRIMARY 4 p.bID 1 1 SIMPLE x1 eq_ref PRIMARY PRIMARY 10 p.Name 1 Using where 1 SIMPLE x2 eq_ref PRIMARY PRIMARY 10 p.Number 1 1 SIMPLE x3 eq_ref PRIMARY PRIMARY 10 b.Code 1 抱歉新手开始没懂什么意思, 这个查询数据表不全 所以没有查出结果 这是还没在P。name上加索引之前的,加了索引第一个用了p。name索引 但还是有用临时表
SELECT DISTINCT id,一些COALESCE(CONVERT(),CONVERT())函数
FROM p JOIN b
LEFT JOIN 翻译表 x1 ON x1.xid = p.Name
LEFT JOIN 翻译表 x2 ON x2.xid = p.Number
LEFT JOIN 翻译表 x3 ON x3.xid = b.Code
WHERE b.id = p.bID
AND p.bID > 0
AND COALESCE(CONVERT(),CONVERT())函数 LIKE '%xxxx%'
ORDER BY p.name LIMIT 15;当有order by 的时候 show processlist显示创建临时表, 删掉orderby显示send data 没有order by和模糊查询时候就1S内查完 都有用的只有主键索引,innodb不能创建全文索引
p.name 上建个索引试试
试过了 用了name索引 除非把模糊查询 和distinct去掉 不然还是建临时表 很慢
explain select ...
show index from ..
以供分析。
1 SIMPLE p ALL \N \N \N \N 299070 Using where; Using temporary; Using filesort
1 SIMPLE b eq_ref PRIMARY PRIMARY 4 p.bID 1
1 SIMPLE x1 eq_ref PRIMARY PRIMARY 10 p.Name 1 Using where
1 SIMPLE x2 eq_ref PRIMARY PRIMARY 10 p.Number 1
1 SIMPLE x3 eq_ref PRIMARY PRIMARY 10 b.Code 1 抱歉新手开始没懂什么意思, 这个查询数据表不全 所以没有查出结果 这是还没在P。name上加索引之前的,加了索引第一个用了p。name索引 但还是有用临时表