From 58c75dde6ff082a1cbb9070b76a619d8bd3265dc Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 1 Dec 2022 11:38:34 +0800 Subject: [PATCH] fix: add seperate group for normal table when group by db_name/stbable_name --- source/dnode/vnode/inc/vnode.h | 26 +++++++++--------- source/dnode/vnode/src/meta/metaQuery.c | 4 +++ source/libs/executor/src/scanoperator.c | 35 ++++++++++++++----------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index fe2892a76b..756e23deeb 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -107,23 +107,23 @@ int32_t metaReadNext(SMetaReader *pReader); const void *metaGetTableTagVal(void *tag, int16_t type, STagVal *tagVal); int metaGetTableNameByUid(void *meta, uint64_t uid, char *tbName); -int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName); -int metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid); -int metaGetTableTypeByName(void *meta, char *tbName, ETableType *tbType); -bool metaIsTableExist(SMeta *pMeta, tb_uid_t uid); -int32_t metaGetCachedTableUidList(SMeta *pMeta, tb_uid_t suid, const uint8_t *key, int32_t keyLen, SArray *pList, - bool *acquired); -int32_t metaUidFilterCachePut(SMeta *pMeta, uint64_t suid, const void *pKey, int32_t keyLen, void *pPayload, - int32_t payloadLen, double selectivityRatio); -int32_t metaUidCacheClear(SMeta *pMeta, uint64_t suid); -tb_uid_t metaGetTableEntryUidByName(SMeta* pMeta, const char* name); -int64_t metaGetTbNum(SMeta* pMeta); - +int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName); +int metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid); +int metaGetTableTypeByName(void *meta, char *tbName, ETableType *tbType); +bool metaIsTableExist(SMeta *pMeta, tb_uid_t uid); +int32_t metaGetCachedTableUidList(SMeta *pMeta, tb_uid_t suid, const uint8_t *key, int32_t keyLen, SArray *pList, + bool *acquired); +int32_t metaUidFilterCachePut(SMeta *pMeta, uint64_t suid, const void *pKey, int32_t keyLen, void *pPayload, + int32_t payloadLen, double selectivityRatio); +int32_t metaUidCacheClear(SMeta *pMeta, uint64_t suid); +tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name); +int64_t metaGetTbNum(SMeta *pMeta); +int64_t metaGetNtbNum(SMeta *pMeta); typedef struct { int64_t uid; int64_t ctbNum; } SMetaStbStats; -int32_t metaGetStbStats(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo); +int32_t metaGetStbStats(SMeta *pMeta, int64_t uid, SMetaStbStats *pInfo); typedef struct SMetaFltParam { tb_uid_t suid; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 8fb93f2c2e..cfdb4ab8d1 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -756,6 +756,10 @@ int64_t metaGetTimeSeriesNum(SMeta *pMeta) { return pMeta->pVnode->config.vndStats.numOfTimeSeries + pMeta->pVnode->config.vndStats.numOfNTimeSeries; } +int64_t metaGetNtbNum(SMeta *pMeta) { + return pMeta->pVnode->config.vndStats.numOfNTables; +} + typedef struct { SMeta *pMeta; TBC *pCur; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index db508b43f9..437e3e1393 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -3050,7 +3050,7 @@ _error: void fillTableCountScanDataBlock(STableCountScanSupp* pSupp, char* dbName, char* stbName, int64_t count, SSDataBlock* pRes) { if (pSupp->dbNameSlotId != -1) { - ASSERT(strlen(dbName)); + ASSERT(strlen(pSupp->dbName)); SColumnInfoData* colInfoData = taosArrayGet(pRes->pDataBlock, pSupp->dbNameSlotId); char varDbName[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; strncpy(varDataVal(varDbName), dbName, strlen(dbName)); @@ -3059,12 +3059,15 @@ void fillTableCountScanDataBlock(STableCountScanSupp* pSupp, char* dbName, char* } if (pSupp->stbNameSlotId != -1) { - ASSERT(strlen(stbName)); SColumnInfoData* colInfoData = taosArrayGet(pRes->pDataBlock, pSupp->stbNameSlotId); - char varStbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - strncpy(varDataVal(varStbName), stbName, strlen(stbName)); - varDataSetLen(varStbName, strlen(stbName)); - colDataAppend(colInfoData, 0, varStbName, false); + if (strlen(stbName) != 0) { + char varStbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + strncpy(varDataVal(varStbName), stbName, strlen(stbName)); + varDataSetLen(varStbName, strlen(stbName)); + colDataAppend(colInfoData, 0, varStbName, false); + } else { + colDataAppendNULL(colInfoData, 0); + } } if (pSupp->tbCountSlotId != -1) { @@ -3084,10 +3087,6 @@ static SSDataBlock* buildSysDbTableCount(SOperatorInfo* pOperator, STableCountSc getPerfDbMeta(NULL, &perfdbTableNum); if (pSupp->groupByDbName) { - if (pSupp->groupByStbName) { - setOperatorCompleted(pOperator); - return NULL; - } if (pInfo->currGrpIdx == 0) { uint64_t groupId = calcGroupId(TSDB_INFORMATION_SCHEMA_DB, strlen(TSDB_INFORMATION_SCHEMA_DB)); pRes->info.id.groupId = groupId; @@ -3121,10 +3120,7 @@ static SSDataBlock* doTableCountScan(SOperatorInfo* pOperator) { STableCountScanSupp* pSupp = &pInfo->supp; SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); - // compute group id must, but output is according to scancols. output group by group - // grouptags high priority(groupid<=>grouptag), then tablename(dbname,tableName). - // scanCols, (grouptags cols) - // mnode, query table count of information_schema and performance_schema + if (pOperator->status == OP_EXEC_DONE) { return NULL; } @@ -3145,7 +3141,6 @@ static SSDataBlock* doTableCountScan(SOperatorInfo* pOperator) { } if (pSupp->groupByDbName) { if (pSupp->groupByStbName) { - // group by db_name and stable_name if (pInfo->stbUidList == NULL) { pInfo->stbUidList = taosArrayInit(16, sizeof(tb_uid_t)); if (vnodeGetStbIdList(pInfo->readHandle.vnode, 0, pInfo->stbUidList) < 0) { @@ -3169,13 +3164,21 @@ static SSDataBlock* doTableCountScan(SOperatorInfo* pOperator) { fillTableCountScanDataBlock(pSupp, dbName, stbName, ctbNum, pRes); + pInfo->currGrpIdx++; + } else if (pInfo->currGrpIdx == taosArrayGetSize(pInfo->stbUidList)) { + char fullStbName[TSDB_TABLE_FNAME_LEN] = {0}; + snprintf(fullStbName, TSDB_TABLE_FNAME_LEN, "%s.%s", dbName, ""); + uint64_t groupId = calcGroupId(fullStbName, strlen(fullStbName)); + pRes->info.id.groupId = groupId; + int64_t ntbNum = metaGetNtbNum(pInfo->readHandle.meta); + fillTableCountScanDataBlock(pSupp, dbName, "", ntbNum, pRes); + pInfo->currGrpIdx++; } else { setOperatorCompleted(pOperator); return NULL; } } else { - // group by only db_name uint64_t groupId = calcGroupId(dbName, strlen(dbName)); pRes->info.id.groupId = groupId; int64_t dbTableCount = metaGetTbNum(pInfo->readHandle.meta); -- GitLab