8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:43:02 +01:00

Fix #8078 - SIMILAR TO with constant pattern using ‘|’, ‘*’, ‘?’ or ‘{0,N}’ doesn't work as expected.

This commit is contained in:
Adriano dos Santos Fernandes 2024-04-11 21:08:25 -03:00
parent 3496c5d2c7
commit ff9f094895

View File

@ -3158,6 +3158,8 @@ ValueExprNode* Optimizer::optimizeLikeSimilar(ComparativeBoolNode* cmpNode)
MoveBuffer prefixBuffer;
ULONG charLen = 0;
bool specialCharFound = false;
FB_SIZE_T prevPrefixSize = 0;
while (IntlUtil::readOneChar(matchCharset, &patternPtr, patternEnd, &charLen))
{
@ -3172,9 +3174,36 @@ ValueExprNode* Optimizer::optimizeLikeSimilar(ComparativeBoolNode* cmpNode)
}
}
else if (charLen == 1 && SimilarToRegex::isSpecialChar(*patternPtr))
break;
{
const auto patternChar = *patternPtr;
prefixBuffer.push(patternPtr, charLen);
// If there are any branches, we assume there is no commom prefix.
if (patternChar == '|')
return nullptr;
if (!specialCharFound)
{
switch (patternChar)
{
// These patterns may make the previous char optional.
case '*':
case '?':
case '{':
prefixBuffer.resize(prevPrefixSize);
break;
}
specialCharFound = true;
}
break;
}
if (!specialCharFound)
{
prevPrefixSize = prefixBuffer.getCount();
prefixBuffer.push(patternPtr, charLen);
}
}
if (prefixBuffer.isEmpty())