Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will indexing a SQL table improve the performance of a LINQ statement?

Apologies for what may very well be a stupid question.

I'm just intrigued as to (a) will indexing improve performance (b) how will it improve performance and (c) why will it improve performance?

Also, if this does improve performance, would this be the case across the board for LINQ to SQL, LINQ to Entities, LINQ to Objects, etc, etc.

Again, if this is a really stupid question, I do apologise.

like image 801
Ricardo Deano Avatar asked Aug 05 '10 09:08

Ricardo Deano


1 Answers

It will improve the performance if, and only if, your LINQ query causes an SQL statement to be executed which can make use of the index - since, when using Linq-To-Sql, your LINQ query is translated to an SQL statement (hence the name).

For example, the following query would obviously benefit from an index on the LastName column of the Customers table.

var results = from c in db.Customers
    where c.LastName == 'Smith'
    select c;
like image 79
Winston Smith Avatar answered Sep 28 '22 22:09

Winston Smith