8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 10:40:38 +01:00

Fixed inconsistency between unique vs non-unique retrievals (see CORE-4702).

This commit is contained in:
dimitr 2015-03-06 14:04:07 +00:00
parent 12da25ce6d
commit a14e993fbe

View File

@ -240,10 +240,10 @@ IndexScratch::IndexScratch(MemoryPool& p, thread_db* tdbb, index_desc* ix,
// We assume that the average index-key can be compressed by a factor 0.5
// In the future the average key-length should be stored and retrieved
// from a system table (RDB$INDICES for example).
// Multipling the selectivity with this cardinality gives the estimated
// Multiplying the selectivity with this cardinality gives the estimated
// number of index pages that are read for the index retrieval.
double factor = 0.5;
if (segments.getCount() >= 2)
if (segments.getCount() > 1)
{
// Compound indexes are generally less compressed.
factor = 0.7;
@ -986,7 +986,7 @@ void OptimizerRetrieval::getInversionCandidates(InversionCandidateList* inversio
invCandidate->unique = unique;
invCandidate->selectivity = selectivity;
// Calculate the cost (only index pages) for this index.
invCandidate->cost = DEFAULT_INDEX_COST - 1 + scratch.selectivity * scratch.cardinality;
invCandidate->cost = DEFAULT_INDEX_COST + scratch.selectivity * scratch.cardinality;
invCandidate->nonFullMatchedSegments = scratch.nonFullMatchedSegments;
invCandidate->matchedSegments = MAX(scratch.lowerCount, scratch.upperCount);
invCandidate->indexes = 1;
@ -1589,7 +1589,7 @@ InversionCandidate* OptimizerRetrieval::makeInversion(InversionCandidateList* in
invCandidate = FB_NEW(pool) InversionCandidate(pool);
invCandidate->selectivity *= navigationCandidate->selectivity;
invCandidate->cost += DEFAULT_INDEX_COST - 1 +
invCandidate->cost += DEFAULT_INDEX_COST +
navigationCandidate->cardinality * navigationCandidate->selectivity;
++invCandidate->indexes;
invCandidate->navigated = true;