all groups > sql server (microsoft) > november 2003 >
You're in the

sql server (microsoft)

group:

Table scan occurs when there is an index


Table scan occurs when there is an index itamar NO[at]SPAM xor.co.il
11/18/2003 7:27:50 AM
sql server (microsoft):
select * from table2
where Date2 = '10-12-2003 12:00:00'

Using the query analyzer "Display Estimated Execution Plan" shows a
table scan will occur (and running the query takes a long time).

The problem is - there is only 1 index on the table, a primary index
on Date2 field.

To make things more interesting, the following 'identical' query runs
in a second using the primary index (as indicated in its "Estimated
Execution Plan").

select * from table2
where Date2 = '10-11-2003 12:00:00'


The table:
Create table table2 (
date2 smalldatetime null,
value1 char(8) collate SQL_Latin1_General_CP1_CI_AS null,
value2 int null,
value3 bigint null,
value4 float null
) on primary

The index:
Create index ix_table2_date2 on dbo.table2(date2) with fillfactor=90
on primary

Product Version 9.00.384 (SP1)
Re: Table scan occurs when there is an index Niall Litchfield
11/19/2003 2:22:09 PM
It isn't identical, the date is different. Take a look at the distribution
of your data.

--
Niall Litchfield
Oracle DBA
Audit Commission UK
[quoted text, click to view]

Re: Table scan occurs when there is an index Greg D. Moore (Strider)
11/21/2003 5:15:10 AM

[quoted text, click to view]

Also, do an update statistics on the table.

[quoted text, click to view]

AddThis Social Bookmark Button