From 8b6a50d9708c3922683ffcd38339466a4217ff90 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 7 Feb 2023 18:35:42 +0800 Subject: [PATCH] feat: add explain test case --- include/libs/nodes/plannodes.h | 1 + source/libs/executor/src/dataInserter.c | 36 ++++++++++++---------- source/libs/nodes/src/nodesCodeFuncs.c | 9 +++++- source/libs/nodes/src/nodesMsgFuncs.c | 9 +++++- source/libs/planner/src/planPhysiCreater.c | 1 + 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 3602225789..89ad7fc9ba 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -562,6 +562,7 @@ typedef struct SQueryInserterNode { char tableName[TSDB_TABLE_NAME_LEN]; int32_t vgId; SEpSet epSet; + bool explain; } SQueryInserterNode; typedef struct SDataDeleterNode { diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c index f78e3c22e1..a823baa2ae 100644 --- a/source/libs/executor/src/dataInserter.c +++ b/source/libs/executor/src/dataInserter.c @@ -46,6 +46,7 @@ typedef struct SDataInserterHandle { uint64_t cachedSize; TdThreadMutex mutex; tsem_t ready; + bool explain; } SDataInserterHandle; typedef struct SSubmitRspParam { @@ -333,26 +334,28 @@ int32_t dataBlocksToSubmitReq(SDataInserterHandle* pInserter, void** pMsg, int32 static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) { SDataInserterHandle* pInserter = (SDataInserterHandle*)pHandle; - taosArrayPush(pInserter->pDataBlocks, &pInput->pData); - void* pMsg = NULL; - int32_t msgLen = 0; - int32_t code = dataBlocksToSubmitReq(pInserter, &pMsg, &msgLen); - if (code) { - return code; - } + if (!pInserter->explain) { + taosArrayPush(pInserter->pDataBlocks, &pInput->pData); + void* pMsg = NULL; + int32_t msgLen = 0; + int32_t code = dataBlocksToSubmitReq(pInserter, &pMsg, &msgLen); + if (code) { + return code; + } - taosArrayClear(pInserter->pDataBlocks); + taosArrayClear(pInserter->pDataBlocks); - code = sendSubmitRequest(pInserter, pMsg, msgLen, pInserter->pParam->readHandle->pMsgCb->clientRpc, - &pInserter->pNode->epSet); - if (code) { - return code; - } + code = sendSubmitRequest(pInserter, pMsg, msgLen, pInserter->pParam->readHandle->pMsgCb->clientRpc, + &pInserter->pNode->epSet); + if (code) { + return code; + } - tsem_wait(&pInserter->ready); + tsem_wait(&pInserter->ready); - if (pInserter->submitRes.code) { - return pInserter->submitRes.code; + if (pInserter->submitRes.code) { + return pInserter->submitRes.code; + } } *pContinue = true; @@ -412,6 +415,7 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat inserter->pParam = pParam; inserter->status = DS_BUF_EMPTY; inserter->queryEnd = false; + inserter->explain = pInserterNode->explain; int64_t suid = 0; int32_t code = diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index d9b3237993..348cd702c3 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -176,7 +176,7 @@ const char* nodesNodeName(ENodeType type) { case QUERY_NODE_SHOW_DB_ALIVE_STMT: return "ShowDbAliveStmt"; case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT: - return "ShowClusterAliveStmt"; + return "ShowClusterAliveStmt"; case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT: return "RedistributeVgroupStmt"; case QUERY_NODE_SPLIT_VGROUP_STMT: @@ -2595,6 +2595,7 @@ static const char* jkQueryInsertPhysiPlanTableType = "TableType"; static const char* jkQueryInsertPhysiPlanTableFName = "TableFName"; static const char* jkQueryInsertPhysiPlanVgId = "VgId"; static const char* jkQueryInsertPhysiPlanEpSet = "EpSet"; +static const char* jkQueryInsertPhysiPlanExplain = "Explain"; static int32_t physiQueryInsertNodeToJson(const void* pObj, SJson* pJson) { const SQueryInserterNode* pNode = (const SQueryInserterNode*)pObj; @@ -2621,6 +2622,9 @@ static int32_t physiQueryInsertNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkQueryInsertPhysiPlanEpSet, epSetToJson, &pNode->epSet); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddBoolToObject(pJson, jkQueryInsertPhysiPlanExplain, pNode->explain); + } return code; } @@ -2650,6 +2654,9 @@ static int32_t jsonToPhysiQueryInsertNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonToObject(pJson, jkQueryInsertPhysiPlanEpSet, jsonToEpSet, &pNode->epSet); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBoolValue(pJson, jkQueryInsertPhysiPlanExplain, &pNode->explain); + } return code; } diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index a4b77fad69..d671dea1ed 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -3244,7 +3244,8 @@ enum { PHY_QUERY_INSERT_CODE_TABLE_TYPE, PHY_QUERY_INSERT_CODE_TABLE_NAME, PHY_QUERY_INSERT_CODE_VG_ID, - PHY_QUERY_INSERT_CODE_EP_SET + PHY_QUERY_INSERT_CODE_EP_SET, + PHY_QUERY_INSERT_CODE_EXPLAIN }; static int32_t physiQueryInsertNodeToMsg(const void* pObj, STlvEncoder* pEncoder) { @@ -3272,6 +3273,9 @@ static int32_t physiQueryInsertNodeToMsg(const void* pObj, STlvEncoder* pEncoder if (TSDB_CODE_SUCCESS == code) { code = tlvEncodeObj(pEncoder, PHY_QUERY_INSERT_CODE_EP_SET, epSetToMsg, &pNode->epSet); } + if (TSDB_CODE_SUCCESS == code) { + code = tlvEncodeBool(pEncoder, PHY_QUERY_INSERT_CODE_EXPLAIN, pNode->explain); + } return code; } @@ -3307,6 +3311,9 @@ static int32_t msgToPhysiQueryInsertNode(STlvDecoder* pDecoder, void* pObj) { case PHY_QUERY_INSERT_CODE_EP_SET: code = tlvDecodeObjFromTlv(pTlv, msgToEpSet, &pNode->epSet); break; + case PHY_QUERY_INSERT_CODE_EXPLAIN: + code = tlvDecodeBool(pTlv, &pNode->explain); + break; default: break; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index f83704be87..d111ad7da8 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1718,6 +1718,7 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod strcpy(pInserter->tableName, pModify->tableName); pInserter->vgId = pModify->pVgroupList->vgroups[0].vgId; pInserter->epSet = pModify->pVgroupList->vgroups[0].epSet; + pInserter->explain = (QUERY_NODE_EXPLAIN_STMT == nodeType(pCxt->pPlanCxt->pAstRoot) ? true : false); vgroupInfoToNodeAddr(pModify->pVgroupList->vgroups, &pSubplan->execNode); int32_t code = setListSlotId(pCxt, pSubplan->pNode->pOutputDataBlockDesc->dataBlockId, -1, pModify->pInsertCols, -- GitLab