From 1792bf5ff3221b3e148ca6a5db715f199f3342e7 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Sat, 7 May 2022 14:46:04 +0800 Subject: [PATCH 1/9] fix bug --- include/util/taoserror.h | 1 + source/client/inc/clientInt.h | 1 + source/client/src/clientStmt.c | 16 +++- source/dnode/vnode/src/vnd/vnodeSvr.c | 2 +- source/libs/scalar/src/filter.c | 16 ++++ source/libs/scalar/src/sclvector.c | 117 +++++++++++++++++++++++++- source/util/src/terror.c | 1 + tests/script/api/batchprepare.c | 6 +- 8 files changed, 148 insertions(+), 12 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 441e87eff7..d2c447e851 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -88,6 +88,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0114) #define TSDB_CODE_REPEAT_INIT TAOS_DEF_ERROR_CODE(0, 0x0115) #define TSDB_CODE_DUP_KEY TAOS_DEF_ERROR_CODE(0, 0x0116) +#define TSDB_CODE_NEED_RETRY TAOS_DEF_ERROR_CODE(0, 0x0117) #define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0140) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0141) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index ce5b101b4a..b021651c16 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -310,6 +310,7 @@ void hbMgrInitMqHbRspHandle(); SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery); int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList); int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList); +int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest); #ifdef __cplusplus } diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index f7ef1f7e81..d7b746605d 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -586,6 +586,16 @@ int stmtExec(TAOS_STMT *stmt) { STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->exec.pVgHash, pStmt->exec.pBlockHash)); launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true); } + + if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) { + code = refreshMeta(pStmt->exec.pRequest->pTscObj, pStmt->exec.pRequest); + if (code) { + pStmt->exec.pRequest->code = code; + } else { + STMT_ERR_RET(stmtResetStmt(pStmt)); + STMT_ERR_RET(TSDB_CODE_NEED_RETRY); + } + } STMT_ERR_JRET(pStmt->exec.pRequest->code); @@ -613,13 +623,11 @@ int stmtClose(TAOS_STMT *stmt) { const char *stmtErrstr(TAOS_STMT *stmt) { STscStmt* pStmt = (STscStmt*)stmt; - if (stmt == NULL) { + if (stmt == NULL || NULL == pStmt->exec.pRequest) { return (char*) tstrerror(terrno); } - if (pStmt->exec.pRequest) { - pStmt->exec.pRequest->code = terrno; - } + pStmt->exec.pRequest->code = terrno; return taos_errstr(pStmt->exec.pRequest); } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 8460400b59..5f023fb637 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -537,7 +537,7 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in goto _exit; } - rsp.numOfRows += nRows; + rsp.affectedRows += nRows; } _exit: diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 80e5669cc2..eaab8e1f53 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3577,6 +3577,22 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { } if (QUERY_NODE_NODE_LIST == nodeType(*pNode)) { + SNodeListNode *listNode = (SNodeListNode *)*pNode; + if (QUERY_NODE_VALUE != nodeType(listNode->pNodeList->pHead->pNode)) { + stat->scalarMode = true; + return DEAL_RES_CONTINUE; + } + + SValueNode *valueNode = (SValueNode *)listNode->pNodeList->pHead->pNode; + uint8_t type = valueNode->node.resType.type; + SNode *node = NULL; + FOREACH(node, listNode->pNodeList) { + if (type != ((SValueNode *)node)->node.resType.type) { + stat->scalarMode = true; + return DEAL_RES_CONTINUE; + } + } + return DEAL_RES_CONTINUE; } diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 1e37533f2c..b83147bfee 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -265,13 +265,53 @@ static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t r } static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { - int64_t value = strtoll(buf, NULL, 10); - colDataAppendInt64(pOut->columnData, rowIndex, &value); + switch (pOut->columnData->info.type) { + case TSDB_DATA_TYPE_TINYINT: { + int8_t value = (int8_t)strtoll(buf, NULL, 10); + colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); + break; + } + case TSDB_DATA_TYPE_SMALLINT: { + int16_t value = (int16_t)strtoll(buf, NULL, 10); + colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); + break; + } + case TSDB_DATA_TYPE_INT: { + int32_t value = (int32_t)strtoll(buf, NULL, 10); + colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); + break; + } + case TSDB_DATA_TYPE_BIGINT: { + int64_t value = (int64_t)strtoll(buf, NULL, 10); + colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); + break; + } + } } static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { - uint64_t value = strtoull(buf, NULL, 10); - colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*) &value); + switch (pOut->columnData->info.type) { + case TSDB_DATA_TYPE_UTINYINT: { + uint8_t value = (uint8_t)strtoull(buf, NULL, 10); + colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); + break; + } + case TSDB_DATA_TYPE_USMALLINT: { + uint16_t value = (uint16_t)strtoull(buf, NULL, 10); + colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); + break; + } + case TSDB_DATA_TYPE_UINT: { + uint32_t value = (uint32_t)strtoull(buf, NULL, 10); + colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); + break; + } + case TSDB_DATA_TYPE_UBIGINT: { + uint64_t value = (uint64_t)strtoull(buf, NULL, 10); + colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); + break; + } + } } static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex) { @@ -453,6 +493,71 @@ void convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t } } +int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int16_t inType, int16_t outType) { + SColumnInfoData* pInputCol = pIn->columnData; + SColumnInfoData* pOutputCol = pOut->columnData; + char tmp[128] = {0}; + + if (IS_SIGNED_NUMERIC_TYPE(inType) || inType == TSDB_DATA_TYPE_BOOL || inType == TSDB_DATA_TYPE_TIMESTAMP) { + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppendNULL(pOutputCol, i); + continue; + } + + int64_t value = 0; + GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); + int32_t len = sprintf(varDataVal(tmp), "%" PRId64, value); + varDataLen(tmp) = len; + if (outType == TSDB_DATA_TYPE_NCHAR) { + varToNchar(tmp, pOut, i); + } else { + colDataAppend(pOutputCol, i, (char *)&value, false); + } + } + } else if (IS_UNSIGNED_NUMERIC_TYPE(inType)) { + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppendNULL(pOutputCol, i); + continue; + } + + uint64_t value = 0; + GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i)); + int32_t len = sprintf(varDataVal(tmp), "%" PRIu64, value); + varDataLen(tmp) = len; + if (outType == TSDB_DATA_TYPE_NCHAR) { + varToNchar(tmp, pOut, i); + } else { + colDataAppend(pOutputCol, i, (char *)&value, false); + } + } + } else if (IS_FLOAT_TYPE(inType)) { + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppendNULL(pOutputCol, i); + continue; + } + + double value = 0; + GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i)); + int32_t len = sprintf(varDataVal(tmp), "%lf", value); + varDataLen(tmp) = len; + if (outType == TSDB_DATA_TYPE_NCHAR) { + varToNchar(tmp, pOut, i); + } else { + colDataAppend(pOutputCol, i, (char *)&value, false); + } + } + } else { + sclError("not supported input type:%d", inType); + return TSDB_CODE_QRY_APP_ERROR; + } + + return TSDB_CODE_SUCCESS; +} + + // TODO opt performance int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { SColumnInfoData* pInputCol = pIn->columnData; @@ -610,6 +715,10 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { } break; } + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: { + return vectorConvertToVarData(pIn, pOut, inType, outType); + } default: sclError("invalid convert output type:%d", outType); return TSDB_CODE_QRY_APP_ERROR; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 1470496c68..60af8c241c 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -94,6 +94,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed TAOS_DEFINE_ERROR(TSDB_CODE_CFG_NOT_FOUND, "Config not found") TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization") TAOS_DEFINE_ERROR(TSDB_CODE_DUP_KEY, "Cannot add duplicate keys to hash") +TAOS_DEFINE_ERROR(TSDB_CODE_NEED_RETRY, "Retry needed") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 99e546fcd0..beabb0c473 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -11,7 +11,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_SMALLINT, TSDB_DATA_TYPE_DOUBLE}; +int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_NCHAR}; int32_t optrIdxList[] = {0, 1, 2}; typedef struct { @@ -235,7 +235,7 @@ CaseCtrl gCaseCtrl = { // query case with specified col&oper .bindColTypeList = NULL, .optrIdxListNum = 0, .optrIdxList = NULL, - .checkParamNum = true, + .checkParamNum = false, .printRes = true, .runTimes = 0, .caseRunIdx = -1, @@ -795,7 +795,7 @@ int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) { } } - generateQuerySQL(data, tblIdx); + generateQueryCondSQL(data, tblIdx); return 0; } From 6f49a2ca73964a43067c65fc1ebdbd17ae9a8e23 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Sat, 7 May 2022 21:10:52 +0800 Subject: [PATCH 2/9] stmt insert --- include/libs/qcom/query.h | 2 +- source/client/inc/clientStmt.h | 1 + source/client/src/clientSml.c | 2 +- source/client/src/clientStmt.c | 22 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 4 +- source/libs/catalog/inc/catalogInt.h | 2 +- source/libs/parser/src/parInsert.c | 3 +- source/libs/parser/src/parTranslater.c | 2 +- tests/script/api/batchprepare.c | 524 +++++++++++++++++-------- 9 files changed, 394 insertions(+), 168 deletions(-) diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index c1e53fa805..3cc71546fc 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -182,7 +182,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE #define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE -#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID || (_code) == TSDB_CODE_VND_TB_NOT_EXIST) +#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST) #define NEED_CLIENT_REFRESH_VG_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) #define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED) #define NEED_CLIENT_HANDLE_ERROR(_code) (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code)) diff --git a/source/client/inc/clientStmt.h b/source/client/inc/clientStmt.h index 43e886faf5..32da75fb1e 100644 --- a/source/client/inc/clientStmt.h +++ b/source/client/inc/clientStmt.h @@ -60,6 +60,7 @@ typedef struct SStmtBindInfo { int32_t sBindRowNum; int32_t sBindLastIdx; int8_t tbType; + bool tagsCached; void* boundTags; char* tbName; SName sname; diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 85cd0661e3..a5b7b08d0a 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -432,7 +432,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) { code = catalogGetSTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, &pTableMeta); - if (code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_MND_INVALID_STB) { + if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_INVALID_STB) { SSchemaAction schemaAction = {0}; schemaAction.action = SCHEMA_ACTION_CREATE_STABLE; memcpy(schemaAction.createSTable.sTableName, superTable, superTableLen); diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index ba8123d960..347debe68d 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -123,6 +123,7 @@ int32_t stmtSetBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags) { pStmt->bInfo.tbSuid = pTableMeta->suid; pStmt->bInfo.tbType = pTableMeta->tableType; pStmt->bInfo.boundTags = tags; + pStmt->bInfo.tagsCached = false; return TSDB_CODE_SUCCESS; } @@ -207,8 +208,6 @@ int32_t stmtParseSql(STscStmt* pStmt) { STMT_ERR_RET(TSDB_CODE_TSC_STMT_CLAUSE_ERROR); } - STMT_ERR_RET(stmtCacheBlock(pStmt)); - return TSDB_CODE_SUCCESS; } @@ -219,8 +218,10 @@ int32_t stmtCleanBindInfo(STscStmt* pStmt) { pStmt->bInfo.needParse = true; taosMemoryFreeClear(pStmt->bInfo.tbName); - destroyBoundColumnInfo(pStmt->bInfo.boundTags); - taosMemoryFreeClear(pStmt->bInfo.boundTags); + if (!pStmt->bInfo.tagsCached) { + destroyBoundColumnInfo(pStmt->bInfo.boundTags); + taosMemoryFreeClear(pStmt->bInfo.boundTags); + } return TSDB_CODE_SUCCESS; } @@ -275,6 +276,7 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) { qDestroyStmtDataBlock(pCache->pDataBlock); destroyBoundColumnInfo(pCache->boundTags); + taosMemoryFreeClear(pCache->boundTags); pIter = taosHashIterate(pStmt->sql.pTableCache, pIter); } @@ -302,7 +304,15 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STableMeta *pTableMeta = NULL; SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); - STMT_ERR_RET(catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &pTableMeta)); + int32_t code = catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &pTableMeta); + if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + return TSDB_CODE_SUCCESS; + } + + STMT_ERR_RET(code); + uint64_t uid = pTableMeta->uid; uint64_t suid = pTableMeta->suid; int8_t tableType = pTableMeta->tableType; @@ -328,6 +338,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.tbSuid = suid; pStmt->bInfo.tbType = tableType; pStmt->bInfo.boundTags = pCache->boundTags; + pStmt->bInfo.tagsCached = true; return TSDB_CODE_SUCCESS; } @@ -340,6 +351,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.tbSuid = suid; pStmt->bInfo.tbType = tableType; pStmt->bInfo.boundTags = pCache->boundTags; + pStmt->bInfo.tagsCached = true; STableDataBlocks* pNewBlock = NULL; STMT_ERR_RET(qRebuildStmtDataBlock(&pNewBlock, pCache->pDataBlock)); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 0b9f21dbcf..3d9ef6cf8a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -3869,7 +3869,7 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch if (metaGetTableEntryByUid(&mr, uid) < 0) { tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); - terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; + terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; goto _error; } else { tsdbDebug("%p succeed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); @@ -3939,7 +3939,7 @@ int32_t tsdbGetOneTableGroup(void* pMeta, uint64_t uid, TSKEY startKey, STableGr metaReaderInit(&mr, (SMeta*)pMeta, 0); if (metaGetTableEntryByUid(&mr, uid) < 0) { - terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; + terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; goto _error; } diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 3e8528e3d9..1bf21ad7d1 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -36,7 +36,7 @@ extern "C" { #define CTG_DEFAULT_INVALID_VERSION (-1) -#define CTG_ERR_CODE_TABLE_NOT_EXIST TSDB_CODE_TDB_INVALID_TABLE_ID +#define CTG_ERR_CODE_TABLE_NOT_EXIST TSDB_CODE_PAR_TABLE_NOT_EXIST enum { CTG_READ = 1, diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 05d247c037..4bc04f8eab 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1151,6 +1151,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { (*pCxt->pStmtCb->setExecInfoFn)(pCxt->pStmtCb->pStmt, pCxt->pVgroupsHashObj, pCxt->pTableBlockHashObj); pCxt->pVgroupsHashObj = NULL; pCxt->pTableBlockHashObj = NULL; + pCxt->pTableMeta = NULL; return TSDB_CODE_SUCCESS; } @@ -1276,7 +1277,7 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, char *tN return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta); + SSchema* pSchema = pDataBlock->pTableMeta->schema; SKvParam param = {.builder = &tagBuilder}; for (int c = 0; c < tags->numOfBound; ++c) { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 6874b5b7d4..ec593c75ac 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2574,7 +2574,7 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt SName tableName; int32_t code = getTableMetaImpl( pCxt, toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName), &pTableMeta); - if ((TSDB_CODE_TDB_INVALID_TABLE_ID == code || TSDB_CODE_VND_TB_NOT_EXIST == code) && pClause->ignoreNotExists) { + if ((TSDB_CODE_PAR_TABLE_NOT_EXIST == code || TSDB_CODE_VND_TB_NOT_EXIST == code) && pClause->ignoreNotExists) { return TSDB_CODE_SUCCESS; } if (TSDB_CODE_SUCCESS == code) { diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index beabb0c473..3dddb03f3b 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -20,6 +20,11 @@ typedef struct { bool enclose; } OperInfo; +typedef enum { + BP_BIND_TAG = 1, + BP_BIND_COL, +} BP_BIND_TYPE; + OperInfo operInfo[] = { {">", 2, false}, {">=", 2, false}, @@ -41,6 +46,8 @@ int32_t varoperatorList[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; char *bpStbPrefix = "st"; char *bpTbPrefix = "t"; +int32_t bpDefaultStbId = 1; + //char *operatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in"}; @@ -65,6 +72,7 @@ typedef struct { char* isNull; int32_t* binaryLen; TAOS_MULTI_BIND* pBind; + TAOS_MULTI_BIND* pTags; char* sql; int32_t* colTypes; int32_t colNum; @@ -83,6 +91,7 @@ int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos); int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos); int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos); int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos); +int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos); int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos); enum { @@ -102,45 +111,48 @@ typedef struct { int32_t rowNum; int32_t bindRowNum; int32_t bindColNum; // equal colNum in full column case + int32_t bindTagNum; // equal colNum in full column case int32_t bindNullNum; int32_t runTimes; int32_t preCaseIdx; } CaseCfg; CaseCfg gCase[] = { - {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 1, 10, 10, 0, 0, 1, -1}, - {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 1, -1}, + {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 1, 10, 10, 0, 0, 0, 1, -1}, + {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 0, 1, -1}, - {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 1, -1}, - {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 1, -1}, - {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 1, -1}, + {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 0, 1, -1}, + {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 0, 1, -1}, + {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 0, 1, -1}, - {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 1, -1}, - {"insert:MBSE2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 1, -1}, - {"insert:MBSE2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 1, -1}, + {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 0, 1, -1}, + {"insert:MBSE2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 0, 1, -1}, + {"insert:MBSE2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 0, 1, -1}, - {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 1, -1}, - {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 1, -1}, - {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 1, -1}, + {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 0, 1, -1}, + {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 0, 1, -1}, + {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 0, 1, -1}, // 11 - {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 1, -1}, - {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 1, -1}, - {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 1, -1}, + {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 0, 1, -1}, + {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 0, 1, -1}, + {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 0, 1, -1}, - {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 1, -1}, - {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 1, -1}, - {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 1, -1}, + {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 0, 1, -1}, + {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 0, 1, -1}, + {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 0, 1, -1}, - {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 1, -1}, - {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 1, -1}, - {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 1, -1}, + {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 0, 1, -1}, + {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 0, 1, -1}, + {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 0, 1, -1}, - {"insert:MPME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMPMETest1, 10, 10, 2, 0, 0, 1, -1}, - {"insert:MPME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMPMETest1, 10, 10, 2, 12, 0, 1, -1}, + {"insert:MPME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMPMETest1, 10, 10, 2, 0, 0, 0, 1, -1}, + {"insert:MPME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMPMETest1, 10, 10, 2, 12, 0, 0, 1, -1}, // 22 - {"query:SUBT-FULL", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, querySUBTTest1, 10, 10, 1, 3, 0, 1, 2}, + {"insert:AUTO1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, true, true, insertAUTOTest1, 10, 10, 2, 0, 0, 0, 1, -1}, + + {"query:SUBT-FULL", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, querySUBTTest1, 10, 10, 1, 3, 0, 0, 1, 2}, }; @@ -149,7 +161,6 @@ CaseCfg *gCurCase = NULL; typedef struct { char caseCatalog[255]; int32_t bindNullNum; - bool prepareStb; bool checkParamNum; bool printRes; bool printCreateTblSql; @@ -157,9 +168,12 @@ typedef struct { bool printStmtSql; int32_t rowNum; //row num for one table int32_t bindColNum; + int32_t bindTagNum; int32_t bindRowNum; //row num for once bind int32_t bindColTypeNum; int32_t* bindColTypeList; + int32_t bindTagTypeNum; + int32_t* bindTagTypeList; int32_t optrIdxListNum; int32_t* optrIdxList; int32_t runTimes; @@ -172,15 +186,17 @@ typedef struct { #if 0 CaseCtrl gCaseCtrl = { // default .bindNullNum = 0, - .prepareStb = false, .printCreateTblSql = false, .printQuerySql = true, .printStmtSql = true, .rowNum = 0, .bindColNum = 0, + .bindTagNum = 0, .bindRowNum = 0, .bindColTypeNum = 0, .bindColTypeList = NULL, + .bindTagTypeNum = 0, + .bindTagTypeList = NULL, .optrIdxListNum = 0, .optrIdxList = NULL, .checkParamNum = false, @@ -196,7 +212,6 @@ CaseCtrl gCaseCtrl = { // default #if 0 CaseCtrl gCaseCtrl = { // query case with specified col&oper .bindNullNum = 0, - .prepareStb = false, .printCreateTblSql = false, .printQuerySql = true, .printStmtSql = true, @@ -224,8 +239,7 @@ CaseCtrl gCaseCtrl = { // query case with specified col&oper #if 1 CaseCtrl gCaseCtrl = { // query case with specified col&oper .bindNullNum = 0, - .prepareStb = false, - .printCreateTblSql = false, + .printCreateTblSql = true, .printQuerySql = true, .printStmtSql = true, .rowNum = 0, @@ -239,10 +253,10 @@ CaseCtrl gCaseCtrl = { // query case with specified col&oper .printRes = true, .runTimes = 0, .caseRunIdx = -1, - .optrIdxListNum = tListLen(optrIdxList), - .optrIdxList = optrIdxList, - .bindColTypeNum = tListLen(bindColTypeList), - .bindColTypeList = bindColTypeList, + //.optrIdxListNum = tListLen(optrIdxList), + //.optrIdxList = optrIdxList, + //.bindColTypeNum = tListLen(bindColTypeList), + //.bindColTypeList = bindColTypeList, .caseIdx = 22, .caseNum = 1, .caseRunNum = 1, @@ -299,6 +313,78 @@ void generateInsertSQL(BindData *data) { } else { len = sprintf(data->sql, "insert into %s0 ", bpTbPrefix); } + + if (gCurCase->bindTagNum > 0) { + len += sprintf(data->sql + len, "using %s%d ", bpStbPrefix, bpDefaultStbId); + + if (!gCurCase->fullCol) { + len += sprintf(data->sql + len, "("); + for (int c = 0; c < gCurCase->bindTagNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + switch (data->pTags[c].buffer_type) { + case TSDB_DATA_TYPE_BOOL: + len += sprintf(data->sql + len, "tbooldata"); + break; + case TSDB_DATA_TYPE_TINYINT: + len += sprintf(data->sql + len, "ttinydata"); + break; + case TSDB_DATA_TYPE_SMALLINT: + len += sprintf(data->sql + len, "tsmalldata"); + break; + case TSDB_DATA_TYPE_INT: + len += sprintf(data->sql + len, "tintdata"); + break; + case TSDB_DATA_TYPE_BIGINT: + len += sprintf(data->sql + len, "tbigdata"); + break; + case TSDB_DATA_TYPE_FLOAT: + len += sprintf(data->sql + len, "tfloatdata"); + break; + case TSDB_DATA_TYPE_DOUBLE: + len += sprintf(data->sql + len, "tdoubledata"); + break; + case TSDB_DATA_TYPE_VARCHAR: + len += sprintf(data->sql + len, "tbinarydata"); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + len += sprintf(data->sql + len, "tts"); + break; + case TSDB_DATA_TYPE_NCHAR: + len += sprintf(data->sql + len, "tnchardata"); + break; + case TSDB_DATA_TYPE_UTINYINT: + len += sprintf(data->sql + len, "tutinydata"); + break; + case TSDB_DATA_TYPE_USMALLINT: + len += sprintf(data->sql + len, "tusmalldata"); + break; + case TSDB_DATA_TYPE_UINT: + len += sprintf(data->sql + len, "tuintdata"); + break; + case TSDB_DATA_TYPE_UBIGINT: + len += sprintf(data->sql + len, "tubigdata"); + break; + default: + printf("!!!invalid tag type:%d", data->pTags[c].buffer_type); + exit(1); + } + } + + len += sprintf(data->sql + len, ") "); + } + + len += sprintf(data->sql + len, "tags ("); + for (int c = 0; c < gCurCase->bindTagNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + len += sprintf(data->sql + len, "?"); + } + len += sprintf(data->sql + len, ") "); + } + if (!gCurCase->fullCol) { len += sprintf(data->sql + len, "("); for (int c = 0; c < gCurCase->bindColNum; ++c) { @@ -552,7 +638,7 @@ void generateErrorSQL(BindData *data, int32_t tblIdx) { } } -void generateDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) { +void generateColDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) { if (bindIdx < gCurCase->bindColNum) { if (gCaseCtrl.bindColTypeNum) { *dataType = gCaseCtrl.bindColTypeList[colIdx]; @@ -584,104 +670,146 @@ void generateDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t * } } -int32_t prepareColData(BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t colIdx) { - int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP; +void generateTagDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) { + if (bindIdx < gCurCase->bindTagNum) { + if (gCaseCtrl.bindTagTypeNum) { + *dataType = gCaseCtrl.bindTagTypeList[colIdx]; + return; + } else if (gCurCase->fullCol) { + *dataType = gCurCase->colList[bindIdx]; + return; + } else { + while (true) { + *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1; + if (*dataType == TSDB_DATA_TYPE_JSON || *dataType == TSDB_DATA_TYPE_DECIMAL + || *dataType == TSDB_DATA_TYPE_BLOB || *dataType == TSDB_DATA_TYPE_MEDIUMBLOB + || *dataType == TSDB_DATA_TYPE_VARBINARY) { + continue; + } + + if (colExists(data->pTags, *dataType)) { + continue; + } + + break; + } + } + } else { + *dataType = data->pTags[bindIdx%gCurCase->bindTagNum].buffer_type; + } +} + + +int32_t prepareColData(BP_BIND_TYPE bType, BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t colIdx) { + int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP; + TAOS_MULTI_BIND *pBase = NULL; + + if (bType == BP_BIND_TAG) { + pBase = data->pTags; + generateTagDataType(data, bindIdx, colIdx, &dataType); + } else { + pBase = data->pBind; + generateColDataType(data, bindIdx, colIdx, &dataType); + } - generateDataType(data, bindIdx, colIdx, &dataType); switch (dataType) { case TSDB_DATA_TYPE_BOOL: - data->pBind[bindIdx].buffer_length = sizeof(bool); - data->pBind[bindIdx].buffer = data->boolData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(bool); + pBase[bindIdx].buffer = data->boolData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_TINYINT: - data->pBind[bindIdx].buffer_length = sizeof(int8_t); - data->pBind[bindIdx].buffer = data->tinyData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(int8_t); + pBase[bindIdx].buffer = data->tinyData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_SMALLINT: - data->pBind[bindIdx].buffer_length = sizeof(int16_t); - data->pBind[bindIdx].buffer = data->smallData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(int16_t); + pBase[bindIdx].buffer = data->smallData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_INT: - data->pBind[bindIdx].buffer_length = sizeof(int32_t); - data->pBind[bindIdx].buffer = data->intData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(int32_t); + pBase[bindIdx].buffer = data->intData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_BIGINT: - data->pBind[bindIdx].buffer_length = sizeof(int64_t); - data->pBind[bindIdx].buffer = data->bigData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(int64_t); + pBase[bindIdx].buffer = data->bigData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_FLOAT: - data->pBind[bindIdx].buffer_length = sizeof(float); - data->pBind[bindIdx].buffer = data->floatData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(float); + pBase[bindIdx].buffer = data->floatData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_DOUBLE: - data->pBind[bindIdx].buffer_length = sizeof(double); - data->pBind[bindIdx].buffer = data->doubleData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(double); + pBase[bindIdx].buffer = data->doubleData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_VARCHAR: - data->pBind[bindIdx].buffer_length = gVarCharSize; - data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; - data->pBind[bindIdx].length = data->binaryLen; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = gVarCharSize; + pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; + pBase[bindIdx].length = data->binaryLen; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_TIMESTAMP: - data->pBind[bindIdx].buffer_length = sizeof(int64_t); - data->pBind[bindIdx].buffer = data->tsData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = NULL; + pBase[bindIdx].buffer_length = sizeof(int64_t); + pBase[bindIdx].buffer = data->tsData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = NULL; break; case TSDB_DATA_TYPE_NCHAR: - data->pBind[bindIdx].buffer_length = gVarCharSize; - data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; - data->pBind[bindIdx].length = data->binaryLen; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = gVarCharSize; + pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; + pBase[bindIdx].length = data->binaryLen; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_UTINYINT: - data->pBind[bindIdx].buffer_length = sizeof(uint8_t); - data->pBind[bindIdx].buffer = data->utinyData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(uint8_t); + pBase[bindIdx].buffer = data->utinyData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_USMALLINT: - data->pBind[bindIdx].buffer_length = sizeof(uint16_t); - data->pBind[bindIdx].buffer = data->usmallData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(uint16_t); + pBase[bindIdx].buffer = data->usmallData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_UINT: - data->pBind[bindIdx].buffer_length = sizeof(uint32_t); - data->pBind[bindIdx].buffer = data->uintData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(uint32_t); + pBase[bindIdx].buffer = data->uintData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; case TSDB_DATA_TYPE_UBIGINT: - data->pBind[bindIdx].buffer_length = sizeof(uint64_t); - data->pBind[bindIdx].buffer = data->ubigData + rowIdx; - data->pBind[bindIdx].length = NULL; - data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + pBase[bindIdx].buffer_length = sizeof(uint64_t); + pBase[bindIdx].buffer = data->ubigData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; default: printf("!!!invalid col type:%d", dataType); exit(1); } - data->pBind[bindIdx].buffer_type = dataType; - data->pBind[bindIdx].num = gCurCase->bindRowNum; + pBase[bindIdx].buffer_type = dataType; + pBase[bindIdx].num = gCurCase->bindRowNum; + if (bType == BP_BIND_TAG) { + pBase[bindIdx].num = 1; + } + return 0; } @@ -694,6 +822,7 @@ int32_t prepareInsertData(BindData *data) { data->colTypes = taosMemoryCalloc(30, sizeof(int32_t)); data->sql = taosMemoryCalloc(1, 1024); data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND)); + data->pTags = taosMemoryCalloc(gCurCase->tblNum*gCurCase->bindTagNum, sizeof(TAOS_MULTI_BIND)); data->tsData = taosMemoryMalloc(allRowNum * sizeof(int64_t)); data->boolData = taosMemoryMalloc(allRowNum * sizeof(bool)); data->tinyData = taosMemoryMalloc(allRowNum * sizeof(int8_t)); @@ -734,10 +863,17 @@ int32_t prepareInsertData(BindData *data) { for (int b = 0; b < (allRowNum/gCurCase->bindRowNum); b++) { for (int c = 0; c < gCurCase->bindColNum; ++c) { - prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); + prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); } } + for (int b = 0; b < gCurCase->tblNum; b++) { + for (int c = 0; c < gCurCase->bindTagNum; ++c) { + prepareColData(BP_BIND_TAG, data, b*gCurCase->bindTagNum+c, b, c); + } + } + + generateInsertSQL(data); return 0; @@ -791,7 +927,7 @@ int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) { for (int b = 0; b < bindNum; b++) { for (int c = 0; c < gCurCase->bindColNum; ++c) { - prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); + prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); } } @@ -849,7 +985,7 @@ int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) { for (int b = 0; b < bindNum; b++) { for (int c = 0; c < gCurCase->bindColNum; ++c) { - prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); + prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); } } @@ -1502,6 +1638,73 @@ int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) { return 0; } +/* [prepare [settbnametag [bind add] exec]] */ +int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos) { + int32_t loop = 0; + + while (gCurCase->bindColNum >= 2) { + BindData data = {0}; + prepareInsertData(&data); + + int code = taos_stmt_prepare(stmt, data.sql, 0); + if (code != 0){ + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname_tags(stmt, buf, data.pTags + t * gCurCase->bindTagNum); + if (code != 0){ + printf("!!!taos_stmt_set_tbname_tags error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b bindColNum + b*gCurCase->bindColNum)) { + exit(1); + } + + if (taos_stmt_add_batch(stmt)) { + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (taos_stmt_execute(stmt) != 0) { + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + bpCheckIsInsert(stmt, 1); + + destroyData(&data); + + gCurCase->bindColNum -= 2; + gCurCase->bindTagNum -= 2; + gCurCase->fullCol = false; + loop++; + } + + bpCheckAffectedRows(stmt, loop); + + gExecLoopTimes = loop; + + return 0; +} + + /* select * from table */ int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; @@ -2911,63 +3114,6 @@ int sql_s_perf1(TAOS *taos) { void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) { int32_t blen = 0; blen = sprintf(buf, "create table %s%d ", (stable ? bpStbPrefix : bpTbPrefix), tblIdx); - if (stable) { - blen += sprintf(buf + blen, "tags ("); - for (int c = 0; c < colNum; ++c) { - if (c > 0) { - blen += sprintf(buf + blen, ","); - } - switch (colList[c]) { - case TSDB_DATA_TYPE_BOOL: - blen += sprintf(buf + blen, "tbooldata bool"); - break; - case TSDB_DATA_TYPE_TINYINT: - blen += sprintf(buf + blen, "ttinydata tinyint"); - break; - case TSDB_DATA_TYPE_SMALLINT: - blen += sprintf(buf + blen, "tsmalldata smallint"); - break; - case TSDB_DATA_TYPE_INT: - blen += sprintf(buf + blen, "tintdata int"); - break; - case TSDB_DATA_TYPE_BIGINT: - blen += sprintf(buf + blen, "tbigdata bigint"); - break; - case TSDB_DATA_TYPE_FLOAT: - blen += sprintf(buf + blen, "tfloatdata float"); - break; - case TSDB_DATA_TYPE_DOUBLE: - blen += sprintf(buf + blen, "tdoubledata double"); - break; - case TSDB_DATA_TYPE_VARCHAR: - blen += sprintf(buf + blen, "tbinarydata binary(%d)", gVarCharSize); - break; - case TSDB_DATA_TYPE_TIMESTAMP: - blen += sprintf(buf + blen, "tts ts"); - break; - case TSDB_DATA_TYPE_NCHAR: - blen += sprintf(buf + blen, "tnchardata nchar(%d)", gVarCharSize); - break; - case TSDB_DATA_TYPE_UTINYINT: - blen += sprintf(buf + blen, "tutinydata tinyint unsigned"); - break; - case TSDB_DATA_TYPE_USMALLINT: - blen += sprintf(buf + blen, "tusmalldata smallint unsigned"); - break; - case TSDB_DATA_TYPE_UINT: - blen += sprintf(buf + blen, "tuintdata int unsigned"); - break; - case TSDB_DATA_TYPE_UBIGINT: - blen += sprintf(buf + blen, "tubigdata bigint unsigned"); - break; - default: - printf("invalid col type:%d", colList[c]); - exit(1); - } - } - - blen += sprintf(buf + blen, ")"); - } blen += sprintf(buf + blen, " ("); @@ -3027,6 +3173,64 @@ void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t * blen += sprintf(buf + blen, ")"); + if (stable) { + blen += sprintf(buf + blen, "tags ("); + for (int c = 0; c < colNum; ++c) { + if (c > 0) { + blen += sprintf(buf + blen, ","); + } + switch (colList[c]) { + case TSDB_DATA_TYPE_BOOL: + blen += sprintf(buf + blen, "tbooldata bool"); + break; + case TSDB_DATA_TYPE_TINYINT: + blen += sprintf(buf + blen, "ttinydata tinyint"); + break; + case TSDB_DATA_TYPE_SMALLINT: + blen += sprintf(buf + blen, "tsmalldata smallint"); + break; + case TSDB_DATA_TYPE_INT: + blen += sprintf(buf + blen, "tintdata int"); + break; + case TSDB_DATA_TYPE_BIGINT: + blen += sprintf(buf + blen, "tbigdata bigint"); + break; + case TSDB_DATA_TYPE_FLOAT: + blen += sprintf(buf + blen, "tfloatdata float"); + break; + case TSDB_DATA_TYPE_DOUBLE: + blen += sprintf(buf + blen, "tdoubledata double"); + break; + case TSDB_DATA_TYPE_VARCHAR: + blen += sprintf(buf + blen, "tbinarydata binary(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + blen += sprintf(buf + blen, "tts timestamp"); + break; + case TSDB_DATA_TYPE_NCHAR: + blen += sprintf(buf + blen, "tnchardata nchar(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_UTINYINT: + blen += sprintf(buf + blen, "tutinydata tinyint unsigned"); + break; + case TSDB_DATA_TYPE_USMALLINT: + blen += sprintf(buf + blen, "tusmalldata smallint unsigned"); + break; + case TSDB_DATA_TYPE_UINT: + blen += sprintf(buf + blen, "tuintdata int unsigned"); + break; + case TSDB_DATA_TYPE_UBIGINT: + blen += sprintf(buf + blen, "tubigdata bigint unsigned"); + break; + default: + printf("invalid col type:%d", colList[c]); + exit(1); + } + } + + blen += sprintf(buf + blen, ")"); + } + if (gCaseCtrl.printCreateTblSql) { printf("\tCreate Table SQL:%s\n", buf); } @@ -3067,7 +3271,7 @@ void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int prepareStb) { } } else { char buf[1024]; - generateCreateTableSQL(buf, 1, colNum, colList, true); + generateCreateTableSQL(buf, bpDefaultStbId, colNum, colList, true); result = taos_query(taos, buf); code = taos_errno(result); @@ -3113,14 +3317,18 @@ int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) { if (gCurCase->fullCol) { gCurCase->bindColNum = gCurCase->colNum; + gCurCase->bindTagNum = gCurCase->colNum; } gCurCase->bindNullNum = gCaseCtrl.bindNullNum; - gCurCase->prepareStb = gCaseCtrl.prepareStb; if (gCaseCtrl.bindColNum) { gCurCase->bindColNum = gCaseCtrl.bindColNum; gCurCase->fullCol = false; } + if (gCaseCtrl.bindTagNum) { + gCurCase->bindTagNum = gCaseCtrl.bindTagNum; + gCurCase->fullCol = false; + } if (gCaseCtrl.bindRowNum) { gCurCase->bindRowNum = gCaseCtrl.bindRowNum; } @@ -3128,6 +3336,10 @@ int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) { gCurCase->bindColNum = gCaseCtrl.bindColTypeNum; gCurCase->fullCol = false; } + if (gCaseCtrl.bindTagTypeNum) { + gCurCase->bindTagNum = gCaseCtrl.bindTagTypeNum; + gCurCase->fullCol = false; + } if (!silent) { printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc); From 1f4749439f3f0d5c6bad33db1401c3613805d83e Mon Sep 17 00:00:00 2001 From: dapan Date: Mon, 9 May 2022 07:59:07 +0800 Subject: [PATCH 3/9] stmt test --- tests/script/api/batchprepare.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 3dddb03f3b..6afe0a5cd1 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -244,6 +244,7 @@ CaseCtrl gCaseCtrl = { // query case with specified col&oper .printStmtSql = true, .rowNum = 0, .bindColNum = 0, + .bindTagNum = 0, .bindRowNum = 0, .bindColTypeNum = 0, .bindColTypeList = NULL, From 6621ee69a049a249c15c6bec2152145936a14530 Mon Sep 17 00:00:00 2001 From: dapan Date: Mon, 9 May 2022 11:40:24 +0800 Subject: [PATCH 4/9] fix bug --- source/common/src/tmsg.c | 6 +++--- source/libs/executor/src/executorimpl.c | 6 ++++-- source/libs/parser/src/parTranslater.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 56bb93faa4..85b55611dc 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1233,21 +1233,21 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs for (int32_t i = 0; i < numOfCreatedDbs; ++i) { char db[TSDB_DB_FNAME_LEN] = {0}; if (tDecodeCStrTo(pDecoder, db) < 0) return -1; - int32_t len = strlen(db) + 1; + int32_t len = strlen(db); taosHashPut(pRsp->createdDbs, db, len, db, len); } for (int32_t i = 0; i < numOfReadDbs; ++i) { char db[TSDB_DB_FNAME_LEN] = {0}; if (tDecodeCStrTo(pDecoder, db) < 0) return -1; - int32_t len = strlen(db) + 1; + int32_t len = strlen(db); taosHashPut(pRsp->readDbs, db, len, db, len); } for (int32_t i = 0; i < numOfWriteDbs; ++i) { char db[TSDB_DB_FNAME_LEN] = {0}; if (tDecodeCStrTo(pDecoder, db) < 0) return -1; - int32_t len = strlen(db) + 1; + int32_t len = strlen(db); taosHashPut(pRsp->writeDbs, db, len, db, len); } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index e4437f1a93..45995173e6 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4206,7 +4206,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { } } - taosMemoryFree(pOperator->pExpr); + taosMemoryFreeClear(pOperator->pExpr); taosMemoryFreeClear(pOperator->info); taosMemoryFreeClear(pOperator); } @@ -4391,6 +4391,9 @@ void destroySFillOperatorInfo(void* param, int32_t numOfOutput) { } static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) { + if (NULL == param) { + return; + } SProjectOperatorInfo* pInfo = (SProjectOperatorInfo*)param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); cleanupAggSup(&pInfo->aggSup); @@ -5328,7 +5331,6 @@ void doDestroyTask(SExecTaskInfo* pTaskInfo) { // taosArrayDestroy(pTaskInfo->summary.queryProfEvents); // taosHashCleanup(pTaskInfo->summary.operatorProfResults); - destroyOperatorInfo(pTaskInfo->pRoot); taosMemoryFreeClear(pTaskInfo->sql); taosMemoryFreeClear(pTaskInfo->id.str); taosMemoryFreeClear(pTaskInfo); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 63ef3fc9a1..c8a3a89e40 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3146,7 +3146,7 @@ static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) { req.alterType = TSDB_ALTER_USER_ADD_WRITE_DB; } strcpy(req.user, pStmt->userName); - strcpy(req.dbname, pStmt->dbName); + sprintf(req.dbname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->dbName); return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req); } From f0154c03c91b554bbb3baa0d601128e70c0b7b65 Mon Sep 17 00:00:00 2001 From: dapan Date: Mon, 9 May 2022 16:03:56 +0800 Subject: [PATCH 5/9] stmt auto create table --- source/client/src/clientStmt.c | 9 ++- source/libs/parser/src/parInsert.c | 9 +++ tests/script/api/batchprepare.c | 95 +++++++++++++++++++++++++----- 3 files changed, 95 insertions(+), 18 deletions(-) diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 347debe68d..737282d214 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -29,6 +29,11 @@ int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) { if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND_COL)) { code = TSDB_CODE_TSC_STMT_API_ERROR; } +/* + if ((pStmt->sql.type == STMT_TYPE_MULTI_INSERT) && ()) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } +*/ break; case STMT_BIND_COL: if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND)) { @@ -513,8 +518,6 @@ 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; } @@ -532,6 +535,8 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx) { STMT_ERR_RET(stmtParseSql(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)); diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index ba39ba6986..64d2934282 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -241,6 +241,15 @@ static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool SParseContext* pBasicCtx = pCxt->pComCxt; SName name = {0}; createSName(&name, pTname, pBasicCtx->acctId, pBasicCtx->db, &pCxt->msg); + + char dbFname[TSDB_DB_FNAME_LEN] = {0}; + tNameGetFullDbName(&name, dbFname); + + bool pass = false; + CHECK_CODE(catalogChkAuth(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, pBasicCtx->pUser, dbFname, AUTH_TYPE_WRITE, &pass)); + if (!pass) { + return TSDB_CODE_PAR_PERMISSION_DENIED; + } if (isStb) { CHECK_CODE(catalogGetSTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &pCxt->pTableMeta)); diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index ba9fa4638a..f3fab0c965 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -104,7 +104,7 @@ typedef struct { int32_t colNum; int32_t *colList; // full table column list int32_t testType; - bool prepareStb; + bool autoCreateTbl; bool fullCol; int32_t (*runFn)(TAOS_STMT*, TAOS*); int32_t tblNum; @@ -118,8 +118,8 @@ typedef struct { } CaseCfg; CaseCfg gCase[] = { - {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 1, 10, 10, 0, 0, 0, 1, -1}, - {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 0, 1, -1}, + {"insert:MBSE0-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 1, 10, 10, 0, 0, 0, 1, -1}, + {"insert:MBSE0-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 0, 1, -1}, {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 0, 1, -1}, {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 0, 1, -1}, @@ -166,6 +166,7 @@ typedef struct { bool printCreateTblSql; bool printQuerySql; bool printStmtSql; + bool autoCreateTbl; int32_t rowNum; //row num for one table int32_t bindColNum; int32_t bindTagNum; @@ -189,6 +190,35 @@ CaseCtrl gCaseCtrl = { // default .printCreateTblSql = false, .printQuerySql = true, .printStmtSql = true, + .autoCreateTbl = false, + .rowNum = 0, + .bindColNum = 0, + .bindTagNum = 0, + .bindRowNum = 0, + .bindColTypeNum = 0, + .bindColTypeList = NULL, + .bindTagTypeNum = 0, + .bindTagTypeList = NULL, + .optrIdxListNum = 0, + .optrIdxList = NULL, + .checkParamNum = false, + .printRes = true, + .runTimes = 0, + .caseIdx = -1, + .caseNum = -1, + .caseRunIdx = -1, + .caseRunNum = -1, +}; +#endif + + +#if 1 +CaseCtrl gCaseCtrl = { // default + .bindNullNum = 0, + .printCreateTblSql = true, + .printQuerySql = true, + .printStmtSql = true, + .autoCreateTbl = false, .rowNum = 0, .bindColNum = 0, .bindTagNum = 0, @@ -236,12 +266,13 @@ CaseCtrl gCaseCtrl = { // query case with specified col&oper }; #endif -#if 1 +#if 0 CaseCtrl gCaseCtrl = { // query case with specified col&oper .bindNullNum = 0, .printCreateTblSql = true, .printQuerySql = true, .printStmtSql = true, + .autoCreateTbl = true, .rowNum = 0, .bindColNum = 0, .bindTagNum = 0, @@ -1237,6 +1268,15 @@ void bpCheckQueryResult(TAOS_STMT *stmt, TAOS *taos, char *stmtSql, TAOS_MULTI_B printf("***sql res num match stmt res num %d\n", stmtResNum); } +int32_t bpSetTableNameTags(BindData *data, int32_t tblIdx, char *tblName, TAOS_STMT *stmt) { + if (gCurCase->bindTagNum > 0) { + return taos_stmt_set_tbname_tags(stmt, tblName, data->pTags + tblIdx * gCurCase->bindTagNum); + } else { + return taos_stmt_set_tbname(stmt, tblName); + } +} + + /* prepare [settbname [bind add]] exec */ int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; @@ -1255,7 +1295,7 @@ int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1312,7 +1352,7 @@ int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1365,7 +1405,7 @@ int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1419,7 +1459,7 @@ int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1473,7 +1513,7 @@ int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1488,7 +1528,7 @@ int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1540,7 +1580,7 @@ int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1596,7 +1636,7 @@ int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) { if (gCurCase->tblNum > 1) { char buf[32]; sprintf(buf, "t%d", t); - code = taos_stmt_set_tbname(stmt, buf); + code = bpSetTableNameTags(&data, t, buf, stmt); if (code != 0){ printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); @@ -1640,11 +1680,12 @@ int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) { return 0; } + /* [prepare [settbnametag [bind add] exec]] */ int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos) { int32_t loop = 0; - while (gCurCase->bindColNum >= 2) { + while (gCurCase->bindTagNum > 0 && gCurCase->bindColNum > 0) { BindData data = {0}; prepareInsertData(&data); @@ -3316,10 +3357,23 @@ int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) { if (gCaseCtrl.rowNum) { gCurCase->rowNum = gCaseCtrl.rowNum; } + + if (gCaseCtrl.autoCreateTbl) { + if (gCurCase->testType == TTYPE_INSERT && gCurCase->tblNum > 1) { + gCurCase->autoCreateTbl = true; + if (gCurCase->bindTagNum <= 0) { + gCurCase->bindTagNum = gCurCase->colNum; + } + } else { + return 1; + } + } if (gCurCase->fullCol) { gCurCase->bindColNum = gCurCase->colNum; - gCurCase->bindTagNum = gCurCase->colNum; + if (gCurCase->autoCreateTbl) { + gCurCase->bindTagNum = gCurCase->colNum; + } } gCurCase->bindNullNum = gCaseCtrl.bindNullNum; @@ -3350,7 +3404,7 @@ int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) { totalUs = 0; for (int32_t n = 0; n < gCurCase->runTimes; ++n) { if (gCurCase->preCaseIdx < 0) { - prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->prepareStb); + prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->autoCreateTbl); } beginUs = taosGetTimestampUs(); @@ -3411,10 +3465,18 @@ void* runCaseList(TAOS *taos) { } void runAll(TAOS *taos) { +/* strcpy(gCaseCtrl.caseCatalog, "Normal Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); runCaseList(taos); +*/ + strcpy(gCaseCtrl.caseCatalog, "Auto Create Table Test"); + gCaseCtrl.autoCreateTbl = true; + printf("%s Begin\n", gCaseCtrl.caseCatalog); + runCaseList(taos); + gCaseCtrl.autoCreateTbl = false; +/* strcpy(gCaseCtrl.caseCatalog, "Null Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.bindNullNum = 1; @@ -3458,7 +3520,8 @@ void runAll(TAOS *taos) { gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList); gCaseCtrl.bindColTypeList = bindColTypeList; runCaseList(taos); - +*/ + printf("All Test End\n"); } From 0c1ac7a3674e923c0579826a1bc8362e86926ac7 Mon Sep 17 00:00:00 2001 From: dapan Date: Mon, 9 May 2022 17:01:55 +0800 Subject: [PATCH 6/9] stmt test --- source/libs/parser/src/parInsertData.c | 2 +- tests/script/api/batchprepare.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index c5c4463a95..5fa2961474 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -469,7 +469,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p // the maximum expanded size in byte when a row-wise data is converted to SDataRow format int32_t expandSize = isRawPayload ? getRowExpandSize(pOneTableBlock->pTableMeta) : 0; int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize + - sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta); + sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta) + pOneTableBlock->createTbReqLen; if (dataBuf->nAllocSize < destSize) { dataBuf->nAllocSize = (uint32_t)(destSize * 1.5); diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index f3fab0c965..8169e6c503 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -233,9 +233,9 @@ CaseCtrl gCaseCtrl = { // default .printRes = true, .runTimes = 0, .caseIdx = -1, - .caseNum = -1, - .caseRunIdx = -1, - .caseRunNum = -1, + .caseNum = 1, + .caseRunIdx = 11, + .caseRunNum = 1, }; #endif From 1157154d1e1233f505edb08a89bb7d486fa66021 Mon Sep 17 00:00:00 2001 From: dapan Date: Mon, 9 May 2022 20:03:09 +0800 Subject: [PATCH 7/9] stmt test --- source/client/src/clientStmt.c | 6 ++++-- source/libs/parser/src/parInsertData.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 737282d214..c804213d89 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -465,10 +465,12 @@ int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags) { STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS)); - if (pStmt->bInfo.needParse) { - STMT_ERR_RET(stmtParseSql(pStmt)); + if (!pStmt->bInfo.needParse) { + return TSDB_CODE_SUCCESS; } + STMT_ERR_RET(stmtParseSql(pStmt)); + STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid)); if (NULL == pDataBlock) { tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid); diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index 5fa2961474..c074334722 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -601,6 +601,7 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) { pBlock->numOfTables = 1; pBlock->nAllocSize = TSDB_PAYLOAD_SIZE; pBlock->headerSize = pBlock->size; + pBlock->createTbReqLen = 0; memset(&pBlock->rowBuilder, 0, sizeof(pBlock->rowBuilder)); From 3cc90115792c65cd98dc6807ba2b77b61fa481de Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 9 May 2022 20:35:59 +0800 Subject: [PATCH 8/9] fix case --- source/dnode/mnode/impl/test/user/user.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 1e03d8ff4a..3c15bc3492 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -367,8 +367,8 @@ TEST_F(MndTestUser, 03_Alter_User) { EXPECT_EQ(numOfReadDbs, 1); EXPECT_EQ(numOfWriteDbs, 0); - char* dbname = (char*)taosHashGet(authRsp.readDbs, "1.d2", 5); - EXPECT_STREQ(dbname, "1.d2"); + char* dbname = (char*)taosHashGet(authRsp.readDbs, "1.d2", 4); + EXPECT_TRUE(dbname != NULL); taosHashCleanup(authRsp.readDbs); taosHashCleanup(authRsp.writeDbs); From 5122a6e2689ac5d286f38d26d0297083db635b9f Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 9 May 2022 21:52:39 +0800 Subject: [PATCH 9/9] enh: add submit row debug log in taosd --- include/common/taosdef.h | 2 +- source/dnode/vnode/src/tsdb/tsdbMemTable.c | 5 +++ source/dnode/vnode/src/vnd/vnodeSvr.c | 46 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/common/taosdef.h b/include/common/taosdef.h index e1f8832edf..5384082da3 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -89,7 +89,7 @@ extern char *qtypeStr[]; #define TSDB_PORT_HTTP 11 -#undef TD_DEBUG_PRINT_ROW +#define TD_DEBUG_PRINT_ROW #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index eaa0893f29..d514512881 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -326,6 +326,11 @@ int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlo tSkipListPutBatchByIter(pTbData->pData, &blkIter, (iter_next_fn_t)tGetSubmitBlkNext); +#ifdef TD_DEBUG_PRINT_ROW + printf("!!! %s:%d table %" PRIi64 " has %d rows in skiplist\n\n", __func__, __LINE__, pTbData->uid, + SL_SIZE(pTbData->pData)); +#endif + // Set statistics keyMax = TD_ROW_KEY(blkIter.row); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index abc112038b..a54c30fc61 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -497,6 +497,47 @@ _exit: return 0; } +static int vnodeDebugPrintSubmitMsg(SVnode *pVnode, SSubmitReq *pMsg, const char* tags) { + ASSERT(pMsg != NULL); + SSubmitMsgIter msgIter = {0}; + SMeta *pMeta = pVnode->pMeta; + SSubmitBlk *pBlock = NULL; + SSubmitBlkIter blkIter = {0}; + STSRow *row = NULL; + STSchema *pSchema = NULL; + tb_uid_t suid = 0; + + if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1; + while (true) { + if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1; + if (pBlock == NULL) break; + tInitSubmitBlkIter(&msgIter, pBlock, &blkIter); + if (blkIter.row == NULL) continue; + if (!pSchema || (suid != msgIter.suid)) { + if (pSchema) { + taosMemoryFreeClear(pSchema); + } + pSchema = metaGetTbTSchema(pMeta, msgIter.suid, 0); // TODO: use the real schema + if(pSchema) { + suid = msgIter.suid; + } + } + if(!pSchema) { + printf("%s:%d no valid schema\n", tags, __LINE__); + continue; + } + char __tags[128] = {0}; + snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter.uid); + while ((row = tGetSubmitBlkNext(&blkIter))) { + tdSRowPrint(row, pSchema, __tags); + } + } + + taosMemoryFreeClear(pSchema); + + return 0; +} + static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { SSubmitReq *pSubmitReq = (SSubmitReq *)pReq; SSubmitMsgIter msgIter = {0}; @@ -508,6 +549,10 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in pRsp->code = 0; +#ifdef TD_DEBUG_PRINT_ROW + vnodeDebugPrintSubmitMsg(pVnode, pReq, __func__); +#endif + // handle the request if (tInitSubmitMsgIter(pSubmitReq, &msgIter) < 0) { pRsp->code = TSDB_CODE_INVALID_MSG; @@ -551,6 +596,7 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in } rsp.affectedRows += nRows; + } _exit: