From 1286f7473cc2a4ece9f0ea1789f68f6a97d7a73c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 28 Sep 2022 22:07:16 +0800 Subject: [PATCH 01/11] QRY: opt tbname in --- source/dnode/vnode/inc/vnode.h | 3 ++ source/dnode/vnode/src/meta/metaOpen.c | 12 ++--- source/dnode/vnode/src/meta/metaQuery.c | 15 ++++++ source/dnode/vnode/src/vnd/vnodeQuery.c | 3 ++ source/libs/executor/src/executil.c | 68 +++++++++++++++++++++---- 5 files changed, 83 insertions(+), 18 deletions(-) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 6ba10641f5..35ea512f81 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -62,7 +62,9 @@ void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot); void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId); int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen); int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list); + int32_t vnodeGetCtbIdList(SVnode *pVnode, int64_t suid, SArray *list); +int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg); int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list); void *vnodeGetIdx(SVnode *pVnode); void *vnodeGetIvtIdx(SVnode *pVnode); @@ -96,6 +98,7 @@ int32_t metaGetTableTags(SMeta *pMeta, uint64_t suid, SArray *uidList, SHash 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 metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid); bool metaIsTableExist(SMeta *pMeta, tb_uid_t uid); typedef struct SMetaFltParam { diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index f8ecd17cb7..034d6260da 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -200,36 +200,30 @@ int metaClose(SMeta *pMeta) { int32_t metaRLock(SMeta *pMeta) { int32_t ret = 0; - metaTrace("meta rlock %p B", &pMeta->lock); + metaTrace("meta rlock %p", &pMeta->lock); ret = taosThreadRwlockRdlock(&pMeta->lock); - metaTrace("meta rlock %p E", &pMeta->lock); - return ret; } int32_t metaWLock(SMeta *pMeta) { int32_t ret = 0; - metaTrace("meta wlock %p B", &pMeta->lock); + metaTrace("meta wlock %p", &pMeta->lock); ret = taosThreadRwlockWrlock(&pMeta->lock); - metaTrace("meta wlock %p E", &pMeta->lock); - return ret; } int32_t metaULock(SMeta *pMeta) { int32_t ret = 0; - metaTrace("meta ulock %p B", &pMeta->lock); + metaTrace("meta ulock %p", &pMeta->lock); ret = taosThreadRwlockUnlock(&pMeta->lock); - metaTrace("meta ulock %p E", &pMeta->lock); - return ret; } diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index f549ef84f8..995e30bd4c 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -202,6 +202,21 @@ int metaGetTableNameByUid(void *meta, uint64_t uid, char *tbName) { return 0; } +int metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid) { + int code = 0; + SMetaReader mr = {0}; + metaReaderInit(&mr, (SMeta *)meta, 0); + code = metaGetTableEntryByName(&mr, tbName); + if (code < 0) { + metaReaderClear(&mr); + return -1; + } + *uid = mr.me.uid; + + metaReaderClear(&mr); + + return 0; +} int metaReadNext(SMetaReader *pReader) { SMeta *pMeta = pReader->pMeta; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 825bf8a0a7..6806c034dc 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -409,6 +409,9 @@ int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) { return TSDB_CODE_SUCCESS; } +int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg) { + return 0; +} int32_t vnodeGetCtbIdList(SVnode *pVnode, int64_t suid, SArray *list) { SMCtbCursor *pCur = metaOpenCtbCursor(pVnode->pMeta, suid); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index b26603b394..fa0142973b 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -26,6 +26,8 @@ #include "executorimpl.h" #include "tcompression.h" +static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond); + void initResultRowInfo(SResultRowInfo* pResultRowInfo) { pResultRowInfo->size = 0; pResultRowInfo->cur.pageId = -1; @@ -407,11 +409,15 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, uint64_t suid, SArray // int64_t stt = taosGetTimestampUs(); tags = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - code = metaGetTableTags(metaHandle, suid, uidList, tags); - if (code != TSDB_CODE_SUCCESS) { - qError("failed to get table tags from meta, reason:%s, suid:%" PRIu64, tstrerror(code), suid); - terrno = code; - goto end; + + int32_t filter = optimizeTbnameInCond(metaHandle, suid, uidList, pTagCond); + if (filter == -1) { + code = metaGetTableTags(metaHandle, suid, uidList, tags); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table tags from meta, reason:%s, suid:%" PRIu64, tstrerror(code), suid); + terrno = code; + goto end; + } } int32_t rows = taosArrayGetSize(uidList); @@ -742,6 +748,53 @@ end: return code; } +static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond) { + if (nodeType(pTagCond) != QUERY_NODE_OPERATOR) { + return -1; + } + SOperatorNode* pNode = (SOperatorNode*)pTagCond; + if (pNode->opType != OP_TYPE_IN) { + return -1; + } + if ((pNode->pLeft != NULL && nodeType(pNode->pLeft) == QUERY_NODE_COLUMN && + ((SColumnNode*)pNode->pLeft)->colType == COLUMN_TYPE_TBNAME) && + (pNode->pRight != NULL && nodeType(pNode->pRight) == QUERY_NODE_NODE_LIST)) { + SNodeListNode* pList = (SNodeListNode*)pNode->pRight; + + int32_t len = LIST_LENGTH(pList->pNodeList); + if (len <= 0) return -1; + + SListCell* cell = pList->pNodeList->pHead; + + SArray* pTbList = taosArrayInit(len, sizeof(void*)); + for (int i = 0; i < pList->pNodeList->length; i++) { + SValueNode* valueNode = (SValueNode*)cell->pNode; + if (!IS_VAR_DATA_TYPE(valueNode->node.resType.type)) { + taosArrayDestroy(pTbList); + return -1; + } + char* name = varDataVal(valueNode->datum.p); + taosArrayPush(pTbList, &name); + + cell = cell->pNext; + } + + for (int i = 0; i < taosArrayGetSize(pTbList); i++) { + char* name = taosArrayGetP(pTbList, i); + uint64_t uid = 0; + if (metaGetTableUidByName(metaHandle, name, &uid) == 0) { + taosArrayPush(list, &uid); + } else { + terrno = 0; + qError("failed to get tableIds from by table name: %s", name); + taosArrayDestroy(pTbList); + return -1; + } + } + taosArrayDestroy(pTbList); + } + return -1; +} int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond, STableListInfo* pListInfo) { int32_t code = TSDB_CODE_SUCCESS; @@ -767,9 +820,6 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, qError("failed to get tableIds from index, reason:%s, suid:%" PRIu64, tstrerror(code), tableUid); code = TDB_CODE_SUCCESS; } - - // int64_t stt1 = taosGetTimestampUs(); - // qDebug("generate table list, cost:%ld us", stt1-stt); } else if (!pTagCond) { vnodeGetCtbIdList(pVnode, pScanNode->suid, res); } @@ -813,7 +863,7 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, size_t numOfTables = taosArrayGetSize(res); for (int i = 0; i < numOfTables; i++) { STableKeyInfo info = {.uid = *(uint64_t*)taosArrayGet(res, i), .groupId = 0}; - void* p = taosArrayPush(pListInfo->pTableList, &info); + void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { taosArrayDestroy(res); return TSDB_CODE_OUT_OF_MEMORY; From 5b4d0eaabe6cf34bf7d6f1af77b77a68f6f5236d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 11:07:32 +0800 Subject: [PATCH 02/11] enh: opt tbname in --- source/dnode/vnode/src/inc/vnodeInt.h | 38 +++++++++++++------------ source/dnode/vnode/src/meta/metaQuery.c | 11 +++++-- source/libs/executor/src/executil.c | 8 +++--- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 4c8045d651..ec570b4540 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -111,22 +111,23 @@ SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, boo STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver); int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema); int metaGetTableEntryByName(SMetaReader* pReader, const char* name); -tb_uid_t metaGetTableEntryUidByName(SMeta* pMeta, const char* name); -int64_t metaGetTbNum(SMeta* pMeta); -int64_t metaGetTimeSeriesNum(SMeta* pMeta); -SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid); -void metaCloseCtbCursor(SMCtbCursor* pCtbCur); -tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur); -SMStbCursor* metaOpenStbCursor(SMeta* pMeta, tb_uid_t uid); -void metaCloseStbCursor(SMStbCursor* pStbCur); -tb_uid_t metaStbCursorNext(SMStbCursor* pStbCur); -STSma* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid); -STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid, bool deepCopy); -SArray* metaGetSmaIdsByTable(SMeta* pMeta, tb_uid_t uid); -SArray* metaGetSmaTbUids(SMeta* pMeta); -void* metaGetIdx(SMeta* pMeta); -void* metaGetIvtIdx(SMeta* pMeta); -int metaTtlSmaller(SMeta* pMeta, uint64_t time, SArray* uidList); + +tb_uid_t metaGetTableEntryUidByName(SMeta* pMeta, const char* name); +int64_t metaGetTbNum(SMeta* pMeta); +int64_t metaGetTimeSeriesNum(SMeta* pMeta); +SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid); +void metaCloseCtbCursor(SMCtbCursor* pCtbCur); +tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur); +SMStbCursor* metaOpenStbCursor(SMeta* pMeta, tb_uid_t uid); +void metaCloseStbCursor(SMStbCursor* pStbCur); +tb_uid_t metaStbCursorNext(SMStbCursor* pStbCur); +STSma* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid); +STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid, bool deepCopy); +SArray* metaGetSmaIdsByTable(SMeta* pMeta, tb_uid_t uid); +SArray* metaGetSmaTbUids(SMeta* pMeta); +void* metaGetIdx(SMeta* pMeta); +void* metaGetIvtIdx(SMeta* pMeta); +int metaTtlSmaller(SMeta* pMeta, uint64_t time, SArray* uidList); int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg); int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid); @@ -184,8 +185,9 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg); -SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema, SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, - const char* stbFullName, SBatchDeleteReq* pDeleteReq); +SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema, + SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName, + SBatchDeleteReq* pDeleteReq); // sma int32_t smaInit(); diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 995e30bd4c..33af87bf73 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -206,13 +206,18 @@ int metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid) { int code = 0; SMetaReader mr = {0}; metaReaderInit(&mr, (SMeta *)meta, 0); - code = metaGetTableEntryByName(&mr, tbName); - if (code < 0) { + + SMeta *pMeta = mr.pMeta; + SMetaReader *pReader = &mr; + + // query name.idx + if (tdbTbGet(pMeta->pNameIdx, tbName, strlen(tbName) + 1, &pReader->pBuf, &pReader->szBuf) < 0) { + terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; metaReaderClear(&mr); return -1; } - *uid = mr.me.uid; + *uid = *(tb_uid_t *)pReader->pBuf; metaReaderClear(&mr); return 0; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index fa0142973b..1ece2f902f 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -418,6 +418,8 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, uint64_t suid, SArray terrno = code; goto end; } + } else { + qInfo("succ to get table from meta, suid:%" PRIu64, suid); } int32_t rows = taosArrayGetSize(uidList); @@ -785,15 +787,13 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list if (metaGetTableUidByName(metaHandle, name, &uid) == 0) { taosArrayPush(list, &uid); } else { + qWarn("failed to get tableIds from by table name: %s, reason: %s", name, tstrerror(terrno)); terrno = 0; - qError("failed to get tableIds from by table name: %s", name); - taosArrayDestroy(pTbList); - return -1; } } taosArrayDestroy(pTbList); } - return -1; + return 0; } int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond, STableListInfo* pListInfo) { From 4977e2e676f7daca2c4aba3ee8f2d88fbd7f6d8a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 18:35:12 +0800 Subject: [PATCH 03/11] opt tbname in --- include/libs/index/index.h | 6 ++++ source/dnode/mgmt/node_mgmt/src/dmMgmt.c | 2 ++ source/libs/executor/src/executil.c | 40 ++++++++++++++++++++++-- source/libs/index/src/index.c | 12 +++++-- source/libs/index/src/indexCache.c | 2 +- source/libs/transport/src/transComm.c | 2 +- 6 files changed, 57 insertions(+), 7 deletions(-) diff --git a/include/libs/index/index.h b/include/libs/index/index.h index c1fdc4df52..a6e6373325 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -225,6 +225,12 @@ typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltS SIdxFltStatus idxGetFltStatus(SNode* pFilterNode); int32_t doFilterTag(SNode* pFilterNode, SIndexMetaArg* metaArg, SArray* result, SIdxFltStatus* status); + +/* + * init index env + * + */ +void indexInit(int32_t threads); /* * destory index env * diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index 582b16ce99..2e149be3b6 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -193,6 +193,8 @@ int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) { goto _OVER; } + indexInit(tsNumOfCommitThreads); + dmReportStartup("dnode-transport", "initialized"); dDebug("dnode is created, ptr:%p", pDnode); code = 0; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 1ece2f902f..9da48dac86 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -27,6 +27,7 @@ #include "tcompression.h" static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond); +static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond); void initResultRowInfo(SResultRowInfo* pResultRowInfo) { pResultRowInfo->size = 0; @@ -750,7 +751,43 @@ end: return code; } -static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond) { +static int tableUidCompare(const void* a, const void* b) { + uint64_t u1 = *(uint64_t*)a; + uint64_t u2 = *(uint64_t*)b; + if (u1 == u2) { + return 0; + } + return u1 < u2 ? -1 : 1; +} +static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* cond) { + if (nodeType(cond) == QUERY_NODE_OPERATOR) { + return optimizeTbnameInCondImpl(metaHandle, suid, list, cond); + } + + if (nodeType(cond) != QUERY_NODE_LOGIC_CONDITION || ((SLogicConditionNode*)cond)->condType != LOGIC_COND_TYPE_AND) { + return -1; + } + + SLogicConditionNode* pNode = (SLogicConditionNode*)cond; + SNodeListNode* pList = (SNodeListNode*)pNode->pParameterList; + int32_t len = LIST_LENGTH(pList->pNodeList); + + bool hasTbnameCond = false; + if (len <= 0) return -1; + + SListCell* cell = pList->pNodeList->pHead; + for (int i = 0; i < len; i++) { + if (cell && optimizeTbnameInCondImpl(metaHandle, suid, list, cell->pNode) == 0) { + hasTbnameCond = true; + } + cell = cell->pNext; + } + taosArraySort(list, tableUidCompare); + taosArrayRemoveDuplicate(list, tableUidCompare, NULL); + + return hasTbnameCond == true ? 0 : -1; +} +static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond) { if (nodeType(pTagCond) != QUERY_NODE_OPERATOR) { return -1; } @@ -777,7 +814,6 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list } char* name = varDataVal(valueNode->datum.p); taosArrayPush(pTbList, &name); - cell = cell->pNext; } diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index f507e1b3be..cb671cfff9 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -54,11 +54,17 @@ void* indexQhandle = NULL; int32_t indexRefMgt; +int32_t indexThreads = 5; + static void indexDestroy(void* sIdx); -void indexInit() { +void indexInit(int32_t threadNum) { + indexThreads = threadNum; + if (indexThreads <= 1) indexThreads = INDEX_NUM_OF_THREADS; +} +void indexEnvInit() { // refactor later - indexQhandle = taosInitScheduler(INDEX_QUEUE_SIZE, INDEX_NUM_OF_THREADS, "index", NULL); + indexQhandle = taosInitScheduler(INDEX_QUEUE_SIZE, indexThreads, "index", NULL); indexRefMgt = taosOpenRef(1000, indexDestroy); } void indexCleanup() { @@ -99,7 +105,7 @@ static void indexWait(void* idx) { int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { int ret = TSDB_CODE_SUCCESS; - taosThreadOnce(&isInit, indexInit); + taosThreadOnce(&isInit, indexEnvInit); SIndex* idx = taosMemoryCalloc(1, sizeof(SIndex)); if (idx == NULL) { return TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index 39bba4e269..72f693f7e5 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -22,7 +22,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later #define MEM_TERM_LIMIT 10 * 10000 -#define MEM_THRESHOLD 512 * 1024 +#define MEM_THRESHOLD 8 * 512 * 1024 // 8M #define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20 #define MEM_ESTIMATE_RADIO 1.5 diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 5f3171ee0e..ae9f3155b4 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -193,7 +193,7 @@ bool transReadComplete(SConnBuffer* connBuf) { int transSetConnOption(uv_tcp_t* stream) { uv_tcp_nodelay(stream, 1); - int ret = uv_tcp_keepalive(stream, 5, 5); + int ret = uv_tcp_keepalive(stream, 5, 60); return ret; } From 50478a31cc2789f8747146176d69d2935fbd36d9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 20:30:32 +0800 Subject: [PATCH 04/11] opt tbname in --- source/libs/executor/src/executil.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 9da48dac86..887493a485 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -768,16 +768,17 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list return -1; } + bool hasTbnameCond = false; SLogicConditionNode* pNode = (SLogicConditionNode*)cond; SNodeListNode* pList = (SNodeListNode*)pNode->pParameterList; - int32_t len = LIST_LENGTH(pList->pNodeList); - bool hasTbnameCond = false; + int32_t len = LIST_LENGTH(pList->pNodeList); if (len <= 0) return -1; SListCell* cell = pList->pNodeList->pHead; for (int i = 0; i < len; i++) { - if (cell && optimizeTbnameInCondImpl(metaHandle, suid, list, cell->pNode) == 0) { + if (cell == NULL) break; + if (optimizeTbnameInCondImpl(metaHandle, suid, list, cell->pNode) == 0) { hasTbnameCond = true; } cell = cell->pNext; From 47234dfeecbb0edf87c2a35e75dc3cca0278b1ac Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 20:37:23 +0800 Subject: [PATCH 05/11] opt tbname in --- source/libs/executor/src/executil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 887493a485..8679fa1297 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -420,7 +420,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, uint64_t suid, SArray goto end; } } else { - qInfo("succ to get table from meta, suid:%" PRIu64, suid); + qInfo("succ to get table from meta idx, suid:%" PRIu64, suid); } int32_t rows = taosArrayGetSize(uidList); From 02310d59526f7a9bdb93f69ddd17fadb8058ca05 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 21:35:14 +0800 Subject: [PATCH 06/11] fix invalid read --- source/libs/executor/src/executil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 8679fa1297..bd24dd0315 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -770,12 +770,12 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list bool hasTbnameCond = false; SLogicConditionNode* pNode = (SLogicConditionNode*)cond; - SNodeListNode* pList = (SNodeListNode*)pNode->pParameterList; + SNodeList* pList = (SNodeList*)pNode->pParameterList; - int32_t len = LIST_LENGTH(pList->pNodeList); + int32_t len = LIST_LENGTH(pList); if (len <= 0) return -1; - SListCell* cell = pList->pNodeList->pHead; + SListCell* cell = pList->pHead; for (int i = 0; i < len; i++) { if (cell == NULL) break; if (optimizeTbnameInCondImpl(metaHandle, suid, list, cell->pNode) == 0) { From 1148ae8f6ea1ee6349ecaba642751c727676987a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 21:53:39 +0800 Subject: [PATCH 07/11] opt tbname in --- source/libs/executor/src/executil.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index bd24dd0315..cdd2a2efad 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -829,8 +829,9 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* } } taosArrayDestroy(pTbList); + return 0; } - return 0; + return -1; } int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond, STableListInfo* pListInfo) { From d74779805abb301e71e4d99abff845b377eb0ff4 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 23:13:54 +0800 Subject: [PATCH 08/11] opt tbname in --- source/dnode/vnode/inc/vnode.h | 1 + source/dnode/vnode/src/meta/metaQuery.c | 14 ++++++++++++++ source/libs/executor/src/executil.c | 1 + 3 files changed, 16 insertions(+) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 35ea512f81..c37cecc06d 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -95,6 +95,7 @@ void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags); void metaReaderClear(SMetaReader *pReader); int32_t metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid); int32_t metaGetTableTags(SMeta *pMeta, uint64_t suid, SArray *uidList, SHashObj *tags); +int32_t metaGetTableTagsOpt(SMeta *pMeta, uint64_t suid, SArray *uidList, SHashObj *tags); int32_t metaReadNext(SMetaReader *pReader); const void *metaGetTableTagVal(void *tag, int16_t type, STagVal *tagVal); int metaGetTableNameByUid(void *meta, uint64_t uid, char *tbName); diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 7ddcd20d22..a20bae8a2d 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -1122,6 +1122,20 @@ END: return ret; } +int32_t metaGetTableTagsOpt(SMeta *pMeta, uint64_t suid, SArray *uidList, SHashObj *tags) { + int32_t sz = uidList ? taosArrayGetSize(uidList) : 0; + for (int i = 0; i < sz; i++) { + tb_uid_t *id = taosArrayGet(uidList, i); + SCtbIdxKey ctbIdxKey = {.suid = suid, .uid = *id}; + + void *val = NULL; + int32_t len = 0; + if (0 == tdbTbGet(pMeta->pCtbIdx, &ctbIdxKey, sizeof(SCtbIdxKey), &val, &len)) { + taosHashPut(tags, id, sizeof(tb_uid_t), val, len); + } + } + return 0; +} int32_t metaGetTableTags(SMeta *pMeta, uint64_t suid, SArray *uidList, SHashObj *tags) { SMCtbCursor *pCur = metaOpenCtbCursor(pMeta, suid); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index cdd2a2efad..82ee6265f8 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -420,6 +420,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, uint64_t suid, SArray goto end; } } else { + metaGetTableTagsOpt(metaHandle, suid, uidList, tags); qInfo("succ to get table from meta idx, suid:%" PRIu64, suid); } From 6445ee8ad6d6ff84e8ef34c32da072fbee534860 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 29 Sep 2022 23:56:07 +0800 Subject: [PATCH 09/11] opt tbname in --- include/libs/index/index.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/libs/index/index.h b/include/libs/index/index.h index a6e6373325..0d31ca2f68 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -206,12 +206,6 @@ void indexJsonRebuild(SIndexJson* idx, void* iter); **/ bool indexJsonIsRebuild(SIndexJson* idx); -/* - * init index env - * - */ -void indexInit(); - /* index filter */ typedef struct SIndexMetaArg { void* metaEx; From 0d3da109543ec988aa0f732e7a679dc8c1dcd4c1 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 30 Sep 2022 09:31:19 +0800 Subject: [PATCH 10/11] fix invalid read --- source/dnode/vnode/inc/vnode.h | 1 + source/dnode/vnode/src/meta/metaQuery.c | 15 ++++++++++++++- source/libs/executor/src/executil.c | 8 +++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index c37cecc06d..2cc22a4298 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -100,6 +100,7 @@ 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 metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid); +int metaGetTableTypeByName(void *meta, char *tbName, ETableType *tbType); bool metaIsTableExist(SMeta *pMeta, tb_uid_t uid); typedef struct SMetaFltParam { diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index a20bae8a2d..d499db4958 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -223,6 +223,18 @@ int metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid) { return 0; } +int metaGetTableTypeByName(void *meta, char *tbName, ETableType *tbType) { + int code = 0; + SMetaReader mr = {0}; + metaReaderInit(&mr, (SMeta *)meta, 0); + + if (metaGetTableEntryByName(&mr, tbName) == 0) { + *tbType = mr.me.type; + } + metaReaderClear(&mr); + return 0; +} + int metaReadNext(SMetaReader *pReader) { SMeta *pMeta = pReader->pMeta; @@ -1130,7 +1142,8 @@ int32_t metaGetTableTagsOpt(SMeta *pMeta, uint64_t suid, SArray *uidList, SHashO void *val = NULL; int32_t len = 0; - if (0 == tdbTbGet(pMeta->pCtbIdx, &ctbIdxKey, sizeof(SCtbIdxKey), &val, &len)) { + if (taosHashGet(tags, id, sizeof(tb_uid_t)) == NULL && + 0 == tdbTbGet(pMeta->pCtbIdx, &ctbIdxKey, sizeof(SCtbIdxKey), &val, &len)) { taosHashPut(tags, id, sizeof(tb_uid_t), val, len); } } diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 82ee6265f8..38304bcc76 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -823,7 +823,13 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* char* name = taosArrayGetP(pTbList, i); uint64_t uid = 0; if (metaGetTableUidByName(metaHandle, name, &uid) == 0) { - taosArrayPush(list, &uid); + ETableType tbType = TSDB_TABLE_MAX; + if (metaGetTableTypeByName(metaHandle, name, &tbType) == 0 && tbType == TSDB_CHILD_TABLE) { + taosArrayPush(list, &uid); + } else { + taosArrayDestroy(pTbList); + return -1; + } } else { qWarn("failed to get tableIds from by table name: %s, reason: %s", name, tstrerror(terrno)); terrno = 0; From 3a9dee68cb21c519b2288d470c6385ce92aa6ec5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 30 Sep 2022 11:30:07 +0800 Subject: [PATCH 11/11] opt tbname in --- source/libs/index/src/indexTfile.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 1fc631e9f3..f3009c051b 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -555,6 +555,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { taosArraySort(v->tableId, idxUidCompare); taosArrayRemoveDuplicate(v->tableId, idxUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); + if (tbsz == 0) continue; fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } tfileWriteFstOffset(tw, fstOffset); @@ -566,6 +567,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { TFileValue* v = taosArrayGetP((SArray*)data, i); int32_t tbsz = taosArrayGetSize(v->tableId); + if (tbsz == 0) continue; // check buf has enough space or not int32_t ttsz = TF_TABLE_TATOAL_SIZE(tbsz); @@ -592,6 +594,10 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { for (size_t i = 0; i < sz; i++) { // TODO, fst batch write later TFileValue* v = taosArrayGetP((SArray*)data, i); + + int32_t tbsz = taosArrayGetSize(v->tableId); + if (tbsz == 0) continue; + if (tfileWriteData(tw, v) != 0) { indexError("failed to write data: %s, offset: %d len: %d", v->colVal, v->offset, (int)taosArrayGetSize(v->tableId));