I have a table with 240000 registers. This table is "fifluxoc"
If have these indexes for this table:
RDB$PRIMARY143 on fields "cod_estab,registro"
FIFLUXOC_ESTAB_DT_BAIXA_SIT_IDX on fields "COD_ESTAB,DATA_BAIXA,SITUACAO"
FIFLUXOC_ESTAB_DT_PREV_SIT_IDX on fileds "COD_ESTAB,DATA_PREVISTA,SITUACAO"
When I do this select:
select *
from fifluxoc
where cod_estab = :cod_estab_par and
registro = :registro_par
It is very slow, because they use the index FIFLUXOC_ESTAB_DT_PREV_SIT_IDX instead the PRIMARY KEY thai is the perfect index for this query.
So, I do this:
select *
from fifluxoc
where cod_estab = :cod_estab_par and
registro = :registro_par
PLAN( fifluxoc INDEX(RDB$PRIMARY143) )
In this time, it works very fast!!! Because I force the use of the correct index on the PLAN. But I cannot do it because if I do a backup-restore in my database the name "RDB$PRIMARY143" will be changed.
Why don't my query change the more approprieted index for the select? Why does it always select the FIFLUXOC_ESTAB_DT_PREV_SIT_IDX for all the querys? How can I do???
Thanks
regards,