Merge pull request #14777 from taosdata/szhou/td-17001
feat: tag scan optimization
This commit is contained in:
commit
f797e60f3f
|
@ -1364,9 +1364,9 @@ static EDealRes partTagsOptHasColImpl(SNode* pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool partTagsOptHasCol(SNodeList* pPartKeys) {
|
static bool planOptNodeListHasCol(SNodeList* pKeys) {
|
||||||
bool hasCol = false;
|
bool hasCol = false;
|
||||||
nodesWalkExprs(pPartKeys, partTagsOptHasColImpl, &hasCol);
|
nodesWalkExprs(pKeys, partTagsOptHasColImpl, &hasCol);
|
||||||
return hasCol;
|
return hasCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1409,7 +1409,7 @@ static bool partTagsOptMayBeOptimized(SLogicNode* pNode) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !partTagsOptHasCol(partTagsGetPartKeys(pNode)) && partTagsOptAreSupportedFuncs(partTagsGetFuncs(pNode));
|
return !planOptNodeListHasCol(partTagsGetPartKeys(pNode)) && partTagsOptAreSupportedFuncs(partTagsGetFuncs(pNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) {
|
static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) {
|
||||||
|
@ -2096,6 +2096,37 @@ static int32_t mergeProjectsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLog
|
||||||
return mergeProjectsOptimizeImpl(pCxt, pLogicSubplan, pProjectNode);
|
return mergeProjectsOptimizeImpl(pCxt, pLogicSubplan, pProjectNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool tagScanMayBeOptimized(SLogicNode* pNode) {
|
||||||
|
if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode) || (SCAN_TYPE_TAG == ((SScanLogicNode*)pNode)->scanType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SScanLogicNode *pScan = (SScanLogicNode*)pNode;
|
||||||
|
if (NULL != pScan->pScanCols) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (NULL == pNode->pParent || QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent) || 1 != LIST_LENGTH(pNode->pParent->pChildren)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SAggLogicNode* pAgg = (SAggLogicNode*)(pNode->pParent);
|
||||||
|
if (NULL == pAgg->pGroupKeys || NULL != pAgg->pAggFuncs || planOptNodeListHasCol(pAgg->pGroupKeys)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tagScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||||
|
SScanLogicNode* pScanNode = (SScanLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, tagScanMayBeOptimized);
|
||||||
|
if (NULL == pScanNode) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pScanNode->scanType = SCAN_TYPE_TAG;
|
||||||
|
pCxt->optimized = true;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const SOptimizeRule optimizeRuleSet[] = {
|
static const SOptimizeRule optimizeRuleSet[] = {
|
||||||
{.pName = "ScanPath", .optimizeFunc = scanPathOptimize},
|
{.pName = "ScanPath", .optimizeFunc = scanPathOptimize},
|
||||||
|
@ -2108,7 +2139,8 @@ static const SOptimizeRule optimizeRuleSet[] = {
|
||||||
{.pName = "EliminateSetOperator", .optimizeFunc = eliminateSetOpOptimize},
|
{.pName = "EliminateSetOperator", .optimizeFunc = eliminateSetOpOptimize},
|
||||||
{.pName = "RewriteTail", .optimizeFunc = rewriteTailOptimize},
|
{.pName = "RewriteTail", .optimizeFunc = rewriteTailOptimize},
|
||||||
{.pName = "RewriteUnique", .optimizeFunc = rewriteUniqueOptimize},
|
{.pName = "RewriteUnique", .optimizeFunc = rewriteUniqueOptimize},
|
||||||
{.pName = "LastRowScan", .optimizeFunc = lastRowScanOptimize}
|
{.pName = "LastRowScan", .optimizeFunc = lastRowScanOptimize},
|
||||||
|
{.pName = "TagScan", .optimizeFunc = tagScanOptimize}
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
|
@ -88,3 +88,10 @@ TEST_F(PlanOptimizeTest, pushDownProjectCond) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) where 1-c1>5 order by 1 nulls first");
|
run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) where 1-c1>5 order by 1 nulls first");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PlanOptimizeTest, tagScan) {
|
||||||
|
useDb("root", "test");
|
||||||
|
run("select tag1 from st1 group by tag1");
|
||||||
|
run("select distinct tag1 from st1");
|
||||||
|
run("select tag1*tag1 from st1 group by tag1*tag1");
|
||||||
|
}
|
Loading…
Reference in New Issue