提交 2a6dfbb0 编写于 作者: G Ganlin Zhao

enh(query): avg function use pre-agg results

上级 2926d141
...@@ -642,8 +642,8 @@ bool avgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { ...@@ -642,8 +642,8 @@ bool avgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
int32_t avgFunction(SqlFunctionCtx* pCtx) { int32_t avgFunction(SqlFunctionCtx* pCtx) {
int32_t numOfElem = 0; int32_t numOfElem = 0;
// Only the pre-computing information loaded and actual data does not loaded
SInputColumnInfoData* pInput = &pCtx->input; SInputColumnInfoData* pInput = &pCtx->input;
SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0];
int32_t type = pInput->pData[0]->info.type; int32_t type = pInput->pData[0]->info.type;
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
...@@ -660,95 +660,107 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { ...@@ -660,95 +660,107 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
goto _avg_over; goto _avg_over;
} }
switch (type) { if (pInput->colDataAggIsSet) {
case TSDB_DATA_TYPE_TINYINT: { numOfElem = numOfRows - pAgg->numOfNull;
int8_t* plist = (int8_t*)pCol->pData; ASSERT(numOfElem >= 0);
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
}
numOfElem += 1;
pAvgRes->count += 1;
pAvgRes->sum.isum += plist[i];
}
break; pAvgRes->count += numOfElem;
if (IS_INTEGER_TYPE(type)) {
pAvgRes->sum.isum += pAgg->sum;
} else if (IS_FLOAT_TYPE(type)) {
pAvgRes->sum.dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
} }
} else { // computing based on the true data block
switch (type) {
case TSDB_DATA_TYPE_TINYINT: {
int8_t* plist = (int8_t*)pCol->pData;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
}
case TSDB_DATA_TYPE_SMALLINT: { numOfElem += 1;
int16_t* plist = (int16_t*)pCol->pData; pAvgRes->count += 1;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { pAvgRes->sum.isum += plist[i];
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
} }
numOfElem += 1; break;
pAvgRes->count += 1;
pAvgRes->sum.isum += plist[i];
} }
break;
}
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_SMALLINT: {
int32_t* plist = (int32_t*)pCol->pData; int16_t* plist = (int16_t*)pCol->pData;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue; continue;
} }
numOfElem += 1; numOfElem += 1;
pAvgRes->count += 1; pAvgRes->count += 1;
pAvgRes->sum.isum += plist[i]; pAvgRes->sum.isum += plist[i];
}
break;
} }
break; case TSDB_DATA_TYPE_INT: {
} int32_t* plist = (int32_t*)pCol->pData;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
}
case TSDB_DATA_TYPE_BIGINT: { numOfElem += 1;
int64_t* plist = (int64_t*)pCol->pData; pAvgRes->count += 1;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { pAvgRes->sum.isum += plist[i];
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
} }
numOfElem += 1; break;
pAvgRes->count += 1;
pAvgRes->sum.isum += plist[i];
} }
break;
}
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_BIGINT: {
float* plist = (float*)pCol->pData; int64_t* plist = (int64_t*)pCol->pData;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue; continue;
} }
numOfElem += 1; numOfElem += 1;
pAvgRes->count += 1; pAvgRes->count += 1;
pAvgRes->sum.dsum += plist[i]; pAvgRes->sum.isum += plist[i];
}
break;
} }
break;
}
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_FLOAT: {
double* plist = (double*)pCol->pData; float* plist = (float*)pCol->pData;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue; continue;
}
numOfElem += 1;
pAvgRes->count += 1;
pAvgRes->sum.dsum += plist[i];
} }
break;
}
numOfElem += 1; case TSDB_DATA_TYPE_DOUBLE: {
pAvgRes->count += 1; double* plist = (double*)pCol->pData;
pAvgRes->sum.dsum += plist[i]; for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
}
numOfElem += 1;
pAvgRes->count += 1;
pAvgRes->sum.dsum += plist[i];
}
break;
} }
break;
}
default: default:
break; break;
}
} }
_avg_over: _avg_over:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册