Skip to content

Commit 6c0d61b

Browse files
committed
Do not add fakely used (ignored but unmatched) conjuncts to the inversion match list. This should fix #8379: Incorrect cardinality estimation for retrievals with multiple compound indices having common set of fields.
1 parent 89a88b7 commit 6c0d61b

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

src/jrd/optimizer/Retrieval.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,21 +1393,21 @@ InversionCandidate* Retrieval::makeInversion(InversionCandidateList& inversions)
13931393
invCandidate->nonFullMatchedSegments = 0;
13941394
invCandidate->matchedSegments = currentInv->matchedSegments;
13951395
invCandidate->dependencies = currentInv->dependencies;
1396-
matches.clear();
13971396

13981397
for (const auto currentMatch : currentInv->matches)
13991398
{
1400-
if (!matches.exist(currentMatch))
1401-
matches.add(currentMatch);
1399+
if (!invCandidate->matches.exist(currentMatch))
1400+
invCandidate->matches.add(currentMatch);
14021401
}
14031402

1404-
if (currentInv->boolean)
1403+
if (const auto currentMatch = currentInv->boolean)
14051404
{
1406-
if (!matches.exist(currentInv->boolean))
1407-
matches.add(currentInv->boolean);
1405+
if (!invCandidate->matches.exist(currentMatch))
1406+
invCandidate->matches.add(currentMatch);
14081407
}
14091408

1410-
invCandidate->matches.join(matches);
1409+
matches.assign(invCandidate->matches);
1410+
14111411
if (customPlan)
14121412
continue;
14131413

@@ -1581,16 +1581,19 @@ InversionCandidate* Retrieval::makeInversion(InversionCandidateList& inversions)
15811581
invCandidate->dependencies = bestCandidate->dependencies;
15821582
invCandidate->condition = bestCandidate->condition;
15831583

1584-
for (FB_SIZE_T j = 0; j < bestCandidate->matches.getCount(); j++)
1584+
for (const auto bestMatch : bestCandidate->matches)
15851585
{
1586-
if (!matches.exist(bestCandidate->matches[j]))
1587-
matches.add(bestCandidate->matches[j]);
1586+
if (!invCandidate->matches.exist(bestMatch))
1587+
invCandidate->matches.add(bestMatch);
15881588
}
1589-
if (bestCandidate->boolean)
1589+
1590+
if (const auto bestMatch = bestCandidate->boolean)
15901591
{
1591-
if (!matches.exist(bestCandidate->boolean))
1592-
matches.add(bestCandidate->boolean);
1592+
if (!invCandidate->matches.exist(bestMatch))
1593+
invCandidate->matches.add(bestMatch);
15931594
}
1595+
1596+
matches.join(invCandidate->matches);
15941597
}
15951598
else if (!bestCandidate->condition)
15961599
{
@@ -1617,15 +1620,17 @@ InversionCandidate* Retrieval::makeInversion(InversionCandidateList& inversions)
16171620

16181621
for (const auto bestMatch : bestCandidate->matches)
16191622
{
1620-
if (!matches.exist(bestMatch))
1621-
matches.add(bestMatch);
1623+
if (!invCandidate->matches.exist(bestMatch))
1624+
invCandidate->matches.add(bestMatch);
16221625
}
16231626

1624-
if (bestCandidate->boolean)
1627+
if (const auto bestMatch = bestCandidate->boolean)
16251628
{
1626-
if (!matches.exist(bestCandidate->boolean))
1627-
matches.add(bestCandidate->boolean);
1629+
if (!invCandidate->matches.exist(bestMatch))
1630+
invCandidate->matches.add(bestMatch);
16281631
}
1632+
1633+
matches.join(invCandidate->matches);
16291634
}
16301635

16311636
if (invCandidate->unique)
@@ -1659,10 +1664,13 @@ InversionCandidate* Retrieval::makeInversion(InversionCandidateList& inversions)
16591664
invCandidate->cost += navigationCandidate->cost;
16601665
++invCandidate->indexes;
16611666
invCandidate->navigated = true;
1662-
}
16631667

1664-
if (invCandidate)
1665-
invCandidate->matches.join(matches);
1668+
for (const auto navMatch : navigationCandidate->matches)
1669+
{
1670+
if (!invCandidate->matches.exist(navMatch))
1671+
invCandidate->matches.add(navMatch);
1672+
}
1673+
}
16661674

16671675
return invCandidate;
16681676
}

0 commit comments

Comments
 (0)