Biblioteca

How to calculate number of records using statistics value of the unique index

Firebird has a special parameter for every index, called "index statistics".
The statistics value is calculated as 1 divided by the number of unique keys in an index, e.g. for 100 records the statistics will be 1/100.
Firebird uses this value to estimate the quality of the specific index (i.e., to use or not to use it in the plan for the query).

This value is kept in the column RDB$STATISTICS in the system table RDB$INDICES, if you know the name of the index. you can get it

select rdb$statistics  as cnt  from rdb$indices where rdb$index_name='PK_USERS2PROJECTS'

If this index is unique (in this case it is primary key), we can use