Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Rashmidharshan
Starting Member
2 Posts |
Posted - 2009-10-09 : 01:57:09
|
Hi All,I have a prepared statement which i execute through jdbc, it is a simpleselect statement with a few parameters in the IN clause. The execution of thisprepared statement is taking 3 seconds but if i execute the same querydirectly through jdbc itself it returns results immediately in fraction of asecond.The query is likeSelect info from MYTABLEwhere gid IN (?,?,?,?,....)The table i'm querying for has nonclustered unique index on gid andclustered index on 2 date fieldsI saw the execution plan for the direct execution and prepared execution.Direct execution does an index seek while prepared execution is doing atable scan.I'm using SQLServer 2005.Is there a way to prevent prepared queries from doing table scan whenindexes are present? Since these prepared statements are generated by our application using WITH (INDEX = index_on_gid) is not an option for meRashmi |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-09 : 04:26:08
|
I have no clue about that java stuff.But I have heard something like this in our company.The solution was to configure on the java-side (jdbc or ... don't know) because of the following:The searchvalue was given to the SQL Server in a wrong datatype so the index could not be used.Maybe that helps. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
Rashmidharshan
Starting Member
2 Posts |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-10 : 06:01:32
|
Glad that I could help! No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|