mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 15:23:03 +01:00
Rework fix for #5751 (Available indices are not used in some cases if ORDER BY expression is a filtered one) and also attempt to fix the special case for OR conditions partially matched to an index
This commit is contained in:
parent
5167c588a4
commit
91dce62553
@ -1494,45 +1494,69 @@ InversionCandidate* Retrieval::makeInversion(InversionCandidateList& inversions)
|
|||||||
return invCandidate;
|
return invCandidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look if a match is already used by previous matches.
|
if (!customPlan)
|
||||||
bool anyMatchAlreadyUsed = false, matchUsedByNavigation = false;
|
|
||||||
for (const auto currentMatch : currentInv->matches)
|
|
||||||
{
|
{
|
||||||
if (matches.exist(currentMatch))
|
// Look if a match is already used by previous matches
|
||||||
{
|
bool anyMatchAlreadyUsed = false, matchUsedByNavigation = false;
|
||||||
anyMatchAlreadyUsed = true;
|
|
||||||
|
|
||||||
if (navigationCandidate &&
|
|
||||||
navigationCandidate->matches.exist(currentMatch))
|
|
||||||
{
|
|
||||||
matchUsedByNavigation = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentInv->boolean && matches.exist(currentInv->boolean))
|
|
||||||
anyMatchAlreadyUsed = true;
|
|
||||||
|
|
||||||
if (anyMatchAlreadyUsed && !customPlan)
|
|
||||||
{
|
|
||||||
currentInv->used = true;
|
|
||||||
|
|
||||||
if (matchUsedByNavigation)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// If a match on this index was already used by another
|
|
||||||
// index, add also the other matches from this index.
|
|
||||||
for (const auto currentMatch : currentInv->matches)
|
for (const auto currentMatch : currentInv->matches)
|
||||||
{
|
{
|
||||||
if (!matches.exist(currentMatch))
|
if (matches.exist(currentMatch))
|
||||||
matches.add(currentMatch);
|
{
|
||||||
|
anyMatchAlreadyUsed = true;
|
||||||
|
|
||||||
|
if (navigationCandidate &&
|
||||||
|
navigationCandidate->matches.exist(currentMatch))
|
||||||
|
{
|
||||||
|
matchUsedByNavigation = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart loop, because other indexes could also be excluded now.
|
if (const auto currentMatch = currentInv->boolean)
|
||||||
restartLoop = true;
|
{
|
||||||
break;
|
if (matches.exist(currentMatch))
|
||||||
|
{
|
||||||
|
anyMatchAlreadyUsed = true;
|
||||||
|
|
||||||
|
if (navigationCandidate &&
|
||||||
|
navigationCandidate->matches.exist(currentMatch))
|
||||||
|
{
|
||||||
|
matchUsedByNavigation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (matchUsedByNavigation)
|
||||||
|
anyMatchAlreadyUsed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If some match was already used by another index, skip this index
|
||||||
|
|
||||||
|
if (anyMatchAlreadyUsed)
|
||||||
|
{
|
||||||
|
if (!matchUsedByNavigation)
|
||||||
|
{
|
||||||
|
// Add the other matches from this index
|
||||||
|
|
||||||
|
for (const auto currentMatch : currentInv->matches)
|
||||||
|
{
|
||||||
|
if (!matches.exist(currentMatch))
|
||||||
|
matches.add(currentMatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (const auto currentMatch = currentInv->boolean)
|
||||||
|
{
|
||||||
|
if (!matches.exist(currentMatch))
|
||||||
|
matches.add(currentMatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restart loop, because other indexes could also be excluded now
|
||||||
|
currentInv->used = true;
|
||||||
|
restartLoop = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bestCandidate)
|
if (!bestCandidate)
|
||||||
|
Loading…
Reference in New Issue
Block a user