8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:43:02 +01:00

Merge pull request #8057 from FirebirdSQL/work/auto-update-empty-stats

Let optimizer automatically update empty index statistics for relatively small system tables
This commit is contained in:
Vlad Khorsun 2024-03-22 10:46:16 +02:00 committed by GitHub
commit ef66a9b4d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1111,6 +1111,9 @@ void Optimizer::compileRelation(StreamType stream)
const auto relation = tail->csb_relation;
fb_assert(relation);
const auto format = CMP_format(tdbb, csb, stream);
tail->csb_cardinality = getCardinality(tdbb, relation, format);
tail->csb_idx = nullptr;
if (needIndices && !relation->rel_file && !relation->isVirtual())
@ -1119,15 +1122,39 @@ 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);
if (tail->csb_plan)
markIndices(tail, relation->rel_id);
}
const auto format = CMP_format(tdbb, csb, stream);
tail->csb_cardinality = getCardinality(tdbb, relation, format);
}