1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

[MCOL-5205] Fix bug from union type in UNION processing.

This patch fixs the reported JIRA issue MCOL 5205, which consists of a wrong union type from two input Int types. The bug results in wrong unioned answers in CS. The fix includes more INT case discussions. Additionaly, this patch provides detailed unit tests for correctness in UNION processing with Int.

Signed-off-by: Jigao Luo <luojigao@outlook.com>
This commit is contained in:
Jigao Luo
2022-09-09 22:54:35 +02:00
parent e000236af7
commit 6c4af1461f
4 changed files with 1054 additions and 47 deletions

View File

@ -2984,25 +2984,29 @@ void DataConvert::joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& u
break;
}
if (type.colWidth > unionedType.colWidth)
if (type.colDataType == unionedType.colDataType)
{
unionedType.colDataType = type.colDataType;
unionedType.colWidth = type.colWidth;
if (type.colWidth > unionedType.colWidth)
unionedType.colWidth = type.colWidth;
}
else if (sameSignednessInteger(unionedType.colDataType, type.colDataType))
{
// Keep the signedness on the larger data type.
if (type.colWidth > unionedType.colWidth)
{
unionedType.colDataType = type.colDataType;
unionedType.colWidth = type.colWidth;
}
}
else if (differentSignednessInteger(unionedType.colDataType, type.colDataType))
{
// unionedType must be signed integer with upcasted size to prevent overflow & underflow.
if (type.colWidth > unionedType.colWidth)
unionedType.colDataType = type.colDataType;
promoteSignedInteger(unionedType);
}
// If same size but different signedness
if (type.colWidth == unionedType.colWidth &&
((!isUnsigned(unionedType.colDataType) && isUnsigned(type.colDataType)) ||
(!isUnsigned(type.colDataType) && isUnsigned(unionedType.colDataType))))
{
unionedType.colDataType = datatypes::SystemCatalog::DECIMAL;
unionedType.colWidth = datatypes::Decimal::isWideDecimalTypeByPrecision(unionedType.precision)
? datatypes::MAXDECIMALWIDTH
: datatypes::MAXLEGACYWIDTH;
}
if (type.colDataType == datatypes::SystemCatalog::DECIMAL ||
type.colDataType == datatypes::SystemCatalog::UDECIMAL)
if (isDecimal(type.colDataType))
{
unionedType.colDataType = datatypes::SystemCatalog::DECIMAL;
}