From 571e936b4accf44f8ef34dd01c2b52742102aeac Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 7 Feb 2023 17:13:38 +0800 Subject: [PATCH] feat: add explain test case --- source/libs/scheduler/src/schJob.c | 6 ++++-- source/libs/scheduler/src/schRemote.c | 8 ++++++++ tests/script/tsim/query/explain.sim | 23 +++++++++++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 1bfbab0591..fb8a7a42ba 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -537,7 +537,9 @@ int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRs SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_SUCC); - schProcessOnDataFetched(pJob); + if (!SCH_IS_INSERT_JOB(pJob)) { + schProcessOnDataFetched(pJob); + } return TSDB_CODE_SUCCESS; } @@ -682,7 +684,7 @@ void schFreeJobImpl(void *job) { int32_t schJobFetchRows(SSchJob *pJob) { int32_t code = 0; - if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) { + if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC) && !(SCH_IS_EXPLAIN_JOB(pJob) && SCH_IS_INSERT_JOB(pJob))) { SCH_ERR_RET(schLaunchFetchTask(pJob)); if (schChkCurrentOp(pJob, SCH_OP_FETCH, true)) { diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 5ceb8228b0..ad675cf383 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -341,6 +341,14 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } + if (taosArrayGetSize(pTask->parents) == 0 && SCH_IS_EXPLAIN_JOB(pJob) && SCH_IS_INSERT_JOB(pJob)) { + SRetrieveTableRsp *pRsp = NULL; + SCH_ERR_JRET(qExecExplainEnd(pJob->explainCtx, &pRsp)); + if (pRsp) { + SCH_ERR_JRET(schProcessOnExplainDone(pJob, pTask, pRsp)); + } + } + SQueryTableRsp rsp = {0}; if (tDeserializeSQueryTableRsp(msg, msgSize, &rsp) < 0) { SCH_TASK_ELOG("tDeserializeSQueryTableRsp failed, msgSize:%d", msgSize); diff --git a/tests/script/tsim/query/explain.sim b/tests/script/tsim/query/explain.sim index 78d905233b..eb6b102bd9 100644 --- a/tests/script/tsim/query/explain.sim +++ b/tests/script/tsim/query/explain.sim @@ -29,43 +29,62 @@ sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..2 #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)"); +# for explain insert into select +sql create table t1 (ts timestamp, f1 int, f2 binary(200), t1 int); print ======== step2 sql explain select * from st1 where -2; +sql explain insert into t1 select * from st1 where -2; sql explain select ts from tb1; +sql explain insert into t1(ts) select ts from tb1; sql explain select * from st1; +sql explain insert into t1 select * from st1; sql explain select * from st1 order by ts; +sql explain insert into t1 select * from st1 order by ts; sql explain select * from information_schema.ins_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(10s, 2s) sliding(3s) fill(prev); +sql explain insert into t1(ts, t1) select _wstart, count(*) from st1 interval(10s); print ======== step3 sql explain verbose true select * from st1 where -2; +sql explain verbose true insert into t1 select * from st1 where -2; sql explain verbose true select ts from tb1 where f1 > 0; +sql explain verbose true insert into t1(ts) 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 insert into t1 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 count(*) from st1 partition by tbname slimit 1 soffset 2 limit 2 offset 1; sql explain verbose true select * from information_schema.ins_stables where db_name='db2'; sql explain verbose true select st1.f1 from st1 join st2 on st1.ts=st2.ts and st1.f1 > 0; +sql explain verbose true insert into t1(ts) select st1.f1 from st1 join st2 on st1.ts=st2.ts and st1.f1 > 0; +sql explain verbose true insert into t1(ts, t1) select _wstart, count(*) from st1 interval(10s); print ======== step4 sql explain analyze select ts from st1 where -2; +sql explain analyze insert into t1(ts) select ts from st1 where -2; sql explain analyze select ts from tb1; +sql explain analyze insert into t1(ts) select ts from tb1; sql explain analyze select ts from st1; -sql explain analyze select ts from st1; +sql explain analyze insert into t1(ts) select ts from st1; sql explain analyze select ts from st1 order by ts; +sql explain analyze insert into t1(ts) select ts from st1 order by ts; sql explain analyze select * from information_schema.ins_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 insert into t1(ts, t1) select _wstart, count(*) from st1 interval(10s); print ======== step5 sql explain analyze verbose true select ts from st1 where -2; +sql explain analyze verbose true insert into t1(ts) select ts from st1 where -2; sql explain analyze verbose true select ts from tb1; +sql explain analyze verbose true insert into t1(ts) 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 insert into t1(ts) select ts from st1; sql explain analyze verbose true select ts from st1 order by ts; +sql explain analyze verbose true insert into t1(ts) select ts from st1 order by ts; sql explain analyze verbose true select * from information_schema.ins_stables; sql explain analyze verbose true select count(*),sum(f1) from tb1; sql explain analyze verbose true select count(*),sum(f1) from st1;