fix: select tags and set tag scan execution mode
This commit is contained in:
parent
9fb9d863b9
commit
514da6e1b0
|
@ -16,6 +16,7 @@
|
|||
#ifndef _TD_COMMON_TOKEN_H_
|
||||
#define _TD_COMMON_TOKEN_H_
|
||||
|
||||
|
||||
#define TK_OR 1
|
||||
#define TK_AND 2
|
||||
#define TK_UNION 3
|
||||
|
@ -354,7 +355,6 @@
|
|||
#define TK_VIEW 336
|
||||
#define TK_WAL 337
|
||||
|
||||
|
||||
#define TK_NK_SPACE 600
|
||||
#define TK_NK_COMMENT 601
|
||||
#define TK_NK_ILLEGAL 602
|
||||
|
|
|
@ -143,6 +143,7 @@ SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange);
|
|||
SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery);
|
||||
SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill);
|
||||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
||||
SNode* setSelectStmtTagMode(SAstCreateContext* pCxt, SNode* pStmt, bool bSelectTags);
|
||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
||||
|
||||
SDataType createDataType(uint8_t type);
|
||||
|
|
|
@ -1013,7 +1013,7 @@ query_specification(A) ::=
|
|||
where_clause_opt(E) partition_by_clause_opt(F) range_opt(J) every_opt(K)
|
||||
fill_opt(L) twindow_clause_opt(G) group_by_clause_opt(H) having_clause_opt(I). {
|
||||
A = createSelectStmt(pCxt, B, C, D);
|
||||
A = setSelectStmtTagMode(pCtxt, A, M);
|
||||
A = setSelectStmtTagMode(pCxt, A, M);
|
||||
A = addWhereClause(pCxt, A, E);
|
||||
A = addPartitionByClause(pCxt, A, F);
|
||||
A = addWindowClauseClause(pCxt, A, G);
|
||||
|
|
|
@ -852,6 +852,13 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
|
|||
return select;
|
||||
}
|
||||
|
||||
SNode* setSelectStmtTagMode(SAstCreateContext* pCxt, SNode* pStmt, bool bSelectTags) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->tagScan = bSelectTags;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
static void setSubquery(SNode* pStmt) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->isSubquery = true;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "planInt.h"
|
||||
|
||||
#include "filter.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
typedef struct SLogicPlanContext {
|
||||
|
@ -344,6 +344,45 @@ static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealT
|
|||
|
||||
static bool needScanDefaultCol(EScanType scanType) { return SCAN_TYPE_TABLE_COUNT != scanType; }
|
||||
|
||||
static EDealRes tagScanNodeHasTbnameFunc(SNode* pNode, void* pContext) {
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
if (COLUMN_TYPE_TBNAME == ((SColumnNode*)pNode)->colType) {
|
||||
*(bool*)pContext = true;
|
||||
return DEAL_RES_END;
|
||||
}
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static bool tagScanNodeListHasTbname(SNodeList* pCols) {
|
||||
bool hasTbname = false;
|
||||
nodesWalkExprs(pCols, tagScanNodeHasTbnameFunc, &hasTbname);
|
||||
return hasTbname;
|
||||
}
|
||||
|
||||
static bool tagScanNodeHasTbname(SNode* pKeys) {
|
||||
bool hasTbname = false;
|
||||
nodesWalkExpr(pKeys, tagScanNodeHasTbnameFunc, &hasTbname);
|
||||
return hasTbname;
|
||||
}
|
||||
|
||||
static int32_t setTagScanOnlyMetaCtbIdx(SScanLogicNode* pScan) {
|
||||
SNode* pCond = nodesCloneNode(pScan->node.pConditions);
|
||||
SNode* pTagCond = NULL;
|
||||
SNode* pTagIndexCond = NULL;
|
||||
bool bOnlyMetaCtbIdx = false;
|
||||
filterPartitionCond(&pCond, NULL, &pTagIndexCond, &pTagCond, NULL);
|
||||
if (pTagIndexCond || tagScanNodeListHasTbname(pScan->pScanPseudoCols) || tagScanNodeHasTbname(pTagCond)) {
|
||||
bOnlyMetaCtbIdx = false;
|
||||
} else {
|
||||
bOnlyMetaCtbIdx = true;
|
||||
}
|
||||
nodesDestroyNode(pCond);
|
||||
nodesDestroyNode(pTagIndexCond);
|
||||
nodesDestroyNode(pTagCond);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable,
|
||||
SLogicNode** pLogicNode) {
|
||||
SScanLogicNode* pScan = NULL;
|
||||
|
@ -411,6 +450,10 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
code = createColumnByRewriteExprs(pScan->pScanPseudoCols, &pScan->node.pTargets);
|
||||
}
|
||||
|
||||
if (pSelect->tagScan) {
|
||||
code = setTagScanOnlyMetaCtbIdx(pScan);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pScan;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue