From 632fb40a43a78e3cdb226eecc2af7ff3d15c1061 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Wed, 21 Jun 2023 09:31:44 +0800 Subject: [PATCH] postfix: propagate ts order to parents for more logic nodes --- source/libs/planner/src/planOptimizer.c | 22 +++++++++---------- .../tsim/query/r/explain_tsorder.result | 8 +++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 2371731467..2d1a758f33 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -167,25 +167,25 @@ static bool scanPathOptMayBeOptimized(SLogicNode* pNode) { if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode)) { return false; } - if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && - QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent) && - QUERY_NODE_LOGIC_PLAN_PARTITION != nodeType(pNode->pParent))) { - return false; - } - if ((QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent) && - WINDOW_TYPE_INTERVAL == ((SWindowLogicNode*)pNode->pParent)->winType) || - (QUERY_NODE_LOGIC_PLAN_PARTITION == nodeType(pNode->pParent) && pNode->pParent->pParent && - QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent->pParent) && + return true; +} + +static bool scanPathOptShouldGetFuncs(SLogicNode* pNode) { + if ((QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode) && + WINDOW_TYPE_INTERVAL == ((SWindowLogicNode*)pNode)->winType) || + (QUERY_NODE_LOGIC_PLAN_PARTITION == nodeType(pNode) && pNode->pParent && + QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent) && WINDOW_TYPE_INTERVAL == ((SWindowLogicNode*)pNode->pParent)->winType)) { return true; } - if (QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode->pParent)) { - return !scanPathOptHaveNormalCol(((SAggLogicNode*)pNode->pParent)->pGroupKeys); + if (QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode)) { + return !scanPathOptHaveNormalCol(((SAggLogicNode*)pNode)->pGroupKeys); } return false; } static SNodeList* scanPathOptGetAllFuncs(SLogicNode* pNode) { + if (!scanPathOptShouldGetFuncs(pNode)) return NULL; switch (nodeType(pNode)) { case QUERY_NODE_LOGIC_PLAN_WINDOW: return ((SWindowLogicNode*)pNode)->pFuncs; diff --git a/tests/script/tsim/query/r/explain_tsorder.result b/tests/script/tsim/query/r/explain_tsorder.result index a31a05e66f..6c63a343de 100644 --- a/tests/script/tsim/query/r/explain_tsorder.result +++ b/tests/script/tsim/query/r/explain_tsorder.result @@ -2000,7 +2000,7 @@ QUERY_PLAN: -> Data Exchange 1:1 (width=12) *************************** 6.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 7.row *************************** -QUERY_PLAN: -> Sort input_order=unknown output_order=unknown (columns=2 width=12) +QUERY_PLAN: -> Sort input_order=asc output_order=unknown (columns=2 width=12) *************************** 8.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 9.row *************************** @@ -2014,7 +2014,7 @@ QUERY_PLAN: -> Data Exchange 1:1 (width=12) *************************** 13.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 14.row *************************** -QUERY_PLAN: -> Sort input_order=unknown output_order=unknown (columns=2 width=12) +QUERY_PLAN: -> Sort input_order=asc output_order=unknown (columns=2 width=12) *************************** 15.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 16.row *************************** @@ -2074,7 +2074,7 @@ QUERY_PLAN: -> Data Exchange 1:1 (width=12) *************************** 12.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 13.row *************************** -QUERY_PLAN: -> Sort input_order=unknown output_order=unknown (columns=2 width=12) +QUERY_PLAN: -> Sort input_order=asc output_order=unknown (columns=2 width=12) *************************** 14.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 15.row *************************** @@ -2088,7 +2088,7 @@ QUERY_PLAN: -> Data Exchange 1:1 (width=12) *************************** 19.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 20.row *************************** -QUERY_PLAN: -> Sort input_order=unknown output_order=unknown (columns=2 width=12) +QUERY_PLAN: -> Sort input_order=asc output_order=unknown (columns=2 width=12) *************************** 21.row *************************** QUERY_PLAN: Output: columns=2 width=12 *************************** 22.row *************************** -- GitLab