Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
select A,B,C,D from tableName where A=1 and B=2 or C=3 and D like 'test%';
create index indexAB on table tableName (A,B,C,D);
create index indexCD on table tableName (C,D,A,B);
select A,B,C,D from tableName where A=1 and B=2
union all
select A,B,C,D from tableName where C=3 and D like 'test%' and (not (A=1 and B=2) or A is null or B is null)
)
select A,C,D from tableName where B=3 or C=3 and D ='test' order by B;
create index (B,A,C,D);
create index (C,D,B,A);
select A,C,D from tableName where (B<3 /*or B is null*/)and C=3 and D ='test' order by B
union all
select A,C,D from tableName where B=3
union all
select A,C,D from tableName where (B>3 /*or B is null*/)and C=3 and D ='test' order by B
Оптимизация сложных запросов MySQL