From c33f31b6d5e9c7ba0cc123e65fa106c82d67eb7f Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Sat, 9 Apr 2022 18:12:15 +0800 Subject: [PATCH 1/6] feature/qnode --- source/libs/command/src/explain.c | 14 ++++++-------- source/libs/qworker/inc/qworkerInt.h | 1 + source/libs/qworker/src/qworker.c | 10 +++++++--- source/libs/qworker/src/qworkerMsg.c | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 605d8f41da..155da8de49 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -52,16 +52,14 @@ void qExplainFreeCtx(SExplainCtx *pCtx) { void *pIter = taosHashIterate(pCtx->groupHash, NULL); while (pIter) { SExplainGroup *group = (SExplainGroup *)pIter; - if (NULL == group->nodeExecInfo) { - continue; + if (group->nodeExecInfo) { + int32_t num = taosArrayGetSize(group->nodeExecInfo); + for (int32_t i = 0; i < num; ++i) { + SExplainRsp *rsp = taosArrayGet(group->nodeExecInfo, i); + taosMemoryFreeClear(rsp->subplanInfo); + } } - int32_t num = taosArrayGetSize(group->nodeExecInfo); - for (int32_t i = 0; i < num; ++i) { - SExplainRsp *rsp = taosArrayGet(group->nodeExecInfo, i); - taosMemoryFreeClear(rsp->subplanInfo); - } - pIter = taosHashIterate(pCtx->groupHash, pIter); } } diff --git a/source/libs/qworker/inc/qworkerInt.h b/source/libs/qworker/inc/qworkerInt.h index cfd4a3ec7b..d62f9f04b8 100644 --- a/source/libs/qworker/inc/qworkerInt.h +++ b/source/libs/qworker/inc/qworkerInt.h @@ -79,6 +79,7 @@ typedef struct SQWConnInfo { typedef struct SQWMsg { void *node; + int32_t code; char *msg; int32_t msgLen; SQWConnInfo connInfo; diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index f0f04a8a9b..67871dfe62 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -536,6 +536,8 @@ int32_t qwDropTask(QW_FPARAMS_DEF) { QW_ERR_RET(qwDropTaskStatus(QW_FPARAMS())); QW_ERR_RET(qwDropTaskCtx(QW_FPARAMS())); + QW_TASK_DLOG_E("task is dropped"); + return TSDB_CODE_SUCCESS; } @@ -1239,8 +1241,10 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) { QW_ERR_JRET(qwKillTaskHandle(QW_FPARAMS(), ctx)); qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROPPING); } else if (ctx->phase > 0) { - qwBuildAndSendDropRsp(&qwMsg->connInfo, code); - QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + if (0 == qwMsg->code) { + qwBuildAndSendDropRsp(&qwMsg->connInfo, code); + QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + } QW_ERR_JRET(qwDropTask(QW_FPARAMS())); rsped = true; @@ -1273,7 +1277,7 @@ _return: qwReleaseTaskCtx(mgmt, ctx); } - if (TSDB_CODE_SUCCESS != code) { + if ((TSDB_CODE_SUCCESS != code) && (0 == qwMsg->code)) { qwBuildAndSendDropRsp(&qwMsg->connInfo, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); } diff --git a/source/libs/qworker/src/qworkerMsg.c b/source/libs/qworker/src/qworkerMsg.c index bf8f97aa4c..15a42d3a31 100644 --- a/source/libs/qworker/src/qworkerMsg.c +++ b/source/libs/qworker/src/qworkerMsg.c @@ -549,7 +549,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { uint64_t tId = msg->taskId; int64_t rId = msg->refId; - SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0}; + SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .code = pMsg->code}; qwMsg.connInfo.handle = pMsg->handle; qwMsg.connInfo.ahandle = pMsg->ahandle; From f052e64103d49cf9c3344ddaa2e157ceaeda91c2 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Sat, 9 Apr 2022 18:12:53 +0800 Subject: [PATCH 2/6] feature/qnode --- tests/script/general/explain/explain.sim | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/script/general/explain/explain.sim diff --git a/tests/script/general/explain/explain.sim b/tests/script/general/explain/explain.sim new file mode 100644 index 0000000000..666e4040b7 --- /dev/null +++ b/tests/script/general/explain/explain.sim @@ -0,0 +1,102 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c wallevel -v 2 +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 + +print ========= start dnode1 as master +system sh/exec.sh -n dnode1 -s start +sleep 2000 +sql connect + +print ======== step1 +sql create database db1 vgroups 3; +sql use db1; +sql show databases; +sql create stable st1 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); +sql create stable st2 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); +sql create table tb1 using st1 tags(1); +sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); + +sql create table tb2 using st1 tags(2); +sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); +sql create table tb3 using st1 tags(3); +sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); +sql create table tb4 using st1 tags(4); +sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); + +sql create table tb1 using st2 tags(1); +sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); + +sql create table tb2 using st2 tags(2); +sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); +sql create table tb3 using st2 tags(3); +sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); +sql create table tb4 using st2 tags(4); +sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); + + +print ======== step2 +sql explain select * from st1 where -2; +sql explain select ts from tb1; +sql explain select * from st1; +sql explain select * from st1 order by ts; +sql explain select * from information_schema.user_stables; +sql explain select count(*),sum(f1) from tb1; +sql explain select count(*),sum(f1) from st1; +sql explain select count(*),sum(f1) from st1 group by f1; +sql explain select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain select min(f1) from st1 interval(1m, 2a) sliding(3n); + +print ======== step3 +sql explain verbose true select * from st1 where -2; +sql explain verbose true select ts from tb1 where f1 > 0; +sql explain verbose true select * from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; +sql explain verbose true select * from information_schema.user_stables where db_name='db2'; +sql explain verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; + +print ======== step4 +sql explain analyze select ts from st1 where -2; +sql explain analyze select ts from tb1; +sql explain analyze select ts from st1; +sql explain analyze select ts from st1; +sql explain analyze select ts from st1 order by ts; +sql explain analyze select * from information_schema.user_stables; +sql explain analyze select count(*),sum(f1) from tb1; +sql explain analyze select count(*),sum(f1) from st1; +sql explain analyze select count(*),sum(f1) from st1 group by f1; +sql explain analyze select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain analyze select min(f1) from st1 interval(3n, 2a) sliding(1n); + +print ======== step5 +sql explain analyze verbose true select ts from st1 where -2; +sql explain analyze verbose true select ts from tb1; +sql explain analyze verbose true select ts from st1; +sql explain analyze verbose true select ts from st1; +sql explain analyze verbose true select ts from st1 order by ts; +sql explain analyze verbose true select * from information_schema.user_stables; +sql explain analyze verbose true select count(*),sum(f1) from tb1; +sql explain analyze verbose true select count(*),sum(f1) from st1; +sql explain analyze verbose true select count(*),sum(f1) from st1 group by f1; +sql explain analyze verbose true select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain analyze verbose true select ts from tb1 where f1 > 0; +sql explain analyze verbose true select f1 from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; +sql explain analyze verbose true select * from information_schema.user_stables where db_name='db2'; +sql explain analyze verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; +sql explain analyze verbose true select min(f1) from st1 interval(3n, 2a) sliding(1n); +sql explain analyze verbose true select * from (select min(f1),count(*) a from st1 where f1 > 0) where a < 0; + +#not pass case +#sql explain verbose true select count(*),sum(f1) as aa from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by aa; +#sql explain verbose true select * from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; +#sql explain verbose true select count(*),sum(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; +#sql explain verbose true select count(f1) from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(1s, 2d) sliding(3s) order by ts; +#sql explain verbose true select min(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(1m, 2a) sliding(3n) fill(linear) order by ts; +#sql explain select max(f1) from tb1 SESSION(ts, 1s); +#sql explain select max(f1) from st1 SESSION(ts, 1s); +#sql explain select * from tb1, tb2 where tb1.ts=tb2.ts; +#sql explain select * from st1, st2 where tb1.ts=tb2.ts; +#sql explain analyze verbose true select sum(a+b) from (select _rowts, min(f1) b,count(*) a from st1 where f1 > 0 interval(1a)) where a < 0 interval(1s); + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 6f12bc1093f24e49ca0662451845c23fc81fab1f Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 14:15:09 +0800 Subject: [PATCH 3/6] feature/qnode --- include/libs/command/command.h | 2 +- source/client/inc/clientInt.h | 8 +++---- source/client/src/clientEnv.c | 6 ++--- source/client/src/clientHb.c | 16 ++++--------- source/client/src/clientImpl.c | 6 ++--- source/libs/command/inc/commandInt.h | 14 +++++++---- source/libs/command/src/explain.c | 30 +++++++++++++++++++++--- source/libs/parser/src/parAstCreater.c | 9 ++++--- tests/script/general/explain/explain.sim | 2 +- 9 files changed, 60 insertions(+), 33 deletions(-) diff --git a/include/libs/command/command.h b/include/libs/command/command.h index fa229d7265..0cd566ee46 100644 --- a/include/libs/command/command.h +++ b/include/libs/command/command.h @@ -22,7 +22,7 @@ typedef struct SExplainCtx SExplainCtx; int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp); int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp); -int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int32_t startTs); +int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs); int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp); int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp); void qExplainFreeCtx(SExplainCtx *pCtx); diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index ae1b34a3bd..96d7cead68 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -84,10 +84,10 @@ typedef struct { } SClientHbMgr; typedef struct SQueryExecMetric { - int64_t start; // start timestamp - int64_t parsed; // start to parse - int64_t send; // start to send to server - int64_t rsp; // receive response from server + int64_t start; // start timestamp, us + int64_t parsed; // start to parse, us + int64_t send; // start to send to server, us + int64_t rsp; // receive response from server, us } SQueryExecMetric; typedef struct SInstanceSummary { diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 769870ada8..359649884f 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -65,10 +65,10 @@ static void deregisterRequest(SRequestObj *pRequest) { int32_t currentInst = atomic_sub_fetch_64(&pActivity->currentRequests, 1); int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1); - int64_t duration = taosGetTimestampMs() - pRequest->metric.start; + int64_t duration = taosGetTimestampUs() - pRequest->metric.start; tscDebug("0x%" PRIx64 " free Request from connObj: 0x%" PRIx64 ", reqId:0x%" PRIx64 " elapsed:%" PRIu64 " ms, current:%d, app current:%d", - pRequest->self, pTscObj->id, pRequest->requestId, duration, num, currentInst); + pRequest->self, pTscObj->id, pRequest->requestId, duration/1000, num, currentInst); taosReleaseRef(clientConnRefPool, pTscObj->id); } @@ -151,7 +151,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty pRequest->pDb = getDbOfConnection(pObj); pRequest->requestId = generateRequestId(); - pRequest->metric.start = taosGetTimestampMs(); + pRequest->metric.start = taosGetTimestampUs(); pRequest->type = type; pRequest->pTscObj = pObj; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index abb6e7fbd1..d389fc34c6 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -435,11 +435,11 @@ static int32_t hbCreateThread() { taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); -// if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { -// terrno = TAOS_SYSTEM_ERROR(errno); -// return -1; -// } -// taosThreadAttrDestroy(&thAttr); + if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + taosThreadAttrDestroy(&thAttr); return 0; } @@ -500,8 +500,6 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) { } void appHbMgrCleanup(void) { - taosThreadMutexLock(&clientHbMgr.lock); - int sz = taosArrayGetSize(clientHbMgr.appHbMgrs); for (int i = 0; i < sz; i++) { SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i); @@ -510,8 +508,6 @@ void appHbMgrCleanup(void) { taosHashCleanup(pTarget->connInfo); pTarget->connInfo = NULL; } - - taosThreadMutexUnlock(&clientHbMgr.lock); } int hbMgrInit() { @@ -532,7 +528,6 @@ int hbMgrInit() { } void hbMgrCleanUp() { -#if 0 hbStopThread(); // destroy all appHbMgr @@ -545,7 +540,6 @@ void hbMgrCleanUp() { taosThreadMutexUnlock(&clientHbMgr.lock); clientHbMgr.appHbMgrs = NULL; -#endif } int hbRegisterConnImpl(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, SHbConnInfo *info) { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 9938a2e1b9..b311060ea9 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -520,7 +520,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { SRequestObj* pRequest = (SRequestObj*)taosAcquireRef(clientReqRefPool, pSendInfo->requestObjRefId); assert(pRequest->self == pSendInfo->requestObjRefId); - pRequest->metric.rsp = taosGetTimestampMs(); + pRequest->metric.rsp = taosGetTimestampUs(); STscObj* pTscObj = pRequest->pTscObj; if (pEpSet) { @@ -536,10 +536,10 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId); } else { tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId); } taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index 23e4f2b24f..452804ac91 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -44,6 +44,9 @@ extern "C" { #define EXPLAIN_OUTPUT_FORMAT "Output: " #define EXPLAIN_TIME_WINDOWS_FORMAT "Time Window: interval=%" PRId64 "%c offset=%" PRId64 "%c sliding=%" PRId64 "%c" #define EXPLAIN_WINDOW_FORMAT "Window: gap=%" PRId64 +#define EXPLAIN_RATIO_TIME_FORMAT "Ratio: %f" +#define EXPLAIN_PLANNING_TIME_FORMAT "Planning Time: %.3f ms" +#define EXPLAIN_EXEC_TIME_FORMAT "Execution Time: %.3f ms" //append area #define EXPLAIN_LEFT_PARENTHESIS_FORMAT " (" @@ -108,16 +111,19 @@ typedef struct SExplainCtx { #define EXPLAIN_ROW_NEW(level, ...) \ do { \ if (isVerboseLine) { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s", (level) * 2 + 3, ""); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s", (level) * 2 + 3, ""); \ } else { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s%s", (level) * 2, "", "-> "); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s%s", (level) * 2, "", "-> "); \ } \ - tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__); \ + tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__); \ } while (0) -#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__) +#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__) #define EXPLAIN_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; isVerboseLine = true; } while (0) +#define EXPLAIN_SUM_ROW_NEW(...) tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, __VA_ARGS__) +#define EXPLAIN_SUM_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; } while (0) + #ifdef __cplusplus } #endif diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 155da8de49..7a6264709f 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -894,9 +894,33 @@ _return: QRY_RET(code); } +int32_t qExplainAppendPlanRows(SExplainCtx *pCtx) { + if (EXPLAIN_MODE_ANALYZE != pCtx->mode) { + return TSDB_CODE_SUCCESS; + } + + int32_t tlen = 0; + char *tbuf = pCtx->tbuf; + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_RATIO_TIME_FORMAT, pCtx->ratio); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_PLANNING_TIME_FORMAT, (double)(pCtx->jobStartTs - pCtx->reqStartTs) / 1000.0); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_EXEC_TIME_FORMAT, (double)(pCtx->jobDoneTs - pCtx->jobStartTs) / 1000.0); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + return TSDB_CODE_SUCCESS; +} int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { QRY_ERR_RET(qExplainAppendGroupResRows(pCtx, pCtx->rootGroupId, 0)); + + QRY_ERR_RET(qExplainAppendPlanRows(pCtx)); QRY_ERR_RET(qExplainGetRspFromCtx(pCtx, pRsp)); @@ -977,18 +1001,18 @@ _return: QRY_RET(code); } -int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int32_t startTs) { +int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) { QRY_ERR_RET(qExplainPrepareCtx(pDag, pCtx)); (*pCtx)->reqStartTs = startTs; - (*pCtx)->jobStartTs = taosGetTimestampMs(); + (*pCtx)->jobStartTs = taosGetTimestampUs(); return TSDB_CODE_SUCCESS; } int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { int32_t code = 0; - pCtx->jobDoneTs = taosGetTimestampMs(); + pCtx->jobDoneTs = taosGetTimestampUs(); atomic_store_8((int8_t *)&pCtx->execDone, true); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4908748f0d..cf05d87d4d 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -207,7 +207,9 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { CHECK_RAW_EXPR_NODE(pNode); SRawExprNode* pRawExpr = (SRawExprNode*)pNode; SNode* pExpr = pRawExpr->pNode; - strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, pRawExpr->n); + if (nodesIsExprNode(pExpr)) { + strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, pRawExpr->n); + } taosMemoryFreeClear(pNode); return pExpr; } @@ -498,8 +500,9 @@ SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* p if (NULL == pNode || !pCxt->valid) { return pNode; } - uint32_t maxLen = sizeof(((SExprNode*)pNode)->aliasName); - strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, pAlias->n > maxLen ? maxLen : pAlias->n); + int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n); + strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, len); + ((SExprNode*)pNode)->aliasName[len] = '\0'; return pNode; } diff --git a/tests/script/general/explain/explain.sim b/tests/script/general/explain/explain.sim index 666e4040b7..3358b24e83 100644 --- a/tests/script/general/explain/explain.sim +++ b/tests/script/general/explain/explain.sim @@ -99,4 +99,4 @@ sql explain analyze verbose true select * from (select min(f1),count(*) a from s #sql explain analyze verbose true select sum(a+b) from (select _rowts, min(f1) b,count(*) a from st1 where f1 > 0 interval(1a)) where a < 0 interval(1s); -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 86a39034d3209ee4dbb7638f4135d9547572e0d6 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:13:53 +0800 Subject: [PATCH 4/6] add explain case --- tests/script/{general/explain => tsim/query}/explain.sim | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/script/{general/explain => tsim/query}/explain.sim (100%) diff --git a/tests/script/general/explain/explain.sim b/tests/script/tsim/query/explain.sim similarity index 100% rename from tests/script/general/explain/explain.sim rename to tests/script/tsim/query/explain.sim From e158dbeed99f6c0685d71092b943488c17f095c8 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:21:55 +0800 Subject: [PATCH 5/6] add case to CI --- tests/script/jenkins/basic.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2d18167337..d3ae58a524 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -32,6 +32,7 @@ ./test.sh -f tsim/query/interval-offset.sim ./test.sh -f tsim/query/scalarFunction.sim ./test.sh -f tsim/query/charScalarFunction.sim +./test.sh -f tsim/query/explain.sim # ---- qnode ./test.sh -f tsim/qnode/basic1.sim From e4d53ef3c77245311a65b54d5de0a70b9830c28c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:57:34 +0800 Subject: [PATCH 6/6] fix hb bug --- source/common/src/tmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 5973a70b59..0edfcb3314 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1960,7 +1960,7 @@ int32_t tDeserializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pR int32_t numOfBatch = taosArrayGetSize(pRsp->pArray); if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1; - pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbBatchRsp)); + pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbRsp)); if (pRsp->pArray == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1;