From ebcd4dde644fbf886dcf191b61eeadf72bec74dd Mon Sep 17 00:00:00 2001 From: Dmitry Yemanov Date: Mon, 11 Mar 2024 10:19:49 +0300 Subject: [PATCH] Better (methinks) inversion choice when the OR condition includes a node which is also matched directly --- src/jrd/optimizer/Retrieval.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/jrd/optimizer/Retrieval.cpp b/src/jrd/optimizer/Retrieval.cpp index 019c31fcb9..e5acca5d36 100644 --- a/src/jrd/optimizer/Retrieval.cpp +++ b/src/jrd/optimizer/Retrieval.cpp @@ -1393,19 +1393,35 @@ InversionCandidate* Retrieval::makeInversion(InversionCandidateList& inversions) // Look if a match is already used by previous matches. bool anyMatchAlreadyUsed = false, matchUsedByNavigation = false; - for (const auto currentMatch : currentInv->matches) + if (currentInv->boolean) { - if (matches.exist(currentMatch)) + if (matches.exist(currentInv->boolean)) { anyMatchAlreadyUsed = true; if (navigationCandidate && - navigationCandidate->matches.exist(currentMatch)) + navigationCandidate->matches.exist(currentInv->boolean)) { matchUsedByNavigation = true; } + } + } + else + { + for (const auto currentMatch : currentInv->matches) + { + if (matches.exist(currentMatch)) + { + anyMatchAlreadyUsed = true; - break; + if (navigationCandidate && + navigationCandidate->matches.exist(currentMatch)) + { + matchUsedByNavigation = true; + } + + break; + } } }