How does DataView.RowFilter works?
-
Hi, I have a DataTable that has a primary key. If I want to find a row by primary key I can use
DataTable.Rows.Find (new object [] {id})
, or I can perform a row filter likeMytable.DefaultView.RowFilter = "ID = " + id
. It looks like RowFilter is MUCH slower than Find. Any idea why? Does RowFilter perform a linear search and Find does some binary search? Thanks Best regards, Alexandru Savescu P.S. Interested in art? Visit this! -
Hi, I have a DataTable that has a primary key. If I want to find a row by primary key I can use
DataTable.Rows.Find (new object [] {id})
, or I can perform a row filter likeMytable.DefaultView.RowFilter = "ID = " + id
. It looks like RowFilter is MUCH slower than Find. Any idea why? Does RowFilter perform a linear search and Find does some binary search? Thanks Best regards, Alexandru Savescu P.S. Interested in art? Visit this!I have discovered the same thing. In a test application that I created the results were REALLY unbelievable. The thing that I did was: 1. Connect to SQL Server 2. Use Northwind as Initial Catalog 3. Filled the dataset with Customers table records After using DataTable.Rows.Find("MORGK"), the time taken was 40 milliseconds After using DataTable.DefaultView.Find("MORGK"), the time taken was 0(?) :wtf: milliseconds but the record index was correctly found and the return value was 51. After using DataView.RowFilter the time taken was 70 milliseconds. And then, going through the documentation, DataTable.Rows.Find() uses PrimaryKey to locate the record. There was nothing like this for RowFilter so my assumption is that DataView uses an approach like Table Scan which means that PrimaryKey is completely ignored. Also, DataView constantly monitors for new rows and if it matches the criteria it is automatically available in the DataView. I guess this could be a sort of explanation. Husein