linq performance: linq vs t-sql -- where does the time go? -
I am now testing Linq demo and I do not know that for some time (MS SQL Server 2005 ) Is in vain.
So what do I have here: a table with clustered and non-clustered index, all searches are done using columns, which are included in the 100% non-clustered index . I have 10 000 records, and all actions touch all the records one by one. Now and the bar:
T-SQL:
- < Li> Check whether each record exists (if existing ...); Yes, it exists - 0:30 (30 seconds)
- Updating each record - 1:16
LINQ:
LINQ (fetch) + TSQL (update) & lt; LINQ (Update)
Also keep in mind that the actual update is faster than bringing the part alone!
The update in LINQ is not already optimized for using the primary (cluster) index table (WHERE block).
So, where were 2 minutes gone?
edit
Please reply on the answer Question: Why is the difference between LINQ and TSQL? Please do not discuss the subject: TSQL is for the set, you should do it in a batch (all records at one time), you should do the TSQL faster. The structure of the table is very simple: ID (PK), name (int, external index), bit field +
edit2:
40 fields or somethingI run such loops to focus on a specific query:
declare @i int; @nr int declared; Announce @ P1 Bit; Declared @ p int; Set @i = 0; Set @ nr = 1000000000; While @I & lt; Select 10000 @ p0 = id, @ p1 = bit_field from test_mono where name = @ nr; Set @ P1 = 1- @ P1; Update test_mono set bit_field = @ p1 where id = @ p0; Set @i = @ I + 1; Set @ nr = @ nr-1; End
A little comment on that: bit_field here assures me that there will be modifiers to make sure. The counters that go up and down are from the actual data, I have to ensure that I get a record with each selection. And the last one - the only difference with LINQ is the selection, I get all the fields (updates are copied and pasted), though I can take the time of LINQ SELECT and add it to this time (TSQL) and I should get LINQ SELECT + UPDATE. But I did not get the time.
With the last edit I describe a slightly different structure, the reason is that I try to make it as clear as possible. I do not like examples of serious cases, so I will try to simplify things for readers; -)
You can start by using a tool such as actual SQL queries executed by LINQ is being done.
Personally, however, I have seen this time and time again, in this way, when I am the top priority, then I remain with TSQL.
There are more abnormalities than the SQL that are generated
Comments
Post a Comment