Sql – MS SQL Server optimizer and varying table and field aliases


We have a lot of queries for which we append a random alias at the end of field and table names (due to a custom ORM implementation that might be hard to change). The queries are like the following (though substantially more complex, most of the time):

SELECT fooA.field1 as field1B, 
       fooA.field2 as field1C 
FROM foo as fooA

The suffixes A, B and C are randomly generated (and longer than one character). Will this hurt performance of our queries (i.e. will the optimizer not be able to recognize repeated queries due to the random part)? We mainly use SQL Server 2005.

Best Solution

Yes, the optimizer will need to reparse and recompile your query each time, since the query hash will change.