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

MCOL-4234: improve GROUP BY and ORDER BY interaction (#3194)

This patch fixes the problem in MCOL-4234 and also generally improves
behavior of GROUP BY.

It does so by introducing a "dummy" aggregate and by wrapping columns
into it. This allows for columns that are not in GROUP BY to be used
more freely, for example, in SELECT * FROM tbl GROUP BY col - all
columns that are not "col" will be wrapped into an aggregate and query
will proceed to execution.

The dummy aggregate itself does nothing more than remember last value
passed into it.

There also an additional error message that tries to explain what types
of expressions can be wrapped into an aggregate.
This commit is contained in:
Sergey Zefirov
2024-06-17 20:00:54 +03:00
committed by GitHub
parent b1045d27b6
commit 1122b64cb1
16 changed files with 312 additions and 25 deletions

View File

@ -1254,6 +1254,108 @@ void RowAggregation::doMinMax(const Row& rowIn, int64_t colIn, int64_t colOut, i
}
}
}
//------------------------------------------------------------------------------
// Update the fields with anything that goes in.
// rowIn(in) - Row to be included in aggregation.
// colIn(in) - column in the input row group
// colOut(in) - column in the output row group
//------------------------------------------------------------------------------
void RowAggregation::doSelectSome(const Row& rowIn, int64_t colIn, int64_t colOut)
{
int colDataType = (fRowGroupIn.getColTypes())[colIn];
switch (colDataType)
{
case execplan::CalpontSystemCatalog::UTINYINT:
case execplan::CalpontSystemCatalog::USMALLINT:
case execplan::CalpontSystemCatalog::UMEDINT:
case execplan::CalpontSystemCatalog::UINT:
case execplan::CalpontSystemCatalog::UBIGINT:
case execplan::CalpontSystemCatalog::TINYINT:
case execplan::CalpontSystemCatalog::SMALLINT:
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::BIGINT:
{
fRow.setIntField(rowIn.getIntField(colIn), colOut);
break;
}
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{
if (LIKELY(rowIn.getColumnWidth(colIn) == datatypes::MAXDECIMALWIDTH))
{
fRow.setInt128Field(rowIn.getTSInt128Field(colIn).getValue(), colOut);
}
else if (rowIn.getColumnWidth(colIn) <= datatypes::MAXLEGACYWIDTH)
{
fRow.setIntField(rowIn.getIntField(colIn), colOut);
}
else
{
idbassert(0);
throw std::logic_error("RowAggregation::doMinMax(): DECIMAL bad length.");
}
break;
}
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::TEXT:
{
auto valIn = rowIn.getStringField(colIn);
fRow.setStringField(valIn, colOut);
break;
}
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::UDOUBLE:
{
double valIn = rowIn.getDoubleField(colIn);
fRow.setDoubleField(valIn, colOut);
break;
}
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT:
{
float valIn = rowIn.getFloatField(colIn);
fRow.setFloatField(valIn, colOut);
break;
}
case execplan::CalpontSystemCatalog::DATE:
case execplan::CalpontSystemCatalog::DATETIME:
case execplan::CalpontSystemCatalog::TIMESTAMP:
case execplan::CalpontSystemCatalog::TIME:
{
uint64_t valIn = rowIn.getUintField(colIn);
fRow.setUintField(valIn, colOut);
break;
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double valIn = rowIn.getLongDoubleField(colIn);
fRow.setLongDoubleField(valIn, colOut);
break;
}
case execplan::CalpontSystemCatalog::CLOB:
case execplan::CalpontSystemCatalog::BLOB:
{
fRow.setVarBinaryField(rowIn.getVarBinaryField(colIn), rowIn.getVarBinaryLength(colIn), colOut);
break;
}
default:
{
idbassert_s(0, "unknown data type in doSelectSome()");
break;
}
}
}
//------------------------------------------------------------------------------
// Update the sum fields if input is not null.
@ -1723,6 +1825,11 @@ void RowAggregation::updateEntry(const Row& rowIn, std::vector<mcsv1sdk::mcsv1Co
doUDAF(rowIn, colIn, colOut, colOut + 1, i, rgContextColl);
break;
}
case ROWAGG_SELECT_SOME:
{
doSelectSome(rowIn, colIn, colOut);
break;
}
default:
{
@ -1783,6 +1890,12 @@ void RowAggregation::mergeEntries(const Row& rowIn)
case ROWAGG_UDAF: doUDAF(rowIn, colOut, colOut, colOut + 1, i); break;
case ROWAGG_SELECT_SOME:
{
doSelectSome(rowIn, colOut, colOut);
break;
}
default:
std::ostringstream errmsg;
errmsg << "RowAggregation: function (id = " << (uint64_t)fFunctionCols[i]->fAggFunction
@ -2617,6 +2730,12 @@ void RowAggregationUM::updateEntry(const Row& rowIn, std::vector<mcsv1sdk::mcsv1
break;
}
case ROWAGG_SELECT_SOME:
{
doSelectSome(rowIn, colIn, colOut);
break;
}
default:
{
// need a exception to show the value
@ -4208,6 +4327,12 @@ void RowAggregationUMP2::updateEntry(const Row& rowIn, std::vector<mcsv1sdk::mcs
break;
}
case ROWAGG_SELECT_SOME:
{
doSelectSome(rowIn, colIn, colOut);
break;
}
default:
{
std::ostringstream errmsg;
@ -4700,6 +4825,12 @@ void RowAggregationDistinct::updateEntry(const Row& rowIn, std::vector<mcsv1sdk:
break;
}
case ROWAGG_SELECT_SOME:
{
doSelectSome(rowIn, colIn, colOut);
break;
}
default:
{
std::ostringstream errmsg;