Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions source/client/src/clientStmt2.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ static int32_t stmtUpdateBindInfo(TAOS_STMT2* stmt, STableMeta* pTableMeta, void
return code;
}

if ((tags != NULL && ((SBoundColInfo*)tags)->numOfCols == 0) || !autoCreateTbl) {
pStmt->sql.autoCreateTbl = false;
}

(void)memcpy(&pStmt->bInfo.sname, tbName, sizeof(*tbName));
tstrncpy(pStmt->bInfo.tbFName, tbFName, sizeof(pStmt->bInfo.tbFName));
pStmt->bInfo.tbFName[sizeof(pStmt->bInfo.tbFName) - 1] = 0;
Expand Down Expand Up @@ -609,6 +613,41 @@ static int32_t stmtTryAddTableVgroupInfo(STscStmt2* pStmt, int32_t* vgId) {
return TSDB_CODE_SUCCESS;
}

int32_t stmtGetTableMetaAndValidate(STscStmt2* pStmt, uint64_t* uid, uint64_t* suid, int32_t* vgId, int8_t* tableType) {
STableMeta* pTableMeta = NULL;
SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
.requestId = pStmt->exec.pRequest->requestId,
.requestObjRefId = pStmt->exec.pRequest->self,
.mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta);

pStmt->stat.ctgGetTbMetaNum++;

if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
STMT2_ELOG("tb %s not exist", pStmt->bInfo.tbFName);
(void)stmtCleanBindInfo(pStmt);

if (!pStmt->sql.autoCreateTbl) {
STMT2_ELOG("table %s does not exist and autoCreateTbl is disabled", pStmt->bInfo.tbFName);
STMT_ERR_RET(TSDB_CODE_PAR_TABLE_NOT_EXIST);
}

STMT_ERR_RET(code);
}

STMT_ERR_RET(code);

*uid = pTableMeta->uid;
*suid = pTableMeta->suid;
*tableType = pTableMeta->tableType;
pStmt->bInfo.tbVgId = pTableMeta->vgId;
*vgId = pTableMeta->vgId;

taosMemoryFree(pTableMeta);

return TSDB_CODE_SUCCESS;
}

static int32_t stmtRebuildDataBlock(STscStmt2* pStmt, STableDataCxt* pDataBlock, STableDataCxt** newBlock, uint64_t uid,
uint64_t suid, int32_t vgId) {
STMT_ERR_RET(stmtTryAddTableVgroupInfo(pStmt, &vgId));
Expand Down Expand Up @@ -655,6 +694,7 @@ static int32_t stmtGetFromCache(STscStmt2* pStmt) {
}

STMT2_DLOG("no stmt block cache for tb %s", pStmt->bInfo.tbFName);

return TSDB_CODE_SUCCESS;
}

Expand Down Expand Up @@ -686,31 +726,7 @@ static int32_t stmtGetFromCache(STscStmt2* pStmt) {
int32_t vgId;
int8_t tableType;

STableMeta* pTableMeta = NULL;
SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
.requestId = pStmt->exec.pRequest->requestId,
.requestObjRefId = pStmt->exec.pRequest->self,
.mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta);

pStmt->stat.ctgGetTbMetaNum++;

if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
STMT2_DLOG("tb %s not exist", pStmt->bInfo.tbFName);
STMT_ERR_RET(stmtCleanBindInfo(pStmt));

STMT_ERR_RET(code);
}

STMT_ERR_RET(code);

uid = pTableMeta->uid;
suid = pTableMeta->suid;
tableType = pTableMeta->tableType;
pStmt->bInfo.tbVgId = pTableMeta->vgId;
vgId = pTableMeta->vgId;

taosMemoryFree(pTableMeta);
STMT_ERR_RET(stmtGetTableMetaAndValidate(pStmt, &uid, &suid, &vgId, &tableType));

uint64_t cacheUid = (TSDB_CHILD_TABLE == tableType) ? suid : uid;

Expand Down Expand Up @@ -805,11 +821,11 @@ static void stmtAsyncOutput(STscStmt2* pStmt, void* param) {
int code = qAppendStmt2TableOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, &pParam->tblData, pStmt->exec.pCurrBlock,
&pStmt->sql.siInfo, pParam->pCreateTbReq);
// taosMemoryFree(pParam->pTbData);
(void)atomic_sub_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1);
if (code != TSDB_CODE_SUCCESS) {
STMT2_ELOG("async append stmt output failed, tbname:%s, err:%s", pParam->tblData.tbName, tstrerror(code));
pStmt->errCode = code;
}
(void)atomic_sub_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1);
}
}

Expand Down Expand Up @@ -1350,7 +1366,18 @@ int stmtSetTbName2(TAOS_STMT2* stmt, const char* tbName) {
pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0;

STMT_ERR_RET(stmtParseSql(pStmt));
if (!pStmt->sql.autoCreateTbl) {
uint64_t uid, suid;
int32_t vgId;
int8_t tableType;

int32_t code = stmtGetTableMetaAndValidate(pStmt, &uid, &suid, &vgId, &tableType);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
}
}

} else {
tstrncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName));
pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0;
Expand Down
Loading
Loading