Quantcast
Channel: Go4Expert
Viewing all articles
Browse latest Browse all 1987

How to tune SQL with Like '%ABC%'

$
0
0
It is common we come across SQL with Like '%Alex%' in MySQL that no index will be used.
Here is one of the rewrite solution that may help in your environment.

Example
select *
from employee
where emp_name like '%Alex%';

If emp_name is indexed, we can rewrite the SQL into the following syntax.

Rewritten SQL
select *
from employee force index (emp_name_inx)
where emp_name like '%Alex%'
and emp_name>'';

Viewing all articles
Browse latest Browse all 1987

Trending Articles