提交 5b820755 编写于 作者: S slzhou

fix: taken onCondtion of join node into account when eliminate projects

上级 5ad27aab
...@@ -1693,22 +1693,30 @@ static EDealRes eliminateProjOptCanUseNewChildTargetsImpl(SNode* pNode, void* pC ...@@ -1693,22 +1693,30 @@ static EDealRes eliminateProjOptCanUseNewChildTargetsImpl(SNode* pNode, void* pC
CheckNewChildTargetsCxt* pCxt = pContext; CheckNewChildTargetsCxt* pCxt = pContext;
SNode* pTarget = NULL; SNode* pTarget = NULL;
FOREACH(pTarget, pCxt->pNewChildTargets) { FOREACH(pTarget, pCxt->pNewChildTargets) {
if (!nodesEqualNode(pTarget, pNode)) { if (nodesEqualNode(pTarget, pNode)) {
pCxt->canUse = false; pCxt->canUse = true;
return DEAL_RES_END; return DEAL_RES_CONTINUE;
} }
} }
pCxt->canUse = false;
return DEAL_RES_END;
} }
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
static bool eliminateProjOptCanUseNewChildTargets(SLogicNode* pChild, SNodeList* pNewChildTargets) { static bool eliminateProjOptCanChildConditionUseChildTargets(SLogicNode* pChild, SNodeList* pNewChildTargets) {
if (NULL == pChild->pConditions) { if (NULL != pChild->pConditions) {
return true; CheckNewChildTargetsCxt cxt = {.pNewChildTargets = pNewChildTargets, .canUse = false};
nodesWalkExpr(pChild->pConditions, eliminateProjOptCanUseNewChildTargetsImpl, &cxt);
if (!cxt.canUse) return false;
} }
CheckNewChildTargetsCxt cxt = {.pNewChildTargets = pNewChildTargets, .canUse = true}; if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pChild) && NULL != ((SJoinLogicNode*)pChild)->pOnConditions) {
nodesWalkExpr(pChild->pConditions, eliminateProjOptCanUseNewChildTargetsImpl, &cxt); SJoinLogicNode* pJoinLogicNode = (SJoinLogicNode*)pChild;
return cxt.canUse; CheckNewChildTargetsCxt cxt = {.pNewChildTargets = pNewChildTargets, .canUse = false};
nodesWalkExpr(pJoinLogicNode->pOnConditions, eliminateProjOptCanUseNewChildTargetsImpl, &cxt);
if (!cxt.canUse) return false;
}
return true;
} }
static void alignProjectionWithTarget(SLogicNode* pNode) { static void alignProjectionWithTarget(SLogicNode* pNode) {
...@@ -1748,7 +1756,7 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* ...@@ -1748,7 +1756,7 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan*
} }
} }
} }
if (eliminateProjOptCanUseNewChildTargets(pChild, pNewChildTargets)) { if (eliminateProjOptCanChildConditionUseChildTargets(pChild, pNewChildTargets)) {
nodesDestroyList(pChild->pTargets); nodesDestroyList(pChild->pTargets);
pChild->pTargets = pNewChildTargets; pChild->pTargets = pNewChildTargets;
} else { } else {
...@@ -1760,6 +1768,7 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* ...@@ -1760,6 +1768,7 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan*
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
NODES_CLEAR_LIST(pProjectNode->node.pChildren); NODES_CLEAR_LIST(pProjectNode->node.pChildren);
nodesDestroyNode((SNode*)pProjectNode); nodesDestroyNode((SNode*)pProjectNode);
//if pChild is a project logic node, remove its projection which is not reference by its target.
alignProjectionWithTarget(pChild); alignProjectionWithTarget(pChild);
} }
pCxt->optimized = true; pCxt->optimized = true;
......
...@@ -682,7 +682,7 @@ if $data08 != 3 then ...@@ -682,7 +682,7 @@ if $data08 != 3 then
return -1 return -1
endi endi
sql select st0.f1,st1.f1 from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1; sql select st0.f1,st1.f1 from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 order by st0.f1;
if $rows != 25 then if $rows != 25 then
return -1 return -1
endi endi
...@@ -721,22 +721,10 @@ endi ...@@ -721,22 +721,10 @@ endi
if $data01 != @21-03-01 01:00:00.000@ then if $data01 != @21-03-01 01:00:00.000@ then
return -1 return -1
endi endi
if $data10 != @21-03-02 01:00:00.000@ then if $data50 != @21-03-02 01:00:00.000@ then
return -1 return -1
endi endi
if $data11 != @21-03-02 01:00:00.000@ then if $data51 != @21-03-02 01:00:00.000@ then
return -1
endi
if $data20 != @21-03-03 01:00:00.000@ then
return -1
endi
if $data21 != @21-03-03 01:00:00.000@ then
return -1
endi
if $data30 != @21-03-04 01:00:00.000@ then
return -1
endi
if $data31 != @21-03-04 01:00:00.000@ then
return -1 return -1
endi endi
...@@ -782,23 +770,23 @@ endi ...@@ -782,23 +770,23 @@ endi
if $data04 != 01 then if $data04 != 01 then
return -1 return -1
endi endi
if $data10 != @21-03-02 01:00:00.000@ then if $data50 != @21-03-02 01:00:00.000@ then
return -1 return -1
endi endi
if $data11 != 9901.000000000 then if $data51 != 9901.000000000 then
return -1 return -1
endi endi
if $data12 != 11 then if $data52 != 11 then
return -1 return -1
endi endi
if $data13 != 9911.000000000 then if $data53 != 9911.000000000 then
return -1 return -1
endi endi
if $data14 != 01 then if $data54 != 01 then
return -1 return -1
endi endi
sql select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 interval(10a); sql select _wstart, last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 interval(10a);
if $rows != 25 then if $rows != 25 then
return -1 return -1
endi endi
...@@ -830,7 +818,7 @@ if $data08 != 11 then ...@@ -830,7 +818,7 @@ if $data08 != 11 then
return -1 return -1
endi endi
sql select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 interval(1d) sliding(1d); sql select _wstart, last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 interval(1d) sliding(1d);
if $rows != 5 then if $rows != 5 then
return -1 return -1
endi endi
...@@ -937,7 +925,7 @@ sql select st0.*,st1.* from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and ...@@ -937,7 +925,7 @@ sql select st0.*,st1.* from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and
if $rows != 5 then if $rows != 5 then
return -1 return -1
endi endi
if $data00 != @21-03-01 01:00:00.000@ then if $data00 != @21-03-02 01:00:00.000@ then
print $data00 print $data00
return -1 return -1
endi endi
...@@ -965,7 +953,7 @@ endi ...@@ -965,7 +953,7 @@ endi
if $data08 != 3 then if $data08 != 3 then
return -1 return -1
endi endi
if $data09 != @21-03-01 01:00:00.000@ then if $data09 != @21-03-02 01:00:00.000@ then
return -1 return -1
endi endi
...@@ -973,38 +961,23 @@ sql select top(st1.f1, 5) from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts ...@@ -973,38 +961,23 @@ sql select top(st1.f1, 5) from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts
if $rows != 5 then if $rows != 5 then
return -1 return -1
endi endi
if $data00 != @21-03-01 05:00:00.000@ then if $data00 != 9915 then
return -1
endi
if $data01 != 9915 then
return -1 return -1
endi endi
if $data10 != @21-03-02 05:00:00.000@ then if $data10 != 9915 then
return -1
endi
if $data11 != 9915 then
return -1 return -1
endi endi
if $data20 != @21-03-03 05:00:00.000@ then if $data20 != 9915 then
return -1
endi
if $data21 != 9915 then
return -1 return -1
endi endi
if $data30 != @21-03-04 05:00:00.000@ then if $data30 != 9915 then
return -1
endi
if $data31 != 9915 then
return -1 return -1
endi endi
if $data40 != @21-03-05 05:00:00.000@ then if $data40 != 9915 then
return -1
endi
if $data41 != 9915 then
return -1 return -1
endi endi
sql select top(st0.f1,5) from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1; sql select st0.ts, top(st0.f1,5) from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1 order by st0.ts;
if $rows != 5 then if $rows != 5 then
return -1 return -1
endi endi
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册