小编Rah*_*hul的帖子

添加 where 条件后,Mysql 查询需要永远

我有一个 mysql 查询,它在 4 秒内返回结果。

SELECT 
    *
FROM
    xercasehistory
WHERE
    xerId = 192             
ORDER BY id DESC limit 10;
Run Code Online (Sandbox Code Playgroud)

但是当我向现有参数添加额外的 where 参数时,大约需要 30 秒才能完成。

SELECT 
    *
FROM
    xercasehistory
WHERE
    xerId = 192 AND type = 'case'
        AND fieldName = 'statusCode'
        AND typesKey=5            
ORDER BY id DESC limit 10;
Run Code Online (Sandbox Code Playgroud)

因此,我通过运行检查同一张表中的索引 show indexes from xercasehistory

xercasehistory 0 PRIMARY 1 ID A 24545933 BTREE
xercasehistory 1 xecasehistory_caseId_IDX 1 caseId A 2045494 BTREE
xercasehistory 1 xecasehistory_typeskey 1 typesKey A 20169 是 BTREE
xercasehistory 1 …

mysql performance optimization query-performance

5
推荐指数
1
解决办法
149
查看次数