This commit is contained in:
Bob Liu 2023-12-25 11:54:10 +08:00
parent da0ecc18b9
commit 15694df001
5 changed files with 19 additions and 35 deletions

View File

@ -424,6 +424,7 @@ static int32_t logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
COPY_SCALAR_FIELD(groupOrderScan); COPY_SCALAR_FIELD(groupOrderScan);
COPY_SCALAR_FIELD(onlyMetaCtbIdx); COPY_SCALAR_FIELD(onlyMetaCtbIdx);
COPY_SCALAR_FIELD(filesetDelimited); COPY_SCALAR_FIELD(filesetDelimited);
COPY_SCALAR_FIELD(isCountByTag);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -453,7 +454,6 @@ static int32_t logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) {
COPY_SCALAR_FIELD(isGroupTb); COPY_SCALAR_FIELD(isGroupTb);
COPY_SCALAR_FIELD(isPartTb); COPY_SCALAR_FIELD(isPartTb);
COPY_SCALAR_FIELD(hasGroup); COPY_SCALAR_FIELD(hasGroup);
COPY_SCALAR_FIELD(isCountByTag);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -486,6 +486,16 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
code = tagScanSetExecutionMode(pScan); code = tagScanSetExecutionMode(pScan);
} }
bool isCountByTag = false;
if (pSelect->hasCountFunc) {
if (pSelect->pGroupByList) {
isCountByTag = !keysHasCol(pSelect->pGroupByList);
} else if (pSelect->pPartitionByList) {
isCountByTag = !keysHasCol(pSelect->pPartitionByList);
}
}
pScan->isCountByTag = isCountByTag;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
*pLogicNode = (SLogicNode*)pScan; *pLogicNode = (SLogicNode*)pScan;
} else { } else {
@ -748,15 +758,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
pAgg->isGroupTb = pAgg->pGroupKeys ? keysHasTbname(pAgg->pGroupKeys) : 0; pAgg->isGroupTb = pAgg->pGroupKeys ? keysHasTbname(pAgg->pGroupKeys) : 0;
pAgg->isPartTb = pSelect->pPartitionByList ? keysHasTbname(pSelect->pPartitionByList) : 0; pAgg->isPartTb = pSelect->pPartitionByList ? keysHasTbname(pSelect->pPartitionByList) : 0;
pAgg->hasGroup = pAgg->pGroupKeys || pSelect->pPartitionByList; pAgg->hasGroup = pAgg->pGroupKeys || pSelect->pPartitionByList;
bool isCountByTag = false;
if (pSelect->hasCountFunc) {
if (pSelect->pGroupByList) {
isCountByTag = !keysHasCol(pSelect->pGroupByList);
} else if (pSelect->pPartitionByList) {
isCountByTag = !keysHasCol(pSelect->pPartitionByList);
}
}
pAgg->isCountByTag = isCountByTag;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
*pLogicNode = (SLogicNode*)pAgg; *pLogicNode = (SLogicNode*)pAgg;

View File

@ -2783,7 +2783,6 @@ static int32_t splitCacheLastFuncOptCreateAggLogicNode(SAggLogicNode** pNewAgg,
pNew->isGroupTb = pAgg->isGroupTb; pNew->isGroupTb = pAgg->isGroupTb;
pNew->isPartTb = pAgg->isPartTb; pNew->isPartTb = pAgg->isPartTb;
pNew->hasGroup = pAgg->hasGroup; pNew->hasGroup = pAgg->hasGroup;
pNew->isCountByTag = pAgg->isCountByTag;
pNew->node.pChildren = nodesCloneList(pAgg->node.pChildren); pNew->node.pChildren = nodesCloneList(pAgg->node.pChildren);
int32_t code = 0; int32_t code = 0;

View File

@ -37,7 +37,6 @@ typedef struct SPhysiPlanContext {
SArray* pLocationHelper; SArray* pLocationHelper;
bool hasScan; bool hasScan;
bool hasSysScan; bool hasSysScan;
SLogicNode* pNode; // tmp record LogicSubplan->pNode
} SPhysiPlanContext; } SPhysiPlanContext;
static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey, int32_t keyBufSize) { static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey, int32_t keyBufSize) {
@ -595,23 +594,8 @@ static bool calcNeedCountEmpty(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLog
} }
// limit: root node is select // limit: root node is select
SNode* pRoot = pCxt->pPlanCxt->pAstRoot; SNode* pRoot = pCxt->pPlanCxt->pAstRoot;
if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) { if (QUERY_NODE_SELECT_STMT == nodeType(pRoot) && pScanLogicNode->isCountByTag) {
// case1 root select return true;
SSelectStmt* pSelect = (SSelectStmt*)pRoot;
if (pSelect->hasCountFunc) {
if (NULL != pSelect->pGroupByList) {
return !keysHasCol(pSelect->pGroupByList);
} else if (NULL != pSelect->pPartitionByList) {
return !keysHasCol(pSelect->pPartitionByList);
}
}
// case2 inner agg
if (pCxt->pNode && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pCxt->pNode)) {
SAggLogicNode* pNode = (SAggLogicNode*)pCxt->pNode;
if (pNode->isCountByTag) {
return true;
}
}
} }
return false; return false;
@ -2312,9 +2296,6 @@ static int32_t createPhysiSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogic
pSubplan->msgType = TDMT_SCH_MERGE_QUERY; pSubplan->msgType = TDMT_SCH_MERGE_QUERY;
} }
if (QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pLogicSubplan->pNode)) {
pCxt->pNode = pLogicSubplan->pNode;
}
code = createPhysiNode(pCxt, pLogicSubplan->pNode, pSubplan, &pSubplan->pNode); code = createPhysiNode(pCxt, pLogicSubplan->pNode, pSubplan, &pSubplan->pNode);
if (TSDB_CODE_SUCCESS == code && !pCxt->pPlanCxt->streamQuery && !pCxt->pPlanCxt->topicQuery) { if (TSDB_CODE_SUCCESS == code && !pCxt->pPlanCxt->streamQuery && !pCxt->pPlanCxt->topicQuery) {
code = createDataDispatcher(pCxt, pSubplan->pNode, &pSubplan->pDataSink); code = createDataDispatcher(pCxt, pSubplan->pNode, &pSubplan->pDataSink);
@ -2416,7 +2397,6 @@ static int32_t doCreatePhysiPlan(SPhysiPlanContext* pCxt, SQueryLogicPlan* pLogi
break; break;
} }
} }
pCxt->pNode = NULL;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
*pPhysiPlan = pPlan; *pPhysiPlan = pPlan;
@ -2468,8 +2448,7 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryP
.nextDataBlockId = 0, .nextDataBlockId = 0,
.pLocationHelper = taosArrayInit(32, POINTER_BYTES), .pLocationHelper = taosArrayInit(32, POINTER_BYTES),
.hasScan = false, .hasScan = false,
.hasSysScan = false, .hasSysScan = false};
.pNode = NULL};
if (NULL == cxt.pLocationHelper) { if (NULL == cxt.pLocationHelper) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }

View File

@ -348,6 +348,10 @@ e
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/cos.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/cos.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/cos.py -R ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/cos.py -R
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/group_partition.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/group_partition.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/group_partition.py -R
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/group_partition.py -Q 2
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/group_partition.py -Q 3
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/group_partition.py -Q 4
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count_partition.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count_partition.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count_partition.py -R ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count_partition.py -R
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count.py