feat: add hint supporting

This commit is contained in:
dapan1121 2023-08-14 17:21:15 +08:00
parent 6ce28e8886
commit 6a78053b51
17 changed files with 2844 additions and 2739 deletions

View File

@ -247,6 +247,7 @@ typedef enum ENodeType {
QUERY_NODE_WHEN_THEN, QUERY_NODE_WHEN_THEN,
QUERY_NODE_CASE_WHEN, QUERY_NODE_CASE_WHEN,
QUERY_NODE_EVENT_WINDOW, QUERY_NODE_EVENT_WINDOW,
QUERY_NODE_HINT,
// Statement nodes are used in parser and planner module. // Statement nodes are used in parser and planner module.
QUERY_NODE_SET_OPERATOR = 100, QUERY_NODE_SET_OPERATOR = 100,
@ -950,7 +951,6 @@ typedef struct STimeWindow {
} STimeWindow; } STimeWindow;
typedef struct SQueryHint { typedef struct SQueryHint {
bool withHint;
bool batchScan; bool batchScan;
} SQueryHint; } SQueryHint;

View File

@ -276,83 +276,86 @@
#define TK_JOIN 258 #define TK_JOIN 258
#define TK_INNER 259 #define TK_INNER 259
#define TK_SELECT 260 #define TK_SELECT 260
#define TK_DISTINCT 261 #define TK_NO_BATCH_SCAN 261
#define TK_WHERE 262 #define TK_BATCH_SCAN 262
#define TK_PARTITION 263 #define TK_DISTINCT 263
#define TK_BY 264 #define TK_WHERE 264
#define TK_SESSION 265 #define TK_PARTITION 265
#define TK_STATE_WINDOW 266 #define TK_BY 266
#define TK_EVENT_WINDOW 267 #define TK_SESSION 267
#define TK_SLIDING 268 #define TK_STATE_WINDOW 268
#define TK_FILL 269 #define TK_EVENT_WINDOW 269
#define TK_VALUE 270 #define TK_SLIDING 270
#define TK_VALUE_F 271 #define TK_FILL 271
#define TK_NONE 272 #define TK_VALUE 272
#define TK_PREV 273 #define TK_VALUE_F 273
#define TK_NULL_F 274 #define TK_NONE 274
#define TK_LINEAR 275 #define TK_PREV 275
#define TK_NEXT 276 #define TK_NULL_F 276
#define TK_HAVING 277 #define TK_LINEAR 277
#define TK_RANGE 278 #define TK_NEXT 278
#define TK_EVERY 279 #define TK_HAVING 279
#define TK_ORDER 280 #define TK_RANGE 280
#define TK_SLIMIT 281 #define TK_EVERY 281
#define TK_SOFFSET 282 #define TK_ORDER 282
#define TK_LIMIT 283 #define TK_SLIMIT 283
#define TK_OFFSET 284 #define TK_SOFFSET 284
#define TK_ASC 285 #define TK_LIMIT 285
#define TK_NULLS 286 #define TK_OFFSET 286
#define TK_ABORT 287 #define TK_ASC 287
#define TK_AFTER 288 #define TK_NULLS 288
#define TK_ATTACH 289 #define TK_ABORT 289
#define TK_BEFORE 290 #define TK_AFTER 290
#define TK_BEGIN 291 #define TK_ATTACH 291
#define TK_BITAND 292 #define TK_BEFORE 292
#define TK_BITNOT 293 #define TK_BEGIN 293
#define TK_BITOR 294 #define TK_BITAND 294
#define TK_BLOCKS 295 #define TK_BITNOT 295
#define TK_CHANGE 296 #define TK_BITOR 296
#define TK_COMMA 297 #define TK_BLOCKS 297
#define TK_CONCAT 298 #define TK_CHANGE 298
#define TK_CONFLICT 299 #define TK_COMMA 299
#define TK_COPY 300 #define TK_CONCAT 300
#define TK_DEFERRED 301 #define TK_CONFLICT 301
#define TK_DELIMITERS 302 #define TK_COPY 302
#define TK_DETACH 303 #define TK_DEFERRED 303
#define TK_DIVIDE 304 #define TK_DELIMITERS 304
#define TK_DOT 305 #define TK_DETACH 305
#define TK_EACH 306 #define TK_DIVIDE 306
#define TK_FAIL 307 #define TK_DOT 307
#define TK_FILE 308 #define TK_EACH 308
#define TK_FOR 309 #define TK_FAIL 309
#define TK_GLOB 310 #define TK_FILE 310
#define TK_ID 311 #define TK_FOR 311
#define TK_IMMEDIATE 312 #define TK_GLOB 312
#define TK_IMPORT 313 #define TK_ID 313
#define TK_INITIALLY 314 #define TK_IMMEDIATE 314
#define TK_INSTEAD 315 #define TK_IMPORT 315
#define TK_ISNULL 316 #define TK_INITIALLY 316
#define TK_KEY 317 #define TK_INSTEAD 317
#define TK_MODULES 318 #define TK_ISNULL 318
#define TK_NK_BITNOT 319 #define TK_KEY 319
#define TK_NK_SEMI 320 #define TK_MODULES 320
#define TK_NOTNULL 321 #define TK_NK_BITNOT 321
#define TK_OF 322 #define TK_NK_SEMI 322
#define TK_PLUS 323 #define TK_NOTNULL 323
#define TK_PRIVILEGE 324 #define TK_OF 324
#define TK_RAISE 325 #define TK_PLUS 325
#define TK_RESTRICT 326 #define TK_PRIVILEGE 326
#define TK_ROW 327 #define TK_RAISE 327
#define TK_SEMI 328 #define TK_RESTRICT 328
#define TK_STAR 329 #define TK_ROW 329
#define TK_STATEMENT 330 #define TK_SEMI 330
#define TK_STRICT 331 #define TK_STAR 331
#define TK_STRING 332 #define TK_STATEMENT 332
#define TK_TIMES 333 #define TK_STRICT 333
#define TK_VALUES 334 #define TK_STRING 334
#define TK_VARIABLE 335 #define TK_TIMES 335
#define TK_VIEW 336 #define TK_VALUES 336
#define TK_WAL 337 #define TK_VARIABLE 337
#define TK_VIEW 338
#define TK_WAL 339
#define TK_NK_SPACE 600 #define TK_NK_SPACE 600

View File

@ -116,6 +116,18 @@ typedef struct SLeftValueNode {
ENodeType type; ENodeType type;
} SLeftValueNode; } SLeftValueNode;
typedef enum EHintOption {
HINT_NO_BATCH_SCAN = 1,
HINT_BATCH_SCAN,
} EHintOption;
typedef struct SHintNode {
ENodeType type;
EHintOption option;
char* literal;
void* value;
} SHintNode;
typedef struct SOperatorNode { typedef struct SOperatorNode {
SExprNode node; // QUERY_NODE_OPERATOR SExprNode node; // QUERY_NODE_OPERATOR
EOperatorType opType; EOperatorType opType;
@ -304,6 +316,7 @@ typedef struct SSelectStmt {
SLimitNode* pLimit; SLimitNode* pLimit;
SLimitNode* pSlimit; SLimitNode* pSlimit;
STimeWindow timeRange; STimeWindow timeRange;
SNodeList* pHint;
char stmtName[TSDB_TABLE_NAME_LEN]; char stmtName[TSDB_TABLE_NAME_LEN];
uint8_t precision; uint8_t precision;
int32_t selectFuncNum; int32_t selectFuncNum;

View File

@ -236,6 +236,9 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
goto _error; goto _error;
} }
numOfDownstream = 2; numOfDownstream = 2;
} else {
pInfo->downstreamResBlkId[0] = getOperatorResultBlockId(pDownstream[0], 0);
pInfo->downstreamResBlkId[1] = getOperatorResultBlockId(pDownstream[1], 1);
} }
int32_t numOfCols = 0; int32_t numOfCols = 0;
@ -653,10 +656,12 @@ static int32_t mergeJoinJoinDownstreamTsRanges(SOperatorInfo* pOperator, int64_t
static void setMergeJoinDone(SOperatorInfo* pOperator) { static void setMergeJoinDone(SOperatorInfo* pOperator) {
setOperatorCompleted(pOperator); setOperatorCompleted(pOperator);
freeOperatorParam(pOperator->pDownstreamGetParams[0], OP_GET_PARAM); if (pOperator->pDownstreamGetParams) {
freeOperatorParam(pOperator->pDownstreamGetParams[1], OP_GET_PARAM); freeOperatorParam(pOperator->pDownstreamGetParams[0], OP_GET_PARAM);
pOperator->pDownstreamGetParams[0] = NULL; freeOperatorParam(pOperator->pDownstreamGetParams[1], OP_GET_PARAM);
pOperator->pDownstreamGetParams[1] = NULL; pOperator->pDownstreamGetParams[0] = NULL;
pOperator->pDownstreamGetParams[1] = NULL;
}
} }
static bool mergeJoinGetNextTimestamp(SOperatorInfo* pOperator, int64_t* pLeftTs, int64_t* pRightTs) { static bool mergeJoinGetNextTimestamp(SOperatorInfo* pOperator, int64_t* pLeftTs, int64_t* pRightTs) {
@ -785,7 +790,7 @@ void resetMergeJoinOperator(struct SOperatorInfo* pOperator) {
SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) { SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
SMJoinOperatorInfo* pJoinInfo = pOperator->info; SMJoinOperatorInfo* pJoinInfo = pOperator->info;
if (pOperator->status == OP_EXEC_DONE) { if (pOperator->status == OP_EXEC_DONE) {
if (NULL == pOperator->pDownstreamGetParams[0] || NULL == pOperator->pDownstreamGetParams[1]) { if (NULL == pOperator->pDownstreamGetParams || NULL == pOperator->pDownstreamGetParams[0] || NULL == pOperator->pDownstreamGetParams[1]) {
qError("total merge join res rows:%" PRId64, pJoinInfo->resRows); qError("total merge join res rows:%" PRId64, pJoinInfo->resRows);
return NULL; return NULL;
} else { } else {

View File

@ -301,6 +301,8 @@ SNode* nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SCaseWhenNode)); return makeNode(type, sizeof(SCaseWhenNode));
case QUERY_NODE_EVENT_WINDOW: case QUERY_NODE_EVENT_WINDOW:
return makeNode(type, sizeof(SEventWindowNode)); return makeNode(type, sizeof(SEventWindowNode));
case QUERY_NODE_HINT:
return makeNode(type, sizeof(SHintNode));
case QUERY_NODE_SET_OPERATOR: case QUERY_NODE_SET_OPERATOR:
return makeNode(type, sizeof(SSetOperator)); return makeNode(type, sizeof(SSetOperator));
case QUERY_NODE_SELECT_STMT: case QUERY_NODE_SELECT_STMT:
@ -656,6 +658,15 @@ static void destroyTableCfg(STableCfg* pCfg) {
static void destroySmaIndex(void* pIndex) { taosMemoryFree(((STableIndexInfo*)pIndex)->expr); } static void destroySmaIndex(void* pIndex) { taosMemoryFree(((STableIndexInfo*)pIndex)->expr); }
static void destroyHintValue(EHintOption option, void* value) {
switch (option) {
default:
break;
}
taosMemoryFree(value);
}
void nodesDestroyNode(SNode* pNode) { void nodesDestroyNode(SNode* pNode) {
if (NULL == pNode) { if (NULL == pNode) {
return; return;
@ -814,6 +825,12 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyNode(pEvent->pEndCond); nodesDestroyNode(pEvent->pEndCond);
break; break;
} }
case QUERY_NODE_HINT: {
SHintNode* pHint = (SHintNode*)pNode;
taosMemoryFreeClear(pHint->literal);
destroyHintValue(pHint->option, pHint->value);
break;
}
case QUERY_NODE_SET_OPERATOR: { case QUERY_NODE_SET_OPERATOR: {
SSetOperator* pStmt = (SSetOperator*)pNode; SSetOperator* pStmt = (SSetOperator*)pNode;
nodesDestroyList(pStmt->pProjectionList); nodesDestroyList(pStmt->pProjectionList);
@ -840,6 +857,7 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyList(pStmt->pOrderByList); nodesDestroyList(pStmt->pOrderByList);
nodesDestroyNode((SNode*)pStmt->pLimit); nodesDestroyNode((SNode*)pStmt->pLimit);
nodesDestroyNode((SNode*)pStmt->pSlimit); nodesDestroyNode((SNode*)pStmt->pSlimit);
nodesDestroyList(pStmt->pHint);
break; break;
} }
case QUERY_NODE_VNODE_MODIFY_STMT: { case QUERY_NODE_VNODE_MODIFY_STMT: {

View File

@ -101,6 +101,7 @@ SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode
SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName); SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName);
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral); SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral);
SNode* createHintNode(SAstCreateContext* pCxt, EHintOption option, const SToken* pLiteral);
SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral); SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral);
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral); SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral);
SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt); SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt);
@ -142,7 +143,7 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange); SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange);
SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery); SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery);
SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill); SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill);
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable); SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint);
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight); SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
SDataType createDataType(uint8_t type); SDataType createDataType(uint8_t type);

View File

@ -116,7 +116,7 @@ int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName,
int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput); int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput);
int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes); int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes);
void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request); void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request);
SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable); SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint);
/** /**
* @brief return a - b with overflow check * @brief return a - b with overflow check

View File

@ -1024,12 +1024,12 @@ query_specification(A) ::=
} }
hint_opt(A) ::= . { A = false; }
hint_opt(A) ::= NO_BATCH_SCAN NK_LP NK_RP. { A = createHintNode(pCxt, HINT_NO_BATCH_SCAN, NULL); } hint_opt(A) ::= NO_BATCH_SCAN NK_LP NK_RP. { A = createHintNode(pCxt, HINT_NO_BATCH_SCAN, NULL); }
hint_opt(A) ::= BATCH_SCAN NK_LP NK_RP. { A = createHintNode(pCxt, HINT_BATCH_SCAN, NULL); } hint_opt(A) ::= BATCH_SCAN NK_LP NK_RP. { A = createHintNode(pCxt, HINT_BATCH_SCAN, NULL); }
%type hint_opt_list { SNodeList* } %type hint_opt_list { SNodeList* }
%destructor hint_opt_list { nodesDestroyList($$); } %destructor hint_opt_list { nodesDestroyList($$); }
hint_opt_list(A) ::= . { A = NULL; }
hint_opt_list(A) ::= hint_opt(B). { A = createNodeList(pCxt, B); } hint_opt_list(A) ::= hint_opt(B). { A = createNodeList(pCxt, B); }
hint_opt_list(A) ::= hint_opt_list(B) hint_opt(C). { A = addNodeToList(pCxt, B, C); } hint_opt_list(A) ::= hint_opt_list(B) hint_opt(C). { A = addNodeToList(pCxt, B, C); }

View File

@ -348,6 +348,17 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
return (SNode*)val; return (SNode*)val;
} }
SNode* createHintNode(SAstCreateContext* pCxt, EHintOption option, const SToken* pLiteral) {
CHECK_PARSER_STATUS(pCxt);
SHintNode* hint = (SHintNode*)nodesMakeNode(QUERY_NODE_HINT);
CHECK_OUT_OF_MEM(hint);
hint->option = option;
hint->literal = strndup(pLiteral->z, pLiteral->n);
trimString(pLiteral->z, pLiteral->n, hint->literal, pLiteral->n);
CHECK_OUT_OF_MEM(hint->literal);
return (SNode*)hint;
}
SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral) { SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral) {
trimEscape(pLiteral); trimEscape(pLiteral);
return createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, pLiteral); return createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, pLiteral);
@ -845,9 +856,9 @@ SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill) {
return pStmt; return pStmt;
} }
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable) { SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint) {
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
SNode* select = createSelectStmtImpl(isDistinct, pProjectionList, pTable); SNode* select = createSelectStmtImpl(isDistinct, pProjectionList, pTable, pHint);
CHECK_OUT_OF_MEM(select); CHECK_OUT_OF_MEM(select);
return select; return select;
} }

View File

@ -42,6 +42,7 @@ static SKeyword keywordTable[] = {
{"ASC", TK_ASC}, {"ASC", TK_ASC},
{"AT_ONCE", TK_AT_ONCE}, {"AT_ONCE", TK_AT_ONCE},
{"BALANCE", TK_BALANCE}, {"BALANCE", TK_BALANCE},
{"BATCH_SCAN", TK_BATCH_SCAN},
{"BETWEEN", TK_BETWEEN}, {"BETWEEN", TK_BETWEEN},
{"BIGINT", TK_BIGINT}, {"BIGINT", TK_BIGINT},
{"BINARY", TK_BINARY}, {"BINARY", TK_BINARY},
@ -153,6 +154,7 @@ static SKeyword keywordTable[] = {
{"NONE", TK_NONE}, {"NONE", TK_NONE},
{"NOT", TK_NOT}, {"NOT", TK_NOT},
{"NOW", TK_NOW}, {"NOW", TK_NOW},
{"NO_BATCH_SCAN", TK_NO_BATCH_SCAN},
{"NULL", TK_NULL}, {"NULL", TK_NULL},
{"NULL_F", TK_NULL_F}, {"NULL_F", TK_NULL_F},
{"NULLS", TK_NULLS}, {"NULLS", TK_NULLS},

View File

@ -6166,7 +6166,7 @@ static int32_t buildQueryForTableTopic(STranslateContext* pCxt, SCreateTopicStmt
strcpy(realTable->table.dbName, pStmt->subDbName); strcpy(realTable->table.dbName, pStmt->subDbName);
strcpy(realTable->table.tableName, pStmt->subSTbName); strcpy(realTable->table.tableName, pStmt->subSTbName);
strcpy(realTable->table.tableAlias, pStmt->subSTbName); strcpy(realTable->table.tableAlias, pStmt->subSTbName);
*pSelect = createSelectStmtImpl(true, pProjection, (SNode*)realTable); *pSelect = createSelectStmtImpl(true, pProjection, (SNode*)realTable, NULL);
((SSelectStmt*)*pSelect)->pWhere = nodesCloneNode(pStmt->pWhere); ((SSelectStmt*)*pSelect)->pWhere = nodesCloneNode(pStmt->pWhere);
pCxt->pParseCxt->topicQuery = true; pCxt->pParseCxt->topicQuery = true;
code = translateQuery(pCxt, *pSelect); code = translateQuery(pCxt, *pSelect);

View File

@ -692,7 +692,7 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog
} }
SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable) { SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint) {
SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT); SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
if (NULL == select) { if (NULL == select) {
return NULL; return NULL;
@ -704,6 +704,7 @@ SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode*
select->timeLineResMode = select->isDistinct ? TIME_LINE_NONE : TIME_LINE_GLOBAL; select->timeLineResMode = select->isDistinct ? TIME_LINE_NONE : TIME_LINE_GLOBAL;
select->onlyHasKeepOrderFunc = true; select->onlyHasKeepOrderFunc = true;
select->timeRange = TSWINDOW_INITIALIZER; select->timeRange = TSWINDOW_INITIALIZER;
select->pHint = pHint;
return (SNode*)select; return (SNode*)select;
} }
@ -1157,3 +1158,5 @@ int64_t int64SafeSub(int64_t a, int64_t b) {
} }
return res; return res;
} }

File diff suppressed because it is too large Load Diff

View File

@ -45,6 +45,7 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryP
bool isPartTableAgg(SAggLogicNode* pAgg); bool isPartTableAgg(SAggLogicNode* pAgg);
bool isPartTableWinodw(SWindowLogicNode* pWindow); bool isPartTableWinodw(SWindowLogicNode* pWindow);
bool getBatchScanOptionFromHint(SNodeList* pList);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -435,6 +435,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
} }
pJoin->joinType = pJoinTable->joinType; pJoin->joinType = pJoinTable->joinType;
pJoin->joinAlgo = JOIN_ALGO_UNKNOWN;
pJoin->isSingleTableJoin = pJoinTable->table.singleTable; pJoin->isSingleTableJoin = pJoinTable->table.singleTable;
pJoin->hasSubQuery = pJoinTable->hasSubQuery; pJoin->hasSubQuery = pJoinTable->hasSubQuery;
pJoin->node.inputTsOrder = ORDER_ASC; pJoin->node.inputTsOrder = ORDER_ASC;

View File

@ -930,6 +930,7 @@ static int32_t pushDownCondOptDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* p
if (pJoin->joinAlgo != JOIN_ALGO_UNKNOWN) { if (pJoin->joinAlgo != JOIN_ALGO_UNKNOWN) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
pJoin->joinAlgo = JOIN_ALGO_MERGE;
if (NULL == pJoin->node.pConditions) { if (NULL == pJoin->node.pConditions) {
int32_t code = pushDownCondOptJoinExtractCond(pCxt, pJoin); int32_t code = pushDownCondOptJoinExtractCond(pCxt, pJoin);
@ -3328,7 +3329,7 @@ static int32_t stbJoinOptCreateTableScanNodes(SLogicNode* pJoin, SNodeList** ppL
return code; return code;
} }
static int32_t stbJoinOptCreateGroupCacheNode(SNodeList* pChildren, SLogicNode** ppLogic) { static int32_t stbJoinOptCreateGroupCacheNode(SOptimizeContext* pCxt, SNodeList* pChildren, SLogicNode** ppLogic) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SGroupCacheLogicNode* pGrpCache = (SGroupCacheLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_GROUP_CACHE); SGroupCacheLogicNode* pGrpCache = (SGroupCacheLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_GROUP_CACHE);
if (NULL == pGrpCache) { if (NULL == pGrpCache) {
@ -3338,7 +3339,7 @@ static int32_t stbJoinOptCreateGroupCacheNode(SNodeList* pChildren, SLogicNode**
//pGrpCache->node.dynamicOp = true; //pGrpCache->node.dynamicOp = true;
pGrpCache->grpColsMayBeNull = false; pGrpCache->grpColsMayBeNull = false;
pGrpCache->grpByUid = true; pGrpCache->grpByUid = true;
pGrpCache->batchFetch = false; pGrpCache->batchFetch = getBatchScanOptionFromHint(((SSelectStmt*)pCxt->pPlanCxt->pAstRoot)->pHint);
pGrpCache->node.pChildren = pChildren; pGrpCache->node.pChildren = pChildren;
pGrpCache->node.pTargets = nodesMakeList(); pGrpCache->node.pTargets = nodesMakeList();
if (NULL == pGrpCache->node.pTargets) { if (NULL == pGrpCache->node.pTargets) {
@ -3435,8 +3436,7 @@ static int32_t stbJoinOptCreateMergeJoinNode(SLogicNode* pOrig, SLogicNode* pChi
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t stbJoinOptCreateDynQueryCtrlNode(SOptimizeContext* pCxt, SLogicNode* pPrev, SLogicNode* pPost, bool* srcScan, SLogicNode** ppDynNode) {
static int32_t stbJoinOptCreateDynQueryCtrlNode(SLogicNode* pPrev, SLogicNode* pPost, bool* srcScan, SLogicNode** ppDynNode) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SDynQueryCtrlLogicNode* pDynCtrl = (SDynQueryCtrlLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL); SDynQueryCtrlLogicNode* pDynCtrl = (SDynQueryCtrlLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL);
if (NULL == pDynCtrl) { if (NULL == pDynCtrl) {
@ -3444,7 +3444,7 @@ static int32_t stbJoinOptCreateDynQueryCtrlNode(SLogicNode* pPrev, SLogicNode* p
} }
pDynCtrl->qType = DYN_QTYPE_STB_HASH; pDynCtrl->qType = DYN_QTYPE_STB_HASH;
pDynCtrl->stbJoin.batchFetch = false; pDynCtrl->stbJoin.batchFetch = getBatchScanOptionFromHint(((SSelectStmt*)pCxt->pPlanCxt->pAstRoot)->pHint);
memcpy(pDynCtrl->stbJoin.srcScan, srcScan, sizeof(pDynCtrl->stbJoin.srcScan)); memcpy(pDynCtrl->stbJoin.srcScan, srcScan, sizeof(pDynCtrl->stbJoin.srcScan));
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -3510,13 +3510,13 @@ static int32_t stbJoinOptRewriteStableJoin(SOptimizeContext* pCxt, SLogicNode* p
code = stbJoinOptCreateTableScanNodes(pJoin, &pTbScanNodes, srcScan); code = stbJoinOptCreateTableScanNodes(pJoin, &pTbScanNodes, srcScan);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = stbJoinOptCreateGroupCacheNode(pTbScanNodes, &pGrpCacheNode); code = stbJoinOptCreateGroupCacheNode(pCxt, pTbScanNodes, &pGrpCacheNode);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = stbJoinOptCreateMergeJoinNode(pJoin, pGrpCacheNode, &pMJoinNode); code = stbJoinOptCreateMergeJoinNode(pJoin, pGrpCacheNode, &pMJoinNode);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = stbJoinOptCreateDynQueryCtrlNode(pHJoinNode, pMJoinNode, srcScan, &pDynNode); code = stbJoinOptCreateDynQueryCtrlNode(pCxt, pHJoinNode, pMJoinNode, srcScan, &pDynNode);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = replaceLogicNode(pLogicSubplan, pJoin, (SLogicNode*)pDynNode); code = replaceLogicNode(pLogicSubplan, pJoin, (SLogicNode*)pDynNode);

View File

@ -374,4 +374,21 @@ bool isPartTableWinodw(SWindowLogicNode* pWindow) {
return stbHasPartTbname(stbSplGetPartKeys((SLogicNode*)nodesListGetNode(pWindow->node.pChildren, 0))); return stbHasPartTbname(stbSplGetPartKeys((SLogicNode*)nodesListGetNode(pWindow->node.pChildren, 0)));
} }
bool getBatchScanOptionFromHint(SNodeList* pList) {
SNode* pNode = NULL;
bool batchScan = true;
FOREACH(pNode, pList) {
SHintNode* pHint = (SHintNode*)pNode;
if (pHint->option == HINT_BATCH_SCAN) {
batchScan = true;
break;
} else if (pHint->option == HINT_NO_BATCH_SCAN) {
batchScan = false;
break;
}
}
return batchScan;
}