My question about searching queries with .NOT . I’m confused which is faster for loading and process SQL query, I have implemented SQL Server query and my query getting larger and slow of fetching data even though I’m using indexing search with SQL Server 2012.
So is there any way to make my query faster with linq?
Here is simple of my query
SELECT
counting
FROM
xxxxxxx
WHERE
(Contains(BOOLEANTEXT, '"FORM"'))
AND ((Contains(BOOLEANTEXT, ' "FORM" and "WARRANT" ' )))
AND ((Contains(BOOLEANTEXT, ' "RETURN" or "RESPECTING" or "ELECTION" or "EXPENSES" ')))
OR ((Contains(BOOLEANTEXT, 'Near((FORM,WARRANT,RETURN,RESPECTING,ELECTION,EXPENSES), 1000, TRUE)' )))
AND ((Contains(BOOLEANTEXT, 'FORMSOF(INFLECTIONAL, FORM,WARRANT,RETURN,RESPECTING,ELECTION,EXPENSES)' )))
AND ((Contains(BOOLEANTEXT, 'FORMSOF(THESAURUS, FORM,WARRANT,RETURN,RESPECTING,ELECTION,EXPENSES)' )))
ORDER BY
FORMTITLE ASC
No, there is no way of improving the performance of this query with
LINQ.There will even be a slight overhead when using
LINQ, but that will for sure be neglectable in this case.LINQwill eventually also produceSQLand execute it on your database. SoLINQwill not provide any performance benefits.If you want to improve performance, you’ll have to improve this
SQL-statement itself.Looking at your WHERE-clause, there are no brackets to combine any of the
AND‘s to that singleOR. Is that on purpose? Your results will now satisfy allAND-conditionsOR ((Contains(BOOLEANTEXT, 'Near((FORM,WARRANT,RETURN,RESPECTING,ELECTION,EXPENSES), 1000, TRUE)' )))This might get you a lot more results than you are expecting.
Some more on the
AND‘s andOR.Your
WHERE-clause is now similar to:I suppose, you actually mean something like:
I don not say your
WHERE-clause is wrong. I only suspect you need some extra brackets somewhere, to get theWHERE-clause you had in mind.But before adding brackets, let’s remove some to improve readability. This will do the same as yours: