mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 22:43:03 +01:00
simplify code and some cosmetic changes
This commit is contained in:
parent
7ac89419e2
commit
9ae0b6d273
@ -1369,7 +1369,11 @@ InversionCandidate* OptimizerRetrieval::getInversion(RecordSource** rsb)
|
||||
*
|
||||
**************************************
|
||||
*
|
||||
* Functional description
|
||||
* Return an inversionCandidate which
|
||||
* contains a created inversion when a
|
||||
* index could be used.
|
||||
* This function should always return
|
||||
* an InversionCandidate;
|
||||
*
|
||||
**************************************/
|
||||
createIndexScanNodes = true;
|
||||
@ -2478,6 +2482,7 @@ void OptimizerInnerJoin::calculateStreamInfo()
|
||||
innerStreams[i]->baseIndexes = candidate->indexes;
|
||||
innerStreams[i]->baseUnique = candidate->unique;
|
||||
innerStreams[i]->baseConjunctionMatches = candidate->matches.getCount();
|
||||
delete candidate;
|
||||
delete optimizerRetrieval;
|
||||
|
||||
csb_tail->csb_flags &= ~csb_active;
|
||||
@ -2577,15 +2582,15 @@ bool OptimizerInnerJoin::estimateCost(USHORT stream, double *cost,
|
||||
// Create the optimizer retrieval generation class and calculate
|
||||
// which indexes will be used and the total estimated
|
||||
// selectivity will be returned.
|
||||
InversionCandidate* inversionNew = NULL;
|
||||
InversionCandidate* candidate = NULL;
|
||||
OptimizerRetrieval* optimizerRetrieval = FB_NEW(pool)
|
||||
OptimizerRetrieval(pool, optimizer, stream, false, false, NULL);
|
||||
inversionNew = optimizerRetrieval->getCost();
|
||||
double selectivity = inversionNew->selectivity;
|
||||
if (inversionNew->indexes) {
|
||||
candidate = optimizerRetrieval->getCost();
|
||||
double selectivity = candidate->selectivity;
|
||||
if (candidate->indexes) {
|
||||
const double nodesPerPage = ((double)database->dbb_page_size / 10);
|
||||
const double indexCost = 2 + ((cardinality * selectivity) / nodesPerPage);
|
||||
*cost = (cardinality * selectivity) + (inversionNew->indexes * indexCost);
|
||||
*cost = (cardinality * selectivity) + (candidate->indexes * indexCost);
|
||||
}
|
||||
else {
|
||||
*cost = cardinality;
|
||||
@ -2593,15 +2598,15 @@ bool OptimizerInnerJoin::estimateCost(USHORT stream, double *cost,
|
||||
|
||||
cardinality *= selectivity;
|
||||
|
||||
if (inversionNew->unique) {
|
||||
if (candidate->unique) {
|
||||
*resulting_cardinality = cardinality;
|
||||
}
|
||||
else {
|
||||
*resulting_cardinality = MAX(cardinality, 1.0);
|
||||
}
|
||||
|
||||
const bool useIndexRetrieval = (inversionNew->indexes >= 1);
|
||||
delete inversionNew;
|
||||
const bool useIndexRetrieval = (candidate->indexes >= 1);
|
||||
delete candidate;
|
||||
delete optimizerRetrieval;
|
||||
|
||||
return useIndexRetrieval;
|
||||
@ -2864,6 +2869,7 @@ void OptimizerInnerJoin::getIndexedRelationship(InnerJoinStreamInfo* baseStream,
|
||||
baseStream->indexedRelationships.insert(index, indexRelationship);
|
||||
testStream->previousExpectedStreams.add(baseStream->stream);
|
||||
}
|
||||
delete candidate;
|
||||
delete optimizerRetrieval;
|
||||
|
||||
csb_tail->csb_flags &= ~csb_active;
|
||||
|
@ -3298,6 +3298,7 @@ static void find_index_relationship_streams(thread_db* tdbb,
|
||||
if (candidate->dependentFromStreams.getCount() >= 1) {
|
||||
indexed_relationship = true;
|
||||
}
|
||||
delete candidate;
|
||||
delete optimizerRetrieval;
|
||||
}
|
||||
else {
|
||||
@ -4534,7 +4535,8 @@ static RecordSource* gen_outer(thread_db* tdbb,
|
||||
gen_retrieval(tdbb,
|
||||
opt,
|
||||
stream_i.stream_num,
|
||||
sort_clause,
|
||||
NULL, // AB: the sort clause for the inner stream of an
|
||||
// OUTER JOIN is never usefull for index retrieval.
|
||||
project_clause,
|
||||
bOuter,
|
||||
true,
|
||||
@ -4739,28 +4741,17 @@ static RecordSource* gen_retrieval(thread_db* tdbb,
|
||||
|
||||
Database* dbb = tdbb->tdbb_database;
|
||||
const bool ods11orHigher = (dbb->dbb_ods_version >= ODS_VERSION11);
|
||||
if (ods11orHigher) {
|
||||
if (ods11orHigher && !relation->rel_file) {
|
||||
// For ODS11 and higher databases we can use new calculations
|
||||
|
||||
InversionCandidate* inversionNew = NULL;
|
||||
InversionCandidate* candidate = NULL;
|
||||
OptimizerRetrieval* optimizerRetrieval = FB_NEW(*tdbb->getDefaultPool())
|
||||
OptimizerRetrieval(*tdbb->getDefaultPool(), opt, stream, outer_flag, inner_flag, sort_ptr);
|
||||
if (relation->rel_file) {
|
||||
rsb = EXT_optimize(opt, stream, sort_ptr ? sort_ptr : project_ptr);
|
||||
}
|
||||
else {
|
||||
inversionNew = optimizerRetrieval->getInversion(&rsb);
|
||||
candidate = optimizerRetrieval->getInversion(&rsb);
|
||||
if (candidate && candidate->inversion) {
|
||||
inversion = candidate->inversion;
|
||||
}
|
||||
delete candidate;
|
||||
delete optimizerRetrieval;
|
||||
|
||||
if (inversionNew && inversionNew->inversion) {
|
||||
inversion = inversionNew->inversion;
|
||||
delete inversionNew;
|
||||
}
|
||||
else {
|
||||
inversion = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
else if (relation->rel_file) {
|
||||
// External
|
||||
|
Loading…
Reference in New Issue
Block a user