Skip to content

Performance degradation after ALTER INDEX ... ACTIVE #8778

@RaulWW

Description

@RaulWW

A significant performance degradation was observed after executing ALTER INDEX ... ACTIVE on all indexes of a Firebird database.

Before activating the indexes (right after a backup/restore), the query ran normally and used an efficient plan.

After running ALTER INDEX ... ACTIVE for all indexes, the same query became ~40x slower and started using a completely different, suboptimal plan.

Environment

  • Firebird version: 5.0.3
  • OS: Windows 11
    *Database size: 22GB

Query used:
select first 1 count (NF.NFS) as REGISTROS,
NF.STATUS_NFE
from NF_SAIDA NF
join OPERACOES_FISCAIS OP
on NF.EMPRESA = OP.EMPRESA
and NF.OPF_CODIGO = OP.OPF_CODIGO
where NF.EMPRESA = 1
and (NF.DT_EMISSAO between '01.10.2025' and current_date)
and NF.DT_CANCELAMENTO is null
and (NF.STATUS_NFE is null or NF.STATUS_NFE in ('AA','AS','RE'))
and NF.STATUS <> 1
and OP.TIPO_DOCTO = 1
group by NF.STATUS_NFE
order by REGISTROS desc;

Result AFTER runnig activate all index

Plan
PLAN SORT (SORT (JOIN (OP NATURAL, NF INDEX (IDX_NFS_NFS))))

------ Performance info ------
Prepare time = 0ms
Execute time = 38s 954ms
Current memory = 7.427.312
Max memory = 7.454.928
Memory buffers = 256
Reads from disk to cache = 1.810.885
Writes from cache to disk = 0
Fetches from cache = 28.945.697


Result BEFORE and same result using using FB 3.0 (even if active all index, FB 3.0 mantain the same performance);

Plan
PLAN SORT (SORT (JOIN (OP NATURAL, NF INDEX (FK_NFS_OPERACAO))))

------ Performance info ------
Prepare time = 0ms
Execute time = 2s 828ms
Current memory = 3.819.120
Max memory = 6.291.408
Memory buffers = 256
Reads from disk to cache = 161.028
Writes from cache to disk = 0
Fetches from cache = 2.421.604

@dyemanov already have a sample database;

Question

Is this behavior expected?
After activating all indexes, the optimizer seems to choose a clearly worse plan, resulting in a huge performance drop, even though the dataset and query remain identical.

Additional notes

The query results are identical in both scenarios.
The only change was executing ALTER INDEX ... ACTIVE.
After activation, the optimizer consistently picks a different and much slower index.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions