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

taosdata / TDengine / #5034

24 Apr 2026 11:25AM UTC coverage: 73.058%. Remained the same
#5034

push

travis-ci

web-flow
merge: from main to 3.0 branch #35224

merge: from main to 3.0 branch[manual-only]

1336 of 1975 new or added lines in 48 files covered. (67.65%)

14149 existing lines in 164 files now uncovered.

275896 of 377640 relevant lines covered (73.06%)

132944440.29 hits per line

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

92.86
/include/libs/qcom/query.h
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
#ifndef _TD_QUERY_H_
17
#define _TD_QUERY_H_
18

19
// clang-foramt off
20
#ifdef __cplusplus
21
extern "C" {
22
#endif
23

24
#include "systable.h"
25
#include "tarray.h"
26
#include "thash.h"
27
#include "tcol.h"
28
#include "tlog.h"
29
#include "tmsg.h"
30
#include "tmsgcb.h"
31
#include "tsimplehash.h"
32

33
typedef enum {
34
  JOB_TASK_STATUS_NULL = 0,
35
  JOB_TASK_STATUS_INIT,
36
  JOB_TASK_STATUS_EXEC,
37
  JOB_TASK_STATUS_PART_SUCC,
38
  JOB_TASK_STATUS_FETCH,
39
  JOB_TASK_STATUS_SUCC,
40
  JOB_TASK_STATUS_FAIL,
41
  JOB_TASK_STATUS_DROP,
42
  JOB_TASK_STATUS_MAX,
43
} EJobTaskType;
44

45
typedef enum {
46
  TASK_TYPE_HQUERY = 1,
47
  TASK_TYPE_QUERY,
48
} ETaskType;
49

50
typedef enum {
51
  TARGET_TYPE_MNODE = 1,
52
  TARGET_TYPE_VNODE,
53
  TARGET_TYPE_OTHER,
54
} ETargetType;
55

56
typedef enum {
57
  TCOL_TYPE_COLUMN = 1,
58
  TCOL_TYPE_TAG,
59
  TCOL_TYPE_NONE,
60
} ETableColumnType;
61

62
#define QUERY_POLICY_VNODE  1
63
#define QUERY_POLICY_HYBRID 2
64
#define QUERY_POLICY_QNODE  3
65
#define QUERY_POLICY_CLIENT 4
66

67
#define QUERY_RSP_POLICY_DELAY 0
68
#define QUERY_RSP_POLICY_QUICK 1
69

70
#define QUERY_MSG_MASK_SHOW_REWRITE() (1 << 0)
71
#define QUERY_MSG_MASK_AUDIT()        (1 << 1)
72
#define QUERY_MSG_MASK_VIEW()         (1 << 2)
73
#define QUERY_MSG_MASK_SUBQUERY()     (1 << 3)
74

75
#define TEST_SHOW_REWRITE_MASK(m)     (((m)&QUERY_MSG_MASK_SHOW_REWRITE()) != 0)
76
#define TEST_AUDIT_MASK(m)            (((m)&QUERY_MSG_MASK_AUDIT()) != 0)
77
#define TEST_VIEW_MASK(m)             (((m)&QUERY_MSG_MASK_VIEW()) != 0)
78
#define TEST_SUBQUERY_MASK(m)         (((m)&QUERY_MSG_MASK_SUBQUERY()) != 0)
79

80
typedef struct STableComInfo {
81
  uint8_t  numOfTags;     // the number of tags in schema
82
  uint8_t  precision;     // the number of precision
83
  col_id_t numOfColumns;  // the number of columns
84
  int16_t  numOfPKs;
85
  int32_t  rowSize;  // row size of the schema
86
} STableComInfo;
87

88
typedef struct SIndexMeta {
89
#if defined(WINDOWS) || defined(_TD_DARWIN_64)
90
  size_t avoidCompilationErrors;
91
#endif
92

93
} SIndexMeta;
94

95
typedef struct SExecResult {
96
  int32_t  code;
97
  uint64_t numOfRows;
98
  uint64_t numOfBytes;
99
  int32_t  msgType;
100
  void*    res;
101
} SExecResult;
102

103
#pragma pack(push, 1)
104
typedef struct SCTableMeta {
105
  uint64_t uid;
106
  uint64_t suid;
107
  int32_t  vgId;
108
  int8_t   tableType;
109
} SCTableMeta;
110
#pragma pack(pop)
111

112
#pragma pack(push, 1)
113
typedef struct SVCTableMeta {
114
  uint64_t uid;
115
  uint64_t suid;
116
  int32_t  vgId;
117
  int8_t   tableType;
118
  int32_t  numOfColRefs;
119
  int32_t  rversion; // virtual table's column ref's version
120
  SColRef* colRef;
121
  int32_t  numOfTagRefs;
122
  SColRef* tagRef;
123
} SVCTableMeta;
124
#pragma pack(pop)
125

126
#pragma pack(push, 1)
127
typedef struct STableMeta {
128
  // BEGIN: KEEP THIS PART SAME WITH SVCTableMeta
129
  // BEGIN: KEEP THIS PART SAME WITH SCTableMeta
130
  uint64_t uid;
131
  uint64_t suid;
132
  int32_t  vgId;
133
  int8_t   tableType;
134
  // END: KEEP THIS PART SAME WITH SCTableMeta
135

136
  int32_t       numOfColRefs;
137
  int32_t       rversion; // virtual table's column ref's version
138
  SColRef*      colRef;
139
  int32_t       numOfTagRefs;
140
  SColRef*      tagRef;
141
  // END: KEEP THIS PART SAME WITH SVCTableMeta
142

143
  // if the table is TSDB_CHILD_TABLE, the following information is acquired from the corresponding super table meta
144
  // info
145
  int32_t       sversion;
146
  int32_t       tversion;
147
  STableComInfo tableInfo;
148
  SSchemaExt*   schemaExt;  // There is no additional memory allocation, and the pointer is fixed to the next address of
149
                            // the schema content.
150
  union {
151
    uint8_t flag;
152
    struct {
153
      uint8_t virtualStb : 1;
154
      uint8_t isAudit : 1;
155
      uint8_t secLvl : 3;  // security level (0-4), mapped from STableMetaRsp.secLvl
156
      uint8_t reserved : 3;
157
    };
158
  };
159
  int64_t ownerId;
160
  int8_t  secureDelete;
161
  SSchema schema[];
162
} STableMeta;
163
#pragma pack(pop)
164

165
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
166

167
#define TABLE_META_BASE_SIZE(pMeta) \
168
  (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
169

170
#define TABLE_META_SCHEMA_EXT_SIZE(pMeta) \
171
  ((withExtSchema((pMeta)->tableType) && NULL != (pMeta)->schemaExt) ? (pMeta)->tableInfo.numOfColumns * sizeof(SSchemaExt) : 0)
172

173
#define TABLE_META_COL_REF_SIZE(pMeta) \
174
  ((hasRefCol((pMeta)->tableType) && NULL != (pMeta)->colRef) ? (pMeta)->numOfColRefs * sizeof(SColRef) : 0)
175

176
#define TABLE_META_FULL_SIZE(pMeta) \
177
  (NULL == (pMeta) ? 0 : (TABLE_META_BASE_SIZE((pMeta)) + TABLE_META_SCHEMA_EXT_SIZE((pMeta)) + TABLE_META_COL_REF_SIZE((pMeta))))
178

179
static inline void tableMetaResetPointers(STableMeta *pMeta) {
2,147,483,647✔
180
  if (NULL == pMeta) {
2,147,483,647✔
UNCOV
181
    return;
×
182
  }
183

184
  char *pCursor = (char *)pMeta + TABLE_META_BASE_SIZE(pMeta);
2,147,483,647✔
185

186
  if (withExtSchema(pMeta->tableType) && NULL != pMeta->schemaExt) {
2,147,483,647✔
187
    pMeta->schemaExt = (SSchemaExt *)pCursor;
2,147,483,647✔
188
    pCursor += pMeta->tableInfo.numOfColumns * sizeof(SSchemaExt);
2,147,483,647✔
189
  } else {
190
    pMeta->schemaExt = NULL;
29,318,207✔
191
  }
192

193
  if (hasRefCol(pMeta->tableType) && NULL != pMeta->colRef) {
2,147,483,647✔
194
    pMeta->colRef = (SColRef *)pCursor;
11,138,039✔
195
    pCursor += pMeta->numOfColRefs * sizeof(SColRef);
11,138,039✔
196
  } else {
197
    pMeta->colRef = NULL;
2,147,483,647✔
198
  }
199

200
  pMeta->tagRef = NULL;
2,147,483,647✔
201
  pMeta->numOfTagRefs = 0;
2,147,483,647✔
202
}
203

204
typedef struct SViewMeta {
205
  uint64_t viewId;
206
  int64_t  ownerId;
207
  char*    createUser;
208
  char*    querySql;
209
  int8_t   precision;
210
  int8_t   type;
211
  int32_t  version;
212
  int32_t  numOfCols;
213
  SSchema* pSchema;
214
} SViewMeta;
215

216
typedef SRsmaInfoRsp SRsmaMeta;
217
typedef SRsmaMeta SRsmaMetaOutput;
218

219
typedef struct SDBVgInfo {
220
  int32_t vgVersion;
221
  int16_t hashPrefix;
222
  int16_t hashSuffix;
223
  int8_t  hashMethod;
224
  union {
225
    uint8_t flags;
226
    struct {
227
      uint8_t isMount : 1;  // TS-5868
228
      uint8_t padding : 7;
229
    };
230
  };
231
  int32_t   numOfTable;  // DB's table num, unit is TSDB_TABLE_NUM_UNIT
232
  int64_t   stateTs;
233
  SHashObj* vgHash;   // key:vgId, value:SVgroupInfo
234
  SArray*   vgArray;  // SVgroupInfo
235
} SDBVgInfo;
236

237
typedef struct SVGroupHashInfo {
238
  int32_t  vgId;
239
  uint32_t hashBegin;
240
  uint32_t hashEnd;
241
} SVGroupHashInfo;
242

243
typedef struct SDBVgHashInfo {
244
  int16_t   hashPrefix;
245
  int16_t   hashSuffix;
246
  int8_t    hashMethod;
247
  bool      vgSorted;
248
  SArray*   vgArray;   //SArray<SVGroupHashInfo>
249
} SDBVgHashInfo;
250

251
typedef struct SColIdName {
252
  int16_t colId;
253
  char*   colName;
254
} SColIdName;
255

256
typedef struct SStreamVBuildCtx {
257
  int64_t      lastUid;
258
  SRefColInfo* lastCol;
259

260
  SSHashObj*   lastVg;
261
  SSHashObj*   lastVtable;
262
  SArray*      lastOtable;
263
} SStreamVBuildCtx;
264

265
typedef struct SUseDbOutput {
266
  char       db[TSDB_DB_FNAME_LEN];
267
  uint64_t   dbId;
268
  SDBVgInfo* dbVgroup;
269
} SUseDbOutput;
270
typedef SUseDbOutput** SUseDbOutputPPter;
271

272
enum { META_TYPE_NULL_TABLE = 1,
273
       META_TYPE_CTABLE,
274
       META_TYPE_VCTABLE,
275
       META_TYPE_TABLE,
276
       META_TYPE_BOTH_TABLE,
277
       META_TYPE_BOTH_VTABLE};
278

279
typedef struct STableMetaOutput {
280
  int32_t       metaType;
281
  uint64_t      dbId;
282
  char          dbFName[TSDB_DB_FNAME_LEN];
283
  char          ctbName[TSDB_TABLE_NAME_LEN];
284
  char          tbName[TSDB_TABLE_NAME_LEN];
285
  SCTableMeta   ctbMeta;
286
  SVCTableMeta* vctbMeta;
287
  STableMeta*   tbMeta;
288
} STableMetaOutput;
289

290
typedef struct SViewMetaOutput {
291
  char     name[TSDB_VIEW_NAME_LEN];
292
  char     dbFName[TSDB_DB_FNAME_LEN];
293
  char*    querySql;
294
  int8_t   precision;
295
  int32_t  numOfCols;
296
  SSchema* pSchema;
297
} SViewMetaOutput;
298

299
typedef struct SDataBuf {
300
  int32_t  msgType;
301
  void*    pData;
302
  uint32_t len;
303
  void*    handle;
304
  int64_t  handleRefId;
305
  SEpSet*  pEpSet;
306
} SDataBuf;
307

308
typedef struct STargetInfo {
309
  ETargetType type;
310
  char*       dbFName;  // used to update db's vgroup epset
311
  int32_t     vgId;
312
} STargetInfo;
313

314
typedef struct STagsInfo {
315
  SArray*  STagNames;  // STagVal
316
  SArray*  pTagVals;
317
  uint8_t* pTagIndex;
318
  int32_t  numOfTags;
319
} STagsInfo;
320

321
typedef struct SBoundColInfo {
322
  int16_t* pColIndex;  // bound index => schema index
323
  int32_t  numOfCols;
324
  int32_t  numOfBound;
325
  bool     hasBoundCols;
326
  bool     mixTagsCols;
327
  STagsInfo* parseredTags;  // used for partial fixed value stmt
328
} SBoundColInfo;
329

330
typedef struct STableColsData {
331
  char    tbName[TSDB_TABLE_NAME_LEN];
332
  SArray* aCol;
333
  SBlobSet* pBlobSet;
334
  bool    getFromHash;
335
  bool    isOrdered;
336
  bool    isDuplicateTs;
337
} STableColsData;
338

339
typedef struct STableVgUid {
340
  uint64_t uid;
341
  uint64_t suid;
342
  int32_t  vgid;
343
} STableVgUid;
344

345
typedef struct STableBufInfo {
346
  void*   pCurBuff;
347
  SArray* pBufList;
348
  int64_t buffUnit;
349
  int64_t buffSize;
350
  int64_t buffIdx;
351
  int64_t buffOffset;
352
} STableBufInfo;
353

354
typedef struct STableDataCxt {
355
  STableMeta*    pMeta;
356
  STSchema*      pSchema;
357
  SBoundColInfo  boundColsInfo;
358
  SArray*        pValues;  // SColVal
359
  SSubmitTbData* pData;
360
  SRowKey        lastKey;
361
  bool           ordered;
362
  bool           duplicateTs;
363
  int8_t         hasBlob;  // if the table has blob column
364
} STableDataCxt;
365

366
typedef struct SStbInterlaceInfo {
367
  void*          pCatalog;
368
  void*          pQuery;
369
  int32_t        acctId;
370
  char*          dbname;
371
  void*          transport;
372
  SEpSet         mgmtEpSet;
373
  void*          pRequest;
374
  uint64_t       requestId;
375
  int64_t        requestSelf;
376
  bool           tbFromHash;
377
  SHashObj*      pVgroupHash;        // key:vgId, value:SVgroupDataCxt
378
  SArray*        pVgroupList;        // SVgroupDataCxt
379
  SSHashObj*     pTableHash;         // key:tbname, value:STableVgUid
380
  SSHashObj*     pTableRowDataHash;  // key:tbname, value:SSubmitTbData->aRowP
381
  int64_t        tbRemainNum;
382
  STableBufInfo  tbBuf;
383
  char           firstName[TSDB_TABLE_NAME_LEN];
384
  STSchema*      pTSchema;
385
  STableDataCxt* pDataCtx;
386
  void*          boundTags;
387

388
  bool    tableColsReady;
389
  SArray* pTableCols;
390
  int32_t pTableColsIdx;
391
} SStbInterlaceInfo;
392

393
typedef int32_t (*__async_send_cb_fn_t)(void* param, SDataBuf* pMsg, int32_t code);
394
typedef int32_t (*__async_exec_fn_t)(void* param);
395

396
typedef struct SRequestConnInfo {
397
  void*    pTrans;
398
  uint64_t requestId;
399
  int64_t  requestObjRefId;
400
  SEpSet   mgmtEps;
401
} SRequestConnInfo;
402

403
typedef void (*__freeFunc)(void* param);
404

405
// todo add creator/destroyer function
406
typedef struct SMsgSendInfo {
407
  __async_send_cb_fn_t fp;      // async callback function
408
  STargetInfo          target;  // for update epset
409
  __freeFunc           paramFreeFp;
410
  void*                param;
411
  int8_t               streamAHandle;
412
  uint64_t             requestId;
413
  uint64_t             requestObjRefId;
414
  int32_t              msgType;
415
  SDataBuf             msgInfo;
416
} SMsgSendInfo;
417

418
typedef struct SQueryNodeStat {
419
  int32_t tableNum;  // vg table number, unit is TSDB_TABLE_NUM_UNIT
420
} SQueryNodeStat;
421

422
typedef struct SQueryStat {
423
  int64_t inputRowNum;
424
  int32_t inputRowSize;
425
} SQueryStat;
426

427
int32_t initTaskQueue();
428
int32_t cleanupTaskQueue();
429

430
/**
431
 *
432
 * @param execFn      The asynchronously execution function
433
 * @param execParam   The parameters of the execFn
434
 * @param code        The response code during execution the execFn
435
 * @return
436
 */
437
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
438
int32_t taosAsyncWait();
439
int32_t taosAsyncRecover();
440
int32_t taosStmt2AsyncBind(__async_exec_fn_t execFn, void* execParam);
441
bool    beginAsyncWorkShutdown();
442
bool    mayCreateAsyncWork();
443

444
void destroySendMsgInfo(SMsgSendInfo* pMsgBody);
445

446
void destroyAhandle(void* ahandle);
447

448
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, SMsgSendInfo* pInfo,
449
                                bool persistHandle, void* ctx);
450

451
int32_t asyncFreeConnById(void* pTransporter, int64_t pid);
452
;
453
/**
454
 * Asynchronously send message to server, after the response received, the callback will be incured.
455
 *
456
 * @param pTransporter
457
 * @param epSet
458
 * @param pTransporterId
459
 * @param pInfo
460
 * @return
461
 */
462
int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, SMsgSendInfo* pInfo);
463

464
int32_t queryBuildUseDbOutput(SUseDbOutput* pOut, SUseDbRsp* usedbRsp);
465

466
void initQueryModuleMsgHandle();
467

468
const SSchema* tGetTbnameColumnSchema();
469
bool           tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags, bool isVirtual);
470
int32_t        getAsofJoinReverseOp(EOperatorType op);
471
bool           hasDecimalBytesTypeInfo(int32_t bytes);
472
void           schemaToRefDataType(const SSchema* pSchema, STypeMod typeMod, SDataType* pType);
473
bool           isSameRefDataType(const SDataType* pLeft, const SDataType* pRight);
474
int32_t        getNormalColSchemaIndex(const STableMeta* pTableMeta, const char* pColName);
475

476
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp* msg, SCTableMeta* pMeta);
477
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta);
478
int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta);
479
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta);
480
char*   jobTaskStatusStr(int32_t status);
481

482
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name);
483

484
void    destroyQueryExecRes(SExecResult* pRes);
485
int32_t dataConverToStr(char* str, int64_t capacity, int type, void* buf, int32_t bufSize, int32_t* len);
486
void    parseTagDatatoJson(void* p, char** jsonStr, void *charsetCxt);
487
int32_t setColRef(SColRef* colRef, col_id_t colId, const char* colName, char* refColName, char* refTableName, char* refDbName);
488
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
489
void    getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType);
490
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
491
int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst);
492
void    freeVgInfo(SDBVgInfo* vgInfo);
493
void    freeDbCfgInfo(SDbCfgInfo* pInfo);
494
void    qDestroyBoundColInfo(void* pInfo);
495

496
void tFreeStreamVtbOtbInfo(void* param);
497
void tFreeStreamVtbVtbInfo(void* param);
498
void tFreeStreamVtbDbVgInfo(void* param);
499

500
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen,
501
                                          void* (*mallocFp)(int64_t), void (*freeFp)(void*));
502
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize);
503

504
void* getTaskPoolWorkerCb();
505

506
#define SET_META_TYPE_NULL(t)        (t) = META_TYPE_NULL_TABLE
507
#define SET_META_TYPE_CTABLE(t)      (t) = META_TYPE_CTABLE
508
#define SET_META_TYPE_VCTABLE(t)     (t) = META_TYPE_VCTABLE
509
#define SET_META_TYPE_TABLE(t)       (t) = META_TYPE_TABLE
510
#define SET_META_TYPE_BOTH_TABLE(t)  (t) = META_TYPE_BOTH_TABLE
511
#define SET_META_TYPE_BOTH_VTABLE(t) (t) = META_TYPE_BOTH_VTABLE
512

513
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code)                                                   \
514
  ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_TDB_TABLE_NOT_EXIST ||    \
515
   (_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \
516
   (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG ||    \
517
   (_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID))
518
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) \
519
  ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
520
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) \
521
  ((_code) == TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER || (_code) == TSDB_CODE_MND_INVALID_SCHEMA_VER || (_code) == TSDB_CODE_SCH_DATA_SRC_EP_MISS)
522
#define NEED_CLIENT_HANDLE_ERROR(_code)                                          \
523
  (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \
524
   NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
525

526
#define SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code)                                    \
527
  ((_code) == TSDB_CODE_SYN_NOT_LEADER || (_code) == TSDB_CODE_SYN_INTERNAL_ERROR || \
528
   (_code) == TSDB_CODE_VND_STOPPED || (_code) == TSDB_CODE_APP_IS_STARTING || (_code) == TSDB_CODE_APP_IS_STOPPING)
529
#define SYNC_SELF_LEADER_REDIRECT_ERROR(_code) \
530
  ((_code) == TSDB_CODE_SYN_NOT_LEADER || (_code) == TSDB_CODE_SYN_RESTORING || (_code) == TSDB_CODE_SYN_INTERNAL_ERROR || (_code) == TSDB_CODE_SYN_TIMEOUT)
531
#define SYNC_OTHER_LEADER_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_MNODE_NOT_FOUND)
532

533
#define NO_RET_REDIRECT_ERROR(_code)                                                   \
534
  ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || \
535
   (_code) == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED)
536

537
#define NEED_REDIRECT_ERROR(_code)                                              \
538
  (NO_RET_REDIRECT_ERROR(_code) || SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || \
539
   SYNC_SELF_LEADER_REDIRECT_ERROR(_code) || SYNC_OTHER_LEADER_REDIRECT_ERROR(_code))
540

541
#define IS_VIEW_REQUEST(_type) ((_type) == TDMT_MND_CREATE_VIEW || (_type) == TDMT_MND_DROP_VIEW)
542

543
#define NEED_CLIENT_RM_TBLMETA_REQ(_type)                                                                  \
544
  ((_type) == TDMT_VND_CREATE_TABLE || (_type) == TDMT_MND_CREATE_STB || (_type) == TDMT_VND_DROP_TABLE || \
545
   (_type) == TDMT_MND_DROP_STB || (_type) == TDMT_MND_CREATE_VIEW || (_type) == TDMT_MND_DROP_VIEW ||     \
546
   (_type) == TDMT_MND_CREATE_TSMA || (_type) == TDMT_MND_DROP_TSMA || (_type) == TDMT_MND_DROP_TB_WITH_TSMA)
547

548
#define NEED_SCHEDULER_REDIRECT_ERROR(_code)                                              \
549
  (SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || SYNC_SELF_LEADER_REDIRECT_ERROR(_code) || \
550
   SYNC_OTHER_LEADER_REDIRECT_ERROR(_code))
551

552
#define REQUEST_TOTAL_EXEC_TIMES 2
553

554
#define IS_INFORMATION_SCHEMA_DB(_name) ((*(_name) == 'i') && (0 == strcmp(_name, TSDB_INFORMATION_SCHEMA_DB)))
555
#define IS_PERFORMANCE_SCHEMA_DB(_name) ((*(_name) == 'p') && (0 == strcmp(_name, TSDB_PERFORMANCE_SCHEMA_DB)))
556

557
#define IS_SYS_DBNAME(_dbname) (IS_INFORMATION_SCHEMA_DB(_dbname) || IS_PERFORMANCE_SCHEMA_DB(_dbname))
558

559
#define IS_SYS_PREFIX(_name) (_name[0] == 'S' && _name[1] == 'Y' && _name[2] == 'S')
560

561
#define IS_AUDIT_DBNAME(_dbname)    ((*(_dbname) == 'a') && (0 == strcmp(_dbname, TSDB_AUDIT_DB)))
562
#define IS_AUDIT_STB_NAME(_stbname) ((*(_stbname) == 'o') && (0 == strcmp(_stbname, TSDB_AUDIT_STB_OPERATION)))
563
#define IS_AUDIT_CTB_NAME(_ctbname) \
564
  ((*(_ctbname) == 't') && (0 == strncmp(_ctbname, TSDB_AUDIT_CTB_OPERATION, TSDB_AUDIT_CTB_OPERATION_LEN)))
565

566
// clang-format off
567
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", DEBUG_FATAL, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0)
568
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0)
569
#define qWarn(...)  do { if (qDebugFlag & DEBUG_WARN)  { taosPrintLog("QRY WARN  ", DEBUG_WARN,  tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0)
570
#define qInfo(...)  do { if (qDebugFlag & DEBUG_INFO)  { taosPrintLog("QRY INFO  ", DEBUG_INFO,  tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0)
571
#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY DEBUG ", DEBUG_DEBUG, qDebugFlag,                       __VA_ARGS__); }} while(0)
572
#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY TRACE ", DEBUG_TRACE, qDebugFlag,                       __VA_ARGS__); }} while(0)
573
#define qDebugL(...)do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY DEBUG ", DEBUG_DEBUG, qDebugFlag,                       __VA_ARGS__); }} while(0)
574
#define qInfoL(...) do { if (qDebugFlag & DEBUG_INFO)  { taosPrintLongString("QRY INFO  ", DEBUG_INFO,  tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0)
575
// clang-format on
576

577
#define QRY_ERR_RET(c)                \
578
  do {                                \
579
    int32_t _code = c;                \
580
    if (_code != TSDB_CODE_SUCCESS) { \
581
      terrno = _code;                 \
582
      return _code;                   \
583
    }                                 \
584
  } while (0)
585
#define QRY_RET(c)                    \
586
  do {                                \
587
    int32_t _code = c;                \
588
    if (_code != TSDB_CODE_SUCCESS) { \
589
      terrno = _code;                 \
590
    }                                 \
591
    return _code;                     \
592
  } while (0)
593
#define QRY_ERR_JRET(c)              \
594
  do {                               \
595
    code = c;                        \
596
    if (code != TSDB_CODE_SUCCESS) { \
597
      terrno = code;                 \
598
      goto _return;                  \
599
    }                                \
600
  } while (0)
601

602
#ifdef __cplusplus
603
}
604
#endif
605

606
#endif /*_TD_QUERY_H_*/
607
       // clang-foramt on
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