Solved

SQL Server query issue using index hints

Posted on 2011-09-16
6
398 Views
Last Modified: 2012-05-12
On one server, using an index hint made the sql go very fast as expected.  So used the index hint.  But the same query, on another database server, performed much slower.  Funny thing was, when the index was removed, the query performed very fast. Why is that, and what can be done.  This is a conflicting behavior, how to solve this issue. Are there any other settings to look at, if any experts have seen this.
0
Comment
Question by:tapdev72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 125 total points
ID: 36551563
Try re-creating the index on the other server and see if it runs fast.  It may be that the index just needed to be rebuilt.
0
 
LVL 21

Assisted Solution

by:JestersGrind
JestersGrind earned 125 total points
ID: 36551579
Compare the execution plans look like on each server.  Do both servers have exactly the same indexes?  Is maintenance being performed on each server (i.e. rebuilding indexes, updating statistics)  If the proper indexes are in place and statistics are up to date, you shouldn't need index hints.

Greg

0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 125 total points
ID: 36552845
>>On one server, using an index hint made the sql go very fast as expected.  So used the index hint.<<
That is not a good enough reason.  Hints should only be used as a last resort for precisely the reason you have discovered.  Help the SQL optimizer by building efficient queries and don't force it to use an index that will make it grind to a halt.

>>Why is that, and what can be done.  <<
Don't use hints.  Optimize the query.

>>This is a conflicting behavior, how to solve this issue. <<
Not at all you just told the SQL optimizer to use a less than optimum plan when there were obviously better ones available.
0
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
LVL 18

Assisted Solution

by:ShogunWade
ShogunWade earned 125 total points
ID: 36554455
Agree with acperkins.   you should avoind using hints where possible.

Perhaps if you could post your query and provide some detail about the tables and indexes we could help you tune it?
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 36554858
> Perhaps you have a caching problem.  Free your cache to make sure you are not using an older plan.
> Double check your stats
> Determine the lock escalation level of the query on each server.  Make sure they are the same.
> Using hints makes troubleshooting easy only for the experienced.  You should avoid them if you do not have a complete knowledge of what they are doing exactly.
0
 

Author Comment

by:tapdev72
ID: 36898251
Thanks for the helpful hints.  After doing maintenance work - like recreating indexes, updating statistics, the need for the index hint does not arise.  
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question