Thursday, June 2, 2011

The power of Basics, LINQ

Few days back I needed to write a small utility program in C# to update few million (91 to be exact) records in a table.

I thought it is fairly straight forward, single user, single connection application scenario hence I used WPF and Linq to do the job.

First run and updated record number started to fly like Jet. In a minute or two it processed entire table (yes! With 91 Million records). I was surprised to see that kind of performance.

Then I want to check database to check updated records, there were none

I was scratching my head for a while and it occurred to me that there may be some problem in table structure; hence I checked table structure, to my surprise there was no primary key defined (no wonder it got processed so fast !!!).

I requested that change to our DBA, and updated code accordingly, and I started the program again

Now I started to get more believable numbers (like 200 - 500 records / second)

Lesson learned:
  • Do not assume that input supplied to you (the table in this case) is correct; Verify it before you start processing it.
  • If there is no primary key defined in the table, given table will not update any rows (and it will not complaint either)

No comments:

Post a Comment