diff --git a/include/libs/parser/parsenodes.h b/include/libs/parser/parsenodes.h index d4c6ddb26fb36616f521b869eb84da396212b6a5..1a8e8ddd47e01ebcb9781f3e37fc4331102847c4 100644 --- a/include/libs/parser/parsenodes.h +++ b/include/libs/parser/parsenodes.h @@ -44,11 +44,12 @@ typedef struct SField { } SField; typedef struct SParseBasicCtx { - const char *db; - int32_t acctId; - uint64_t requestId; - void *pTransporter; - SEpSet mgmtEpSet; + uint64_t requestId; + int32_t acctId; + const char *db; + void *pTransporter; + SEpSet mgmtEpSet; + struct SCatalog *pCatalog; } SParseBasicCtx; typedef struct SFieldInfo { diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 8e7ff8ccc2e761f64d38fc64d35d6129844b03f7..bc69523b54d13c5171f0a325a97914167728e4ef 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -24,7 +24,6 @@ extern "C" { typedef struct SParseContext { SParseBasicCtx ctx; - struct SCatalog *pCatalog; int8_t schemaAttached; // denote if submit block is built with table schema or not const char *pSql; // sql string size_t sqlLen; // length of the sql string diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index c55f702b327ad909702f794493807d1552abb580..7eadece7289bd774c505f980118ceeb5de2f25e8 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -145,17 +145,32 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj* } int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) { + STscObj* pTscObj = pRequest->pTscObj; + SParseContext cxt = { - .ctx = {.requestId = pRequest->requestId, .acctId = pRequest->pTscObj->acctId, .db = getConnectionDB(pRequest->pTscObj), .pTransporter = pRequest->pTscObj->pTransporter}, + .ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj), .pTransporter = pTscObj->pTransporter}, .pSql = pRequest->sqlstr, .sqlLen = pRequest->sqlLen, .pMsg = pRequest->msgBuf, .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE }; - cxt.ctx.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp); + cxt.ctx.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); + + // todo OPT performance + char buf[12] = {0}; + sprintf(buf, "%"PRId64, pTscObj->pAppInfo->clusterId); + + struct SCatalog* pCatalog = NULL; + int32_t code = catalogGetHandle(buf, &pCatalog); + if (code != TSDB_CODE_SUCCESS) { + tfree(cxt.ctx.db); + return code; + } + + cxt.ctx.pCatalog = pCatalog; + code = qParseQuerySql(&cxt, pQuery); - int32_t code = qParseQuerySql(&cxt, pQuery); tfree(cxt.ctx.db); return code; } diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 0d857bc4036ce613991888e2f972ffba9e6d77eb..5e69c668dca5e487775357b0a6bca13810bf8012 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -323,12 +323,10 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx *pCtx, SMsgBuf* p size_t valSize = taosArrayGetSize(pValList); STableMeta* pSuperTableMeta = NULL; - struct SCatalog* pCatalog = NULL; - char dbName[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(&name, dbName); - catalogGetTableMeta(pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, dbName, pCreateTableInfo->tagdata.name, &pSuperTableMeta); + catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, dbName, pCreateTableInfo->tagdata.name, &pSuperTableMeta); // too long tag values will return invalid sql, not be truncated automatically SSchema *pTagSchema = getTableTagSchema(pSuperTableMeta); diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index 73232cd2e1f04d9c45b15ff72f3da61457f58663..d6bdf5dbcabec61638a8a5bd05f8427adca7b098 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -173,9 +173,9 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { char fullDbName[TSDB_DB_FNAME_LEN] = {0}; char tableName[TSDB_TABLE_NAME_LEN] = {0}; CHECK_CODE(buildName(pCxt, pTname, fullDbName, tableName)); - CHECK_CODE(catalogGetTableMeta(pCxt->pComCxt->pCatalog, pCxt->pComCxt->ctx.pTransporter, &pCxt->pComCxt->ctx.mgmtEpSet, fullDbName, tableName, &pCxt->pTableMeta)); + CHECK_CODE(catalogGetTableMeta(pCxt->pComCxt->ctx.pCatalog, pCxt->pComCxt->ctx.pTransporter, &pCxt->pComCxt->ctx.mgmtEpSet, fullDbName, tableName, &pCxt->pTableMeta)); SVgroupInfo vg; - CHECK_CODE(catalogGetTableHashVgroup(pCxt->pComCxt->pCatalog, pCxt->pComCxt->ctx.pTransporter, &pCxt->pComCxt->ctx.mgmtEpSet, fullDbName, tableName, &vg)); + CHECK_CODE(catalogGetTableHashVgroup(pCxt->pComCxt->ctx.pCatalog, pCxt->pComCxt->ctx.pTransporter, &pCxt->pComCxt->ctx.mgmtEpSet, fullDbName, tableName, &vg)); CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp index f2cb4864fba79e06e16b454ea8e0f9f695e828b0..423aa1a7bedcdc3a8920925924c4c06260448602 100644 --- a/source/libs/parser/test/parserTests.cpp +++ b/source/libs/parser/test/parserTests.cpp @@ -715,7 +715,7 @@ TEST(testCase, show_user_Test) { ASSERT_EQ(info1.valid, true); SDclStmtInfo output; - SParseBasicCtx ct= {.db= "abc", .acctId = 1, .requestId = 1}; + SParseBasicCtx ct= {.requestId = 1, .acctId = 1, .db = "abc", .pTransporter = NULL}; int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); ASSERT_EQ(code, 0); @@ -736,7 +736,7 @@ TEST(testCase, create_user_Test) { ASSERT_EQ(isDclSqlStatement(&info1), true); SDclStmtInfo output; - SParseBasicCtx ct= {.db= "abc", .acctId = 1, .requestId = 1}; + SParseBasicCtx ct= {.requestId = 1, .acctId = 1, .db = "abc"}; int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); ASSERT_EQ(code, 0);