I need to optimise this query
SELECT DISTINCT abc.*
FROM abc, xyz, xyz_value
WHERE abc.CategoryID IN ( $category_children )
$where_var AND abc.Removed = 0 AND
xyz_value.Removed = 0 AND abc.abcID = xyz_value.GenericID AND
xyz_value.AttributeID = xyz.AttributeID $narrow_query
ORDER BY
if(abc.Title REGEXP ('^[0-9]') = 1,cast(abc.Title as UNSIGNED),999999) ASC,
if(abc.Title REGEXP ('^[0-9]') = 1,'z',abc.Title) $order_how
$limit
$category_children
is an array containing a bunch of category IDs. The attribute to be sorted contains string starting from digits, alphabets and also special characters.
This query is getting slow due to regular expression used for sorting having execution time of 3 secs. And it takes .01 secs without sorting. How can I reduce its execution time? Any type of help is greatly appreciated.