calcNeedCountEmpty
This commit is contained in:
parent
6e4703e5b4
commit
c9b69316c1
|
@ -147,6 +147,7 @@ typedef struct SAggLogicNode {
|
||||||
bool isGroupTb;
|
bool isGroupTb;
|
||||||
bool isPartTb; // true if partition keys has tbname
|
bool isPartTb; // true if partition keys has tbname
|
||||||
bool hasGroup;
|
bool hasGroup;
|
||||||
|
bool isCountByTag; // true if hasCountFunc & part by tag/tbname
|
||||||
} SAggLogicNode;
|
} SAggLogicNode;
|
||||||
|
|
||||||
typedef struct SProjectLogicNode {
|
typedef struct SProjectLogicNode {
|
||||||
|
|
|
@ -453,6 +453,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -748,6 +748,15 @@ 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;
|
||||||
|
|
|
@ -2783,6 +2783,7 @@ 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;
|
||||||
|
|
|
@ -37,6 +37,7 @@ 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) {
|
||||||
|
@ -592,17 +593,13 @@ static bool calcNeedCountEmpty(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLog
|
||||||
if (pScanLogicNode->interval > 0) {
|
if (pScanLogicNode->interval > 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// 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)
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pRoot;
|
&& pCxt->pNode && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pCxt->pNode)) {
|
||||||
// select & count
|
SAggLogicNode* pNode = (SAggLogicNode*)pCxt->pNode;
|
||||||
if (pSelect->hasCountFunc) {
|
if (pNode->isCountByTag) {
|
||||||
// key only accept tag/tbname
|
return true;
|
||||||
if (NULL != pSelect->pGroupByList) {
|
|
||||||
return !keysHasCol(pSelect->pGroupByList);
|
|
||||||
} else if (NULL != pSelect->pPartitionByList) {
|
|
||||||
return !keysHasCol(pSelect->pPartitionByList);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -2302,7 +2299,9 @@ static int32_t createPhysiSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogic
|
||||||
} else {
|
} else {
|
||||||
pSubplan->msgType = TDMT_SCH_MERGE_QUERY;
|
pSubplan->msgType = TDMT_SCH_MERGE_QUERY;
|
||||||
}
|
}
|
||||||
|
pCxt->pNode = pLogicSubplan->pNode;
|
||||||
code = createPhysiNode(pCxt, pLogicSubplan->pNode, pSubplan, &pSubplan->pNode);
|
code = createPhysiNode(pCxt, pLogicSubplan->pNode, pSubplan, &pSubplan->pNode);
|
||||||
|
pCxt->pNode = NULL;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -2454,7 +2453,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue