FIX: Cardinality Estimation of ISNULL Function Does Not Account for Null Values (326314)



The information in this article applies to:

  • Microsoft SQL Server 2000 (all editions)

This article was previously published under Q326314
BUG #: 360172 (SHILOH_BUGS)

SYMPTOMS

A query that uses the ISNULL function for a predicate on a column with statistics may result in:
  • Poor estimation by the optimizer.

    -and-

  • Suboptimal query performance.
When you review the execution plan, you may find that the EstimateRows value is off by an order of magnitude from the Rows value.

CAUSE

If the optimizer uses the statistics on the column in the ISNULL predicate, it may result in a poor estimate in the number of rows that qualify, and may result in suboptimal query performance.

The following is an example of the affect on the row estimate for a query in which the optimizer used statistics on the column in the ISNULL predicate:
Rows     EstimateRows     Plan
4302     1.0             |--Table Scan(OBJECT:([pubs].[dbo].[Table1]), WHERE:(isnull([Table1].[col1], 10)>=10))  
In the next example, with AUTO_CREATE_STATISTICS set off, the estimate is much closer to the number of rows that actually match:
Rows     EstimateRows    Plan
4320     1363.8
|--Table Scan(OBJECT:([pubs].[dbo].[Table1]), WHERE:(isnull([Table1].[col1], 10)>=10))

RESOLUTION

To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

290211 INF: How To Obtain the Latest SQL Server 2000 Service Pack

NOTE: The following hotfix was created before the release of Microsoft SQL Server 2000 Service Pack 3.

The English version of this fix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date       Time       Version    Size              File name
   ---------------------------------------------------------------

   07/11/02   20:31:59   8.00.658   7,467,089 bytes   Sqlservr.exe
NOTE: Because of file dependencies, the most recent hotfix or feature that contains the files may also contain additional files.


STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
This problem was first corrected in Microsoft SQL Server 2000 Service Pack 3.

Modification Type:MinorLast Reviewed:9/27/2005
Keywords:kbHotfixServer kbQFE kbbug kbfix kbSQLServ2000preSP3fix kbSQLServ2000sp3fix KB326314