FWIW, I don't think the previously provided duplicate questions were actually duplicate of this specific question and instead answered a more complex tangentially related question on how to improve searching with double wildcards (contains type of searches). Some of the answers probably can be applied here as well, but are overly complicated for this much easier problem, hence my vote to re-open the question. I tried locating a suitable duplicate with the simpler solution but could not find one.
Is there any way to improve performance on like searches that have the % to the left of the searched value?
Assuming you do strictly mean only starts-with type of searches (only leading wildcards) and not contains type of searches, then there are some fairly simple solutions.
One solution involves storing a copy of the column reversed (a computed column can help here) and then creating an index on the reversed column. Then you can reverse your wildcard order to make it an ends-with search against the reversed column. This would be logically equivalent and also be sargable, therefore allowing the index to be used in an efficient manner.
Example code:
-- Step 1: Add a computed column with the reversed column
ALTER TABLE YourTable
ADD fullpath_reversed AS REVERSE(fullpath);
-- Step 2: Index the newly created reversed column
CREATE NONCLUSTERED INDEX IX_YourTable_fullpath_reversed ON YourTable (fullpath_reversed);
-- Step 3: Query the newly created column efficiently
select *
from YourTable
where fullpath_reversed like 'exe.ih%';
Note you shouldn't use SELECT *
in any non-adhoc code, especially when you're concerned about performance. Only list out the columns you actually care about for that particular query. It's more performant both from reading less data than necessary and potentially resulting in a better query plan, with indexes chosen, and index operations used.