mysql - index usage on union where conditions -
i have following query:
select * t t.a = '1' or t.b = '2' or t.c = '3'
full scan performed there no single index satisy these conditions.
are there way avoid full scans , use indexes?
according documentation, mysql offer "index merge". however, i'm not sure gets used in practice.
first, let me assume have indexes on t(a)
, t(b)
, , t(c)
. then, check if index merge helps.
if not, rephrase query union
(not union all
) query:
select t.* t t.a = '1' union select t.* t t.b = '2' union select t.* t t.c = '3';
each of subqueries should use index. union
incur overhead removing duplicates. if know there no duplicates (or not care them), change union
union all
.
Comments
Post a Comment