Home > Archive > Sybase Database > March 2006 > performance with dynamic variable...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author performance with dynamic variable...
Padhu Vinirs

2006-03-28, 3:23 am


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


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com