diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 80cef9a893bbe15c8a187464fb9bfb51108e6017..e5f90cb11855ba338c3bd522054004545cfca1e2 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 41419cbc4ead207d757208492bd184079c94b084..d61c0677ae676e05bfbc05dd4e80e5e36b35ded2 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 e8c0c8c3b871794e1f790f6ff34764f2042bb1b1..9f15e2d93772a6b2a919edbd0e305351a7840291 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 7187637b705a0adb39b1da08a90989964139c746..11d1dd1a9afdb5deec9726158f83a0acc2f15f4b 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);