Subject Plan shows 3 indexes used for a simple STARTING WITH clause
Author Milan Babuskov
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 IDX_KBST1 is
much better than RDB$FOREIGN231 or 232).


Thanks,
--
Milan Babuskov
http://www.flamerobin.org