diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index 6acf19218d893a9962853e1fe7b0c73c8dddf7bc..764553f1e9dc53495c1fbfdf432c9d6fc89a3a8a 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -64,6 +64,9 @@ extern "C" { #define EXPLAIN_IGNORE_GROUPID_FORMAT "Ignore Group Id: %s" #define EXPLAIN_PARTITION_KETS_FORMAT "Partition Key: " #define EXPLAIN_INTERP_FORMAT "Interp" +#define EXPLAIN_EVENT_FORMAT "Event" +#define EXPLAIN_EVENT_START_FORMAT "Start Cond: " +#define EXPLAIN_EVENT_END_FORMAT "End Cond: " #define EXPLAIN_PLANNING_TIME_FORMAT "Planning Time: %.3f ms" #define EXPLAIN_EXEC_TIME_FORMAT "Execution Time: %.3f ms" diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 253718048dcebb71b64ca4d4b48b3004c6d9ea3a..4624e471bf5c3066fc861c3f2f6558466b4afb88 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -114,129 +114,7 @@ _return: int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNodeList **pChildren) { int32_t tlen = 0; - SNodeList *pPhysiChildren = NULL; - - switch (pNode->type) { - case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: { - STagScanPhysiNode *pTagScanNode = (STagScanPhysiNode *)pNode; - pPhysiChildren = pTagScanNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: - case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: { - STableScanPhysiNode *pTblScanNode = (STableScanPhysiNode *)pNode; - pPhysiChildren = pTblScanNode->scan.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: { - SSystemTableScanPhysiNode *pSTblScanNode = (SSystemTableScanPhysiNode *)pNode; - pPhysiChildren = pSTblScanNode->scan.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_PROJECT: { - SProjectPhysiNode *pPrjNode = (SProjectPhysiNode *)pNode; - pPhysiChildren = pPrjNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: { - SSortMergeJoinPhysiNode *pJoinNode = (SSortMergeJoinPhysiNode *)pNode; - pPhysiChildren = pJoinNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: { - SAggPhysiNode *pAggNode = (SAggPhysiNode *)pNode; - pPhysiChildren = pAggNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: { - SExchangePhysiNode *pExchNode = (SExchangePhysiNode *)pNode; - pPhysiChildren = pExchNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_SORT: { - SSortPhysiNode *pSortNode = (SSortPhysiNode *)pNode; - pPhysiChildren = pSortNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: { - SIntervalPhysiNode *pIntNode = (SIntervalPhysiNode *)pNode; - pPhysiChildren = pIntNode->window.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: { - SSessionWinodwPhysiNode *pSessNode = (SSessionWinodwPhysiNode *)pNode; - pPhysiChildren = pSessNode->window.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: { - SStateWinodwPhysiNode *pStateNode = (SStateWinodwPhysiNode *)pNode; - pPhysiChildren = pStateNode->window.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_PARTITION: { - SPartitionPhysiNode *partitionPhysiNode = (SPartitionPhysiNode *)pNode; - pPhysiChildren = partitionPhysiNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_MERGE: { - SMergePhysiNode *mergePhysiNode = (SMergePhysiNode *)pNode; - pPhysiChildren = mergePhysiNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: { - SIndefRowsFuncPhysiNode *indefPhysiNode = (SIndefRowsFuncPhysiNode *)pNode; - pPhysiChildren = indefPhysiNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL: { - SMergeAlignedIntervalPhysiNode *intPhysiNode = (SMergeAlignedIntervalPhysiNode *)pNode; - pPhysiChildren = intPhysiNode->window.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_FILL: { - SFillPhysiNode *fillPhysiNode = (SFillPhysiNode *)pNode; - pPhysiChildren = fillPhysiNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN: { - STableMergeScanPhysiNode *mergePhysiNode = (STableMergeScanPhysiNode *)pNode; - pPhysiChildren = mergePhysiNode->scan.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: { - SBlockDistScanPhysiNode *distPhysiNode = (SBlockDistScanPhysiNode *)pNode; - pPhysiChildren = distPhysiNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: { - SLastRowScanPhysiNode *lastRowPhysiNode = (SLastRowScanPhysiNode *)pNode; - pPhysiChildren = lastRowPhysiNode->scan.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN: { - STableCountScanPhysiNode *tableCountPhysiNode = (STableCountScanPhysiNode *)pNode; - pPhysiChildren = tableCountPhysiNode->scan.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT: { - SGroupSortPhysiNode *groupSortPhysiNode = (SGroupSortPhysiNode *)pNode; - pPhysiChildren = groupSortPhysiNode->node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: { - SMergeIntervalPhysiNode *mergeIntPhysiNode = (SMergeIntervalPhysiNode *)pNode; - pPhysiChildren = mergeIntPhysiNode->window.node.pChildren; - break; - } - case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: { - SInterpFuncPhysiNode *interpPhysiNode = (SInterpFuncPhysiNode *)pNode; - pPhysiChildren = interpPhysiNode->node.pChildren; - break; - } - default: - qError("not supported physical node type %d", pNode->type); - QRY_ERR_RET(TSDB_CODE_APP_ERROR); - } + SNodeList *pPhysiChildren = pNode->pChildren; if (pPhysiChildren) { *pChildren = nodesMakeList(); @@ -1583,6 +1461,36 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } break; } + case QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT: { + SEventWinodwPhysiNode *pEventNode = (SEventWinodwPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_EVENT_FORMAT); + EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + } + EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pEventNode->window.pFuncs->length); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pEventNode->window.node.pOutputDataBlockDesc->totalRowSize); + EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_EVENT_START_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pEventNode->pStartCond, tbuf + VARSTR_HEADER_SIZE, + TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_EVENT_END_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pEventNode->pEndCond, tbuf + VARSTR_HEADER_SIZE, + TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + break; + } default: qError("not supported physical node type %d", pNode->type); return TSDB_CODE_APP_ERROR; diff --git a/tests/script/tsim/query/event.sim b/tests/script/tsim/query/event.sim new file mode 100644 index 0000000000000000000000000000000000000000..c72b7ba12582fd757640138fa06a15b8299d9601 --- /dev/null +++ b/tests/script/tsim/query/event.sim @@ -0,0 +1,69 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ======== prepare data + +sql drop database if exists db1; +sql create database db1 vgroups 5; +sql use db1; +sql create stable sta (ts timestamp, f1 int, f2 binary(10), f3 bool) tags(t1 int, t2 bool, t3 binary(10)); +sql create table tba1 using sta tags(0, false, '0'); +sql create table tba2 using sta tags(1, true, '1'); +sql create table tba3 using sta tags(null, null, ''); +sql create table tba4 using sta tags(1, false, null); +sql create table tba5 using sta tags(3, true, 'aa'); +sql insert into tba1 values ('2022-09-26 15:15:01', 0, "a", false); +sql insert into tba1 values ('2022-09-26 15:15:02', 1, "0", true); +sql insert into tba1 values ('2022-09-26 15:15:03', 5, "5", false); +sql insert into tba1 values ('2022-09-26 15:15:04', 3, 'b', false); +sql insert into tba1 values ('2022-09-26 15:15:05', 0, '1', false); +sql insert into tba1 values ('2022-09-26 15:15:06', 2, 'd', true); + +sql insert into tba2 values ('2022-09-27 15:15:01', 0, "a", false); +sql insert into tba2 values ('2022-09-27 15:15:02', 1, "0", true); +sql insert into tba2 values ('2022-09-27 15:15:03', 5, "5", false); +sql insert into tba2 values ('2022-09-27 15:15:04', null, null, null); + +# child table: no window +print ====> select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'c'; +sql select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'c'; +if $rows != 0 then + return -1 +endi + +# child table: single row window +print ====> select count(*) from tba1 event_window start with f1 = 0 end with f3 = false; +sql select count(*) from tba1 event_window start with f1 = 0 end with f3 = false +if $rows != 1 then + return -1 +endi +if $data00 != 1 then + return -1 +endi + +# child table: multi rows window +print ====> select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'b'; +sql select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'b'; +if $rows != 1 then + return -1 +endi +if $data00 != 4 then + return -1 +endi + +# child table: multi windows +print ====> select count(*) from tba1 event_window start with f1 >= 0 end with f3 = true; +sql select count(*) from tba1 event_window start with f1 >= 0 end with f3 = true; +if $rows != 2 then + return -1 +endi +if $data00 != 2 then + return -1 +endi +if $data00 != 4 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT