stmt
This commit is contained in:
parent
c8fe5bc88b
commit
1e1cca9857
|
@ -26,7 +26,7 @@ typedef void STableDataBlocks;
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STMT_TYPE_INSERT = 1,
|
STMT_TYPE_INSERT = 1,
|
||||||
STMT_TYPE_MULTI_INSERT,
|
STMT_TYPE_MULTI_INSERT,
|
||||||
STMT_TYPE_QUERY
|
STMT_TYPE_QUERY,
|
||||||
} STMT_TYPE;
|
} STMT_TYPE;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -38,7 +38,7 @@ typedef enum {
|
||||||
STMT_BIND,
|
STMT_BIND,
|
||||||
STMT_BIND_COL,
|
STMT_BIND_COL,
|
||||||
STMT_ADD_BATCH,
|
STMT_ADD_BATCH,
|
||||||
STMT_EXECUTE
|
STMT_EXECUTE,
|
||||||
} STMT_STATUS;
|
} STMT_STATUS;
|
||||||
|
|
||||||
typedef struct SStmtTableCache {
|
typedef struct SStmtTableCache {
|
||||||
|
@ -79,7 +79,7 @@ typedef struct STscStmt {
|
||||||
|
|
||||||
SStmtSQLInfo sql;
|
SStmtSQLInfo sql;
|
||||||
SStmtExecInfo exec;
|
SStmtExecInfo exec;
|
||||||
SStmtBindInfo bind;
|
SStmtBindInfo bInfo;
|
||||||
} STscStmt;
|
} STscStmt;
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +91,6 @@ typedef struct STscStmt {
|
||||||
do { \
|
do { \
|
||||||
switch (_newstatus) { \
|
switch (_newstatus) { \
|
||||||
case STMT_INIT: \
|
case STMT_INIT: \
|
||||||
if ((_stmt)->sql.status != 0) return (_errcode); \
|
|
||||||
break; \
|
break; \
|
||||||
case STMT_PREPARE: \
|
case STMT_PREPARE: \
|
||||||
if ((_stmt)->sql.status != STMT_INIT) STMT_ERR_RET(_errcode); \
|
if ((_stmt)->sql.status != STMT_INIT) STMT_ERR_RET(_errcode); \
|
||||||
|
|
|
@ -127,6 +127,10 @@ const char *taos_errstr(TAOS_RES *res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void taos_free_result(TAOS_RES *res) {
|
void taos_free_result(TAOS_RES *res) {
|
||||||
|
if (NULL == res) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SRequestObj *pRequest = (SRequestObj *)res;
|
SRequestObj *pRequest = (SRequestObj *)res;
|
||||||
destroyRequest(pRequest);
|
destroyRequest(pRequest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,12 @@ int32_t stmtGetTbName(TAOS_STMT *stmt, char **tbName) {
|
||||||
|
|
||||||
pStmt->sql.type = STMT_TYPE_MULTI_INSERT;
|
pStmt->sql.type = STMT_TYPE_MULTI_INSERT;
|
||||||
|
|
||||||
if (NULL == pStmt->bind.tbName) {
|
if (NULL == pStmt->bInfo.tbName) {
|
||||||
tscError("no table name set");
|
tscError("no table name set");
|
||||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_TBNAME_ERROR);
|
STMT_ERR_RET(TSDB_CODE_TSC_STMT_TBNAME_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
*tbName = pStmt->bind.tbName;
|
*tbName = pStmt->bInfo.tbName;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ int32_t stmtGetTbName(TAOS_STMT *stmt, char **tbName) {
|
||||||
int32_t stmtSetBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags) {
|
int32_t stmtSetBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags) {
|
||||||
STscStmt* pStmt = (STscStmt*)stmt;
|
STscStmt* pStmt = (STscStmt*)stmt;
|
||||||
|
|
||||||
pStmt->bind.tbUid = pTableMeta->uid;
|
pStmt->bInfo.tbUid = pTableMeta->uid;
|
||||||
pStmt->bind.tbSuid = pTableMeta->suid;
|
pStmt->bInfo.tbSuid = pTableMeta->suid;
|
||||||
pStmt->bind.tbType = pTableMeta->tableType;
|
pStmt->bInfo.tbType = pTableMeta->tableType;
|
||||||
pStmt->bind.boundTags = tags;
|
pStmt->bInfo.boundTags = tags;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,11 @@ int32_t stmtCacheBlock(STscStmt *pStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
if (TSDB_CHILD_TABLE == pStmt->bind.tbType) {
|
if (TSDB_CHILD_TABLE == pStmt->bInfo.tbType) {
|
||||||
uid = pStmt->bind.tbSuid;
|
uid = pStmt->bInfo.tbSuid;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(TSDB_NORMAL_TABLE == pStmt->bind.tbType);
|
ASSERT(TSDB_NORMAL_TABLE == pStmt->bInfo.tbType);
|
||||||
uid = pStmt->bind.tbUid;
|
uid = pStmt->bInfo.tbUid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosHashGet(pStmt->sql.pTableCache, &uid, sizeof(uid))) {
|
if (taosHashGet(pStmt->sql.pTableCache, &uid, sizeof(uid))) {
|
||||||
|
@ -72,14 +72,14 @@ int32_t stmtCacheBlock(STscStmt *pStmt) {
|
||||||
|
|
||||||
SStmtTableCache cache = {
|
SStmtTableCache cache = {
|
||||||
.pDataBlock = pDst,
|
.pDataBlock = pDst,
|
||||||
.boundTags = pStmt->bind.boundTags,
|
.boundTags = pStmt->bInfo.boundTags,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (taosHashPut(pStmt->sql.pTableCache, &uid, sizeof(uid), &cache, sizeof(cache))) {
|
if (taosHashPut(pStmt->sql.pTableCache, &uid, sizeof(uid), &cache, sizeof(cache))) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStmt->bind.boundTags = NULL;
|
pStmt->bInfo.boundTags = NULL;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ int32_t stmtParseSql(STscStmt* pStmt) {
|
||||||
|
|
||||||
STMT_ERR_RET(parseSql(pStmt->exec.pRequest, false, &pStmt->sql.pQuery, &stmtCb));
|
STMT_ERR_RET(parseSql(pStmt->exec.pRequest, false, &pStmt->sql.pQuery, &stmtCb));
|
||||||
|
|
||||||
pStmt->bind.needParse = false;
|
pStmt->bInfo.needParse = false;
|
||||||
|
|
||||||
switch (nodeType(pStmt->sql.pQuery->pRoot)) {
|
switch (nodeType(pStmt->sql.pQuery->pRoot)) {
|
||||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||||
|
@ -116,14 +116,14 @@ int32_t stmtParseSql(STscStmt* pStmt) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
int32_t stmtCleanBindInfo(STscStmt* pStmt) {
|
int32_t stmtCleanBindInfo(STscStmt* pStmt) {
|
||||||
pStmt->bind.tbUid = 0;
|
pStmt->bInfo.tbUid = 0;
|
||||||
pStmt->bind.tbSuid = 0;
|
pStmt->bInfo.tbSuid = 0;
|
||||||
pStmt->bind.tbType = 0;
|
pStmt->bInfo.tbType = 0;
|
||||||
pStmt->bind.needParse = true;
|
pStmt->bInfo.needParse = true;
|
||||||
|
|
||||||
taosMemoryFreeClear(pStmt->bind.tbName);
|
taosMemoryFreeClear(pStmt->bInfo.tbName);
|
||||||
destroyBoundColumnInfo(pStmt->bind.boundTags);
|
destroyBoundColumnInfo(pStmt->bInfo.boundTags);
|
||||||
taosMemoryFreeClear(pStmt->bind.boundTags);
|
taosMemoryFreeClear(pStmt->bInfo.boundTags);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable) {
|
||||||
STableDataBlocks* pBlocks = *(STableDataBlocks**)pIter;
|
STableDataBlocks* pBlocks = *(STableDataBlocks**)pIter;
|
||||||
uint64_t *key = taosHashGetKey(pIter, NULL);
|
uint64_t *key = taosHashGetKey(pIter, NULL);
|
||||||
|
|
||||||
if (keepTable && (*key == pStmt->bind.tbUid)) {
|
if (keepTable && (*key == pStmt->bInfo.tbUid)) {
|
||||||
qResetStmtDataBlock(pBlocks, true);
|
qResetStmtDataBlock(pBlocks, true);
|
||||||
|
|
||||||
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
||||||
|
@ -197,10 +197,10 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
||||||
|
|
||||||
STableMeta *pTableMeta = NULL;
|
STableMeta *pTableMeta = NULL;
|
||||||
SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp);
|
SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp);
|
||||||
STMT_ERR_RET(catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bind.sname, &pTableMeta));
|
STMT_ERR_RET(catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &pTableMeta));
|
||||||
|
|
||||||
if (pTableMeta->uid == pStmt->bind.tbUid) {
|
if (pTableMeta->uid == pStmt->bInfo.tbUid) {
|
||||||
pStmt->bind.needParse = false;
|
pStmt->bInfo.needParse = false;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -212,29 +212,29 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
||||||
STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR);
|
STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
pStmt->bind.needParse = false;
|
pStmt->bInfo.needParse = false;
|
||||||
|
|
||||||
pStmt->bind.tbUid = pTableMeta->uid;
|
pStmt->bInfo.tbUid = pTableMeta->uid;
|
||||||
pStmt->bind.tbSuid = pTableMeta->suid;
|
pStmt->bInfo.tbSuid = pTableMeta->suid;
|
||||||
pStmt->bind.tbType = pTableMeta->tableType;
|
pStmt->bInfo.tbType = pTableMeta->tableType;
|
||||||
pStmt->bind.boundTags = pCache->boundTags;
|
pStmt->bInfo.boundTags = pCache->boundTags;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pTableMeta->uid, sizeof(pTableMeta->uid));
|
SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pTableMeta->uid, sizeof(pTableMeta->uid));
|
||||||
if (pCache) {
|
if (pCache) {
|
||||||
pStmt->bind.needParse = false;
|
pStmt->bInfo.needParse = false;
|
||||||
|
|
||||||
pStmt->bind.tbUid = pTableMeta->uid;
|
pStmt->bInfo.tbUid = pTableMeta->uid;
|
||||||
pStmt->bind.tbSuid = pTableMeta->suid;
|
pStmt->bInfo.tbSuid = pTableMeta->suid;
|
||||||
pStmt->bind.tbType = pTableMeta->tableType;
|
pStmt->bInfo.tbType = pTableMeta->tableType;
|
||||||
pStmt->bind.boundTags = pCache->boundTags;
|
pStmt->bInfo.boundTags = pCache->boundTags;
|
||||||
|
|
||||||
STableDataBlocks* pNewBlock = NULL;
|
STableDataBlocks* pNewBlock = NULL;
|
||||||
STMT_ERR_RET(qRebuildStmtDataBlock(&pNewBlock, pCache->pDataBlock));
|
STMT_ERR_RET(qRebuildStmtDataBlock(&pNewBlock, pCache->pDataBlock));
|
||||||
|
|
||||||
if (taosHashPut(pStmt->exec.pBlockHash, &pStmt->bind.tbUid, sizeof(pStmt->bind.tbUid), &pNewBlock, POINTER_BYTES)) {
|
if (taosHashPut(pStmt->exec.pBlockHash, &pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid), &pNewBlock, POINTER_BYTES)) {
|
||||||
STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,11 +261,11 @@ TAOS_STMT *stmtInit(TAOS *taos) {
|
||||||
taosMemoryFree(pStmt);
|
taosMemoryFree(pStmt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStmt->taos = pObj;
|
|
||||||
pStmt->sql.status = STMT_INIT;
|
|
||||||
pStmt->bind.needParse = true;
|
|
||||||
|
|
||||||
|
pStmt->taos = pObj;
|
||||||
|
pStmt->bInfo.needParse = true;
|
||||||
|
pStmt->sql.status = STMT_INIT;
|
||||||
|
|
||||||
return pStmt;
|
return pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,15 +290,15 @@ int stmtSetTbName(TAOS_STMT *stmt, const char *tbName) {
|
||||||
|
|
||||||
STMT_SWITCH_STATUS(pStmt, STMT_SETTBNAME, TSDB_CODE_TSC_STMT_API_ERROR);
|
STMT_SWITCH_STATUS(pStmt, STMT_SETTBNAME, TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
|
|
||||||
taosMemoryFree(pStmt->bind.tbName);
|
taosMemoryFree(pStmt->bInfo.tbName);
|
||||||
|
|
||||||
if (NULL == pStmt->exec.pRequest) {
|
if (NULL == pStmt->exec.pRequest) {
|
||||||
STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest));
|
STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
STMT_ERR_RET(qCreateSName(&pStmt->bind.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
|
STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
|
||||||
|
|
||||||
pStmt->bind.tbName = strdup(tbName);
|
pStmt->bInfo.tbName = strdup(tbName);
|
||||||
|
|
||||||
STMT_ERR_RET(stmtGetFromCache(pStmt));
|
STMT_ERR_RET(stmtGetFromCache(pStmt));
|
||||||
|
|
||||||
|
@ -310,17 +310,17 @@ int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags) {
|
||||||
|
|
||||||
STMT_SWITCH_STATUS(pStmt, STMT_SETTBNAME, TSDB_CODE_TSC_STMT_API_ERROR);
|
STMT_SWITCH_STATUS(pStmt, STMT_SETTBNAME, TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
|
|
||||||
if (pStmt->bind.needParse) {
|
if (pStmt->bInfo.needParse) {
|
||||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bind.tbUid, sizeof(pStmt->bind.tbUid));
|
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid));
|
||||||
if (NULL == pDataBlock) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bind.tbUid);
|
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid);
|
||||||
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
STMT_ERR_RET(qBindStmtTagsValue(pDataBlock, pStmt->bind.boundTags, pStmt->bind.tbSuid, &pStmt->bind.sname, tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
|
STMT_ERR_RET(qBindStmtTagsValue(pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, &pStmt->bInfo.sname, tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ int32_t stmtFetchTagFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
|
||||||
|
|
||||||
STMT_SWITCH_STATUS(pStmt, STMT_FETCH_TAG_FIELDS, TSDB_CODE_TSC_STMT_API_ERROR);
|
STMT_SWITCH_STATUS(pStmt, STMT_FETCH_TAG_FIELDS, TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
|
|
||||||
if (pStmt->bind.needParse) {
|
if (pStmt->bInfo.needParse) {
|
||||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,13 +340,13 @@ int32_t stmtFetchTagFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
|
||||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bind.tbUid, sizeof(pStmt->bind.tbUid));
|
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid));
|
||||||
if (NULL == pDataBlock) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bind.tbUid);
|
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid);
|
||||||
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
STMT_ERR_RET(qBuildStmtTagFields(pDataBlock, pStmt->bind.boundTags, fieldNum, fields));
|
STMT_ERR_RET(qBuildStmtTagFields(pDataBlock, pStmt->bInfo.boundTags, fieldNum, fields));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ int32_t stmtFetchColFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
|
||||||
|
|
||||||
STMT_SWITCH_STATUS(pStmt, STMT_FETCH_COL_FIELDS, TSDB_CODE_TSC_STMT_API_ERROR);
|
STMT_SWITCH_STATUS(pStmt, STMT_FETCH_COL_FIELDS, TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
|
|
||||||
if (pStmt->bind.needParse) {
|
if (pStmt->bInfo.needParse) {
|
||||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,9 +365,9 @@ int32_t stmtFetchColFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
|
||||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bind.tbUid, sizeof(pStmt->bind.tbUid));
|
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid));
|
||||||
if (NULL == pDataBlock) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bind.tbUid);
|
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid);
|
||||||
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,21 +381,21 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) {
|
||||||
|
|
||||||
STMT_SWITCH_STATUS(pStmt, STMT_BIND, TSDB_CODE_TSC_STMT_API_ERROR);
|
STMT_SWITCH_STATUS(pStmt, STMT_BIND, TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
|
|
||||||
if (pStmt->bind.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
|
if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
|
||||||
pStmt->bind.needParse = false;
|
pStmt->bInfo.needParse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pStmt->exec.pRequest) {
|
if (NULL == pStmt->exec.pRequest) {
|
||||||
STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest));
|
STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStmt->bind.needParse) {
|
if (pStmt->bInfo.needParse) {
|
||||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bind.tbUid, sizeof(pStmt->bind.tbUid));
|
STableDataBlocks *pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid));
|
||||||
if (NULL == pDataBlock) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bind.tbUid);
|
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid);
|
||||||
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "../../../include/client/taos.h"
|
#include "../../../include/client/taos.h"
|
||||||
|
|
||||||
|
@ -15,19 +16,23 @@ typedef struct {
|
||||||
|
|
||||||
void taosMsleep(int mseconds);
|
void taosMsleep(int mseconds);
|
||||||
|
|
||||||
unsigned long long getCurrentTime(){
|
int32_t taosGetTimeOfDay(struct timeval *tv) {
|
||||||
struct timeval tv;
|
return gettimeofday(tv, NULL);
|
||||||
if (taosGetTimeOfDay(&tv) != 0) {
|
}
|
||||||
perror("Failed to get current time in ms");
|
void *taosMemoryCalloc(int32_t num, int32_t size) {
|
||||||
exit(EXIT_FAILURE);
|
return calloc(num, size);
|
||||||
}
|
}
|
||||||
|
void taosMemoryFree(const void *ptr) {
|
||||||
|
if (ptr == NULL) return;
|
||||||
|
|
||||||
return (uint64_t)tv.tv_sec * 1000000ULL + (uint64_t)tv.tv_usec;
|
return free((void*)ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int64_t taosGetTimestampUs() {
|
||||||
|
struct timeval systemTime;
|
||||||
|
taosGetTimeOfDay(&systemTime);
|
||||||
|
return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
|
||||||
|
}
|
||||||
|
|
||||||
int stmt_scol_func1(TAOS_STMT *stmt) {
|
int stmt_scol_func1(TAOS_STMT *stmt) {
|
||||||
struct {
|
struct {
|
||||||
|
@ -42,43 +47,50 @@ int stmt_scol_func1(TAOS_STMT *stmt) {
|
||||||
char bin[40];
|
char bin[40];
|
||||||
char blob[80];
|
char blob[80];
|
||||||
} v = {0};
|
} v = {0};
|
||||||
|
int32_t len[10] = {sizeof(v.ts), sizeof(v.v1), sizeof(v.v2), sizeof(v.f4), sizeof(v.bin), sizeof(v.bin)};
|
||||||
|
|
||||||
TAOS_BIND params[10];
|
TAOS_BIND_v2 params[10];
|
||||||
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
params[0].buffer_length = sizeof(v.ts);
|
params[0].buffer_length = sizeof(v.ts);
|
||||||
params[0].buffer = &v.ts;
|
params[0].buffer = &v.ts;
|
||||||
params[0].length = ¶ms[0].buffer_length;
|
params[0].length = &len[0];
|
||||||
params[0].is_null = NULL;
|
params[0].is_null = NULL;
|
||||||
|
params[0].num = 1;
|
||||||
|
|
||||||
params[1].buffer_type = TSDB_DATA_TYPE_TINYINT;
|
params[1].buffer_type = TSDB_DATA_TYPE_TINYINT;
|
||||||
params[1].buffer_length = sizeof(v.v1);
|
params[1].buffer_length = sizeof(v.v1);
|
||||||
params[1].buffer = &v.v1;
|
params[1].buffer = &v.v1;
|
||||||
params[1].length = ¶ms[1].buffer_length;
|
params[1].length = &len[1];
|
||||||
params[1].is_null = NULL;
|
params[1].is_null = NULL;
|
||||||
|
params[1].num = 1;
|
||||||
|
|
||||||
params[2].buffer_type = TSDB_DATA_TYPE_SMALLINT;
|
params[2].buffer_type = TSDB_DATA_TYPE_SMALLINT;
|
||||||
params[2].buffer_length = sizeof(v.v2);
|
params[2].buffer_length = sizeof(v.v2);
|
||||||
params[2].buffer = &v.v2;
|
params[2].buffer = &v.v2;
|
||||||
params[2].length = ¶ms[2].buffer_length;
|
params[2].length = &len[2];
|
||||||
params[2].is_null = NULL;
|
params[2].is_null = NULL;
|
||||||
|
params[2].num = 1;
|
||||||
|
|
||||||
params[3].buffer_type = TSDB_DATA_TYPE_FLOAT;
|
params[3].buffer_type = TSDB_DATA_TYPE_FLOAT;
|
||||||
params[3].buffer_length = sizeof(v.f4);
|
params[3].buffer_length = sizeof(v.f4);
|
||||||
params[3].buffer = &v.f4;
|
params[3].buffer = &v.f4;
|
||||||
params[3].length = ¶ms[3].buffer_length;
|
params[3].length = &len[3];
|
||||||
params[3].is_null = NULL;
|
params[3].is_null = NULL;
|
||||||
|
params[3].num = 1;
|
||||||
|
|
||||||
params[4].buffer_type = TSDB_DATA_TYPE_BINARY;
|
params[4].buffer_type = TSDB_DATA_TYPE_BINARY;
|
||||||
params[4].buffer_length = sizeof(v.bin);
|
params[4].buffer_length = sizeof(v.bin);
|
||||||
params[4].buffer = v.bin;
|
params[4].buffer = v.bin;
|
||||||
params[4].length = ¶ms[4].buffer_length;
|
params[4].length = &len[4];
|
||||||
params[4].is_null = NULL;
|
params[4].is_null = NULL;
|
||||||
|
params[4].num = 1;
|
||||||
|
|
||||||
params[5].buffer_type = TSDB_DATA_TYPE_BINARY;
|
params[5].buffer_type = TSDB_DATA_TYPE_BINARY;
|
||||||
params[5].buffer_length = sizeof(v.bin);
|
params[5].buffer_length = sizeof(v.bin);
|
||||||
params[5].buffer = v.bin;
|
params[5].buffer = v.bin;
|
||||||
params[5].length = ¶ms[5].buffer_length;
|
params[5].length = &len[5];
|
||||||
params[5].is_null = NULL;
|
params[5].is_null = NULL;
|
||||||
|
params[5].num = 1;
|
||||||
|
|
||||||
char *sql = "insert into ? (ts, v1,v2,f4,bin,bin2) values(?,?,?,?,?,?)";
|
char *sql = "insert into ? (ts, v1,v2,f4,bin,bin2) values(?,?,?,?,?,?)";
|
||||||
int code = taos_stmt_prepare(stmt, sql, 0);
|
int code = taos_stmt_prepare(stmt, sql, 0);
|
||||||
|
@ -122,7 +134,7 @@ int stmt_scol_func1(TAOS_STMT *stmt) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
int stmt_scol_func2(TAOS_STMT *stmt) {
|
int stmt_scol_func2(TAOS_STMT *stmt) {
|
||||||
struct {
|
struct {
|
||||||
|
@ -4192,7 +4204,7 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void check_result(TAOS *taos, char *tname, int printr, int expected) {
|
void check_result(TAOS *taos, char *tname, int printr, int expected) {
|
||||||
char sql[255] = "SELECT * FROM ";
|
char sql[255] = "SELECT * FROM ";
|
||||||
|
@ -4263,7 +4275,7 @@ int sql_perf1(TAOS *taos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long starttime = getCurrentTime();
|
int64_t starttime = taosGetTimestampUs();
|
||||||
for (int i = 0; i < 3000; ++i) {
|
for (int i = 0; i < 3000; ++i) {
|
||||||
result = taos_query(taos, sql[i]);
|
result = taos_query(taos, sql[i]);
|
||||||
int code = taos_errno(result);
|
int code = taos_errno(result);
|
||||||
|
@ -4275,7 +4287,7 @@ int sql_perf1(TAOS *taos) {
|
||||||
|
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
}
|
}
|
||||||
unsigned long long endtime = getCurrentTime();
|
int64_t endtime = taosGetTimestampUs();
|
||||||
printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));
|
printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));
|
||||||
|
|
||||||
for (int i = 0; i < 3000; i++) {
|
for (int i = 0; i < 3000; i++) {
|
||||||
|
@ -4291,7 +4303,7 @@ int sql_perf1(TAOS *taos) {
|
||||||
|
|
||||||
//one table 60 records one time
|
//one table 60 records one time
|
||||||
int sql_perf_s1(TAOS *taos) {
|
int sql_perf_s1(TAOS *taos) {
|
||||||
char **sql = taosMemoryCalloc(1, sizeof(char*) * 360000);
|
char **sql = calloc(1, sizeof(char*) * 360000);
|
||||||
TAOS_RES *result;
|
TAOS_RES *result;
|
||||||
|
|
||||||
for (int i = 0; i < 360000; i++) {
|
for (int i = 0; i < 360000; i++) {
|
||||||
|
@ -4316,7 +4328,7 @@ int sql_perf_s1(TAOS *taos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long starttime = getCurrentTime();
|
unsigned long long starttime = taosGetTimestampUs();
|
||||||
for (int i = 0; i < 360000; ++i) {
|
for (int i = 0; i < 360000; ++i) {
|
||||||
result = taos_query(taos, sql[i]);
|
result = taos_query(taos, sql[i]);
|
||||||
int code = taos_errno(result);
|
int code = taos_errno(result);
|
||||||
|
@ -4328,7 +4340,7 @@ int sql_perf_s1(TAOS *taos) {
|
||||||
|
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
}
|
}
|
||||||
unsigned long long endtime = getCurrentTime();
|
unsigned long long endtime = taosGetTimestampUs();
|
||||||
printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));
|
printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));
|
||||||
|
|
||||||
for (int i = 0; i < 360000; i++) {
|
for (int i = 0; i < 360000; i++) {
|
||||||
|
@ -4363,7 +4375,7 @@ int sql_s_perf1(TAOS *taos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long starttime = getCurrentTime();
|
unsigned long long starttime = taosGetTimestampUs();
|
||||||
for (int i = 0; i < 3000; ++i) {
|
for (int i = 0; i < 3000; ++i) {
|
||||||
result = taos_query(taos, sql[i]);
|
result = taos_query(taos, sql[i]);
|
||||||
int code = taos_errno(result);
|
int code = taos_errno(result);
|
||||||
|
@ -4375,7 +4387,7 @@ int sql_s_perf1(TAOS *taos) {
|
||||||
|
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
}
|
}
|
||||||
unsigned long long endtime = getCurrentTime();
|
unsigned long long endtime = taosGetTimestampUs();
|
||||||
printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));
|
printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));
|
||||||
|
|
||||||
for (int i = 0; i < 3000; i++) {
|
for (int i = 0; i < 3000; i++) {
|
||||||
|
@ -4528,7 +4540,7 @@ void* runcase(void *par) {
|
||||||
taos_stmt_close(stmt);
|
taos_stmt_close(stmt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
#if 1
|
#if 1
|
||||||
prepare(taos, 1, 1);
|
prepare(taos, 1, 1);
|
||||||
|
|
||||||
|
@ -5024,6 +5036,7 @@ void* runcase(void *par) {
|
||||||
printf("check result end\n");
|
printf("check result end\n");
|
||||||
taos_stmt_close(stmt);
|
taos_stmt_close(stmt);
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("test end\n");
|
printf("test end\n");
|
||||||
|
@ -5066,11 +5079,11 @@ int main(int argc, char *argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TdThread *pThreadList = (TdThread *) taosMemoryCalloc(sizeof(TdThread), 4);
|
pthread_t *pThreadList = (pthread_t *) taosMemoryCalloc(sizeof(pthread_t), 4);
|
||||||
|
|
||||||
TdThreadAttr thattr;
|
pthread_attr_t thattr;
|
||||||
taosThreadAttrInit(&thattr);
|
pthread_attr_init(&thattr);
|
||||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||||
T_par par[4];
|
T_par par[4];
|
||||||
|
|
||||||
par[0].taos = taos[0];
|
par[0].taos = taos[0];
|
||||||
|
@ -5082,13 +5095,13 @@ int main(int argc, char *argv[])
|
||||||
par[3].taos = taos[3];
|
par[3].taos = taos[3];
|
||||||
par[3].idx = 3;
|
par[3].idx = 3;
|
||||||
|
|
||||||
taosThreadCreate(&(pThreadList[0]), &thattr, runcase, (void *)&par[0]);
|
pthread_create(&(pThreadList[0]), &thattr, runcase, (void *)&par[0]);
|
||||||
//taosThreadCreate(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
|
//pthread_create(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
|
||||||
//taosThreadCreate(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
|
//pthread_create(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
|
||||||
//taosThreadCreate(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
|
//pthread_create(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
taosSsleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue