mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-02-02 09:20:39 +01:00
Reworked my yesterday's commit re. empty tables and indices
This commit is contained in:
parent
252c5b2b2f
commit
022f092877
@ -898,17 +898,6 @@ void Retrieval::getInversionCandidates(InversionCandidateList& inversions,
|
|||||||
// Add matches for this segment to the main matches list
|
// Add matches for this segment to the main matches list
|
||||||
matches.join(segment.matches);
|
matches.join(segment.matches);
|
||||||
|
|
||||||
// When selectivity is zero the statement is prepared on an
|
|
||||||
// empty table or the statistics aren't updated.
|
|
||||||
// For an unique index, estimate the selectivity via the stream cardinality.
|
|
||||||
// For a non-unique one, assume 1/10 of the maximum selectivity, so that
|
|
||||||
// at least some indexes could be chosen by the optimizer.
|
|
||||||
if (scratch.selectivity <= 0)
|
|
||||||
{
|
|
||||||
scratch.selectivity = (unique && cardinality > MINIMUM_CARDINALITY) ?
|
|
||||||
1 / cardinality : DEFAULT_SELECTIVITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// An equality scan for any unique index cannot retrieve more
|
// An equality scan for any unique index cannot retrieve more
|
||||||
// than one row. The same is true for an equivalence scan for
|
// than one row. The same is true for an equivalence scan for
|
||||||
// any primary index.
|
// any primary index.
|
||||||
@ -1001,6 +990,19 @@ void Retrieval::getInversionCandidates(InversionCandidateList& inversions,
|
|||||||
{
|
{
|
||||||
double selectivity = scratch.selectivity;
|
double selectivity = scratch.selectivity;
|
||||||
|
|
||||||
|
// When the index selectivity is zero then the statement is prepared
|
||||||
|
// on an empty table or the statistics aren't updated. The priorly
|
||||||
|
// calculated selectivity is meaningless in this case. So instead:
|
||||||
|
// - for an unique match, estimate the selectivity via the stream cardinality;
|
||||||
|
// - for a non-unique one, assume 1/10 of the maximum selectivity, so that
|
||||||
|
// at least some indexes could be utilized by the optimizer.
|
||||||
|
if (idx->idx_selectivity <= 0)
|
||||||
|
{
|
||||||
|
selectivity = unique ?
|
||||||
|
MIN(MAXIMUM_SELECTIVITY / cardinality, DEFAULT_SELECTIVITY) :
|
||||||
|
DEFAULT_SELECTIVITY;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the cost (only index pages) for this index
|
// Calculate the cost (only index pages) for this index
|
||||||
auto cost = DEFAULT_INDEX_COST + selectivity * scratch.cardinality;
|
auto cost = DEFAULT_INDEX_COST + selectivity * scratch.cardinality;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user