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

#ifndef TDENGINE_TSCUTIL_H
#define TDENGINE_TSCUTIL_H

#ifdef __cplusplus
extern "C" {
#endif

23
#include "exception.h"
H
Haojun Liao 已提交
24 25
#include "os.h"
#include "qExtbuffer.h"
26
#include "taosdef.h"
H
Haojun Liao 已提交
27
#include "tbuffer.h"
H
Haojun Liao 已提交
28 29
#include "tscGlobalmerge.h"
#include "tsched.h"
S
slguan 已提交
30
#include "tsclient.h"
H
hzcheng 已提交
31

32 33 34 35 36 37 38 39
#define LABEL_SQL   "sql:"
#define LABEL_TO    " to:"
#define LABEL_SPLIT " split:"

#define LABEL_SQL_LEN   (sizeof(LABEL_SQL) - 1)
#define LABEL_TO_LEN    (sizeof(LABEL_TO) - 1)
#define LABEL_SPLIT_LEN (sizeof(LABEL_SPLIT) - 1)

40
#define UTIL_TABLE_IS_SUPER_TABLE(metaInfo) \
H
hjxilinx 已提交
41
  (((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_SUPER_TABLE))
42

43
#define UTIL_TABLE_IS_CHILD_TABLE(metaInfo) \
H
hjxilinx 已提交
44
  (((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_CHILD_TABLE))
H
hzcheng 已提交
45

46
#define UTIL_TABLE_IS_TMP_TABLE(metaInfo) \
H
Haojun Liao 已提交
47 48
  (((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_TEMP_TABLE))

D
dapan1121 已提交
49 50 51
#define UTIL_TABLE_IS_NORMAL_TABLE(metaInfo) \
  (!(UTIL_TABLE_IS_SUPER_TABLE(metaInfo) || UTIL_TABLE_IS_CHILD_TABLE(metaInfo) || UTIL_TABLE_IS_TMP_TABLE(metaInfo)))

52 53 54 55 56 57 58 59 60
#define UTIL_GET_VGROUPMAP(pSql) \
  (pSql->pTscObj->pClusterInfo->vgroupMap)

#define UTIL_GET_TABLEMETA(pSql) \
  (pSql->pTscObj->pClusterInfo->tableMetaMap)

#define UTIL_GET_VGROUPLIST(pSql) \
  (pSql->pTscObj->pClusterInfo->vgroupListBuf)

61 62 63 64
#pragma pack(push,1)
// this struct is transfered as binary, padding two bytes to avoid
// an 'uid' whose low bytes is 0xff being recoginized as NULL,
// and set 'pack' to 1 to avoid break existing code.
65
typedef struct STidTags {
66
  int16_t  padding;
67 68 69 70 71
  int64_t  uid;
  int32_t  tid;
  int32_t  vgId;
  char     tag[];
} STidTags;
72
#pragma pack(pop)
73 74

typedef struct SJoinSupporter {
W
td-6502  
wpan 已提交
75
  int64_t         pObj;           // parent SqlObj
S
slguan 已提交
76
  int32_t         subqueryIndex;  // index of sub query
77
  SInterval       interval;
S
slguan 已提交
78
  SLimitVal       limit;          // limit info
H
Haojun Liao 已提交
79
  uint64_t        uid;            // query table uid
H
hjxilinx 已提交
80 81
  SArray*         colList;        // previous query information, no need to use this attribute, and the corresponding attribution
  SArray*         exprList;
W
wpan 已提交
82
  SArray*         colCond;
S
slguan 已提交
83 84
  SFieldInfo      fieldsInfo;
  STagCond        tagCond;
H
Haojun Liao 已提交
85
  SGroupbyExpr    groupInfo;       // group by info
H
hjxilinx 已提交
86 87
  struct STSBuf*  pTSBuf;          // the TSBuf struct that holds the compressed timestamp array
  FILE*           f;               // temporary file in order to create TSBuf
88 89 90 91 92
  char            path[PATH_MAX];  // temporary file path, todo dynamic allocate memory
  int32_t         tagSize;         // the length of each in the first filter stage
  char*           pIdTagList;      // result of first stage tags
  int32_t         totalLen;
  int32_t         num;
H
Haojun Liao 已提交
93
  SArray*         pVgroupTables;
D
dapan1121 已提交
94 95 96 97 98

  int16_t          fillType;      // final result fill type
  int64_t *        fillVal;       // default value for fill
  int32_t          numOfFillVal;  // fill value size
  
99 100
} SJoinSupporter;

D
dapan1121 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

typedef struct SMergeCtx {
  SJoinSupporter* p;
  int32_t         idx;
  SArray*         res;
  int8_t          compared;
}SMergeCtx;

typedef struct SMergeTsCtx {
  SJoinSupporter* p;
  STSBuf*         res;
  int64_t         numOfInput;
  int8_t          compared;
}SMergeTsCtx;

116
typedef struct SVgroupTableInfo {
117
  SVgroupMsg  vgInfo;
H
Haojun Liao 已提交
118
  SArray     *itemList;   // SArray<STableIdInfo>
119
} SVgroupTableInfo;
S
slguan 已提交
120

C
Cary Xu 已提交
121 122 123 124 125 126
typedef struct SBlockKeyTuple {
  TSKEY skey;
  void* payloadAddr;
} SBlockKeyTuple;

typedef struct SBlockKeyInfo {
C
Cary Xu 已提交
127
  int32_t         maxBytesAlloc;
C
Cary Xu 已提交
128 129 130
  SBlockKeyTuple* pKeyTuple;
} SBlockKeyInfo;

131

D
dapan1121 已提交
132
int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *len);
H
Haojun Liao 已提交
133

134
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
135
int32_t tscCreateDataBlockData(STableDataBlocks* dataBuf, size_t defaultSize, int32_t rowSize, int32_t startOffset);
S
Shengliang Guan 已提交
136
void    tscDestroyDataBlock(SSqlObj *pSql, STableDataBlocks* pDataBlock, bool removeMeta);
137
void    tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf);
C
Cary Xu 已提交
138
int     tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo);
139
int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows);
H
hjxilinx 已提交
140

H
Haojun Liao 已提交
141
void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo);
H
Haojun Liao 已提交
142
void doRetrieveSubqueryData(SSchedMsg *pMsg);
H
Haojun Liao 已提交
143

144
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, int16_t bytes,
H
hjxilinx 已提交
145 146
                                   uint32_t offset);

147
void*   tscDestroyBlockArrayList(SSqlObj* pSql, SArray* pDataBlockList);
D
dapan1121 已提交
148
void*  tscDestroyUdfArrayList(SArray* pUdfList);
149
void*   tscDestroyBlockHashTable(SSqlObj* pSql, SHashObj* pBlockHashTable, bool removeMeta);
H
Haojun Liao 已提交
150

H
hjxilinx 已提交
151
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
152
int32_t tscMergeTableDataBlocks(SSqlObj *pSql, SInsertStatementParam *pInsertParam, bool freeBlockMap);
153
int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, SName* pName, STableMeta* pTableMeta,
H
Haojun Liao 已提交
154
                                STableDataBlocks** dataBlocks, SArray* pBlockList);
H
hjxilinx 已提交
155

H
hzcheng 已提交
156 157
/**
 * for the projection query on metric or point interpolation query on metric,
S
slguan 已提交
158
 * we iterate all the meters, instead of invoke query on all qualified meters simultaneously.
H
hzcheng 已提交
159 160 161 162
 *
 * @param pSql  sql object
 * @return
 */
H
Haojun Liao 已提交
163
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
D
dapan1121 已提交
164
bool tscGetPointInterpQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
165
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
166
bool tscIsIrateQuery(SQueryInfo* pQueryInfo);
167
bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId);
H
Haojun Liao 已提交
168

Y
yihaoDeng 已提交
169
bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
170
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
171
bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
172
bool tscGroupbyColumn(SQueryInfo* pQueryInfo);
173
bool tscGroupbyTag(SQueryInfo* pQueryInfo);
S
shenglian zhou 已提交
174
int32_t tscGetTopBotQueryExprIndex(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
175 176
bool tscIsTopBotQuery(SQueryInfo* pQueryInfo);
bool hasTagValOutput(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
177
bool timeWindowInterpoRequired(SQueryInfo *pQueryInfo);
H
Haojun Liao 已提交
178
bool isStabledev(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
179
bool isTsCompQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
180
bool isBlockDistQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
181
bool isSimpleAggregateRv(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
182 183 184

bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
185
bool tscIsDiffDerivLikeQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
186 187 188
bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);

bool tscIsProjectionQuery(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
189
bool tscHasColumnFilter(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
190 191 192 193 194 195 196

bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscQueryTags(SQueryInfo* pQueryInfo);
bool tscMultiRoundQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscQueryBlockInfo(SQueryInfo* pQueryInfo);

SExprInfo* tscAddFuncInSelectClause(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId,
H
Haojun Liao 已提交
197
                                       SColumnIndex* pIndex, SSchema* pColSchema, int16_t colType, int16_t colId);
H
hzcheng 已提交
198

W
wpan 已提交
199
int32_t tscSetTableFullName(SName* pName, SStrToken* pzTableName, SSqlObj* pSql, bool dbIncluded);
H
Haojun Liao 已提交
200
void    tscClearInterpInfo(SQueryInfo* pQueryInfo);
H
hzcheng 已提交
201

H
hjxilinx 已提交
202
bool tscIsInsertData(char* sqlstr);
H
hzcheng 已提交
203

204 205 206
// the memory is not reset in case of fast allocate payload function
int32_t tscAllocPayloadFast(SSqlCmd *pCmd, size_t size);
int32_t tscAllocPayload(SSqlCmd* pCmd, int size);
H
hzcheng 已提交
207

H
hjxilinx 已提交
208 209
TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes);

H
Haojun Liao 已提交
210 211
SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField);
SInternalField* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field);
H
hjxilinx 已提交
212

H
Haojun Liao 已提交
213
SInternalField* tscFieldInfoGetInternalField(SFieldInfo* pFieldInfo, int32_t index);
H
hjxilinx 已提交
214
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index);
H
hzcheng 已提交
215

H
Haojun Liao 已提交
216
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo);
H
hzcheng 已提交
217

218
int32_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
H
hjxilinx 已提交
219
void    tscFieldInfoClear(SFieldInfo* pFieldInfo);
220
void tscFieldInfoCopy(SFieldInfo* pFieldInfo, const SFieldInfo* pSrc, const SArray* pExprList);
H
Haojun Liao 已提交
221

H
Haojun Liao 已提交
222
static FORCE_INLINE int32_t tscNumOfFields(SQueryInfo* pQueryInfo) { return pQueryInfo->fieldsInfo.numOfOutput; }
W
wpan 已提交
223
int32_t tscGetFirstInvisibleFieldPos(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
224

D
fix bug  
dapan1121 已提交
225
int32_t tscFieldInfoCompare(const SFieldInfo* pFieldInfo1, const SFieldInfo* pFieldInfo2, int32_t *diffSize);
H
Haojun Liao 已提交
226
void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t uid);
H
hzcheng 已提交
227

H
Haojun Liao 已提交
228
int32_t tscFieldInfoSetSize(const SFieldInfo* pFieldInfo1, const SFieldInfo* pFieldInfo2);
H
Haojun Liao 已提交
229
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes);
H
hzcheng 已提交
230

H
hjxilinx 已提交
231
int32_t   tscGetResRowLength(SArray* pExprList);
H
hjxilinx 已提交
232

H
Haojun Liao 已提交
233
SExprInfo* tscExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
wmmhello's avatar
wmmhello 已提交
234
    int16_t size, int16_t resColId, int32_t interSize, bool isTagCol);
H
hjxilinx 已提交
235

H
Haojun Liao 已提交
236
SExprInfo* tscExprCreate(STableMetaInfo* pTableMetaInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
wmmhello's avatar
wmmhello 已提交
237
                         int16_t size, int16_t resColId, int32_t interSize, int32_t colType);
H
Haojun Liao 已提交
238 239 240 241

void tscExprAddParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes);

SExprInfo* tscExprAppend(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
wmmhello's avatar
wmmhello 已提交
242
                           int16_t size, int16_t resColId, int32_t interSize, bool isTagCol);
H
hjxilinx 已提交
243

H
Haojun Liao 已提交
244
SExprInfo* tscExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
wmmhello's avatar
wmmhello 已提交
245
                           int32_t size);
H
hzcheng 已提交
246

H
Haojun Liao 已提交
247
size_t     tscNumOfExprs(SQueryInfo* pQueryInfo);
248
int32_t     tscExprTopBottomIndex(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
249 250
SExprInfo *tscExprGet(SQueryInfo* pQueryInfo, int32_t index);
int32_t    tscExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
251
int32_t    tscExprCopyAll(SArray* dst, const SArray* src, bool deepcopy);
H
Haojun Liao 已提交
252 253 254 255
void       tscExprAssign(SExprInfo* dst, const SExprInfo* src);
void       tscExprDestroy(SArray* pExprInfo);

int32_t createProjectionExpr(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SExprInfo*** pExpr, int32_t* num);
S
slguan 已提交
256

H
Haojun Liao 已提交
257
void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, bool removeMeta, uint64_t id);
S
slguan 已提交
258

259
SColumn* tscColumnClone(const SColumn* src);
H
Haojun Liao 已提交
260 261
void tscColumnCopy(SColumn* pDest, const SColumn* pSrc);
int32_t tscColumnExists(SArray* pColumnList, int32_t columnId, uint64_t uid);
H
Haojun Liao 已提交
262
SColumn* tscColumnListInsert(SArray* pColumnList, int32_t columnIndex, uint64_t uid, SSchema* pSchema);
263
void tscColumnListDestroy(SArray* pColList);
H
Haojun Liao 已提交
264
void tscColumnListCopy(SArray* dst, const SArray* src, uint64_t tableUid);
H
Haojun Liao 已提交
265
void tscColumnListCopyAll(SArray* dst, const SArray* src);
H
hzcheng 已提交
266

wmmhello's avatar
wmmhello 已提交
267
void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId, bool convertNchar, bool convertJson);
H
Haojun Liao 已提交
268

W
wpan 已提交
269
int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded);
H
hzcheng 已提交
270 271 272

void tscIncStreamExecutionCount(void* pStream);

273
bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId);
H
hzcheng 已提交
274

S
slguan 已提交
275
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
276
SCond* tsGetSTableQueryCond(STagCond* pCond, uint64_t uid);
277
void   tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw);
S
slguan 已提交
278

H
Haojun Liao 已提交
279
int32_t tscTagCondCopy(STagCond* dest, const STagCond* src);
W
wpan 已提交
280
int32_t tscColCondCopy(SArray** dest, const SArray* src, uint64_t uid, int16_t tidx);
H
hzcheng 已提交
281
void tscTagCondRelease(STagCond* pCond);
W
wpan 已提交
282
void tscColCondRelease(SArray** pCond);
H
Haojun Liao 已提交
283
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo);
H
hzcheng 已提交
284

H
hjxilinx 已提交
285
bool tscShouldBeFreed(SSqlObj* pSql);
S
slguan 已提交
286

H
Haojun Liao 已提交
287
STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd *pCmd, int32_t tableIndex);
H
Haojun Liao 已提交
288
STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex);
289

H
Haojun Liao 已提交
290
void        tscInitQueryInfo(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
291 292
void        tscClearSubqueryInfo(SSqlCmd* pCmd);
int32_t     tscAddQueryInfo(SSqlCmd *pCmd);
H
Haojun Liao 已提交
293
SQueryInfo *tscGetQueryInfo(SSqlCmd* pCmd);
H
Haojun Liao 已提交
294
SQueryInfo *tscGetQueryInfoS(SSqlCmd *pCmd);
295

296
void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo);
S
slguan 已提交
297

H
Haojun Liao 已提交
298
STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, SName* name, STableMeta* pTableMeta,
299
                                    SVgroupsInfo* vgroupList, SArray* pTagCols, SArray* pVgroupTables);
300

H
Haojun Liao 已提交
301
STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo *pQueryInfo);
H
hjxilinx 已提交
302

303
void tscFreeVgroupTableInfo(SArray* pVgroupTables);
H
Haojun Liao 已提交
304
SArray* tscVgroupTableInfoDup(SArray* pVgroupTables);
H
Haojun Liao 已提交
305
void tscRemoveVgroupTableGroup(SArray* pVgroupTable, int32_t index);
306
void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo);
S
slguan 已提交
307

H
Haojun Liao 已提交
308
int  tscGetSTableVgroupInfo(SSqlObj* pSql, SQueryInfo* pQueryInfo);
H
hjxilinx 已提交
309
int  tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo);
W
fix bug  
wpan 已提交
310
int  tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists, bool onlyLocal);
311
int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo);
S
slguan 已提交
312 313

void tscResetForNextRetrieve(SSqlRes* pRes);
H
Haojun Liao 已提交
314 315
void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo);
void doExecuteQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo);
H
hzcheng 已提交
316

H
Haojun Liao 已提交
317 318
SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *pInfo);
void* tscVgroupInfoClear(SVgroupsInfo *pInfo);
319 320

#if 0
S
TD-1732  
Shengliang Guan 已提交
321
void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src);
322 323
#endif

S
slguan 已提交
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
/**
 * The create object function must be successful expect for the out of memory issue.
 *
 * Therefore, the metermeta/metricmeta object is directly passed to the newly created subquery object from the
 * previous sql object, instead of retrieving the metermeta/metricmeta from cache.
 *
 * Because the metermeta/metricmeta may have been released by other threads, resulting in the retrieving failed as
 * well as the create function.
 *
 * @param pSql
 * @param vnodeIndex
 * @param tableIndex
 * @param fp
 * @param param
 * @param pPrevSql
 * @return
 */
H
Haojun Liao 已提交
341
SSqlObj* createSimpleSubObj(SSqlObj* pSql, __async_cb_func_t fp, void* param, int32_t cmd);
H
Haojun Liao 已提交
342

343
void registerSqlObj(SSqlObj* pSql);
H
Haojun Liao 已提交
344
void tscInitResForMerge(SSqlRes* pRes);
345

H
Haojun Liao 已提交
346
SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t fp, void* param, int32_t cmd, SSqlObj* pPrevSql);
347
void     addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClauseIndex, int32_t tableIndex);
S
slguan 已提交
348

H
Haojun Liao 已提交
349
void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex, SSqlCmd* pCmd);
S
slguan 已提交
350

H
Haojun Liao 已提交
351
int16_t tscGetJoinTagColIdByUid(STagCond* pTagCond, uint64_t uid);
H
Haojun Liao 已提交
352
int16_t tscGetTagColIndexById(STableMeta* pTableMeta, int16_t colId);
H
Haojun Liao 已提交
353
int32_t doInitSubState(SSqlObj* pSql, int32_t numOfSubqueries);
S
slguan 已提交
354

H
Haojun Liao 已提交
355
void tscPrintSelNodeList(SSqlObj* pSql, int32_t subClauseIndex);
H
hjxilinx 已提交
356

357
bool hasMoreVnodesToTry(SSqlObj *pSql);
H
Haojun Liao 已提交
358 359
bool hasMoreClauseToTry(SSqlObj* pSql);

H
Haojun Liao 已提交
360
void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeCachedMeta, uint64_t id);
H
Haojun Liao 已提交
361

362
void tscTryQueryNextVnode(SSqlObj *pSql, __async_cb_func_t fp);
H
Haojun Liao 已提交
363
void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp);
dengyihao's avatar
TD-2257  
dengyihao 已提交
364
int  tscSetMgmtEpSetFromCfg(const char *first, const char *second, SRpcCorEpSet *corEpSet);
H
Haojun Liao 已提交
365
int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVgroupNameList, SArray* pUdfList, __async_cb_func_t fp, bool metaClone);
366 367

int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray);
368

H
Haojun Liao 已提交
369
bool subAndCheckDone(SSqlObj *pSql, SSqlObj *pParentSql, int idx);
370

371 372
bool tscSetSqlOwner(SSqlObj* pSql);
void tscClearSqlOwner(SSqlObj* pSql);
373
int32_t doScalarExprCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize);
374

375 376 377
char*   serializeTagData(STagData* pTagData, char* pMsg);
int32_t copyTagData(STagData* dst, const STagData* src);

378 379 380 381
STableMeta* createSuperTableMeta(STableMetaMsg* pChild);
uint32_t tscGetTableMetaSize(STableMeta* pTableMeta);
CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta);
uint32_t tscGetTableMetaMaxSize();
382
int32_t tscCreateTableMetaFromSTableMeta(SSqlObj *pSql, STableMeta** ppChild, const char* name, size_t *tableMetaCapacity, STableMeta **ppStable);
H
Haojun Liao 已提交
383
STableMeta* tscTableMetaDup(STableMeta* pTableMeta);
384 385
SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo);

386
int32_t tscGetTagFilterSerializeLen(SQueryInfo* pQueryInfo);
387
int32_t tscGetColFilterSerializeLen(SQueryInfo* pQueryInfo);
H
Haojun Liao 已提交
388
int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr);
389
void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage, uint64_t qId);
390

weixin_48148422's avatar
weixin_48148422 已提交
391 392 393 394
void* malloc_throw(size_t size);
void* calloc_throw(size_t nmemb, size_t size);
char* strdup_throw(const char* str);

H
Haojun Liao 已提交
395 396
bool vgroupInfoIdentical(SNewVgroupInfo *pExisted, SVgroupMsg* src);
SNewVgroupInfo createNewVgroupInfo(SVgroupMsg *pVgroupMsg);
397
STblCond* tsGetTableFilter(SArray* filters, uint64_t uid, int16_t idx);
H
Haojun Liao 已提交
398

H
Haojun Liao 已提交
399
void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id);
400

401 402
char* cloneCurrentDBName(SSqlObj* pSql);

403 404
int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId);
int8_t jsonType2DbType(double data, int jsonType);
405
void getJsonKey(SStrToken *t0);
406

407 408
char* cloneCurrentDBName(SSqlObj* pSql);

H
hzcheng 已提交
409 410 411 412 413
#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TSCUTIL_H