Excessive number of rows returned

The excessive number of rows returned warning is generated from the profiler when a query is returning a large number of rows. The simplest scenario is that we loaded all the rows in a large table, using something like the following code snippet:

var allPosts = blogDataContext.Posts.ToList();

This is a common mistake when you are binding to a UI component (such as a grid) that performs its own paging. This is a problem on several levels:

  • We tend to want to see only part of the data
  • We just loaded a whole lot of unnecessary data
  • We are sending more data than necessary over the network
  • We have a higher memory footprint than we should
  • In extreme cases, we may crash as a result of an out of memory exception

None of these are good, and like the discussion on unbounded result sets, this problem can be easily prevented by applying a limit at the database level to the number of rows that we want to load at any given time.

Last update: 11/13/2009 8:00:49 AM