From f1181384eb9af127c9dd156364a0bb13a2214c72 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Mon, 26 Sep 2022 19:55:32 +0800 Subject: [PATCH] feat(query): change config to tsAggAlways and apply code --- src/common/inc/tglobal.h | 2 +- src/common/src/tglobal.c | 6 +++--- src/query/src/qAggMain.c | 8 +++++++- src/query/src/queryMain.c | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 80cef9a893..e5f90cb118 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -219,7 +219,7 @@ extern int32_t cqDebugFlag; extern int32_t debugFlag; extern int8_t tsClientMerge; -extern int8_t tsCountAlwaysReturnValue; +extern int8_t tsAggAlways; // probe alive connection extern int32_t tsProbeSeconds; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 41419cbc4e..d61c0677ae 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -273,7 +273,7 @@ int32_t cqDebugFlag = 131; int32_t fsDebugFlag = 135; int8_t tsClientMerge = 0; -int8_t tsCountAlwaysReturnValue = 0; +int8_t tsAggAlways = 0; // Agg function always return value even if zero row // probe alive connection int32_t tsProbeSeconds = 5 * 60; // start probe link alive after tsProbeSeconds from starting query @@ -1691,8 +1691,8 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); - cfg.option = "countAlwaysReturnValue"; - cfg.ptr = &tsCountAlwaysReturnValue; + cfg.option = "aggAlways"; + cfg.ptr = &tsAggAlways; cfg.valType = TAOS_CFG_VTYPE_INT8; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 0; diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index e8c0c8c3b8..9f15e2d937 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -30,6 +30,7 @@ #include "qUdf.h" #include "tcompare.h" #include "hashfunc.h" +#include "tglobal.h" #define GET_INPUT_DATA_LIST(x) ((char *)((x)->pInput)) #define GET_INPUT_DATA(x, y) (GET_INPUT_DATA_LIST(x) + (y) * (x)->inputBytes) @@ -936,7 +937,7 @@ static void count_function(SQLFunctionCtx *pCtx) { } } - if (numOfElem > 0 || tsCountAlwaysReturnValue) { + if (numOfElem > 0 || tsAggAlways) { GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG; *((int64_t *)pCtx->pOutput) += numOfElem; pCtx->resultInfo->numOfRes = 1; @@ -1156,6 +1157,11 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) { } } + // support always return value option + if(notNullElems == 0 && tsAggAlways) { + notNullElems = 1; + } + SET_VAL(pCtx, notNullElems, 1); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index 7187637b70..11d1dd1a9a 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -338,6 +338,27 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex return code; } +bool qFitAlwaysValue(SQInfo * pQInfo) { + // must agg query + if (pQInfo->query.simpleAgg) + return false; + + // must not include ts column + SSDataBlock* pBlock = pQInfo->runtimeEnv.outputBuf; + if (pBlock == NULL || pBlock->pDataBlock == NULL) + return false; + + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); + if (pColInfoData == NULL) + return false; + // must not first column is timestamp + if (pColInfoData->info.type == TSDB_DATA_TYPE_TIMESTAMP) + return false; + + // fit ok + return true; +} + int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *contLen, bool* continueExec) { SQInfo *pQInfo = (SQInfo *)qinfo; int32_t compLen = 0; @@ -350,6 +371,11 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; int32_t s = GET_NUM_OF_RESULTS(pRuntimeEnv); + if (s == 0 && tsAggAlways) { + if (qFitAlwaryValue(pQInfo)) + s = 1; + } + size_t size = pQueryAttr->resultRowSize * s; size += sizeof(int32_t); size += sizeof(STableIdInfo) * taosHashGetSize(pRuntimeEnv->pTableRetrieveTsMap); -- GitLab