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

ID: Q246474


The information in this article applies to:
  • Microsoft SQL Server version 7.0

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 will choose clustered index on column1 even though use of 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 version 7.0.

Additional query words:

Keywords : kbbug7.00 kbSQLServ700bug
Version : winnt:7.0
Platform : winnt
Issue type : kbbug


Last Reviewed: January 7, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.