提交 c303ff2a 编写于 作者: H hjxilinx

refactor some codes [tbase-266]

上级 8c2766e3
...@@ -72,6 +72,8 @@ for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) { \ ...@@ -72,6 +72,8 @@ for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) { \
void noop1(SQLFunctionCtx *UNUSED_PARAM(pCtx)) {} void noop1(SQLFunctionCtx *UNUSED_PARAM(pCtx)) {}
void noop2(SQLFunctionCtx *UNUSED_PARAM(pCtx), int32_t UNUSED_PARAM(index)) {} void noop2(SQLFunctionCtx *UNUSED_PARAM(pCtx), int32_t UNUSED_PARAM(index)) {}
void doFinalizer(SQLFunctionCtx *pCtx) { resetResultInfo(GET_RES_INFO(pCtx)); }
typedef struct tValuePair { typedef struct tValuePair {
tVariant v; tVariant v;
int64_t timestamp; int64_t timestamp;
...@@ -355,8 +357,8 @@ static void function_finalizer(SQLFunctionCtx *pCtx) { ...@@ -355,8 +357,8 @@ static void function_finalizer(SQLFunctionCtx *pCtx) {
pTrace("no result generated, result is set to NULL"); pTrace("no result generated, result is set to NULL");
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes); setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
} }
resetResultInfo(GET_RES_INFO(pCtx)); doFinalizer(pCtx);
} }
/* /*
...@@ -889,6 +891,7 @@ static void avg_finalizer(SQLFunctionCtx *pCtx) { ...@@ -889,6 +891,7 @@ static void avg_finalizer(SQLFunctionCtx *pCtx) {
// cannot set the numOfIteratedElems again since it is set during previous iteration // cannot set the numOfIteratedElems again since it is set during previous iteration
GET_RES_INFO(pCtx)->numOfRes = 1; GET_RES_INFO(pCtx)->numOfRes = 1;
doFinalizer(pCtx);
} }
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
...@@ -1433,8 +1436,8 @@ static void stddev_finalizer(SQLFunctionCtx *pCtx) { ...@@ -1433,8 +1436,8 @@ static void stddev_finalizer(SQLFunctionCtx *pCtx) {
*retValue = sqrt(pStd->res / pStd->num); *retValue = sqrt(pStd->res / pStd->num);
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
} }
resetResultInfo(GET_RES_INFO(pCtx)); doFinalizer(pCtx);
} }
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
...@@ -1836,7 +1839,7 @@ static void last_row_finalizer(SQLFunctionCtx *pCtx) { ...@@ -1836,7 +1839,7 @@ static void last_row_finalizer(SQLFunctionCtx *pCtx) {
} }
GET_RES_INFO(pCtx)->numOfRes = 1; GET_RES_INFO(pCtx)->numOfRes = 1;
resetResultInfo(GET_RES_INFO(pCtx)); doFinalizer(pCtx);
} }
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
...@@ -2404,8 +2407,8 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) { ...@@ -2404,8 +2407,8 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) {
GET_TRUE_DATA_TYPE(); GET_TRUE_DATA_TYPE();
copyTopBotRes(pCtx, type); copyTopBotRes(pCtx, type);
resetResultInfo(pResInfo); doFinalizer(pCtx);
} }
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
...@@ -2481,8 +2484,8 @@ static void percentile_finalizer(SQLFunctionCtx *pCtx) { ...@@ -2481,8 +2484,8 @@ static void percentile_finalizer(SQLFunctionCtx *pCtx) {
tOrderDescDestroy(pMemBucket->pOrderDesc); tOrderDescDestroy(pMemBucket->pOrderDesc);
tMemBucketDestroy(pMemBucket); tMemBucketDestroy(pMemBucket);
resetResultInfo(GET_RES_INFO(pCtx)); doFinalizer(pCtx);
} }
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
...@@ -2690,8 +2693,8 @@ static void apercentile_finalizer(SQLFunctionCtx *pCtx) { ...@@ -2690,8 +2693,8 @@ static void apercentile_finalizer(SQLFunctionCtx *pCtx) {
return; return;
} }
} }
resetResultInfo(pResInfo); doFinalizer(pCtx);
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
...@@ -2871,7 +2874,7 @@ static void leastsquares_finalizer(SQLFunctionCtx *pCtx) { ...@@ -2871,7 +2874,7 @@ static void leastsquares_finalizer(SQLFunctionCtx *pCtx) {
param[1][2] /= param[1][1]; param[1][2] /= param[1][1];
sprintf(pCtx->aOutputBuf, "(%lf, %lf)", param[0][2], param[1][2]); sprintf(pCtx->aOutputBuf, "(%lf, %lf)", param[0][2], param[1][2]);
resetResultInfo(GET_RES_INFO(pCtx)); doFinalizer(pCtx);
} }
static void date_col_output_function(SQLFunctionCtx *pCtx) { static void date_col_output_function(SQLFunctionCtx *pCtx) {
...@@ -2927,18 +2930,17 @@ static void tag_project_function(SQLFunctionCtx *pCtx) { ...@@ -2927,18 +2930,17 @@ static void tag_project_function(SQLFunctionCtx *pCtx) {
INC_INIT_VAL(pCtx, pCtx->size); INC_INIT_VAL(pCtx, pCtx->size);
assert(pCtx->inputBytes == pCtx->outputBytes); assert(pCtx->inputBytes == pCtx->outputBytes);
// int32_t factor = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
for (int32_t i = 0; i < pCtx->size; ++i) { for (int32_t i = 0; i < pCtx->size; ++i) {
tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->outputType); tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->outputType);
pCtx->aOutputBuf += pCtx->outputBytes/* * factor*/; pCtx->aOutputBuf += pCtx->outputBytes;
} }
} }
static void tag_project_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void tag_project_function_f(SQLFunctionCtx *pCtx, int32_t index) {
INC_INIT_VAL(pCtx, 1); INC_INIT_VAL(pCtx, 1);
tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->tag.nType); tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->tag.nType);
pCtx->aOutputBuf += pCtx->outputBytes/* * GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/; pCtx->aOutputBuf += pCtx->outputBytes;
} }
/** /**
...@@ -4183,7 +4185,7 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) { ...@@ -4183,7 +4185,7 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) {
} }
GET_RES_INFO(pCtx)->numOfRes = 1; GET_RES_INFO(pCtx)->numOfRes = 1;
resetResultInfo(GET_RES_INFO(pCtx)); doFinalizer(pCtx);
} }
/** /**
...@@ -4345,7 +4347,7 @@ static void ts_comp_finalize(SQLFunctionCtx *pCtx) { ...@@ -4345,7 +4347,7 @@ static void ts_comp_finalize(SQLFunctionCtx *pCtx) {
strcpy(pCtx->aOutputBuf, pTSbuf->path); strcpy(pCtx->aOutputBuf, pTSbuf->path);
tsBufDestory(pTSbuf); tsBufDestory(pTSbuf);
resetResultInfo(GET_RES_INFO(pCtx)); doFinalizer(pCtx);
} }
/* /*
...@@ -4385,7 +4387,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4385,7 +4387,7 @@ SQLAggFuncElem aAggs[28] = {{
count_function, count_function,
count_function_f, count_function_f,
no_next_step, no_next_step,
noop1, doFinalizer,
count_func_merge, count_func_merge,
count_func_merge, count_func_merge,
count_load_data_info, count_load_data_info,
...@@ -4628,7 +4630,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4628,7 +4630,7 @@ SQLAggFuncElem aAggs[28] = {{
date_col_output_function, date_col_output_function,
date_col_output_function_f, date_col_output_function_f,
no_next_step, no_next_step,
noop1, doFinalizer,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
...@@ -4643,7 +4645,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4643,7 +4645,7 @@ SQLAggFuncElem aAggs[28] = {{
noop1, noop1,
noop2, noop2,
no_next_step, no_next_step,
noop1, doFinalizer,
copy_function, copy_function,
copy_function, copy_function,
data_req_load_info, data_req_load_info,
...@@ -4658,7 +4660,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4658,7 +4660,7 @@ SQLAggFuncElem aAggs[28] = {{
tag_function, tag_function,
noop2, noop2,
no_next_step, no_next_step,
noop1, doFinalizer,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
...@@ -4688,7 +4690,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4688,7 +4690,7 @@ SQLAggFuncElem aAggs[28] = {{
tag_function, tag_function,
tag_function_f, tag_function_f,
no_next_step, no_next_step,
noop1, doFinalizer,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
...@@ -4703,7 +4705,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4703,7 +4705,7 @@ SQLAggFuncElem aAggs[28] = {{
col_project_function, col_project_function,
col_project_function_f, col_project_function_f,
no_next_step, no_next_step,
noop1, doFinalizer,
copy_function, copy_function,
copy_function, copy_function,
data_req_load_info, data_req_load_info,
...@@ -4718,7 +4720,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4718,7 +4720,7 @@ SQLAggFuncElem aAggs[28] = {{
tag_project_function, tag_project_function,
tag_project_function_f, tag_project_function_f,
no_next_step, no_next_step,
noop1, doFinalizer,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
...@@ -4733,7 +4735,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4733,7 +4735,7 @@ SQLAggFuncElem aAggs[28] = {{
arithmetic_function, arithmetic_function,
arithmetic_function_f, arithmetic_function_f,
no_next_step, no_next_step,
noop1, doFinalizer,
copy_function, copy_function,
copy_function, copy_function,
data_req_load_info, data_req_load_info,
...@@ -4748,7 +4750,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4748,7 +4750,7 @@ SQLAggFuncElem aAggs[28] = {{
diff_function, diff_function,
diff_function_f, diff_function_f,
no_next_step, no_next_step,
noop1, doFinalizer,
noop1, noop1,
noop1, noop1,
data_req_load_info, data_req_load_info,
...@@ -4794,7 +4796,7 @@ SQLAggFuncElem aAggs[28] = {{ ...@@ -4794,7 +4796,7 @@ SQLAggFuncElem aAggs[28] = {{
interp_function, interp_function,
do_sum_f, // todo filter handle do_sum_f, // todo filter handle
no_next_step, no_next_step,
noop1, doFinalizer,
noop1, noop1,
copy_function, copy_function,
no_data_info, no_data_info,
......
...@@ -279,9 +279,11 @@ void vnodePrintQueryStatistics(SMeterQuerySupportObj* pSupporter); ...@@ -279,9 +279,11 @@ void vnodePrintQueryStatistics(SMeterQuerySupportObj* pSupporter);
void clearGroupResultBuf(SOutputRes* pOneOutputRes, int32_t nOutputCols); void clearGroupResultBuf(SOutputRes* pOneOutputRes, int32_t nOutputCols);
void copyGroupResultBuf(SOutputRes* dst, const SOutputRes* src, int32_t nOutputCols); void copyGroupResultBuf(SOutputRes* dst, const SOutputRes* src, int32_t nOutputCols);
void resetResWindowInfo(SSlidingWindowResInfo* pWindowResInfo, int32_t numOfCols); void resetSlidingWindowInfo(SSlidingWindowInfo* pSlidingWindowInfo, int32_t numOfCols);
void clearCompletedResWindows(SSlidingWindowResInfo* pWindowResInfo, int32_t numOfCols); void clearCompletedSlidingWindows(SSlidingWindowInfo* pSlidingWindowInfo, int32_t numOfCols);
int32_t numOfResFromResWindowInfo(SSlidingWindowResInfo* pWindowResInfo); int32_t numOfClosedSlidingWindow(SSlidingWindowInfo* pSlidingWindowInfo);
void closeSlidingWindow(SSlidingWindowInfo* pSlidingWindowInfo, int32_t slot);
void closeAllSlidingWindow(SSlidingWindowInfo* pSlidingWindowInfo);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -122,7 +122,7 @@ typedef struct SWindowStatus { ...@@ -122,7 +122,7 @@ typedef struct SWindowStatus {
bool closed; bool closed;
} SWindowStatus; } SWindowStatus;
typedef struct SSlidingWindowResInfo { typedef struct SSlidingWindowInfo {
SOutputRes* pResult; // reference to SQuerySupporter->pResult SOutputRes* pResult; // reference to SQuerySupporter->pResult
SWindowStatus* pStatus; // current query window closed or not? SWindowStatus* pStatus; // current query window closed or not?
void* hashList; // hash list for quick access void* hashList; // hash list for quick access
...@@ -134,7 +134,7 @@ typedef struct SSlidingWindowResInfo { ...@@ -134,7 +134,7 @@ typedef struct SSlidingWindowResInfo {
int64_t startTime; // start time of the first time window for sliding query int64_t startTime; // start time of the first time window for sliding query
int64_t prevSKey; // previous (not completed) sliding window start key int64_t prevSKey; // previous (not completed) sliding window start key
int64_t threshold; // threshold for return completed results. int64_t threshold; // threshold for return completed results.
} SSlidingWindowResInfo; } SSlidingWindowInfo;
typedef struct SQueryRuntimeEnv { typedef struct SQueryRuntimeEnv {
SPositionInfo startPos; /* the start position, used for secondary/third iteration */ SPositionInfo startPos; /* the start position, used for secondary/third iteration */
...@@ -159,14 +159,13 @@ typedef struct SQueryRuntimeEnv { ...@@ -159,14 +159,13 @@ typedef struct SQueryRuntimeEnv {
SInterpolationInfo interpoInfo; SInterpolationInfo interpoInfo;
SData** pInterpoBuf; SData** pInterpoBuf;
SSlidingWindowResInfo swindowResInfo; SSlidingWindowInfo swindowResInfo;
STSBuf* pTSBuf; STSBuf* pTSBuf;
STSCursor cur; STSCursor cur;
SQueryCostSummary summary; SQueryCostSummary summary;
TSKEY intervalSKey; // skey of the complete time window, not affected by the actual data distribution STimeWindow intervalWindow; // the complete time window, not affected by the actual data distribution
TSKEY intervalEKey; // ekey of the complete time window
/* /*
* Temporarily hold the in-memory cache block info during scan cache blocks * Temporarily hold the in-memory cache block info during scan cache blocks
...@@ -296,7 +295,7 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo* pQInfo, SQuery* pQuery, void* param) ...@@ -296,7 +295,7 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo* pQInfo, SQuery* pQuery, void* param)
void vnodeDecMeterRefcnt(SQInfo* pQInfo); void vnodeDecMeterRefcnt(SQInfo* pQInfo);
/* sql query handle in dnode */ /* sql query handle in dnode */
void vnodeSingleMeterQuery(SSchedMsg* pMsg); void vnodeSingleTableQuery(SSchedMsg* pMsg);
/* /*
* handle multi-meter query process * handle multi-meter query process
......
...@@ -88,22 +88,10 @@ static void setStartPositionForCacheBlock(SQuery *pQuery, SCacheBlock *pBlock, b ...@@ -88,22 +88,10 @@ static void setStartPositionForCacheBlock(SQuery *pQuery, SCacheBlock *pBlock, b
static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) { static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
SQuery* pQuery = pRuntimeEnv->pQuery; SQuery* pQuery = pRuntimeEnv->pQuery;
// enable execution for next table for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
if (isGroupbyNormalCol(pQuery->pGroupbyExpr) || (pQuery->nAggTimeInterval > 0 && pQuery->slidingTime > 0)) { SResultInfo *pResInfo = GET_RES_INFO(&pRuntimeEnv->pCtx[i]);
SSlidingWindowResInfo *pWindowResInfo = &pRuntimeEnv->swindowResInfo; if (pResInfo != NULL) {
pResInfo->complete = false;
for (int32_t i = 0; i < pWindowResInfo->size; ++i) {
SOutputRes *buf = &pWindowResInfo->pResult[i];
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
buf->resultInfo[j].complete = false;
}
}
} else {
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
SResultInfo *pResInfo = GET_RES_INFO(&pRuntimeEnv->pCtx[i]);
if (pResInfo != NULL) {
pResInfo->complete = false;
}
} }
} }
} }
...@@ -535,6 +523,7 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool * ...@@ -535,6 +523,7 @@ static bool multimeterMultioutputHelper(SQInfo *pQInfo, bool *dataInDisk, bool *
} }
} }
initCtxOutputBuf(pRuntimeEnv);
return true; return true;
} }
...@@ -572,13 +561,8 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start ...@@ -572,13 +561,8 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start
vnodeScanAllData(pRuntimeEnv); vnodeScanAllData(pRuntimeEnv);
// enable execution for next table
enableExecutionForNextTable(pRuntimeEnv);
// first/last_row query, do not invoke the finalize for super table query // first/last_row query, do not invoke the finalize for super table query
if (!isFirstLastRowQuery(pQuery)) { doFinalizeResult(pRuntimeEnv);
doFinalizeResult(pRuntimeEnv);
}
int64_t numOfRes = getNumOfResult(pRuntimeEnv); int64_t numOfRes = getNumOfResult(pRuntimeEnv);
assert(numOfRes == 1 || numOfRes == 0); assert(numOfRes == 1 || numOfRes == 0);
...@@ -592,7 +576,14 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start ...@@ -592,7 +576,14 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start
return numOfRes; return numOfRes;
} }
static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { /**
* super table query handler
* 1. super table projection query, group-by on normal columns query, ts-comp query
* 2. point interpolation query, last row query
*
* @param pQInfo
*/
static void vnodeSTableSeqProcessor(SQInfo *pQInfo) {
SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter;
SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo; SMeterSidExtInfo **pMeterSidExtInfo = pSupporter->pMeterSidExtInfo;
...@@ -601,8 +592,8 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -601,8 +592,8 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
tSidSet *pSids = pSupporter->pSidSet; tSidSet *pSids = pSupporter->pSidSet;
SMeterObj *pOneMeter = getMeterObj(pSupporter->pMetersHashTable, pMeterSidExtInfo[0]->sid); int32_t vid = getMeterObj(pSupporter->pMetersHashTable, pMeterSidExtInfo[0]->sid)->vnode;
resetCtxOutputBuf(pRuntimeEnv); resetCtxOutputBuf(pRuntimeEnv);
if (isPointInterpoQuery(pQuery)) { if (isPointInterpoQuery(pQuery)) {
...@@ -613,7 +604,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -613,7 +604,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
int32_t end = pSids->starterPos[pSupporter->subgroupIdx + 1] - 1; int32_t end = pSids->starterPos[pSupporter->subgroupIdx + 1] - 1;
if (isFirstLastRowQuery(pQuery)) { if (isFirstLastRowQuery(pQuery)) {
dTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, pOneMeter->vnode, dTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid,
pSids->numOfSubSet, pSupporter->subgroupIdx); pSids->numOfSubSet, pSupporter->subgroupIdx);
TSKEY key = -1; TSKEY key = -1;
...@@ -646,7 +637,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -646,7 +637,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
int64_t num = doCheckMetersInGroup(pQInfo, index, start); int64_t num = doCheckMetersInGroup(pQInfo, index, start);
assert(num >= 0); assert(num >= 0);
} else { } else {
dTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, pOneMeter->vnode, dTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid,
pSids->numOfSubSet, pSupporter->subgroupIdx); pSids->numOfSubSet, pSupporter->subgroupIdx);
for (int32_t k = start; k <= end; ++k) { for (int32_t k = start; k <= end; ++k) {
...@@ -673,7 +664,9 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -673,7 +664,9 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
} }
} }
} else { } else {
// this procedure treats all tables as single group /*
* 1. super table projection query, 2. group-by on normal columns query, 3. ts-comp query
*/
assert(pSupporter->meterIdx >= 0); assert(pSupporter->meterIdx >= 0);
/* /*
...@@ -693,9 +686,9 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -693,9 +686,9 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
return; return;
} }
resetResWindowInfo(&pRuntimeEnv->swindowResInfo, pQuery->numOfOutputCols); resetSlidingWindowInfo(&pRuntimeEnv->swindowResInfo, pQuery->numOfOutputCols);
while (pSupporter->meterIdx < pSupporter->numOfMeters) { while (pSupporter->meterIdx < pSupporter->numOfMeters) {
int32_t k = pSupporter->meterIdx; int32_t k = pSupporter->meterIdx;
if (isQueryKilled(pQuery)) { if (isQueryKilled(pQuery)) {
...@@ -752,7 +745,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -752,7 +745,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
break; break;
} }
// enable execution for next table // enable execution for next table, when handling the projection query
enableExecutionForNextTable(pRuntimeEnv); enableExecutionForNextTable(pRuntimeEnv);
if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK | QUERY_COMPLETED)) { if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK | QUERY_COMPLETED)) {
...@@ -772,8 +765,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -772,8 +765,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
break; break;
} }
} else { } else { // forward query range
// forward query range
pQuery->skey = pQuery->lastKey; pQuery->skey = pQuery->lastKey;
// all data in the result buffer are skipped due to the offset, continue to retrieve data from current meter // all data in the result buffer are skipped due to the offset, continue to retrieve data from current meter
...@@ -789,7 +781,18 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -789,7 +781,18 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
} }
} }
if (!isGroupbyNormalCol(pQuery->pGroupbyExpr) && !isFirstLastRowQuery(pQuery)) { /*
* 1. super table projection query, group-by on normal columns query, ts-comp query
* 2. point interpolation query, last row query
*
* group-by on normal columns query and last_row query do NOT invoke the finalizer here,
* since the finalize stage will be done at the client side.
*
* projection query, point interpolation query do not need the finalizer.
*
* Only the ts-comp query requires the finalizer function to be executed here.
*/
if (isTSCompQuery(pQuery)) {
doFinalizeResult(pRuntimeEnv); doFinalizeResult(pRuntimeEnv);
} }
...@@ -799,11 +802,11 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -799,11 +802,11 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
// todo refactor // todo refactor
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) { if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
SSlidingWindowResInfo* pWindowResInfo = &pRuntimeEnv->swindowResInfo; SSlidingWindowInfo* pSlidingWindowInfo = &pRuntimeEnv->swindowResInfo;
for (int32_t i = 0; i < pWindowResInfo->size; ++i) { for (int32_t i = 0; i < pSlidingWindowInfo->size; ++i) {
SOutputRes *buf = &pWindowResInfo->pResult[i]; SOutputRes *buf = &pSlidingWindowInfo->pResult[i];
pWindowResInfo->pStatus[i].closed = true; // enable return all results for group by normal columns pSlidingWindowInfo->pStatus[i].closed = true; // enable return all results for group by normal columns
for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) { for (int32_t j = 0; j < pQuery->numOfOutputCols; ++j) {
buf->numOfRows = MAX(buf->numOfRows, buf->resultInfo[j].numOfRes); buf->numOfRows = MAX(buf->numOfRows, buf->resultInfo[j].numOfRes);
...@@ -812,7 +815,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -812,7 +815,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
pQInfo->pMeterQuerySupporter->subgroupIdx = 0; pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
pQuery->pointsRead = 0; pQuery->pointsRead = 0;
copyFromGroupBuf(pQInfo, pWindowResInfo->pResult); copyFromGroupBuf(pQInfo, pSlidingWindowInfo->pResult);
} }
pQInfo->pointsRead += pQuery->pointsRead; pQInfo->pointsRead += pQuery->pointsRead;
...@@ -821,7 +824,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { ...@@ -821,7 +824,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) {
dTrace( dTrace(
"QInfo %p vid:%d, numOfMeters:%d, index:%d, numOfGroups:%d, %d points returned, totalRead:%d totalReturn:%d," "QInfo %p vid:%d, numOfMeters:%d, index:%d, numOfGroups:%d, %d points returned, totalRead:%d totalReturn:%d,"
"next skey:%" PRId64 ", offset:%" PRId64, "next skey:%" PRId64 ", offset:%" PRId64,
pQInfo, pOneMeter->vnode, pSids->numOfSids, pSupporter->meterIdx, pSids->numOfSubSet, pQuery->pointsRead, pQInfo, vid, pSids->numOfSids, pSupporter->meterIdx, pSids->numOfSubSet, pQuery->pointsRead,
pQInfo->pointsRead, pQInfo->pointsReturned, pQuery->skey, pQuery->limit.offset); pQInfo->pointsRead, pQInfo->pointsReturned, pQuery->skey, pQuery->limit.offset);
} }
...@@ -979,7 +982,7 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) { ...@@ -979,7 +982,7 @@ static void vnodeMultiMeterQueryProcessor(SQInfo *pQInfo) {
* select count(*)/top(field,k)/avg(field name) from table_name [where ts>now-1a]; * select count(*)/top(field,k)/avg(field name) from table_name [where ts>now-1a];
* select count(*) from table_name group by status_column; * select count(*) from table_name group by status_column;
*/ */
static void vnodeSingleMeterFixedOutputProcessor(SQInfo *pQInfo) { static void vnodeSingleTableFixedOutputProcessor(SQInfo *pQInfo) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->pMeterQuerySupporter->runtimeEnv;
...@@ -1002,19 +1005,13 @@ static void vnodeSingleMeterFixedOutputProcessor(SQInfo *pQInfo) { ...@@ -1002,19 +1005,13 @@ static void vnodeSingleMeterFixedOutputProcessor(SQInfo *pQInfo) {
assert(isTopBottomQuery(pQuery)); assert(isTopBottomQuery(pQuery));
} }
if (isGroupbyNormalCol(pQuery->pGroupbyExpr)) {
pQInfo->pMeterQuerySupporter->subgroupIdx = 0;
pQuery->pointsRead = 0;
copyFromGroupBuf(pQInfo, pRuntimeEnv->swindowResInfo.pResult);
}
doSkipResults(pRuntimeEnv); doSkipResults(pRuntimeEnv);
doRevisedResultsByLimit(pQInfo); doRevisedResultsByLimit(pQInfo);
pQInfo->pointsRead = pQuery->pointsRead; pQInfo->pointsRead = pQuery->pointsRead;
} }
static void vnodeSingleMeterMultiOutputProcessor(SQInfo *pQInfo) { static void vnodeSingleTableMultiOutputProcessor(SQInfo *pQInfo) {
SQuery * pQuery = &pQInfo->query; SQuery * pQuery = &pQInfo->query;
SMeterObj *pMeterObj = pQInfo->pObj; SMeterObj *pMeterObj = pQInfo->pObj;
...@@ -1083,7 +1080,7 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter ...@@ -1083,7 +1080,7 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
(pQuery->skey >= pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))); (pQuery->skey >= pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery)));
initCtxOutputBuf(pRuntimeEnv); initCtxOutputBuf(pRuntimeEnv);
clearCompletedResWindows(&pRuntimeEnv->swindowResInfo, pQuery->numOfOutputCols); clearCompletedSlidingWindows(&pRuntimeEnv->swindowResInfo, pQuery->numOfOutputCols);
vnodeScanAllData(pRuntimeEnv); vnodeScanAllData(pRuntimeEnv);
if (isQueryKilled(pQuery)) { if (isQueryKilled(pQuery)) {
...@@ -1133,7 +1130,7 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter ...@@ -1133,7 +1130,7 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
} }
/* handle time interval query on single table */ /* handle time interval query on single table */
static void vnodeSingleMeterIntervalProcessor(SQInfo *pQInfo) { static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
SQuery * pQuery = &(pQInfo->query); SQuery * pQuery = &(pQInfo->query);
SMeterObj *pMeterObj = pQInfo->pObj; SMeterObj *pMeterObj = pQInfo->pObj;
...@@ -1187,7 +1184,7 @@ static void vnodeSingleMeterIntervalProcessor(SQInfo *pQInfo) { ...@@ -1187,7 +1184,7 @@ static void vnodeSingleMeterIntervalProcessor(SQInfo *pQInfo) {
pQInfo->pointsRead - pQInfo->pointsInterpo, pQInfo->pointsInterpo, pQInfo->pointsReturned); pQInfo->pointsRead - pQInfo->pointsInterpo, pQInfo->pointsInterpo, pQInfo->pointsReturned);
} }
void vnodeSingleMeterQuery(SSchedMsg *pMsg) { void vnodeSingleTableQuery(SSchedMsg *pMsg) {
SQInfo *pQInfo = (SQInfo *)pMsg->ahandle; SQInfo *pQInfo = (SQInfo *)pMsg->ahandle;
if (pQInfo == NULL || pQInfo->pMeterQuerySupporter == NULL) { if (pQInfo == NULL || pQInfo->pMeterQuerySupporter == NULL) {
...@@ -1280,16 +1277,17 @@ void vnodeSingleMeterQuery(SSchedMsg *pMsg) { ...@@ -1280,16 +1277,17 @@ void vnodeSingleMeterQuery(SSchedMsg *pMsg) {
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
if (pQuery->nAggTimeInterval != 0) { // interval (down sampling operation) // group by normal column, sliding window query, interval query are handled by interval query processor
if (pQuery->nAggTimeInterval != 0 || isGroupbyNormalCol(pQuery->pGroupbyExpr)) { // interval (down sampling operation)
assert(pQuery->checkBufferInLoop == 0 && pQuery->pointsOffset == pQuery->pointsToRead); assert(pQuery->checkBufferInLoop == 0 && pQuery->pointsOffset == pQuery->pointsToRead);
vnodeSingleMeterIntervalProcessor(pQInfo); vnodeSingleTableIntervalProcessor(pQInfo);
} else { } else {
if (isFixedOutputQuery(pQuery)) { if (isFixedOutputQuery(pQuery)) {
assert(pQuery->checkBufferInLoop == 0); assert(pQuery->checkBufferInLoop == 0);
vnodeSingleMeterFixedOutputProcessor(pQInfo); vnodeSingleTableFixedOutputProcessor(pQInfo);
} else { // diff/add/multiply/subtract/division } else { // diff/add/multiply/subtract/division
assert(pQuery->checkBufferInLoop == 1); assert(pQuery->checkBufferInLoop == 1);
vnodeSingleMeterMultiOutputProcessor(pQInfo); vnodeSingleTableMultiOutputProcessor(pQInfo);
} }
} }
...@@ -1336,7 +1334,7 @@ void vnodeMultiMeterQuery(SSchedMsg *pMsg) { ...@@ -1336,7 +1334,7 @@ void vnodeMultiMeterQuery(SSchedMsg *pMsg) {
assert((pQuery->checkBufferInLoop == 1 && pQuery->nAggTimeInterval == 0) || isPointInterpoQuery(pQuery) || assert((pQuery->checkBufferInLoop == 1 && pQuery->nAggTimeInterval == 0) || isPointInterpoQuery(pQuery) ||
isGroupbyNormalCol(pQuery->pGroupbyExpr)); isGroupbyNormalCol(pQuery->pGroupbyExpr));
vnodeMultiMeterMultiOutputProcessor(pQInfo); vnodeSTableSeqProcessor(pQInfo);
} }
/* record the total elapsed time */ /* record the total elapsed time */
......
...@@ -673,7 +673,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE ...@@ -673,7 +673,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
return pQInfo; return pQInfo;
} }
schedMsg.fp = vnodeSingleMeterQuery; schedMsg.fp = vnodeSingleTableQuery;
} }
/* /*
...@@ -891,7 +891,7 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) { ...@@ -891,7 +891,7 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
if (pQInfo->pMeterQuerySupporter != NULL) { if (pQInfo->pMeterQuerySupporter != NULL) {
if (pQInfo->pMeterQuerySupporter->pSidSet == NULL) { if (pQInfo->pMeterQuerySupporter->pSidSet == NULL) {
schedMsg.fp = vnodeSingleMeterQuery; schedMsg.fp = vnodeSingleTableQuery;
} else { // group by tag } else { // group by tag
schedMsg.fp = vnodeMultiMeterQuery; schedMsg.fp = vnodeMultiMeterQuery;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册