Merge pull request #21763 from taosdata/fix/TD-24845
fix: distinct column removed in union all issue
This commit is contained in:
commit
3b246d4a91
|
@ -372,18 +372,33 @@ static bool notRefByOrderBy(SColumnNode* pCol, SNodeList* pOrderByList) {
|
||||||
return !cxt.hasThisCol;
|
return !cxt.hasThisCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isDistinctSubQuery(SNode* pNode) {
|
||||||
|
if (NULL == pNode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (nodeType(pNode)) {
|
||||||
|
case QUERY_NODE_SELECT_STMT:
|
||||||
|
return ((SSelectStmt*)pNode)->isDistinct;
|
||||||
|
case QUERY_NODE_SET_OPERATOR:
|
||||||
|
return isDistinctSubQuery((((SSetOperator*)pNode)->pLeft)) || isDistinctSubQuery((((SSetOperator*)pNode)->pLeft));
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static bool isSetUselessCol(SSetOperator* pSetOp, int32_t index, SExprNode* pProj) {
|
static bool isSetUselessCol(SSetOperator* pSetOp, int32_t index, SExprNode* pProj) {
|
||||||
if (!isUselessCol(pProj)) {
|
if (!isUselessCol(pProj)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNodeList* pLeftProjs = getChildProjection(pSetOp->pLeft);
|
SNodeList* pLeftProjs = getChildProjection(pSetOp->pLeft);
|
||||||
if (!isUselessCol((SExprNode*)nodesListGetNode(pLeftProjs, index))) {
|
if (!isUselessCol((SExprNode*)nodesListGetNode(pLeftProjs, index)) || isDistinctSubQuery(pSetOp->pLeft)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNodeList* pRightProjs = getChildProjection(pSetOp->pRight);
|
SNodeList* pRightProjs = getChildProjection(pSetOp->pRight);
|
||||||
if (!isUselessCol((SExprNode*)nodesListGetNode(pRightProjs, index))) {
|
if (!isUselessCol((SExprNode*)nodesListGetNode(pRightProjs, index)) || isDistinctSubQuery(pSetOp->pLeft)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue