I have a query that is executed several hundred thousand times a day. Due to legacy support, the incoming variables on this SP cannot change. Currently it looks like this:
Select id, name, otherdata FROM Table1 t1 --<Various joins with aliases>-- INNER JOIN Culture c on c.id = t1.ID_Culture WHERE c.CultureTag = @CultureTag -- Usually 'en-US'
My question is: Would it be more efficient to remove the join to the culture table, and instead, SELECT the value of the primary key on the culture table and use THAT in the where clause? Would it be negligible?
EDIT: To clarify, would changing the code to this be more efficient?
DECLARE @CultureIdLocal int = (Select id from Culture where CultureTag = @CultureTag) Select id, name, otherdata FROM Table1 t1 --<Various joins with aliases>-- --INNER JOIN Culture c on c.id = t1.ID_Culture WHERE t1.ID_Culture = @CultureIdLocal
No need to refactor the single query into two separate ones. SQL Server should be able to figure out the most optimal way to execute the query on your behalf. Make sure the Culture table has a unique index on CultureTag and, in the case of a non-clustered index, add all of the columns needed by the query as