8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 09:20:39 +01:00

Let optimizer automatically update empty index statistics for relatively small system tables.

This commit is contained in:
Vlad Khorsun 2024-03-21 12:16:37 +02:00
parent bd00da8262
commit f2b281d05b

View File

@ -1119,6 +1119,33 @@ void Optimizer::compileRelation(StreamType stream)
IndexDescList idxList;
BTR_all(tdbb, relation, idxList, relPages);
// if index stats is empty, update it for non-empty and not too big system relations
const bool updateStats = (relation->isSystem() && idxList.hasData() &&
!tdbb->getDatabase()->readOnly() &&
(relPages->rel_data_pages > 0) && (relPages->rel_data_pages < 100));
if (updateStats)
{
bool updated = false;
for (const index_desc& idx : idxList)
{
if (idx.idx_selectivity == 0.0f)
{
SelectivityList selectivity;
BTR_selectivity(tdbb, relation, idx.idx_id, selectivity);
if (selectivity[0] != 0.0f)
updated = true;
}
}
if (updated)
{
idxList.clear();
BTR_all(tdbb, relation, idxList, relPages);
}
}
if (idxList.hasData())
tail->csb_idx = FB_NEW_POOL(getPool()) IndexDescList(getPool(), idxList);