dbTalk Databases Forums  

Index problem

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Index problem in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jan
 
Posts: n/a

Default Index problem - 02-13-2004 , 03:16 AM






Hi!

When we uses a search, where we use a expression for example (date >=
20040101)
The SQL-server 2000 doesn't use the indexes we have created.
Is there a problem using between values in a search?
Can I force the SQL-server to use a specific index?

Regards Jan Rockstedt




Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Index problem - 02-13-2004 , 03:48 AM






What does it do.

Do you an index on the column? if yes then Clus or NC?

If the Query would return a large proportion of the rows in the table then
it may simply choose to do a table scan.



--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote

Quote:
Hi!

When we uses a search, where we use a expression for example (date >=
20040101)
The SQL-server 2000 doesn't use the indexes we have created.
Is there a problem using between values in a search?
Can I force the SQL-server to use a specific index?

Regards Jan Rockstedt






Reply With Quote
  #3  
Old   
Jan
 
Posts: n/a

Default Re: Index problem - 02-13-2004 , 04:06 AM



We have a NC index on the column.

The table has approximate 2,3 million rows and we only seeks a small
proportion of the rows depending on date.

Regards Jan Rockstedt


Allan Mitchell wrote:
Quote:
What does it do.

Do you an index on the column? if yes then Clus or NC?

If the Query would return a large proportion of the rows in the table
then it may simply choose to do a table scan.




"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote in message
news:utoIUIh8DHA.2576 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi!

When we uses a search, where we use a expression for example (date >=
20040101)
The SQL-server 2000 doesn't use the indexes we have created.
Is there a problem using between values in a search?
Can I force the SQL-server to use a specific index?

Regards Jan Rockstedt




Reply With Quote
  #4  
Old   
Ray Higdon
 
Posts: n/a

Default Re: Index problem - 02-13-2004 , 05:05 AM



What are you returning? If you are saying "select date from table where
(date >=20040101)" Then it should use that index.

If you are saying "select column1,column2,column3..." then it might make
more sense to not access the index just to lookup and locate the other
values.

HTH

--
Ray Higdon MCSE, MCDBA, CCNA
---
"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote

Quote:
We have a NC index on the column.

The table has approximate 2,3 million rows and we only seeks a small
proportion of the rows depending on date.

Regards Jan Rockstedt


Allan Mitchell wrote:
What does it do.

Do you an index on the column? if yes then Clus or NC?

If the Query would return a large proportion of the rows in the table
then it may simply choose to do a table scan.




"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote in message
news:utoIUIh8DHA.2576 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi!

When we uses a search, where we use a expression for example (date >=
20040101)
The SQL-server 2000 doesn't use the indexes we have created.
Is there a problem using between values in a search?
Can I force the SQL-server to use a specific index?

Regards Jan Rockstedt






Reply With Quote
  #5  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Index problem - 02-13-2004 , 05:36 AM



So WHAT do you see the query doing?

Are you a performance hit?

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote

Quote:
We have a NC index on the column.

The table has approximate 2,3 million rows and we only seeks a small
proportion of the rows depending on date.

Regards Jan Rockstedt


Allan Mitchell wrote:
What does it do.

Do you an index on the column? if yes then Clus or NC?

If the Query would return a large proportion of the rows in the table
then it may simply choose to do a table scan.




"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote in message
news:utoIUIh8DHA.2576 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi!

When we uses a search, where we use a expression for example (date >=
20040101)
The SQL-server 2000 doesn't use the indexes we have created.
Is there a problem using between values in a search?
Can I force the SQL-server to use a specific index?

Regards Jan Rockstedt






Reply With Quote
  #6  
Old   
Jan
 
Posts: n/a

Default Re: Index problem - 02-24-2004 , 03:20 AM



We say "SELECT column1, column2,column3,....

FROM Table

WHERE date >= 20040101

AND date <= 20040201 "

When we do the select within a range like this, it does a table scan.

There is 2,3 million records in that table, the result will be between 500
to 2000 records.

Regards Jan Rockstedt


Ray Higdon wrote:
Quote:
What are you returning? If you are saying "select date from table
where (date >=20040101)" Then it should use that index.

If you are saying "select column1,column2,column3..." then it might
make more sense to not access the index just to lookup and locate the
other values.

HTH

We have a NC index on the column.

The table has approximate 2,3 million rows and we only seeks a small
proportion of the rows depending on date.

Regards Jan Rockstedt


Allan Mitchell wrote:
What does it do.

Do you an index on the column? if yes then Clus or NC?

If the Query would return a large proportion of the rows in the
table then it may simply choose to do a table scan.




"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote in message
news:utoIUIh8DHA.2576 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi!

When we uses a search, where we use a expression for example (date
= 20040101)
The SQL-server 2000 doesn't use the indexes we have created.
Is there a problem using between values in a search?
Can I force the SQL-server to use a specific index?

Regards Jan Rockstedt




Reply With Quote
  #7  
Old   
Ray Higdon
 
Posts: n/a

Default Re: Index problem - 02-24-2004 , 04:42 AM



You could put a covering nonclustered index on this. It will still do a
table scan but a much smaller one. Some people would argue to put the
clustered index on the date column, which you could but your logical IO
would probably be about the same.

--
Ray Higdon MCSE, MCDBA, CCNA
---
"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote

Quote:
We say "SELECT column1, column2,column3,....

FROM Table

WHERE date >= 20040101

AND date <= 20040201 "

When we do the select within a range like this, it does a table scan.

There is 2,3 million records in that table, the result will be between 500
to 2000 records.

Regards Jan Rockstedt


Ray Higdon wrote:
What are you returning? If you are saying "select date from table
where (date >=20040101)" Then it should use that index.

If you are saying "select column1,column2,column3..." then it might
make more sense to not access the index just to lookup and locate the
other values.

HTH

We have a NC index on the column.

The table has approximate 2,3 million rows and we only seeks a small
proportion of the rows depending on date.

Regards Jan Rockstedt


Allan Mitchell wrote:
What does it do.

Do you an index on the column? if yes then Clus or NC?

If the Query would return a large proportion of the rows in the
table then it may simply choose to do a table scan.




"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote in message
news:utoIUIh8DHA.2576 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi!

When we uses a search, where we use a expression for example (date
= 20040101)
The SQL-server 2000 doesn't use the indexes we have created.
Is there a problem using between values in a search?
Can I force the SQL-server to use a specific index?

Regards Jan Rockstedt






Reply With Quote
  #8  
Old   
JP
 
Posts: n/a

Default Re: Index problem - 02-24-2004 , 01:57 PM



"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote

Quote:
Hi!

When we uses a search, where we use a expression for example (date >=
20040101)
Do you say "date >= '20040101'" or do you say "date >= '@mydate'" ?

Depending on the context, the optimizer may not make a good decision
because it doesn't know the value of @mydate when it optimizes the
query plan. That's one possibility.

Quote:
Is there a problem using between values in a search?
Years ago there was reported to be an issue using ">" as opposed to
">=" but as far as I know it's no longer an issue.

Quote:
Can I force the SQL-server to use a specific index?
Yes. Try using an optimizer hint to specify the index and see if it
works better; then you can decide whether you want to leave the hint
or try to figure out why the optimizer figure it out by itself.
Despite the usual advice about not using optimizer hints, sometimes
SQL Server doesn't have enough info to do the job at the time it is
choosing its query plan so you have to help it:

SELECT * FROM table_name WITH (INDEX ( index_name ) )

JP


Reply With Quote
  #9  
Old   
Jan
 
Posts: n/a

Default Re: Index problem - 02-25-2004 , 02:22 AM



JP wrote:
Quote:
"Jan" <_NO_SPAM_ (AT) telia (DOT) com> wrote in message
news:<utoIUIh8DHA.2576 (AT) TK2MSFTNGP09 (DOT) phx.gbl>...
Hi!

When we uses a search, where we use a expression for example (date >=
20040101)

Do you say "date >= '20040101'" or do you say "date >= '@mydate'" ?

Depending on the context, the optimizer may not make a good decision
because it doesn't know the value of @mydate when it optimizes the
query plan. That's one possibility.

Is there a problem using between values in a search?

Years ago there was reported to be an issue using ">" as opposed to
">=" but as far as I know it's no longer an issue.

Can I force the SQL-server to use a specific index?

Yes. Try using an optimizer hint to specify the index and see if it
works better; then you can decide whether you want to leave the hint
or try to figure out why the optimizer figure it out by itself.
Despite the usual advice about not using optimizer hints, sometimes
SQL Server doesn't have enough info to do the job at the time it is
choosing its query plan so you have to help it:

SELECT * FROM table_name WITH (INDEX ( index_name ) )

JP
JP,

We use "date >= '@mydate'"

Thanks for the answer. :-)

//Jan




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.