• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #5044

06 May 2026 02:35AM UTC coverage: 73.169% (+0.06%) from 73.107%
#5044

push

travis-ci

web-flow
feat: [6659794715] cpu limit (#35153)

244 of 275 new or added lines in 23 files covered. (88.73%)

526 existing lines in 141 files now uncovered.

277745 of 379596 relevant lines covered (73.17%)

133740972.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

16
#include "cmdnodes.h"
17
#include "functionMgt.h"
18
#include "os.h"
19
#include "parAst.h"
20
#include "parInt.h"
21
#include "parToken.h"
22
#include "systable.h"
23
#include "tglobal.h"
24
#include "tmsg.h"
25

26
typedef void* (*FMalloc)(size_t);
27
typedef void (*FFree)(void*);
28

29
extern SConfig* tsCfg;
30

31
extern void* ParseAlloc(FMalloc);
32
extern void  Parse(void*, int, SToken, void*);
33
extern void  ParseFree(void*, FFree);
34
extern void  ParseTrace(FILE*, char*);
35

36
int32_t buildQueryAfterParse(SQuery** pQuery, SNode* pRootNode, int16_t placeholderNo, SArray** pPlaceholderValues) {
480,178,110✔
37
  *pQuery = NULL;
480,178,110✔
38
  int32_t code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)pQuery);
480,185,806✔
39
  if (NULL == *pQuery) {
480,211,199✔
40
    return code;
×
41
  }
42
  (*pQuery)->pRoot = pRootNode;
480,211,218✔
43
  (*pQuery)->placeholderNum = placeholderNo;
480,208,792✔
44
  TSWAP((*pQuery)->pPlaceholderValues, *pPlaceholderValues);
480,203,172✔
45
  (*pQuery)->execStage = QUERY_EXEC_STAGE_ANALYSE;
480,195,026✔
46

47
  return TSDB_CODE_SUCCESS;
480,191,730✔
48
}
49

50
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
494,452,191✔
51
  SAstCreateContext cxt;
284,380,985✔
52
  initAstCreateContext(pParseCxt, &cxt);
494,453,143✔
53
  void* pParser = ParseAlloc((FMalloc)taosMemMalloc);
494,447,008✔
54
  if (!pParser) return terrno;
494,467,311✔
55
  int32_t i = 0;
494,467,311✔
56
  while (1) {
2,147,483,647✔
57
    SToken t0 = {0};
2,147,483,647✔
58
    if (cxt.pQueryCxt->pSql[i] == 0) {
2,147,483,647✔
59
      Parse(pParser, 0, t0, &cxt);
183,118,708✔
60
      goto abort_parse;
396,557,577✔
61
    }
62
    if (!pParseCxt->hasDupQuoteChar) {
2,147,483,647✔
63
      char dupQuoteChar = 0;
2,147,483,647✔
64
      t0.n = tGetToken((char*)&cxt.pQueryCxt->pSql[i], &t0.type, &dupQuoteChar);
2,147,483,647✔
65
      if (dupQuoteChar) pParseCxt->hasDupQuoteChar = true;
2,147,483,647✔
66
    } else {
67
      t0.n = tGetToken((char*)&cxt.pQueryCxt->pSql[i], &t0.type, NULL);
833,493✔
68
    }
69
    t0.z = (char*)(cxt.pQueryCxt->pSql + i);
2,147,483,647✔
70
    i += t0.n;
2,147,483,647✔
71

72
    switch (t0.type) {
2,147,483,647✔
73
      case TK_NK_SPACE:
2,147,483,647✔
74
      case TK_NK_COMMENT: {
75
        break;
2,147,483,647✔
76
      }
77
      case TK_NK_SEMI: {
297,779,179✔
78
        Parse(pParser, 0, t0, &cxt);
297,779,179✔
79
        goto abort_parse;
297,771,440✔
80
      }
81
      case TK_NK_ILLEGAL: {
236,103✔
82
        snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unrecognized token: \"%s\"", t0.z);
236,103✔
83
        cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
236,103✔
84
        goto abort_parse;
236,103✔
85
      }
86
      case TK_NK_OCT: {
×
87
        snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unsupported token: \"%s\"", t0.z);
×
88
        cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
×
89
        goto abort_parse;
×
90
      }
91
      default:
2,147,483,647✔
92
        // ParseTrace(stdout, "");
93
        Parse(pParser, t0.type, t0, &cxt);
2,147,483,647✔
94
        if (TSDB_CODE_SUCCESS != cxt.errCode) {
2,147,483,647✔
95
          goto abort_parse;
17,758,297✔
96
        }
97
    }
98
  }
99

100
abort_parse:
498,852,753✔
101
  ParseFree(pParser, (FFree)taosAutoMemoryFree);
498,864,322✔
102
  if (TSDB_CODE_SUCCESS == cxt.errCode) {
494,443,232✔
103
    int32_t code = buildQueryAfterParse(pQuery, cxt.pRootNode, cxt.placeholderNo, &cxt.pPlaceholderValues);
480,190,442✔
104
    if (TSDB_CODE_SUCCESS != code) {
480,178,900✔
105
      return code;
×
106
    }
107
  }
108
  taosArrayDestroy(cxt.pPlaceholderValues);
494,431,690✔
109
  return cxt.errCode;
494,425,351✔
110
}
111

112
typedef struct SCollectMetaKeyCxt {
113
  SParseContext*   pParseCxt;
114
  SParseMetaCache* pMetaCache;
115
  SNode*           pStmt;
116
  bool             collectVStbRefDbs;
117
} SCollectMetaKeyCxt;
118

119
typedef struct SCollectMetaKeyFromExprCxt {
120
  SCollectMetaKeyCxt* pComCxt;
121
  bool                hasLastRowOrLast;
122
  bool                tbnameCollect;
123
  int32_t             errCode;
124
} SCollectMetaKeyFromExprCxt;
125

126
static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt);
127
static int32_t collectMetaKeyFromSetOperator(SCollectMetaKeyCxt* pCxt, SSetOperator* pStmt);
128
static int32_t collectMetaKeyFromSelect(SCollectMetaKeyCxt* pCxt, SSelectStmt* pStmt);
129

130
static EDealRes collectMetaKeyFromFunction(SCollectMetaKeyFromExprCxt* pCxt, SFunctionNode* pFunc) {
633,566,565✔
131
  switch (fmGetFuncType(pFunc->functionName)) {
633,566,565✔
132
    case FUNCTION_TYPE_LAST_ROW:
22,560,842✔
133
    case FUNCTION_TYPE_LAST:
134
      pCxt->hasLastRowOrLast = true;
22,560,842✔
135
      break;
22,561,092✔
136
    case FUNCTION_TYPE_UDF:
213,779✔
137
      pCxt->errCode = reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache);
213,779✔
138
      break;
213,233✔
139
    default:
610,797,033✔
140
      break;
610,797,033✔
141
  }
142
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
633,571,358✔
143
}
144

145
static bool needGetTableIndex(SNode* pStmt) {
751,413,484✔
146
  return false;
751,413,484✔
147
  if (QUERY_SMA_OPTIMIZE_ENABLE == tsQuerySmaOptimize && QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
148
    SSelectStmt* pSelect = (SSelectStmt*)pStmt;
149
    return (NULL != pSelect->pWindow && QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow));
150
  }
151
  return false;
152
}
153

154
static int32_t collectMetaKeyFromInsTagsImpl(SCollectMetaKeyCxt* pCxt, SName* pName) {
1,772,114✔
155
  if (0 == pName->type) {
1,772,114✔
156
    return TSDB_CODE_SUCCESS;
1,180,949✔
157
  }
158
  if (TSDB_DB_NAME_T == pName->type) {
591,165✔
159
    return reserveDbVgInfoInCache(pName->acctId, pName->dbname, pCxt->pMetaCache);
151,139✔
160
  }
161
  return reserveTableVgroupInCacheExt(pName, pCxt->pMetaCache);
440,026✔
162
}
163

164
static int32_t collectMetaKeyFromInsTags(SCollectMetaKeyCxt* pCxt) {
1,772,114✔
165
  SSelectStmt* pSelect = (SSelectStmt*)pCxt->pStmt;
1,772,114✔
166
  SName        name = {0};
1,772,114✔
167
  int32_t      code = getVnodeSysTableTargetName(pCxt->pParseCxt->acctId, pSelect->pWhere, &name);
1,772,114✔
168
  if (TSDB_CODE_SUCCESS == code) {
1,772,114✔
169
    code = collectMetaKeyFromInsTagsImpl(pCxt, &name);
1,772,114✔
170
  }
171
  return code;
1,772,114✔
172
}
173

174
static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const char* pDb, const char* pTable,
751,389,094✔
175
                                               EPrivType privType, EPrivObjType objType) {
176
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
751,389,094✔
177
  if (TSDB_CODE_SUCCESS == code) {
751,413,802✔
178
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, NULL, PRIV_DB_USE, PRIV_OBJ_DB,
751,418,590✔
179
                                  pCxt->pMetaCache);
180
  }
181
  if (TSDB_CODE_SUCCESS == code) {
751,420,223✔
182
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
751,426,193✔
183
  }
184
  if (TSDB_CODE_SUCCESS == code) {
751,426,248✔
185
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
751,432,180✔
186
  }
187
  if (TSDB_CODE_SUCCESS == code) {
751,419,175✔
188
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, pTable, privType, objType,
751,417,001✔
189
                                  pCxt->pMetaCache);
190
  }
191
#ifdef TD_ENTERPRISE
192
  if (TSDB_CODE_SUCCESS == code && NULL != pCxt->pParseCxt->pEffectiveUser) {
751,429,131✔
193
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pEffectiveUser, pDb, pTable, privType,
351,295✔
194
                                  objType, pCxt->pMetaCache);
195
  }
196
#endif
197
  if (TSDB_CODE_SUCCESS == code) {
751,427,000✔
198
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
751,427,341✔
199
  }
200
  if (TSDB_CODE_SUCCESS == code && needGetTableIndex(pCxt->pStmt)) {
751,428,959✔
201
    code = reserveTableIndexInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
×
202
  }
203
  if (TSDB_CODE_SUCCESS == code && (0 == strcmp(pTable, TSDB_INS_TABLE_DNODE_VARIABLES) ||
751,420,398✔
204
                                     0 == strcmp(pTable, TSDB_INS_TABLE_CPU_ALLOCATION))) {
751,416,819✔
205
    code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
12,831✔
206
  }
207
  if (TSDB_CODE_SUCCESS == code &&
751,410,282✔
208
      (0 == strcmp(pTable, TSDB_INS_TABLE_TAGS) || 0 == strcmp(pTable, TSDB_INS_TABLE_TABLES) ||
751,427,249✔
209
       0 == strcmp(pTable, TSDB_INS_TABLE_COLS) || 0 == strcmp(pTable, TSDB_INS_TABLE_VC_COLS) ||
750,770,104✔
210
       0 == strcmp(pTable, TSDB_INS_DISK_USAGE) || 0 == strcmp(pTable, TSDB_INS_TABLE_FILESETS) ||
749,728,958✔
211
       0 == strcmp(pTable, TSDB_INS_TABLE_VIRTUAL_TABLES_REFERENCING) ||
749,732,022✔
212
       0 == strcmp(pTable, TSDB_INS_TABLE_TABLE_FIXED_DISTRIBUTED)) &&
749,654,329✔
213
      QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
1,776,388✔
214
    code = collectMetaKeyFromInsTags(pCxt);
1,772,114✔
215
  }
216
  // ins_table_fixed_distributed: reserve DB vgroup info + target table meta
217
  if (TSDB_CODE_SUCCESS == code &&
751,409,651✔
218
      0 == strcmp(pTable, TSDB_INS_TABLE_TABLE_FIXED_DISTRIBUTED) &&
751,420,152✔
219
      QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
3,468✔
220
    SSelectStmt* pSelect = (SSelectStmt*)pCxt->pStmt;
2,020✔
221
    SName        targetName = {0};
2,020✔
222
    code = getVnodeSysTableTargetName(pCxt->pParseCxt->acctId, pSelect->pWhere, &targetName);
2,020✔
223
    if (TSDB_CODE_SUCCESS == code && targetName.dbname[0] != '\0') {
2,020✔
224
      code = reserveDbVgInfoInCache(targetName.acctId, targetName.dbname, pCxt->pMetaCache);
1,414✔
225
    }
226
    if (TSDB_CODE_SUCCESS == code && targetName.tname[0] != '\0' && targetName.dbname[0] != '\0') {
2,020✔
227
      code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, targetName.dbname, targetName.tname, pCxt->pMetaCache);
1,212✔
228
    }
229
  }
230
  if (TSDB_CODE_SUCCESS == code && QUERY_SMA_OPTIMIZE_ENABLE == tsQuerySmaOptimize &&
751,409,651✔
231
      QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
441,542✔
232
    code = reserveTableTSMAInfoInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
441,542✔
233
  }
234
  return code;
751,418,580✔
235
}
236

237
static EDealRes collectMetaKeyFromRealTable(SCollectMetaKeyFromExprCxt* pCxt, SRealTableNode* pRealTable) {
748,197,053✔
238
  pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, pRealTable->table.dbName, pRealTable->table.tableName,
748,197,053✔
239
                                                  PRIV_TBL_SELECT, PRIV_OBJ_TBL);
240
  if (TSDB_CODE_SUCCESS == pCxt->errCode && pCxt->pComCxt->collectVStbRefDbs) {
748,222,944✔
241
    pCxt->errCode = reserveVStbRefDbsInCache(pCxt->pComCxt->pParseCxt->acctId, pRealTable->table.dbName,
928,061,095✔
242
                                             pRealTable->table.tableName, pCxt->pComCxt->pMetaCache);
928,067,133✔
243
  }
244
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
748,218,351✔
245
}
246

247
static EDealRes collectMetaKeyFromTempTable(SCollectMetaKeyFromExprCxt* pCxt, STempTableNode* pTempTable) {
34,534,113✔
248
  pCxt->errCode = collectMetaKeyFromQuery(pCxt->pComCxt, pTempTable->pSubquery);
34,534,113✔
249
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
34,534,113✔
250
}
251

252
static int32_t isTbnameEqCondOperator(SOperatorNode* pOperator, char** ppTableName) {
453,587,576✔
253
  if (pOperator->opType != OP_TYPE_EQUAL) {
453,587,576✔
254
    return TSDB_CODE_SUCCESS;
389,933,682✔
255
  }
256

257
  SValueNode* pValueNode = NULL;
63,653,814✔
258
  if (nodeType(pOperator->pLeft) == QUERY_NODE_FUNCTION &&
63,653,814✔
259
      0 == strcasecmp(((SFunctionNode*)(pOperator->pLeft))->functionName, "tbname") &&
4,857,869✔
260
      nodeType(pOperator->pRight) == QUERY_NODE_VALUE) {
697,528✔
261
    pValueNode = (SValueNode*)pOperator->pRight;
673,736✔
262
  } else if (nodeType(pOperator->pRight) == QUERY_NODE_FUNCTION &&
62,980,078✔
263
             0 == strcasecmp(((SFunctionNode*)(pOperator->pRight))->functionName, "tbname") &&
95,570✔
264
             nodeType(pOperator->pLeft) == QUERY_NODE_VALUE) {
1,266✔
265
    pValueNode = (SValueNode*)pOperator->pLeft;
×
266
  } else {
267
    return TSDB_CODE_SUCCESS;
62,980,078✔
268
  }
269

270
  *ppTableName = pValueNode->literal;
673,736✔
271

272
  return TSDB_CODE_SUCCESS;
673,736✔
273
}
274

275
static EDealRes collectMetaKeyFromOperator(SCollectMetaKeyFromExprCxt* pCxt, SOperatorNode* pOpNode) {
595,836,511✔
276
  if (!pCxt->tbnameCollect) {
595,836,511✔
277
    return DEAL_RES_CONTINUE;
142,252,248✔
278
  }
279

280
  char*   pTableName = NULL;
453,584,720✔
281
  int32_t code = isTbnameEqCondOperator((SOperatorNode*)pOpNode, &pTableName);
453,584,263✔
282
  if (TSDB_CODE_SUCCESS != code) return DEAL_RES_CONTINUE;
453,595,515✔
283
  if (pTableName) {
453,595,515✔
284
    SSelectStmt* pSelect = (SSelectStmt*)pCxt->pComCxt->pStmt;
673,736✔
285
    pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, ((SRealTableNode*)pSelect->pFromTable)->table.dbName,
673,736✔
286
                                                    pTableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL);
287
  }
288

289
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
453,595,515✔
290
}
291

292
static EDealRes collectMetaKeyFromExprImpl(SNode* pNode, void* pContext) {
2,147,483,647✔
293
  SCollectMetaKeyFromExprCxt* pCxt = pContext;
2,147,483,647✔
294
  switch (nodeType(pNode)) {
2,147,483,647✔
295
    case QUERY_NODE_FUNCTION:
633,576,995✔
296
      return collectMetaKeyFromFunction(pCxt, (SFunctionNode*)pNode);
633,576,995✔
297
    case QUERY_NODE_REAL_TABLE:
747,819,561✔
298
      return collectMetaKeyFromRealTable(pCxt, (SRealTableNode*)pNode);
747,819,561✔
299
    case QUERY_NODE_TEMP_TABLE:
34,534,113✔
300
      return collectMetaKeyFromTempTable(pCxt, (STempTableNode*)pNode);
34,534,113✔
301
    case QUERY_NODE_OPERATOR:
595,851,554✔
302
      return collectMetaKeyFromOperator(pCxt, (SOperatorNode*)pNode);
595,851,554✔
303
    case QUERY_NODE_SET_OPERATOR:
31,331,085✔
304
      return collectMetaKeyFromSetOperator(pCxt->pComCxt, (SSetOperator*)pNode);
31,331,085✔
305
    case QUERY_NODE_SELECT_STMT:
358,141,515✔
306
      return collectMetaKeyFromQuery(pCxt->pComCxt, pNode);
358,141,515✔
307
    default:
2,147,483,647✔
308
      break;
2,147,483,647✔
309
  }
310
  return DEAL_RES_CONTINUE;
2,147,483,647✔
311
}
312

313
static int32_t collectMetaKeyFromExprs(SCollectMetaKeyCxt* pCxt, SNodeList* pList) {
46,728,607✔
314
  SCollectMetaKeyFromExprCxt cxt = {.pComCxt = pCxt, .errCode = TSDB_CODE_SUCCESS, .tbnameCollect = false};
46,728,607✔
315
  nodesWalkExprs(pList, collectMetaKeyFromExprImpl, &cxt);
46,728,607✔
316
  return cxt.errCode;
46,728,678✔
317
}
318

319
static int32_t collectMetaKeyFromSetOperator(SCollectMetaKeyCxt* pCxt, SSetOperator* pStmt) {
46,725,782✔
320
  int32_t code = collectMetaKeyFromQuery(pCxt, pStmt->pLeft);
46,725,782✔
321
  if (TSDB_CODE_SUCCESS == code) {
46,728,695✔
322
    code = collectMetaKeyFromQuery(pCxt, pStmt->pRight);
46,728,867✔
323
  }
324
  if (TSDB_CODE_SUCCESS == code) {
46,728,435✔
325
    code = collectMetaKeyFromExprs(pCxt, pStmt->pOrderByList);
46,728,607✔
326
  }
327
  return code;
46,728,764✔
328
}
329

330
static int32_t reserveDbCfgForLastRow(SCollectMetaKeyCxt* pCxt, SNode* pTable) {
17,789,315✔
331
  if (NULL == pTable || QUERY_NODE_REAL_TABLE != nodeType(pTable)) {
17,789,315✔
332
    return TSDB_CODE_SUCCESS;
521,335✔
333
  }
334
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SRealTableNode*)pTable)->table.dbName, pCxt->pMetaCache);
17,267,955✔
335
}
336

337
static int32_t collectMetaKeyFromSelect(SCollectMetaKeyCxt* pCxt, SSelectStmt* pStmt) {
761,374,219✔
338
  SCollectMetaKeyFromExprCxt cxt = {.pComCxt = pCxt, .hasLastRowOrLast = false, .errCode = TSDB_CODE_SUCCESS};
761,374,219✔
339
  if (pStmt->pFromTable && QUERY_NODE_REAL_TABLE == nodeType(pStmt->pFromTable)) {
761,375,886✔
340
    cxt.tbnameCollect = true;
654,728,530✔
341
    cxt.pComCxt->collectVStbRefDbs = true;
654,728,530✔
342
  }
343
  nodesWalkSelectStmt(pStmt, SQL_CLAUSE_FROM, collectMetaKeyFromExprImpl, &cxt);
761,372,244✔
344
  if (TSDB_CODE_SUCCESS == cxt.errCode && cxt.hasLastRowOrLast) {
761,405,001✔
345
    cxt.errCode = reserveDbCfgForLastRow(pCxt, pStmt->pFromTable);
17,789,434✔
346
  }
347
  return cxt.errCode;
761,405,327✔
348
}
349

350
static int32_t collectMetaKeyFromCreateDatabase(SCollectMetaKeyCxt* pCxt, SCreateDatabaseStmt* pStmt) {
1,715,411✔
351
  int32_t code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_DB_CREATE, 0,
1,715,411✔
352
                                        pCxt->pMetaCache);
353
  if (TSDB_CODE_SUCCESS == code) {
1,715,411✔
354
    // pre-fetch PRIV_SECURITY_POLICY_ALTER for CREATE DATABASE ... SECURITY_LEVEL X (MAC mode)
355
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
1,715,411✔
356
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
357
  }
358
  return code;
1,715,411✔
359
}
360

361
static int32_t collectMetaKeyFromAlterDatabase(SCollectMetaKeyCxt* pCxt, SAlterDatabaseStmt* pStmt) {
212,604✔
362
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
212,604✔
363
  if (TSDB_CODE_SUCCESS == code) {
212,604✔
364
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_CM_ALTER,
212,604✔
365
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
366
  }
367
  if (TSDB_CODE_SUCCESS == code) {
212,604✔
368
    // ALTER DATABASE ... SECURITY_LEVEL uses PRIV_SECURITY_POLICY_ALTER as primary check: pre-fetch unconditionally.
369
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
212,604✔
370
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
371
  }
372
  return code;
212,604✔
373
}
374

375
static int32_t collectMetaKeyFromDropDatabase(SCollectMetaKeyCxt* pCxt, SDropDatabaseStmt* pStmt) {
1,456,495✔
376
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
1,456,495✔
377
  if (TSDB_CODE_SUCCESS == code) {
1,456,495✔
378
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_CM_DROP,
1,456,495✔
379
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
380
  }
381
  return code;
1,456,495✔
382
}
383

384
static int32_t collectMetaKeyFromFlushDatabase(SCollectMetaKeyCxt* pCxt, SFlushDatabaseStmt* pStmt) {
2,034,894✔
385
  int32_t code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
2,034,894✔
386
  if (TSDB_CODE_SUCCESS == code) {
2,034,894✔
387
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_FLUSH,
2,034,894✔
388
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
389
  }
390
  return code;
2,034,894✔
391
}
392

393
static int32_t collectMetaKeyFromCreateTable(SCollectMetaKeyCxt* pCxt, SCreateTableStmt* pStmt) {
9,758,176✔
394
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
9,758,176✔
395
  if (TSDB_CODE_SUCCESS == code && NULL == pStmt->pTags) {
9,758,176✔
396
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
7,921,854✔
397
  }
398
  if (TSDB_CODE_SUCCESS == code) {
9,758,176✔
399
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
9,758,176✔
400
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
401
  }
402
  if (TSDB_CODE_SUCCESS == code) {
9,758,176✔
403
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_TBL_CREATE,
9,758,176✔
404
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
405
  }
406
  return code;
9,758,176✔
407
}
408

409
static int32_t collectMetaKeyFromCreateVTable(SCollectMetaKeyCxt* pCxt, SCreateVTableStmt* pStmt) {
238,349✔
410
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
238,349✔
411
  if (TSDB_CODE_SUCCESS == code) {
238,349✔
412
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
238,349✔
413
  }
414
  if (TSDB_CODE_SUCCESS == code) {
238,349✔
415
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
238,349✔
416
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
417
  }
418
  if (TSDB_CODE_SUCCESS == code) {
238,349✔
419
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_TBL_CREATE,
238,349✔
420
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
421
  }
422
  if (TSDB_CODE_SUCCESS == code) {
238,349✔
423
    SNode* pNode = NULL;
238,349✔
424
    FOREACH(pNode, pStmt->pCols) {
156,424,855✔
425
      SColumnDefNode* pCol = (SColumnDefNode*)pNode;
156,186,506✔
426
      if (NULL == pCol) {
156,186,506✔
427
        code = TSDB_CODE_PAR_INVALID_COLUMN;
×
428
        break;
×
429
      }
430
      SColumnOptions* pOptions = (SColumnOptions*)pCol->pOptions;
156,186,506✔
431
      if (pOptions && pOptions->hasRef) {
156,186,506✔
432
        code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pOptions->refDb, pOptions->refTable, pCxt->pMetaCache);
97,433,823✔
433
        if (TSDB_CODE_SUCCESS == code) {
97,433,823✔
434
          code =
435
              reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pOptions->refDb, pOptions->refTable, pCxt->pMetaCache);
97,433,823✔
436
        }
437
        if (TSDB_CODE_SUCCESS == code) {
97,433,823✔
438
          code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pOptions->refDb,
194,867,190✔
439
                                        pOptions->refTable, PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache);
97,433,823✔
440
        }
441
        if (TSDB_CODE_SUCCESS != code) {
97,433,823✔
442
          break;
×
443
        }
444
      }
445
    }
446
  }
447
  return code;
238,349✔
448
}
449

450
static int32_t collectMetaKeyFromCreateVSubTable(SCollectMetaKeyCxt* pCxt, SCreateVSubTableStmt* pStmt) {
419,330✔
451
  int32_t code = TSDB_CODE_SUCCESS;
419,330✔
452
  PAR_ERR_RET(reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache));
419,330✔
453
  // super table's meta
454
  PAR_ERR_RET(
419,330✔
455
      reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->useDbName, pStmt->useTableName, pCxt->pMetaCache));
456
  // child table's meta
457
  PAR_ERR_RET(reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache));
419,330✔
458
  // check db's write auth
459
  PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
419,330✔
460
                                     PRIV_OBJ_DB, pCxt->pMetaCache));
461
  PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
419,330✔
462
                                     PRIV_TBL_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache));
463
  // check org table's read auth for column references
464
  SNode*     pNode = NULL;
419,330✔
465
  SNodeList* pTmpNodeList = pStmt->pSpecificColRefs ? pStmt->pSpecificColRefs : pStmt->pColRefs;
419,330✔
466
  if (pTmpNodeList) {
419,330✔
467
    FOREACH(pNode, pTmpNodeList) {
60,150,451✔
468
      SColumnRefNode* pColRef = (SColumnRefNode*)pNode;
59,757,566✔
469
      if (NULL == pColRef) {
59,757,566✔
470
        code = TSDB_CODE_PAR_INVALID_COLUMN;
×
471
        break;
×
472
      }
473
      PAR_ERR_RET(
59,757,566✔
474
          reserveTableMetaInCache(pCxt->pParseCxt->acctId, pColRef->refDbName, pColRef->refTableName, pCxt->pMetaCache));
475
      PAR_ERR_RET(reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pColRef->refDbName, pColRef->refTableName,
59,757,566✔
476
                                            pCxt->pMetaCache));
477
      PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pColRef->refDbName,
59,757,566✔
478
                                         pColRef->refTableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache));
479
    }
480
  }
481

482
  // collect metadata for tag reference tables (SColumnRefNode nodes in pValsOfTags)
483
  // Handles all tag ref syntax forms: legacy (FROM db.table.tag), specific (tag_name FROM db.table.tag),
484
  // and positional (db.table.tag) - all produce SColumnRefNode in pValsOfTags.
485
  if (pStmt->pValsOfTags) {
419,330✔
486
    FOREACH(pNode, pStmt->pValsOfTags) {
2,269,434✔
487
      if (nodeType(pNode) == QUERY_NODE_COLUMN_REF) {
1,850,104✔
488
        SColumnRefNode* pTagRef = (SColumnRefNode*)pNode;
×
489
        PAR_ERR_RET(
×
490
            reserveTableMetaInCache(pCxt->pParseCxt->acctId, pTagRef->refDbName, pTagRef->refTableName, pCxt->pMetaCache));
491
        PAR_ERR_RET(reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pTagRef->refDbName, pTagRef->refTableName,
×
492
                                              pCxt->pMetaCache));
493
        PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pTagRef->refDbName,
×
494
                                           pTagRef->refTableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache));
495
      }
496
    }
497
  }
498

499
  return code;
419,330✔
500
}
501

502
static int32_t collectMetaKeyFromCreateMultiTable(SCollectMetaKeyCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
38,060,239✔
503
  int32_t code = TSDB_CODE_SUCCESS;
38,060,239✔
504
  SNode*  pNode = NULL;
38,060,239✔
505
  FOREACH(pNode, pStmt->pSubTables) {
83,685,653✔
506
    if (pNode->type == QUERY_NODE_CREATE_SUBTABLE_CLAUSE) {
45,617,675✔
507
      SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
45,610,437✔
508
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
45,610,437✔
509
      if (TSDB_CODE_SUCCESS == code) {
45,629,636✔
510
        code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pClause->useTableName,
45,631,025✔
511
                                       pCxt->pMetaCache);
512
      }
513
      if (TSDB_CODE_SUCCESS == code) {
45,629,195✔
514
        code =
515
            reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
45,629,195✔
516
      }
517
      if (TSDB_CODE_SUCCESS == code) {
45,638,797✔
518
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL,
45,638,797✔
519
                                      PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
520
      }
521
      if (TSDB_CODE_SUCCESS == code) {
45,631,527✔
522
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL,
45,631,527✔
523
                                      PRIV_TBL_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
524
      }
525
    } else {
UNCOV
526
      SCreateSubTableFromFileClause* pClause = (SCreateSubTableFromFileClause*)pNode;
×
UNCOV
527
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pCxt->pMetaCache);
×
528
      if (TSDB_CODE_SUCCESS == code) {
×
529
        code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pClause->useTableName,
×
530
                                       pCxt->pMetaCache);
531
      }
532
      if (TSDB_CODE_SUCCESS == code) {
×
533
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->useDbName, NULL,
×
534
                                      PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
535
      }
536
      if (TSDB_CODE_SUCCESS == code) {
×
537
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->useDbName, NULL,
×
538
                                      PRIV_TBL_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
539
      }
540
    }
541

542
    if (TSDB_CODE_SUCCESS != code) {
45,625,414✔
543
      break;
×
544
    }
545
  }
546
  return code;
38,059,779✔
547
}
548

549
static int32_t collectMetaKeyFromCreateSubTableFromFile(SCollectMetaKeyCxt*            pCxt,
1,491✔
550
                                                        SCreateSubTableFromFileClause* pClause) {
551
  int32_t code = TSDB_CODE_SUCCESS;
1,491✔
552
  SNode*  pNode = NULL;
1,491✔
553

554
  code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pCxt->pMetaCache);
1,491✔
555
  if (TSDB_CODE_SUCCESS == code) {
1,491✔
556
    code =
557
        reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pClause->useTableName, pCxt->pMetaCache);
1,491✔
558
  }
559
  if (TSDB_CODE_SUCCESS == code) {
1,491✔
560
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->useDbName, NULL,
1,491✔
561
                                  PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
562
  }
563
  if (TSDB_CODE_SUCCESS == code) {
1,491✔
564
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->useDbName, NULL,
1,491✔
565
                                  PRIV_TBL_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
566
  }
567

568
  return code;
1,491✔
569
}
570

571
static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) {
2,677,053✔
572
  int32_t code = TSDB_CODE_SUCCESS;
2,677,053✔
573
  SNode*  pNode = NULL;
2,677,053✔
574
  FOREACH(pNode, pStmt->pTables) {
5,477,505✔
575
    SDropTableClause* pClause = (SDropTableClause*)pNode;
2,800,452✔
576
    if (pStmt->withOpt) {
2,800,452✔
577
      code = reserveTableUidInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
157,519✔
578
      if (TSDB_CODE_SUCCESS == code) {
157,519✔
579
        code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
157,519✔
580
      }
581
    } else {
582
      code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
2,642,933✔
583
      if (TSDB_CODE_SUCCESS == code) {
2,642,933✔
584
        code =
585
            reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
2,642,933✔
586
      }
587
      if (TSDB_CODE_SUCCESS == code) {
2,642,933✔
588
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
5,278,572✔
589
                                      pClause->tableName, PRIV_CM_DROP, PRIV_OBJ_TBL, pCxt->pMetaCache);
2,642,933✔
590
      }
591
    }
592
    if (TSDB_CODE_SUCCESS == code) {
2,800,452✔
593
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
2,800,452✔
594
    }
595
    if (TSDB_CODE_SUCCESS == code) {
2,800,452✔
596
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL, PRIV_DB_USE,
2,800,452✔
597
                                    PRIV_OBJ_DB, pCxt->pMetaCache);
598
    }
599

600
    if (TSDB_CODE_SUCCESS != code) {
2,800,452✔
601
      break;
×
602
    }
603
  }
604
  return code;
2,677,053✔
605
}
606

607
static int32_t collectMetaKeyFromDropStable(SCollectMetaKeyCxt* pCxt, SDropSuperTableStmt* pStmt) {
103,513✔
608
  int32_t code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
103,513✔
609
                                        PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
610
  if (TSDB_CODE_SUCCESS == code) {
103,513✔
611
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
103,513✔
612
  }
613
  if (TSDB_CODE_SUCCESS == code) {
103,513✔
614
    if (pStmt->withOpt) {
103,513✔
615
      code = reserveTableUidInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
61,204✔
616
    } else {
617
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
42,309✔
618
                                    PRIV_CM_DROP, PRIV_OBJ_TBL, pCxt->pMetaCache);
619
    }
620
  }
621
  return code;
103,513✔
622
}
623

624
static int32_t collectMetaKeyFromDropVtable(SCollectMetaKeyCxt* pCxt, SDropVirtualTableStmt* pStmt) {
80,108✔
625
  int32_t code = TSDB_CODE_SUCCESS;
80,108✔
626
  if (pStmt->withOpt) {
80,108✔
627
    code = reserveTableUidInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
×
628
    if (TSDB_CODE_SUCCESS == code) {
×
629
      code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
×
630
    }
631
    if (TSDB_CODE_SUCCESS == code) {
×
632
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
×
633
    }
634
  } else {
635
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
80,108✔
636
    if (TSDB_CODE_SUCCESS == code) {
80,108✔
637
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
80,108✔
638
    }
639
    if (TSDB_CODE_SUCCESS == code) {
80,108✔
640
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
80,108✔
641
                                    PRIV_OBJ_DB, pCxt->pMetaCache);
642
    }
643
    if (TSDB_CODE_SUCCESS == code) {
80,108✔
644
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
80,108✔
645
                                    PRIV_CM_DROP, PRIV_OBJ_TBL, pCxt->pMetaCache);
646
    }
647
  }
648
  return code;
80,108✔
649
}
650

651

652

653
static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
20,840,779✔
654
  int32_t code = TSDB_CODE_SUCCESS;
20,840,779✔
655

656
  if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
20,840,779✔
657
    SNode*  pNode = NULL;
8,942,641✔
658
    FOREACH(pNode, pStmt->pList) {
17,920,850✔
659
      SAlterTableUpdateTagValClause* pClause = (SAlterTableUpdateTagValClause*)pNode;
8,978,209✔
660
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
8,978,209✔
661
      if (code != TSDB_CODE_SUCCESS) {
8,978,209✔
662
        break;
×
663
      }
664

665
      SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
8,978,209✔
666
      tstrncpy(name.dbname, pClause->dbName, TSDB_DB_NAME_LEN);
8,978,209✔
667
      tstrncpy(name.tname, pClause->tableName, TSDB_TABLE_NAME_LEN);
8,978,209✔
668
      code = catalogRemoveTableRelatedMeta(pCxt->pParseCxt->pCatalog, &name);
8,978,209✔
669
      if (code != TSDB_CODE_SUCCESS) {
8,978,209✔
670
        break;
×
671
      }
672

673
      code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
8,978,209✔
674
      if (code != TSDB_CODE_SUCCESS) {
8,978,209✔
675
        break;
×
676
      }
677

678
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
8,978,209✔
679
      if (code != TSDB_CODE_SUCCESS) {
8,978,209✔
680
        break;
×
681
      }
682

683
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
8,978,209✔
684
      if (code != TSDB_CODE_SUCCESS) {
8,978,209✔
685
        break;
×
686
      }
687
                                      
688
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, pClause->tableName, PRIV_CM_ALTER, PRIV_OBJ_TBL, pCxt->pMetaCache);
8,978,209✔
689
      if (code != TSDB_CODE_SUCCESS) {
8,978,209✔
690
        break;
×
691
      }
692
    }
693

694
    return code;
8,942,641✔
695
  }
696
  
697
  if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
11,898,138✔
698
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
33,518✔
699
    if (TSDB_CODE_SUCCESS != code) {
33,518✔
700
      return code;
×
701
    }
702

703
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
33,518✔
704
    if (TSDB_CODE_SUCCESS != code) {
33,518✔
705
      return code;
×
706
    }
707

708
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
33,518✔
709
    if (TSDB_CODE_SUCCESS != code) {
33,518✔
710
      return code;
×
711
    }
712

713
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
33,518✔
714
    if (TSDB_CODE_SUCCESS != code) {
33,518✔
715
      return code;
×
716
    }
717

718
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName, PRIV_CM_ALTER, PRIV_OBJ_TBL, pCxt->pMetaCache);
33,518✔
719
    return code;
33,518✔
720
  }
721

722
  code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
11,864,620✔
723
  if (code != TSDB_CODE_SUCCESS) {
11,864,620✔
724
    return code;
×
725
  }
726

727
  code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
11,864,620✔
728
  if (code != TSDB_CODE_SUCCESS) {
11,864,620✔
729
    return code;
×
730
  }
731

732
  code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
11,864,620✔
733
  if (code != TSDB_CODE_SUCCESS) {
11,864,620✔
734
    return code;
×
735
  }
736

737
  code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
11,864,620✔
738
  if (code != TSDB_CODE_SUCCESS) {
11,864,620✔
739
    return code;
×
740
  }
741
                                  
742
  code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName, PRIV_CM_ALTER, PRIV_OBJ_TBL, pCxt->pMetaCache);
11,864,620✔
743
  if (TSDB_CODE_SUCCESS == code) {
11,864,620✔
744
    // ALTER TABLE ... SECURITY_LEVEL uses PRIV_SECURITY_POLICY_ALTER as primary check: pre-fetch unconditionally.
745
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
11,864,620✔
746
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
747
  }
748
  return code;
11,864,620✔
749
}
750

751

752

753
static int32_t collectMetaKeyFromAlterStable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
571,286✔
754
  if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
571,286✔
755
    // TODO: should return TSDB_CODE_PAR_INVALID_ALTER_TABLE directly
756
    int32_t code = TSDB_CODE_SUCCESS;
206✔
757
    SNode*  pNode = NULL;
206✔
758
    FOREACH(pNode, pStmt->pList) {
412✔
759
      SAlterTableUpdateTagValClause* pClause = (SAlterTableUpdateTagValClause*)pNode;
206✔
760
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
206✔
761
      if (code != TSDB_CODE_SUCCESS) break;
206✔
762
      code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
206✔
763
      if (code != TSDB_CODE_SUCCESS) break;
206✔
764
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
206✔
765
      if (code != TSDB_CODE_SUCCESS) break;
206✔
766
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, pClause->tableName, PRIV_CM_ALTER, PRIV_OBJ_TBL, pCxt->pMetaCache);
206✔
767
      if (code != TSDB_CODE_SUCCESS) break;
206✔
768
    }
769
    return code;
206✔
770
  }
771

772
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
571,080✔
773
  if (TSDB_CODE_SUCCESS == code) {
571,080✔
774
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
571,080✔
775
  }
776
  if (TSDB_CODE_SUCCESS == code) {
571,080✔
777
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
571,080✔
778
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
779
  }
780
  if (TSDB_CODE_SUCCESS == code) {
571,080✔
781
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
571,080✔
782
                                  PRIV_CM_ALTER, PRIV_OBJ_TBL, pCxt->pMetaCache);
783
  }
784
  if (TSDB_CODE_SUCCESS == code) {
571,080✔
785
    // ALTER TABLE ... SECURITY_LEVEL uses PRIV_SECURITY_POLICY_ALTER as primary check: pre-fetch unconditionally.
786
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
571,080✔
787
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
788
  }
789
  return code;
571,080✔
790
}
791

792

793

794
static int32_t collectMetaKeyFromAlterVtable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
458,274✔
795
  PAR_ERR_RET(collectMetaKeyFromAlterTable(pCxt, pStmt));
458,274✔
796

797
  if (pStmt->alterType == TSDB_ALTER_TABLE_ALTER_COLUMN_REF ||
458,274✔
798
      pStmt->alterType == TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF) {
331,892✔
799
    PAR_ERR_RET(
167,115✔
800
        reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->refDbName, pStmt->refTableName, pCxt->pMetaCache));
801
    PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->refDbName, NULL,
167,115✔
802
                                       PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache));
803
    PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->refDbName,
167,115✔
804
                                       pStmt->refTableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache));
805
  }
806

807
  return TSDB_CODE_SUCCESS;
458,274✔
808
}
809

810

811

812
static int32_t collectMetaKeyFromUseDatabase(SCollectMetaKeyCxt* pCxt, SUseDatabaseStmt* pStmt) {
98,381,128✔
813
  int32_t code = reserveDbVgVersionInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
98,381,128✔
814
  if (TSDB_CODE_SUCCESS == code) {
98,385,577✔
815
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
98,386,129✔
816
  }
817
  if (TSDB_CODE_SUCCESS == code) {
98,385,915✔
818
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
98,384,833✔
819
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
820
  }
821
  return code;
98,386,083✔
822
}
823

824
static int32_t collectMetaKeyFromCreateIndex(SCollectMetaKeyCxt* pCxt, SCreateIndexStmt* pStmt) {
23,767✔
825
  int32_t code = TSDB_CODE_SUCCESS;
23,767✔
826
  if (INDEX_TYPE_SMA == pStmt->indexType || INDEX_TYPE_NORMAL == pStmt->indexType) {
23,767✔
827
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
23,767✔
828
    if (TSDB_CODE_SUCCESS == code) {
23,767✔
829
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
23,767✔
830
    }
831
    if (TSDB_CODE_SUCCESS == code) {
23,767✔
832
      code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
23,767✔
833
    }
834
    if (TSDB_CODE_SUCCESS == code) {
23,767✔
835
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
23,767✔
836
    }
837
    if (TSDB_CODE_SUCCESS == code) {
23,767✔
838
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
23,767✔
839
                                    PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache);
840
    }
841
    if (TSDB_CODE_SUCCESS == code) {
23,767✔
842
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
23,767✔
843
                                    PRIV_IDX_CREATE, PRIV_OBJ_TBL, pCxt->pMetaCache);
844
    }
845
    if (TSDB_CODE_SUCCESS == code) {
23,767✔
846
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
23,767✔
847
                                    PRIV_OBJ_DB, pCxt->pMetaCache);
848
    }
849
  }
850
  return code;
23,767✔
851
}
852

853
static int32_t collectMetaKeyFromDropIndex(SCollectMetaKeyCxt* pCxt, SDropIndexStmt* pStmt) {
11,209✔
854
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->indexDbName, pCxt->pMetaCache);
11,209✔
855
  if (TSDB_CODE_SUCCESS == code) {
11,209✔
856
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->indexDbName, NULL,
11,209✔
857
                                  PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
858
  }
859
  if (TSDB_CODE_SUCCESS == code) {
11,209✔
860
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->indexDbName, pStmt->indexName,
11,209✔
861
                                  PRIV_CM_DROP, PRIV_OBJ_IDX, pCxt->pMetaCache);
862
  }
863
  return code;
11,209✔
864
}
865

866
static int32_t collectMetaKeyFromCreateTopic(SCollectMetaKeyCxt* pCxt, SCreateTopicStmt* pStmt) {
206,520✔
867
  int32_t code = 0;
206,520✔
868
  if (NULL != pStmt->pQuery) {
206,520✔
869
    code = collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
159,785✔
870
  }
871
  if (NULL != pStmt->pWhere) {
206,520✔
872
    code = collectMetaKeyFromRealTableImpl(pCxt, pStmt->subDbName, pStmt->subSTbName, PRIV_TBL_SELECT, PRIV_OBJ_TBL);
9,653✔
873
  }
874
  if (pStmt->subDbName[0] != '\0') {
206,520✔
875
    if (TSDB_CODE_SUCCESS == code) {
46,735✔
876
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->subDbName, pCxt->pMetaCache);
46,735✔
877
    }
878
    if (TSDB_CODE_SUCCESS == code) {
46,735✔
879
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->subDbName, NULL,
46,735✔
880
                                    PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
881
    }
882
    if (TSDB_CODE_SUCCESS == code) {
46,735✔
883
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->subDbName, NULL,
46,735✔
884
                                    PRIV_TOPIC_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
885
    }
886
  }
887
  return code;
206,520✔
888
}
889

890
static int32_t collectMetaKeyFromExplain(SCollectMetaKeyCxt* pCxt, SExplainStmt* pStmt) {
100,328,035✔
891
  return collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
100,328,035✔
892
}
893

894
static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStmt* pStmt) {
583,950✔
895
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
583,950✔
896
  tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
583,921✔
897
  tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
583,921✔
898
  int32_t code = catalogRemoveTableRelatedMeta(pCxt->pParseCxt->pCatalog, &name);
583,950✔
899
#ifdef TD_ENTERPRISE
900
  if (TSDB_CODE_SUCCESS == code) {
583,950✔
901
    char dbFName[TSDB_DB_FNAME_LEN];
571,908✔
902
    (void)tNameGetFullDbName(&name, dbFName);
583,950✔
903
    code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, dbFName, 0, pStmt->tableName, 0);
583,950✔
904
  }
905
#endif
906
  if (TSDB_CODE_SUCCESS == code) {
583,950✔
907
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
583,950✔
908
  }
909
  if (TSDB_CODE_SUCCESS == code) {
583,950✔
910
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
583,950✔
911
  }
912
  return code;
583,950✔
913
}
914

915
static int32_t collectMetaKeyFromCreateStream(SCollectMetaKeyCxt* pCxt, SCreateStreamStmt* pStmt) {
405,832✔
916
  int32_t code = TSDB_CODE_SUCCESS;
405,832✔
917

918
  if (strcmp(pStmt->targetTabName, "") != 0) {
405,832✔
919
    PAR_ERR_RET(
402,373✔
920
        reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->targetDbName, pStmt->targetTabName, pCxt->pMetaCache));
921
    (void)reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->targetDbName, pStmt->targetTabName,
402,373✔
922
                                    pCxt->pMetaCache);
923
    PAR_ERR_RET(reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->targetDbName, pCxt->pMetaCache));
402,373✔
924
  }
925
  PAR_ERR_RET(reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->streamDbName, pCxt->pMetaCache));
405,832✔
926
  SRealTableNode* pTriggerTable = (SRealTableNode*)((SStreamTriggerNode*)pStmt->pTrigger)->pTrigerTable;
405,832✔
927
  if (pTriggerTable) {
405,832✔
928
    SCollectMetaKeyFromExprCxt cxt = {
393,586✔
929
        .pComCxt = pCxt, .hasLastRowOrLast = false, .tbnameCollect = true, .errCode = TSDB_CODE_SUCCESS};
930
    cxt.pComCxt->collectVStbRefDbs = true;
393,586✔
931
    EDealRes res = collectMetaKeyFromRealTable(&cxt, pTriggerTable);
393,586✔
932
    PAR_ERR_RET(cxt.errCode);
393,586✔
933
    PAR_ERR_RET(reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pTriggerTable->table.dbName, pCxt->pMetaCache));
393,586✔
934
    PAR_ERR_RET(reserveDbCfgInCache(pCxt->pParseCxt->acctId, pTriggerTable->table.dbName, pCxt->pMetaCache));
393,586✔
935
    PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pTriggerTable->table.dbName,
393,586✔
936
                                       pTriggerTable->table.tableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL,
937
                                       pCxt->pMetaCache));
938
    PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pTriggerTable->table.dbName,
393,586✔
939
                                       NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache));
940
  }
941
  if (pStmt->pQuery) {
405,832✔
942
    PAR_ERR_RET(collectMetaKeyFromQuery(pCxt, pStmt->pQuery));
402,373✔
943
  }
944
  PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->streamDbName, NULL,
405,832✔
945
                                     PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache));
946
  PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->streamDbName, NULL,
405,832✔
947
                                     PRIV_STREAM_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache));
948
  if (pStmt->targetDbName[0] != '\0') {
405,832✔
949
    PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->targetDbName, NULL,
402,373✔
950
                                       PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache));
951
    PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->targetDbName, NULL,
402,373✔
952
                                       PRIV_TBL_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache));
953
  }
954

955
  return code;
405,832✔
956
}
957

958
static int32_t collectMetaKeyFromRecalculateStream(SCollectMetaKeyCxt* pCxt, SRecalcStreamStmt* pStmt) {
13,089✔
959
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->streamDbName, pCxt->pMetaCache);
13,089✔
960
}
961

962
static int32_t collectMetaKeyFromShowDnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
25,147✔
963
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODES,
25,147✔
964
                                         pCxt->pMetaCache);
965
  if (TSDB_CODE_SUCCESS == code) {
25,147✔
966
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
25,147✔
967
                                  pCxt->pMetaCache);
968
  }
969
  return code;
25,147✔
970
}
971

972
static int32_t collectMetaKeyFromShowMnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
362,576✔
973
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES,
362,576✔
974
                                         pCxt->pMetaCache);
975
  if (TSDB_CODE_SUCCESS == code) {
362,576✔
976
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
362,576✔
977
                                  pCxt->pMetaCache);
978
  }
979
  return code;
362,576✔
980
}
981

982
static int32_t collectMetaKeyFromShowModules(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
×
983
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MODULES,
×
984
                                         pCxt->pMetaCache);
985
  return code;
×
986
}
987

988
static int32_t collectMetaKeyFromShowQnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,065✔
989
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES,
2,065✔
990
                                         pCxt->pMetaCache);
991
  if (TSDB_CODE_SUCCESS == code) {
2,065✔
992
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
2,065✔
993
                                  pCxt->pMetaCache);
994
  }
995
  return code;
2,065✔
996
}
997

998
static int32_t collectMetaKeyFromShowSnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
75,475✔
999
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SNODES,
75,475✔
1000
                                         pCxt->pMetaCache);
1001
  if (TSDB_CODE_SUCCESS == code) {
75,475✔
1002
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
75,475✔
1003
                                  pCxt->pMetaCache);
1004
  }
1005
  return code;
75,475✔
1006
}
1007

1008
static int32_t collectMetaKeyFromShowAnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
193✔
1009
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_ANODES,
193✔
1010
                                         pCxt->pMetaCache);
1011
  if (TSDB_CODE_SUCCESS == code) {
193✔
1012
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
193✔
1013
                                  pCxt->pMetaCache);
1014
  }
1015
  return code;
193✔
1016
}
1017

1018
static int32_t collectMetaKeyFromShowAnodesFull(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
×
1019
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
×
1020
                                         TSDB_INS_TABLE_ANODES_FULL, pCxt->pMetaCache);
1021
  if (TSDB_CODE_SUCCESS == code) {
×
1022
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
×
1023
                                  pCxt->pMetaCache);
1024
  }
1025
  return code;
×
1026
}
1027

1028
static int32_t collectMetaKeyFromShowBnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
65,366✔
1029
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_BNODES,
65,366✔
1030
                                         pCxt->pMetaCache);
1031
  if (TSDB_CODE_SUCCESS == code) {
65,366✔
1032
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
65,366✔
1033
                                  pCxt->pMetaCache);
1034
  }
1035
  return code;
65,366✔
1036
}
1037

1038
static int32_t collectMetaKeyFromShowBackupNodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
×
1039
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
×
1040
                                         TSDB_INS_TABLE_BACKUP_NODES, pCxt->pMetaCache);
1041
  if (TSDB_CODE_SUCCESS == code) {
×
1042
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
×
1043
                                  pCxt->pMetaCache);
1044
  }
1045
  return code;
×
1046
}
1047

1048
static int32_t collectMetaKeyFromShowXnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,361✔
1049
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_XNODES,
2,361✔
1050
                                         pCxt->pMetaCache);
1051
  if (TSDB_CODE_SUCCESS == code) {
2,361✔
1052
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
2,361✔
1053
                                  pCxt->pMetaCache);
1054
  }
1055
  return code;
2,361✔
1056
}
1057

1058
static int32_t collectMetaKeyFromShowXnodeTasks(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
7,229✔
1059
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
7,229✔
1060
                                         TSDB_INS_TABLE_XNODE_TASKS, pCxt->pMetaCache);
1061
  if (TSDB_CODE_SUCCESS == code) {
7,229✔
1062
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_CM_SHOW, 0,
7,229✔
1063
                                  pCxt->pMetaCache);
1064
  }
1065
  return code;
7,229✔
1066
}
1067
static int32_t collectMetaKeyFromShowXnodeAgents(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
4,310✔
1068
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
4,310✔
1069
                                         TSDB_INS_TABLE_XNODE_AGENTS, pCxt->pMetaCache);
1070
  if (TSDB_CODE_SUCCESS == code) {
4,310✔
1071
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
4,310✔
1072
                                  pCxt->pMetaCache);
1073
  }
1074
  return code;
4,310✔
1075
}
1076
static int32_t collectMetaKeyFromShowXnodeJobs(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
5,283✔
1077
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_XNODE_JOBS,
5,283✔
1078
                                         pCxt->pMetaCache);
1079
  if (TSDB_CODE_SUCCESS == code) {
5,283✔
1080
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_CM_SHOW, 0,
5,283✔
1081
                                  pCxt->pMetaCache);
1082
  }
1083
  return code;
5,283✔
1084
}
1085

1086
static int32_t collectMetaKeyFromShowVirtualTablesReferencing(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
×
1087
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
×
1088
                                         TSDB_INS_TABLE_VIRTUAL_TABLES_REFERENCING, pCxt->pMetaCache);
1089
  if (TSDB_CODE_SUCCESS == code) {
×
1090
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
×
1091
                                  pCxt->pMetaCache);
1092
  }
1093
  return code;
×
1094
}
1095

1096
static int32_t collectMetaKeyFromShowCpuAllocation(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,021✔
1097
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
2,021✔
1098
                                         TSDB_INS_TABLE_CPU_ALLOCATION, pCxt->pMetaCache);
1099
  if (TSDB_CODE_SUCCESS == code) {
2,021✔
1100
    code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
2,021✔
1101
  }
1102
  return code;
2,021✔
1103
}
1104

1105
static int32_t collectMetaKeyFromShowArbGroups(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
741✔
1106
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_ARBGROUPS,
741✔
1107
                                         pCxt->pMetaCache);
1108
  return code;
741✔
1109
}
1110

1111
static int32_t collectMetaKeyFromShowCluster(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,622✔
1112
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CLUSTER,
2,622✔
1113
                                         pCxt->pMetaCache);
1114
  if (TSDB_CODE_SUCCESS == code) {
2,622✔
1115
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_CLUSTER_SHOW, 0,
2,622✔
1116
                                  pCxt->pMetaCache);
1117
  }
1118
  return code;
2,622✔
1119
}
1120

1121
static int32_t collectMetaKeyFromShowSecurityPolicies(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
516✔
1122
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SECURITY_POLICIES,
516✔
1123
                                   pCxt->pMetaCache);
1124
  if (TSDB_CODE_SUCCESS == code) {
516✔
1125
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_SECURITY_POLICIES_SHOW, 0,
516✔
1126
                                  pCxt->pMetaCache);
1127
  }
1128
  return code;
516✔
1129
}
1130

1131
static int32_t collectMetaKeyFromShowDatabases(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
206,006✔
1132
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DATABASES,
206,006✔
1133
                                 pCxt->pMetaCache);
1134
}
1135

1136
static int32_t collectMetaKeyFromShowFunctions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
12,282✔
1137
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_FUNCTIONS,
12,282✔
1138
                                         pCxt->pMetaCache);
1139
  if (TSDB_CODE_SUCCESS == code) {
12,282✔
1140
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_FUNC_SHOW, 0,
12,282✔
1141
                                  pCxt->pMetaCache);
1142
  }
1143
  return code;
12,282✔
1144
}
1145

1146
static int32_t collectMetaKeyFromShowIndexes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
7,260✔
1147
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_INDEXES,
7,260✔
1148
                                         pCxt->pMetaCache);
1149
  if (TSDB_CODE_SUCCESS == code) {
7,260✔
1150
    code =
1151
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
7,260✔
1152
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1153
  }
1154
  return code;
7,260✔
1155
}
1156

1157
static int32_t collectMetaKeyFromShowStables(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
246,582✔
1158
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STABLES,
246,582✔
1159
                                         pCxt->pMetaCache);
1160
  if (TSDB_CODE_SUCCESS == code) {
246,582✔
1161
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
246,582✔
1162
  }
1163
  if (TSDB_CODE_SUCCESS == code) {
246,582✔
1164
    code =
1165
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
246,582✔
1166
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1167
  }
1168
  return code;
246,582✔
1169
}
1170

1171
static int32_t collectMetaKeyFromShowStreams(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
129,587✔
1172
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STREAMS,
129,587✔
1173
                                         pCxt->pMetaCache);
1174
  if (TSDB_CODE_SUCCESS == code && pStmt->pDbName != NULL) {
129,587✔
1175
    if (TSDB_CODE_SUCCESS == code) {
128,981✔
1176
      code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
128,981✔
1177
    }
1178
    if (TSDB_CODE_SUCCESS == code) {
128,981✔
1179
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
128,981✔
1180
    }
1181
    if (TSDB_CODE_SUCCESS == code) {
128,981✔
1182
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser,
257,680✔
1183
                                    ((SValueNode*)pStmt->pDbName)->literal, NULL, PRIV_DB_USE, PRIV_OBJ_DB,
128,981✔
1184
                                    pCxt->pMetaCache);
1185
    }
1186
  }
1187
  return code;
129,587✔
1188
}
1189

1190
static int32_t collectMetaKeyFromShowTables(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
363,056✔
1191
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TABLES,
363,056✔
1192
                                         pCxt->pMetaCache);
1193
  if (TSDB_CODE_SUCCESS == code) {
363,056✔
1194
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
363,056✔
1195
  }
1196

1197
  if (TSDB_CODE_SUCCESS == code) {
363,056✔
1198
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
363,056✔
1199
  }
1200
  if (TSDB_CODE_SUCCESS == code) {
363,056✔
1201
    code =
1202
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
363,056✔
1203
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1204
  }
1205
  return code;
363,056✔
1206
}
1207

1208
static int32_t collectMetaKeyFromShowFilesets(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
×
1209
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_FILESETS,
×
1210
                                         pCxt->pMetaCache);
1211
  if (TSDB_CODE_SUCCESS == code) {
×
1212
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
×
1213
  }
1214
  if (TSDB_CODE_SUCCESS == code) {
×
1215
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
×
1216
  }
1217
  if (TSDB_CODE_SUCCESS == code) {
×
1218
    code =
1219
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
×
1220
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1221
  }
1222
  return code;
×
1223
}
1224

1225
static int32_t collectMetaKeyFromShowTags(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
719,366✔
1226
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TAGS,
719,366✔
1227
                                         pCxt->pMetaCache);
1228
  if (TSDB_CODE_SUCCESS == code) {
719,366✔
1229
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal,
1,438,526✔
1230
                                   ((SValueNode*)pStmt->pTbName)->literal, pCxt->pMetaCache);
719,366✔
1231
  }
1232
  if (TSDB_CODE_SUCCESS == code) {
719,366✔
1233
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
719,366✔
1234
  }
1235
  if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pTbName) {
719,366✔
1236
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal,
1,438,526✔
1237
                                     ((SValueNode*)pStmt->pTbName)->literal, pCxt->pMetaCache);
719,366✔
1238
  }
1239
  return code;
719,366✔
1240
}
1241

1242
static int32_t collectMetaKeyFromShowStableTags(SCollectMetaKeyCxt* pCxt, SShowTableTagsStmt* pStmt) {
6,480✔
1243
  return collectMetaKeyFromRealTableImpl(pCxt, ((SValueNode*)pStmt->pDbName)->literal,
7,098✔
1244
                                         ((SValueNode*)pStmt->pTbName)->literal, PRIV_TBL_SELECT, PRIV_OBJ_TBL);
6,480✔
1245
}
1246

1247
static int32_t collectMetaKeyFromShowUsers(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
113,250✔
1248
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USERS,
113,250✔
1249
                                         pCxt->pMetaCache);
1250
  if (TSDB_CODE_SUCCESS == code) {
113,250✔
1251
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_USER_SHOW, 0,
113,250✔
1252
                                  pCxt->pMetaCache);
1253
  }
1254
  return code;
113,250✔
1255
}
1256

1257
static int32_t collectMetaKeyFromShowUsersFull(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
15,384✔
1258
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USERS_FULL,
15,384✔
1259
                                         pCxt->pMetaCache);
1260
  if (TSDB_CODE_SUCCESS == code) {
15,384✔
1261
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_USER_SHOW, 0,
15,384✔
1262
                                  pCxt->pMetaCache);
1263
  }
1264
  return code;
15,384✔
1265
}
1266

1267
static int32_t collectMetaKeyFromShowRoles(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
1,420✔
1268
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_ROLES,
1,420✔
1269
                                         pCxt->pMetaCache);
1270
  if (TSDB_CODE_SUCCESS == code) {
1,420✔
1271
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_ROLE_SHOW, 0,
1,420✔
1272
                                  pCxt->pMetaCache);
1273
  }
1274
  return code;
1,420✔
1275
}
1276

1277
static int32_t collectMetaKeyFromShowLicence(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
3,201✔
1278
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_LICENCES,
3,201✔
1279
                                         pCxt->pMetaCache);
1280
  if (TSDB_CODE_SUCCESS == code) {
3,201✔
1281
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_GRANTS_SHOW, 0,
3,201✔
1282
                                  pCxt->pMetaCache);
1283
  }
1284
  return code;
3,201✔
1285
}
1286

1287
static int32_t collectMetaKeyFromShowVgroups(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
265,073✔
1288
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS,
265,073✔
1289
                                         pCxt->pMetaCache);
1290
  if (TSDB_CODE_SUCCESS == code) {
265,073✔
1291
    // just to verify whether the database exists
1292
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
265,073✔
1293
  }
1294
  return code;
265,073✔
1295
}
1296

1297
static int32_t collectMetaKeyFromShowTopics(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
20,894✔
1298
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TOPICS,
20,894✔
1299
                                 pCxt->pMetaCache);
1300
}
1301

1302
static int32_t collectMetaKeyFromShowConsumers(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
16,862✔
1303
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB,
16,862✔
1304
                                         TSDB_PERFS_TABLE_CONSUMERS, pCxt->pMetaCache);
1305
  if (TSDB_CODE_SUCCESS == code) {
16,862✔
1306
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_CONSUMER_SHOW, 0,
16,862✔
1307
                                  pCxt->pMetaCache);
1308
  }
1309
  return code;
16,862✔
1310
}
1311

1312
static int32_t collectMetaKeyFromShowConnections(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,629✔
1313
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB,
2,629✔
1314
                                         TSDB_PERFS_TABLE_CONNECTIONS, pCxt->pMetaCache);
1315
  if (TSDB_CODE_SUCCESS == code) {
2,629✔
1316
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_CONN_SHOW, 0,
2,629✔
1317
                                  pCxt->pMetaCache);
1318
  }
1319
  return code;
2,629✔
1320
}
1321

1322
static int32_t collectMetaKeyFromShowQueries(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
3,532✔
1323
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_QUERIES,
3,532✔
1324
                                         pCxt->pMetaCache);
1325
  if (TSDB_CODE_SUCCESS == code) {
3,532✔
1326
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_QUERY_SHOW, 0,
3,532✔
1327
                                  pCxt->pMetaCache);
1328
  }
1329
  return code;
3,532✔
1330
}
1331

1332
static int32_t collectMetaKeyFromShowVariables(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
10,514✔
1333
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS,
10,514✔
1334
                                 pCxt->pMetaCache);
1335
}
1336

1337
static int32_t collectMetaKeyFromShowDnodeVariables(SCollectMetaKeyCxt* pCxt, SShowDnodeVariablesStmt* pStmt) {
41,091✔
1338
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
41,091✔
1339
                                         TSDB_INS_TABLE_DNODE_VARIABLES, pCxt->pMetaCache);
1340
  if (TSDB_CODE_SUCCESS == code) {
41,091✔
1341
    code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
41,091✔
1342
  }
1343
  return code;
41,091✔
1344
}
1345

1346
static int32_t collectMetaKeyFromShowVnodes(SCollectMetaKeyCxt* pCxt, SShowVnodesStmt* pStmt) {
9,109✔
1347
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VNODES,
9,109✔
1348
                                 pCxt->pMetaCache);
1349
}
1350

1351
static int32_t collectMetaKeyFromShowUserPrivileges(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
3,963✔
1352
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
3,963✔
1353
                                         TSDB_INS_TABLE_USER_PRIVILEGES, pCxt->pMetaCache);
1354
  if (TSDB_CODE_SUCCESS == code) {
3,963✔
1355
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_SHOW_PRIVILEGES, 0,
3,963✔
1356
                                  pCxt->pMetaCache);
1357
  }
1358
  return code;
3,963✔
1359
}
1360

1361
static int32_t collectMetaKeyFromShowRolePrivileges(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
1,210✔
1362
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
1,210✔
1363
                                         TSDB_INS_TABLE_ROLE_PRIVILEGES, pCxt->pMetaCache);
1364
  if (TSDB_CODE_SUCCESS == code) {
1,210✔
1365
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_SHOW_PRIVILEGES, 0,
1,210✔
1366
                                  pCxt->pMetaCache);
1367
  }
1368
  return code;
1,210✔
1369
}
1370

1371
static int32_t collectMetaKeyFromShowRoleColPrivileges(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
×
1372
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
×
1373
                                         TSDB_INS_TABLE_ROLE_COL_PRIVILEGES, pCxt->pMetaCache);
1374
  if (TSDB_CODE_SUCCESS == code) {
×
1375
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_SHOW_PRIVILEGES, 0,
×
1376
                                  pCxt->pMetaCache);
1377
  }
1378
  return code;
×
1379
}
1380

1381
static int32_t collectMetaKeyFromShowViews(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
15,907✔
1382
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VIEWS,
15,907✔
1383
                                         pCxt->pMetaCache);
1384
  if (TSDB_CODE_SUCCESS == code) {
15,907✔
1385
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
15,907✔
1386
  }
1387
  if (TSDB_CODE_SUCCESS == code) {
15,907✔
1388
    code =
1389
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
15,907✔
1390
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1391
  }
1392
  return code;
15,907✔
1393
}
1394

1395
static int32_t collectMetaKeyFromShowCompacts(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
381,226✔
1396
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_COMPACTS,
381,226✔
1397
                                         pCxt->pMetaCache);
1398
  return code;
381,226✔
1399
}
1400

1401
static int32_t collectMetaKeyFromShowScans(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,508✔
1402
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SCANS,
2,508✔
1403
                                         pCxt->pMetaCache);
1404
  return code;
2,508✔
1405
}
1406

1407
static int32_t collectMetaKeyFromShowCompactDetails(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
34,894✔
1408
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
34,894✔
1409
                                         TSDB_INS_TABLE_COMPACT_DETAILS, pCxt->pMetaCache);
1410
  return code;
34,894✔
1411
}
1412

1413
static int32_t collectMetaKeyFromShowScanDetails(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,280✔
1414
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
2,280✔
1415
                                         TSDB_INS_TABLE_SCAN_DETAILS, pCxt->pMetaCache);
1416
  return code;
2,280✔
1417
}
1418

1419
static int32_t collectMetaKeyFromShowSsMigrates(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
93,483✔
1420
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SSMIGRATES,
93,483✔
1421
                                         pCxt->pMetaCache);
1422
  return code;
93,483✔
1423
}
1424

1425
static int32_t collectMetaKeyFromShowTokens(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,021✔
1426
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TOKENS,
2,021✔
1427
                                         pCxt->pMetaCache);
1428
  return code;
2,021✔
1429
}
1430

1431
static int32_t collectMetaKeyFromShowTransactionDetails(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
321✔
1432
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
321✔
1433
                                         TSDB_INS_TABLE_TRANSACTION_DETAILS, pCxt->pMetaCache);
1434
  if (TSDB_CODE_SUCCESS == code) {
321✔
1435
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_TRANS_SHOW, 0,
321✔
1436
                                  pCxt->pMetaCache);
1437
  }
1438
  return code;
321✔
1439
}
1440

1441
static int32_t collectMetaKeyFromShowGrantsFull(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,269✔
1442
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
2,269✔
1443
                                         TSDB_INS_TABLE_GRANTS_FULL, pCxt->pMetaCache);
1444
  if (TSDB_CODE_SUCCESS == code) {
2,269✔
1445
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_GRANTS_SHOW, 0,
2,269✔
1446
                                  pCxt->pMetaCache);
1447
  }
1448
  return code;
2,269✔
1449
}
1450

1451
static int32_t collectMetaKeyFromShowGrantsLogs(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
1,810✔
1452
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
1,810✔
1453
                                         TSDB_INS_TABLE_GRANTS_LOGS, pCxt->pMetaCache);
1454
  if (TSDB_CODE_SUCCESS == code) {
1,810✔
1455
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_GRANTS_SHOW, 0,
1,810✔
1456
                                  pCxt->pMetaCache);
1457
  }
1458
  return code;
1,810✔
1459
}
1460

1461
static int32_t collectMetaKeyFromShowClusterMachines(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,012✔
1462
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MACHINES,
2,012✔
1463
                                         pCxt->pMetaCache);
1464
  if (TSDB_CODE_SUCCESS == code) {
2,012✔
1465
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_GRANTS_SHOW, 0,
2,012✔
1466
                                  pCxt->pMetaCache);
1467
  }
1468
  return code;
2,012✔
1469
}
1470

1471
static int32_t collectMetaKeyFromShowEncryptions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
201✔
1472
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_ENCRYPTIONS,
201✔
1473
                                 pCxt->pMetaCache);
1474
}
1475

1476
static int32_t collectMetaKeyFromShowEncryptAlgorithms(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
826✔
1477
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
826✔
1478
                                         TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, pCxt->pMetaCache);
1479
  return code;
826✔
1480
}
1481

1482
static int32_t collectMetaKeyFromShowEncryptStatus(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
×
1483
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
×
1484
                                         TSDB_INS_TABLE_ENCRYPT_STATUS, pCxt->pMetaCache);
1485
  return code;
×
1486
}
1487

1488
static int32_t collectMetaKeyFromShowMounts(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,053✔
1489
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MOUNTS,
2,053✔
1490
                                         pCxt->pMetaCache);
1491
  if (TSDB_CODE_SUCCESS == code) {
2,053✔
1492
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_MOUNT_SHOW, 0,
2,053✔
1493
                                  pCxt->pMetaCache);
1494
  }
1495
  return code;
2,053✔
1496
}
1497

1498
static int32_t collectMetaKeyFromShowCreateDatabase(SCollectMetaKeyCxt* pCxt, SShowCreateDatabaseStmt* pStmt) {
68,417✔
1499
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
68,417✔
1500
  if (TSDB_CODE_SUCCESS == code) {
68,417✔
1501
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
68,417✔
1502
                                  PRIV_CM_SHOW_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
1503
  }
1504
  return code;
68,417✔
1505
}
1506

1507
static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShowCreateTableStmt* pStmt) {
106,035✔
1508
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
106,035✔
1509
  tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
106,035✔
1510
  tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
106,035✔
1511
  int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
106,035✔
1512
  if (TSDB_CODE_SUCCESS == code) {
106,035✔
1513
    code = reserveTableCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
106,035✔
1514
  }
1515
  if (TSDB_CODE_SUCCESS == code) {
106,035✔
1516
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
106,035✔
1517
  }
1518
  // if (TSDB_CODE_SUCCESS == code) {
1519
  //   code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
1520
  //                                 AUTH_TYPE_READ, pCxt->pMetaCache);
1521
  // }
1522
  if (TSDB_CODE_SUCCESS == code) {
106,035✔
1523
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
106,035✔
1524
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1525
  }
1526
  if (TSDB_CODE_SUCCESS == code) {
106,035✔
1527
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
106,035✔
1528
                                  PRIV_CM_SHOW_CREATE, PRIV_OBJ_TBL, pCxt->pMetaCache);
1529
  }
1530
  return code;
106,035✔
1531
}
1532

1533
static int32_t collectMetaKeyFromShowCreateView(SCollectMetaKeyCxt* pCxt, SShowCreateViewStmt* pStmt) {
9,166✔
1534
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
9,166✔
1535
  tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
9,166✔
1536
  tstrncpy(name.tname, pStmt->viewName, TSDB_TABLE_NAME_LEN);
9,166✔
1537
  char dbFName[TSDB_DB_FNAME_LEN];
9,166✔
1538
  (void)tNameGetFullDbName(&name, dbFName);
9,166✔
1539
  int32_t code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, dbFName, 0, pStmt->viewName, 0);
9,166✔
1540
  if (TSDB_CODE_SUCCESS == code) {
9,166✔
1541
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
9,166✔
1542
  }
1543
  if (TSDB_CODE_SUCCESS == code) {
9,166✔
1544
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
9,166✔
1545
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1546
  }
1547
  if (TSDB_CODE_SUCCESS == code) {
9,166✔
1548
    code = reserveViewUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->viewName,
9,166✔
1549
                                      PRIV_CM_SHOW_CREATE, PRIV_OBJ_VIEW, pCxt->pMetaCache);
1550
  }
1551
  if (TSDB_CODE_SUCCESS == code) {
9,166✔
1552
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, pCxt->pMetaCache);
9,166✔
1553
  }
1554
  pCxt->pMetaCache->forceFetchViewMeta = true;
9,166✔
1555
  return code;
9,166✔
1556
}
1557

1558
static int32_t collectMetaKeyFromShowCreateRsma(SCollectMetaKeyCxt* pCxt, SShowCreateRsmaStmt* pStmt) {
3,468✔
1559
  int32_t code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
3,468✔
1560
                                        PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1561
  if (TSDB_CODE_SUCCESS == code) {
3,468✔
1562
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
3,468✔
1563
  }
1564
  if (TSDB_CODE_SUCCESS == code) {
3,468✔
1565
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->rsmaName,
3,468✔
1566
                                  PRIV_CM_SHOW_CREATE, PRIV_OBJ_RSMA, pCxt->pMetaCache);
1567
  }
1568
  return code;
3,468✔
1569
}
1570

1571
static int32_t collectMetaKeyFromShowApps(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,012✔
1572
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_APPS,
2,012✔
1573
                                         pCxt->pMetaCache);
1574
  if (TSDB_CODE_SUCCESS == code) {
2,012✔
1575
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_APPS_SHOW, 0,
2,012✔
1576
                                  pCxt->pMetaCache);
1577
  }
1578
  return code;
2,012✔
1579
}
1580

1581
static int32_t collectMetaKeyFromShowInstances(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
800✔
1582
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_INSTANCES,
800✔
1583
                                 pCxt->pMetaCache);
1584
}
1585

1586
static int32_t collectMetaKeyFromShowTransactions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
577,690✔
1587
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_TRANS,
577,690✔
1588
                                         pCxt->pMetaCache);
1589
  if (TSDB_CODE_SUCCESS == code) {
577,690✔
1590
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_TRANS_SHOW, 0,
577,690✔
1591
                                  pCxt->pMetaCache);
1592
  }
1593
  return code;
577,690✔
1594
}
1595

1596
static int32_t collectMetaKeyFromDelete(SCollectMetaKeyCxt* pCxt, SDeleteStmt* pStmt) {
1,974,116✔
1597
  STableNode* pTable = (STableNode*)pStmt->pFromTable;
1,974,116✔
1598
  return collectMetaKeyFromRealTableImpl(pCxt, pTable->dbName, pTable->tableName, PRIV_TBL_DELETE, PRIV_OBJ_TBL);
1,974,116✔
1599
}
1600

1601
static int32_t collectMetaKeyFromInsert(SCollectMetaKeyCxt* pCxt, SInsertStmt* pStmt) {
527,348✔
1602
  STableNode* pTable = (STableNode*)pStmt->pTable;
527,348✔
1603
  int32_t     code =
1604
      collectMetaKeyFromRealTableImpl(pCxt, pTable->dbName, pTable->tableName, PRIV_TBL_INSERT, PRIV_OBJ_TBL);
527,348✔
1605
  if (TSDB_CODE_SUCCESS == code) {
527,348✔
1606
    code = collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
527,348✔
1607
  }
1608
  return code;
527,348✔
1609
}
1610

1611
static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTableDistributedStmt* pStmt) {
3,703✔
1612
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
3,703✔
1613
  tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
3,703✔
1614
  tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
3,703✔
1615
  int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
3,703✔
1616
  if (TSDB_CODE_SUCCESS == code) {
3,703✔
1617
    code = collectMetaKeyFromRealTableImpl(pCxt, pStmt->dbName, pStmt->tableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL);
3,703✔
1618
  }
1619
  return code;
3,703✔
1620
}
1621
static int32_t collectMetaKeyFromShowValidateVtable(SCollectMetaKeyCxt* pCxt, SShowValidateVirtualTable* pStmt) {
3,978✔
1622
  // Collect database information
1623
  int32_t code = 0;
3,978✔
1624

1625
  code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
3,978✔
1626
                                 TSDB_INS_TABLE_VIRTUAL_TABLES_REFERENCING, pCxt->pMetaCache);
1627
  if (TSDB_CODE_SUCCESS == code && pStmt->tableName[0] != 0) {
3,978✔
1628
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
3,978✔
1629
  }
1630

1631
  if (TSDB_CODE_SUCCESS == code) {
3,978✔
1632
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
3,978✔
1633
  }
1634
  if (TSDB_CODE_SUCCESS == code && pStmt->tableName[0] != 0) {
3,978✔
1635
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
3,978✔
1636
  }
1637
  return code;
3,978✔
1638
}
1639

1640
static int32_t collectMetaKeyFromShowSubscriptions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
26,261✔
1641
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SUBSCRIPTIONS,
26,261✔
1642
                                 pCxt->pMetaCache);
1643
}
1644

1645
static int32_t collectMetaKeyFromCompactDatabase(SCollectMetaKeyCxt* pCxt, SCompactDatabaseStmt* pStmt) {
31,937✔
1646
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
31,937✔
1647
  if (TSDB_CODE_SUCCESS == code) {
31,937✔
1648
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_COMPACT,
31,937✔
1649
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1650
  }
1651
  return code;
31,937✔
1652
}
1653

1654
static int32_t collectMetaKeyFromRollupDatabase(SCollectMetaKeyCxt* pCxt, SRollupDatabaseStmt* pStmt) {
12,376✔
1655
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
12,376✔
1656
  if (TSDB_CODE_SUCCESS == code) {
12,376✔
1657
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_ROLLUP,
12,376✔
1658
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1659
  }
1660
  return code;
12,376✔
1661
}
1662

1663
static int32_t collectMetaKeyFromScanDatabase(SCollectMetaKeyCxt* pCxt, SScanDatabaseStmt* pStmt) {
879✔
1664
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
879✔
1665
  if (TSDB_CODE_SUCCESS == code) {
879✔
1666
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_SCAN,
879✔
1667
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1668
  }
1669
  return code;
879✔
1670
}
1671

1672
static int32_t collectMetaKeyFromSsmigrateDatabase(SCollectMetaKeyCxt* pCxt, SSsMigrateDatabaseStmt* pStmt) {
3,315✔
1673
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
3,315✔
1674
  if (TSDB_CODE_SUCCESS == code) {
3,315✔
1675
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
3,315✔
1676
                                  PRIV_DB_SSMIGRATE, PRIV_OBJ_DB, pCxt->pMetaCache);
1677
  }
1678
  return code;
3,315✔
1679
}
1680

1681
static int32_t collectMetaKeyFromTrimDatabase(SCollectMetaKeyCxt* pCxt, STrimDatabaseStmt* pStmt) {
9,996✔
1682
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
9,996✔
1683
  if (TSDB_CODE_SUCCESS == code) {
9,996✔
1684
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_TRIM,
9,996✔
1685
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1686
  }
1687
  return code;
9,996✔
1688
}
1689

1690
static int32_t collectMetaKeyFromCompactVgroups(SCollectMetaKeyCxt* pCxt, SCompactVgroupsStmt* pStmt) {
4,130✔
1691
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
4,130✔
1692
}
1693

1694
static int32_t collectMetaKeyFromRollupVgroups(SCollectMetaKeyCxt* pCxt, SRollupVgroupsStmt* pStmt) {
4,794✔
1695
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
4,794✔
1696
}
1697

1698
static int32_t collectMetaKeyFromScanVgroups(SCollectMetaKeyCxt* pCxt, SScanVgroupsStmt* pStmt) {
285✔
1699
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
285✔
1700
}
1701

1702
static int32_t collectMetaKeyFromGrantImpl(SCollectMetaKeyCxt* pCxt, SGrantStmt* pStmt, bool grant) {
1,515,354✔
1703
  int32_t code = TSDB_CODE_SUCCESS;
1,515,354✔
1704

1705
  if (pStmt->optrType == TSDB_ALTER_ROLE_ROLE) {
1,515,354✔
1706
    if (pStmt->roleName[0] == 'S' && pStmt->roleName[1] == 'Y' && pStmt->roleName[2] == 'S') {
18,461✔
1707
      if (strcmp(pStmt->roleName, TSDB_ROLE_SYSDBA) == 0) {
16,888✔
1708
        return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
3,045✔
1709
                                      grant ? PRIV_GRANT_SYSDBA : PRIV_REVOKE_SYSDBA, 0, pCxt->pMetaCache);
1710
      }
1711
      if (strcmp(pStmt->roleName, TSDB_ROLE_SYSSEC) == 0) {
13,843✔
1712
        return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
3,465✔
1713
                                      grant ? PRIV_GRANT_SYSSEC : PRIV_REVOKE_SYSSEC, 0, pCxt->pMetaCache);
1714
      }
1715
      if (strcmp(pStmt->roleName, TSDB_ROLE_SYSAUDIT) == 0) {
10,378✔
1716
        return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
2,089✔
1717
                                      grant ? PRIV_GRANT_SYSAUDIT : PRIV_REVOKE_SYSAUDIT, 0, pCxt->pMetaCache);
1718
      }
1719
    }
1720
  } else if (TSDB_ALTER_ROLE_PRIVILEGES == pStmt->optrType) {
1,496,893✔
1721
    bool isRealObj = IS_SPECIFIC_OBJ(pStmt->objName);
1,496,893✔
1722
    if (isRealObj) {
1,496,893✔
1723
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->objName, pCxt->pMetaCache);
1,470,920✔
1724
    }
1725
    if (TSDB_CODE_SUCCESS == code) {
1,496,893✔
1726
      if (isRealObj && IS_SPECIFIC_OBJ(pStmt->tabName)) {
1,496,893✔
1727
        if (PRIV_OBJ_TBL == pStmt->privileges.objType) {
707,123✔
1728
          code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
12,609✔
1729
        } else if (PRIV_OBJ_VIEW == pStmt->privileges.objType || PRIV_OBJ_NONE == pStmt->privileges.objType) {
694,514✔
1730
          code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
683,765✔
1731
          pCxt->pMetaCache->forceFetchViewMeta = true;
683,765✔
1732
        } else {
1733
          // TODO: other object types
1734
        }
1735
      }
1736
    }
1737
  }
1738
  if (TSDB_CODE_SUCCESS == code) {
1,506,755✔
1739
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
1,506,755✔
1740
                                  grant ? PRIV_GRANT_PRIVILEGE : PRIV_REVOKE_PRIVILEGE, 0, pCxt->pMetaCache);
1741
  }
1742

1743
  return code;
1,506,755✔
1744
}
1745

1746
static int32_t collectMetaKeyFromGrant(SCollectMetaKeyCxt* pCxt, SGrantStmt* pStmt) {
992,432✔
1747
  return collectMetaKeyFromGrantImpl(pCxt, pStmt, true);
992,432✔
1748
}
1749

1750
static int32_t collectMetaKeyFromRevoke(SCollectMetaKeyCxt* pCxt, SRevokeStmt* pStmt) {
522,922✔
1751
  return collectMetaKeyFromGrantImpl(pCxt, (SGrantStmt*)pStmt, false);
522,922✔
1752
}
1753

1754
static int32_t collectMetaKeyFromCreateViewStmt(SCollectMetaKeyCxt* pCxt, SCreateViewStmt* pStmt) {
236,165✔
1755
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, pCxt->pMetaCache);
236,165✔
1756

1757
  if (TSDB_CODE_SUCCESS == code) {
236,165✔
1758
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
236,165✔
1759
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1760
  }
1761
  if (TSDB_CODE_SUCCESS == code) {
236,165✔
1762
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
236,165✔
1763
  }
1764

1765
  if (TSDB_CODE_SUCCESS == code) {
236,165✔
1766
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
236,165✔
1767
                                  PRIV_VIEW_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
1768
  }
1769
  if (TSDB_CODE_SUCCESS == code && pStmt->orReplace) {
236,165✔
1770
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->viewName,
21,369✔
1771
                                  PRIV_CM_ALTER, PRIV_OBJ_VIEW, pCxt->pMetaCache);
1772
  }
1773
  if (TSDB_CODE_SUCCESS == code) {
236,165✔
1774
    if (!pStmt->pQuery ||
236,165✔
1775
        (QUERY_NODE_SELECT_STMT != nodeType(pStmt->pQuery) && QUERY_NODE_SET_OPERATOR != nodeType(pStmt->pQuery))) {
236,165✔
1776
      code = TSDB_CODE_PAR_INVALID_VIEW_QUERY;
×
1777
    } else {
1778
      code = collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
236,165✔
1779
    }
1780
  }
1781

1782
  return code;
236,165✔
1783
}
1784

1785
static int32_t collectMetaKeyFromDropViewStmt(SCollectMetaKeyCxt* pCxt, SDropViewStmt* pStmt) {
177,169✔
1786
  int32_t code = reserveViewUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName,
354,338✔
1787
                                            pStmt->viewName, PRIV_CM_DROP, PRIV_OBJ_VIEW, pCxt->pMetaCache);
177,169✔
1788
  pCxt->pMetaCache->forceFetchViewMeta = true;
177,169✔
1789
  if (TSDB_CODE_SUCCESS == code) {
177,169✔
1790
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
177,169✔
1791
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1792
  }
1793
  if (TSDB_CODE_SUCCESS == code) {
177,169✔
1794
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
177,169✔
1795
  }
1796
  if (TSDB_CODE_SUCCESS == code) {
177,169✔
1797
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, pCxt->pMetaCache);
177,169✔
1798
  }
1799
  return code;
177,169✔
1800
}
1801

1802
static int32_t collectMetaKeyFromCreateTSMAStmt(SCollectMetaKeyCxt* pCxt, SCreateTSMAStmt* pStmt) {
8,561✔
1803
  int32_t code;
1804
  if (pStmt->pOptions->recursiveTsma) {
8,561✔
1805
    // if creating recursive tsma, the tablename is tsmaName
1806
    code = reserveTSMAInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
1,260✔
1807
    if (TSDB_CODE_SUCCESS == code) {
1,260✔
1808
      char dstTbName[TSDB_TABLE_NAME_LEN] = {0};
1,260✔
1809
      snprintf(dstTbName, TSDB_TABLE_NAME_LEN, "%s" TSMA_RES_STB_POSTFIX, pStmt->tableName);
1,260✔
1810
      code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, dstTbName, pCxt->pMetaCache);
1,260✔
1811
      if (TSDB_CODE_SUCCESS == code) {
1,260✔
1812
        code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, dstTbName, pCxt->pMetaCache);
1,260✔
1813
      }
1814
    }
1815
  } else {
1816
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
7,301✔
1817
    if (TSDB_CODE_SUCCESS == code) {
7,301✔
1818
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
7,301✔
1819
    }
1820
    if (TSDB_CODE_SUCCESS == code) {
7,301✔
1821
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
7,301✔
1822
                                    PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache);
1823
    }
1824
    if (TSDB_CODE_SUCCESS == code) {
7,301✔
1825
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
7,301✔
1826
                                    PRIV_STREAM_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
1827
    }
1828
    if (TSDB_CODE_SUCCESS == code) {
7,301✔
1829
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
7,301✔
1830
                                    PRIV_TSMA_CREATE, PRIV_OBJ_TBL, pCxt->pMetaCache);
1831
    }
1832
  }
1833
  if (TSDB_CODE_SUCCESS == code) {
8,561✔
1834
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
8,561✔
1835
  }
1836
  if (TSDB_CODE_SUCCESS == code) {
8,561✔
1837
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
8,561✔
1838
  }
1839

1840
  if (TSDB_CODE_SUCCESS == code) {
8,561✔
1841
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
8,561✔
1842
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1843
  }
1844
  if (TSDB_CODE_SUCCESS == code) {
8,561✔
1845
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_TBL_CREATE,
8,561✔
1846
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1847
  }
1848

1849
  return code;
8,561✔
1850
}
1851

1852
static int32_t collectMetaKeyFromDropTSMAStmt(SCollectMetaKeyCxt* pCxt, SDropTSMAStmt* pStmt) {
4,112✔
1853
  int32_t code;
1854
  code = reserveTSMAInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, pCxt->pMetaCache);
4,112✔
1855
  if (TSDB_CODE_SUCCESS == code) {
4,112✔
1856
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
4,112✔
1857
  }
1858
  if (TSDB_CODE_SUCCESS == code) {
4,112✔
1859
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
4,112✔
1860
  }
1861

1862
  if (TSDB_CODE_SUCCESS == code) {
4,112✔
1863
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
4,112✔
1864
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1865
  }
1866
  if (TSDB_CODE_SUCCESS == code) {
4,112✔
1867
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tsmaName,
4,112✔
1868
                                  PRIV_CM_DROP, PRIV_OBJ_TSMA, pCxt->pMetaCache);
1869
  }
1870
  return code;
4,112✔
1871
}
1872

1873
static int32_t collectMetaKeyFromShowUsage(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
377✔
1874
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_DISK_USAGE,
377✔
1875
                                         pCxt->pMetaCache);
1876
  if (TSDB_CODE_SUCCESS == code) {
377✔
1877
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
377✔
1878
  }
1879
  if (TSDB_CODE_SUCCESS == code) {
377✔
1880
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
377✔
1881
  }
1882
  if (TSDB_CODE_SUCCESS == code) {
377✔
1883
    code =
1884
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
377✔
1885
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1886
  }
1887
  return code;
377✔
1888
}
1889

1890
static int32_t collectMetaKeyFromShowTSMASStmt(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
459✔
1891
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TSMAS,
459✔
1892
                                 pCxt->pMetaCache);
1893
}
1894

1895
static int32_t collectMetaKeyFromCreateRsmaStmt(SCollectMetaKeyCxt* pCxt, SCreateRsmaStmt* pStmt) {
121,074✔
1896
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
121,074✔
1897
  if (TSDB_CODE_SUCCESS == code) {
121,074✔
1898
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
121,074✔
1899
  }
1900
  if (TSDB_CODE_SUCCESS == code) {
121,074✔
1901
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
121,074✔
1902
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1903
  }
1904
  if (TSDB_CODE_SUCCESS == code) {
121,074✔
1905
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
121,074✔
1906
                                  PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache);
1907
  }
1908
  if (TSDB_CODE_SUCCESS == code) {
121,074✔
1909
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
121,074✔
1910
                                  PRIV_TBL_INSERT, PRIV_OBJ_TBL, pCxt->pMetaCache);
1911
  }
1912
  if (TSDB_CODE_SUCCESS == code) {
121,074✔
1913
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
121,074✔
1914
                                  PRIV_RSMA_CREATE, PRIV_OBJ_TBL, pCxt->pMetaCache);
1915
  }
1916
  return code;
121,074✔
1917
}
1918

1919
static int32_t collectMetaKeyFromDropRsmaStmt(SCollectMetaKeyCxt* pCxt, SDropRsmaStmt* pStmt) {
11,152✔
1920
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
11,152✔
1921
  if (TSDB_CODE_SUCCESS == code) {
11,152✔
1922
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
11,152✔
1923
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1924
  }
1925
  if (TSDB_CODE_SUCCESS == code) {
11,152✔
1926
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->rsmaName,
11,152✔
1927
                                  PRIV_CM_DROP, PRIV_OBJ_RSMA, pCxt->pMetaCache);
1928
  }
1929
  return code;
11,152✔
1930
}
1931

1932
static int32_t collectMetaKeyFromAlterRsmaStmt(SCollectMetaKeyCxt* pCxt, SAlterRsmaStmt* pStmt) {
22,491✔
1933
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
22,491✔
1934
  if (TSDB_CODE_SUCCESS == code) {
22,491✔
1935
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->rsmaName,
22,491✔
1936
                                  PRIV_CM_ALTER, PRIV_OBJ_RSMA, pCxt->pMetaCache);
1937
  }
1938
  return code;
22,491✔
1939
}
1940

1941
static int32_t collectMetaKeyFromShowRsmasStmt(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
14,841✔
1942
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_RSMAS,
14,841✔
1943
                                 pCxt->pMetaCache);
1944
}
1945

1946
static int32_t collectMetaKeyFromShowRetentionsStmt(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
42,432✔
1947
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_RETENTIONS,
42,432✔
1948
                                 pCxt->pMetaCache);
1949
}
1950

1951
static int32_t collectMetaKeyFromShowRetentionDetailsStmt(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
2,397✔
1952
  return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_RETENTION_DETAILS,
2,397✔
1953
                                 pCxt->pMetaCache);
1954
}
1955

1956
static int32_t collectMetaKeyFromShowAlive(SCollectMetaKeyCxt* pCxt, SShowAliveStmt* pStmt) {
5,846✔
1957
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS,
5,846✔
1958
                                         pCxt->pMetaCache);
1959
  if (TSDB_CODE_SUCCESS == code && pStmt->dbName[0]) {
5,846✔
1960
    // just to verify whether the database exists
1961
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
1,780✔
1962
  }
1963
  return code;
5,846✔
1964
}
1965

1966
static int32_t collectMetaKeyFromAlterLocalStmt(SCollectMetaKeyCxt* pCxt, SAlterLocalStmt* pStmt) {
513,299✔
1967
  if ('\0' == pStmt->value[0]) {
513,299✔
1968
    char* p = strchr(pStmt->config, ' ');
6,490✔
1969
    if (NULL != p) {
6,490✔
1970
      *p = 0;
6,035✔
1971
      tstrncpy(pStmt->value, p + 1, sizeof(pStmt->value));
6,035✔
1972
    }
1973
  }
1974
  int32_t privType = cfgGetPrivType(tsCfg, pStmt->config, 0);
513,299✔
1975
  return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, privType, 0,
513,299✔
1976
                                pCxt->pMetaCache);
1977
  return TSDB_CODE_SUCCESS;
1978
}
1979

1980
EPrivType getAlterUserPrivType(const char* pCurrentUser, const SAlterUserStmt* pStmt) {
129,064✔
1981
  EPrivType     privType = PRIV_USER_ALTER;
129,064✔
1982
  SUserOptions* pOptions = pStmt->pUserOptions;
129,064✔
1983
  if ((pOptions->hasPassword) &&
129,064✔
1984
      !(pOptions->hasTotpseed || pOptions->hasEnable || pOptions->hasSysinfo || pOptions->hasIsImport ||
77,660✔
1985
        pOptions->hasChangepass || pOptions->hasCreatedb || pOptions->hasSessionPerUser || pOptions->hasConnectTime ||
77,660✔
1986
        pOptions->hasConnectIdleTime || pOptions->hasCallPerSession || pOptions->hasVnodePerCall ||
77,660✔
1987
        pOptions->hasFailedLoginAttempts || pOptions->hasPasswordLifeTime || pOptions->hasPasswordReuseTime ||
77,660✔
1988
        pOptions->hasPasswordReuseMax || pOptions->hasPasswordLockTime || pOptions->hasPasswordGraceTime ||
77,660✔
1989
        pOptions->hasInactiveAccountTime || pOptions->hasAllowTokenNum || pOptions->pSecurityLevels)) {
77,660✔
1990
    if (pCurrentUser && strcmp(pCurrentUser, pStmt->userName) == 0) {
77,660✔
1991
      privType = PRIV_PASS_ALTER_SELF;
7,092✔
1992
    } else {
1993
      privType = PRIV_PASS_ALTER;
70,568✔
1994
    }
1995
  }
1996
  return privType;
129,064✔
1997
}
1998

1999
static int32_t collectMetaKeyFromAlterUserStmt(SCollectMetaKeyCxt* pCxt, SAlterUserStmt* pStmt) {
64,532✔
2000
  EPrivType privType = getAlterUserPrivType(pCxt->pParseCxt->pUser, pStmt);
64,532✔
2001
  return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, privType, 0,
64,532✔
2002
                                pCxt->pMetaCache);
2003
}
2004

2005
static int32_t collectMetaKeyFromSysPrivStmt(SCollectMetaKeyCxt* pCxt, EPrivType privType) {
767,818✔
2006
  return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, privType, 0,
767,818✔
2007
                                pCxt->pMetaCache);
2008
}
2009

2010
static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
1,067,775,926✔
2011
  int32_t code = 0;
1,067,775,926✔
2012
  SNode*  pOrigStmt = pCxt->pStmt;
1,067,775,926✔
2013
  pCxt->pStmt = pStmt;
1,067,778,045✔
2014

2015
  switch (nodeType(pStmt)) {
1,067,777,792✔
2016
    case QUERY_NODE_SET_OPERATOR:
15,395,988✔
2017
      code = collectMetaKeyFromSetOperator(pCxt, (SSetOperator*)pStmt);
15,395,988✔
2018
      break;
15,397,394✔
2019
    case QUERY_NODE_SELECT_STMT:
761,361,280✔
2020
      code = collectMetaKeyFromSelect(pCxt, (SSelectStmt*)pStmt);
761,361,280✔
2021
      break;
761,387,276✔
2022
    case QUERY_NODE_ALTER_DATABASE_STMT:
212,604✔
2023
      code = collectMetaKeyFromAlterDatabase(pCxt, (SAlterDatabaseStmt*)pStmt);
212,604✔
2024
      break;
212,604✔
2025
    case QUERY_NODE_FLUSH_DATABASE_STMT:
2,034,894✔
2026
      code = collectMetaKeyFromFlushDatabase(pCxt, (SFlushDatabaseStmt*)pStmt);
2,034,894✔
2027
      break;
2,034,894✔
2028
    case QUERY_NODE_CREATE_TABLE_STMT:
9,758,176✔
2029
      code = collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt);
9,758,176✔
2030
      break;
9,758,176✔
2031
    case QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT:
238,349✔
2032
      code = collectMetaKeyFromCreateVTable(pCxt, (SCreateVTableStmt*)pStmt);
238,349✔
2033
      break;
238,349✔
2034
    case QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT:
419,330✔
2035
      code = collectMetaKeyFromCreateVSubTable(pCxt, (SCreateVSubTableStmt*)pStmt);
419,330✔
2036
      break;
419,330✔
2037
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
38,056,071✔
2038
      code = collectMetaKeyFromCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
38,056,071✔
2039
      break;
38,058,945✔
2040
    case QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE:
1,491✔
2041
      code = collectMetaKeyFromCreateSubTableFromFile(pCxt, (SCreateSubTableFromFileClause*)pStmt);
1,491✔
2042
      break;
1,491✔
2043
    case QUERY_NODE_DROP_TABLE_STMT:
2,677,053✔
2044
      code = collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
2,677,053✔
2045
      break;
2,677,053✔
2046
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
103,513✔
2047
      code = collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
103,513✔
2048
      break;
103,513✔
2049
    case QUERY_NODE_DROP_VIRTUAL_TABLE_STMT:
80,108✔
2050
      code = collectMetaKeyFromDropVtable(pCxt, (SDropVirtualTableStmt*)pStmt);
80,108✔
2051
      break;
80,108✔
2052
    case QUERY_NODE_ALTER_TABLE_STMT:
20,382,505✔
2053
      code = collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
20,382,505✔
2054
      break;
20,382,505✔
2055
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
571,286✔
2056
      code = collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt);
571,286✔
2057
      break;
571,286✔
2058
    case QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT:
458,274✔
2059
      code = collectMetaKeyFromAlterVtable(pCxt, (SAlterTableStmt*)pStmt);
458,274✔
2060
      break;
458,274✔
2061
    case QUERY_NODE_USE_DATABASE_STMT:
98,379,755✔
2062
      code = collectMetaKeyFromUseDatabase(pCxt, (SUseDatabaseStmt*)pStmt);
98,379,755✔
2063
      break;
98,383,349✔
2064
    case QUERY_NODE_CREATE_INDEX_STMT:
23,767✔
2065
      code = collectMetaKeyFromCreateIndex(pCxt, (SCreateIndexStmt*)pStmt);
23,767✔
2066
      break;
23,767✔
2067
    case QUERY_NODE_DROP_INDEX_STMT:
11,209✔
2068
      code = collectMetaKeyFromDropIndex(pCxt, (SDropIndexStmt*)pStmt);
11,209✔
2069
      break;
11,209✔
2070
    case QUERY_NODE_CREATE_TOPIC_STMT:
206,520✔
2071
      code = collectMetaKeyFromCreateTopic(pCxt, (SCreateTopicStmt*)pStmt);
206,520✔
2072
      break;
206,520✔
2073
    case QUERY_NODE_EXPLAIN_STMT:
100,328,740✔
2074
      code = collectMetaKeyFromExplain(pCxt, (SExplainStmt*)pStmt);
100,328,740✔
2075
      break;
100,342,884✔
2076
    case QUERY_NODE_DESCRIBE_STMT:
583,950✔
2077
      code = collectMetaKeyFromDescribe(pCxt, (SDescribeStmt*)pStmt);
583,950✔
2078
      break;
583,950✔
2079
    case QUERY_NODE_COMPACT_DATABASE_STMT:
31,937✔
2080
      code = collectMetaKeyFromCompactDatabase(pCxt, (SCompactDatabaseStmt*)pStmt);
31,937✔
2081
      break;
31,937✔
2082
    case QUERY_NODE_ROLLUP_DATABASE_STMT:
12,376✔
2083
      code = collectMetaKeyFromRollupDatabase(pCxt, (SRollupDatabaseStmt*)pStmt);
12,376✔
2084
      break;
12,376✔
2085
    case QUERY_NODE_SCAN_DATABASE_STMT:
879✔
2086
      code = collectMetaKeyFromScanDatabase(pCxt, (SScanDatabaseStmt*)pStmt);
879✔
2087
      break;
879✔
2088
    case QUERY_NODE_SSMIGRATE_DATABASE_STMT:
3,315✔
2089
      code = collectMetaKeyFromSsmigrateDatabase(pCxt, (SSsMigrateDatabaseStmt*)pStmt);
3,315✔
2090
      break;
3,315✔
2091
    case QUERY_NODE_TRIM_DATABASE_STMT:
9,996✔
2092
      code = collectMetaKeyFromTrimDatabase(pCxt, (STrimDatabaseStmt*)pStmt);
9,996✔
2093
      break;
9,996✔
2094
    case QUERY_NODE_COMPACT_VGROUPS_STMT:
4,130✔
2095
      code = collectMetaKeyFromCompactVgroups(pCxt, (SCompactVgroupsStmt*)pStmt);
4,130✔
2096
      break;
4,130✔
2097
    case QUERY_NODE_ROLLUP_VGROUPS_STMT:
4,794✔
2098
      code = collectMetaKeyFromRollupVgroups(pCxt, (SRollupVgroupsStmt*)pStmt);
4,794✔
2099
      break;
4,794✔
2100
    case QUERY_NODE_SCAN_VGROUPS_STMT:
285✔
2101
      code = collectMetaKeyFromScanVgroups(pCxt, (SScanVgroupsStmt*)pStmt);
285✔
2102
      break;
285✔
2103
    case QUERY_NODE_CREATE_STREAM_STMT:
405,832✔
2104
      code = collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
405,832✔
2105
      break;
405,832✔
2106
    case QUERY_NODE_RECALCULATE_STREAM_STMT:
13,089✔
2107
      code = collectMetaKeyFromRecalculateStream(pCxt, (SRecalcStreamStmt*)pStmt);
13,089✔
2108
      break;
13,089✔
2109
    case QUERY_NODE_GRANT_STMT:
992,432✔
2110
      code = collectMetaKeyFromGrant(pCxt, (SGrantStmt*)pStmt);
992,432✔
2111
      break;
992,432✔
2112
    case QUERY_NODE_REVOKE_STMT:
522,922✔
2113
      code = collectMetaKeyFromRevoke(pCxt, (SRevokeStmt*)pStmt);
522,922✔
2114
      break;
522,922✔
2115
    case QUERY_NODE_SHOW_DNODES_STMT:
25,147✔
2116
      code = collectMetaKeyFromShowDnodes(pCxt, (SShowStmt*)pStmt);
25,147✔
2117
      break;
25,147✔
2118
    case QUERY_NODE_SHOW_MNODES_STMT:
362,576✔
2119
      code = collectMetaKeyFromShowMnodes(pCxt, (SShowStmt*)pStmt);
362,576✔
2120
      break;
362,576✔
2121
    case QUERY_NODE_SHOW_MODULES_STMT:
×
2122
      code = collectMetaKeyFromShowModules(pCxt, (SShowStmt*)pStmt);
×
2123
      break;
×
2124
    case QUERY_NODE_SHOW_QNODES_STMT:
2,065✔
2125
      code = collectMetaKeyFromShowQnodes(pCxt, (SShowStmt*)pStmt);
2,065✔
2126
      break;
2,065✔
2127
    case QUERY_NODE_SHOW_SNODES_STMT:
75,475✔
2128
      code = collectMetaKeyFromShowSnodes(pCxt, (SShowStmt*)pStmt);
75,475✔
2129
      break;
75,475✔
2130
    case QUERY_NODE_SHOW_ANODES_STMT:
193✔
2131
      code = collectMetaKeyFromShowAnodes(pCxt, (SShowStmt*)pStmt);
193✔
2132
      break;
193✔
2133
    case QUERY_NODE_SHOW_ANODES_FULL_STMT:
×
2134
      code = collectMetaKeyFromShowAnodesFull(pCxt, (SShowStmt*)pStmt);
×
2135
      break;
×
2136
    case QUERY_NODE_SHOW_BNODES_STMT:
65,366✔
2137
      code = collectMetaKeyFromShowBnodes(pCxt, (SShowStmt*)pStmt);
65,366✔
2138
      break;
65,366✔
2139
    case QUERY_NODE_SHOW_BACKUP_NODES_STMT:
×
2140
      code = collectMetaKeyFromShowBackupNodes(pCxt, (SShowStmt*)pStmt);
×
2141
      break;
×
2142
    case QUERY_NODE_SHOW_XNODES_STMT:
2,361✔
2143
      code = collectMetaKeyFromShowXnodes(pCxt, (SShowStmt*)pStmt);
2,361✔
2144
      break;
2,361✔
2145
    case QUERY_NODE_SHOW_XNODE_TASKS_STMT:
7,229✔
2146
      code = collectMetaKeyFromShowXnodeTasks(pCxt, (SShowStmt*)pStmt);
7,229✔
2147
      break;
7,229✔
2148
    case QUERY_NODE_SHOW_XNODE_AGENTS_STMT:
4,310✔
2149
      code = collectMetaKeyFromShowXnodeAgents(pCxt, (SShowStmt*)pStmt);
4,310✔
2150
      break;
4,310✔
2151
    case QUERY_NODE_SHOW_XNODE_JOBS_STMT:
5,283✔
2152
      code = collectMetaKeyFromShowXnodeJobs(pCxt, (SShowStmt*)pStmt);
5,283✔
2153
      break;
5,283✔
2154
    case QUERY_NODE_SHOW_ARBGROUPS_STMT:
741✔
2155
      code = collectMetaKeyFromShowArbGroups(pCxt, (SShowStmt*)pStmt);
741✔
2156
      break;
741✔
2157
    case QUERY_NODE_SHOW_CLUSTER_STMT:
2,622✔
2158
      code = collectMetaKeyFromShowCluster(pCxt, (SShowStmt*)pStmt);
2,622✔
2159
      break;
2,622✔
2160
    case QUERY_NODE_SHOW_SECURITY_POLICIES_STMT:
516✔
2161
      code = collectMetaKeyFromShowSecurityPolicies(pCxt, (SShowStmt*)pStmt);
516✔
2162
      break;
516✔
2163
    case QUERY_NODE_SHOW_DATABASES_STMT:
206,006✔
2164
      code = collectMetaKeyFromShowDatabases(pCxt, (SShowStmt*)pStmt);
206,006✔
2165
      break;
206,006✔
2166
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
12,282✔
2167
      code = collectMetaKeyFromShowFunctions(pCxt, (SShowStmt*)pStmt);
12,282✔
2168
      break;
12,282✔
2169
    case QUERY_NODE_SHOW_INDEXES_STMT:
7,260✔
2170
      code = collectMetaKeyFromShowIndexes(pCxt, (SShowStmt*)pStmt);
7,260✔
2171
      break;
7,260✔
2172
    case QUERY_NODE_SHOW_STABLES_STMT:
246,582✔
2173
      code = collectMetaKeyFromShowStables(pCxt, (SShowStmt*)pStmt);
246,582✔
2174
      break;
246,582✔
2175
    case QUERY_NODE_SHOW_STREAMS_STMT:
129,587✔
2176
      code = collectMetaKeyFromShowStreams(pCxt, (SShowStmt*)pStmt);
129,587✔
2177
      break;
129,587✔
2178
    case QUERY_NODE_SHOW_TABLES_STMT:
363,056✔
2179
    case QUERY_NODE_SHOW_VTABLES_STMT:
2180
      code = collectMetaKeyFromShowTables(pCxt, (SShowStmt*)pStmt);
363,056✔
2181
      break;
363,056✔
2182
    case QUERY_NODE_SHOW_FILESETS_STMT:
×
2183
      code = collectMetaKeyFromShowFilesets(pCxt, (SShowStmt*)pStmt);
×
2184
      break;
×
2185
    case QUERY_NODE_SHOW_TAGS_STMT:
719,366✔
2186
      code = collectMetaKeyFromShowTags(pCxt, (SShowStmt*)pStmt);
719,366✔
2187
      break;
719,366✔
2188
    case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
6,480✔
2189
      code = collectMetaKeyFromShowStableTags(pCxt, (SShowTableTagsStmt*)pStmt);
6,480✔
2190
      break;
6,480✔
2191
    case QUERY_NODE_SHOW_USERS_STMT:
113,250✔
2192
      code = collectMetaKeyFromShowUsers(pCxt, (SShowStmt*)pStmt);
113,250✔
2193
      break;
113,250✔
2194
    case QUERY_NODE_SHOW_USERS_FULL_STMT:
15,384✔
2195
      code = collectMetaKeyFromShowUsersFull(pCxt, (SShowStmt*)pStmt);
15,384✔
2196
      break;
15,384✔
2197
    case QUERY_NODE_SHOW_ROLES_STMT:
1,420✔
2198
      code = collectMetaKeyFromShowRoles(pCxt, (SShowStmt*)pStmt);
1,420✔
2199
      break;
1,420✔
2200
    case QUERY_NODE_SHOW_LICENCES_STMT:
3,201✔
2201
      code = collectMetaKeyFromShowLicence(pCxt, (SShowStmt*)pStmt);
3,201✔
2202
      break;
3,201✔
2203
    case QUERY_NODE_SHOW_VGROUPS_STMT:
265,073✔
2204
      code = collectMetaKeyFromShowVgroups(pCxt, (SShowStmt*)pStmt);
265,073✔
2205
      break;
265,073✔
2206
    case QUERY_NODE_SHOW_TOPICS_STMT:
20,894✔
2207
      code = collectMetaKeyFromShowTopics(pCxt, (SShowStmt*)pStmt);
20,894✔
2208
      break;
20,894✔
2209
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
16,862✔
2210
      code = collectMetaKeyFromShowConsumers(pCxt, (SShowStmt*)pStmt);
16,862✔
2211
      break;
16,862✔
2212
    case QUERY_NODE_SHOW_CONNECTIONS_STMT:
2,629✔
2213
      code = collectMetaKeyFromShowConnections(pCxt, (SShowStmt*)pStmt);
2,629✔
2214
      break;
2,629✔
2215
    case QUERY_NODE_SHOW_QUERIES_STMT:
3,532✔
2216
      code = collectMetaKeyFromShowQueries(pCxt, (SShowStmt*)pStmt);
3,532✔
2217
      break;
3,532✔
2218
    case QUERY_NODE_SHOW_VARIABLES_STMT:
10,514✔
2219
      code = collectMetaKeyFromShowVariables(pCxt, (SShowStmt*)pStmt);
10,514✔
2220
      break;
10,514✔
2221
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
41,091✔
2222
      code = collectMetaKeyFromShowDnodeVariables(pCxt, (SShowDnodeVariablesStmt*)pStmt);
41,091✔
2223
      break;
41,091✔
2224
    case QUERY_NODE_SHOW_VNODES_STMT:
9,109✔
2225
      code = collectMetaKeyFromShowVnodes(pCxt, (SShowVnodesStmt*)pStmt);
9,109✔
2226
      break;
9,109✔
2227
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
3,963✔
2228
      code = collectMetaKeyFromShowUserPrivileges(pCxt, (SShowStmt*)pStmt);
3,963✔
2229
      break;
3,963✔
2230
    case QUERY_NODE_SHOW_ROLE_PRIVILEGES_STMT:
1,210✔
2231
      code = collectMetaKeyFromShowRolePrivileges(pCxt, (SShowStmt*)pStmt);
1,210✔
2232
      break;
1,210✔
2233
    case QUERY_NODE_SHOW_ROLE_COL_PRIVILEGES_STMT:
×
2234
      code = collectMetaKeyFromShowRoleColPrivileges(pCxt, (SShowStmt*)pStmt);
×
2235
      break;
×
2236
    case QUERY_NODE_SHOW_VIEWS_STMT:
15,907✔
2237
      code = collectMetaKeyFromShowViews(pCxt, (SShowStmt*)pStmt);
15,907✔
2238
      break;
15,907✔
2239
    case QUERY_NODE_SHOW_COMPACTS_STMT:
381,226✔
2240
      code = collectMetaKeyFromShowCompacts(pCxt, (SShowStmt*)pStmt);
381,226✔
2241
      break;
381,226✔
2242
    case QUERY_NODE_SHOW_SCANS_STMT:
2,508✔
2243
      code = collectMetaKeyFromShowScans(pCxt, (SShowStmt*)pStmt);
2,508✔
2244
      break;
2,508✔
2245
    case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
34,894✔
2246
      code = collectMetaKeyFromShowCompactDetails(pCxt, (SShowStmt*)pStmt);
34,894✔
2247
      break;
34,894✔
2248
    case QUERY_NODE_SHOW_SCAN_DETAILS_STMT:
2,280✔
2249
      code = collectMetaKeyFromShowScanDetails(pCxt, (SShowStmt*)pStmt);
2,280✔
2250
      break;
2,280✔
2251
    case QUERY_NODE_SHOW_SSMIGRATES_STMT:
93,483✔
2252
      code = collectMetaKeyFromShowSsMigrates(pCxt, (SShowStmt*)pStmt);
93,483✔
2253
      break;
93,483✔
2254
    case QUERY_NODE_SHOW_TOKENS_STMT:
2,021✔
2255
      code = collectMetaKeyFromShowTokens(pCxt, (SShowStmt*)pStmt);
2,021✔
2256
      break;
2,021✔
2257
    case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
321✔
2258
      code = collectMetaKeyFromShowTransactionDetails(pCxt, (SShowStmt*)pStmt);
321✔
2259
      break;
321✔
2260
    case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
2,269✔
2261
      code = collectMetaKeyFromShowGrantsFull(pCxt, (SShowStmt*)pStmt);
2,269✔
2262
      break;
2,269✔
2263
    case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
1,810✔
2264
      code = collectMetaKeyFromShowGrantsLogs(pCxt, (SShowStmt*)pStmt);
1,810✔
2265
      break;
1,810✔
2266
    case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT:
2,012✔
2267
      code = collectMetaKeyFromShowClusterMachines(pCxt, (SShowStmt*)pStmt);
2,012✔
2268
      break;
2,012✔
2269
    case QUERY_NODE_SHOW_ENCRYPTIONS_STMT:
201✔
2270
      code = collectMetaKeyFromShowEncryptions(pCxt, (SShowStmt*)pStmt);
201✔
2271
      break;
201✔
2272
    case QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT:
826✔
2273
      code = collectMetaKeyFromShowEncryptAlgorithms(pCxt, (SShowStmt*)pStmt);
826✔
2274
      break;
826✔
2275
    case QUERY_NODE_SHOW_ENCRYPT_STATUS_STMT:
×
2276
      code = collectMetaKeyFromShowEncryptStatus(pCxt, (SShowStmt*)pStmt);
×
2277
      break;
×
2278
    case QUERY_NODE_SHOW_MOUNTS_STMT:
2,053✔
2279
      code = collectMetaKeyFromShowMounts(pCxt, (SShowStmt*)pStmt);
2,053✔
2280
      break;
2,053✔
2281
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
68,417✔
2282
      code = collectMetaKeyFromShowCreateDatabase(pCxt, (SShowCreateDatabaseStmt*)pStmt);
68,417✔
2283
      break;
68,417✔
2284
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
106,035✔
2285
    case QUERY_NODE_SHOW_CREATE_VTABLE_STMT:
2286
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
2287
      code = collectMetaKeyFromShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
106,035✔
2288
      break;
106,035✔
2289
    case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
9,166✔
2290
      code = collectMetaKeyFromShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
9,166✔
2291
      break;
9,166✔
2292
    case QUERY_NODE_SHOW_CREATE_RSMA_STMT:
3,468✔
2293
      code = collectMetaKeyFromShowCreateRsma(pCxt, (SShowCreateRsmaStmt*)pStmt);
3,468✔
2294
      break;
3,468✔
2295
    case QUERY_NODE_SHOW_APPS_STMT:
2,012✔
2296
      code = collectMetaKeyFromShowApps(pCxt, (SShowStmt*)pStmt);
2,012✔
2297
      break;
2,012✔
2298
    case QUERY_NODE_SHOW_INSTANCES_STMT:
800✔
2299
      code = collectMetaKeyFromShowInstances(pCxt, (SShowStmt*)pStmt);
800✔
2300
      break;
800✔
2301
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
577,690✔
2302
      code = collectMetaKeyFromShowTransactions(pCxt, (SShowStmt*)pStmt);
577,690✔
2303
      break;
577,690✔
2304
    case QUERY_NODE_SHOW_USAGE_STMT:
377✔
2305
      code = collectMetaKeyFromShowUsage(pCxt, (SShowStmt*)pStmt);
377✔
2306
      break;
377✔
2307
    case QUERY_NODE_DELETE_STMT:
1,974,116✔
2308
      code = collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt);
1,974,116✔
2309
      break;
1,974,116✔
2310
    case QUERY_NODE_INSERT_STMT:
527,348✔
2311
      code = collectMetaKeyFromInsert(pCxt, (SInsertStmt*)pStmt);
527,348✔
2312
      break;
527,348✔
2313
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
3,703✔
2314
      code = collectMetaKeyFromShowBlockDist(pCxt, (SShowTableDistributedStmt*)pStmt);
3,703✔
2315
      break;
3,703✔
2316
    case QUERY_NODE_SHOW_VALIDATE_VTABLE_STMT:
3,978✔
2317
      code = collectMetaKeyFromShowValidateVtable(pCxt, (SShowValidateVirtualTable*)pStmt);
3,978✔
2318
      break;
3,978✔
2319
    case QUERY_NODE_SHOW_CPU_ALLOCATION_STMT:
2,021✔
2320
      code = collectMetaKeyFromShowCpuAllocation(pCxt, (SShowStmt*)pStmt);
2,021✔
2321
      break;
2,021✔
2322
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
26,261✔
2323
      code = collectMetaKeyFromShowSubscriptions(pCxt, (SShowStmt*)pStmt);
26,261✔
2324
      break;
26,261✔
2325
    case QUERY_NODE_CREATE_VIEW_STMT:
236,165✔
2326
      code = collectMetaKeyFromCreateViewStmt(pCxt, (SCreateViewStmt*)pStmt);
236,165✔
2327
      break;
236,165✔
2328
    case QUERY_NODE_DROP_VIEW_STMT:
177,169✔
2329
      code = collectMetaKeyFromDropViewStmt(pCxt, (SDropViewStmt*)pStmt);
177,169✔
2330
      break;
177,169✔
2331
    case QUERY_NODE_CREATE_TSMA_STMT:
8,561✔
2332
      code = collectMetaKeyFromCreateTSMAStmt(pCxt, (SCreateTSMAStmt*)pStmt);
8,561✔
2333
      break;
8,561✔
2334
    case QUERY_NODE_DROP_TSMA_STMT:
4,112✔
2335
      code = collectMetaKeyFromDropTSMAStmt(pCxt, (SDropTSMAStmt*)pStmt);
4,112✔
2336
      break;
4,112✔
2337
    case QUERY_NODE_SHOW_TSMAS_STMT:
459✔
2338
      code = collectMetaKeyFromShowTSMASStmt(pCxt, (SShowStmt*)pStmt);
459✔
2339
      break;
459✔
2340
    case QUERY_NODE_CREATE_RSMA_STMT:
121,074✔
2341
      code = collectMetaKeyFromCreateRsmaStmt(pCxt, (SCreateRsmaStmt*)pStmt);
121,074✔
2342
      break;
121,074✔
2343
    case QUERY_NODE_DROP_RSMA_STMT:
11,152✔
2344
      code = collectMetaKeyFromDropRsmaStmt(pCxt, (SDropRsmaStmt*)pStmt);
11,152✔
2345
      break;
11,152✔
2346
    case QUERY_NODE_ALTER_RSMA_STMT:
22,491✔
2347
      code = collectMetaKeyFromAlterRsmaStmt(pCxt, (SAlterRsmaStmt*)pStmt);
22,491✔
2348
      break;
22,491✔
2349
    case QUERY_NODE_SHOW_RSMAS_STMT:
14,841✔
2350
      code = collectMetaKeyFromShowRsmasStmt(pCxt, (SShowStmt*)pStmt);
14,841✔
2351
      break;
14,841✔
2352
    case QUERY_NODE_SHOW_RETENTIONS_STMT:
42,432✔
2353
      code = collectMetaKeyFromShowRetentionsStmt(pCxt, (SShowStmt*)pStmt);
42,432✔
2354
      break;
42,432✔
2355
    case QUERY_NODE_SHOW_RETENTION_DETAILS_STMT:
2,397✔
2356
      code = collectMetaKeyFromShowRetentionDetailsStmt(pCxt, (SShowStmt*)pStmt);
2,397✔
2357
      break;
2,397✔
2358
    case QUERY_NODE_SHOW_DB_ALIVE_STMT:
5,846✔
2359
    case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
2360
      code = collectMetaKeyFromShowAlive(pCxt, (SShowAliveStmt*)pStmt);
5,846✔
2361
      break;
5,846✔
2362
    case QUERY_NODE_CREATE_DATABASE_STMT:
1,715,411✔
2363
      code = collectMetaKeyFromCreateDatabase(pCxt, (SCreateDatabaseStmt*)pStmt);
1,715,411✔
2364
      break;
1,715,411✔
2365
    case QUERY_NODE_DROP_DATABASE_STMT:
1,456,495✔
2366
      code = collectMetaKeyFromDropDatabase(pCxt, (SDropDatabaseStmt*)pStmt);
1,456,495✔
2367
      break;
1,456,495✔
2368
    case QUERY_NODE_BALANCE_VGROUP_STMT:
12,852✔
2369
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_BALANCE);
12,852✔
2370
      break;
12,852✔
2371
    case QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT:
3,982✔
2372
    case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT:
2373
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_BALANCE_LEADER);
3,982✔
2374
      break;
3,982✔
2375
    case QUERY_NODE_MERGE_VGROUP_STMT:
×
2376
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_MERGE);
×
2377
      break;
×
2378
    case QUERY_NODE_SPLIT_VGROUP_STMT:
19,430✔
2379
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_SPLIT);
19,430✔
2380
      break;
19,430✔
2381
    case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
66,779✔
2382
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_REDISTRIBUTE);
66,779✔
2383
      break;
66,779✔
2384
    case QUERY_NODE_CREATE_FUNCTION_STMT:
15,807✔
2385
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_FUNC_CREATE);
15,807✔
2386
      break;
15,807✔
2387
    case QUERY_NODE_DROP_FUNCTION_STMT:
9,398✔
2388
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_FUNC_DROP);
9,398✔
2389
      break;
9,398✔
2390
    case QUERY_NODE_CREATE_MOUNT_STMT:
2,077✔
2391
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_MOUNT_CREATE);
2,077✔
2392
      break;
2,077✔
2393
    case QUERY_NODE_DROP_MOUNT_STMT:
644✔
2394
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_MOUNT_DROP);
644✔
2395
      break;
644✔
2396
    case QUERY_NODE_CREATE_ROLE_STMT:
4,945✔
2397
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_ROLE_CREATE);
4,945✔
2398
      break;
4,945✔
2399
    case QUERY_NODE_DROP_ROLE_STMT:
2,013✔
2400
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_ROLE_DROP);
2,013✔
2401
      break;
2,013✔
2402
    case QUERY_NODE_CREATE_USER_STMT:
121,405✔
2403
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_USER_CREATE);
121,405✔
2404
      break;
121,405✔
2405
    case QUERY_NODE_ALTER_USER_STMT:
64,532✔
2406
      code = collectMetaKeyFromAlterUserStmt(pCxt, (SAlterUserStmt*)pStmt);
64,532✔
2407
      break;
64,532✔
2408
    case QUERY_NODE_DROP_USER_STMT:
62,580✔
2409
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_USER_DROP);
62,580✔
2410
      break;
62,580✔
2411
    case QUERY_NODE_ALTER_LOCAL_STMT:
513,299✔
2412
      return collectMetaKeyFromAlterLocalStmt(pCxt, (SAlterLocalStmt*)pStmt);
513,299✔
2413
    case QUERY_NODE_CREATE_DNODE_STMT:
333,928✔
2414
    case QUERY_NODE_CREATE_MNODE_STMT:
2415
    case QUERY_NODE_CREATE_QNODE_STMT:
2416
    case QUERY_NODE_CREATE_SNODE_STMT:
2417
    case QUERY_NODE_CREATE_BNODE_STMT:
2418
    case QUERY_NODE_CREATE_ANODE_STMT:
2419
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_NODE_CREATE);
333,928✔
2420
      break;
333,928✔
2421
    case QUERY_NODE_DROP_DNODE_STMT:
109,431✔
2422
    case QUERY_NODE_DROP_MNODE_STMT:
2423
    case QUERY_NODE_DROP_QNODE_STMT:
2424
    case QUERY_NODE_DROP_SNODE_STMT:
2425
    case QUERY_NODE_DROP_BNODE_STMT:
2426
    case QUERY_NODE_DROP_ANODE_STMT:
2427
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_NODE_DROP);
109,431✔
2428
      break;
109,431✔
2429
    case QUERY_NODE_KILL_TRANSACTION_STMT:
618✔
2430
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_TRANS_KILL);
618✔
2431
      break;
618✔
2432
    case QUERY_NODE_KILL_QUERY_STMT:
1,583✔
2433
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_QUERY_KILL);
1,583✔
2434
      break;
1,583✔
2435
    case QUERY_NODE_KILL_CONNECTION_STMT:
346✔
2436
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_CONN_KILL);
346✔
2437
      break;
346✔
2438
    default:
2,712,512✔
2439
      break;
2,712,512✔
2440
  }
2441

2442
  pCxt->pStmt = pOrigStmt;
1,067,296,782✔
2443

2444
  return code;
1,067,308,600✔
2445
}
2446

2447
int32_t collectMetaKey(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
480,000,528✔
2448
  SCollectMetaKeyCxt cxt = {.pParseCxt = pParseCxt, .pMetaCache = pMetaCache, .pStmt = pQuery->pRoot};
480,000,528✔
2449
  return collectMetaKeyFromQuery(&cxt, pQuery->pRoot);
479,988,168✔
2450
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc