The largest data and database services provider in North America | Speak with Us
Database Performance and Row Size for DB2
Recently I was reading through some posts on a database-related blog or mailing list (actually, right now I can’t remember which one it was). The conversation I was reading was in response to this question: “Does the number of columns or size of the row matter in terms of performance?”
Actually, the question asked what kind of a performance impact might be expected if a query was issued against two similar tables. The first table had (say) 20 columns, and the second table had the same 20 columns, as well as 35 additional columns.
Well, most of the basic responses were similar. The consensus was that as long as the query was going against the same columns then performance should be about the same. I disagree. Here is why.
You also need to factor in the I/O requests that are required to return the data. The DBMS will perform I/O at the block (or page) level – this is so whether you return one row or millions of rows. For multi-row results, accessing data from the table with the wider row (more columns) will usually be less efficient. This is so because fewer rows will exist on each page (the row with 100 columns is smaller than the row with 150 columns so more rows can reside in a single, pre-sized block/page). The bigger the result set, the more pronounced the performance degradation can be (because more physical I/Os are required to retrieve the data).
Think about it this way. Is it faster to pull smaller peaches out of a basket than bigger peaches? That is about the same type of question and anybody can envision the process. Say you want 100 peaches. Small peaches fit 25 per basket; big peaches fit ten per basket. To get 100 small peaches you’d need to pull 4 baskets from the shelf. To get 100 big peaches you’d need to pull 10 baskets from the shelf. The second task will clearly take more time.
Of course, the exact performance difference is difficult to calculate – especially over an online forum and without knowledge of the specific DBMS being used, information about in-memory tactics and buffer pools, and the exact type of data and queries being used. But there will, more than likely, be a performance effect on queries when you add columns to a table.
This blog was originally published on Craig Mullins’ blog at: http://db2portal.blogspot.com/2008/09/database-performance-and-row-size.html