开发者

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

开发者 https://www.devze.com 2023-01-10 13:29 出处:网络
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?

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 t开发者_StackOverflow社区he board for LINQ to SQL, LINQ to Entities, LINQ to Objects, etc, etc.

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


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 everything SQL -- it depends.

If you have a small table it doesnt really matter (todays value for "small" is < 3000 rows).

If your query is going to return more than 30% of the rows in a table then it will probably be quicker without an index.

However if you want to select one or two particular rows from a large table then indexing some of the columns you use in the where statement (the search arguments you pass to LINQ) will speed thing up considerably.

Also if you frequntly join tables than the join predicates (the columns used in the "ON" statement for the joined to table) should be indexed. This can reduce the response time on some queries from hours to seconds.


It could improve performance if you index correctly. LINQ just generates a SQL statment behind the scenes... if the statement makes use of your index, then it will improve performance... if it doesn't then it won't.


In order to improve performance, indexing should be used smartly. E.g. you should index the key columns you are querying by or joining by.

http://www.sql-server-performance.com/tips/optimizing_indexes_general_p1.aspx

Indexing would typically improve select request performance, but slightly increase insert and update times, since the index has to be re-calculated.


LINQ to SQL generate a SQL statement, you can see this statement in different utilities like Linq pad. When you query will run in SQL Server the indexes will definitely improve performance.

  • will indexing improve performanc - Yes.
  • how will it improve performance - Read about Indexes.
  • why will it improve performance?- I really don't have answer of this question.

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.

Answer of this is what is the relation of SQL table with an Object?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号