@@ -1249,12 +1249,16 @@ InversionCandidate* OptimizerRetrieval::makeInversion(InversionCandidateList* in
12491249 inversion[i]->used = false ;
12501250 const IndexScratch* const indexScratch = inversion[i]->scratch ;
12511251
1252- if (indexScratch && (indexScratch->idx ->idx_runtime_flags & idx_plan_dont_use))
1252+ if (indexScratch &&
1253+ (indexScratch == navigationCandidate ||
1254+ (indexScratch->idx ->idx_runtime_flags & idx_plan_dont_use)))
1255+ {
12531256 inversion[i]->used = true ;
1257+ }
12541258 }
12551259
12561260 // The matches returned in this inversion are always sorted.
1257- SortedArray<BoolExprNode*> matches;
1261+ SortedArray<BoolExprNode*> matches, navigationMatches ;
12581262
12591263 if (navigationCandidate)
12601264 {
@@ -1269,11 +1273,13 @@ InversionCandidate* OptimizerRetrieval::makeInversion(InversionCandidateList* in
12691273
12701274 for (FB_SIZE_T j = 0 ; j < segment->matches .getCount (); j++)
12711275 {
1272- if (!matches .exist (segment->matches [j]))
1273- matches .add (segment->matches [j]);
1276+ if (!navigationMatches .exist (segment->matches [j]))
1277+ navigationMatches .add (segment->matches [j]);
12741278 }
12751279 }
12761280
1281+ matches.join (navigationMatches);
1282+
12771283 // If the navigational candidate includes any matching segments,
12781284 // reset the selectivity/cost prerequisites to account these matches
12791285 if (matchedSegments)
@@ -1338,19 +1344,23 @@ InversionCandidate* OptimizerRetrieval::makeInversion(InversionCandidateList* in
13381344 }
13391345
13401346 // Look if a match is already used by previous matches.
1341- bool anyMatchAlreadyUsed = false ;
1347+ bool anyMatchAlreadyUsed = false , matchUsedByNavigation = false ;
13421348 for (FB_SIZE_T k = 0 ; k < currentInv->matches .getCount (); k++)
13431349 {
13441350 if (matches.exist (currentInv->matches [k]))
13451351 {
13461352 anyMatchAlreadyUsed = true ;
1353+ if (navigationMatches.exist (currentInv->matches [k]))
1354+ matchUsedByNavigation = true ;
13471355 break ;
13481356 }
13491357 }
13501358
13511359 if (anyMatchAlreadyUsed && !customPlan)
13521360 {
13531361 currentInv->used = true ;
1362+ if (matchUsedByNavigation)
1363+ continue ;
13541364 // If a match on this index was already used by another
13551365 // index, add also the other matches from this index.
13561366 for (FB_SIZE_T j = 0 ; j < currentInv->matches .getCount (); j++)
0 commit comments