Subject | Re: Plan shows 3 indexes used for a simple STARTING WITH clause |
---|---|
Author | amoradell |
Post date | 2007-11-02T10:19:50Z |
Hi,
1) Try use KBST.ID field in your query.
select count(*) from kbst
where br starting with 'K2' and id between 1 and 999999
and see if he uses RDB$PRIMARY39
2) or add KBST.SR field with the same approach
and sr between 'A' and 'ZZZZZ'
Regards
Alexandre
--- In firebird-support@yahoogroups.com, Milan Babuskov <milanb@...>
wrote:
1) Try use KBST.ID field in your query.
select count(*) from kbst
where br starting with 'K2' and id between 1 and 999999
and see if he uses RDB$PRIMARY39
2) or add KBST.SR field with the same approach
and sr between 'A' and 'ZZZZZ'
Regards
Alexandre
--- In firebird-support@yahoogroups.com, Milan Babuskov <milanb@...>
wrote:
>IDX_KBST1 is
> Hi,
>
> Firebird 1.5.3 Classic on Linux
>
> I got this simple STARTING WITH query:
>
> SQL> set planonly;
> SQL> select count(*) from kbst where br starting with 'K2';
>
> PLAN (KBST INDEX (RDB$FOREIGN231,RDB$PRIMARY39,IDX_KBST1))
>
> SQL> show index kbst;
> IDX_KBST1 INDEX ON KBST(BR, SR)
> RDB$FOREIGN231 INDEX ON KBST(BR)
> RDB$FOREIGN232 INDEX ON KBST(SR)
> RDB$PRIMARY39 UNIQUE INDEX ON KBST(BR, ID)
>
> Is Firebird really going to read all three indexes?
>
> I'd remove some, but of those 4 indexes, 3 are used by PK/FK
> constraints. IDX_KBST1 is the only candidate, but I have a lot of:
>
> WHERE BR = ? and SR = ?
>
> queries in many places in application (and selectivity for
> much better than RDB$FOREIGN231 or 232).
>
>
> Thanks,
> --
> Milan Babuskov
> http://www.flamerobin.org
>