/src/tdengine/include/libs/qcom/query.h
Line | Count | Source |
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 | 0 | #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 | | char* extErrMsg; // federated query: remote-side error message (heap-allocated, caller frees) |
102 | | } SExecResult; |
103 | | |
104 | | #pragma pack(push, 1) |
105 | | typedef struct SCTableMeta { |
106 | | uint64_t uid; |
107 | | uint64_t suid; |
108 | | int32_t vgId; |
109 | | int8_t tableType; |
110 | | } SCTableMeta; |
111 | | #pragma pack(pop) |
112 | | |
113 | | #pragma pack(push, 1) |
114 | | typedef struct SVCTableMeta { |
115 | | uint64_t uid; |
116 | | uint64_t suid; |
117 | | int32_t vgId; |
118 | | int8_t tableType; |
119 | | int32_t numOfColRefs; |
120 | | int32_t rversion; // virtual table's column ref's version |
121 | | SColRef* colRef; |
122 | | int32_t numOfTagRefs; |
123 | | SColRef* tagRef; |
124 | | int32_t numOfSeries; |
125 | | SSeriesEntry* seriesEntries; |
126 | | } SVCTableMeta; |
127 | | #pragma pack(pop) |
128 | | |
129 | | #pragma pack(push, 1) |
130 | | typedef struct STableMeta { |
131 | | // BEGIN: KEEP THIS PART SAME WITH SVCTableMeta |
132 | | // BEGIN: KEEP THIS PART SAME WITH SCTableMeta |
133 | | uint64_t uid; |
134 | | uint64_t suid; |
135 | | int32_t vgId; |
136 | | int8_t tableType; |
137 | | // END: KEEP THIS PART SAME WITH SCTableMeta |
138 | | |
139 | | int32_t numOfColRefs; |
140 | | int32_t rversion; // virtual table's column ref's version |
141 | | SColRef* colRef; |
142 | | int32_t numOfTagRefs; |
143 | | SColRef* tagRef; |
144 | | int32_t numOfSeries; |
145 | | SSeriesEntry* seriesEntries; |
146 | | // END: KEEP THIS PART SAME WITH SVCTableMeta |
147 | | |
148 | | // if the table is TSDB_CHILD_TABLE, the following information is acquired from the corresponding super table meta |
149 | | // info |
150 | | int32_t sversion; |
151 | | int32_t tversion; |
152 | | STableComInfo tableInfo; |
153 | | SSchemaExt* schemaExt; // There is no additional memory allocation, and the pointer is fixed to the next address of |
154 | | // the schema content. |
155 | | union { |
156 | | uint8_t flag; |
157 | | struct { |
158 | | uint8_t virtualStb : 1; |
159 | | uint8_t isAudit : 1; |
160 | | uint8_t secLvl : 3; // security level (0-4), mapped from STableMetaRsp.secLvl |
161 | | uint8_t hasInheritors : 1; // 1 if other VSTs inherit from this STB |
162 | | uint8_t reserved : 2; |
163 | | }; |
164 | | }; |
165 | | int64_t ownerId; |
166 | | int8_t secureDelete; |
167 | | SSchema schema[]; |
168 | | } STableMeta; |
169 | | #pragma pack(pop) |
170 | | |
171 | 0 | #define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags) |
172 | | |
173 | | #define TABLE_META_BASE_SIZE(pMeta) \ |
174 | 0 | (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema))) |
175 | | |
176 | | #define TABLE_META_SCHEMA_EXT_SIZE(pMeta) \ |
177 | 0 | ((withExtSchema((pMeta)->tableType) && NULL != (pMeta)->schemaExt) ? (pMeta)->tableInfo.numOfColumns * sizeof(SSchemaExt) : 0) |
178 | | |
179 | | #define TABLE_META_COL_REF_SIZE(pMeta) \ |
180 | 0 | ((hasColRef((pMeta)->tableType) && NULL != (pMeta)->colRef) ? (pMeta)->numOfColRefs * sizeof(SColRef) : 0) |
181 | | |
182 | | #define TABLE_META_TAG_REF_SIZE(pMeta) \ |
183 | 0 | ((hasTagRef((pMeta)->tableType) && NULL != (pMeta)->tagRef && (pMeta)->numOfTagRefs > 0) ? (pMeta)->numOfTagRefs * sizeof(SColRef) : 0) |
184 | | |
185 | | #define TABLE_META_FULL_SIZE(pMeta) \ |
186 | 0 | (NULL == (pMeta) ? 0 : (TABLE_META_BASE_SIZE((pMeta)) + TABLE_META_SCHEMA_EXT_SIZE((pMeta)) + TABLE_META_COL_REF_SIZE((pMeta)) + TABLE_META_TAG_REF_SIZE((pMeta)))) |
187 | | |
188 | 0 | static inline void tableMetaResetPointers(STableMeta *pMeta) { |
189 | 0 | if (NULL == pMeta) { |
190 | 0 | return; |
191 | 0 | } |
192 | | |
193 | 0 | char *pCursor = (char *)pMeta + TABLE_META_BASE_SIZE(pMeta); |
194 | |
|
195 | 0 | if (withExtSchema(pMeta->tableType) && NULL != pMeta->schemaExt) { |
196 | 0 | pMeta->schemaExt = (SSchemaExt *)pCursor; |
197 | 0 | pCursor += pMeta->tableInfo.numOfColumns * sizeof(SSchemaExt); |
198 | 0 | } else { |
199 | 0 | pMeta->schemaExt = NULL; |
200 | 0 | } |
201 | |
|
202 | 0 | if (hasColRef(pMeta->tableType) && NULL != pMeta->colRef) { |
203 | 0 | pMeta->colRef = (SColRef *)pCursor; |
204 | 0 | pCursor += pMeta->numOfColRefs * sizeof(SColRef); |
205 | 0 | } else { |
206 | 0 | pMeta->colRef = NULL; |
207 | 0 | } |
208 | |
|
209 | 0 | if (hasTagRef(pMeta->tableType) && NULL != pMeta->tagRef && pMeta->numOfTagRefs > 0) { |
210 | 0 | pMeta->tagRef = (SColRef *)pCursor; |
211 | 0 | pCursor += pMeta->numOfTagRefs * sizeof(SColRef); |
212 | 0 | } else { |
213 | 0 | pMeta->tagRef = NULL; |
214 | 0 | pMeta->numOfTagRefs = 0; |
215 | 0 | } |
216 | 0 | } Unexecuted instantiation: sql-fuzzer.c:tableMetaResetPointers Unexecuted instantiation: parser.c:tableMetaResetPointers Unexecuted instantiation: parTranslater.c:tableMetaResetPointers Unexecuted instantiation: parUtil.c:tableMetaResetPointers Unexecuted instantiation: parAstParser.c:tableMetaResetPointers Unexecuted instantiation: parAuthenticator.c:tableMetaResetPointers Unexecuted instantiation: parCalcConst.c:tableMetaResetPointers Unexecuted instantiation: parInsertSql.c:tableMetaResetPointers Unexecuted instantiation: parInsertUtil.c:tableMetaResetPointers Unexecuted instantiation: taos_lemon_sql.tab.c:tableMetaResetPointers Unexecuted instantiation: parAstCreater.c:tableMetaResetPointers Unexecuted instantiation: parInsertSml.c:tableMetaResetPointers Unexecuted instantiation: planner.c:tableMetaResetPointers Unexecuted instantiation: planLogicCreater.c:tableMetaResetPointers Unexecuted instantiation: planOptimizer.c:tableMetaResetPointers Unexecuted instantiation: planPhysiCreater.c:tableMetaResetPointers Unexecuted instantiation: planScaleOut.c:tableMetaResetPointers Unexecuted instantiation: planSpliter.c:tableMetaResetPointers Unexecuted instantiation: planUtil.c:tableMetaResetPointers Unexecuted instantiation: planValidator.c:tableMetaResetPointers Unexecuted instantiation: catalog.c:tableMetaResetPointers Unexecuted instantiation: ctgAsync.c:tableMetaResetPointers Unexecuted instantiation: ctgCache.c:tableMetaResetPointers Unexecuted instantiation: ctgDbg.c:tableMetaResetPointers Unexecuted instantiation: ctgRemote.c:tableMetaResetPointers Unexecuted instantiation: ctgRent.c:tableMetaResetPointers Unexecuted instantiation: ctgUtil.c:tableMetaResetPointers Unexecuted instantiation: builtinsimpl.c:tableMetaResetPointers Unexecuted instantiation: thistogram.c:tableMetaResetPointers Unexecuted instantiation: tpercentile.c:tableMetaResetPointers Unexecuted instantiation: filter.c:tableMetaResetPointers Unexecuted instantiation: scalar.c:tableMetaResetPointers Unexecuted instantiation: sclfunc.c:tableMetaResetPointers Unexecuted instantiation: sclvector.c:tableMetaResetPointers Unexecuted instantiation: nodesCloneFuncs.c:tableMetaResetPointers Unexecuted instantiation: nodesCodeFuncs.c:tableMetaResetPointers Unexecuted instantiation: nodesEqualFuncs.c:tableMetaResetPointers Unexecuted instantiation: nodesMsgFuncs.c:tableMetaResetPointers Unexecuted instantiation: nodesRemotePlanToSQL.c:tableMetaResetPointers Unexecuted instantiation: nodesToSQLFuncs.c:tableMetaResetPointers Unexecuted instantiation: nodesTraverseFuncs.c:tableMetaResetPointers Unexecuted instantiation: nodesUtilFuncs.c:tableMetaResetPointers Unexecuted instantiation: extTypeMap.c:tableMetaResetPointers Unexecuted instantiation: queryUtil.c:tableMetaResetPointers Unexecuted instantiation: querymsg.c:tableMetaResetPointers Unexecuted instantiation: geomFunc.c:tableMetaResetPointers |
217 | | |
218 | | typedef struct SViewMeta { |
219 | | uint64_t viewId; |
220 | | int64_t ownerId; |
221 | | char* createUser; |
222 | | char* querySql; |
223 | | int8_t precision; |
224 | | int8_t type; |
225 | | int32_t version; |
226 | | int32_t numOfCols; |
227 | | SSchema* pSchema; |
228 | | } SViewMeta; |
229 | | |
230 | | typedef SRsmaInfoRsp SRsmaMeta; |
231 | | typedef SRsmaMeta SRsmaMetaOutput; |
232 | | |
233 | | typedef struct SDBVgInfo { |
234 | | int32_t vgVersion; |
235 | | int16_t hashPrefix; |
236 | | int16_t hashSuffix; |
237 | | int8_t hashMethod; |
238 | | union { |
239 | | uint8_t flags; |
240 | | struct { |
241 | | uint8_t isMount : 1; // TS-5868 |
242 | | uint8_t padding : 7; |
243 | | }; |
244 | | }; |
245 | | int32_t numOfTable; // DB's table num, unit is TSDB_TABLE_NUM_UNIT |
246 | | int64_t stateTs; |
247 | | SHashObj* vgHash; // key:vgId, value:SVgroupInfo |
248 | | SArray* vgArray; // SVgroupInfo |
249 | | } SDBVgInfo; |
250 | | |
251 | | typedef struct SVGroupHashInfo { |
252 | | int32_t vgId; |
253 | | uint32_t hashBegin; |
254 | | uint32_t hashEnd; |
255 | | } SVGroupHashInfo; |
256 | | |
257 | | typedef struct SDBVgHashInfo { |
258 | | int16_t hashPrefix; |
259 | | int16_t hashSuffix; |
260 | | int8_t hashMethod; |
261 | | bool vgSorted; |
262 | | SArray* vgArray; //SArray<SVGroupHashInfo> |
263 | | } SDBVgHashInfo; |
264 | | |
265 | | typedef struct SColIdName { |
266 | | int16_t colId; |
267 | | char* colName; |
268 | | } SColIdName; |
269 | | |
270 | | typedef struct SStreamVBuildCtx { |
271 | | int64_t lastUid; |
272 | | SRefColInfo* lastCol; |
273 | | |
274 | | SSHashObj* lastVg; |
275 | | SSHashObj* lastVtable; |
276 | | SArray* lastOtable; |
277 | | } SStreamVBuildCtx; |
278 | | |
279 | | typedef struct SUseDbOutput { |
280 | | char db[TSDB_DB_FNAME_LEN]; |
281 | | uint64_t dbId; |
282 | | SDBVgInfo* dbVgroup; |
283 | | } SUseDbOutput; |
284 | | typedef SUseDbOutput** SUseDbOutputPPter; |
285 | | |
286 | | enum { META_TYPE_NULL_TABLE = 1, |
287 | | META_TYPE_CTABLE, |
288 | | META_TYPE_VCTABLE, |
289 | | META_TYPE_TABLE, |
290 | | META_TYPE_BOTH_TABLE, |
291 | | META_TYPE_BOTH_VTABLE}; |
292 | | |
293 | | typedef struct STableMetaOutput { |
294 | | int32_t metaType; |
295 | | uint64_t dbId; |
296 | | char dbFName[TSDB_DB_FNAME_LEN]; |
297 | | char ctbName[TSDB_TABLE_NAME_LEN]; |
298 | | char tbName[TSDB_TABLE_NAME_LEN]; |
299 | | SCTableMeta ctbMeta; |
300 | | SVCTableMeta* vctbMeta; |
301 | | STableMeta* tbMeta; |
302 | | } STableMetaOutput; |
303 | | |
304 | | typedef struct SViewMetaOutput { |
305 | | char name[TSDB_VIEW_NAME_LEN]; |
306 | | char dbFName[TSDB_DB_FNAME_LEN]; |
307 | | char* querySql; |
308 | | int8_t precision; |
309 | | int32_t numOfCols; |
310 | | SSchema* pSchema; |
311 | | } SViewMetaOutput; |
312 | | |
313 | | typedef struct SDataBuf { |
314 | | int32_t msgType; |
315 | | void* pData; |
316 | | uint32_t len; |
317 | | void* handle; |
318 | | int64_t handleRefId; |
319 | | SEpSet* pEpSet; |
320 | | } SDataBuf; |
321 | | |
322 | | typedef struct STargetInfo { |
323 | | ETargetType type; |
324 | | char* dbFName; // used to update db's vgroup epset |
325 | | int32_t vgId; |
326 | | } STargetInfo; |
327 | | |
328 | | typedef struct STagsInfo { |
329 | | SArray* STagNames; // STagVal |
330 | | SArray* pTagVals; |
331 | | uint8_t* pTagIndex; |
332 | | int32_t numOfTags; |
333 | | } STagsInfo; |
334 | | |
335 | | typedef struct SBoundColInfo { |
336 | | int16_t* pColIndex; // bound index => schema index |
337 | | int32_t numOfCols; |
338 | | int32_t numOfBound; |
339 | | bool hasBoundCols; |
340 | | bool mixTagsCols; |
341 | | STagsInfo* parseredTags; // used for partial fixed value stmt |
342 | | } SBoundColInfo; |
343 | | |
344 | | typedef struct STableColsData { |
345 | | char tbName[TSDB_TABLE_NAME_LEN]; |
346 | | SArray* aCol; |
347 | | SBlobSet* pBlobSet; |
348 | | bool getFromHash; |
349 | | bool isOrdered; |
350 | | bool isDuplicateTs; |
351 | | } STableColsData; |
352 | | |
353 | | typedef struct STableVgUid { |
354 | | uint64_t uid; |
355 | | uint64_t suid; |
356 | | int32_t vgid; |
357 | | } STableVgUid; |
358 | | |
359 | | typedef struct STableBufInfo { |
360 | | void* pCurBuff; |
361 | | SArray* pBufList; |
362 | | int64_t buffUnit; |
363 | | int64_t buffSize; |
364 | | int64_t buffIdx; |
365 | | int64_t buffOffset; |
366 | | } STableBufInfo; |
367 | | |
368 | | typedef struct STableDataCxt { |
369 | | STableMeta* pMeta; |
370 | | STSchema* pSchema; |
371 | | SBoundColInfo boundColsInfo; |
372 | | SArray* pValues; // SColVal |
373 | | SSubmitTbData* pData; |
374 | | SRowKey lastKey; |
375 | | bool ordered; |
376 | | bool duplicateTs; |
377 | | int8_t hasBlob; // if the table has blob column |
378 | | } STableDataCxt; |
379 | | |
380 | | typedef struct SStbInterlaceInfo { |
381 | | void* pCatalog; |
382 | | void* pQuery; |
383 | | int32_t acctId; |
384 | | char* dbname; /* heap copy; TAOS client frees with stmt siInfo cleanup (stmtCleanSQLInfo) */ |
385 | | void* transport; |
386 | | SEpSet mgmtEpSet; |
387 | | void* pRequest; |
388 | | uint64_t requestId; |
389 | | int64_t requestSelf; |
390 | | bool tbFromHash; |
391 | | SHashObj* pVgroupHash; // key:vgId, value:SVgroupDataCxt |
392 | | SArray* pVgroupList; // SVgroupDataCxt |
393 | | SSHashObj* pTableHash; // key:tbname, value:STableVgUid |
394 | | void* pTableHashMutex; // TdThreadMutex*, guards producer/worker access to pTableHash |
395 | | SSHashObj* pTableRowDataHash; // key:tbname, value:SSubmitTbData->aRowP |
396 | | int64_t tbRemainNum; |
397 | | STableBufInfo tbBuf; |
398 | | char firstName[TSDB_TABLE_NAME_LEN]; |
399 | | STSchema* pTSchema; |
400 | | STableDataCxt* pDataCtx; |
401 | | void* boundTags; |
402 | | |
403 | | bool tableColsReady; |
404 | | SArray* pTableCols; |
405 | | int32_t pTableColsIdx; |
406 | | } SStbInterlaceInfo; |
407 | | |
408 | | typedef int32_t (*__async_send_cb_fn_t)(void* param, SDataBuf* pMsg, int32_t code); |
409 | | typedef int32_t (*__async_exec_fn_t)(void* param); |
410 | | |
411 | | typedef struct SRequestConnInfo { |
412 | | void* pTrans; |
413 | | uint64_t requestId; |
414 | | int64_t requestObjRefId; |
415 | | SEpSet mgmtEps; |
416 | | int64_t txnId; // batch meta txn: same-txn visibility for PRE_CREATE entries |
417 | | } SRequestConnInfo; |
418 | | |
419 | | typedef void (*__freeFunc)(void* param); |
420 | | |
421 | | // todo add creator/destroyer function |
422 | | typedef struct SMsgSendInfo { |
423 | | __async_send_cb_fn_t fp; // async callback function |
424 | | STargetInfo target; // for update epset |
425 | | __freeFunc paramFreeFp; |
426 | | void* param; |
427 | | int8_t streamAHandle; |
428 | | uint64_t requestId; |
429 | | uint64_t requestObjRefId; |
430 | | int32_t msgType; |
431 | | SDataBuf msgInfo; |
432 | | } SMsgSendInfo; |
433 | | |
434 | | typedef struct SQueryNodeStat { |
435 | | int32_t tableNum; // vg table number, unit is TSDB_TABLE_NUM_UNIT |
436 | | } SQueryNodeStat; |
437 | | |
438 | | typedef struct SQueryStat { |
439 | | int64_t inputRowNum; |
440 | | int32_t inputRowSize; |
441 | | } SQueryStat; |
442 | | |
443 | | int32_t initTaskQueue(); |
444 | | int32_t cleanupTaskQueue(); |
445 | | |
446 | | /** |
447 | | * |
448 | | * @param execFn The asynchronously execution function |
449 | | * @param execParam The parameters of the execFn |
450 | | * @param code The response code during execution the execFn |
451 | | * @return |
452 | | */ |
453 | | int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code); |
454 | | int32_t taosAsyncWait(); |
455 | | int32_t taosAsyncRecover(); |
456 | | int32_t taosStmt2AsyncBind(__async_exec_fn_t execFn, void* execParam); |
457 | | bool beginAsyncWorkShutdown(); |
458 | | bool mayCreateAsyncWork(); |
459 | | |
460 | | void destroySendMsgInfo(SMsgSendInfo* pMsgBody); |
461 | | |
462 | | void destroyAhandle(void* ahandle); |
463 | | |
464 | | int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, SMsgSendInfo* pInfo, |
465 | | bool persistHandle, void* ctx); |
466 | | |
467 | | int32_t asyncFreeConnById(void* pTransporter, int64_t pid); |
468 | | ; |
469 | | /** |
470 | | * Asynchronously send message to server, after the response received, the callback will be incured. |
471 | | * |
472 | | * @param pTransporter |
473 | | * @param epSet |
474 | | * @param pTransporterId |
475 | | * @param pInfo |
476 | | * @return |
477 | | */ |
478 | | int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, SMsgSendInfo* pInfo); |
479 | | |
480 | | int32_t queryBuildUseDbOutput(SUseDbOutput* pOut, SUseDbRsp* usedbRsp); |
481 | | |
482 | | void initQueryModuleMsgHandle(); |
483 | | |
484 | | const SSchema* tGetTbnameColumnSchema(); |
485 | | bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags, bool isVirtual); |
486 | | int32_t getAsofJoinReverseOp(EOperatorType op); |
487 | | bool hasDecimalBytesTypeInfo(int32_t bytes); |
488 | | void schemaToRefDataType(const SSchema* pSchema, STypeMod typeMod, SDataType* pType); |
489 | | bool isSameRefDataType(const SDataType* pLeft, const SDataType* pRight); |
490 | | int32_t getNormalColSchemaIndex(const STableMeta* pTableMeta, const char* pColName); |
491 | | |
492 | | int32_t queryCreateCTableMetaFromMsg(STableMetaRsp* msg, SCTableMeta* pMeta); |
493 | | int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta); |
494 | | int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta); |
495 | | int32_t queryCreateTableMetaExFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta); |
496 | | void queryFreeSeriesEntries(SSeriesEntry* pSeries, int32_t nSeries); |
497 | | void queryFreeColRefTagConds(SColRef* pColRef, int32_t nCols); |
498 | | void queryFreeTableMeta(STableMeta* pMeta); |
499 | | int32_t queryCloneColRefTagConds(const SColRef* pSrc, int32_t nCols, SColRef* pDst); |
500 | | int32_t queryCloneSeriesEntries(const SSeriesEntry* pSrc, int32_t nSeries, SSeriesEntry** ppDst); |
501 | | char* jobTaskStatusStr(int32_t status); |
502 | | |
503 | | SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name); |
504 | | |
505 | | void destroyQueryExecRes(SExecResult* pRes); |
506 | | int32_t dataConverToStr(char* str, int64_t capacity, int type, void* buf, int32_t bufSize, int32_t* len); |
507 | | void parseTagDatatoJson(void* p, char** jsonStr, void *charsetCxt); |
508 | | int32_t setColRef(SColRef* colRef, col_id_t colId, const char* colName, char* refColName, char* refTableName, |
509 | | char* refDbName, int8_t refType, const char* refSourceName, const char* tagCondJson, int32_t tagCondLen); |
510 | | int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst); |
511 | | void getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType); |
512 | | int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst); |
513 | | int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst); |
514 | | void freeVgInfo(SDBVgInfo* vgInfo); |
515 | | void freeDbCfgInfo(SDbCfgInfo* pInfo); |
516 | | void qDestroyBoundColInfo(void* pInfo); |
517 | | |
518 | | void tFreeStreamVtbOtbInfo(void* param); |
519 | | void tFreeStreamVtbVtbInfo(void* param); |
520 | | void tFreeStreamVtbDbVgInfo(void* param); |
521 | | |
522 | | extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen, |
523 | | void* (*mallocFp)(int64_t), void (*freeFp)(void*)); |
524 | | extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize); |
525 | | |
526 | | void* getTaskPoolWorkerCb(); |
527 | | |
528 | 0 | #define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE |
529 | 0 | #define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE |
530 | 0 | #define SET_META_TYPE_VCTABLE(t) (t) = META_TYPE_VCTABLE |
531 | 0 | #define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE |
532 | 0 | #define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE |
533 | 0 | #define SET_META_TYPE_BOTH_VTABLE(t) (t) = META_TYPE_BOTH_VTABLE |
534 | | |
535 | | #define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \ |
536 | 10 | ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_TDB_TABLE_NOT_EXIST || \ |
537 | 5 | (_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \ |
538 | 5 | (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG || \ |
539 | 5 | (_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID)) |
540 | | #define NEED_CLIENT_REFRESH_VG_ERROR(_code) \ |
541 | 10 | ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) |
542 | | #define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) \ |
543 | 5 | ((_code) == TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER || \ |
544 | 5 | (_code) == TSDB_CODE_MND_INVALID_SCHEMA_VER || \ |
545 | 5 | (_code) == TSDB_CODE_SCH_DATA_SRC_EP_MISS || \ |
546 | 5 | (_code) == TSDB_CODE_VTABLE_DATA_SRC_EP_MISS) |
547 | | #define NEED_CLIENT_HANDLE_ERROR(_code) \ |
548 | 5 | (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \ |
549 | 5 | NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code)) |
550 | | |
551 | | // Federated query: external data source error classification macros |
552 | | // NOTE: ext error codes are intentionally NOT merged into NEED_CLIENT_HANDLE_ERROR. |
553 | | // External source retries are handled inside the FederatedScan operator (Module B FB-9); |
554 | | // once exhausted, the client dispatches through NEED_CLIENT_HANDLE_EXT_ERROR. |
555 | | #define NEED_CLIENT_RM_EXT_SOURCE_ERROR(_code) \ |
556 | | ((_code) == TSDB_CODE_EXT_SOURCE_NOT_FOUND) |
557 | | #define NEED_CLIENT_REFRESH_EXT_SOURCE_ERROR(_code) \ |
558 | | ((_code) == TSDB_CODE_EXT_SOURCE_CHANGED || \ |
559 | | (_code) == TSDB_CODE_EXT_SCHEMA_CHANGED || \ |
560 | | (_code) == TSDB_CODE_EXT_TABLE_NOT_EXIST || \ |
561 | | (_code) == TSDB_CODE_EXT_COLUMN_NOT_EXIST) |
562 | | #define NEED_CLIENT_RETURN_EXT_SOURCE_ERROR(_code) \ |
563 | | ((_code) == TSDB_CODE_EXT_CONNECT_FAILED || \ |
564 | | (_code) == TSDB_CODE_EXT_AUTH_FAILED || \ |
565 | | (_code) == TSDB_CODE_EXT_ACCESS_DENIED || \ |
566 | | (_code) == TSDB_CODE_EXT_QUERY_TIMEOUT || \ |
567 | | (_code) == TSDB_CODE_EXT_FETCH_FAILED || \ |
568 | | (_code) == TSDB_CODE_EXT_REMOTE_INTERNAL) |
569 | | #define NEED_CLIENT_RETRY_EXT_POOL_ERROR(_code) \ |
570 | | ((_code) == TSDB_CODE_EXT_RESOURCE_EXHAUSTED) |
571 | | #define NEED_CLIENT_HANDLE_EXT_ERROR(_code) \ |
572 | | (NEED_CLIENT_RM_EXT_SOURCE_ERROR(_code) || \ |
573 | | NEED_CLIENT_REFRESH_EXT_SOURCE_ERROR(_code) || \ |
574 | | NEED_CLIENT_RETURN_EXT_SOURCE_ERROR(_code) || \ |
575 | | NEED_CLIENT_RETRY_EXT_POOL_ERROR(_code) || \ |
576 | | (_code) == TSDB_CODE_EXT_PUSHDOWN_FAILED || \ |
577 | | (_code) == TSDB_CODE_EXT_CAPABILITY_CHANGED) |
578 | | |
579 | | #define SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) \ |
580 | | ((_code) == TSDB_CODE_SYN_NOT_LEADER || (_code) == TSDB_CODE_SYN_INTERNAL_ERROR || \ |
581 | | (_code) == TSDB_CODE_VND_STOPPED || (_code) == TSDB_CODE_APP_IS_STARTING || (_code) == TSDB_CODE_APP_IS_STOPPING) |
582 | | #define SYNC_SELF_LEADER_REDIRECT_ERROR(_code) \ |
583 | | ((_code) == TSDB_CODE_SYN_NOT_LEADER || (_code) == TSDB_CODE_SYN_RESTORING || (_code) == TSDB_CODE_SYN_INTERNAL_ERROR || (_code) == TSDB_CODE_SYN_TIMEOUT) |
584 | | #define SYNC_OTHER_LEADER_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_MNODE_NOT_FOUND) |
585 | | |
586 | | #define NO_RET_REDIRECT_ERROR(_code) \ |
587 | | ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || \ |
588 | | (_code) == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED) |
589 | | |
590 | | #define NEED_REDIRECT_ERROR(_code) \ |
591 | | (NO_RET_REDIRECT_ERROR(_code) || SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || \ |
592 | | SYNC_SELF_LEADER_REDIRECT_ERROR(_code) || SYNC_OTHER_LEADER_REDIRECT_ERROR(_code)) |
593 | | |
594 | | #define IS_VIEW_REQUEST(_type) ((_type) == TDMT_MND_CREATE_VIEW || (_type) == TDMT_MND_DROP_VIEW) |
595 | | |
596 | | #define NEED_CLIENT_RM_TBLMETA_REQ(_type) \ |
597 | | ((_type) == TDMT_VND_CREATE_TABLE || (_type) == TDMT_MND_CREATE_STB || (_type) == TDMT_VND_DROP_TABLE || \ |
598 | | (_type) == TDMT_MND_DROP_STB || (_type) == TDMT_MND_ALTER_STB || (_type) == TDMT_MND_CREATE_VIEW || \ |
599 | | (_type) == TDMT_MND_DROP_VIEW || \ |
600 | | (_type) == TDMT_MND_CREATE_TSMA || (_type) == TDMT_MND_DROP_TSMA || (_type) == TDMT_MND_DROP_TB_WITH_TSMA || \ |
601 | | (_type) == TDMT_MND_CREATE_STREAM || (_type) == TDMT_MND_DROP_STREAM) |
602 | | |
603 | | #define NEED_SCHEDULER_REDIRECT_ERROR(_code) \ |
604 | | (SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || SYNC_SELF_LEADER_REDIRECT_ERROR(_code) || \ |
605 | | SYNC_OTHER_LEADER_REDIRECT_ERROR(_code)) |
606 | | |
607 | | #define REQUEST_TOTAL_EXEC_TIMES 2 |
608 | | |
609 | 0 | #define IS_INFORMATION_SCHEMA_DB(_name) ((*(_name) == 'i') && (0 == strcmp(_name, TSDB_INFORMATION_SCHEMA_DB))) |
610 | 0 | #define IS_PERFORMANCE_SCHEMA_DB(_name) ((*(_name) == 'p') && (0 == strcmp(_name, TSDB_PERFORMANCE_SCHEMA_DB))) |
611 | | |
612 | 0 | #define IS_SYS_DBNAME(_dbname) (IS_INFORMATION_SCHEMA_DB(_dbname) || IS_PERFORMANCE_SCHEMA_DB(_dbname)) |
613 | | |
614 | | #define IS_SYS_PREFIX(_name) (_name[0] == 'S' && _name[1] == 'Y' && _name[2] == 'S') |
615 | | |
616 | | #define IS_AUDIT_DBNAME(_dbname) ((*(_dbname) == 'a') && (0 == strcmp(_dbname, TSDB_AUDIT_DB))) |
617 | | #define IS_AUDIT_STB_NAME(_stbname) ((*(_stbname) == 'o') && (0 == strcmp(_stbname, TSDB_AUDIT_STB_OPERATION))) |
618 | | #define IS_AUDIT_CTB_NAME(_ctbname) \ |
619 | | ((*(_ctbname) == 't') && (0 == strncmp(_ctbname, TSDB_AUDIT_CTB_OPERATION, TSDB_AUDIT_CTB_OPERATION_LEN))) |
620 | | |
621 | | // clang-format off |
622 | | #define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", DEBUG_FATAL, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0) |
623 | 0 | #define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0) |
624 | 0 | #define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", DEBUG_WARN, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0) |
625 | 0 | #define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY INFO ", DEBUG_INFO, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0) |
626 | 22.0k | #define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY DEBUG ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0) |
627 | 0 | #define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY TRACE ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); }} while(0) |
628 | 0 | #define qDebugL(...)do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY DEBUG ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0) |
629 | | #define qInfoL(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLongString("QRY INFO ", DEBUG_INFO, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); }} while(0) |
630 | | // clang-format on |
631 | | |
632 | | #define QRY_ERR_RET(c) \ |
633 | | do { \ |
634 | | int32_t _code = c; \ |
635 | | if (_code != TSDB_CODE_SUCCESS) { \ |
636 | | terrno = _code; \ |
637 | | return _code; \ |
638 | | } \ |
639 | | } while (0) |
640 | | #define QRY_RET(c) \ |
641 | | do { \ |
642 | | int32_t _code = c; \ |
643 | | if (_code != TSDB_CODE_SUCCESS) { \ |
644 | | terrno = _code; \ |
645 | | } \ |
646 | | return _code; \ |
647 | | } while (0) |
648 | | #define QRY_ERR_JRET(c) \ |
649 | | do { \ |
650 | | code = c; \ |
651 | | if (code != TSDB_CODE_SUCCESS) { \ |
652 | | terrno = code; \ |
653 | | goto _return; \ |
654 | | } \ |
655 | | } while (0) |
656 | | |
657 | | #ifdef __cplusplus |
658 | | } |
659 | | #endif |
660 | | |
661 | | #endif /*_TD_QUERY_H_*/ |
662 | | // clang-foramt on |