From a52c0cb5f23f62afb4e40adf20d0ee8b468e20c1 Mon Sep 17 00:00:00 2001 From: slzhou Date: Mon, 19 Sep 2022 14:01:12 +0800 Subject: [PATCH] fix: improve group by performance by skip sort when group by --- src/common/inc/tglobal.h | 2 ++ src/common/src/tglobal.c | 25 +++++++++++++++++++++++++ src/query/src/qExecutor.c | 4 ++-- src/util/inc/tconfig.h | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index e1b7cff8be..650bb6bb4e 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -67,6 +67,8 @@ extern int32_t tsCompressColData; extern int32_t tsMaxNumOfDistinctResults; extern char tsTempDir[]; extern int32_t tsShortcutFlag; +extern int32_t tsMaxSqlGroups; +extern int8_t tsSortWhenGroupBy; // query buffer management extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 77540cd0b6..d9b254a26a 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -118,6 +118,12 @@ int32_t tsRetryStreamCompDelay = 30 * 60 * 1000; // The delayed computing ration. 10% of the whole computing time window by default. float tsStreamComputDelayRatio = 0.1f; +// max supported groups for group by clause / interval clause +int32_t tsMaxSqlGroups = 1000000; + +// order by first group by column when group by +int8_t tsSortWhenGroupBy = 1; + int32_t tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance @@ -1772,6 +1778,25 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "maxSqlGroups"; + cfg.ptr = &tsMaxSqlGroups; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 500000; + cfg.maxValue = 10000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + + cfg.option = "sortWhenGroupBy"; + cfg.ptr = &tsSortWhenGroupBy; + cfg.valType = TAOS_CFG_VTYPE_INT8; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + #ifdef TD_TSZ // lossy compress cfg.option = "lossyColumns"; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index bb9ded8e40..47334ab81e 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -621,7 +621,7 @@ static SResultRow* doSetResultOutBufByKey(SQueryRuntimeEnv* pRuntimeEnv, SResult } // too many time window in query - if (pResultRowInfo->size > MAX_INTERVAL_TIME_WINDOW) { + if (pResultRowInfo->size > tsMaxSqlGroups) { longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW); } @@ -7607,7 +7607,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) { } initGroupResInfo(&pRuntimeEnv->groupResInfo, &pInfo->binfo.resultRowInfo); - if (!pRuntimeEnv->pQueryAttr->stableQuery) { + if (!pRuntimeEnv->pQueryAttr->stableQuery && tsSortWhenGroupBy) { sortGroupResByOrderList(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes, pInfo->binfo.pCtx); } diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index 872da82a8e..a2c2937722 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define TSDB_CFG_MAX_NUM 134 +#define TSDB_CFG_MAX_NUM 136 #define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_VALUE_LEN 41 -- GitLab