Friday, February 24, 2012

logic error

Declare @.mx int
Set @.mx = (select max(score)
from ,,,
where ,,,,and
substring(city,1,1)='g')
select score,@.mx
from ,,,,
where ,,,, and
substring(city,1,1)='g')
group by score
go
this seems to work for small tables
but when table is big and substring(city,1,1)='g')
condition is not met it takes aweful time like goes
in an infinit loop.
--
Sent by 3 from yahoo part of com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.comthat's because substring(city,1,1)='g') forces a table scan even if there is
an index on city. the alternative is to use
city like 'g%'
--
-oj
RAC v2.2 & QALite!
http://www.rac4sql.net
"alexqa2003@.yahoo.com" <u128845214@.spawnkill.ip-mobilphone.net> wrote in
message news:l.1065831439.1981964111@.[63.127.215.130]...
> Declare @.mx int
> Set @.mx = (select max(score)
> from ,,,
> where ,,,,and
> substring(city,1,1)='g')
> select score,@.mx
> from ,,,,
> where ,,,, and
> substring(city,1,1)='g')
> group by score
> go
> this seems to work for small tables
> but when table is big and substring(city,1,1)='g')
> condition is not met it takes aweful time like goes
> in an infinit loop.
>
>
> --
> Sent by 3 from yahoo part of com
> This is a spam protected message. Please answer with reference header.
> Posted via http://www.usenet-replayer.com

No comments:

Post a Comment