Re: Optimize A Simple Query -- Help
Posted in 1996
Chao Y. Din wrote:
>
> I have a simple select count statement that takes three minutes to
> execute, yet I only have about 300,0000 rows. Here is the SQL.
>
> SELECT COUNT(*) FROM table WHERE key[1,7] = "B02800A" AND col1 = 2010
>
> Is it possible to force the query to use index on key without dropping
> the composite index?
>
> Thanks in advance.
>
> Chao
Until the optimizer gets really smart, the following strategy seems to
work for eliminating consideration of an index:
select count(*) from table where key matches "B02800A*"
and (1=0 or col1=2010)
sometimes i've wished that the optimizer was smarter in cases where i'd
liked to have (1=? and col=?) type parameters, but it seems to work in
your favor for your case.
--
Sincerly,
Doug Wilson(dougw@amgen.com)
*** The opinions expressed here are my own and no one elses ****
*** Disclaimer: These are the opinions of the poster not Amgen Inc.***