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

taosdata / TDengine / #5058

17 May 2026 01:15AM UTC coverage: 73.387% (-0.02%) from 73.406%
#5058

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

281656 of 383795 relevant lines covered (73.39%)

135114337.11 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) {
477,779,936✔
37
  *pQuery = NULL;
477,779,936✔
38
  int32_t code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)pQuery);
477,790,666✔
39
  if (NULL == *pQuery) {
477,842,035✔
40
    return code;
×
41
  }
42
  (*pQuery)->pRoot = pRootNode;
477,841,596✔
43
  (*pQuery)->placeholderNum = placeholderNo;
477,832,546✔
44
  TSWAP((*pQuery)->pPlaceholderValues, *pPlaceholderValues);
477,807,179✔
45
  (*pQuery)->execStage = QUERY_EXEC_STAGE_ANALYSE;
477,800,953✔
46

47
  return TSDB_CODE_SUCCESS;
477,804,224✔
48
}
49

50
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
492,041,395✔
51
  SAstCreateContext cxt;
295,225,734✔
52
  initAstCreateContext(pParseCxt, &cxt);
492,045,193✔
53
  void* pParser = ParseAlloc((FMalloc)taosMemMalloc);
492,033,743✔
54
  if (!pParser) return terrno;
492,055,395✔
55
  int32_t i = 0;
492,055,395✔
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);
190,247,944✔
60
      goto abort_parse;
389,670,192✔
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);
822,434✔
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: {
288,276,411✔
78
        Parse(pParser, 0, t0, &cxt);
288,276,411✔
79
        goto abort_parse;
288,268,435✔
80
      }
81
      case TK_NK_ILLEGAL: {
244,871✔
82
        snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unrecognized token: \"%s\"", t0.z);
244,871✔
83
        cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
244,871✔
84
        goto abort_parse;
244,871✔
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,309,243✔
96
        }
97
    }
98
  }
99

100
abort_parse:
495,991,997✔
101
  ParseFree(pParser, (FFree)taosAutoMemoryFree);
496,002,354✔
102
  if (TSDB_CODE_SUCCESS == cxt.errCode) {
492,027,642✔
103
    int32_t code = buildQueryAfterParse(pQuery, cxt.pRootNode, cxt.placeholderNo, &cxt.pPlaceholderValues);
477,815,269✔
104
    if (TSDB_CODE_SUCCESS != code) {
477,794,029✔
105
      return code;
×
106
    }
107
  }
108
  taosArrayDestroy(cxt.pPlaceholderValues);
492,006,402✔
109
  return cxt.errCode;
491,997,213✔
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) {
635,013,260✔
131
  switch (fmGetFuncType(pFunc->functionName)) {
635,013,260✔
132
    case FUNCTION_TYPE_LAST_ROW:
22,174,838✔
133
    case FUNCTION_TYPE_LAST:
134
      pCxt->hasLastRowOrLast = true;
22,174,838✔
135
      break;
22,175,045✔
136
    case FUNCTION_TYPE_UDF:
236,745✔
137
      pCxt->errCode = reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache);
236,745✔
138
      break;
225,618✔
139
    default:
612,597,782✔
140
      break;
612,597,782✔
141
  }
142
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
634,998,445✔
143
}
144

145
static bool needGetTableIndex(SNode* pStmt) {
727,319,004✔
146
  return false;
727,319,004✔
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,833,323✔
155
  if (0 == pName->type) {
1,833,323✔
156
    return TSDB_CODE_SUCCESS;
1,230,770✔
157
  }
158
  if (TSDB_DB_NAME_T == pName->type) {
602,553✔
159
    return reserveDbVgInfoInCache(pName->acctId, pName->dbname, pCxt->pMetaCache);
170,056✔
160
  }
161
  return reserveTableVgroupInCacheExt(pName, pCxt->pMetaCache);
432,497✔
162
}
163

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

174
static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const char* pDb, const char* pTable,
727,287,379✔
175
                                               EPrivType privType, EPrivObjType objType) {
176
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
727,287,379✔
177
  if (TSDB_CODE_SUCCESS == code) {
727,337,884✔
178
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, NULL, PRIV_DB_USE, PRIV_OBJ_DB,
727,338,929✔
179
                                  pCxt->pMetaCache);
180
  }
181
  if (TSDB_CODE_SUCCESS == code) {
727,329,095✔
182
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
727,328,375✔
183
  }
184
  if (TSDB_CODE_SUCCESS == code) {
727,345,367✔
185
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
727,345,123✔
186
  }
187
  if (TSDB_CODE_SUCCESS == code) {
727,338,031✔
188
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, pTable, privType, objType,
727,340,308✔
189
                                  pCxt->pMetaCache);
190
  }
191
#ifdef TD_ENTERPRISE
192
  if (TSDB_CODE_SUCCESS == code && NULL != pCxt->pParseCxt->pEffectiveUser) {
727,341,770✔
193
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pEffectiveUser, pDb, pTable, privType,
364,114✔
194
                                  objType, pCxt->pMetaCache);
195
  }
196
#endif
197
  if (TSDB_CODE_SUCCESS == code) {
727,338,822✔
198
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
727,333,348✔
199
  }
200
  if (TSDB_CODE_SUCCESS == code && needGetTableIndex(pCxt->pStmt)) {
727,348,665✔
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) ||
727,345,021✔
204
                                     0 == strcmp(pTable, TSDB_INS_TABLE_CPU_ALLOCATION))) {
727,328,815✔
205
    code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
11,282✔
206
  }
207
  if (TSDB_CODE_SUCCESS == code &&
727,337,456✔
208
      (0 == strcmp(pTable, TSDB_INS_TABLE_TAGS) || 0 == strcmp(pTable, TSDB_INS_TABLE_TABLES) ||
727,337,989✔
209
       0 == strcmp(pTable, TSDB_INS_TABLE_COLS) || 0 == strcmp(pTable, TSDB_INS_TABLE_VC_COLS) ||
726,662,559✔
210
       0 == strcmp(pTable, TSDB_INS_DISK_USAGE) || 0 == strcmp(pTable, TSDB_INS_TABLE_FILESETS) ||
725,583,205✔
211
       0 == strcmp(pTable, TSDB_INS_TABLE_VIRTUAL_TABLES_REFERENCING) ||
725,578,735✔
212
       0 == strcmp(pTable, TSDB_INS_TABLE_TABLE_FIXED_DISTRIBUTED)) &&
725,503,324✔
213
      QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
1,838,451✔
214
    code = collectMetaKeyFromInsTags(pCxt);
1,833,323✔
215
  }
216
  // ins_table_fixed_distributed: reserve DB vgroup info + target table meta
217
  if (TSDB_CODE_SUCCESS == code &&
727,335,174✔
218
      0 == strcmp(pTable, TSDB_INS_TABLE_TABLE_FIXED_DISTRIBUTED) &&
727,335,951✔
219
      QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
3,786✔
220
    SSelectStmt* pSelect = (SSelectStmt*)pCxt->pStmt;
2,210✔
221
    SName        targetName = {0};
2,210✔
222
    code = getVnodeSysTableTargetName(pCxt->pParseCxt->acctId, pSelect->pWhere, &targetName);
2,210✔
223
    if (TSDB_CODE_SUCCESS == code && targetName.dbname[0] != '\0') {
2,210✔
224
      code = reserveDbVgInfoInCache(targetName.acctId, targetName.dbname, pCxt->pMetaCache);
1,547✔
225
    }
226
    if (TSDB_CODE_SUCCESS == code && targetName.tname[0] != '\0' && targetName.dbname[0] != '\0') {
2,210✔
227
      code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, targetName.dbname, targetName.tname, pCxt->pMetaCache);
1,326✔
228
    }
229
  }
230
  if (TSDB_CODE_SUCCESS == code && QUERY_SMA_OPTIMIZE_ENABLE == tsQuerySmaOptimize &&
727,335,174✔
231
      QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
520,730✔
232
    code = reserveTableTSMAInfoInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
520,730✔
233
  }
234
  return code;
727,336,489✔
235
}
236

237
static EDealRes collectMetaKeyFromRealTable(SCollectMetaKeyFromExprCxt* pCxt, SRealTableNode* pRealTable) {
723,931,951✔
238
  pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, pRealTable->table.dbName, pRealTable->table.tableName,
723,931,951✔
239
                                                  PRIV_TBL_SELECT, PRIV_OBJ_TBL);
240
  if (TSDB_CODE_SUCCESS == pCxt->errCode && pCxt->pComCxt->collectVStbRefDbs) {
723,967,008✔
241
    pCxt->errCode = reserveVStbRefDbsInCache(pCxt->pComCxt->pParseCxt->acctId, pRealTable->table.dbName,
911,487,295✔
242
                                             pRealTable->table.tableName, pCxt->pComCxt->pMetaCache);
911,482,480✔
243
  }
244
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
723,970,600✔
245
}
246

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

252
static int32_t isTbnameEqCondOperator(SOperatorNode* pOperator, char** ppTableName) {
449,529,654✔
253
  if (pOperator->opType != OP_TYPE_EQUAL) {
449,529,654✔
254
    return TSDB_CODE_SUCCESS;
385,799,089✔
255
  }
256

257
  SValueNode* pValueNode = NULL;
63,732,878✔
258
  if (nodeType(pOperator->pLeft) == QUERY_NODE_FUNCTION &&
63,732,878✔
259
      0 == strcasecmp(((SFunctionNode*)(pOperator->pLeft))->functionName, "tbname") &&
5,053,076✔
260
      nodeType(pOperator->pRight) == QUERY_NODE_VALUE) {
737,732✔
261
    pValueNode = (SValueNode*)pOperator->pRight;
713,906✔
262
  } else if (nodeType(pOperator->pRight) == QUERY_NODE_FUNCTION &&
63,018,972✔
263
             0 == strcasecmp(((SFunctionNode*)(pOperator->pRight))->functionName, "tbname") &&
97,903✔
264
             nodeType(pOperator->pLeft) == QUERY_NODE_VALUE) {
1,254✔
265
    pValueNode = (SValueNode*)pOperator->pLeft;
×
266
  } else {
267
    return TSDB_CODE_SUCCESS;
63,018,972✔
268
  }
269

270
  *ppTableName = pValueNode->literal;
713,906✔
271

272
  return TSDB_CODE_SUCCESS;
713,906✔
273
}
274

275
static EDealRes collectMetaKeyFromOperator(SCollectMetaKeyFromExprCxt* pCxt, SOperatorNode* pOpNode) {
591,354,228✔
276
  if (!pCxt->tbnameCollect) {
591,354,228✔
277
    return DEAL_RES_CONTINUE;
141,829,713✔
278
  }
279

280
  char*   pTableName = NULL;
449,524,515✔
281
  int32_t code = isTbnameEqCondOperator((SOperatorNode*)pOpNode, &pTableName);
449,523,570✔
282
  if (TSDB_CODE_SUCCESS != code) return DEAL_RES_CONTINUE;
449,539,178✔
283
  if (pTableName) {
449,539,178✔
284
    SSelectStmt* pSelect = (SSelectStmt*)pCxt->pComCxt->pStmt;
713,906✔
285
    pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, ((SRealTableNode*)pSelect->pFromTable)->table.dbName,
713,906✔
286
                                                    pTableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL);
287
  }
288

289
  return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
449,539,178✔
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:
635,015,014✔
296
      return collectMetaKeyFromFunction(pCxt, (SFunctionNode*)pNode);
635,015,014✔
297
    case QUERY_NODE_REAL_TABLE:
723,515,027✔
298
      return collectMetaKeyFromRealTable(pCxt, (SRealTableNode*)pNode);
723,515,027✔
299
    case QUERY_NODE_TEMP_TABLE:
35,757,639✔
300
      return collectMetaKeyFromTempTable(pCxt, (STempTableNode*)pNode);
35,757,639✔
301
    case QUERY_NODE_OPERATOR:
591,373,375✔
302
      return collectMetaKeyFromOperator(pCxt, (SOperatorNode*)pNode);
591,373,375✔
303
    case QUERY_NODE_SET_OPERATOR:
29,207,704✔
304
      return collectMetaKeyFromSetOperator(pCxt->pComCxt, (SSetOperator*)pNode);
29,207,704✔
305
    case QUERY_NODE_SELECT_STMT:
338,642,474✔
306
      return collectMetaKeyFromQuery(pCxt->pComCxt, pNode);
338,642,474✔
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) {
44,786,748✔
314
  SCollectMetaKeyFromExprCxt cxt = {.pComCxt = pCxt, .errCode = TSDB_CODE_SUCCESS, .tbnameCollect = false};
44,786,748✔
315
  nodesWalkExprs(pList, collectMetaKeyFromExprImpl, &cxt);
44,786,748✔
316
  return cxt.errCode;
44,786,670✔
317
}
318

319
static int32_t collectMetaKeyFromSetOperator(SCollectMetaKeyCxt* pCxt, SSetOperator* pStmt) {
44,784,591✔
320
  int32_t code = collectMetaKeyFromQuery(pCxt, pStmt->pLeft);
44,784,591✔
321
  if (TSDB_CODE_SUCCESS == code) {
44,786,354✔
322
    code = collectMetaKeyFromQuery(pCxt, pStmt->pRight);
44,786,578✔
323
  }
324
  if (TSDB_CODE_SUCCESS == code) {
44,786,370✔
325
    code = collectMetaKeyFromExprs(pCxt, pStmt->pOrderByList);
44,786,748✔
326
  }
327
  return code;
44,786,748✔
328
}
329

330
static int32_t reserveDbCfgForLastRow(SCollectMetaKeyCxt* pCxt, SNode* pTable) {
17,286,421✔
331
  if (NULL == pTable || QUERY_NODE_REAL_TABLE != nodeType(pTable)) {
17,286,421✔
332
    return TSDB_CODE_SUCCESS;
552,630✔
333
  }
334
  return reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SRealTableNode*)pTable)->table.dbName, pCxt->pMetaCache);
16,733,910✔
335
}
336

337
static int32_t collectMetaKeyFromSelect(SCollectMetaKeyCxt* pCxt, SSelectStmt* pStmt) {
738,429,419✔
338
  SCollectMetaKeyFromExprCxt cxt = {.pComCxt = pCxt, .hasLastRowOrLast = false, .errCode = TSDB_CODE_SUCCESS};
738,429,419✔
339
  if (pStmt->pFromTable && QUERY_NODE_REAL_TABLE == nodeType(pStmt->pFromTable)) {
738,430,405✔
340
    cxt.tbnameCollect = true;
632,732,718✔
341
    cxt.pComCxt->collectVStbRefDbs = true;
632,732,718✔
342
  }
343
  nodesWalkSelectStmt(pStmt, SQL_CLAUSE_FROM, collectMetaKeyFromExprImpl, &cxt);
738,433,437✔
344
  if (TSDB_CODE_SUCCESS == cxt.errCode && cxt.hasLastRowOrLast) {
738,463,758✔
345
    cxt.errCode = reserveDbCfgForLastRow(pCxt, pStmt->pFromTable);
17,287,020✔
346
  }
347
  return cxt.errCode;
738,463,909✔
348
}
349

350
static int32_t collectMetaKeyFromCreateDatabase(SCollectMetaKeyCxt* pCxt, SCreateDatabaseStmt* pStmt) {
1,795,102✔
351
  int32_t code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_DB_CREATE, 0,
1,795,102✔
352
                                        pCxt->pMetaCache);
353
  if (TSDB_CODE_SUCCESS == code) {
1,795,102✔
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,795,102✔
356
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
357
  }
358
  return code;
1,795,102✔
359
}
360

361
static int32_t collectMetaKeyFromAlterDatabase(SCollectMetaKeyCxt* pCxt, SAlterDatabaseStmt* pStmt) {
228,329✔
362
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
228,329✔
363
  if (TSDB_CODE_SUCCESS == code) {
228,329✔
364
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_CM_ALTER,
228,329✔
365
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
366
  }
367
  if (TSDB_CODE_SUCCESS == code) {
228,329✔
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,
228,329✔
370
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
371
  }
372
  return code;
228,329✔
373
}
374

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

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

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

409
static int32_t collectMetaKeyFromCreateVTable(SCollectMetaKeyCxt* pCxt, SCreateVTableStmt* pStmt) {
247,272✔
410
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
247,272✔
411
  if (TSDB_CODE_SUCCESS == code) {
247,272✔
412
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
247,272✔
413
  }
414
  if (TSDB_CODE_SUCCESS == code) {
247,272✔
415
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
247,272✔
416
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
417
  }
418
  if (TSDB_CODE_SUCCESS == code) {
247,272✔
419
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_TBL_CREATE,
247,272✔
420
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
421
  }
422
  if (TSDB_CODE_SUCCESS == code) {
247,272✔
423
    SNode* pNode = NULL;
247,272✔
424
    FOREACH(pNode, pStmt->pCols) {
163,603,878✔
425
      SColumnDefNode* pCol = (SColumnDefNode*)pNode;
163,356,606✔
426
      if (NULL == pCol) {
163,356,606✔
427
        code = TSDB_CODE_PAR_INVALID_COLUMN;
×
428
        break;
×
429
      }
430
      SColumnOptions* pOptions = (SColumnOptions*)pCol->pOptions;
163,356,606✔
431
      if (pOptions && pOptions->hasRef) {
163,356,606✔
432
        code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pOptions->refDb, pOptions->refTable, pCxt->pMetaCache);
101,906,807✔
433
        if (TSDB_CODE_SUCCESS == code) {
101,906,807✔
434
          code =
435
              reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pOptions->refDb, pOptions->refTable, pCxt->pMetaCache);
101,906,807✔
436
        }
437
        if (TSDB_CODE_SUCCESS == code) {
101,906,807✔
438
          code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pOptions->refDb,
203,813,071✔
439
                                        pOptions->refTable, PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache);
101,906,807✔
440
        }
441
        if (TSDB_CODE_SUCCESS != code) {
101,906,807✔
442
          break;
×
443
        }
444
      }
445
    }
446
  }
447
  return code;
247,272✔
448
}
449

450
static int32_t collectMetaKeyFromCreateVSubTable(SCollectMetaKeyCxt* pCxt, SCreateVSubTableStmt* pStmt) {
437,825✔
451
  int32_t code = TSDB_CODE_SUCCESS;
437,825✔
452
  PAR_ERR_RET(reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache));
437,825✔
453
  // super table's meta
454
  PAR_ERR_RET(
437,825✔
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));
437,825✔
458
  // check db's write auth
459
  PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
437,825✔
460
                                     PRIV_OBJ_DB, pCxt->pMetaCache));
461
  PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL,
437,825✔
462
                                     PRIV_TBL_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache));
463
  // check org table's read auth for column references
464
  SNode*     pNode = NULL;
437,825✔
465
  SNodeList* pTmpNodeList = pStmt->pSpecificColRefs ? pStmt->pSpecificColRefs : pStmt->pColRefs;
437,825✔
466
  if (pTmpNodeList) {
437,825✔
467
    FOREACH(pNode, pTmpNodeList) {
62,922,061✔
468
      SColumnRefNode* pColRef = (SColumnRefNode*)pNode;
62,512,967✔
469
      if (NULL == pColRef) {
62,512,967✔
470
        code = TSDB_CODE_PAR_INVALID_COLUMN;
×
471
        break;
×
472
      }
473
      PAR_ERR_RET(
62,512,967✔
474
          reserveTableMetaInCache(pCxt->pParseCxt->acctId, pColRef->refDbName, pColRef->refTableName, pCxt->pMetaCache));
475
      PAR_ERR_RET(reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pColRef->refDbName, pColRef->refTableName,
62,512,967✔
476
                                            pCxt->pMetaCache));
477
      PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pColRef->refDbName,
62,512,967✔
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) {
437,825✔
486
    FOREACH(pNode, pStmt->pValsOfTags) {
2,373,554✔
487
      if (nodeType(pNode) == QUERY_NODE_COLUMN_REF) {
1,935,729✔
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;
437,825✔
500
}
501

502
static int32_t collectMetaKeyFromCreateMultiTable(SCollectMetaKeyCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
39,819,512✔
503
  int32_t code = TSDB_CODE_SUCCESS;
39,819,512✔
504
  SNode*  pNode = NULL;
39,819,512✔
505
  FOREACH(pNode, pStmt->pSubTables) {
87,558,064✔
506
    if (pNode->type == QUERY_NODE_CREATE_SUBTABLE_CLAUSE) {
47,720,628✔
507
      SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
47,711,046✔
508
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
47,711,046✔
509
      if (TSDB_CODE_SUCCESS == code) {
47,741,012✔
510
        code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pClause->useTableName,
47,743,839✔
511
                                       pCxt->pMetaCache);
512
      }
513
      if (TSDB_CODE_SUCCESS == code) {
47,740,815✔
514
        code =
515
            reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
47,740,815✔
516
      }
517
      if (TSDB_CODE_SUCCESS == code) {
47,748,471✔
518
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL,
47,748,471✔
519
                                      PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
520
      }
521
      if (TSDB_CODE_SUCCESS == code) {
47,749,499✔
522
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL,
47,749,499✔
523
                                      PRIV_TBL_CREATE, PRIV_OBJ_DB, pCxt->pMetaCache);
524
      }
525
    } else {
526
      SCreateSubTableFromFileClause* pClause = (SCreateSubTableFromFileClause*)pNode;
×
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) {
47,738,552✔
543
      break;
×
544
    }
545
  }
546
  return code;
39,825,157✔
547
}
548

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

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

568
  return code;
1,534✔
569
}
570

571
static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) {
2,739,548✔
572
  int32_t code = TSDB_CODE_SUCCESS;
2,739,548✔
573
  SNode*  pNode = NULL;
2,739,548✔
574
  FOREACH(pNode, pStmt->pTables) {
5,611,778✔
575
    SDropTableClause* pClause = (SDropTableClause*)pNode;
2,872,230✔
576
    if (pStmt->withOpt) {
2,872,230✔
577
      code = reserveTableUidInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
169,325✔
578
      if (TSDB_CODE_SUCCESS == code) {
169,325✔
579
        code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
169,325✔
580
      }
581
    } else {
582
      code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
2,702,905✔
583
      if (TSDB_CODE_SUCCESS == code) {
2,702,905✔
584
        code =
585
            reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
2,702,905✔
586
      }
587
      if (TSDB_CODE_SUCCESS == code) {
2,702,905✔
588
        code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
5,397,431✔
589
                                      pClause->tableName, PRIV_CM_DROP, PRIV_OBJ_TBL, pCxt->pMetaCache);
2,702,905✔
590
      }
591
    }
592
    if (TSDB_CODE_SUCCESS == code) {
2,872,230✔
593
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
2,872,230✔
594
    }
595
    if (TSDB_CODE_SUCCESS == code) {
2,872,230✔
596
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL, PRIV_DB_USE,
2,872,230✔
597
                                    PRIV_OBJ_DB, pCxt->pMetaCache);
598
    }
599

600
    if (TSDB_CODE_SUCCESS != code) {
2,872,230✔
601
      break;
×
602
    }
603
  }
604
  return code;
2,739,548✔
605
}
606

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

624
static int32_t collectMetaKeyFromDropVtable(SCollectMetaKeyCxt* pCxt, SDropVirtualTableStmt* pStmt) {
82,610✔
625
  int32_t code = TSDB_CODE_SUCCESS;
82,610✔
626
  if (pStmt->withOpt) {
82,610✔
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);
82,610✔
636
    if (TSDB_CODE_SUCCESS == code) {
82,610✔
637
      code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
82,610✔
638
    }
639
    if (TSDB_CODE_SUCCESS == code) {
82,610✔
640
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
82,610✔
641
                                    PRIV_OBJ_DB, pCxt->pMetaCache);
642
    }
643
    if (TSDB_CODE_SUCCESS == code) {
82,610✔
644
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
82,610✔
645
                                    PRIV_CM_DROP, PRIV_OBJ_TBL, pCxt->pMetaCache);
646
    }
647
  }
648
  return code;
82,610✔
649
}
650

651

652

653
static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
21,553,140✔
654
  int32_t code = TSDB_CODE_SUCCESS;
21,553,140✔
655

656
  if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
21,553,140✔
657
    SNode*  pNode = NULL;
9,197,414✔
658
    FOREACH(pNode, pStmt->pList) {
18,431,399✔
659
      SAlterTableUpdateTagValClause* pClause = (SAlterTableUpdateTagValClause*)pNode;
9,233,985✔
660
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
9,233,985✔
661
      if (code != TSDB_CODE_SUCCESS) {
9,233,985✔
662
        break;
×
663
      }
664

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

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

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

683
      code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
9,233,985✔
684
      if (code != TSDB_CODE_SUCCESS) {
9,233,985✔
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);
9,233,985✔
689
      if (code != TSDB_CODE_SUCCESS) {
9,233,985✔
690
        break;
×
691
      }
692
    }
693

694
    return code;
9,197,414✔
695
  }
696
  
697
  if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
12,355,726✔
698
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
34,470✔
699
    if (TSDB_CODE_SUCCESS != code) {
34,470✔
700
      return code;
×
701
    }
702

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

708
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
34,470✔
709
    if (TSDB_CODE_SUCCESS != code) {
34,470✔
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);
34,470✔
714
    if (TSDB_CODE_SUCCESS != code) {
34,470✔
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);
34,470✔
719
    return code;
34,470✔
720
  }
721

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

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

732
  code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
12,321,256✔
733
  if (code != TSDB_CODE_SUCCESS) {
12,321,256✔
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);
12,321,256✔
738
  if (code != TSDB_CODE_SUCCESS) {
12,321,256✔
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);
12,321,256✔
743
  if (TSDB_CODE_SUCCESS == code) {
12,321,256✔
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,
12,321,256✔
746
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
747
  }
748
  return code;
12,321,256✔
749
}
750

751

752

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

772
  int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
592,257✔
773
  if (TSDB_CODE_SUCCESS == code) {
592,257✔
774
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
592,257✔
775
  }
776
  if (TSDB_CODE_SUCCESS == code) {
592,257✔
777
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
592,257✔
778
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
779
  }
780
  if (TSDB_CODE_SUCCESS == code) {
592,257✔
781
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
592,257✔
782
                                  PRIV_CM_ALTER, PRIV_OBJ_TBL, pCxt->pMetaCache);
783
  }
784
  if (TSDB_CODE_SUCCESS == code) {
592,257✔
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,
592,257✔
787
                                  PRIV_SECURITY_POLICY_ALTER, 0, pCxt->pMetaCache);
788
  }
789
  return code;
592,257✔
790
}
791

792

793

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

797
  if (pStmt->alterType == TSDB_ALTER_TABLE_ALTER_COLUMN_REF ||
472,945✔
798
      pStmt->alterType == TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF) {
342,492✔
799
    PAR_ERR_RET(
172,468✔
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,
172,468✔
802
                                       PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache));
803
    PAR_ERR_RET(reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->refDbName,
172,468✔
804
                                       pStmt->refTableName, PRIV_TBL_SELECT, PRIV_OBJ_TBL, pCxt->pMetaCache));
805
  }
806

807
  return TSDB_CODE_SUCCESS;
472,945✔
808
}
809

810

811

812
static int32_t collectMetaKeyFromUseDatabase(SCollectMetaKeyCxt* pCxt, SUseDatabaseStmt* pStmt) {
92,474,270✔
813
  int32_t code = reserveDbVgVersionInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
92,474,270✔
814
  if (TSDB_CODE_SUCCESS == code) {
92,479,215✔
815
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
92,479,304✔
816
  }
817
  if (TSDB_CODE_SUCCESS == code) {
92,479,279✔
818
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
92,479,456✔
819
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
820
  }
821
  return code;
92,479,166✔
822
}
823

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

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

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

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

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

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

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

955
  return code;
438,078✔
956
}
957

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

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

972
static int32_t collectMetaKeyFromShowMnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
380,457✔
973
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES,
380,457✔
974
                                         pCxt->pMetaCache);
975
  if (TSDB_CODE_SUCCESS == code) {
380,457✔
976
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
380,457✔
977
                                  pCxt->pMetaCache);
978
  }
979
  return code;
380,457✔
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,404✔
989
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES,
2,404✔
990
                                         pCxt->pMetaCache);
991
  if (TSDB_CODE_SUCCESS == code) {
2,404✔
992
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
2,404✔
993
                                  pCxt->pMetaCache);
994
  }
995
  return code;
2,404✔
996
}
997

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

1008
static int32_t collectMetaKeyFromShowAnodes(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
206✔
1009
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_ANODES,
206✔
1010
                                         pCxt->pMetaCache);
1011
  if (TSDB_CODE_SUCCESS == code) {
206✔
1012
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
206✔
1013
                                  pCxt->pMetaCache);
1014
  }
1015
  return code;
206✔
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) {
69,707✔
1029
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_BNODES,
69,707✔
1030
                                         pCxt->pMetaCache);
1031
  if (TSDB_CODE_SUCCESS == code) {
69,707✔
1032
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
69,707✔
1033
                                  pCxt->pMetaCache);
1034
  }
1035
  return code;
69,707✔
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,627✔
1049
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_XNODES,
2,627✔
1050
                                         pCxt->pMetaCache);
1051
  if (TSDB_CODE_SUCCESS == code) {
2,627✔
1052
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
2,627✔
1053
                                  pCxt->pMetaCache);
1054
  }
1055
  return code;
2,627✔
1056
}
1057

1058
static int32_t collectMetaKeyFromShowXnodeTasks(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
8,061✔
1059
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
8,061✔
1060
                                         TSDB_INS_TABLE_XNODE_TASKS, pCxt->pMetaCache);
1061
  if (TSDB_CODE_SUCCESS == code) {
8,061✔
1062
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_CM_SHOW, 0,
8,061✔
1063
                                  pCxt->pMetaCache);
1064
  }
1065
  return code;
8,061✔
1066
}
1067
static int32_t collectMetaKeyFromShowXnodeAgents(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
4,806✔
1068
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
4,806✔
1069
                                         TSDB_INS_TABLE_XNODE_AGENTS, pCxt->pMetaCache);
1070
  if (TSDB_CODE_SUCCESS == code) {
4,806✔
1071
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_NODES_SHOW, 0,
4,806✔
1072
                                  pCxt->pMetaCache);
1073
  }
1074
  return code;
4,806✔
1075
}
1076
static int32_t collectMetaKeyFromShowXnodeJobs(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
5,891✔
1077
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_XNODE_JOBS,
5,891✔
1078
                                         pCxt->pMetaCache);
1079
  if (TSDB_CODE_SUCCESS == code) {
5,891✔
1080
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_CM_SHOW, 0,
5,891✔
1081
                                  pCxt->pMetaCache);
1082
  }
1083
  return code;
5,891✔
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,206✔
1097
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
2,206✔
1098
                                         TSDB_INS_TABLE_CPU_ALLOCATION, pCxt->pMetaCache);
1099
  if (TSDB_CODE_SUCCESS == code) {
2,206✔
1100
    code = reserveDnodeRequiredInCache(pCxt->pMetaCache);
2,206✔
1101
  }
1102
  return code;
2,206✔
1103
}
1104

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

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

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

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

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

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

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

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

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

1197
  if (TSDB_CODE_SUCCESS == code) {
374,779✔
1198
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
374,779✔
1199
  }
1200
  if (TSDB_CODE_SUCCESS == code) {
374,779✔
1201
    code =
1202
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
374,779✔
1203
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1204
  }
1205
  return code;
374,779✔
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) {
743,308✔
1226
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TAGS,
743,308✔
1227
                                         pCxt->pMetaCache);
1228
  if (TSDB_CODE_SUCCESS == code) {
743,308✔
1229
    code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal,
1,486,214✔
1230
                                   ((SValueNode*)pStmt->pTbName)->literal, pCxt->pMetaCache);
743,308✔
1231
  }
1232
  if (TSDB_CODE_SUCCESS == code) {
743,308✔
1233
    code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
743,308✔
1234
  }
1235
  if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pTbName) {
743,308✔
1236
    code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal,
1,486,214✔
1237
                                     ((SValueNode*)pStmt->pTbName)->literal, pCxt->pMetaCache);
743,308✔
1238
  }
1239
  return code;
743,308✔
1240
}
1241

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1361
static int32_t collectMetaKeyFromShowRolePrivileges(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
1,318✔
1362
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
1,318✔
1363
                                         TSDB_INS_TABLE_ROLE_PRIVILEGES, pCxt->pMetaCache);
1364
  if (TSDB_CODE_SUCCESS == code) {
1,318✔
1365
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_SHOW_PRIVILEGES, 0,
1,318✔
1366
                                  pCxt->pMetaCache);
1367
  }
1368
  return code;
1,318✔
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) {
16,605✔
1382
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VIEWS,
16,605✔
1383
                                         pCxt->pMetaCache);
1384
  if (TSDB_CODE_SUCCESS == code) {
16,605✔
1385
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
16,605✔
1386
  }
1387
  if (TSDB_CODE_SUCCESS == code) {
16,605✔
1388
    code =
1389
        reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
16,605✔
1390
                               NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1391
  }
1392
  return code;
16,605✔
1393
}
1394

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

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

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

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

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

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

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

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

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

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

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

1476
static int32_t collectMetaKeyFromShowEncryptAlgorithms(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
853✔
1477
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
853✔
1478
                                         TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, pCxt->pMetaCache);
1479
  return code;
853✔
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,056✔
1489
  int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MOUNTS,
2,056✔
1490
                                         pCxt->pMetaCache);
1491
  if (TSDB_CODE_SUCCESS == code) {
2,056✔
1492
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL, PRIV_MOUNT_SHOW, 0,
2,056✔
1493
                                  pCxt->pMetaCache);
1494
  }
1495
  return code;
2,056✔
1496
}
1497

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

1507
static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShowCreateTableStmt* pStmt) {
119,708✔
1508
  SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
119,708✔
1509
  tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
119,708✔
1510
  tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
119,708✔
1511
  int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
119,708✔
1512
  if (TSDB_CODE_SUCCESS == code) {
119,708✔
1513
    code = reserveTableCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
119,708✔
1514
  }
1515
  if (TSDB_CODE_SUCCESS == code) {
119,708✔
1516
    code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
119,708✔
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) {
119,708✔
1523
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, PRIV_DB_USE,
119,708✔
1524
                                  PRIV_OBJ_DB, pCxt->pMetaCache);
1525
  }
1526
  if (TSDB_CODE_SUCCESS == code) {
119,708✔
1527
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
119,708✔
1528
                                  PRIV_CM_SHOW_CREATE, PRIV_OBJ_TBL, pCxt->pMetaCache);
1529
  }
1530
  return code;
119,708✔
1531
}
1532

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1705
  if (pStmt->optrType == TSDB_ALTER_ROLE_ROLE) {
1,584,933✔
1706
    if (pStmt->roleName[0] == 'S' && pStmt->roleName[1] == 'Y' && pStmt->roleName[2] == 'S') {
20,470✔
1707
      if (strcmp(pStmt->roleName, TSDB_ROLE_SYSDBA) == 0) {
18,730✔
1708
        return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
3,360✔
1709
                                      grant ? PRIV_GRANT_SYSDBA : PRIV_REVOKE_SYSDBA, 0, pCxt->pMetaCache);
1710
      }
1711
      if (strcmp(pStmt->roleName, TSDB_ROLE_SYSSEC) == 0) {
15,370✔
1712
        return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
3,808✔
1713
                                      grant ? PRIV_GRANT_SYSSEC : PRIV_REVOKE_SYSSEC, 0, pCxt->pMetaCache);
1714
      }
1715
      if (strcmp(pStmt->roleName, TSDB_ROLE_SYSAUDIT) == 0) {
11,562✔
1716
        return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
2,304✔
1717
                                      grant ? PRIV_GRANT_SYSAUDIT : PRIV_REVOKE_SYSAUDIT, 0, pCxt->pMetaCache);
1718
      }
1719
    }
1720
  } else if (TSDB_ALTER_ROLE_PRIVILEGES == pStmt->optrType) {
1,564,463✔
1721
    bool isRealObj = IS_SPECIFIC_OBJ(pStmt->objName);
1,564,463✔
1722
    if (isRealObj) {
1,564,463✔
1723
      code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->objName, pCxt->pMetaCache);
1,535,356✔
1724
    }
1725
    if (TSDB_CODE_SUCCESS == code) {
1,564,463✔
1726
      if (isRealObj && IS_SPECIFIC_OBJ(pStmt->tabName)) {
1,564,463✔
1727
        if (PRIV_OBJ_TBL == pStmt->privileges.objType) {
741,180✔
1728
          code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
13,745✔
1729
        } else if (PRIV_OBJ_VIEW == pStmt->privileges.objType || PRIV_OBJ_NONE == pStmt->privileges.objType) {
727,435✔
1730
          code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
715,863✔
1731
          pCxt->pMetaCache->forceFetchViewMeta = true;
715,863✔
1732
        } else {
1733
          // TODO: other object types
1734
        }
1735
      }
1736
    }
1737
  }
1738
  if (TSDB_CODE_SUCCESS == code) {
1,575,461✔
1739
    code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, NULL, NULL,
1,575,461✔
1740
                                  grant ? PRIV_GRANT_PRIVILEGE : PRIV_REVOKE_PRIVILEGE, 0, pCxt->pMetaCache);
1741
  }
1742

1743
  return code;
1,575,461✔
1744
}
1745

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

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

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

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

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

1782
  return code;
245,306✔
1783
}
1784

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

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

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

1849
  return code;
9,624✔
1850
}
1851

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

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

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

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

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

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

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

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

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

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

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

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

1980
EPrivType getAlterUserPrivType(const char* pCurrentUser, const SAlterUserStmt* pStmt) {
140,138✔
1981
  EPrivType     privType = PRIV_USER_ALTER;
140,138✔
1982
  SUserOptions* pOptions = pStmt->pUserOptions;
140,138✔
1983
  if ((pOptions->hasPassword) &&
140,138✔
1984
      !(pOptions->hasTotpseed || pOptions->hasEnable || pOptions->hasSysinfo || pOptions->hasIsImport ||
85,136✔
1985
        pOptions->hasChangepass || pOptions->hasCreatedb || pOptions->hasSessionPerUser || pOptions->hasConnectTime ||
85,136✔
1986
        pOptions->hasConnectIdleTime || pOptions->hasCallPerSession || pOptions->hasVnodePerCall ||
85,136✔
1987
        pOptions->hasFailedLoginAttempts || pOptions->hasPasswordLifeTime || pOptions->hasPasswordReuseTime ||
85,136✔
1988
        pOptions->hasPasswordReuseMax || pOptions->hasPasswordLockTime || pOptions->hasPasswordGraceTime ||
85,136✔
1989
        pOptions->hasInactiveAccountTime || pOptions->hasAllowTokenNum || pOptions->pSecurityLevels)) {
85,136✔
1990
    if (pCurrentUser && strncmp(pCurrentUser, pStmt->userName, TSDB_USER_LEN) == 0) {
85,136✔
1991
      privType = PRIV_PASS_ALTER_SELF;
8,596✔
1992
    } else {
1993
      privType = PRIV_PASS_ALTER;
76,540✔
1994
    }
1995
  }
1996
  return privType;
140,138✔
1997
}
1998

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

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

2010
static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
1,037,778,590✔
2011
  int32_t code = 0;
1,037,778,590✔
2012
  SNode*  pOrigStmt = pCxt->pStmt;
1,037,778,590✔
2013
  pCxt->pStmt = pStmt;
1,037,783,842✔
2014

2015
  switch (nodeType(pStmt)) {
1,037,783,820✔
2016
    case QUERY_NODE_SET_OPERATOR:
15,578,509✔
2017
      code = collectMetaKeyFromSetOperator(pCxt, (SSetOperator*)pStmt);
15,578,509✔
2018
      break;
15,578,881✔
2019
    case QUERY_NODE_SELECT_STMT:
738,433,399✔
2020
      code = collectMetaKeyFromSelect(pCxt, (SSelectStmt*)pStmt);
738,433,399✔
2021
      break;
738,446,759✔
2022
    case QUERY_NODE_ALTER_DATABASE_STMT:
228,329✔
2023
      code = collectMetaKeyFromAlterDatabase(pCxt, (SAlterDatabaseStmt*)pStmt);
228,329✔
2024
      break;
228,329✔
2025
    case QUERY_NODE_FLUSH_DATABASE_STMT:
2,108,242✔
2026
      code = collectMetaKeyFromFlushDatabase(pCxt, (SFlushDatabaseStmt*)pStmt);
2,108,242✔
2027
      break;
2,108,242✔
2028
    case QUERY_NODE_CREATE_TABLE_STMT:
10,260,572✔
2029
      code = collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt);
10,260,572✔
2030
      break;
10,260,572✔
2031
    case QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT:
247,272✔
2032
      code = collectMetaKeyFromCreateVTable(pCxt, (SCreateVTableStmt*)pStmt);
247,272✔
2033
      break;
247,272✔
2034
    case QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT:
437,825✔
2035
      code = collectMetaKeyFromCreateVSubTable(pCxt, (SCreateVSubTableStmt*)pStmt);
437,825✔
2036
      break;
437,825✔
2037
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
39,792,617✔
2038
      code = collectMetaKeyFromCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
39,792,617✔
2039
      break;
39,826,251✔
2040
    case QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE:
1,534✔
2041
      code = collectMetaKeyFromCreateSubTableFromFile(pCxt, (SCreateSubTableFromFileClause*)pStmt);
1,534✔
2042
      break;
1,534✔
2043
    case QUERY_NODE_DROP_TABLE_STMT:
2,739,548✔
2044
      code = collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
2,739,548✔
2045
      break;
2,739,548✔
2046
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
111,072✔
2047
      code = collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
111,072✔
2048
      break;
111,072✔
2049
    case QUERY_NODE_DROP_VIRTUAL_TABLE_STMT:
82,610✔
2050
      code = collectMetaKeyFromDropVtable(pCxt, (SDropVirtualTableStmt*)pStmt);
82,610✔
2051
      break;
82,610✔
2052
    case QUERY_NODE_ALTER_TABLE_STMT:
21,080,195✔
2053
      code = collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
21,080,195✔
2054
      break;
21,080,195✔
2055
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
592,659✔
2056
      code = collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt);
592,659✔
2057
      break;
592,659✔
2058
    case QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT:
472,945✔
2059
      code = collectMetaKeyFromAlterVtable(pCxt, (SAlterTableStmt*)pStmt);
472,945✔
2060
      break;
472,945✔
2061
    case QUERY_NODE_USE_DATABASE_STMT:
92,472,650✔
2062
      code = collectMetaKeyFromUseDatabase(pCxt, (SUseDatabaseStmt*)pStmt);
92,472,650✔
2063
      break;
92,477,832✔
2064
    case QUERY_NODE_CREATE_INDEX_STMT:
24,647✔
2065
      code = collectMetaKeyFromCreateIndex(pCxt, (SCreateIndexStmt*)pStmt);
24,647✔
2066
      break;
24,647✔
2067
    case QUERY_NODE_DROP_INDEX_STMT:
12,031✔
2068
      code = collectMetaKeyFromDropIndex(pCxt, (SDropIndexStmt*)pStmt);
12,031✔
2069
      break;
12,031✔
2070
    case QUERY_NODE_CREATE_TOPIC_STMT:
217,854✔
2071
      code = collectMetaKeyFromCreateTopic(pCxt, (SCreateTopicStmt*)pStmt);
217,854✔
2072
      break;
217,854✔
2073
    case QUERY_NODE_EXPLAIN_STMT:
94,955,134✔
2074
      code = collectMetaKeyFromExplain(pCxt, (SExplainStmt*)pStmt);
94,955,134✔
2075
      break;
94,973,828✔
2076
    case QUERY_NODE_DESCRIBE_STMT:
624,005✔
2077
      code = collectMetaKeyFromDescribe(pCxt, (SDescribeStmt*)pStmt);
624,005✔
2078
      break;
623,984✔
2079
    case QUERY_NODE_COMPACT_DATABASE_STMT:
34,569✔
2080
      code = collectMetaKeyFromCompactDatabase(pCxt, (SCompactDatabaseStmt*)pStmt);
34,569✔
2081
      break;
34,569✔
2082
    case QUERY_NODE_ROLLUP_DATABASE_STMT:
12,778✔
2083
      code = collectMetaKeyFromRollupDatabase(pCxt, (SRollupDatabaseStmt*)pStmt);
12,778✔
2084
      break;
12,778✔
2085
    case QUERY_NODE_SCAN_DATABASE_STMT:
988✔
2086
      code = collectMetaKeyFromScanDatabase(pCxt, (SScanDatabaseStmt*)pStmt);
988✔
2087
      break;
988✔
2088
    case QUERY_NODE_SSMIGRATE_DATABASE_STMT:
3,498✔
2089
      code = collectMetaKeyFromSsmigrateDatabase(pCxt, (SSsMigrateDatabaseStmt*)pStmt);
3,498✔
2090
      break;
3,498✔
2091
    case QUERY_NODE_TRIM_DATABASE_STMT:
10,775✔
2092
      code = collectMetaKeyFromTrimDatabase(pCxt, (STrimDatabaseStmt*)pStmt);
10,775✔
2093
      break;
10,775✔
2094
    case QUERY_NODE_COMPACT_VGROUPS_STMT:
4,155✔
2095
      code = collectMetaKeyFromCompactVgroups(pCxt, (SCompactVgroupsStmt*)pStmt);
4,155✔
2096
      break;
4,155✔
2097
    case QUERY_NODE_ROLLUP_VGROUPS_STMT:
4,956✔
2098
      code = collectMetaKeyFromRollupVgroups(pCxt, (SRollupVgroupsStmt*)pStmt);
4,956✔
2099
      break;
4,956✔
2100
    case QUERY_NODE_SCAN_VGROUPS_STMT:
345✔
2101
      code = collectMetaKeyFromScanVgroups(pCxt, (SScanVgroupsStmt*)pStmt);
345✔
2102
      break;
345✔
2103
    case QUERY_NODE_CREATE_STREAM_STMT:
438,078✔
2104
      code = collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
438,078✔
2105
      break;
438,078✔
2106
    case QUERY_NODE_RECALCULATE_STREAM_STMT:
13,752✔
2107
      code = collectMetaKeyFromRecalculateStream(pCxt, (SRecalcStreamStmt*)pStmt);
13,752✔
2108
      break;
13,752✔
2109
    case QUERY_NODE_GRANT_STMT:
1,041,858✔
2110
      code = collectMetaKeyFromGrant(pCxt, (SGrantStmt*)pStmt);
1,041,858✔
2111
      break;
1,041,858✔
2112
    case QUERY_NODE_REVOKE_STMT:
543,075✔
2113
      code = collectMetaKeyFromRevoke(pCxt, (SRevokeStmt*)pStmt);
543,075✔
2114
      break;
543,075✔
2115
    case QUERY_NODE_SHOW_DNODES_STMT:
25,730✔
2116
      code = collectMetaKeyFromShowDnodes(pCxt, (SShowStmt*)pStmt);
25,730✔
2117
      break;
25,730✔
2118
    case QUERY_NODE_SHOW_MNODES_STMT:
380,457✔
2119
      code = collectMetaKeyFromShowMnodes(pCxt, (SShowStmt*)pStmt);
380,457✔
2120
      break;
380,457✔
2121
    case QUERY_NODE_SHOW_MODULES_STMT:
×
2122
      code = collectMetaKeyFromShowModules(pCxt, (SShowStmt*)pStmt);
×
2123
      break;
×
2124
    case QUERY_NODE_SHOW_QNODES_STMT:
2,404✔
2125
      code = collectMetaKeyFromShowQnodes(pCxt, (SShowStmt*)pStmt);
2,404✔
2126
      break;
2,404✔
2127
    case QUERY_NODE_SHOW_SNODES_STMT:
80,447✔
2128
      code = collectMetaKeyFromShowSnodes(pCxt, (SShowStmt*)pStmt);
80,447✔
2129
      break;
80,447✔
2130
    case QUERY_NODE_SHOW_ANODES_STMT:
206✔
2131
      code = collectMetaKeyFromShowAnodes(pCxt, (SShowStmt*)pStmt);
206✔
2132
      break;
206✔
2133
    case QUERY_NODE_SHOW_ANODES_FULL_STMT:
×
2134
      code = collectMetaKeyFromShowAnodesFull(pCxt, (SShowStmt*)pStmt);
×
2135
      break;
×
2136
    case QUERY_NODE_SHOW_BNODES_STMT:
69,707✔
2137
      code = collectMetaKeyFromShowBnodes(pCxt, (SShowStmt*)pStmt);
69,707✔
2138
      break;
69,707✔
2139
    case QUERY_NODE_SHOW_BACKUP_NODES_STMT:
×
2140
      code = collectMetaKeyFromShowBackupNodes(pCxt, (SShowStmt*)pStmt);
×
2141
      break;
×
2142
    case QUERY_NODE_SHOW_XNODES_STMT:
2,627✔
2143
      code = collectMetaKeyFromShowXnodes(pCxt, (SShowStmt*)pStmt);
2,627✔
2144
      break;
2,627✔
2145
    case QUERY_NODE_SHOW_XNODE_TASKS_STMT:
8,061✔
2146
      code = collectMetaKeyFromShowXnodeTasks(pCxt, (SShowStmt*)pStmt);
8,061✔
2147
      break;
8,061✔
2148
    case QUERY_NODE_SHOW_XNODE_AGENTS_STMT:
4,806✔
2149
      code = collectMetaKeyFromShowXnodeAgents(pCxt, (SShowStmt*)pStmt);
4,806✔
2150
      break;
4,806✔
2151
    case QUERY_NODE_SHOW_XNODE_JOBS_STMT:
5,891✔
2152
      code = collectMetaKeyFromShowXnodeJobs(pCxt, (SShowStmt*)pStmt);
5,891✔
2153
      break;
5,891✔
2154
    case QUERY_NODE_SHOW_ARBGROUPS_STMT:
722✔
2155
      code = collectMetaKeyFromShowArbGroups(pCxt, (SShowStmt*)pStmt);
722✔
2156
      break;
722✔
2157
    case QUERY_NODE_SHOW_CLUSTER_STMT:
3,014✔
2158
      code = collectMetaKeyFromShowCluster(pCxt, (SShowStmt*)pStmt);
3,014✔
2159
      break;
3,014✔
2160
    case QUERY_NODE_SHOW_SECURITY_POLICIES_STMT:
564✔
2161
      code = collectMetaKeyFromShowSecurityPolicies(pCxt, (SShowStmt*)pStmt);
564✔
2162
      break;
564✔
2163
    case QUERY_NODE_SHOW_DATABASES_STMT:
216,029✔
2164
      code = collectMetaKeyFromShowDatabases(pCxt, (SShowStmt*)pStmt);
216,029✔
2165
      break;
216,029✔
2166
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
13,009✔
2167
      code = collectMetaKeyFromShowFunctions(pCxt, (SShowStmt*)pStmt);
13,009✔
2168
      break;
13,009✔
2169
    case QUERY_NODE_SHOW_INDEXES_STMT:
8,146✔
2170
      code = collectMetaKeyFromShowIndexes(pCxt, (SShowStmt*)pStmt);
8,146✔
2171
      break;
8,146✔
2172
    case QUERY_NODE_SHOW_STABLES_STMT:
267,922✔
2173
      code = collectMetaKeyFromShowStables(pCxt, (SShowStmt*)pStmt);
267,922✔
2174
      break;
267,922✔
2175
    case QUERY_NODE_SHOW_STREAMS_STMT:
133,071✔
2176
      code = collectMetaKeyFromShowStreams(pCxt, (SShowStmt*)pStmt);
133,071✔
2177
      break;
133,071✔
2178
    case QUERY_NODE_SHOW_TABLES_STMT:
374,779✔
2179
    case QUERY_NODE_SHOW_VTABLES_STMT:
2180
      code = collectMetaKeyFromShowTables(pCxt, (SShowStmt*)pStmt);
374,779✔
2181
      break;
374,779✔
2182
    case QUERY_NODE_SHOW_FILESETS_STMT:
×
2183
      code = collectMetaKeyFromShowFilesets(pCxt, (SShowStmt*)pStmt);
×
2184
      break;
×
2185
    case QUERY_NODE_SHOW_TAGS_STMT:
743,308✔
2186
      code = collectMetaKeyFromShowTags(pCxt, (SShowStmt*)pStmt);
743,308✔
2187
      break;
743,308✔
2188
    case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
7,563✔
2189
      code = collectMetaKeyFromShowStableTags(pCxt, (SShowTableTagsStmt*)pStmt);
7,563✔
2190
      break;
7,563✔
2191
    case QUERY_NODE_SHOW_USERS_STMT:
121,538✔
2192
      code = collectMetaKeyFromShowUsers(pCxt, (SShowStmt*)pStmt);
121,538✔
2193
      break;
121,538✔
2194
    case QUERY_NODE_SHOW_USERS_FULL_STMT:
16,492✔
2195
      code = collectMetaKeyFromShowUsersFull(pCxt, (SShowStmt*)pStmt);
16,492✔
2196
      break;
16,492✔
2197
    case QUERY_NODE_SHOW_ROLES_STMT:
1,570✔
2198
      code = collectMetaKeyFromShowRoles(pCxt, (SShowStmt*)pStmt);
1,570✔
2199
      break;
1,570✔
2200
    case QUERY_NODE_SHOW_LICENCES_STMT:
3,642✔
2201
      code = collectMetaKeyFromShowLicence(pCxt, (SShowStmt*)pStmt);
3,642✔
2202
      break;
3,642✔
2203
    case QUERY_NODE_SHOW_VGROUPS_STMT:
256,350✔
2204
      code = collectMetaKeyFromShowVgroups(pCxt, (SShowStmt*)pStmt);
256,350✔
2205
      break;
256,350✔
2206
    case QUERY_NODE_SHOW_TOPICS_STMT:
22,124✔
2207
      code = collectMetaKeyFromShowTopics(pCxt, (SShowStmt*)pStmt);
22,124✔
2208
      break;
22,124✔
2209
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
17,676✔
2210
      code = collectMetaKeyFromShowConsumers(pCxt, (SShowStmt*)pStmt);
17,676✔
2211
      break;
17,676✔
2212
    case QUERY_NODE_SHOW_CONNECTIONS_STMT:
2,806✔
2213
      code = collectMetaKeyFromShowConnections(pCxt, (SShowStmt*)pStmt);
2,806✔
2214
      break;
2,806✔
2215
    case QUERY_NODE_SHOW_QUERIES_STMT:
3,804✔
2216
      code = collectMetaKeyFromShowQueries(pCxt, (SShowStmt*)pStmt);
3,804✔
2217
      break;
3,804✔
2218
    case QUERY_NODE_SHOW_VARIABLES_STMT:
6,793✔
2219
      code = collectMetaKeyFromShowVariables(pCxt, (SShowStmt*)pStmt);
6,793✔
2220
      break;
6,793✔
2221
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
46,997✔
2222
      code = collectMetaKeyFromShowDnodeVariables(pCxt, (SShowDnodeVariablesStmt*)pStmt);
46,997✔
2223
      break;
46,997✔
2224
    case QUERY_NODE_SHOW_VNODES_STMT:
9,110✔
2225
      code = collectMetaKeyFromShowVnodes(pCxt, (SShowVnodesStmt*)pStmt);
9,110✔
2226
      break;
9,110✔
2227
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
4,434✔
2228
      code = collectMetaKeyFromShowUserPrivileges(pCxt, (SShowStmt*)pStmt);
4,434✔
2229
      break;
4,434✔
2230
    case QUERY_NODE_SHOW_ROLE_PRIVILEGES_STMT:
1,318✔
2231
      code = collectMetaKeyFromShowRolePrivileges(pCxt, (SShowStmt*)pStmt);
1,318✔
2232
      break;
1,318✔
2233
    case QUERY_NODE_SHOW_ROLE_COL_PRIVILEGES_STMT:
×
2234
      code = collectMetaKeyFromShowRoleColPrivileges(pCxt, (SShowStmt*)pStmt);
×
2235
      break;
×
2236
    case QUERY_NODE_SHOW_VIEWS_STMT:
16,605✔
2237
      code = collectMetaKeyFromShowViews(pCxt, (SShowStmt*)pStmt);
16,605✔
2238
      break;
16,605✔
2239
    case QUERY_NODE_SHOW_COMPACTS_STMT:
402,734✔
2240
      code = collectMetaKeyFromShowCompacts(pCxt, (SShowStmt*)pStmt);
402,734✔
2241
      break;
402,734✔
2242
    case QUERY_NODE_SHOW_SCANS_STMT:
3,105✔
2243
      code = collectMetaKeyFromShowScans(pCxt, (SShowStmt*)pStmt);
3,105✔
2244
      break;
3,105✔
2245
    case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
33,460✔
2246
      code = collectMetaKeyFromShowCompactDetails(pCxt, (SShowStmt*)pStmt);
33,460✔
2247
      break;
33,460✔
2248
    case QUERY_NODE_SHOW_SCAN_DETAILS_STMT:
2,622✔
2249
      code = collectMetaKeyFromShowScanDetails(pCxt, (SShowStmt*)pStmt);
2,622✔
2250
      break;
2,622✔
2251
    case QUERY_NODE_SHOW_SSMIGRATES_STMT:
96,642✔
2252
      code = collectMetaKeyFromShowSsMigrates(pCxt, (SShowStmt*)pStmt);
96,642✔
2253
      break;
96,642✔
2254
    case QUERY_NODE_SHOW_TOKENS_STMT:
2,178✔
2255
      code = collectMetaKeyFromShowTokens(pCxt, (SShowStmt*)pStmt);
2,178✔
2256
      break;
2,178✔
2257
    case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
357✔
2258
      code = collectMetaKeyFromShowTransactionDetails(pCxt, (SShowStmt*)pStmt);
357✔
2259
      break;
357✔
2260
    case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
2,462✔
2261
      code = collectMetaKeyFromShowGrantsFull(pCxt, (SShowStmt*)pStmt);
2,462✔
2262
      break;
2,462✔
2263
    case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
1,952✔
2264
      code = collectMetaKeyFromShowGrantsLogs(pCxt, (SShowStmt*)pStmt);
1,952✔
2265
      break;
1,952✔
2266
    case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT:
2,172✔
2267
      code = collectMetaKeyFromShowClusterMachines(pCxt, (SShowStmt*)pStmt);
2,172✔
2268
      break;
2,172✔
2269
    case QUERY_NODE_SHOW_ENCRYPTIONS_STMT:
214✔
2270
      code = collectMetaKeyFromShowEncryptions(pCxt, (SShowStmt*)pStmt);
214✔
2271
      break;
214✔
2272
    case QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT:
853✔
2273
      code = collectMetaKeyFromShowEncryptAlgorithms(pCxt, (SShowStmt*)pStmt);
853✔
2274
      break;
853✔
2275
    case QUERY_NODE_SHOW_ENCRYPT_STATUS_STMT:
×
2276
      code = collectMetaKeyFromShowEncryptStatus(pCxt, (SShowStmt*)pStmt);
×
2277
      break;
×
2278
    case QUERY_NODE_SHOW_MOUNTS_STMT:
2,056✔
2279
      code = collectMetaKeyFromShowMounts(pCxt, (SShowStmt*)pStmt);
2,056✔
2280
      break;
2,056✔
2281
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
79,658✔
2282
      code = collectMetaKeyFromShowCreateDatabase(pCxt, (SShowCreateDatabaseStmt*)pStmt);
79,658✔
2283
      break;
79,658✔
2284
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
119,708✔
2285
    case QUERY_NODE_SHOW_CREATE_VTABLE_STMT:
2286
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
2287
      code = collectMetaKeyFromShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
119,708✔
2288
      break;
119,708✔
2289
    case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
9,586✔
2290
      code = collectMetaKeyFromShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
9,586✔
2291
      break;
9,586✔
2292
    case QUERY_NODE_SHOW_CREATE_RSMA_STMT:
3,668✔
2293
      code = collectMetaKeyFromShowCreateRsma(pCxt, (SShowCreateRsmaStmt*)pStmt);
3,668✔
2294
      break;
3,668✔
2295
    case QUERY_NODE_SHOW_APPS_STMT:
2,172✔
2296
      code = collectMetaKeyFromShowApps(pCxt, (SShowStmt*)pStmt);
2,172✔
2297
      break;
2,172✔
2298
    case QUERY_NODE_SHOW_INSTANCES_STMT:
1,184✔
2299
      code = collectMetaKeyFromShowInstances(pCxt, (SShowStmt*)pStmt);
1,184✔
2300
      break;
1,184✔
2301
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
528,060✔
2302
      code = collectMetaKeyFromShowTransactions(pCxt, (SShowStmt*)pStmt);
528,060✔
2303
      break;
528,060✔
2304
    case QUERY_NODE_SHOW_USAGE_STMT:
403✔
2305
      code = collectMetaKeyFromShowUsage(pCxt, (SShowStmt*)pStmt);
403✔
2306
      break;
403✔
2307
    case QUERY_NODE_DELETE_STMT:
2,053,381✔
2308
      code = collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt);
2,053,381✔
2309
      break;
2,053,381✔
2310
    case QUERY_NODE_INSERT_STMT:
578,546✔
2311
      code = collectMetaKeyFromInsert(pCxt, (SInsertStmt*)pStmt);
578,546✔
2312
      break;
578,546✔
2313
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
4,112✔
2314
      code = collectMetaKeyFromShowBlockDist(pCxt, (SShowTableDistributedStmt*)pStmt);
4,112✔
2315
      break;
4,112✔
2316
    case QUERY_NODE_SHOW_VALIDATE_VTABLE_STMT:
4,086✔
2317
      code = collectMetaKeyFromShowValidateVtable(pCxt, (SShowValidateVirtualTable*)pStmt);
4,086✔
2318
      break;
4,086✔
2319
    case QUERY_NODE_SHOW_CPU_ALLOCATION_STMT:
2,206✔
2320
      code = collectMetaKeyFromShowCpuAllocation(pCxt, (SShowStmt*)pStmt);
2,206✔
2321
      break;
2,206✔
2322
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
28,471✔
2323
      code = collectMetaKeyFromShowSubscriptions(pCxt, (SShowStmt*)pStmt);
28,471✔
2324
      break;
28,471✔
2325
    case QUERY_NODE_CREATE_VIEW_STMT:
245,306✔
2326
      code = collectMetaKeyFromCreateViewStmt(pCxt, (SCreateViewStmt*)pStmt);
245,306✔
2327
      break;
245,306✔
2328
    case QUERY_NODE_DROP_VIEW_STMT:
183,464✔
2329
      code = collectMetaKeyFromDropViewStmt(pCxt, (SDropViewStmt*)pStmt);
183,464✔
2330
      break;
183,464✔
2331
    case QUERY_NODE_CREATE_TSMA_STMT:
9,624✔
2332
      code = collectMetaKeyFromCreateTSMAStmt(pCxt, (SCreateTSMAStmt*)pStmt);
9,624✔
2333
      break;
9,624✔
2334
    case QUERY_NODE_DROP_TSMA_STMT:
4,560✔
2335
      code = collectMetaKeyFromDropTSMAStmt(pCxt, (SDropTSMAStmt*)pStmt);
4,560✔
2336
      break;
4,560✔
2337
    case QUERY_NODE_SHOW_TSMAS_STMT:
510✔
2338
      code = collectMetaKeyFromShowTSMASStmt(pCxt, (SShowStmt*)pStmt);
510✔
2339
      break;
510✔
2340
    case QUERY_NODE_CREATE_RSMA_STMT:
125,260✔
2341
      code = collectMetaKeyFromCreateRsmaStmt(pCxt, (SCreateRsmaStmt*)pStmt);
125,260✔
2342
      break;
125,260✔
2343
    case QUERY_NODE_DROP_RSMA_STMT:
11,418✔
2344
      code = collectMetaKeyFromDropRsmaStmt(pCxt, (SDropRsmaStmt*)pStmt);
11,418✔
2345
      break;
11,418✔
2346
    case QUERY_NODE_ALTER_RSMA_STMT:
23,322✔
2347
      code = collectMetaKeyFromAlterRsmaStmt(pCxt, (SAlterRsmaStmt*)pStmt);
23,322✔
2348
      break;
23,322✔
2349
    case QUERY_NODE_SHOW_RSMAS_STMT:
15,378✔
2350
      code = collectMetaKeyFromShowRsmasStmt(pCxt, (SShowStmt*)pStmt);
15,378✔
2351
      break;
15,378✔
2352
    case QUERY_NODE_SHOW_RETENTIONS_STMT:
45,531✔
2353
      code = collectMetaKeyFromShowRetentionsStmt(pCxt, (SShowStmt*)pStmt);
45,531✔
2354
      break;
45,531✔
2355
    case QUERY_NODE_SHOW_RETENTION_DETAILS_STMT:
2,478✔
2356
      code = collectMetaKeyFromShowRetentionDetailsStmt(pCxt, (SShowStmt*)pStmt);
2,478✔
2357
      break;
2,478✔
2358
    case QUERY_NODE_SHOW_DB_ALIVE_STMT:
6,313✔
2359
    case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
2360
      code = collectMetaKeyFromShowAlive(pCxt, (SShowAliveStmt*)pStmt);
6,313✔
2361
      break;
6,313✔
2362
    case QUERY_NODE_CREATE_DATABASE_STMT:
1,795,102✔
2363
      code = collectMetaKeyFromCreateDatabase(pCxt, (SCreateDatabaseStmt*)pStmt);
1,795,102✔
2364
      break;
1,795,102✔
2365
    case QUERY_NODE_DROP_DATABASE_STMT:
1,536,550✔
2366
      code = collectMetaKeyFromDropDatabase(pCxt, (SDropDatabaseStmt*)pStmt);
1,536,550✔
2367
      break;
1,536,550✔
2368
    case QUERY_NODE_BALANCE_VGROUP_STMT:
14,375✔
2369
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_BALANCE);
14,375✔
2370
      break;
14,375✔
2371
    case QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT:
4,014✔
2372
    case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT:
2373
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_BALANCE_LEADER);
4,014✔
2374
      break;
4,014✔
2375
    case QUERY_NODE_MERGE_VGROUP_STMT:
×
2376
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_MERGE);
×
2377
      break;
×
2378
    case QUERY_NODE_SPLIT_VGROUP_STMT:
20,582✔
2379
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_SPLIT);
20,582✔
2380
      break;
20,582✔
2381
    case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
52,297✔
2382
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_VG_REDISTRIBUTE);
52,297✔
2383
      break;
52,297✔
2384
    case QUERY_NODE_CREATE_FUNCTION_STMT:
17,310✔
2385
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_FUNC_CREATE);
17,310✔
2386
      break;
17,310✔
2387
    case QUERY_NODE_DROP_FUNCTION_STMT:
14,288✔
2388
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_FUNC_DROP);
14,288✔
2389
      break;
14,288✔
2390
    case QUERY_NODE_CREATE_MOUNT_STMT:
2,232✔
2391
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_MOUNT_CREATE);
2,232✔
2392
      break;
2,232✔
2393
    case QUERY_NODE_DROP_MOUNT_STMT:
688✔
2394
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_MOUNT_DROP);
688✔
2395
      break;
688✔
2396
    case QUERY_NODE_CREATE_ROLE_STMT:
5,426✔
2397
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_ROLE_CREATE);
5,426✔
2398
      break;
5,426✔
2399
    case QUERY_NODE_DROP_ROLE_STMT:
2,232✔
2400
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_ROLE_DROP);
2,232✔
2401
      break;
2,232✔
2402
    case QUERY_NODE_CREATE_USER_STMT:
130,055✔
2403
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_USER_CREATE);
130,055✔
2404
      break;
130,055✔
2405
    case QUERY_NODE_ALTER_USER_STMT:
70,069✔
2406
      code = collectMetaKeyFromAlterUserStmt(pCxt, (SAlterUserStmt*)pStmt);
70,069✔
2407
      break;
70,069✔
2408
    case QUERY_NODE_DROP_USER_STMT:
68,814✔
2409
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_USER_DROP);
68,814✔
2410
      break;
68,814✔
2411
    case QUERY_NODE_ALTER_LOCAL_STMT:
656,490✔
2412
      return collectMetaKeyFromAlterLocalStmt(pCxt, (SAlterLocalStmt*)pStmt);
656,490✔
2413
    case QUERY_NODE_CREATE_DNODE_STMT:
350,176✔
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);
350,176✔
2420
      break;
350,176✔
2421
    case QUERY_NODE_DROP_DNODE_STMT:
120,799✔
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);
120,799✔
2428
      break;
120,799✔
2429
    case QUERY_NODE_KILL_TRANSACTION_STMT:
682✔
2430
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_TRANS_KILL);
682✔
2431
      break;
682✔
2432
    case QUERY_NODE_KILL_QUERY_STMT:
1,657✔
2433
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_QUERY_KILL);
1,657✔
2434
      break;
1,657✔
2435
    case QUERY_NODE_KILL_CONNECTION_STMT:
376✔
2436
      code = collectMetaKeyFromSysPrivStmt(pCxt, PRIV_CONN_KILL);
376✔
2437
      break;
376✔
2438
    default:
2,815,041✔
2439
      break;
2,815,041✔
2440
  }
2441

2442
  pCxt->pStmt = pOrigStmt;
1,037,162,867✔
2443

2444
  return code;
1,037,170,263✔
2445
}
2446

2447
int32_t collectMetaKey(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
477,476,330✔
2448
  SCollectMetaKeyCxt cxt = {.pParseCxt = pParseCxt, .pMetaCache = pMetaCache, .pStmt = pQuery->pRoot};
477,476,330✔
2449
  return collectMetaKeyFromQuery(&cxt, pQuery->pRoot);
477,444,167✔
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