diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 17c70125eebb2ef4c2f7a4c62d9ff2e022b5889c..8eb7f15fde6a878ff617e047826df91c9e2c1878 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -10081,7 +10081,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { size_t tableMetaCapacity = 0; SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); - pCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + pCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); tableNameList = taosArrayInit(4, sizeof(SName)); size_t size = taosArrayGetSize(pInfo->list); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 212787bce55b5f768a511d290d6dc6203a9202d9..8cc28bb2ca8a8ce678dceab83c05dd1ff73d250b 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2564,7 +2564,7 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { } if (pParentCmd->pTableMetaMap == NULL) { - pParentCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + pParentCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); } for (int32_t i = 0; i < pMultiMeta->numOfTables; i++) { @@ -3391,8 +3391,11 @@ int tscRenewTableMeta(SSqlObj *pSql) { tscResetSqlCmd(pCmd, true, pSql->self); SSqlCmd* pCmd2 = &pSql->rootObj->cmd; - pCmd2->pTableMetaMap = tscCleanupTableMetaMap(pCmd2->pTableMetaMap); - pCmd2->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + SHashObj *pmap = pCmd2->pTableMetaMap; + if (pmap == atomic_val_compare_exchange_ptr(&pCmd2->pTableMetaMap, pmap, NULL)) { + tscCleanupTableMetaMap(pCmd2->pTableMetaMap); + } + pCmd2->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); pSql->rootObj->retryReason = pSql->retryReason; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index ca242d8fe96a157d1d0f77021a550fdada95c923..9acebc3a28d5ffab6404f4fa847312f13ccc1208 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -1179,7 +1179,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { return code; } - pSql->cmd.pTableMetaMap = taosHashInit(taosArrayGetSize(plist), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + pSql->cmd.pTableMetaMap = taosHashInit(taosArrayGetSize(plist), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); registerSqlObj(pSql); tscDebug("0x%"PRIx64" load multiple table meta, tableNameList: %s pObj:%p", pSql->self, tableNameList, pObj); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 02459555bf0f6d33d812beaa17f1b8d080f09f69..000c0210cabd5e4bbf4d9fec820ce917d1a374d9 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1647,7 +1647,10 @@ void tscResetSqlCmd(SSqlCmd* pCmd, bool clearCachedMeta, uint64_t id) { pCmd->insertParam.tagData.dataLen = 0; tscFreeQueryInfo(pCmd, clearCachedMeta, id); - pCmd->pTableMetaMap = tscCleanupTableMetaMap(pCmd->pTableMetaMap); + SHashObj *pmap = pCmd->pTableMetaMap; + if (pmap == atomic_val_compare_exchange_ptr(&pCmd->pTableMetaMap, pmap, NULL)) { + tscCleanupTableMetaMap(pCmd->pTableMetaMap); + } taosReleaseRef(tscObjRef, id); } diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index e1b7cff8be8c551d0985ea293fcaff3b52f0d97b..650bb6bb4e6acd013bcfe3e9a43e67309ce0f570 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 77540cd0b61ed54c461fa44984abd20d507a74ab..6260b22c81112647e605247621fdecb0524c43ff 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,26 @@ 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; + taosInitConfigOption(cfg); + + 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/kit/taos-tools b/src/kit/taos-tools index e7270c90fd1888842a45d47700040d3f86ebaf5f..285b5e0f1ce6dd6e70c22508c0285484608e2843 160000 --- a/src/kit/taos-tools +++ b/src/kit/taos-tools @@ -1 +1 @@ -Subproject commit e7270c90fd1888842a45d47700040d3f86ebaf5f +Subproject commit 285b5e0f1ce6dd6e70c22508c0285484608e2843 diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index bb9ded8e40258060cc6a80c4bb0e2ecd42bc74a0..dca79babce9388d7f2d1750db2c9b8410b23c8d1 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); } @@ -1925,7 +1925,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo* pIn STimeWindow w = TSWINDOW_INITIALIZER; char* key = NULL; - int16_t num = 0; + int32_t num = 0; int32_t type = 0; for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { buildGroupbyKeyBuf(pSDataBlock, pInfo, j, &key); @@ -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 872da82a8e16549facd03fb3249b03b150a8f842..a2c293772213fe804bc49fb2b74b9cc557dca269 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