dbTalk Databases Forums  

performance with dynamic variable...

comp.databases.sybase comp.databases.sybase


Discuss performance with dynamic variable... in the comp.databases.sybase forum.



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

Default performance with dynamic variable... - 03-27-2006 , 11:19 PM







Sybase 12.x on Linux. I am relatively new to Sybase.

I have a query q1 ( as part of a stored proc ):

declare @accountId int
set @accountId = 100
select col1, col2 from MyTable where accountId = @accountId

There is an index on "accountId". But this index is not used. Whereas it is
used in the query ( q2 ) below:

declare @accountId int
set @accountId = 100
declare @sqlSel varchar(1000)
set sqlSel = "select col1, col2 from MyTable where accountId = " +
@accountId
exec (@sqlSel)

I can see why the index is used in q2. But in q1, the optimizer knows that
"@accountId" has been declared as int - still it does not try to use the
index.

Is there anyway this can be solved ?

Thanks

-- padhu



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.