You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-08 14:22:09 +03:00
MCOL-5215 Fix overflow of UNION operation involving DECIMAL datatypes.
When a UNION operation involving DECIMAL datatypes with scale and digits before the decimal exceeds the currently supported maximum precision of 38, we throw an error to the user: "MCS-2060: Union operation exceeds maximum DECIMAL precision of 38". This is until MCOL-5417 is implemented where ColumnStore will have full parity with MariaDB server in terms of maximum supported DECIMAL precision and scale of 65 and 38 digits respectively.
This commit is contained in:
@@ -6393,12 +6393,13 @@ boost::any CalpontSystemCatalog::ColType::convertColumnData(const std::string& d
|
||||
}
|
||||
|
||||
CalpontSystemCatalog::ColType CalpontSystemCatalog::ColType::convertUnionColType(
|
||||
vector<CalpontSystemCatalog::ColType>& types)
|
||||
vector<CalpontSystemCatalog::ColType>& types,
|
||||
unsigned int& rc)
|
||||
{
|
||||
idbassert(types.size());
|
||||
CalpontSystemCatalog::ColType unionedType = types[0];
|
||||
for (uint64_t i = 1; i < types.size(); i++)
|
||||
dataconvert::DataConvert::joinColTypeForUnion(unionedType, types[i]);
|
||||
dataconvert::DataConvert::joinColTypeForUnion(unionedType, types[i], rc);
|
||||
return unionedType;
|
||||
}
|
||||
|
||||
|
@@ -306,7 +306,7 @@ class CalpontSystemCatalog : public datatypes::SystemCatalog
|
||||
return !(*this == t);
|
||||
}
|
||||
|
||||
static ColType convertUnionColType(std::vector<ColType>&);
|
||||
static ColType convertUnionColType(std::vector<ColType>&, unsigned int&);
|
||||
};
|
||||
|
||||
/** the structure of a table infomation
|
||||
|
@@ -5102,11 +5102,18 @@ SJSTEP unionQueries(JobStepVector& queries, uint64_t distinctUnionNum, JobInfo&
|
||||
unionStep->inputAssociation(jsaToUnion);
|
||||
unionStep->outputAssociation(jsa);
|
||||
|
||||
// This return code in the call to convertUnionColType() below would
|
||||
// always be 0. This is because convertUnionColType() is also called
|
||||
// in the connector code in getSelectPlan()/getGroupPlan() which handle
|
||||
// the non-zero return code scenarios from this function call and error
|
||||
// out, in which case, the execution does not even get to ExeMgr.
|
||||
unsigned int dummyUnionedTypeRc = 0;
|
||||
|
||||
// get unioned column types
|
||||
for (uint64_t j = 0; j < colCount; ++j)
|
||||
{
|
||||
CalpontSystemCatalog::ColType colType =
|
||||
CalpontSystemCatalog::ColType::convertUnionColType(queryColTypes[j]);
|
||||
CalpontSystemCatalog::ColType::convertUnionColType(queryColTypes[j], dummyUnionedTypeRc);
|
||||
types.push_back(colType.colDataType);
|
||||
csNums.push_back(colType.charsetNumber);
|
||||
scale.push_back(colType.scale);
|
||||
|
@@ -6819,7 +6819,7 @@ int processFrom(bool& isUnion, SELECT_LEX& select_lex, gp_walk_info& gwi, SCSEP&
|
||||
bool unionSel = false;
|
||||
// UNION master unit check
|
||||
// Existed pushdown handlers won't get in this scope
|
||||
// except UNION pushdown that is to come.
|
||||
// MDEV-25080 Union pushdown would enter this scope
|
||||
// is_unit_op() give a segv for derived_handler's SELECT_LEX
|
||||
if (!isUnion && (!isSelectHandlerTop || isSelectLexUnit) && select_lex.master_unit()->is_unit_op())
|
||||
{
|
||||
@@ -7414,8 +7414,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool unionSel = (!isUnion && select_lex.master_unit()->is_unit_op()) ? true : false;
|
||||
|
||||
gwi.clauseType = WHERE;
|
||||
if ((rc = processWhere(select_lex, gwi, csep, condStack)))
|
||||
{
|
||||
@@ -7857,25 +7855,32 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
|
||||
// @bug4388 normalize the project coltypes for union main select list
|
||||
if (!csep->unionVec().empty())
|
||||
{
|
||||
unsigned int unionedTypeRc = 0;
|
||||
|
||||
for (uint32_t i = 0; i < gwi.returnedCols.size(); i++)
|
||||
{
|
||||
vector<CalpontSystemCatalog::ColType> coltypes;
|
||||
|
||||
for (uint32_t j = 0; j < csep->unionVec().size(); j++)
|
||||
{
|
||||
coltypes.push_back(dynamic_cast<CalpontSelectExecutionPlan*>(csep->unionVec()[j].get())
|
||||
->returnedCols()[i]
|
||||
->resultType());
|
||||
CalpontSelectExecutionPlan* unionCsep =
|
||||
dynamic_cast<CalpontSelectExecutionPlan*>(csep->unionVec()[j].get());
|
||||
coltypes.push_back(unionCsep->returnedCols()[i]->resultType());
|
||||
|
||||
// @bug5976. set hasAggregate true for the main column if
|
||||
// one corresponding union column has aggregate
|
||||
if (dynamic_cast<CalpontSelectExecutionPlan*>(csep->unionVec()[j].get())
|
||||
->returnedCols()[i]
|
||||
->hasAggregate())
|
||||
if (unionCsep->returnedCols()[i]->hasAggregate())
|
||||
gwi.returnedCols[i]->hasAggregate(true);
|
||||
}
|
||||
|
||||
gwi.returnedCols[i]->resultType(CalpontSystemCatalog::ColType::convertUnionColType(coltypes));
|
||||
gwi.returnedCols[i]->resultType(CalpontSystemCatalog::ColType::convertUnionColType(coltypes, unionedTypeRc));
|
||||
|
||||
if (unionedTypeRc != 0)
|
||||
{
|
||||
gwi.parseErrorText = IDBErrorInfo::instance()->errorMsg(unionedTypeRc);
|
||||
setError(gwi.thd, ER_CHECK_NOT_IMPLEMENTED, gwi.parseErrorText, gwi);
|
||||
return ER_CHECK_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8044,6 +8049,8 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
|
||||
|
||||
SRCP minSc; // min width projected column. for count(*) use
|
||||
|
||||
bool unionSel = (!isUnion && select_lex.master_unit()->is_unit_op()) ? true : false;
|
||||
|
||||
// Group by list. not valid for union main query
|
||||
if (!unionSel)
|
||||
{
|
||||
@@ -9681,25 +9688,32 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro
|
||||
// @bug4388 normalize the project coltypes for union main select list
|
||||
if (!csep->unionVec().empty())
|
||||
{
|
||||
unsigned int unionedTypeRc = 0;
|
||||
|
||||
for (uint32_t i = 0; i < gwi.returnedCols.size(); i++)
|
||||
{
|
||||
vector<CalpontSystemCatalog::ColType> coltypes;
|
||||
|
||||
for (uint32_t j = 0; j < csep->unionVec().size(); j++)
|
||||
{
|
||||
coltypes.push_back(dynamic_cast<CalpontSelectExecutionPlan*>(csep->unionVec()[j].get())
|
||||
->returnedCols()[i]
|
||||
->resultType());
|
||||
CalpontSelectExecutionPlan* unionCsep =
|
||||
dynamic_cast<CalpontSelectExecutionPlan*>(csep->unionVec()[j].get());
|
||||
coltypes.push_back(unionCsep->returnedCols()[i]->resultType());
|
||||
|
||||
// @bug5976. set hasAggregate true for the main column if
|
||||
// one corresponding union column has aggregate
|
||||
if (dynamic_cast<CalpontSelectExecutionPlan*>(csep->unionVec()[j].get())
|
||||
->returnedCols()[i]
|
||||
->hasAggregate())
|
||||
if (unionCsep->returnedCols()[i]->hasAggregate())
|
||||
gwi.returnedCols[i]->hasAggregate(true);
|
||||
}
|
||||
|
||||
gwi.returnedCols[i]->resultType(CalpontSystemCatalog::ColType::convertUnionColType(coltypes));
|
||||
gwi.returnedCols[i]->resultType(CalpontSystemCatalog::ColType::convertUnionColType(coltypes, unionedTypeRc));
|
||||
|
||||
if (unionedTypeRc != 0)
|
||||
{
|
||||
gwi.parseErrorText = IDBErrorInfo::instance()->errorMsg(unionedTypeRc);
|
||||
setError(gwi.thd, ER_CHECK_NOT_IMPLEMENTED, gwi.parseErrorText, gwi);
|
||||
return ER_CHECK_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -738,7 +738,6 @@ int ha_mcs_group_by_handler::end_scan()
|
||||
* thd - THD pointer.
|
||||
* sel_lex - SELECT_LEX* that describes the query.
|
||||
* sel_unit - SELECT_LEX_UNIT* that describes the query.
|
||||
* Only one of sel_lex and sel_unit is not null.
|
||||
* RETURN:
|
||||
* select_handler if possible
|
||||
* NULL in other case
|
||||
@@ -816,15 +815,15 @@ select_handler* create_columnstore_select_handler_(THD* thd, SELECT_LEX* sel_lex
|
||||
// or unsupported feature.
|
||||
ha_columnstore_select_handler* handler;
|
||||
|
||||
if (sel_unit && sel_lex)
|
||||
if (sel_unit && sel_lex) // partial pushdown of the SELECT_LEX_UNIT
|
||||
{
|
||||
handler = new ha_columnstore_select_handler(thd, sel_lex, sel_unit);
|
||||
}
|
||||
else if (sel_unit)
|
||||
else if (sel_unit) // complete pushdown of the SELECT_LEX_UNIT
|
||||
{
|
||||
handler = new ha_columnstore_select_handler(thd, sel_unit);
|
||||
}
|
||||
else
|
||||
else // Query only has a SELECT_LEX, no SELECT_LEX_UNIT
|
||||
{
|
||||
handler = new ha_columnstore_select_handler(thd, sel_lex);
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
# MCOL-641 Union Test Cases
|
||||
# Once MCOL-5417 is supported, the errored out queries below should be fixed.
|
||||
DROP DATABASE IF EXISTS mcol641_union_db;
|
||||
CREATE DATABASE mcol641_union_db;
|
||||
USE mcol641_union_db;
|
||||
@@ -11,63 +13,52 @@ INSERT INTO cs1 values (99999999999999999999999999999999999999, 9999999999999999
|
||||
INSERT INTO cs1 values (-99999999999999999999999999999999999998, -9999999999999999999999999999.9999999998, -0.99999999999999999999999999999999999998);
|
||||
INSERT INTO cs1 values (-99999999999999999999999999999999999999, -9999999999999999999999999999.9999999999, -0.99999999999999999999999999999999999999);
|
||||
SELECT d1, d1, d2 FROM cs1 UNION SELECT d2, d3, d3 FROM cs1;
|
||||
d1 d1 d2
|
||||
125.0000000000 125.00000000000000000000000000000000000000 1.25000000000000000000000000000000000000
|
||||
-125.0000000000 -125.00000000000000000000000000000000000000 -1.25000000000000000000000000000000000000
|
||||
99999999999999999999999999999999999998.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
99999999999999999999999999999999999999.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
-99999999999999999999999999999999999998.0000000000 -999999999999999999999999999.99999999999999999999999999999999999999 -999999999999999999999999999.99999999999999999999999999999999999999
|
||||
-99999999999999999999999999999999999999.0000000000 -999999999999999999999999999.99999999999999999999999999999999999999 -999999999999999999999999999.99999999999999999999999999999999999999
|
||||
1.2500000000 0.12500000000000000000000000000000000000 0.12500000000000000000000000000000000000
|
||||
-1.2500000000 -0.12500000000000000000000000000000000000 -0.12500000000000000000000000000000000000
|
||||
9999999999999999999999999999.9999999998 0.99999999999999999999999999999999999998 0.99999999999999999999999999999999999998
|
||||
9999999999999999999999999999.9999999999 0.99999999999999999999999999999999999999 0.99999999999999999999999999999999999999
|
||||
-9999999999999999999999999999.9999999998 -0.99999999999999999999999999999999999998 -0.99999999999999999999999999999999999998
|
||||
-9999999999999999999999999999.9999999999 -0.99999999999999999999999999999999999999 -0.99999999999999999999999999999999999999
|
||||
ERROR 42000: The storage engine for the table doesn't support MCS-2060: Union operation exceeds maximum DECIMAL precision of 38.
|
||||
SELECT d2, d3, d3 FROM cs1 UNION SELECT d1, d1, d2 FROM cs1;
|
||||
d2 d3 d3
|
||||
1.2500000000 0.12500000000000000000000000000000000000 0.12500000000000000000000000000000000000
|
||||
-1.2500000000 -0.12500000000000000000000000000000000000 -0.12500000000000000000000000000000000000
|
||||
9999999999999999999999999999.9999999998 0.99999999999999999999999999999999999998 0.99999999999999999999999999999999999998
|
||||
9999999999999999999999999999.9999999999 0.99999999999999999999999999999999999999 0.99999999999999999999999999999999999999
|
||||
-9999999999999999999999999999.9999999998 -0.99999999999999999999999999999999999998 -0.99999999999999999999999999999999999998
|
||||
-9999999999999999999999999999.9999999999 -0.99999999999999999999999999999999999999 -0.99999999999999999999999999999999999999
|
||||
125.0000000000 125.00000000000000000000000000000000000000 1.25000000000000000000000000000000000000
|
||||
-125.0000000000 -125.00000000000000000000000000000000000000 -1.25000000000000000000000000000000000000
|
||||
99999999999999999999999999999999999998.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
99999999999999999999999999999999999999.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
-99999999999999999999999999999999999998.0000000000 -999999999999999999999999999.99999999999999999999999999999999999999 -999999999999999999999999999.99999999999999999999999999999999999999
|
||||
-99999999999999999999999999999999999999.0000000000 -999999999999999999999999999.99999999999999999999999999999999999999 -999999999999999999999999999.99999999999999999999999999999999999999
|
||||
ERROR 42000: The storage engine for the table doesn't support MCS-2060: Union operation exceeds maximum DECIMAL precision of 38.
|
||||
SELECT d1, d2, d3 FROM cs1 UNION SELECT d1, d2, d3 FROM cs1;
|
||||
d1 d2 d3
|
||||
125 1.2500000000 0.12500000000000000000000000000000000000
|
||||
-125 -1.2500000000 -0.12500000000000000000000000000000000000
|
||||
99999999999999999999999999999999999998 9999999999999999999999999999.9999999998 0.99999999999999999999999999999999999998
|
||||
99999999999999999999999999999999999999 9999999999999999999999999999.9999999999 0.99999999999999999999999999999999999999
|
||||
-99999999999999999999999999999999999998 -9999999999999999999999999999.9999999998 -0.99999999999999999999999999999999999998
|
||||
-99999999999999999999999999999999999999 -9999999999999999999999999999.9999999999 -0.99999999999999999999999999999999999999
|
||||
125 1.2500000000 0.12500000000000000000000000000000000000
|
||||
99999999999999999999999999999999999998 9999999999999999999999999999.9999999998 0.99999999999999999999999999999999999998
|
||||
99999999999999999999999999999999999999 9999999999999999999999999999.9999999999 0.99999999999999999999999999999999999999
|
||||
INSERT INTO cs2 VALUES (125, 1.25, 0.125);
|
||||
INSERT INTO cs2 values (99999999999999999999999999999999999998, 9999999999999999999999999999.9999999998, 0.99999999999999999999999999999999999998);
|
||||
INSERT INTO cs2 values (99999999999999999999999999999999999999, 9999999999999999999999999999.9999999999, 0.99999999999999999999999999999999999999);
|
||||
SELECT d1, d1, d2 FROM cs2 UNION SELECT d2, d3, d3 FROM cs2;
|
||||
d1 d1 d2
|
||||
125.0000000000 125.00000000000000000000000000000000000000 1.25000000000000000000000000000000000000
|
||||
99999999999999999999999999999999999998.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
99999999999999999999999999999999999999.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
1.2500000000 0.12500000000000000000000000000000000000 0.12500000000000000000000000000000000000
|
||||
9999999999999999999999999999.9999999998 0.99999999999999999999999999999999999998 0.99999999999999999999999999999999999998
|
||||
9999999999999999999999999999.9999999999 0.99999999999999999999999999999999999999 0.99999999999999999999999999999999999999
|
||||
ERROR 42000: The storage engine for the table doesn't support MCS-2060: Union operation exceeds maximum DECIMAL precision of 38.
|
||||
SELECT d2, d3, d3 FROM cs2 UNION SELECT d1, d1, d2 FROM cs2;
|
||||
d2 d3 d3
|
||||
1.2500000000 0.12500000000000000000000000000000000000 0.12500000000000000000000000000000000000
|
||||
9999999999999999999999999999.9999999998 0.99999999999999999999999999999999999998 0.99999999999999999999999999999999999998
|
||||
9999999999999999999999999999.9999999999 0.99999999999999999999999999999999999999 0.99999999999999999999999999999999999999
|
||||
125.0000000000 125.00000000000000000000000000000000000000 1.25000000000000000000000000000000000000
|
||||
99999999999999999999999999999999999998.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
99999999999999999999999999999999999999.0000000000 999999999999999999999999999.99999999999999999999999999999999999999 999999999999999999999999999.99999999999999999999999999999999999999
|
||||
ERROR 42000: The storage engine for the table doesn't support MCS-2060: Union operation exceeds maximum DECIMAL precision of 38.
|
||||
SELECT d1, d2, d3 FROM cs2 UNION SELECT d1, d2, d3 FROM cs2;
|
||||
d1 d2 d3
|
||||
125 1.2500000000 0.12500000000000000000000000000000000000
|
||||
99999999999999999999999999999999999998 9999999999999999999999999999.9999999998 0.99999999999999999999999999999999999998
|
||||
99999999999999999999999999999999999999 9999999999999999999999999999.9999999999 0.99999999999999999999999999999999999999
|
||||
DROP TABLE cs1, cs2;
|
||||
CREATE TABLE cs1 (d1 DECIMAL(20, 0), d2 DECIMAL(20, 18), d3 DECIMAL(18, 18)) ENGINE=columnstore;
|
||||
CREATE TABLE cs2 (d1 DECIMAL(20, 0) UNSIGNED, d2 DECIMAL(20, 18) UNSIGNED, d3 DECIMAL(18, 18) UNSIGNED) ENGINE=columnstore;
|
||||
INSERT INTO cs1 VALUES (12345678901234567890, 12.345678901234567891, 0.123456789012345678);
|
||||
INSERT INTO cs1 VALUES (-12345678901234567890, -12.345678901234567891, -0.123456789012345678);
|
||||
INSERT INTO cs1 VALUES (99999999999999999999, 99.999999999999999999, 0.999999999999999999);
|
||||
INSERT INTO cs1 VALUES (-99999999999999999999, -99.999999999999999999, -0.999999999999999999);
|
||||
INSERT INTO cs2 VALUES (12345678901234567890, 12.345678901234567891, 0.123456789012345678);
|
||||
INSERT INTO cs2 VALUES (99999999999999999999, 99.999999999999999999, 0.999999999999999999);
|
||||
SELECT d1, d1, d2 FROM cs1 UNION SELECT d2, d3, d3 FROM cs1;
|
||||
d1 d1 d2
|
||||
-12.345678901234567891 -0.123456789012345678 -0.123456789012345678
|
||||
-12345678901234567890.000000000000000000 -12345678901234567890.000000000000000000 -12.345678901234567891
|
||||
-99.999999999999999999 -0.999999999999999999 -0.999999999999999999
|
||||
-99999999999999999999.000000000000000000 -99999999999999999999.000000000000000000 -99.999999999999999999
|
||||
12.345678901234567891 0.123456789012345678 0.123456789012345678
|
||||
12345678901234567890.000000000000000000 12345678901234567890.000000000000000000 12.345678901234567891
|
||||
99.999999999999999999 0.999999999999999999 0.999999999999999999
|
||||
99999999999999999999.000000000000000000 99999999999999999999.000000000000000000 99.999999999999999999
|
||||
SELECT d1, d1, d2 FROM cs2 UNION SELECT d2, d3, d3 FROM cs2;
|
||||
d1 d1 d2
|
||||
12.345678901234567891 0.123456789012345678 0.123456789012345678
|
||||
12345678901234567890.000000000000000000 12345678901234567890.000000000000000000 12.345678901234567891
|
||||
99.999999999999999999 0.999999999999999999 0.999999999999999999
|
||||
99999999999999999999.000000000000000000 99999999999999999999.000000000000000000 99.999999999999999999
|
||||
DROP DATABASE mcol641_union_db;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
-- source ../include/have_columnstore.inc
|
||||
|
||||
--echo # MCOL-641 Union Test Cases
|
||||
--echo # Once MCOL-5417 is supported, the errored out queries below should be fixed.
|
||||
|
||||
--disable_warnings
|
||||
DROP DATABASE IF EXISTS mcol641_union_db;
|
||||
--enable_warnings
|
||||
@@ -19,17 +22,38 @@ INSERT INTO cs1 values (99999999999999999999999999999999999999, 9999999999999999
|
||||
INSERT INTO cs1 values (-99999999999999999999999999999999999998, -9999999999999999999999999999.9999999998, -0.99999999999999999999999999999999999998);
|
||||
INSERT INTO cs1 values (-99999999999999999999999999999999999999, -9999999999999999999999999999.9999999999, -0.99999999999999999999999999999999999999);
|
||||
|
||||
--error ER_CHECK_NOT_IMPLEMENTED
|
||||
SELECT d1, d1, d2 FROM cs1 UNION SELECT d2, d3, d3 FROM cs1;
|
||||
--error ER_CHECK_NOT_IMPLEMENTED
|
||||
SELECT d2, d3, d3 FROM cs1 UNION SELECT d1, d1, d2 FROM cs1;
|
||||
--sorted_result
|
||||
SELECT d1, d2, d3 FROM cs1 UNION SELECT d1, d2, d3 FROM cs1;
|
||||
|
||||
INSERT INTO cs2 VALUES (125, 1.25, 0.125);
|
||||
INSERT INTO cs2 values (99999999999999999999999999999999999998, 9999999999999999999999999999.9999999998, 0.99999999999999999999999999999999999998);
|
||||
INSERT INTO cs2 values (99999999999999999999999999999999999999, 9999999999999999999999999999.9999999999, 0.99999999999999999999999999999999999999);
|
||||
|
||||
--error ER_CHECK_NOT_IMPLEMENTED
|
||||
SELECT d1, d1, d2 FROM cs2 UNION SELECT d2, d3, d3 FROM cs2;
|
||||
--error ER_CHECK_NOT_IMPLEMENTED
|
||||
SELECT d2, d3, d3 FROM cs2 UNION SELECT d1, d1, d2 FROM cs2;
|
||||
--sorted_result
|
||||
SELECT d1, d2, d3 FROM cs2 UNION SELECT d1, d2, d3 FROM cs2;
|
||||
|
||||
DROP TABLE cs1, cs2;
|
||||
CREATE TABLE cs1 (d1 DECIMAL(20, 0), d2 DECIMAL(20, 18), d3 DECIMAL(18, 18)) ENGINE=columnstore;
|
||||
CREATE TABLE cs2 (d1 DECIMAL(20, 0) UNSIGNED, d2 DECIMAL(20, 18) UNSIGNED, d3 DECIMAL(18, 18) UNSIGNED) ENGINE=columnstore;
|
||||
INSERT INTO cs1 VALUES (12345678901234567890, 12.345678901234567891, 0.123456789012345678);
|
||||
INSERT INTO cs1 VALUES (-12345678901234567890, -12.345678901234567891, -0.123456789012345678);
|
||||
INSERT INTO cs1 VALUES (99999999999999999999, 99.999999999999999999, 0.999999999999999999);
|
||||
INSERT INTO cs1 VALUES (-99999999999999999999, -99.999999999999999999, -0.999999999999999999);
|
||||
INSERT INTO cs2 VALUES (12345678901234567890, 12.345678901234567891, 0.123456789012345678);
|
||||
INSERT INTO cs2 VALUES (99999999999999999999, 99.999999999999999999, 0.999999999999999999);
|
||||
|
||||
--sorted_result
|
||||
SELECT d1, d1, d2 FROM cs1 UNION SELECT d2, d3, d3 FROM cs1;
|
||||
--sorted_result
|
||||
SELECT d1, d1, d2 FROM cs2 UNION SELECT d2, d3, d3 FROM cs2;
|
||||
|
||||
# Clean UP
|
||||
DROP DATABASE mcol641_union_db;
|
||||
|
@@ -2934,7 +2934,8 @@ int64_t DataConvert::stringToTime(const string& data)
|
||||
}
|
||||
|
||||
void DataConvert::joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& unionedType,
|
||||
const datatypes::SystemCatalog::TypeHolderStd& type)
|
||||
const datatypes::SystemCatalog::TypeHolderStd& type,
|
||||
unsigned int& rc)
|
||||
{
|
||||
// limited support for VARBINARY, no implicit conversion.
|
||||
if (type.colDataType == datatypes::SystemCatalog::VARBINARY ||
|
||||
@@ -2974,6 +2975,19 @@ void DataConvert::joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& u
|
||||
case datatypes::SystemCatalog::UBIGINT:
|
||||
case datatypes::SystemCatalog::UDECIMAL:
|
||||
|
||||
if (type.scale != 0)
|
||||
{
|
||||
const unsigned int digitsBeforeDecimal = type.precision - type.scale;
|
||||
const unsigned int digitsBeforeDecimalUnion = unionedType.precision - unionedType.scale;
|
||||
|
||||
if ((std::max(digitsBeforeDecimal, digitsBeforeDecimalUnion) +
|
||||
std::max(type.scale, unionedType.scale)) > datatypes::INT128MAXPRECISION)
|
||||
{
|
||||
rc = logging::ERR_UNION_DECIMAL_OVERFLOW;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
unionedType.precision = std::max(type.precision, unionedType.precision);
|
||||
unionedType.scale = std::max(type.scale, unionedType.scale);
|
||||
|
||||
|
@@ -1290,7 +1290,8 @@ class DataConvert
|
||||
EXPORT static int64_t stringToTime(const std::string& data);
|
||||
// bug4388, union type conversion
|
||||
EXPORT static void joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& unionedType,
|
||||
const datatypes::SystemCatalog::TypeHolderStd& type);
|
||||
const datatypes::SystemCatalog::TypeHolderStd& type,
|
||||
unsigned int& rc);
|
||||
|
||||
static boost::any StringToBit(const datatypes::SystemCatalog::TypeAttributesStd& colType,
|
||||
const datatypes::ConvertFromStringParam& prm, const std::string& dataOrig,
|
||||
|
@@ -106,6 +106,8 @@
|
||||
2058 ERR_DISKAGG_OVERFLOW1 The hash function used produces a lot of hash collisions (1).
|
||||
2059 ERR_DISKAGG_OVERFLOW2 The hash function used produces a lot of hash collisions (2).
|
||||
|
||||
2060 ERR_UNION_DECIMAL_OVERFLOW Union operation exceeds maximum DECIMAL precision of 38.
|
||||
|
||||
# Sub-query errors
|
||||
3001 ERR_NON_SUPPORT_SUB_QUERY_TYPE This subquery type is not supported yet.
|
||||
3002 ERR_MORE_THAN_1_ROW Subquery returns more than 1 row.
|
||||
|
Reference in New Issue
Block a user