我遇到了union select
(简称)的性能问题:
SELECT
x.a, x.b, x.c, x.d, x.e, x.f, x.g, y.h, y.i
FROM
x
LEFT JOIN y ON ...
UNION
SELECT
c.a, c.b, c.c., c.d, c.e, c.f, c.g, d.h, d.i
FROM
c
LEFT JOIN d ON ...
ORDER BY `ID`, CAST(`X` as UNSIGNED)
由于ORDER BY
,我认为查询最多需要一秒钟。但删除ORDER BY
并没有真正的性能提升。
EXPLAIN看起来像:
有人有想法吗?
为什么这么慢?
答案 0 :(得分:1)
使用此
ORDER BY `ID`
和CAST(
X as UNSIGNED)
在您按
X
时使用它