parAstParser.c 33.2 KB
Newer Older
X
Xiaoyu Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

16
#include "functionMgt.h"
wafwerar's avatar
wafwerar 已提交
17
#include "os.h"
X
Xiaoyu Wang 已提交
18
#include "parAst.h"
19
#include "parInt.h"
X
Xiaoyu Wang 已提交
20
#include "parToken.h"
21
#include "systable.h"
X
Xiaoyu Wang 已提交
22
#include "tglobal.h"
X
Xiaoyu Wang 已提交
23 24 25 26

typedef void* (*FMalloc)(size_t);
typedef void (*FFree)(void*);

X
Xiaoyu Wang 已提交
27
extern void* ParseAlloc(FMalloc);
X
Xiaoyu Wang 已提交
28 29 30
extern void  Parse(void*, int, SToken, void*);
extern void  ParseFree(void*, FFree);
extern void  ParseTrace(FILE*, char*);
X
Xiaoyu Wang 已提交
31

X
Xiaoyu Wang 已提交
32
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
33 34
  SAstCreateContext cxt;
  initAstCreateContext(pParseCxt, &cxt);
X
Xiaoyu Wang 已提交
35
  void*   pParser = ParseAlloc((FMalloc)taosMemoryMalloc);
X
Xiaoyu Wang 已提交
36 37 38 39
  int32_t i = 0;
  while (1) {
    SToken t0 = {0};
    if (cxt.pQueryCxt->pSql[i] == 0) {
X
Xiaoyu Wang 已提交
40
      Parse(pParser, 0, t0, &cxt);
X
Xiaoyu Wang 已提交
41 42
      goto abort_parse;
    }
X
Xiaoyu Wang 已提交
43 44
    t0.n = tGetToken((char*)&cxt.pQueryCxt->pSql[i], &t0.type);
    t0.z = (char*)(cxt.pQueryCxt->pSql + i);
X
Xiaoyu Wang 已提交
45 46 47
    i += t0.n;

    switch (t0.type) {
48 49
      case TK_NK_SPACE:
      case TK_NK_COMMENT: {
X
Xiaoyu Wang 已提交
50 51
        break;
      }
52
      case TK_NK_SEMI: {
X
Xiaoyu Wang 已提交
53
        Parse(pParser, 0, t0, &cxt);
54 55
        goto abort_parse;
      }
56
      case TK_NK_ILLEGAL: {
X
Xiaoyu Wang 已提交
57
        snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unrecognized token: \"%s\"", t0.z);
58
        cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
X
Xiaoyu Wang 已提交
59 60
        goto abort_parse;
      }
61 62 63
      case TK_NK_HEX:
      case TK_NK_OCT:
      case TK_NK_BIN: {
X
Xiaoyu Wang 已提交
64
        snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unsupported token: \"%s\"", t0.z);
65
        cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
X
Xiaoyu Wang 已提交
66 67 68
        goto abort_parse;
      }
      default:
X
Xiaoyu Wang 已提交
69
        // ParseTrace(stdout, "");
X
Xiaoyu Wang 已提交
70
        Parse(pParser, t0.type, t0, &cxt);
71
        if (TSDB_CODE_SUCCESS != cxt.errCode) {
X
Xiaoyu Wang 已提交
72 73 74 75 76 77
          goto abort_parse;
        }
    }
  }

abort_parse:
wafwerar's avatar
wafwerar 已提交
78
  ParseFree(pParser, (FFree)taosMemoryFree);
79
  if (TSDB_CODE_SUCCESS == cxt.errCode) {
80
    *pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
81 82 83
    if (NULL == *pQuery) {
      return TSDB_CODE_OUT_OF_MEMORY;
    }
84
    (*pQuery)->pRoot = cxt.pRootNode;
D
dapan1121 已提交
85
    (*pQuery)->placeholderNum = cxt.placeholderNo;
X
Xiaoyu Wang 已提交
86
    TSWAP((*pQuery)->pPlaceholderValues, cxt.pPlaceholderValues);
X
Xiaoyu Wang 已提交
87
    (*pQuery)->execStage = QUERY_EXEC_STAGE_ANALYSE;
X
Xiaoyu Wang 已提交
88
  }
X
Xiaoyu Wang 已提交
89
  taosArrayDestroy(cxt.pPlaceholderValues);
90
  return cxt.errCode;
X
Xiaoyu Wang 已提交
91
}
92 93 94 95

typedef struct SCollectMetaKeyCxt {
  SParseContext*   pParseCxt;
  SParseMetaCache* pMetaCache;
X
Xiaoyu Wang 已提交
96
  SNode*           pStmt;
97 98 99 100
} SCollectMetaKeyCxt;

typedef struct SCollectMetaKeyFromExprCxt {
  SCollectMetaKeyCxt* pComCxt;
X
Xiaoyu Wang 已提交
101
  bool                hasLastRowOrLast;
102 103 104 105 106
  int32_t             errCode;
} SCollectMetaKeyFromExprCxt;

static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt);

107
static EDealRes collectMetaKeyFromFunction(SCollectMetaKeyFromExprCxt* pCxt, SFunctionNode* pFunc) {
X
Xiaoyu Wang 已提交
108 109
  switch (fmGetFuncType(pFunc->functionName)) {
    case FUNCTION_TYPE_LAST_ROW:
X
Xiaoyu Wang 已提交
110 111
    case FUNCTION_TYPE_LAST:
      pCxt->hasLastRowOrLast = true;
X
Xiaoyu Wang 已提交
112 113 114 115 116 117
      break;
    case FUNCTION_TYPE_UDF:
      pCxt->errCode = reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache);
      break;
    default:
      break;
118
  }
X
Xiaoyu Wang 已提交
119
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
120 121
}

X
Xiaoyu Wang 已提交
122
static bool needGetTableIndex(SNode* pStmt) {
X
Xiaoyu Wang 已提交
123
  if (QUERY_SMA_OPTIMIZE_ENABLE == tsQuerySmaOptimize && QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
X
Xiaoyu Wang 已提交
124 125 126 127 128 129
    SSelectStmt* pSelect = (SSelectStmt*)pStmt;
    return (NULL != pSelect->pWindow && QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow));
  }
  return false;
}

130
static int32_t collectMetaKeyFromInsTagsImpl(SCollectMetaKeyCxt* pCxt, SName* pName) {
X
Xiaoyu Wang 已提交
131 132 133
  if (0 == pName->type) {
    return TSDB_CODE_SUCCESS;
  }
134 135 136 137 138 139 140 141 142
  if (TSDB_DB_NAME_T == pName->type) {
    return reserveDbVgInfoInCache(pName->acctId, pName->dbname, pCxt->pMetaCache);
  }
  return reserveTableVgroupInCacheExt(pName, pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromInsTags(SCollectMetaKeyCxt* pCxt) {
  SSelectStmt* pSelect = (SSelectStmt*)pCxt->pStmt;
  SName        name = {0};
X
Xiaoyu Wang 已提交
143
  int32_t      code = getVnodeSysTableTargetName(pCxt->pParseCxt->acctId, pSelect->pWhere, &name);
144 145 146 147 148 149
  if (TSDB_CODE_SUCCESS == code) {
    code = collectMetaKeyFromInsTagsImpl(pCxt, &name);
  }
  return code;
}

150
static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const char* pDb, const char* pTable,
X
Xiaoyu Wang 已提交
151
                                               AUTH_TYPE authType) {
152
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
X
Xiaoyu Wang 已提交
153
  if (TSDB_CODE_SUCCESS == code) {
154
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
155
  }
X
Xiaoyu Wang 已提交
156
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
157 158
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, pTable, authType,
                                  pCxt->pMetaCache);
159
  }
X
Xiaoyu Wang 已提交
160
  if (TSDB_CODE_SUCCESS == code) {
161
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
X
Xiaoyu Wang 已提交
162
  }
X
Xiaoyu Wang 已提交
163
  if (TSDB_CODE_SUCCESS == code && needGetTableIndex(pCxt->pStmt)) {
164
    code = reserveTableIndexInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
X
Xiaoyu Wang 已提交
165
  }
166
  if (TSDB_CODE_SUCCESS == code && (0 == strcmp(pTable, TSDB_INS_TABLE_DNODE_VARIABLES))) {
D
dapan1121 已提交
167 168
    code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
  }
X
Xiaoyu Wang 已提交
169
  if (TSDB_CODE_SUCCESS == code &&
170 171
      (0 == strcmp(pTable, TSDB_INS_TABLE_TAGS) || 0 == strcmp(pTable, TSDB_INS_TABLE_TABLES) ||
       0 == strcmp(pTable, TSDB_INS_TABLE_COLS)) &&
172 173 174
      QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
    code = collectMetaKeyFromInsTags(pCxt);
  }
X
Xiaoyu Wang 已提交
175 176 177 178
  return code;
}

static EDealRes collectMetaKeyFromRealTable(SCollectMetaKeyFromExprCxt* pCxt, SRealTableNode* pRealTable) {
179 180
  pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, pRealTable->table.dbName, pRealTable->table.tableName,
                                                  AUTH_TYPE_READ);
181 182 183 184 185 186 187 188 189 190 191 192
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
}

static EDealRes collectMetaKeyFromTempTable(SCollectMetaKeyFromExprCxt* pCxt, STempTableNode* pTempTable) {
  pCxt->errCode = collectMetaKeyFromQuery(pCxt->pComCxt, pTempTable->pSubquery);
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
}

static EDealRes collectMetaKeyFromExprImpl(SNode* pNode, void* pContext) {
  SCollectMetaKeyFromExprCxt* pCxt = pContext;
  switch (nodeType(pNode)) {
    case QUERY_NODE_FUNCTION:
193
      return collectMetaKeyFromFunction(pCxt, (SFunctionNode*)pNode);
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
    case QUERY_NODE_REAL_TABLE:
      return collectMetaKeyFromRealTable(pCxt, (SRealTableNode*)pNode);
    case QUERY_NODE_TEMP_TABLE:
      return collectMetaKeyFromTempTable(pCxt, (STempTableNode*)pNode);
    default:
      break;
  }
  return DEAL_RES_CONTINUE;
}

static int32_t collectMetaKeyFromExprs(SCollectMetaKeyCxt* pCxt, SNodeList* pList) {
  SCollectMetaKeyFromExprCxt cxt = {.pComCxt = pCxt, .errCode = TSDB_CODE_SUCCESS};
  nodesWalkExprs(pList, collectMetaKeyFromExprImpl, &cxt);
  return cxt.errCode;
}

static int32_t collectMetaKeyFromSetOperator(SCollectMetaKeyCxt* pCxt, SSetOperator* pStmt) {
  int32_t code = collectMetaKeyFromQuery(pCxt, pStmt->pLeft);
  if (TSDB_CODE_SUCCESS == code) {
    code = collectMetaKeyFromQuery(pCxt, pStmt->pRight);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = collectMetaKeyFromExprs(pCxt, pStmt->pOrderByList);
  }
  return code;
}

X
Xiaoyu Wang 已提交
221 222 223 224 225 226 227
static int32_t reserveDbCfgForLastRow(SCollectMetaKeyCxt* pCxt, SNode* pTable) {
  if (NULL == pTable || QUERY_NODE_REAL_TABLE != nodeType(pTable)) {
    return TSDB_CODE_SUCCESS;
  }
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SRealTableNode*)pTable)->table.dbName, pCxt->pMetaCache);
}

228
static int32_t collectMetaKeyFromSelect(SCollectMetaKeyCxt* pCxt, SSelectStmt* pStmt) {
X
Xiaoyu Wang 已提交
229
  SCollectMetaKeyFromExprCxt cxt = {.pComCxt = pCxt, .hasLastRowOrLast = false, .errCode = TSDB_CODE_SUCCESS};
230
  nodesWalkSelectStmt(pStmt, SQL_CLAUSE_FROM, collectMetaKeyFromExprImpl, &cxt);
X
Xiaoyu Wang 已提交
231
  if (TSDB_CODE_SUCCESS == cxt.errCode && cxt.hasLastRowOrLast) {
X
Xiaoyu Wang 已提交
232 233
    cxt.errCode = reserveDbCfgForLastRow(pCxt, pStmt->pFromTable);
  }
234 235 236
  return cxt.errCode;
}

X
Xiaoyu Wang 已提交
237 238 239 240
static int32_t collectMetaKeyFromAlterDatabase(SCollectMetaKeyCxt* pCxt, SAlterDatabaseStmt* pStmt) {
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
}

X
Xiaoyu Wang 已提交
241 242 243 244
static int32_t collectMetaKeyFromFlushDatabase(SCollectMetaKeyCxt* pCxt, SFlushDatabaseStmt* pStmt) {
  return reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
}

245
static int32_t collectMetaKeyFromCreateTable(SCollectMetaKeyCxt* pCxt, SCreateTableStmt* pStmt) {
X
Xiaoyu Wang 已提交
246 247 248
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
  if (TSDB_CODE_SUCCESS == code && NULL == pStmt->pTags) {
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
249
  }
X
Xiaoyu Wang 已提交
250
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
251
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, AUTH_TYPE_WRITE,
X
Xiaoyu Wang 已提交
252 253
                                  pCxt->pMetaCache);
  }
X
Xiaoyu Wang 已提交
254
  return code;
255 256
}

X
Xiaoyu Wang 已提交
257
static int32_t collectMetaKeyFromCreateMultiTable(SCollectMetaKeyCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
258 259 260 261
  int32_t code = TSDB_CODE_SUCCESS;
  SNode*  pNode = NULL;
  FOREACH(pNode, pStmt->pSubTables) {
    SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
X
Xiaoyu Wang 已提交
262 263 264 265 266
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
    if (TSDB_CODE_SUCCESS == code) {
      code =
          reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pClause->useTableName, pCxt->pMetaCache);
    }
267 268 269
    if (TSDB_CODE_SUCCESS == code) {
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
    }
X
Xiaoyu Wang 已提交
270
    if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
271 272
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL,
                                    AUTH_TYPE_WRITE, pCxt->pMetaCache);
X
Xiaoyu Wang 已提交
273
    }
274 275 276 277 278 279 280
    if (TSDB_CODE_SUCCESS != code) {
      break;
    }
  }
  return code;
}

X
Xiaoyu Wang 已提交
281 282 283 284 285 286 287 288 289
static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) {
  int32_t code = TSDB_CODE_SUCCESS;
  SNode*  pNode = NULL;
  FOREACH(pNode, pStmt->pTables) {
    SDropTableClause* pClause = (SDropTableClause*)pNode;
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
    if (TSDB_CODE_SUCCESS == code) {
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
    }
X
Xiaoyu Wang 已提交
290 291 292 293
    if (TSDB_CODE_SUCCESS == code) {
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
                                    pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache);
    }
X
Xiaoyu Wang 已提交
294 295 296 297 298 299 300
    if (TSDB_CODE_SUCCESS != code) {
      break;
    }
  }
  return code;
}

X
Xiaoyu Wang 已提交
301 302 303 304 305
static int32_t collectMetaKeyFromDropStable(SCollectMetaKeyCxt* pCxt, SDropSuperTableStmt* pStmt) {
  return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
                                AUTH_TYPE_WRITE, pCxt->pMetaCache);
}

306
static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
307 308 309 310
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
  }
311 312 313
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
  }
X
Xiaoyu Wang 已提交
314 315 316 317
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
                                  AUTH_TYPE_WRITE, pCxt->pMetaCache);
  }
318 319 320
  return code;
}

321
static int32_t collectMetaKeyFromAlterStable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
322 323 324 325
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
  }
X
Xiaoyu Wang 已提交
326 327 328 329
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
                                  AUTH_TYPE_WRITE, pCxt->pMetaCache);
  }
330
  return code;
331 332
}

333 334 335 336
static int32_t collectMetaKeyFromUseDatabase(SCollectMetaKeyCxt* pCxt, SUseDatabaseStmt* pStmt) {
  return reserveDbVgVersionInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
}

337 338 339
static int32_t collectMetaKeyFromCreateIndex(SCollectMetaKeyCxt* pCxt, SCreateIndexStmt* pStmt) {
  int32_t code = TSDB_CODE_SUCCESS;
  if (INDEX_TYPE_SMA == pStmt->indexType) {
X
Xiaoyu Wang 已提交
340
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
341
    if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
342
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
343
    }
344
    if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
345
      code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
346
    }
347
    if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
348
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
349
    }
350 351 352 353 354 355 356 357
  }
  return code;
}

static int32_t collectMetaKeyFromCreateTopic(SCollectMetaKeyCxt* pCxt, SCreateTopicStmt* pStmt) {
  if (NULL != pStmt->pQuery) {
    return collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
  }
358 359 360 361 362
  if (NULL != pStmt->pWhere) {
    int32_t code = collectMetaKeyFromRealTableImpl(pCxt, pStmt->subDbName, pStmt->subSTbName,
                                                    AUTH_TYPE_READ);
    return code;
  }
363 364 365 366 367 368 369
  return TSDB_CODE_SUCCESS;
}

static int32_t collectMetaKeyFromExplain(SCollectMetaKeyCxt* pCxt, SExplainStmt* pStmt) {
  return collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
}

X
Xiaoyu Wang 已提交
370 371 372 373 374 375 376 377 378 379 380
static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStmt* pStmt) {
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
  strcpy(name.dbname, pStmt->dbName);
  strcpy(name.tname, pStmt->tableName);
  int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
  }
  return code;
}

381
static int32_t collectMetaKeyFromCreateStream(SCollectMetaKeyCxt* pCxt, SCreateStreamStmt* pStmt) {
382 383 384 385 386 387
  int32_t code =
      reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->targetDbName, pStmt->targetTabName, pCxt->pMetaCache);
  if (TSDB_CODE_SUCCESS == code) {
    code = collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
  }
  return code;
388 389 390
}

static int32_t collectMetaKeyFromShowDnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
391 392 393 394 395
  if (pCxt->pParseCxt->enableSysInfo) {
    return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODES,
                                   pCxt->pMetaCache);
  }
  return TSDB_CODE_SUCCESS;
396 397 398
}

static int32_t collectMetaKeyFromShowMnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
399 400 401 402 403
  if (pCxt->pParseCxt->enableSysInfo) {
    return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES,
                                   pCxt->pMetaCache);
  }
  return TSDB_CODE_SUCCESS;
404 405 406
}

static int32_t collectMetaKeyFromShowModules(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
407 408 409 410 411
  if (pCxt->pParseCxt->enableSysInfo) {
    return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MODULES,
                                   pCxt->pMetaCache);
  }
  return TSDB_CODE_SUCCESS;
412 413 414
}

static int32_t collectMetaKeyFromShowQnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
415 416 417 418 419
  if (pCxt->pParseCxt->enableSysInfo) {
    return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES,
                                   pCxt->pMetaCache);
  }
  return TSDB_CODE_SUCCESS;
420 421 422
}

static int32_t collectMetaKeyFromShowSnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
423 424 425 426 427
  if (pCxt->pParseCxt->enableSysInfo) {
    return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SNODES,
                                   pCxt->pMetaCache);
  }
  return TSDB_CODE_SUCCESS;
428 429 430
}

static int32_t collectMetaKeyFromShowBnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
431 432 433 434 435
  if (pCxt->pParseCxt->enableSysInfo) {
    return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_BNODES,
                                   pCxt->pMetaCache);
  }
  return TSDB_CODE_SUCCESS;
436 437
}

438
static int32_t collectMetaKeyFromShowCluster(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
439 440 441 442 443
  if (pCxt->pParseCxt->enableSysInfo) {
    return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CLUSTER,
                                   pCxt->pMetaCache);
  }
  return TSDB_CODE_SUCCESS;
444 445
}

446
static int32_t collectMetaKeyFromShowDatabases(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
D
dapan1121 已提交
447
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DATABASES,
448 449 450 451
                                 pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowFunctions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
D
dapan1121 已提交
452
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_FUNCTIONS,
453 454 455 456
                                 pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowIndexes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
D
dapan1121 已提交
457
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_INDEXES,
458 459 460 461
                                 pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowStables(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
462 463 464
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STABLES,
                                         pCxt->pMetaCache);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
465 466 467
    code =
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
                               NULL, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
468 469
  }
  return code;
470 471 472
}

static int32_t collectMetaKeyFromShowStreams(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
473
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STREAMS,
474 475 476 477
                                 pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowTables(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
478 479
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TABLES,
                                         pCxt->pMetaCache);
480
  if (TSDB_CODE_SUCCESS == code) {
481 482 483
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
484 485 486
    code =
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
                               NULL, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
487 488 489 490
  }
  return code;
}

491
static int32_t collectMetaKeyFromShowTags(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
D
dapan1121 已提交
492
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TAGS,
493
                                         pCxt->pMetaCache);
494
  if (TSDB_CODE_SUCCESS == code) {
495
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
496
  }
497 498 499 500
  if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pTbName) {
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal,
                                     ((SValueNode*)pStmt->pTbName)->literal, pCxt->pMetaCache);
  }
501 502 503
  return code;
}

504
static int32_t collectMetaKeyFromShowStableTags(SCollectMetaKeyCxt* pCxt, SShowTableTagsStmt* pStmt) {
505 506 507 508
  return collectMetaKeyFromRealTableImpl(pCxt, ((SValueNode*)pStmt->pDbName)->literal,
                                         ((SValueNode*)pStmt->pTbName)->literal, AUTH_TYPE_READ);
}

509
static int32_t collectMetaKeyFromShowUsers(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
D
dapan1121 已提交
510
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USERS,
511 512 513 514 515 516 517 518 519
                                 pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowLicence(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_LICENCES,
                                 pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowVgroups(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
X
Xiaoyu Wang 已提交
520 521 522 523 524 525 526
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS,
                                         pCxt->pMetaCache);
  if (TSDB_CODE_SUCCESS == code) {
    // just to verify whether the database exists
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
  }
  return code;
527 528 529
}

static int32_t collectMetaKeyFromShowTopics(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
530
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TOPICS,
531 532 533
                                 pCxt->pMetaCache);
}

534 535 536 537 538
static int32_t collectMetaKeyFromShowConsumers(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONSUMERS,
                                 pCxt->pMetaCache);
}

539 540 541 542 543 544 545 546 547 548
static int32_t collectMetaKeyFromShowConnections(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONNECTIONS,
                                 pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowQueries(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_QUERIES,
                                 pCxt->pMetaCache);
}

D
dapan1121 已提交
549 550 551 552 553
static int32_t collectMetaKeyFromShowVariables(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS,
                                 pCxt->pMetaCache);
}

554 555 556 557 558 559 560 561 562
static int32_t collectMetaKeyFromShowDnodeVariables(SCollectMetaKeyCxt* pCxt, SShowDnodeVariablesStmt* pStmt) {
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
                                         TSDB_INS_TABLE_DNODE_VARIABLES, pCxt->pMetaCache);
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
  }
  return code;
}

563 564 565 566 567
static int32_t collectMetaKeyFromShowVnodes(SCollectMetaKeyCxt* pCxt, SShowVnodesStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VNODES,
                                 pCxt->pMetaCache);
}

568 569 570 571 572
static int32_t collectMetaKeyFromShowUserPrivileges(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_PRIVILEGES,
                                 pCxt->pMetaCache);
}

573 574 575 576 577
static int32_t collectMetaKeyFromShowCreateDatabase(SCollectMetaKeyCxt* pCxt, SShowCreateDatabaseStmt* pStmt) {
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
}

static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShowCreateTableStmt* pStmt) {
D
dapan1121 已提交
578 579 580 581 582 583 584
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
  strcpy(name.dbname, pStmt->dbName);
  strcpy(name.tname, pStmt->tableName);
  int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveTableCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
  }
X
Xiaoyu Wang 已提交
585 586 587
  if (TSDB_CODE_SUCCESS == code) {
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
  }
588
  if (TSDB_CODE_SUCCESS == code) {
589
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ,
X
Xiaoyu Wang 已提交
590
                                  pCxt->pMetaCache);
591
  }
D
dapan1121 已提交
592
  return code;
593 594
}

D
dapan1121 已提交
595 596 597 598 599
static int32_t collectMetaKeyFromShowApps(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_APPS,
                                 pCxt->pMetaCache);
}

600 601 602 603 604
static int32_t collectMetaKeyFromShowTransactions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_TRANS,
                                 pCxt->pMetaCache);
}

X
Xiaoyu Wang 已提交
605
static int32_t collectMetaKeyFromDelete(SCollectMetaKeyCxt* pCxt, SDeleteStmt* pStmt) {
606 607
  STableNode* pTable = (STableNode*)pStmt->pFromTable;
  return collectMetaKeyFromRealTableImpl(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE);
X
Xiaoyu Wang 已提交
608 609
}

610
static int32_t collectMetaKeyFromInsert(SCollectMetaKeyCxt* pCxt, SInsertStmt* pStmt) {
611 612
  STableNode* pTable = (STableNode*)pStmt->pTable;
  int32_t     code = collectMetaKeyFromRealTableImpl(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE);
613 614 615 616 617 618
  if (TSDB_CODE_SUCCESS == code) {
    code = collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
  }
  return code;
}

619 620 621 622 623 624
static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTableDistributedStmt* pStmt) {
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
  strcpy(name.dbname, pStmt->dbName);
  strcpy(name.tname, pStmt->tableName);
  int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
  if (TSDB_CODE_SUCCESS == code) {
625
    code = collectMetaKeyFromRealTableImpl(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ);
626
  }
627 628 629
  return code;
}

630
static int32_t collectMetaKeyFromShowSubscriptions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
631
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SUBSCRIPTIONS,
632 633 634
                                 pCxt->pMetaCache);
}

635 636 637 638
static int32_t collectMetaKeyFromCompactDatabase(SCollectMetaKeyCxt* pCxt, SCompactDatabaseStmt* pStmt) {
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
}

639 640 641 642 643 644 645
static int32_t collectMetaKeyFromGrant(SCollectMetaKeyCxt* pCxt, SGrantStmt* pStmt) {
  if ('\0' == pStmt->tabName[0]) {
    return TSDB_CODE_SUCCESS;
  }
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
}

646
static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
X
Xiaoyu Wang 已提交
647
  pCxt->pStmt = pStmt;
648 649 650 651 652
  switch (nodeType(pStmt)) {
    case QUERY_NODE_SET_OPERATOR:
      return collectMetaKeyFromSetOperator(pCxt, (SSetOperator*)pStmt);
    case QUERY_NODE_SELECT_STMT:
      return collectMetaKeyFromSelect(pCxt, (SSelectStmt*)pStmt);
X
Xiaoyu Wang 已提交
653 654
    case QUERY_NODE_ALTER_DATABASE_STMT:
      return collectMetaKeyFromAlterDatabase(pCxt, (SAlterDatabaseStmt*)pStmt);
X
Xiaoyu Wang 已提交
655 656
    case QUERY_NODE_FLUSH_DATABASE_STMT:
      return collectMetaKeyFromFlushDatabase(pCxt, (SFlushDatabaseStmt*)pStmt);
657 658
    case QUERY_NODE_CREATE_TABLE_STMT:
      return collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt);
X
Xiaoyu Wang 已提交
659 660
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
      return collectMetaKeyFromCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
X
Xiaoyu Wang 已提交
661 662
    case QUERY_NODE_DROP_TABLE_STMT:
      return collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
X
Xiaoyu Wang 已提交
663 664
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
      return collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
665 666
    case QUERY_NODE_ALTER_TABLE_STMT:
      return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
667 668
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
      return collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt);
669
    case QUERY_NODE_USE_DATABASE_STMT:
670
      return collectMetaKeyFromUseDatabase(pCxt, (SUseDatabaseStmt*)pStmt);
671 672 673 674 675 676
    case QUERY_NODE_CREATE_INDEX_STMT:
      return collectMetaKeyFromCreateIndex(pCxt, (SCreateIndexStmt*)pStmt);
    case QUERY_NODE_CREATE_TOPIC_STMT:
      return collectMetaKeyFromCreateTopic(pCxt, (SCreateTopicStmt*)pStmt);
    case QUERY_NODE_EXPLAIN_STMT:
      return collectMetaKeyFromExplain(pCxt, (SExplainStmt*)pStmt);
X
Xiaoyu Wang 已提交
677 678
    case QUERY_NODE_DESCRIBE_STMT:
      return collectMetaKeyFromDescribe(pCxt, (SDescribeStmt*)pStmt);
679 680
    case QUERY_NODE_COMPACT_DATABASE_STMT:
      return collectMetaKeyFromCompactDatabase(pCxt, (SCompactDatabaseStmt*)pStmt);
681 682
    case QUERY_NODE_CREATE_STREAM_STMT:
      return collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
683 684
    case QUERY_NODE_GRANT_STMT:
      return collectMetaKeyFromGrant(pCxt, (SGrantStmt*)pStmt);
685 686 687 688 689 690 691 692 693 694 695 696
    case QUERY_NODE_SHOW_DNODES_STMT:
      return collectMetaKeyFromShowDnodes(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_MNODES_STMT:
      return collectMetaKeyFromShowMnodes(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_MODULES_STMT:
      return collectMetaKeyFromShowModules(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_QNODES_STMT:
      return collectMetaKeyFromShowQnodes(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_SNODES_STMT:
      return collectMetaKeyFromShowSnodes(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_BNODES_STMT:
      return collectMetaKeyFromShowBnodes(pCxt, (SShowStmt*)pStmt);
697 698
    case QUERY_NODE_SHOW_CLUSTER_STMT:
      return collectMetaKeyFromShowCluster(pCxt, (SShowStmt*)pStmt);
699 700 701 702 703 704 705 706 707 708 709 710
    case QUERY_NODE_SHOW_DATABASES_STMT:
      return collectMetaKeyFromShowDatabases(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
      return collectMetaKeyFromShowFunctions(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_INDEXES_STMT:
      return collectMetaKeyFromShowIndexes(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_STABLES_STMT:
      return collectMetaKeyFromShowStables(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_STREAMS_STMT:
      return collectMetaKeyFromShowStreams(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_TABLES_STMT:
      return collectMetaKeyFromShowTables(pCxt, (SShowStmt*)pStmt);
711 712
    case QUERY_NODE_SHOW_TAGS_STMT:
      return collectMetaKeyFromShowTags(pCxt, (SShowStmt*)pStmt);
713
    case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
714
      return collectMetaKeyFromShowStableTags(pCxt, (SShowTableTagsStmt*)pStmt);
715 716
    case QUERY_NODE_SHOW_USERS_STMT:
      return collectMetaKeyFromShowUsers(pCxt, (SShowStmt*)pStmt);
X
Xiaoyu Wang 已提交
717
    case QUERY_NODE_SHOW_LICENCES_STMT:
718 719 720 721 722
      return collectMetaKeyFromShowLicence(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_VGROUPS_STMT:
      return collectMetaKeyFromShowVgroups(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_TOPICS_STMT:
      return collectMetaKeyFromShowTopics(pCxt, (SShowStmt*)pStmt);
723 724
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
      return collectMetaKeyFromShowConsumers(pCxt, (SShowStmt*)pStmt);
725 726 727 728
    case QUERY_NODE_SHOW_CONNECTIONS_STMT:
      return collectMetaKeyFromShowConnections(pCxt, (SShowStmt*)pStmt);
    case QUERY_NODE_SHOW_QUERIES_STMT:
      return collectMetaKeyFromShowQueries(pCxt, (SShowStmt*)pStmt);
729
    case QUERY_NODE_SHOW_VARIABLES_STMT:
D
dapan1121 已提交
730
      return collectMetaKeyFromShowVariables(pCxt, (SShowStmt*)pStmt);
731 732
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
      return collectMetaKeyFromShowDnodeVariables(pCxt, (SShowDnodeVariablesStmt*)pStmt);
733 734
    case QUERY_NODE_SHOW_VNODES_STMT:
      return collectMetaKeyFromShowVnodes(pCxt, (SShowVnodesStmt*)pStmt);
735 736
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
      return collectMetaKeyFromShowUserPrivileges(pCxt, (SShowStmt*)pStmt);
737 738 739 740 741
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
      return collectMetaKeyFromShowCreateDatabase(pCxt, (SShowCreateDatabaseStmt*)pStmt);
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
      return collectMetaKeyFromShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
D
dapan1121 已提交
742 743
    case QUERY_NODE_SHOW_APPS_STMT:
      return collectMetaKeyFromShowApps(pCxt, (SShowStmt*)pStmt);
744 745
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
      return collectMetaKeyFromShowTransactions(pCxt, (SShowStmt*)pStmt);
X
Xiaoyu Wang 已提交
746 747
    case QUERY_NODE_DELETE_STMT:
      return collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt);
748 749
    case QUERY_NODE_INSERT_STMT:
      return collectMetaKeyFromInsert(pCxt, (SInsertStmt*)pStmt);
750 751
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
      return collectMetaKeyFromShowBlockDist(pCxt, (SShowTableDistributedStmt*)pStmt);
752 753
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
      return collectMetaKeyFromShowSubscriptions(pCxt, (SShowStmt*)pStmt);
754 755 756 757 758 759
    default:
      break;
  }
  return TSDB_CODE_SUCCESS;
}

760 761 762
int32_t collectMetaKey(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
  SCollectMetaKeyCxt cxt = {.pParseCxt = pParseCxt, .pMetaCache = pMetaCache, .pStmt = pQuery->pRoot};
  return collectMetaKeyFromQuery(&cxt, pQuery->pRoot);
763
}