I have a field in my table having text data type.
Is there a difference in performance for the following two sql queries:
select * from tablename where fieldname="xyz%";
select * from tablename where fieldname="%zyx";
If we were to implement the execution of these queries, this is what I think we would need to do:
We have to match the two regexes (xyz* and *zyx).
We will have to check the string chars one by starting from the beginning.
For the first query we will have to read the first three characters to see if there is a match but for the second one we will have to read till the we get the end of the string to determine if the match has occurred. But if we have the length of the string stored somewhere we can directly read the last three characters giving similar performance as the first case.
My question is whether commercial databases like mysql and oracle show any difference in the performance in the execution of the queries.