Sql server 2008 R2
I have two queries
DECLARE @title NVARCHAR(500) = '"Finite" AND "Elements"'
select * from papers p
where (@title = '""' OR CONTAINS(p.name, @title))
select * from papers p
where (CONTAINS(p.name, @title))
first works about 7 seconds, second several miliseconds. WHY????

The
@title = '""' OR ...bit is the problem.At compile time it does not know whether
@titleis in fact going to contain the value""and thus need to return all rows or not.You could try adding
OPTION(RECOMPILE)to the query so it is recompiled after the variable is assigned or just splitting it up into two cases.