Reputation: 706
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
Upvotes: 1
Views: 1916
Reputation: 3271
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.
LINQ
will eventually also produce SQL
and execute it on your database. So LINQ
will 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 single OR
. Is that on purpose? Your results will now satisfy all AND
-conditions OR ((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 and OR
.
Your WHERE
-clause is now similar to:
(condition1 AND condition2 AND condition3 AND condition5 AND condition6)
OR condition4
I suppose, you actually mean something like:
condition1 AND condition2
AND (condition3 OR condition4)
AND condition5 AND condition6
I don not say your WHERE
-clause is wrong. I only suspect you need some extra brackets somewhere, to get the WHERE
-clause you had in mind.
But before adding brackets, let's remove some to improve readability. This will do the same as yours:
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)')
Upvotes: 2