From 5c1be75b9b552eca5303e2f53cbe5607920fac12 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 13 May 2022 10:53:25 +0800 Subject: [PATCH 1/4] stmt query --- source/client/inc/clientStmt.h | 2 -- source/client/src/clientStmt.c | 52 +++++++++++++++------------------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/source/client/inc/clientStmt.h b/source/client/inc/clientStmt.h index ae27e611cb..a1c109eb20 100644 --- a/source/client/inc/clientStmt.h +++ b/source/client/inc/clientStmt.h @@ -71,7 +71,6 @@ typedef struct SStmtBindInfo { typedef struct SStmtExecInfo { int32_t affectedRows; - bool emptyRes; SRequestObj* pRequest; SHashObj* pVgHash; SHashObj* pBlockHash; @@ -87,7 +86,6 @@ typedef struct SStmtSQLInfo { char* sqlStr; int32_t sqlLen; SArray* nodeList; - SQueryPlan* pQueryPlan; SStmtQueryResInfo queryRes; bool autoCreateTbl; } SStmtSQLInfo; diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 29f965fd74..e295aaaee2 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -226,6 +226,7 @@ int32_t stmtParseSql(STscStmt* pStmt) { break; case QUERY_NODE_SELECT_STMT: pStmt->sql.type = STMT_TYPE_QUERY; + STMT_ERR_RET(stmtBackupQueryFields(pStmt)); break; default: tscError("not supported stmt type %d", nodeType(pStmt->sql.pQuery->pRoot)); @@ -279,7 +280,6 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool freeRequest) { } pStmt->exec.autoCreateTbl = false; - pStmt->exec.emptyRes = false; if (keepTable) { return TSDB_CODE_SUCCESS; @@ -298,7 +298,6 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) { taosMemoryFree(pStmt->sql.queryRes.userFields); taosMemoryFree(pStmt->sql.sqlStr); qDestroyQuery(pStmt->sql.pQuery); - qDestroyQueryPlan(pStmt->sql.pQueryPlan); taosArrayDestroy(pStmt->sql.nodeList); void* pIter = taosHashIterate(pStmt->sql.pTableCache, NULL); @@ -599,6 +598,8 @@ int32_t stmtFetchColFields(STscStmt* pStmt, int32_t* fieldNum, TAOS_FIELD** fiel int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { STscStmt* pStmt = (STscStmt*)stmt; + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { pStmt->bInfo.needParse = false; @@ -615,23 +616,29 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { if (pStmt->bInfo.needParse) { STMT_ERR_RET(stmtParseSql(pStmt)); + } else if (STMT_TYPE_QUERY == pStmt->sql.type) { + STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); } - STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); - if (STMT_TYPE_QUERY == pStmt->sql.type) { - if (NULL == pStmt->sql.pQueryPlan) { - STMT_ERR_RET(getQueryPlan(pStmt->exec.pRequest, pStmt->sql.pQuery, &pStmt->sql.nodeList)); - pStmt->sql.pQueryPlan = pStmt->exec.pRequest->body.pDag; - pStmt->exec.pRequest->body.pDag = NULL; - STMT_ERR_RET(stmtBackupQueryFields(pStmt)); - } else { - STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); - } + STMT_ERR_RET(qStmtBindParams(pStmt->sql.pQuery, bind, colIdx, pStmt->exec.pRequest->requestId)); + + SParseContext ctx = {.requestId = pStmt->exec.pRequest->requestId, + .acctId = pStmt->taos->acctId, + .db = pStmt->exec.pRequest->pDb, + .topicQuery = false, + .pSql = pStmt->sql.sqlStr, + .sqlLen = pStmt->sql.sqlLen, + .pMsg = pStmt->exec.pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, + .pTransporter = pStmt->taos->pAppInfo->pTransporter, + .pStmtCb = NULL, + .pUser = pStmt->taos->user}; + STMT_ERR_RET(qStmtParseQuerySql(&ctx, pStmt->sql.pQuery)); - STMT_RET(qStmtBindParam(pStmt->sql.pQueryPlan, bind, colIdx, pStmt->exec.pRequest->requestId, &pStmt->exec.emptyRes)); + return TSDB_CODE_SUCCESS; } - + STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); if (NULL == pDataBlock) { tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName); @@ -736,11 +743,7 @@ int stmtExec(TAOS_STMT *stmt) { STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); if (STMT_TYPE_QUERY == pStmt->sql.type) { - if (pStmt->exec.emptyRes) { - pStmt->exec.pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT; - } else { - scheduleQuery(pStmt->exec.pRequest, pStmt->sql.pQueryPlan, pStmt->sql.nodeList, NULL); - } + launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true, NULL); } else { STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->exec.pVgHash, pStmt->exec.pBlockHash)); launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true, (autoCreateTbl ? (void**)&pRsp : NULL)); @@ -839,16 +842,7 @@ int stmtGetParamNum(TAOS_STMT* stmt, int* nums) { } if (STMT_TYPE_QUERY == pStmt->sql.type) { - if (NULL == pStmt->sql.pQueryPlan) { - STMT_ERR_RET(getQueryPlan(pStmt->exec.pRequest, pStmt->sql.pQuery, &pStmt->sql.nodeList)); - pStmt->sql.pQueryPlan = pStmt->exec.pRequest->body.pDag; - pStmt->exec.pRequest->body.pDag = NULL; - STMT_ERR_RET(stmtBackupQueryFields(pStmt)); - } else { - STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); - } - - *nums = taosArrayGetSize(pStmt->sql.pQueryPlan->pPlaceholderValues); + *nums = taosArrayGetSize(pStmt->sql.pQuery->pPlaceholderValues); } else { STMT_ERR_RET(stmtFetchColFields(stmt, nums, NULL)); } From ce3b4b3183ae8c59dacd42e48a572a4cfc721897 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 13 May 2022 16:35:19 +0800 Subject: [PATCH 2/4] stmt query --- source/client/src/clientStmt.c | 20 +++++++++++-- source/libs/parser/src/parInsert.c | 12 +++++--- source/libs/parser/src/parser.c | 1 + tests/script/api/batchprepare.c | 45 ++++++++++++++++++++++-------- 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index e295aaaee2..1e9cb7b24f 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -226,7 +226,6 @@ int32_t stmtParseSql(STscStmt* pStmt) { break; case QUERY_NODE_SELECT_STMT: pStmt->sql.type = STMT_TYPE_QUERY; - STMT_ERR_RET(stmtBackupQueryFields(pStmt)); break; default: tscError("not supported stmt type %d", nodeType(pStmt->sql.pQuery->pRoot)); @@ -616,8 +615,6 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { if (pStmt->bInfo.needParse) { STMT_ERR_RET(stmtParseSql(pStmt)); - } else if (STMT_TYPE_QUERY == pStmt->sql.type) { - STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); } if (STMT_TYPE_QUERY == pStmt->sql.type) { @@ -634,8 +631,25 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { .pTransporter = pStmt->taos->pAppInfo->pTransporter, .pStmtCb = NULL, .pUser = pStmt->taos->user}; + ctx.mgmtEpSet = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); + STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &ctx.pCatalog)); + STMT_ERR_RET(qStmtParseQuerySql(&ctx, pStmt->sql.pQuery)); + if (pStmt->sql.pQuery->haveResultSet) { + setResSchemaInfo(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->pResSchema, pStmt->sql.pQuery->numOfResCols); + setResPrecision(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->precision); + } + + TSWAP(pStmt->exec.pRequest->dbList, pStmt->sql.pQuery->pDbList); + TSWAP(pStmt->exec.pRequest->tableList, pStmt->sql.pQuery->pTableList); + + //if (STMT_TYPE_QUERY == pStmt->sql.queryRes) { + // STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); + //} + + //STMT_ERR_RET(stmtBackupQueryFields(pStmt)); + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 228cb5a44b..cf18dfd9fa 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1227,16 +1227,20 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { if (NULL == *pQuery) { return TSDB_CODE_OUT_OF_MEMORY; } - (*pQuery)->pTableList = taosArrayInit(taosHashGetSize(context.pTableNameHashObj), sizeof(SName)); - if (NULL == (*pQuery)->pTableList) { - return TSDB_CODE_OUT_OF_MEMORY; - } + (*pQuery)->execMode = QUERY_EXEC_MODE_SCHEDULE; (*pQuery)->haveResultSet = false; (*pQuery)->msgType = TDMT_VND_SUBMIT; (*pQuery)->pRoot = (SNode*)context.pOutput; } + if (NULL == (*pQuery)->pTableList) { + (*pQuery)->pTableList = taosArrayInit(taosHashGetSize(context.pTableNameHashObj), sizeof(SName)); + if (NULL == (*pQuery)->pTableList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + context.pOutput->payloadType = PAYLOAD_TYPE_KV; int32_t code = skipInsertInto(&context); diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 2652078b96..5962867869 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -184,5 +184,6 @@ int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery) { if (TSDB_CODE_SUCCESS == code) { code = calculateConstant(pCxt, pQuery); } + return code; } diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index ae07b3fc8e..1c1b7c8eb3 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -9,10 +9,12 @@ #include #include "../../../include/client/taos.h" +#define FUNCTION_TEST_IDX 1 + int32_t shortColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT}; int32_t fullColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_TINYINT, TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_USMALLINT, TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_UINT, TSDB_DATA_TYPE_BIGINT, TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_BINARY, TSDB_DATA_TYPE_NCHAR}; -int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_NCHAR}; -int32_t optrIdxList[] = {0, 9}; +int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT}; +int32_t optrIdxList[] = {0, 1}; typedef struct { char* oper; @@ -53,7 +55,6 @@ FuncInfo funcInfo[] = { {"count", 1}, {"sum", 1}, {"min", 1}, - {"sin", 1}, }; char *bpStbPrefix = "st"; @@ -66,6 +67,10 @@ int32_t bpDefaultStbId = 1; //char *varoperatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in", "like", "not like", "match", "nmatch"}; #define tListLen(x) (sizeof(x) / sizeof((x)[0])) +#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT) +#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT) +#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE) +#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t))) typedef struct { int64_t* tsData; @@ -166,7 +171,7 @@ CaseCfg gCase[] = { {"insert:AUTO1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, true, true, insertAUTOTest1, 10, 10, 2, 0, 0, 0, 1, -1}, {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryColumnTest, 10, 10, 1, 3, 0, 0, 1, 2}, - {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryMiscTest, 2, 10, 1, 3, 0, 0, 1, 2}, + {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryMiscTest, 2, 10, 1, 1, 0, 0, 1, 2}, }; @@ -181,6 +186,7 @@ typedef struct { bool printQuerySql; bool printStmtSql; bool autoCreateTbl; + bool numericParam; int32_t rowNum; //row num for one table int32_t bindColNum; int32_t bindTagNum; @@ -207,6 +213,7 @@ CaseCtrl gCaseCtrl = { // default .printQuerySql = true, .printStmtSql = true, .autoCreateTbl = false, + .numericParam = false, .rowNum = 0, .bindColNum = 0, .bindTagNum = 0, @@ -303,11 +310,11 @@ CaseCtrl gCaseCtrl = { // query case with specified col&oper .printRes = true, .runTimes = 0, .caseRunIdx = -1, - //.optrIdxListNum = tListLen(optrIdxList), - //.optrIdxList = optrIdxList, - //.bindColTypeNum = tListLen(bindColTypeList), - //.bindColTypeList = bindColTypeList, - .caseIdx = 22, + .optrIdxListNum = tListLen(optrIdxList), + .optrIdxList = optrIdxList, + .bindColTypeNum = tListLen(bindColTypeList), + .bindColTypeList = bindColTypeList, + .caseIdx = 24, .caseNum = 1, .caseRunNum = 1, }; @@ -661,11 +668,11 @@ void bpGenerateConstInFuncSQL(BindData *data, int32_t tblIdx) { void generateQueryMiscSQL(BindData *data, int32_t tblIdx) { switch(tblIdx) { case 0: - bpGenerateConstInOpSQL(data, tblIdx); - break; - case 1: //TODO FILL TEST default: + bpGenerateConstInOpSQL(data, tblIdx); + break; + case FUNCTION_TEST_IDX: bpGenerateConstInFuncSQL(data, tblIdx); break; } @@ -709,6 +716,16 @@ void generateColDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_ } else if (gCurCase->fullCol) { *dataType = gCurCase->colList[bindIdx]; return; + } else if (gCaseCtrl.numericParam) { + while (true) { + *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1; + if (!IS_NUMERIC_TYPE(*dataType)) { + continue; + } + + break; + } + return; } else if (0 == colIdx) { *dataType = TSDB_DATA_TYPE_TIMESTAMP; return; @@ -1046,6 +1063,10 @@ int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) { data->binaryLen[i] = gVarCharLen; } + if (tblIdx == FUNCTION_TEST_IDX) { + gCaseCtrl.numericParam = true; + } + for (int b = 0; b < bindNum; b++) { for (int c = 0; c < gCurCase->bindColNum; ++c) { prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); From 1b2ca4c1b4b4350bea7f32d70197b2ec7529eb72 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 13 May 2022 19:08:16 +0800 Subject: [PATCH 3/4] stmt query --- source/libs/scalar/inc/sclInt.h | 3 ++- tests/script/api/batchprepare.c | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 9257d2c0d4..9dbfeceb59 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -35,7 +35,8 @@ typedef struct SScalarCtx { #define SCL_IS_CONST_NODE(_node) ((NULL == (_node)) || (QUERY_NODE_VALUE == (_node)->type) || (QUERY_NODE_NODE_LIST == (_node)->type)) #define SCL_IS_CONST_CALC(_ctx) (NULL == (_ctx)->pBlockList) -#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type) && (((SValueNode *)_node)->placeholderNo <= 0)) +//#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type) && (((SValueNode *)_node)->placeholderNo <= 0)) +#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type)) #define sclFatal(...) qFatal(__VA_ARGS__) #define sclError(...) qError(__VA_ARGS__) diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 1c1b7c8eb3..cb914f8d6d 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -14,7 +14,7 @@ int32_t shortColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT}; int32_t fullColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_TINYINT, TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_USMALLINT, TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_UINT, TSDB_DATA_TYPE_BIGINT, TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_BINARY, TSDB_DATA_TYPE_NCHAR}; int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT}; -int32_t optrIdxList[] = {0, 1}; +int32_t optrIdxList[] = {0, 7}; typedef struct { char* oper; @@ -170,7 +170,10 @@ CaseCfg gCase[] = { // 22 {"insert:AUTO1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, true, true, insertAUTOTest1, 10, 10, 2, 0, 0, 0, 1, -1}, - {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryColumnTest, 10, 10, 1, 3, 0, 0, 1, 2}, +// {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryColumnTest, 10, 10, 1, 3, 0, 0, 1, 2}, +// {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryMiscTest, 10, 10, 1, 3, 0, 0, 1, 2}, + + {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryColumnTest, 1, 10, 1, 1, 0, 0, 1, 2}, {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, queryMiscTest, 2, 10, 1, 1, 0, 0, 1, 2}, }; @@ -266,26 +269,22 @@ CaseCtrl gCaseCtrl = { #if 1 CaseCtrl gCaseCtrl = { // query case with specified col&oper - .bindNullNum = 0, + .bindNullNum = 1, .printCreateTblSql = false, .printQuerySql = true, .printStmtSql = true, .rowNum = 0, .bindColNum = 0, .bindRowNum = 0, - .bindColTypeNum = 0, - .bindColTypeList = NULL, - .optrIdxListNum = 0, - .optrIdxList = NULL, + .optrIdxListNum = tListLen(optrIdxList), + .optrIdxList = optrIdxList, + .bindColTypeNum = tListLen(bindColTypeList), + .bindColTypeList = bindColTypeList, .checkParamNum = false, .printRes = true, .runTimes = 0, .caseRunIdx = -1, - .optrIdxListNum = 0, - .optrIdxList = NULL, - .bindColTypeNum = 0, - .bindColTypeList = NULL, - .caseIdx = 24, + .caseIdx = 23, .caseNum = 1, .caseRunNum = 1, }; From aee28eb2fcb5136ac672a0cb31db041357f43157 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 13 May 2022 22:18:43 +0800 Subject: [PATCH 4/4] fix catalog bug --- source/common/src/tglobal.c | 2 ++ source/libs/catalog/src/catalog.c | 17 +++++++++-------- source/libs/qcom/src/querymsg.c | 4 ++++ tests/pytest/util/dnodes.py | 2 +- tests/system-test/99-TDcase/TD-15554.py | 8 ++++---- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 0999cb4d2c..16b5da81ce 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -280,6 +280,7 @@ int32_t taosAddClientLogCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "cDebugFlag", cDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "uDebugFlag", uDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "rpcDebugFlag", rpcDebugFlag, 0, 255, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1; @@ -458,6 +459,7 @@ static void taosSetClientLogCfg(SConfig *pCfg) { tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32; cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32; + qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32; rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->i32; tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32; jniDebugFlag = cfgGetItem(pCfg, "jniDebugFlag")->i32; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index f485f85809..64090d0283 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -841,6 +841,8 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable return TSDB_CODE_SUCCESS; } + + ctgDebug("Got subtable meta from cache, type:%d, dbFName:%s, tbName:%s, suid:%" PRIx64, tbMeta->tableType, dbFName, pTableName->tname, tbMeta->suid); CTG_LOCK(CTG_READ, &dbCache->tbCache.stbLock); @@ -1655,6 +1657,11 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui STableMeta *orig = taosHashGet(tbCache->metaCache, tbName, strlen(tbName)); if (orig) { origType = orig->tableType; + + if (origType == meta->tableType && orig->uid == meta->uid && orig->sversion >= meta->sversion && orig->tversion >= meta->tversion) { + CTG_UNLOCK(CTG_READ, &tbCache->metaLock); + return TSDB_CODE_SUCCESS; + } if (origType == TSDB_SUPER_TABLE) { if ((!isStb) || orig->suid != meta->suid) { @@ -1693,7 +1700,7 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui CTG_CACHE_STAT_ADD(tblNum, 1); } - ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType); + ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d, suid:%" PRIx64, dbFName, tbName, meta->tableType, meta->suid); ctgdShowTableMeta(pCtg, tbName, meta); if (!isStb) { @@ -1701,12 +1708,6 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui return TSDB_CODE_SUCCESS; } - if (origType == TSDB_SUPER_TABLE && origSuid == meta->suid) { - CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock); - CTG_UNLOCK(CTG_READ, &tbCache->metaLock); - return TSDB_CODE_SUCCESS; - } - STableMeta *tbMeta = taosHashGet(tbCache->metaCache, tbName, strlen(tbName)); if (taosHashPut(tbCache->stbCache, &meta->suid, sizeof(meta->suid), &tbMeta, POINTER_BYTES) != 0) { CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock); @@ -1721,7 +1722,7 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui CTG_UNLOCK(CTG_READ, &tbCache->metaLock); - ctgDebug("stb updated to stbCache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType); + ctgDebug("stb updated to stbCache, dbFName:%s, tbName:%s, tbType:%d, suid:%" PRIx64 ",ma:%p", dbFName, tbName, meta->tableType, meta->suid, tbMeta); SSTableMetaVersion metaRent = {.dbId = dbId, .suid = meta->suid, .sversion = meta->sversion, .tversion = meta->tversion}; strcpy(metaRent.dbFName, dbFName); diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 822c214fe5..fb9319bede 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -290,6 +290,10 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isSuperTable, STabl pTableMeta->sversion = msg->sversion; pTableMeta->tversion = msg->tversion; + if (isSuperTable) { + qDebug("stable %s meta returned, suid:%" PRIx64, msg->stbName, pTableMeta->suid); + } + pTableMeta->tableInfo.numOfTags = msg->numOfTags; pTableMeta->tableInfo.precision = msg->precision; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 3c23e784c5..15515a10a0 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -40,7 +40,7 @@ class TDSimClient: "cDebugFlag": "135", "udebugFlag": "135", "jnidebugFlag": "135", - "qdebugFlag": "135", + "qdebugFlag": "143", "telemetryReporting": "0", } diff --git a/tests/system-test/99-TDcase/TD-15554.py b/tests/system-test/99-TDcase/TD-15554.py index 890580ca2c..d7b2856b41 100644 --- a/tests/system-test/99-TDcase/TD-15554.py +++ b/tests/system-test/99-TDcase/TD-15554.py @@ -14,10 +14,10 @@ from util.dnodes import * class TDTestCase: hostname = socket.gethostname() - clientCfgDict = {'qdebugflag':'143'} - updatecfgDict = {'clientCfg': {}, 'qdebugflag':'143'} - updatecfgDict["clientCfg"] = clientCfgDict - print ("===================: ", updatecfgDict) + #clientCfgDict = {'qdebugflag':'143'} + #updatecfgDict = {'clientCfg': {}, 'qdebugflag':'143'} + #updatecfgDict["clientCfg"] = clientCfgDict + #print ("===================: ", updatecfgDict) def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}")