Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/246474

From BetaArchive Wiki
Knowledge Base


FIX: Optimizer Chooses Inefficient Clustered Index on Query with Date Range Condition

Article ID: 246474

Article Last Modified on 3/14/2006



APPLIES TO

  • Microsoft SQL Server 7.0 Standard Edition



This article was previously published under Q246474

BUG #: 56775 (SQLBUG_70)

SYMPTOMS

When executing a query with a WHERE clause that references a date column that has a clustered index and any other column having a non-clustered index, SQL Server may choose an inefficient clustered index resulting in excessive response time to the user.

The optimizer chooses an inefficient clustered index. Forcing a non-clustered index gives much better performance in a simple SELECT statement with 2 search arguments (SARGs), one of which is a DATE range.

If a table has a clustered index on date column (column1) and non-clustered index on any other column (column2) and you perform a simple SELECT on the table with WHERE condition BETWEEN date range (column1) AND column2 = 'value' like this:

select *  from table1
where column1 between 'date1' and 'date2' and column2 = 'value'
                

The optimizer choses the clustered index on column1 even though use of a non-clustered index on column2 gives better performance. That is, less CPU time and logical reads.

WORKAROUND

Force the non-clustered index using a table hint.

STATUS

Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0


For more information, contact your primary support provider.

Keywords: kbbug kbfix KB246474