nodesUtilFuncs.c 68.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

16
#include "cmdnodes.h"
X
Xiaoyu Wang 已提交
17
#include "nodesUtil.h"
X
Xiaoyu Wang 已提交
18
#include "plannodes.h"
19
#include "querynodes.h"
X
Xiaoyu Wang 已提交
20
#include "taos.h"
21
#include "taoserror.h"
wmmhello's avatar
wmmhello 已提交
22
#include "tdatablock.h"
X
Xiaoyu Wang 已提交
23
#include "thash.h"
24
#include "tref.h"
25

26 27 28 29 30 31 32 33
typedef struct SNodeMemChunk {
  int32_t               availableSize;
  int32_t               usedSize;
  char*                 pBuf;
  struct SNodeMemChunk* pNext;
} SNodeMemChunk;

typedef struct SNodeAllocator {
34
  int64_t        self;
35
  int64_t        queryId;
36 37 38 39
  int32_t        chunkSize;
  int32_t        chunkNum;
  SNodeMemChunk* pCurrChunk;
  SNodeMemChunk* pChunks;
40
  TdThreadMutex  mutex;
41 42
} SNodeAllocator;

43 44
static threadlocal SNodeAllocator* g_pNodeAllocator;
static int32_t                     g_allocatorReqRefPool = -1;
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

static SNodeMemChunk* callocNodeChunk(SNodeAllocator* pAllocator) {
  SNodeMemChunk* pNewChunk = taosMemoryCalloc(1, sizeof(SNodeMemChunk) + pAllocator->chunkSize);
  if (NULL == pNewChunk) {
    return NULL;
  }
  pNewChunk->pBuf = (char*)(pNewChunk + 1);
  pNewChunk->availableSize = pAllocator->chunkSize;
  pNewChunk->usedSize = 0;
  pNewChunk->pNext = NULL;
  if (NULL != pAllocator->pCurrChunk) {
    pAllocator->pCurrChunk->pNext = pNewChunk;
  }
  pAllocator->pCurrChunk = pNewChunk;
  if (NULL == pAllocator->pChunks) {
    pAllocator->pChunks = pNewChunk;
  }
  ++(pAllocator->chunkNum);
  return pNewChunk;
}

66
static void* nodesCallocImpl(int32_t size) {
67
  if (NULL == g_pNodeAllocator) {
68
    return taosMemoryCalloc(1, size);
69 70
  }

71 72
  if (g_pNodeAllocator->pCurrChunk->usedSize + size > g_pNodeAllocator->pCurrChunk->availableSize) {
    if (NULL == callocNodeChunk(g_pNodeAllocator)) {
73 74 75
      return NULL;
    }
  }
76 77
  void* p = g_pNodeAllocator->pCurrChunk->pBuf + g_pNodeAllocator->pCurrChunk->usedSize;
  g_pNodeAllocator->pCurrChunk->usedSize += size;
78 79 80
  return p;
}

81 82 83 84 85
static void* nodesCalloc(int32_t num, int32_t size) {
  void* p = nodesCallocImpl(num * size + 1);
  if (NULL == p) {
    return NULL;
  }
86
  *(char*)p = (NULL != g_pNodeAllocator) ? 1 : 0;
87 88 89
  return (char*)p + 1;
}

90
static void nodesFree(void* p) {
91 92 93
  char* ptr = (char*)p - 1;
  if (0 == *ptr) {
    taosMemoryFree(ptr);
94 95 96 97
  }
  return;
}

98
static int32_t createNodeAllocator(int32_t chunkSize, SNodeAllocator** pAllocator) {
99 100 101 102 103 104 105 106 107
  *pAllocator = taosMemoryCalloc(1, sizeof(SNodeAllocator));
  if (NULL == *pAllocator) {
    return TSDB_CODE_OUT_OF_MEMORY;
  }
  (*pAllocator)->chunkSize = chunkSize;
  if (NULL == callocNodeChunk(*pAllocator)) {
    taosMemoryFreeClear(*pAllocator);
    return TSDB_CODE_OUT_OF_MEMORY;
  }
108
  taosThreadMutexInit(&(*pAllocator)->mutex, NULL);
109 110 111
  return TSDB_CODE_SUCCESS;
}

112
static void destroyNodeAllocator(void* p) {
113
  if (NULL == p) {
114 115 116
    return;
  }

117 118
  SNodeAllocator* pAllocator = p;

119 120
  nodesDebug("query id %" PRIx64 " allocator id %" PRIx64 " alloc chunkNum: %d, chunkTotakSize: %d",
             pAllocator->queryId, pAllocator->self, pAllocator->chunkNum, pAllocator->chunkNum * pAllocator->chunkSize);
121 122 123 124 125 126 127

  SNodeMemChunk* pChunk = pAllocator->pChunks;
  while (NULL != pChunk) {
    SNodeMemChunk* pTemp = pChunk->pNext;
    taosMemoryFree(pChunk);
    pChunk = pTemp;
  }
128
  taosThreadMutexDestroy(&pAllocator->mutex);
129 130 131
  taosMemoryFree(pAllocator);
}

132 133 134 135 136 137 138 139 140 141 142 143 144 145
int32_t nodesInitAllocatorSet() {
  if (g_allocatorReqRefPool >= 0) {
    nodesWarn("nodes already initialized");
    return TSDB_CODE_SUCCESS;
  }

  g_allocatorReqRefPool = taosOpenRef(1024, destroyNodeAllocator);
  if (g_allocatorReqRefPool < 0) {
    nodesError("init nodes failed");
    return TSDB_CODE_OUT_OF_MEMORY;
  }

  return TSDB_CODE_SUCCESS;
}
146

147 148 149 150 151 152 153 154 155 156 157 158 159 160
void nodesDestroyAllocatorSet() {
  if (g_allocatorReqRefPool >= 0) {
    SNodeAllocator* pAllocator = taosIterateRef(g_allocatorReqRefPool, 0);
    int64_t         refId = 0;
    while (NULL != pAllocator) {
      refId = pAllocator->self;
      taosRemoveRef(g_allocatorReqRefPool, refId);
      pAllocator = taosIterateRef(g_allocatorReqRefPool, refId);
    }
    taosCloseRef(g_allocatorReqRefPool);
  }
}

int32_t nodesCreateAllocator(int64_t queryId, int32_t chunkSize, int64_t* pAllocatorId) {
161
  SNodeAllocator* pAllocator = NULL;
162
  int32_t         code = createNodeAllocator(chunkSize, &pAllocator);
163
  if (TSDB_CODE_SUCCESS == code) {
164 165 166 167 168 169
    pAllocator->self = taosAddRef(g_allocatorReqRefPool, pAllocator);
    if (pAllocator->self <= 0) {
      return terrno;
    }
    pAllocator->queryId = queryId;
    *pAllocatorId = pAllocator->self;
170 171 172 173
  }
  return code;
}

174 175 176
int32_t nodesAcquireAllocator(int64_t allocatorId) {
  if (allocatorId <= 0) {
    return TSDB_CODE_SUCCESS;
177
  }
178 179 180 181 182 183 184 185

  SNodeAllocator* pAllocator = taosAcquireRef(g_allocatorReqRefPool, allocatorId);
  if (NULL == pAllocator) {
    return terrno;
  }
  taosThreadMutexLock(&pAllocator->mutex);
  g_pNodeAllocator = pAllocator;
  return TSDB_CODE_SUCCESS;
186 187
}

188 189 190 191 192 193 194 195 196 197 198
int32_t nodesReleaseAllocator(int64_t allocatorId) {
  if (allocatorId <= 0) {
    return TSDB_CODE_SUCCESS;
  }

  if (NULL == g_pNodeAllocator) {
    nodesError("allocator id %" PRIx64
               " release failed: The nodesReleaseAllocator function needs to be called after the nodesAcquireAllocator "
               "function is called!",
               allocatorId);
    return TSDB_CODE_FAILED;
199
  }
200 201 202 203
  SNodeAllocator* pAllocator = g_pNodeAllocator;
  g_pNodeAllocator = NULL;
  taosThreadMutexUnlock(&pAllocator->mutex);
  return taosReleaseRef(g_allocatorReqRefPool, allocatorId);
204 205
}

206 207 208
int64_t nodesMakeAllocatorWeakRef(int64_t allocatorId) {
  if (allocatorId <= 0) {
    return 0;
209
  }
210 211

  SNodeAllocator* pAllocator = taosAcquireRef(g_allocatorReqRefPool, allocatorId);
212 213 214
  return pAllocator->self;
}

215 216 217 218 219 220 221 222 223 224
int64_t nodesReleaseAllocatorWeakRef(int64_t allocatorId) { return taosReleaseRef(g_allocatorReqRefPool, allocatorId); }

void nodesDestroyAllocator(int64_t allocatorId) {
  if (allocatorId <= 0) {
    return;
  }

  taosRemoveRef(g_allocatorReqRefPool, allocatorId);
}

225 226
static SNode* makeNode(ENodeType type, int32_t size) {
  SNode* p = nodesCalloc(1, size);
X
Xiaoyu Wang 已提交
227 228 229 230 231 232 233
  if (NULL == p) {
    return NULL;
  }
  setNodeType(p, type);
  return p;
}

234
SNode* nodesMakeNode(ENodeType type) {
235 236
  switch (type) {
    case QUERY_NODE_COLUMN:
X
Xiaoyu Wang 已提交
237
      return makeNode(type, sizeof(SColumnNode));
238
    case QUERY_NODE_VALUE:
X
Xiaoyu Wang 已提交
239
      return makeNode(type, sizeof(SValueNode));
240
    case QUERY_NODE_OPERATOR:
X
Xiaoyu Wang 已提交
241
      return makeNode(type, sizeof(SOperatorNode));
242
    case QUERY_NODE_LOGIC_CONDITION:
X
Xiaoyu Wang 已提交
243
      return makeNode(type, sizeof(SLogicConditionNode));
244
    case QUERY_NODE_FUNCTION:
X
Xiaoyu Wang 已提交
245
      return makeNode(type, sizeof(SFunctionNode));
246
    case QUERY_NODE_REAL_TABLE:
X
Xiaoyu Wang 已提交
247
      return makeNode(type, sizeof(SRealTableNode));
248
    case QUERY_NODE_TEMP_TABLE:
X
Xiaoyu Wang 已提交
249
      return makeNode(type, sizeof(STempTableNode));
250
    case QUERY_NODE_JOIN_TABLE:
X
Xiaoyu Wang 已提交
251
      return makeNode(type, sizeof(SJoinTableNode));
252
    case QUERY_NODE_GROUPING_SET:
X
Xiaoyu Wang 已提交
253
      return makeNode(type, sizeof(SGroupingSetNode));
254
    case QUERY_NODE_ORDER_BY_EXPR:
X
Xiaoyu Wang 已提交
255
      return makeNode(type, sizeof(SOrderByExprNode));
256
    case QUERY_NODE_LIMIT:
X
Xiaoyu Wang 已提交
257
      return makeNode(type, sizeof(SLimitNode));
258
    case QUERY_NODE_STATE_WINDOW:
X
Xiaoyu Wang 已提交
259
      return makeNode(type, sizeof(SStateWindowNode));
260
    case QUERY_NODE_SESSION_WINDOW:
X
Xiaoyu Wang 已提交
261
      return makeNode(type, sizeof(SSessionWindowNode));
262
    case QUERY_NODE_INTERVAL_WINDOW:
X
Xiaoyu Wang 已提交
263
      return makeNode(type, sizeof(SIntervalWindowNode));
264
    case QUERY_NODE_NODE_LIST:
X
Xiaoyu Wang 已提交
265
      return makeNode(type, sizeof(SNodeListNode));
266
    case QUERY_NODE_FILL:
X
Xiaoyu Wang 已提交
267
      return makeNode(type, sizeof(SFillNode));
268
    case QUERY_NODE_RAW_EXPR:
X
Xiaoyu Wang 已提交
269
      return makeNode(type, sizeof(SRawExprNode));
270
    case QUERY_NODE_TARGET:
X
Xiaoyu Wang 已提交
271
      return makeNode(type, sizeof(STargetNode));
272
    case QUERY_NODE_DATABLOCK_DESC:
X
Xiaoyu Wang 已提交
273
      return makeNode(type, sizeof(SDataBlockDescNode));
274
    case QUERY_NODE_SLOT_DESC:
X
Xiaoyu Wang 已提交
275
      return makeNode(type, sizeof(SSlotDescNode));
276
    case QUERY_NODE_COLUMN_DEF:
X
Xiaoyu Wang 已提交
277
      return makeNode(type, sizeof(SColumnDefNode));
X
Xiaoyu Wang 已提交
278
    case QUERY_NODE_DOWNSTREAM_SOURCE:
X
Xiaoyu Wang 已提交
279
      return makeNode(type, sizeof(SDownstreamSourceNode));
X
Xiaoyu Wang 已提交
280
    case QUERY_NODE_DATABASE_OPTIONS:
X
Xiaoyu Wang 已提交
281
      return makeNode(type, sizeof(SDatabaseOptions));
X
Xiaoyu Wang 已提交
282
    case QUERY_NODE_TABLE_OPTIONS:
X
Xiaoyu Wang 已提交
283
      return makeNode(type, sizeof(STableOptions));
X
Xiaoyu Wang 已提交
284
    case QUERY_NODE_INDEX_OPTIONS:
X
Xiaoyu Wang 已提交
285
      return makeNode(type, sizeof(SIndexOptions));
286
    case QUERY_NODE_EXPLAIN_OPTIONS:
X
Xiaoyu Wang 已提交
287
      return makeNode(type, sizeof(SExplainOptions));
288
    case QUERY_NODE_STREAM_OPTIONS:
X
Xiaoyu Wang 已提交
289
      return makeNode(type, sizeof(SStreamOptions));
290
    case QUERY_NODE_LEFT_VALUE:
X
Xiaoyu Wang 已提交
291
      return makeNode(type, sizeof(SLeftValueNode));
292 293
    case QUERY_NODE_COLUMN_REF:
      return makeNode(type, sizeof(SColumnDefNode));
H
Haojun Liao 已提交
294 295 296 297
    case QUERY_NODE_WHEN_THEN:
      return makeNode(type, sizeof(SWhenThenNode));
    case QUERY_NODE_CASE_WHEN:
      return makeNode(type, sizeof(SCaseWhenNode));
298
    case QUERY_NODE_SET_OPERATOR:
X
Xiaoyu Wang 已提交
299
      return makeNode(type, sizeof(SSetOperator));
300
    case QUERY_NODE_SELECT_STMT:
X
Xiaoyu Wang 已提交
301
      return makeNode(type, sizeof(SSelectStmt));
302
    case QUERY_NODE_VNODE_MODIF_STMT:
X
Xiaoyu Wang 已提交
303
      return makeNode(type, sizeof(SVnodeModifOpStmt));
304
    case QUERY_NODE_CREATE_DATABASE_STMT:
X
Xiaoyu Wang 已提交
305
      return makeNode(type, sizeof(SCreateDatabaseStmt));
306
    case QUERY_NODE_DROP_DATABASE_STMT:
X
Xiaoyu Wang 已提交
307
      return makeNode(type, sizeof(SDropDatabaseStmt));
308
    case QUERY_NODE_ALTER_DATABASE_STMT:
X
Xiaoyu Wang 已提交
309
      return makeNode(type, sizeof(SAlterDatabaseStmt));
X
Xiaoyu Wang 已提交
310 311
    case QUERY_NODE_FLUSH_DATABASE_STMT:
      return makeNode(type, sizeof(SFlushDatabaseStmt));
X
Xiaoyu Wang 已提交
312 313
    case QUERY_NODE_TRIM_DATABASE_STMT:
      return makeNode(type, sizeof(STrimDatabaseStmt));
314
    case QUERY_NODE_CREATE_TABLE_STMT:
X
Xiaoyu Wang 已提交
315
      return makeNode(type, sizeof(SCreateTableStmt));
316
    case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
X
Xiaoyu Wang 已提交
317
      return makeNode(type, sizeof(SCreateSubTableClause));
318
    case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
X
Xiaoyu Wang 已提交
319
      return makeNode(type, sizeof(SCreateMultiTableStmt));
320
    case QUERY_NODE_DROP_TABLE_CLAUSE:
X
Xiaoyu Wang 已提交
321
      return makeNode(type, sizeof(SDropTableClause));
322
    case QUERY_NODE_DROP_TABLE_STMT:
X
Xiaoyu Wang 已提交
323
      return makeNode(type, sizeof(SDropTableStmt));
324
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
X
Xiaoyu Wang 已提交
325
      return makeNode(type, sizeof(SDropSuperTableStmt));
326
    case QUERY_NODE_ALTER_TABLE_STMT:
X
Xiaoyu Wang 已提交
327
      return makeNode(type, sizeof(SAlterTableStmt));
328
    case QUERY_NODE_CREATE_USER_STMT:
X
Xiaoyu Wang 已提交
329
      return makeNode(type, sizeof(SCreateUserStmt));
330
    case QUERY_NODE_ALTER_USER_STMT:
X
Xiaoyu Wang 已提交
331
      return makeNode(type, sizeof(SAlterUserStmt));
332
    case QUERY_NODE_DROP_USER_STMT:
X
Xiaoyu Wang 已提交
333
      return makeNode(type, sizeof(SDropUserStmt));
334
    case QUERY_NODE_USE_DATABASE_STMT:
X
Xiaoyu Wang 已提交
335
      return makeNode(type, sizeof(SUseDatabaseStmt));
336
    case QUERY_NODE_CREATE_DNODE_STMT:
X
Xiaoyu Wang 已提交
337
      return makeNode(type, sizeof(SCreateDnodeStmt));
338
    case QUERY_NODE_DROP_DNODE_STMT:
X
Xiaoyu Wang 已提交
339
      return makeNode(type, sizeof(SDropDnodeStmt));
340
    case QUERY_NODE_ALTER_DNODE_STMT:
X
Xiaoyu Wang 已提交
341
      return makeNode(type, sizeof(SAlterDnodeStmt));
X
Xiaoyu Wang 已提交
342
    case QUERY_NODE_CREATE_INDEX_STMT:
X
Xiaoyu Wang 已提交
343
      return makeNode(type, sizeof(SCreateIndexStmt));
344
    case QUERY_NODE_DROP_INDEX_STMT:
X
Xiaoyu Wang 已提交
345
      return makeNode(type, sizeof(SDropIndexStmt));
X
Xiaoyu Wang 已提交
346
    case QUERY_NODE_CREATE_QNODE_STMT:
347 348 349
    case QUERY_NODE_CREATE_BNODE_STMT:
    case QUERY_NODE_CREATE_SNODE_STMT:
    case QUERY_NODE_CREATE_MNODE_STMT:
X
Xiaoyu Wang 已提交
350
      return makeNode(type, sizeof(SCreateComponentNodeStmt));
351
    case QUERY_NODE_DROP_QNODE_STMT:
352 353 354
    case QUERY_NODE_DROP_BNODE_STMT:
    case QUERY_NODE_DROP_SNODE_STMT:
    case QUERY_NODE_DROP_MNODE_STMT:
X
Xiaoyu Wang 已提交
355
      return makeNode(type, sizeof(SDropComponentNodeStmt));
356
    case QUERY_NODE_CREATE_TOPIC_STMT:
X
Xiaoyu Wang 已提交
357
      return makeNode(type, sizeof(SCreateTopicStmt));
358
    case QUERY_NODE_DROP_TOPIC_STMT:
X
Xiaoyu Wang 已提交
359 360 361
      return makeNode(type, sizeof(SDropTopicStmt));
    case QUERY_NODE_DROP_CGROUP_STMT:
      return makeNode(type, sizeof(SDropCGroupStmt));
362 363
    case QUERY_NODE_ALTER_LOCAL_STMT:
      return makeNode(type, sizeof(SAlterLocalStmt));
364
    case QUERY_NODE_EXPLAIN_STMT:
X
Xiaoyu Wang 已提交
365
      return makeNode(type, sizeof(SExplainStmt));
366
    case QUERY_NODE_DESCRIBE_STMT:
X
Xiaoyu Wang 已提交
367
      return makeNode(type, sizeof(SDescribeStmt));
368
    case QUERY_NODE_RESET_QUERY_CACHE_STMT:
X
Xiaoyu Wang 已提交
369
      return makeNode(type, sizeof(SNode));
370
    case QUERY_NODE_COMPACT_STMT:
371
      break;
372
    case QUERY_NODE_CREATE_FUNCTION_STMT:
X
Xiaoyu Wang 已提交
373
      return makeNode(type, sizeof(SCreateFunctionStmt));
374
    case QUERY_NODE_DROP_FUNCTION_STMT:
X
Xiaoyu Wang 已提交
375
      return makeNode(type, sizeof(SDropFunctionStmt));
376
    case QUERY_NODE_CREATE_STREAM_STMT:
X
Xiaoyu Wang 已提交
377
      return makeNode(type, sizeof(SCreateStreamStmt));
378
    case QUERY_NODE_DROP_STREAM_STMT:
X
Xiaoyu Wang 已提交
379
      return makeNode(type, sizeof(SDropStreamStmt));
X
Xiaoyu Wang 已提交
380 381
    case QUERY_NODE_BALANCE_VGROUP_STMT:
      return makeNode(type, sizeof(SBalanceVgroupStmt));
382
    case QUERY_NODE_MERGE_VGROUP_STMT:
X
Xiaoyu Wang 已提交
383
      return makeNode(type, sizeof(SMergeVgroupStmt));
384
    case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
X
Xiaoyu Wang 已提交
385
      return makeNode(type, sizeof(SRedistributeVgroupStmt));
386
    case QUERY_NODE_SPLIT_VGROUP_STMT:
X
Xiaoyu Wang 已提交
387
      return makeNode(type, sizeof(SSplitVgroupStmt));
388 389
    case QUERY_NODE_SYNCDB_STMT:
      break;
390
    case QUERY_NODE_GRANT_STMT:
X
Xiaoyu Wang 已提交
391
      return makeNode(type, sizeof(SGrantStmt));
392
    case QUERY_NODE_REVOKE_STMT:
X
Xiaoyu Wang 已提交
393
      return makeNode(type, sizeof(SRevokeStmt));
394
    case QUERY_NODE_SHOW_DNODES_STMT:
X
Xiaoyu Wang 已提交
395
    case QUERY_NODE_SHOW_MNODES_STMT:
X
Xiaoyu Wang 已提交
396 397
    case QUERY_NODE_SHOW_MODULES_STMT:
    case QUERY_NODE_SHOW_QNODES_STMT:
398 399
    case QUERY_NODE_SHOW_SNODES_STMT:
    case QUERY_NODE_SHOW_BNODES_STMT:
400
    case QUERY_NODE_SHOW_CLUSTER_STMT:
401
    case QUERY_NODE_SHOW_DATABASES_STMT:
X
Xiaoyu Wang 已提交
402 403
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
    case QUERY_NODE_SHOW_INDEXES_STMT:
404
    case QUERY_NODE_SHOW_STABLES_STMT:
X
Xiaoyu Wang 已提交
405
    case QUERY_NODE_SHOW_STREAMS_STMT:
406 407
    case QUERY_NODE_SHOW_TABLES_STMT:
    case QUERY_NODE_SHOW_USERS_STMT:
X
Xiaoyu Wang 已提交
408
    case QUERY_NODE_SHOW_LICENCES_STMT:
409
    case QUERY_NODE_SHOW_VGROUPS_STMT:
S
Shengliang Guan 已提交
410
    case QUERY_NODE_SHOW_TOPICS_STMT:
411
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
412
    case QUERY_NODE_SHOW_CONNECTIONS_STMT:
413 414
    case QUERY_NODE_SHOW_QUERIES_STMT:
    case QUERY_NODE_SHOW_VNODES_STMT:
415 416
    case QUERY_NODE_SHOW_APPS_STMT:
    case QUERY_NODE_SHOW_SCORES_STMT:
417 418
    case QUERY_NODE_SHOW_VARIABLES_STMT:
    case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
419
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
420
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
421
    case QUERY_NODE_SHOW_TAGS_STMT:
422
      return makeNode(type, sizeof(SShowStmt));
423 424
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
      return makeNode(type, sizeof(SShowDnodeVariablesStmt));
425
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
426
      return makeNode(type, sizeof(SShowCreateDatabaseStmt));
427 428
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
429
      return makeNode(type, sizeof(SShowCreateTableStmt));
430 431
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
      return makeNode(type, sizeof(SShowTableDistributedStmt));
432
    case QUERY_NODE_KILL_QUERY_STMT:
X
Xiaoyu Wang 已提交
433
      return makeNode(type, sizeof(SKillQueryStmt));
434
    case QUERY_NODE_KILL_TRANSACTION_STMT:
X
Xiaoyu Wang 已提交
435
    case QUERY_NODE_KILL_CONNECTION_STMT:
X
Xiaoyu Wang 已提交
436
      return makeNode(type, sizeof(SKillStmt));
X
Xiaoyu Wang 已提交
437 438
    case QUERY_NODE_DELETE_STMT:
      return makeNode(type, sizeof(SDeleteStmt));
439 440
    case QUERY_NODE_INSERT_STMT:
      return makeNode(type, sizeof(SInsertStmt));
441 442
    case QUERY_NODE_QUERY:
      return makeNode(type, sizeof(SQuery));
X
Xiaoyu Wang 已提交
443
    case QUERY_NODE_LOGIC_PLAN_SCAN:
X
Xiaoyu Wang 已提交
444
      return makeNode(type, sizeof(SScanLogicNode));
X
Xiaoyu Wang 已提交
445
    case QUERY_NODE_LOGIC_PLAN_JOIN:
X
Xiaoyu Wang 已提交
446
      return makeNode(type, sizeof(SJoinLogicNode));
X
Xiaoyu Wang 已提交
447
    case QUERY_NODE_LOGIC_PLAN_AGG:
X
Xiaoyu Wang 已提交
448
      return makeNode(type, sizeof(SAggLogicNode));
X
Xiaoyu Wang 已提交
449
    case QUERY_NODE_LOGIC_PLAN_PROJECT:
X
Xiaoyu Wang 已提交
450
      return makeNode(type, sizeof(SProjectLogicNode));
X
Xiaoyu Wang 已提交
451 452
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
      return makeNode(type, sizeof(SVnodeModifyLogicNode));
X
Xiaoyu Wang 已提交
453
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
X
Xiaoyu Wang 已提交
454
      return makeNode(type, sizeof(SExchangeLogicNode));
X
Xiaoyu Wang 已提交
455 456
    case QUERY_NODE_LOGIC_PLAN_MERGE:
      return makeNode(type, sizeof(SMergeLogicNode));
X
Xiaoyu Wang 已提交
457
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
X
Xiaoyu Wang 已提交
458
      return makeNode(type, sizeof(SWindowLogicNode));
X
Xiaoyu Wang 已提交
459
    case QUERY_NODE_LOGIC_PLAN_FILL:
X
Xiaoyu Wang 已提交
460
      return makeNode(type, sizeof(SFillLogicNode));
X
Xiaoyu Wang 已提交
461
    case QUERY_NODE_LOGIC_PLAN_SORT:
X
Xiaoyu Wang 已提交
462
      return makeNode(type, sizeof(SSortLogicNode));
463
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
X
Xiaoyu Wang 已提交
464
      return makeNode(type, sizeof(SPartitionLogicNode));
465 466
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
      return makeNode(type, sizeof(SIndefRowsFuncLogicNode));
X
Xiaoyu Wang 已提交
467 468
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
      return makeNode(type, sizeof(SInterpFuncLogicNode));
X
Xiaoyu Wang 已提交
469
    case QUERY_NODE_LOGIC_SUBPLAN:
X
Xiaoyu Wang 已提交
470
      return makeNode(type, sizeof(SLogicSubplan));
X
Xiaoyu Wang 已提交
471
    case QUERY_NODE_LOGIC_PLAN:
X
Xiaoyu Wang 已提交
472
      return makeNode(type, sizeof(SQueryLogicPlan));
X
Xiaoyu Wang 已提交
473
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
X
Xiaoyu Wang 已提交
474
      return makeNode(type, sizeof(STagScanPhysiNode));
X
Xiaoyu Wang 已提交
475
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
X
Xiaoyu Wang 已提交
476
      return makeNode(type, sizeof(STableScanPhysiNode));
477
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
X
Xiaoyu Wang 已提交
478
      return makeNode(type, sizeof(STableSeqScanPhysiNode));
X
Xiaoyu Wang 已提交
479 480
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
      return makeNode(type, sizeof(STableMergeScanPhysiNode));
481
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
X
Xiaoyu Wang 已提交
482
      return makeNode(type, sizeof(SStreamScanPhysiNode));
X
Xiaoyu Wang 已提交
483
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
X
Xiaoyu Wang 已提交
484
      return makeNode(type, sizeof(SSystemTableScanPhysiNode));
485 486
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
      return makeNode(type, sizeof(SBlockDistScanPhysiNode));
X
Xiaoyu Wang 已提交
487 488
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
      return makeNode(type, sizeof(SLastRowScanPhysiNode));
X
Xiaoyu Wang 已提交
489
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
X
Xiaoyu Wang 已提交
490
      return makeNode(type, sizeof(SProjectPhysiNode));
491
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
492
      return makeNode(type, sizeof(SSortMergeJoinPhysiNode));
493
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
X
Xiaoyu Wang 已提交
494
      return makeNode(type, sizeof(SAggPhysiNode));
495
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
X
Xiaoyu Wang 已提交
496
      return makeNode(type, sizeof(SExchangePhysiNode));
X
Xiaoyu Wang 已提交
497 498
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
      return makeNode(type, sizeof(SMergePhysiNode));
499
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
X
Xiaoyu Wang 已提交
500
      return makeNode(type, sizeof(SSortPhysiNode));
501 502
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT:
      return makeNode(type, sizeof(SGroupSortPhysiNode));
X
Xiaoyu Wang 已提交
503
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
X
Xiaoyu Wang 已提交
504
      return makeNode(type, sizeof(SIntervalPhysiNode));
505 506
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
      return makeNode(type, sizeof(SMergeAlignedIntervalPhysiNode));
X
Xiaoyu Wang 已提交
507
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
X
Xiaoyu Wang 已提交
508
      return makeNode(type, sizeof(SStreamIntervalPhysiNode));
509 510 511 512
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
      return makeNode(type, sizeof(SStreamFinalIntervalPhysiNode));
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
      return makeNode(type, sizeof(SStreamSemiIntervalPhysiNode));
X
Xiaoyu Wang 已提交
513
    case QUERY_NODE_PHYSICAL_PLAN_FILL:
X
Xiaoyu Wang 已提交
514
      return makeNode(type, sizeof(SFillPhysiNode));
515
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
X
Xiaoyu Wang 已提交
516
      return makeNode(type, sizeof(SSessionWinodwPhysiNode));
517
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
X
Xiaoyu Wang 已提交
518
      return makeNode(type, sizeof(SStreamSessionWinodwPhysiNode));
519 520 521 522
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
      return makeNode(type, sizeof(SStreamSemiSessionWinodwPhysiNode));
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
      return makeNode(type, sizeof(SStreamFinalSessionWinodwPhysiNode));
523
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
X
Xiaoyu Wang 已提交
524
      return makeNode(type, sizeof(SStateWinodwPhysiNode));
525
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE:
5
54liuyao 已提交
526
      return makeNode(type, sizeof(SStreamStateWinodwPhysiNode));
527
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
X
Xiaoyu Wang 已提交
528
      return makeNode(type, sizeof(SPartitionPhysiNode));
529 530
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION:
      return makeNode(type, sizeof(SStreamPartitionPhysiNode));
531 532
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
      return makeNode(type, sizeof(SIndefRowsFuncPhysiNode));
X
Xiaoyu Wang 已提交
533 534
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
      return makeNode(type, sizeof(SInterpFuncLogicNode));
535
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
X
Xiaoyu Wang 已提交
536
      return makeNode(type, sizeof(SDataDispatcherNode));
537
    case QUERY_NODE_PHYSICAL_PLAN_INSERT:
X
Xiaoyu Wang 已提交
538
      return makeNode(type, sizeof(SDataInserterNode));
539 540
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return makeNode(type, sizeof(SQueryInserterNode));
X
Xiaoyu Wang 已提交
541 542
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return makeNode(type, sizeof(SDataDeleterNode));
X
Xiaoyu Wang 已提交
543
    case QUERY_NODE_PHYSICAL_SUBPLAN:
X
Xiaoyu Wang 已提交
544
      return makeNode(type, sizeof(SSubplan));
X
Xiaoyu Wang 已提交
545
    case QUERY_NODE_PHYSICAL_PLAN:
X
Xiaoyu Wang 已提交
546
      return makeNode(type, sizeof(SQueryPlan));
547 548 549
    default:
      break;
  }
550
  nodesError("nodesMakeNode unknown node = %s", nodesNodeName(type));
X
Xiaoyu Wang 已提交
551
  return NULL;
552 553
}

X
Xiaoyu Wang 已提交
554 555 556 557 558 559 560 561 562 563 564 565
static void destroyVgDataBlockArray(SArray* pArray) {
  size_t size = taosArrayGetSize(pArray);
  for (size_t i = 0; i < size; ++i) {
    SVgDataBlocks* pVg = taosArrayGetP(pArray, i);
    taosMemoryFreeClear(pVg->pData);
    taosMemoryFreeClear(pVg);
  }
  taosArrayDestroy(pArray);
}

static void destroyLogicNode(SLogicNode* pNode) {
  nodesDestroyList(pNode->pTargets);
X
Xiaoyu Wang 已提交
566 567 568 569
  nodesDestroyNode(pNode->pConditions);
  nodesDestroyList(pNode->pChildren);
  nodesDestroyNode(pNode->pLimit);
  nodesDestroyNode(pNode->pSlimit);
X
Xiaoyu Wang 已提交
570 571 572 573 574
}

static void destroyPhysiNode(SPhysiNode* pNode) {
  nodesDestroyList(pNode->pChildren);
  nodesDestroyNode(pNode->pConditions);
575
  nodesDestroyNode((SNode*)pNode->pOutputDataBlockDesc);
576 577
  nodesDestroyNode(pNode->pLimit);
  nodesDestroyNode(pNode->pSlimit);
X
Xiaoyu Wang 已提交
578 579 580 581 582 583
}

static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) {
  destroyPhysiNode((SPhysiNode*)pNode);
  nodesDestroyList(pNode->pExprs);
  nodesDestroyList(pNode->pFuncs);
584
  nodesDestroyNode(pNode->pTspk);
5
54liuyao 已提交
585
  nodesDestroyNode(pNode->pTsEnd);
X
Xiaoyu Wang 已提交
586 587 588 589 590
}

static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
  destroyPhysiNode((SPhysiNode*)pNode);
  nodesDestroyList(pNode->pScanCols);
X
Xiaoyu Wang 已提交
591
  nodesDestroyList(pNode->pScanPseudoCols);
X
Xiaoyu Wang 已提交
592 593
}

594
static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode((SNode*)pNode->pInputDataBlockDesc); }
X
Xiaoyu Wang 已提交
595

X
Xiaoyu Wang 已提交
596 597
static void destroyExprNode(SExprNode* pExpr) { taosArrayDestroy(pExpr->pAssociation); }

598
static void destroyTableCfg(STableCfg* pCfg) {
599 600 601
  if (NULL == pCfg) {
    return;
  }
602 603 604 605 606
  taosArrayDestroy(pCfg->pFuncs);
  taosMemoryFree(pCfg->pComment);
  taosMemoryFree(pCfg->pSchemas);
  taosMemoryFree(pCfg->pTags);
  taosMemoryFree(pCfg);
D
dapan1121 已提交
607 608
}

609 610
static void destroySmaIndex(void* pIndex) { taosMemoryFree(((STableIndexInfo*)pIndex)->expr); }

611
void nodesDestroyNode(SNode* pNode) {
X
Xiaoyu Wang 已提交
612 613 614 615 616
  if (NULL == pNode) {
    return;
  }

  switch (nodeType(pNode)) {
X
Xiaoyu Wang 已提交
617
    case QUERY_NODE_COLUMN:  // pProjectRef is weak reference, no need to release
X
Xiaoyu Wang 已提交
618
      destroyExprNode((SExprNode*)pNode);
X
Xiaoyu Wang 已提交
619
      break;
D
dapan1121 已提交
620
    case QUERY_NODE_VALUE: {
X
Xiaoyu Wang 已提交
621
      SValueNode* pValue = (SValueNode*)pNode;
X
Xiaoyu Wang 已提交
622
      destroyExprNode((SExprNode*)pNode);
wafwerar's avatar
wafwerar 已提交
623
      taosMemoryFreeClear(pValue->literal);
D
dapan1121 已提交
624
      if (IS_VAR_DATA_TYPE(pValue->node.resType.type)) {
wafwerar's avatar
wafwerar 已提交
625
        taosMemoryFreeClear(pValue->datum.p);
D
dapan1121 已提交
626
      }
X
Xiaoyu Wang 已提交
627 628 629 630
      break;
    }
    case QUERY_NODE_OPERATOR: {
      SOperatorNode* pOp = (SOperatorNode*)pNode;
X
Xiaoyu Wang 已提交
631
      destroyExprNode((SExprNode*)pNode);
X
Xiaoyu Wang 已提交
632 633
      nodesDestroyNode(pOp->pLeft);
      nodesDestroyNode(pOp->pRight);
D
dapan1121 已提交
634 635 636
      break;
    }
    case QUERY_NODE_LOGIC_CONDITION:
X
Xiaoyu Wang 已提交
637
      destroyExprNode((SExprNode*)pNode);
X
Xiaoyu Wang 已提交
638
      nodesDestroyList(((SLogicConditionNode*)pNode)->pParameterList);
D
dapan1121 已提交
639 640
      break;
    case QUERY_NODE_FUNCTION:
X
Xiaoyu Wang 已提交
641
      destroyExprNode((SExprNode*)pNode);
X
Xiaoyu Wang 已提交
642
      nodesDestroyList(((SFunctionNode*)pNode)->pParameterList);
X
Xiaoyu Wang 已提交
643 644
      break;
    case QUERY_NODE_REAL_TABLE: {
X
Xiaoyu Wang 已提交
645
      SRealTableNode* pReal = (SRealTableNode*)pNode;
wafwerar's avatar
wafwerar 已提交
646 647
      taosMemoryFreeClear(pReal->pMeta);
      taosMemoryFreeClear(pReal->pVgroupList);
648
      taosArrayDestroyEx(pReal->pSmaIndexes, destroySmaIndex);
X
Xiaoyu Wang 已提交
649 650 651
      break;
    }
    case QUERY_NODE_TEMP_TABLE:
X
Xiaoyu Wang 已提交
652
      nodesDestroyNode(((STempTableNode*)pNode)->pSubquery);
D
dapan1121 已提交
653
      break;
X
Xiaoyu Wang 已提交
654 655 656 657 658
    case QUERY_NODE_JOIN_TABLE: {
      SJoinTableNode* pJoin = (SJoinTableNode*)pNode;
      nodesDestroyNode(pJoin->pLeft);
      nodesDestroyNode(pJoin->pRight);
      nodesDestroyNode(pJoin->pOnCond);
D
dapan1121 已提交
659
      break;
X
Xiaoyu Wang 已提交
660
    }
D
dapan1121 已提交
661
    case QUERY_NODE_GROUPING_SET:
X
Xiaoyu Wang 已提交
662 663 664 665 666
      nodesDestroyList(((SGroupingSetNode*)pNode)->pParameterList);
      break;
    case QUERY_NODE_ORDER_BY_EXPR:
      nodesDestroyNode(((SOrderByExprNode*)pNode)->pExpr);
      break;
X
Xiaoyu Wang 已提交
667
    case QUERY_NODE_LIMIT:  // no pointer field
D
dapan1121 已提交
668
      break;
669 670 671 672
    case QUERY_NODE_STATE_WINDOW: {
      SStateWindowNode* pState = (SStateWindowNode*)pNode;
      nodesDestroyNode(pState->pCol);
      nodesDestroyNode(pState->pExpr);
X
Xiaoyu Wang 已提交
673
      break;
674
    }
X
Xiaoyu Wang 已提交
675 676
    case QUERY_NODE_SESSION_WINDOW: {
      SSessionWindowNode* pSession = (SSessionWindowNode*)pNode;
677 678
      nodesDestroyNode((SNode*)pSession->pCol);
      nodesDestroyNode((SNode*)pSession->pGap);
D
dapan1121 已提交
679
      break;
X
Xiaoyu Wang 已提交
680 681 682 683 684 685 686 687 688 689
    }
    case QUERY_NODE_INTERVAL_WINDOW: {
      SIntervalWindowNode* pJoin = (SIntervalWindowNode*)pNode;
      nodesDestroyNode(pJoin->pCol);
      nodesDestroyNode(pJoin->pInterval);
      nodesDestroyNode(pJoin->pOffset);
      nodesDestroyNode(pJoin->pSliding);
      nodesDestroyNode(pJoin->pFill);
      break;
    }
D
dapan1121 已提交
690
    case QUERY_NODE_NODE_LIST:
X
Xiaoyu Wang 已提交
691 692
      nodesDestroyList(((SNodeListNode*)pNode)->pNodeList);
      break;
X
Xiaoyu Wang 已提交
693 694 695 696
    case QUERY_NODE_FILL: {
      SFillNode* pFill = (SFillNode*)pNode;
      nodesDestroyNode(pFill->pValues);
      nodesDestroyNode(pFill->pWStartTs);
X
Xiaoyu Wang 已提交
697
      break;
X
Xiaoyu Wang 已提交
698
    }
X
Xiaoyu Wang 已提交
699 700
    case QUERY_NODE_RAW_EXPR:
      nodesDestroyNode(((SRawExprNode*)pNode)->pNode);
X
Xiaoyu Wang 已提交
701
      break;
X
Xiaoyu Wang 已提交
702 703 704 705 706 707
    case QUERY_NODE_TARGET:
      nodesDestroyNode(((STargetNode*)pNode)->pExpr);
      break;
    case QUERY_NODE_DATABLOCK_DESC:
      nodesDestroyList(((SDataBlockDescNode*)pNode)->pSlots);
      break;
X
Xiaoyu Wang 已提交
708 709 710
    case QUERY_NODE_SLOT_DESC:          // no pointer field
    case QUERY_NODE_COLUMN_DEF:         // no pointer field
    case QUERY_NODE_DOWNSTREAM_SOURCE:  // no pointer field
X
Xiaoyu Wang 已提交
711
      break;
X
Xiaoyu Wang 已提交
712 713
    case QUERY_NODE_DATABASE_OPTIONS: {
      SDatabaseOptions* pOptions = (SDatabaseOptions*)pNode;
714
      nodesDestroyNode((SNode*)pOptions->pDaysPerFile);
X
Xiaoyu Wang 已提交
715 716
      nodesDestroyList(pOptions->pKeep);
      nodesDestroyList(pOptions->pRetentions);
X
Xiaoyu Wang 已提交
717
      break;
X
Xiaoyu Wang 已提交
718
    }
X
Xiaoyu Wang 已提交
719
    case QUERY_NODE_TABLE_OPTIONS: {
X
Xiaoyu Wang 已提交
720
      STableOptions* pOptions = (STableOptions*)pNode;
721 722
      nodesDestroyList(pOptions->pMaxDelay);
      nodesDestroyList(pOptions->pWatermark);
X
Xiaoyu Wang 已提交
723
      nodesDestroyList(pOptions->pRollupFuncs);
724
      nodesDestroyList(pOptions->pSma);
X
Xiaoyu Wang 已提交
725
      break;
X
Xiaoyu Wang 已提交
726
    }
727
    case QUERY_NODE_INDEX_OPTIONS: {
X
Xiaoyu Wang 已提交
728 729 730 731 732
      SIndexOptions* pOptions = (SIndexOptions*)pNode;
      nodesDestroyList(pOptions->pFuncs);
      nodesDestroyNode(pOptions->pInterval);
      nodesDestroyNode(pOptions->pOffset);
      nodesDestroyNode(pOptions->pSliding);
733
      nodesDestroyNode(pOptions->pStreamOptions);
734 735
      break;
    }
736 737
    case QUERY_NODE_EXPLAIN_OPTIONS:  // no pointer field
      break;
738 739 740 741
    case QUERY_NODE_STREAM_OPTIONS: {
      SStreamOptions* pOptions = (SStreamOptions*)pNode;
      nodesDestroyNode(pOptions->pDelay);
      nodesDestroyNode(pOptions->pWatermark);
742
      break;
743
    }
744
    case QUERY_NODE_LEFT_VALUE:  // no pointer field
H
Haojun Liao 已提交
745
    case QUERY_NODE_COLUMN_REF:  // no pointer field
746
      break;
H
Haojun Liao 已提交
747 748 749 750 751 752 753 754 755 756 757 758 759
    case QUERY_NODE_WHEN_THEN: {
      SWhenThenNode* pStmt = (SWhenThenNode*)pNode;
      nodesDestroyNode(pStmt->pWhen);
      nodesDestroyNode(pStmt->pThen);
      break;
    }
    case QUERY_NODE_CASE_WHEN: {
      SCaseWhenNode* pStmt = (SCaseWhenNode*)pNode;
      nodesDestroyNode(pStmt->pCase);
      nodesDestroyNode(pStmt->pElse);
      nodesDestroyList(pStmt->pWhenThenList);
      break;
    }
X
Xiaoyu Wang 已提交
760 761
    case QUERY_NODE_SET_OPERATOR: {
      SSetOperator* pStmt = (SSetOperator*)pNode;
762
      nodesDestroyList(pStmt->pProjectionList);
X
Xiaoyu Wang 已提交
763 764 765 766 767 768
      nodesDestroyNode(pStmt->pLeft);
      nodesDestroyNode(pStmt->pRight);
      nodesDestroyList(pStmt->pOrderByList);
      nodesDestroyNode(pStmt->pLimit);
      break;
    }
X
Xiaoyu Wang 已提交
769
    case QUERY_NODE_SELECT_STMT: {
X
Xiaoyu Wang 已提交
770
      SSelectStmt* pStmt = (SSelectStmt*)pNode;
X
Xiaoyu Wang 已提交
771 772 773 774 775 776 777
      nodesDestroyList(pStmt->pProjectionList);
      nodesDestroyNode(pStmt->pFromTable);
      nodesDestroyNode(pStmt->pWhere);
      nodesDestroyList(pStmt->pPartitionByList);
      nodesDestroyNode(pStmt->pWindow);
      nodesDestroyList(pStmt->pGroupByList);
      nodesDestroyNode(pStmt->pHaving);
X
Xiaoyu Wang 已提交
778 779 780
      nodesDestroyNode(pStmt->pRange);
      nodesDestroyNode(pStmt->pEvery);
      nodesDestroyNode(pStmt->pFill);
X
Xiaoyu Wang 已提交
781
      nodesDestroyList(pStmt->pOrderByList);
782 783
      nodesDestroyNode((SNode*)pStmt->pLimit);
      nodesDestroyNode((SNode*)pStmt->pSlimit);
X
Xiaoyu Wang 已提交
784 785
      break;
    }
X
Xiaoyu Wang 已提交
786 787 788 789
    case QUERY_NODE_VNODE_MODIF_STMT:
      destroyVgDataBlockArray(((SVnodeModifOpStmt*)pNode)->pDataBlocks);
      break;
    case QUERY_NODE_CREATE_DATABASE_STMT:
790
      nodesDestroyNode((SNode*)((SCreateDatabaseStmt*)pNode)->pOptions);
X
Xiaoyu Wang 已提交
791
      break;
X
Xiaoyu Wang 已提交
792
    case QUERY_NODE_DROP_DATABASE_STMT:  // no pointer field
X
Xiaoyu Wang 已提交
793 794
      break;
    case QUERY_NODE_ALTER_DATABASE_STMT:
795
      nodesDestroyNode((SNode*)((SAlterDatabaseStmt*)pNode)->pOptions);
X
Xiaoyu Wang 已提交
796
      break;
X
Xiaoyu Wang 已提交
797
    case QUERY_NODE_FLUSH_DATABASE_STMT:  // no pointer field
X
Xiaoyu Wang 已提交
798
    case QUERY_NODE_TRIM_DATABASE_STMT:   // no pointer field
X
Xiaoyu Wang 已提交
799
      break;
X
Xiaoyu Wang 已提交
800
    case QUERY_NODE_CREATE_TABLE_STMT: {
X
Xiaoyu Wang 已提交
801
      SCreateTableStmt* pStmt = (SCreateTableStmt*)pNode;
X
Xiaoyu Wang 已提交
802 803
      nodesDestroyList(pStmt->pCols);
      nodesDestroyList(pStmt->pTags);
804
      nodesDestroyNode((SNode*)pStmt->pOptions);
X
Xiaoyu Wang 已提交
805 806 807
      break;
    }
    case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: {
X
Xiaoyu Wang 已提交
808
      SCreateSubTableClause* pStmt = (SCreateSubTableClause*)pNode;
X
Xiaoyu Wang 已提交
809 810
      nodesDestroyList(pStmt->pSpecificTags);
      nodesDestroyList(pStmt->pValsOfTags);
wmmhello's avatar
wmmhello 已提交
811
      nodesDestroyNode((SNode*)pStmt->pOptions);
X
Xiaoyu Wang 已提交
812 813 814
      break;
    }
    case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
X
Xiaoyu Wang 已提交
815 816
      nodesDestroyList(((SCreateMultiTableStmt*)pNode)->pSubTables);
      break;
X
Xiaoyu Wang 已提交
817
    case QUERY_NODE_DROP_TABLE_CLAUSE:  // no pointer field
X
Xiaoyu Wang 已提交
818 819
      break;
    case QUERY_NODE_DROP_TABLE_STMT:
820
      nodesDestroyList(((SDropTableStmt*)pNode)->pTables);
X
Xiaoyu Wang 已提交
821
      break;
X
Xiaoyu Wang 已提交
822
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:  // no pointer field
X
Xiaoyu Wang 已提交
823
      break;
824 825
    case QUERY_NODE_ALTER_TABLE_STMT:
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT: {
X
Xiaoyu Wang 已提交
826
      SAlterTableStmt* pStmt = (SAlterTableStmt*)pNode;
827 828
      nodesDestroyNode((SNode*)pStmt->pOptions);
      nodesDestroyNode((SNode*)pStmt->pVal);
X
Xiaoyu Wang 已提交
829 830
      break;
    }
X
Xiaoyu Wang 已提交
831 832 833 834 835 836 837
    case QUERY_NODE_CREATE_USER_STMT:   // no pointer field
    case QUERY_NODE_ALTER_USER_STMT:    // no pointer field
    case QUERY_NODE_DROP_USER_STMT:     // no pointer field
    case QUERY_NODE_USE_DATABASE_STMT:  // no pointer field
    case QUERY_NODE_CREATE_DNODE_STMT:  // no pointer field
    case QUERY_NODE_DROP_DNODE_STMT:    // no pointer field
    case QUERY_NODE_ALTER_DNODE_STMT:   // no pointer field
838
      break;
839
    case QUERY_NODE_CREATE_INDEX_STMT: {
X
Xiaoyu Wang 已提交
840
      SCreateIndexStmt* pStmt = (SCreateIndexStmt*)pNode;
841
      nodesDestroyNode((SNode*)pStmt->pOptions);
842 843 844
      nodesDestroyList(pStmt->pCols);
      break;
    }
X
Xiaoyu Wang 已提交
845 846 847
    case QUERY_NODE_DROP_INDEX_STMT:    // no pointer field
    case QUERY_NODE_CREATE_QNODE_STMT:  // no pointer field
    case QUERY_NODE_DROP_QNODE_STMT:    // no pointer field
848 849 850 851 852 853
    case QUERY_NODE_CREATE_BNODE_STMT:  // no pointer field
    case QUERY_NODE_DROP_BNODE_STMT:    // no pointer field
    case QUERY_NODE_CREATE_SNODE_STMT:  // no pointer field
    case QUERY_NODE_DROP_SNODE_STMT:    // no pointer field
    case QUERY_NODE_CREATE_MNODE_STMT:  // no pointer field
    case QUERY_NODE_DROP_MNODE_STMT:    // no pointer field
X
Xiaoyu Wang 已提交
854 855 856 857
      break;
    case QUERY_NODE_CREATE_TOPIC_STMT:
      nodesDestroyNode(((SCreateTopicStmt*)pNode)->pQuery);
      break;
X
Xiaoyu Wang 已提交
858
    case QUERY_NODE_DROP_TOPIC_STMT:   // no pointer field
859
    case QUERY_NODE_DROP_CGROUP_STMT:  // no pointer field
X
Xiaoyu Wang 已提交
860
    case QUERY_NODE_ALTER_LOCAL_STMT:  // no pointer field
X
Xiaoyu Wang 已提交
861
      break;
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
    case QUERY_NODE_EXPLAIN_STMT: {
      SExplainStmt* pStmt = (SExplainStmt*)pNode;
      nodesDestroyNode((SNode*)pStmt->pOptions);
      nodesDestroyNode(pStmt->pQuery);
      break;
    }
    case QUERY_NODE_DESCRIBE_STMT:
      taosMemoryFree(((SDescribeStmt*)pNode)->pMeta);
      break;
    case QUERY_NODE_RESET_QUERY_CACHE_STMT:  // no pointer field
    case QUERY_NODE_COMPACT_STMT:            // no pointer field
    case QUERY_NODE_CREATE_FUNCTION_STMT:    // no pointer field
    case QUERY_NODE_DROP_FUNCTION_STMT:      // no pointer field
      break;
    case QUERY_NODE_CREATE_STREAM_STMT: {
      SCreateStreamStmt* pStmt = (SCreateStreamStmt*)pNode;
      nodesDestroyNode((SNode*)pStmt->pOptions);
      nodesDestroyNode(pStmt->pQuery);
      break;
    }
    case QUERY_NODE_DROP_STREAM_STMT:     // no pointer field
    case QUERY_NODE_BALANCE_VGROUP_STMT:  // no pointer field
    case QUERY_NODE_MERGE_VGROUP_STMT:    // no pointer field
      break;
    case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
      nodesDestroyList(((SRedistributeVgroupStmt*)pNode)->pDnodes);
      break;
    case QUERY_NODE_SPLIT_VGROUP_STMT:  // no pointer field
    case QUERY_NODE_SYNCDB_STMT:        // no pointer field
    case QUERY_NODE_GRANT_STMT:         // no pointer field
    case QUERY_NODE_REVOKE_STMT:        // no pointer field
      break;
X
Xiaoyu Wang 已提交
894 895 896 897
    case QUERY_NODE_SHOW_DNODES_STMT:
    case QUERY_NODE_SHOW_MNODES_STMT:
    case QUERY_NODE_SHOW_MODULES_STMT:
    case QUERY_NODE_SHOW_QNODES_STMT:
898 899 900 901
    case QUERY_NODE_SHOW_SNODES_STMT:
    case QUERY_NODE_SHOW_BNODES_STMT:
    case QUERY_NODE_SHOW_CLUSTER_STMT:
    case QUERY_NODE_SHOW_DATABASES_STMT:
X
Xiaoyu Wang 已提交
902 903
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
    case QUERY_NODE_SHOW_INDEXES_STMT:
904 905 906 907
    case QUERY_NODE_SHOW_STABLES_STMT:
    case QUERY_NODE_SHOW_STREAMS_STMT:
    case QUERY_NODE_SHOW_TABLES_STMT:
    case QUERY_NODE_SHOW_USERS_STMT:
X
Xiaoyu Wang 已提交
908
    case QUERY_NODE_SHOW_LICENCES_STMT:
909 910 911 912 913 914 915 916
    case QUERY_NODE_SHOW_VGROUPS_STMT:
    case QUERY_NODE_SHOW_TOPICS_STMT:
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
    case QUERY_NODE_SHOW_CONNECTIONS_STMT:
    case QUERY_NODE_SHOW_QUERIES_STMT:
    case QUERY_NODE_SHOW_VNODES_STMT:
    case QUERY_NODE_SHOW_APPS_STMT:
    case QUERY_NODE_SHOW_SCORES_STMT:
917 918
    case QUERY_NODE_SHOW_VARIABLES_STMT:
    case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
919
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
920 921
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
    case QUERY_NODE_SHOW_TAGS_STMT: {
X
Xiaoyu Wang 已提交
922 923
      SShowStmt* pStmt = (SShowStmt*)pNode;
      nodesDestroyNode(pStmt->pDbName);
924
      nodesDestroyNode(pStmt->pTbName);
X
Xiaoyu Wang 已提交
925 926
      break;
    }
927 928
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
      nodesDestroyNode(((SShowDnodeVariablesStmt*)pNode)->pDnodeId);
929
      break;
930 931 932 933 934
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
      taosMemoryFreeClear(((SShowCreateDatabaseStmt*)pNode)->pCfg);
      break;
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
X
Xiaoyu Wang 已提交
935 936
      taosMemoryFreeClear(((SShowCreateTableStmt*)pNode)->pDbCfg);
      destroyTableCfg((STableCfg*)(((SShowCreateTableStmt*)pNode)->pTableCfg));
937 938 939 940 941
      break;
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:  // no pointer field
    case QUERY_NODE_KILL_CONNECTION_STMT:         // no pointer field
    case QUERY_NODE_KILL_QUERY_STMT:              // no pointer field
    case QUERY_NODE_KILL_TRANSACTION_STMT:        // no pointer field
942 943 944 945 946 947
      break;
    case QUERY_NODE_DELETE_STMT: {
      SDeleteStmt* pStmt = (SDeleteStmt*)pNode;
      nodesDestroyNode(pStmt->pFromTable);
      nodesDestroyNode(pStmt->pWhere);
      nodesDestroyNode(pStmt->pCountFunc);
948 949
      nodesDestroyNode(pStmt->pFirstFunc);
      nodesDestroyNode(pStmt->pLastFunc);
X
Xiaoyu Wang 已提交
950
      nodesDestroyNode(pStmt->pTagCond);
951 952
      break;
    }
953 954 955 956 957 958 959
    case QUERY_NODE_INSERT_STMT: {
      SInsertStmt* pStmt = (SInsertStmt*)pNode;
      nodesDestroyNode(pStmt->pTable);
      nodesDestroyList(pStmt->pCols);
      nodesDestroyNode(pStmt->pQuery);
      break;
    }
960 961 962 963 964 965 966 967 968 969
    case QUERY_NODE_QUERY: {
      SQuery* pQuery = (SQuery*)pNode;
      nodesDestroyNode(pQuery->pRoot);
      taosMemoryFreeClear(pQuery->pResSchema);
      if (NULL != pQuery->pCmdMsg) {
        taosMemoryFreeClear(pQuery->pCmdMsg->pMsg);
        taosMemoryFreeClear(pQuery->pCmdMsg);
      }
      taosArrayDestroy(pQuery->pDbList);
      taosArrayDestroy(pQuery->pTableList);
D
dapan1121 已提交
970
      taosArrayDestroy(pQuery->pTargetTableList);
971 972
      taosArrayDestroy(pQuery->pPlaceholderValues);
      nodesDestroyNode(pQuery->pPrepareRoot);
973 974
      break;
    }
X
Xiaoyu Wang 已提交
975 976 977 978
    case QUERY_NODE_LOGIC_PLAN_SCAN: {
      SScanLogicNode* pLogicNode = (SScanLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pScanCols);
X
Xiaoyu Wang 已提交
979
      nodesDestroyList(pLogicNode->pScanPseudoCols);
X
Xiaoyu Wang 已提交
980
      taosMemoryFreeClear(pLogicNode->pVgroupList);
X
Xiaoyu Wang 已提交
981 982 983
      nodesDestroyList(pLogicNode->pDynamicScanFuncs);
      nodesDestroyNode(pLogicNode->pTagCond);
      nodesDestroyNode(pLogicNode->pTagIndexCond);
984
      taosArrayDestroyEx(pLogicNode->pSmaIndexes, destroySmaIndex);
985
      nodesDestroyList(pLogicNode->pGroupTags);
X
Xiaoyu Wang 已提交
986 987 988 989 990
      break;
    }
    case QUERY_NODE_LOGIC_PLAN_JOIN: {
      SJoinLogicNode* pLogicNode = (SJoinLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
991
      nodesDestroyNode(pLogicNode->pMergeCondition);
X
Xiaoyu Wang 已提交
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
      nodesDestroyNode(pLogicNode->pOnConditions);
      break;
    }
    case QUERY_NODE_LOGIC_PLAN_AGG: {
      SAggLogicNode* pLogicNode = (SAggLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pAggFuncs);
      nodesDestroyList(pLogicNode->pGroupKeys);
      break;
    }
    case QUERY_NODE_LOGIC_PLAN_PROJECT: {
      SProjectLogicNode* pLogicNode = (SProjectLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pProjections);
      break;
    }
X
Xiaoyu Wang 已提交
1008 1009
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY: {
      SVnodeModifyLogicNode* pLogicNode = (SVnodeModifyLogicNode*)pNode;
X
Xiaoyu Wang 已提交
1010 1011
      destroyLogicNode((SLogicNode*)pLogicNode);
      destroyVgDataBlockArray(pLogicNode->pDataBlocks);
X
bugfix  
Xiaoyu Wang 已提交
1012
      // pVgDataBlocks is weak reference
1013
      nodesDestroyNode(pLogicNode->pAffectedRows);
1014 1015
      nodesDestroyNode(pLogicNode->pStartTs);
      nodesDestroyNode(pLogicNode->pEndTs);
1016 1017
      taosMemoryFreeClear(pLogicNode->pVgroupList);
      nodesDestroyList(pLogicNode->pInsertCols);
X
Xiaoyu Wang 已提交
1018 1019 1020 1021 1022
      break;
    }
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
      destroyLogicNode((SLogicNode*)pNode);
      break;
1023 1024 1025 1026 1027 1028 1029
    case QUERY_NODE_LOGIC_PLAN_MERGE: {
      SMergeLogicNode* pLogicNode = (SMergeLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pMergeKeys);
      nodesDestroyList(pLogicNode->pInputs);
      break;
    }
X
Xiaoyu Wang 已提交
1030 1031 1032 1033 1034
    case QUERY_NODE_LOGIC_PLAN_WINDOW: {
      SWindowLogicNode* pLogicNode = (SWindowLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pFuncs);
      nodesDestroyNode(pLogicNode->pTspk);
5
54liuyao 已提交
1035
      nodesDestroyNode(pLogicNode->pTsEnd);
1036
      nodesDestroyNode(pLogicNode->pStateExpr);
X
Xiaoyu Wang 已提交
1037 1038
      break;
    }
1039 1040 1041 1042 1043
    case QUERY_NODE_LOGIC_PLAN_FILL: {
      SFillLogicNode* pLogicNode = (SFillLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyNode(pLogicNode->pWStartTs);
      nodesDestroyNode(pLogicNode->pValues);
F
freemine 已提交
1044
      nodesDestroyList(pLogicNode->pFillExprs);
1045
      nodesDestroyList(pLogicNode->pNotFillExprs);
1046 1047
      break;
    }
X
Xiaoyu Wang 已提交
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
    case QUERY_NODE_LOGIC_PLAN_SORT: {
      SSortLogicNode* pLogicNode = (SSortLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pSortKeys);
      break;
    }
    case QUERY_NODE_LOGIC_PLAN_PARTITION: {
      SPartitionLogicNode* pLogicNode = (SPartitionLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pPartitionKeys);
      break;
    }
1060 1061 1062
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: {
      SIndefRowsFuncLogicNode* pLogicNode = (SIndefRowsFuncLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
X
Xiaoyu Wang 已提交
1063 1064 1065 1066 1067 1068 1069
      nodesDestroyList(pLogicNode->pFuncs);
      break;
    }
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: {
      SInterpFuncLogicNode* pLogicNode = (SInterpFuncLogicNode*)pNode;
      destroyLogicNode((SLogicNode*)pLogicNode);
      nodesDestroyList(pLogicNode->pFuncs);
X
Xiaoyu Wang 已提交
1070 1071
      nodesDestroyNode(pLogicNode->pFillValues);
      nodesDestroyNode(pLogicNode->pTimeSeries);
1072 1073
      break;
    }
X
Xiaoyu Wang 已提交
1074 1075 1076
    case QUERY_NODE_LOGIC_SUBPLAN: {
      SLogicSubplan* pSubplan = (SLogicSubplan*)pNode;
      nodesDestroyList(pSubplan->pChildren);
1077
      nodesDestroyNode((SNode*)pSubplan->pNode);
X
bugfix  
Xiaoyu Wang 已提交
1078
      nodesClearList(pSubplan->pParents);
X
Xiaoyu Wang 已提交
1079 1080 1081 1082 1083 1084 1085 1086
      taosMemoryFreeClear(pSubplan->pVgroupList);
      break;
    }
    case QUERY_NODE_LOGIC_PLAN:
      nodesDestroyList(((SQueryLogicPlan*)pNode)->pTopSubplans);
      break;
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
1087
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
X
Xiaoyu Wang 已提交
1088 1089
      destroyScanPhysiNode((SScanPhysiNode*)pNode);
      break;
1090 1091 1092 1093 1094 1095
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: {
      SLastRowScanPhysiNode* pPhyNode = (SLastRowScanPhysiNode*)pNode;
      destroyScanPhysiNode((SScanPhysiNode*)pNode);
      nodesDestroyList(pPhyNode->pGroupTags);
      break;
    }
X
Xiaoyu Wang 已提交
1096 1097 1098 1099 1100 1101 1102
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: {
      STableScanPhysiNode* pPhyNode = (STableScanPhysiNode*)pNode;
      destroyScanPhysiNode((SScanPhysiNode*)pNode);
      nodesDestroyList(pPhyNode->pDynamicScanFuncs);
1103
      nodesDestroyList(pPhyNode->pGroupTags);
X
Xiaoyu Wang 已提交
1104 1105
      break;
    }
X
Xiaoyu Wang 已提交
1106 1107 1108 1109 1110 1111
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT: {
      SProjectPhysiNode* pPhyNode = (SProjectPhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
      nodesDestroyList(pPhyNode->pProjections);
      break;
    }
1112
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: {
1113
      SSortMergeJoinPhysiNode* pPhyNode = (SSortMergeJoinPhysiNode*)pNode;
X
Xiaoyu Wang 已提交
1114
      destroyPhysiNode((SPhysiNode*)pPhyNode);
1115
      nodesDestroyNode(pPhyNode->pMergeCondition);
X
Xiaoyu Wang 已提交
1116 1117 1118 1119
      nodesDestroyNode(pPhyNode->pOnConditions);
      nodesDestroyList(pPhyNode->pTargets);
      break;
    }
1120
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: {
X
Xiaoyu Wang 已提交
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
      SAggPhysiNode* pPhyNode = (SAggPhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
      nodesDestroyList(pPhyNode->pExprs);
      nodesDestroyList(pPhyNode->pAggFuncs);
      nodesDestroyList(pPhyNode->pGroupKeys);
      break;
    }
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: {
      SExchangePhysiNode* pPhyNode = (SExchangePhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
      nodesDestroyList(pPhyNode->pSrcEndPoints);
      break;
    }
1134 1135 1136 1137 1138 1139 1140
    case QUERY_NODE_PHYSICAL_PLAN_MERGE: {
      SMergePhysiNode* pPhyNode = (SMergePhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
      nodesDestroyList(pPhyNode->pMergeKeys);
      nodesDestroyList(pPhyNode->pTargets);
      break;
    }
1141 1142
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT: {
X
Xiaoyu Wang 已提交
1143 1144
      SSortPhysiNode* pPhyNode = (SSortPhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
1145 1146
      nodesDestroyList(pPhyNode->pExprs);
      nodesDestroyList(pPhyNode->pSortKeys);
X
Xiaoyu Wang 已提交
1147
      nodesDestroyList(pPhyNode->pTargets);
X
Xiaoyu Wang 已提交
1148 1149
      break;
    }
X
Xiaoyu Wang 已提交
1150
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
1151
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
X
Xiaoyu Wang 已提交
1152
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
1153 1154
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
X
Xiaoyu Wang 已提交
1155
      destroyWinodwPhysiNode((SWinodwPhysiNode*)pNode);
X
Xiaoyu Wang 已提交
1156
      break;
1157 1158 1159
    case QUERY_NODE_PHYSICAL_PLAN_FILL: {
      SFillPhysiNode* pPhyNode = (SFillPhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
1160 1161
      nodesDestroyList(pPhyNode->pFillExprs);
      nodesDestroyList(pPhyNode->pNotFillExprs);
1162 1163 1164 1165
      nodesDestroyNode(pPhyNode->pWStartTs);
      nodesDestroyNode(pPhyNode->pValues);
      break;
    }
1166 1167
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
1168
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
1169
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
X
Xiaoyu Wang 已提交
1170 1171
      destroyWinodwPhysiNode((SWinodwPhysiNode*)pNode);
      break;
1172 1173 1174 1175 1176 1177 1178
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: {
      SStateWinodwPhysiNode* pPhyNode = (SStateWinodwPhysiNode*)pNode;
      destroyWinodwPhysiNode((SWinodwPhysiNode*)pPhyNode);
      nodesDestroyNode(pPhyNode->pStateKey);
      break;
    }
1179 1180
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION: {
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
      SPartitionPhysiNode* pPhyNode = (SPartitionPhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
      nodesDestroyList(pPhyNode->pExprs);
      nodesDestroyList(pPhyNode->pPartitionKeys);
      nodesDestroyList(pPhyNode->pTargets);
      break;
    }
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: {
      SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
      nodesDestroyList(pPhyNode->pExprs);
X
Xiaoyu Wang 已提交
1192 1193 1194 1195 1196 1197 1198 1199
      nodesDestroyList(pPhyNode->pFuncs);
      break;
    }
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: {
      SInterpFuncPhysiNode* pPhyNode = (SInterpFuncPhysiNode*)pNode;
      destroyPhysiNode((SPhysiNode*)pPhyNode);
      nodesDestroyList(pPhyNode->pExprs);
      nodesDestroyList(pPhyNode->pFuncs);
X
Xiaoyu Wang 已提交
1200 1201
      nodesDestroyNode(pPhyNode->pFillValues);
      nodesDestroyNode(pPhyNode->pTimeSeries);
1202 1203
      break;
    }
X
Xiaoyu Wang 已提交
1204 1205 1206 1207 1208 1209 1210 1211 1212
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
      destroyDataSinkNode((SDataSinkNode*)pNode);
      break;
    case QUERY_NODE_PHYSICAL_PLAN_INSERT: {
      SDataInserterNode* pSink = (SDataInserterNode*)pNode;
      destroyDataSinkNode((SDataSinkNode*)pSink);
      taosMemoryFreeClear(pSink->pData);
      break;
    }
1213 1214 1215
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
      SQueryInserterNode* pSink = (SQueryInserterNode*)pNode;
      destroyDataSinkNode((SDataSinkNode*)pSink);
D
dapan1121 已提交
1216
      nodesDestroyList(pSink->pCols);
1217 1218
      break;
    }
1219 1220 1221 1222
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
      SDataDeleterNode* pSink = (SDataDeleterNode*)pNode;
      destroyDataSinkNode((SDataSinkNode*)pSink);
      nodesDestroyNode(pSink->pAffectedRows);
1223 1224
      nodesDestroyNode(pSink->pStartTs);
      nodesDestroyNode(pSink->pEndTs);
1225 1226
      break;
    }
X
Xiaoyu Wang 已提交
1227 1228
    case QUERY_NODE_PHYSICAL_SUBPLAN: {
      SSubplan* pSubplan = (SSubplan*)pNode;
X
Xiaoyu Wang 已提交
1229
      nodesClearList(pSubplan->pChildren);
1230 1231
      nodesDestroyNode((SNode*)pSubplan->pNode);
      nodesDestroyNode((SNode*)pSubplan->pDataSink);
X
Xiaoyu Wang 已提交
1232 1233
      nodesDestroyNode((SNode*)pSubplan->pTagCond);
      nodesDestroyNode((SNode*)pSubplan->pTagIndexCond);
X
bugfix  
Xiaoyu Wang 已提交
1234 1235 1236
      nodesClearList(pSubplan->pParents);
      break;
    }
1237 1238
    case QUERY_NODE_PHYSICAL_PLAN:
      nodesDestroyList(((SQueryPlan*)pNode)->pSubplans);
X
Xiaoyu Wang 已提交
1239
      break;
1240 1241 1242
    default:
      break;
  }
1243
  nodesFree(pNode);
X
Xiaoyu Wang 已提交
1244
  return;
1245 1246
}

1247
SNodeList* nodesMakeList() {
1248
  SNodeList* p = nodesCalloc(1, sizeof(SNodeList));
1249 1250 1251 1252 1253 1254
  if (NULL == p) {
    return NULL;
  }
  return p;
}

1255
int32_t nodesListAppend(SNodeList* pList, SNode* pNode) {
1256
  if (NULL == pList || NULL == pNode) {
X
Xiaoyu Wang 已提交
1257
    return TSDB_CODE_FAILED;
1258
  }
1259
  SListCell* p = nodesCalloc(1, sizeof(SListCell));
1260
  if (NULL == p) {
X
Xiaoyu Wang 已提交
1261 1262
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return TSDB_CODE_OUT_OF_MEMORY;
1263 1264
  }
  p->pNode = pNode;
1265 1266 1267 1268 1269 1270
  if (NULL == pList->pHead) {
    pList->pHead = p;
  }
  if (NULL != pList->pTail) {
    pList->pTail->pNext = p;
  }
1271
  p->pPrev = pList->pTail;
1272
  pList->pTail = p;
1273
  ++(pList->length);
X
Xiaoyu Wang 已提交
1274
  return TSDB_CODE_SUCCESS;
1275 1276
}

1277
int32_t nodesListStrictAppend(SNodeList* pList, SNode* pNode) {
1278
  if (NULL == pNode) {
X
Xiaoyu Wang 已提交
1279
    terrno = TSDB_CODE_OUT_OF_MEMORY;
1280 1281 1282 1283 1284 1285 1286 1287 1288
    return TSDB_CODE_OUT_OF_MEMORY;
  }
  int32_t code = nodesListAppend(pList, pNode);
  if (TSDB_CODE_SUCCESS != code) {
    nodesDestroyNode(pNode);
  }
  return code;
}

1289
int32_t nodesListMakeAppend(SNodeList** pList, SNode* pNode) {
X
Xiaoyu Wang 已提交
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
  if (NULL == *pList) {
    *pList = nodesMakeList();
    if (NULL == *pList) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return TSDB_CODE_OUT_OF_MEMORY;
    }
  }
  return nodesListAppend(*pList, pNode);
}

1300
int32_t nodesListMakeStrictAppend(SNodeList** pList, SNode* pNode) {
S
Shengliang Guan 已提交
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
  if (NULL == *pList) {
    *pList = nodesMakeList();
    if (NULL == *pList) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return TSDB_CODE_OUT_OF_MEMORY;
    }
  }
  return nodesListStrictAppend(*pList, pNode);
}

X
Xiaoyu Wang 已提交
1311
int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) {
X
Xiaoyu Wang 已提交
1312
  if (NULL == pTarget || NULL == pSrc) {
X
Xiaoyu Wang 已提交
1313
    return TSDB_CODE_FAILED;
X
Xiaoyu Wang 已提交
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
  }

  if (NULL == pTarget->pHead) {
    pTarget->pHead = pSrc->pHead;
  } else {
    pTarget->pTail->pNext = pSrc->pHead;
    if (NULL != pSrc->pHead) {
      pSrc->pHead->pPrev = pTarget->pTail;
    }
  }
X
Xiaoyu Wang 已提交
1324 1325
  pTarget->pTail = pSrc->pTail;
  pTarget->length += pSrc->length;
1326
  nodesFree(pSrc);
X
Xiaoyu Wang 已提交
1327

X
Xiaoyu Wang 已提交
1328 1329 1330
  return TSDB_CODE_SUCCESS;
}

1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc) {
  if (NULL == pSrc) {
    return TSDB_CODE_OUT_OF_MEMORY;
  }
  int32_t code = nodesListAppendList(pTarget, pSrc);
  if (TSDB_CODE_SUCCESS != code) {
    nodesDestroyList(pSrc);
  }
  return code;
}

1342
int32_t nodesListPushFront(SNodeList* pList, SNode* pNode) {
X
Xiaoyu Wang 已提交
1343 1344 1345
  if (NULL == pList || NULL == pNode) {
    return TSDB_CODE_FAILED;
  }
1346
  SListCell* p = nodesCalloc(1, sizeof(SListCell));
X
Xiaoyu Wang 已提交
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
  if (NULL == p) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return TSDB_CODE_OUT_OF_MEMORY;
  }
  p->pNode = pNode;
  if (NULL != pList->pHead) {
    pList->pHead->pPrev = p;
    p->pNext = pList->pHead;
  }
  pList->pHead = p;
  ++(pList->length);
  return TSDB_CODE_SUCCESS;
}

1361 1362 1363 1364 1365
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell) {
  if (NULL == pCell->pPrev) {
    pList->pHead = pCell->pNext;
  } else {
    pCell->pPrev->pNext = pCell->pNext;
X
Xiaoyu Wang 已提交
1366 1367 1368 1369
  }
  if (NULL == pCell->pNext) {
    pList->pTail = pCell->pPrev;
  } else {
1370 1371 1372
    pCell->pNext->pPrev = pCell->pPrev;
  }
  SListCell* pNext = pCell->pNext;
X
Xiaoyu Wang 已提交
1373
  nodesDestroyNode(pCell->pNode);
1374
  nodesFree(pCell);
1375 1376 1377 1378
  --(pList->length);
  return pNext;
}

X
Xiaoyu Wang 已提交
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc) {
  if (NULL == pTarget || NULL == pPos || NULL == pSrc) {
    return;
  }

  if (NULL == pPos->pPrev) {
    pTarget->pHead = pSrc->pHead;
  } else {
    pPos->pPrev->pNext = pSrc->pHead;
  }
  pSrc->pHead->pPrev = pPos->pPrev;
  pSrc->pTail->pNext = pPos;
  pPos->pPrev = pSrc->pTail;

  pTarget->length += pSrc->length;
1394
  nodesFree(pSrc);
X
Xiaoyu Wang 已提交
1395 1396
}

1397
SNode* nodesListGetNode(SNodeList* pList, int32_t index) {
1398 1399 1400 1401 1402 1403 1404 1405 1406
  SNode* node;
  FOREACH(node, pList) {
    if (0 == index--) {
      return node;
    }
  }
  return NULL;
}

X
Xiaoyu Wang 已提交
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
SListCell* nodesListGetCell(SNodeList* pList, int32_t index) {
  SNode* node;
  FOREACH(node, pList) {
    if (0 == index--) {
      return cell;
    }
  }
  return NULL;
}

1417
void nodesDestroyList(SNodeList* pList) {
1418 1419 1420
  if (NULL == pList) {
    return;
  }
X
Xiaoyu Wang 已提交
1421

D
dapan1121 已提交
1422 1423 1424
  SListCell* pNext = pList->pHead;
  while (NULL != pNext) {
    pNext = nodesListErase(pList, pNext);
1425
  }
1426
  nodesFree(pList);
1427 1428
}

X
Xiaoyu Wang 已提交
1429 1430 1431 1432 1433 1434 1435 1436 1437
void nodesClearList(SNodeList* pList) {
  if (NULL == pList) {
    return;
  }

  SListCell* pNext = pList->pHead;
  while (NULL != pNext) {
    SListCell* tmp = pNext;
    pNext = pNext->pNext;
1438
    nodesFree(tmp);
X
Xiaoyu Wang 已提交
1439
  }
1440
  nodesFree(pList);
X
Xiaoyu Wang 已提交
1441 1442
}

X
Xiaoyu Wang 已提交
1443
void* nodesGetValueFromNode(SValueNode* pNode) {
D
dapan1121 已提交
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
  switch (pNode->node.resType.type) {
    case TSDB_DATA_TYPE_BOOL:
    case TSDB_DATA_TYPE_TINYINT:
    case TSDB_DATA_TYPE_SMALLINT:
    case TSDB_DATA_TYPE_INT:
    case TSDB_DATA_TYPE_BIGINT:
    case TSDB_DATA_TYPE_TIMESTAMP:
    case TSDB_DATA_TYPE_UTINYINT:
    case TSDB_DATA_TYPE_USMALLINT:
    case TSDB_DATA_TYPE_UINT:
    case TSDB_DATA_TYPE_UBIGINT:
    case TSDB_DATA_TYPE_FLOAT:
1456
    case TSDB_DATA_TYPE_DOUBLE:
D
dapan1121 已提交
1457
      return (void*)&pNode->typeData;
D
dapan1121 已提交
1458 1459
    case TSDB_DATA_TYPE_NCHAR:
    case TSDB_DATA_TYPE_VARCHAR:
1460
    case TSDB_DATA_TYPE_VARBINARY:
wmmhello's avatar
wmmhello 已提交
1461
    case TSDB_DATA_TYPE_JSON:
X
Xiaoyu Wang 已提交
1462
      return (void*)pNode->datum.p;
D
dapan1121 已提交
1463 1464 1465 1466 1467 1468 1469
    default:
      break;
  }

  return NULL;
}

X
Xiaoyu Wang 已提交
1470
int32_t nodesSetValueNodeValue(SValueNode* pNode, void* value) {
D
dapan1121 已提交
1471 1472 1473
  switch (pNode->node.resType.type) {
    case TSDB_DATA_TYPE_BOOL:
      pNode->datum.b = *(bool*)value;
D
dapan1121 已提交
1474
      *(bool*)&pNode->typeData = pNode->datum.b;
D
dapan1121 已提交
1475 1476 1477
      break;
    case TSDB_DATA_TYPE_TINYINT:
      pNode->datum.i = *(int8_t*)value;
D
dapan1121 已提交
1478
      *(int8_t*)&pNode->typeData = pNode->datum.i;
D
dapan1121 已提交
1479 1480 1481
      break;
    case TSDB_DATA_TYPE_SMALLINT:
      pNode->datum.i = *(int16_t*)value;
D
dapan1121 已提交
1482
      *(int16_t*)&pNode->typeData = pNode->datum.i;
D
dapan1121 已提交
1483 1484 1485
      break;
    case TSDB_DATA_TYPE_INT:
      pNode->datum.i = *(int32_t*)value;
D
dapan1121 已提交
1486
      *(int32_t*)&pNode->typeData = pNode->datum.i;
D
dapan1121 已提交
1487 1488 1489
      break;
    case TSDB_DATA_TYPE_BIGINT:
      pNode->datum.i = *(int64_t*)value;
D
dapan1121 已提交
1490
      *(int64_t*)&pNode->typeData = pNode->datum.i;
D
dapan1121 已提交
1491 1492 1493
      break;
    case TSDB_DATA_TYPE_TIMESTAMP:
      pNode->datum.i = *(int64_t*)value;
D
dapan1121 已提交
1494
      *(int64_t*)&pNode->typeData = pNode->datum.i;
D
dapan1121 已提交
1495 1496 1497
      break;
    case TSDB_DATA_TYPE_UTINYINT:
      pNode->datum.u = *(int8_t*)value;
D
dapan1121 已提交
1498
      *(int8_t*)&pNode->typeData = pNode->datum.u;
D
dapan1121 已提交
1499 1500 1501
      break;
    case TSDB_DATA_TYPE_USMALLINT:
      pNode->datum.u = *(int16_t*)value;
D
dapan1121 已提交
1502
      *(int16_t*)&pNode->typeData = pNode->datum.u;
D
dapan1121 已提交
1503 1504 1505
      break;
    case TSDB_DATA_TYPE_UINT:
      pNode->datum.u = *(int32_t*)value;
D
dapan1121 已提交
1506
      *(int32_t*)&pNode->typeData = pNode->datum.u;
D
dapan1121 已提交
1507 1508 1509
      break;
    case TSDB_DATA_TYPE_UBIGINT:
      pNode->datum.u = *(uint64_t*)value;
D
dapan1121 已提交
1510
      *(uint64_t*)&pNode->typeData = pNode->datum.u;
D
dapan1121 已提交
1511 1512 1513
      break;
    case TSDB_DATA_TYPE_FLOAT:
      pNode->datum.d = *(float*)value;
D
dapan1121 已提交
1514
      *(float*)&pNode->typeData = pNode->datum.d;
D
dapan1121 已提交
1515 1516 1517
      break;
    case TSDB_DATA_TYPE_DOUBLE:
      pNode->datum.d = *(double*)value;
D
dapan1121 已提交
1518
      *(double*)&pNode->typeData = pNode->datum.d;
D
dapan1121 已提交
1519 1520 1521 1522
      break;
    case TSDB_DATA_TYPE_NCHAR:
    case TSDB_DATA_TYPE_VARCHAR:
    case TSDB_DATA_TYPE_VARBINARY:
wmmhello's avatar
wmmhello 已提交
1523
    case TSDB_DATA_TYPE_JSON:
D
dapan1121 已提交
1524 1525 1526 1527 1528 1529 1530 1531 1532
      pNode->datum.p = (char*)value;
      break;
    default:
      return TSDB_CODE_QRY_APP_ERROR;
  }

  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
1533
char* nodesGetStrValueFromNode(SValueNode* pNode) {
D
dapan1121 已提交
1534
  switch (pNode->node.resType.type) {
D
dapan1121 已提交
1535
    case TSDB_DATA_TYPE_BOOL: {
X
Xiaoyu Wang 已提交
1536
      void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE);
D
dapan1121 已提交
1537 1538 1539
      if (NULL == buf) {
        return NULL;
      }
1540

D
dapan1121 已提交
1541 1542
      sprintf(buf, "%s", pNode->datum.b ? "true" : "false");
      return buf;
D
dapan1121 已提交
1543
    }
D
dapan1121 已提交
1544 1545 1546 1547 1548
    case TSDB_DATA_TYPE_TINYINT:
    case TSDB_DATA_TYPE_SMALLINT:
    case TSDB_DATA_TYPE_INT:
    case TSDB_DATA_TYPE_BIGINT:
    case TSDB_DATA_TYPE_TIMESTAMP: {
X
Xiaoyu Wang 已提交
1549
      void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE);
D
dapan1121 已提交
1550 1551 1552
      if (NULL == buf) {
        return NULL;
      }
1553

D
dapan1121 已提交
1554 1555 1556 1557 1558 1559 1560
      sprintf(buf, "%" PRId64, pNode->datum.i);
      return buf;
    }
    case TSDB_DATA_TYPE_UTINYINT:
    case TSDB_DATA_TYPE_USMALLINT:
    case TSDB_DATA_TYPE_UINT:
    case TSDB_DATA_TYPE_UBIGINT: {
X
Xiaoyu Wang 已提交
1561
      void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE);
D
dapan1121 已提交
1562 1563 1564
      if (NULL == buf) {
        return NULL;
      }
1565

D
dapan1121 已提交
1566 1567 1568 1569 1570
      sprintf(buf, "%" PRIu64, pNode->datum.u);
      return buf;
    }
    case TSDB_DATA_TYPE_FLOAT:
    case TSDB_DATA_TYPE_DOUBLE: {
X
Xiaoyu Wang 已提交
1571
      void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE);
D
dapan1121 已提交
1572 1573 1574
      if (NULL == buf) {
        return NULL;
      }
1575

D
dapan1121 已提交
1576 1577 1578 1579 1580 1581
      sprintf(buf, "%e", pNode->datum.d);
      return buf;
    }
    case TSDB_DATA_TYPE_NCHAR:
    case TSDB_DATA_TYPE_VARCHAR:
    case TSDB_DATA_TYPE_VARBINARY: {
D
dapan1121 已提交
1582
      int32_t bufSize = varDataLen(pNode->datum.p) + 2 + 1;
X
Xiaoyu Wang 已提交
1583
      void*   buf = taosMemoryMalloc(bufSize);
D
dapan1121 已提交
1584 1585 1586
      if (NULL == buf) {
        return NULL;
      }
1587

D
dapan1121 已提交
1588
      snprintf(buf, bufSize, "'%s'", varDataVal(pNode->datum.p));
D
dapan1121 已提交
1589 1590 1591 1592 1593 1594 1595 1596 1597
      return buf;
    }
    default:
      break;
  }

  return NULL;
}

1598 1599
bool nodesIsExprNode(const SNode* pNode) {
  ENodeType type = nodeType(pNode);
X
Xiaoyu Wang 已提交
1600
  return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type ||
X
Xiaoyu Wang 已提交
1601
          QUERY_NODE_FUNCTION == type || QUERY_NODE_LOGIC_CONDITION == type);
1602 1603
}

X
Xiaoyu Wang 已提交
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
bool nodesIsUnaryOp(const SOperatorNode* pOp) {
  switch (pOp->opType) {
    case OP_TYPE_MINUS:
    case OP_TYPE_IS_NULL:
    case OP_TYPE_IS_NOT_NULL:
    case OP_TYPE_IS_TRUE:
    case OP_TYPE_IS_FALSE:
    case OP_TYPE_IS_UNKNOWN:
    case OP_TYPE_IS_NOT_TRUE:
    case OP_TYPE_IS_NOT_FALSE:
    case OP_TYPE_IS_NOT_UNKNOWN:
      return true;
    default:
      break;
  }
  return false;
}

1622 1623 1624 1625 1626 1627
bool nodesIsArithmeticOp(const SOperatorNode* pOp) {
  switch (pOp->opType) {
    case OP_TYPE_ADD:
    case OP_TYPE_SUB:
    case OP_TYPE_MULTI:
    case OP_TYPE_DIV:
1628
    case OP_TYPE_REM:
1629 1630 1631 1632 1633 1634
      return true;
    default:
      break;
  }
  return false;
}
1635

1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
bool nodesIsComparisonOp(const SOperatorNode* pOp) {
  switch (pOp->opType) {
    case OP_TYPE_GREATER_THAN:
    case OP_TYPE_GREATER_EQUAL:
    case OP_TYPE_LOWER_THAN:
    case OP_TYPE_LOWER_EQUAL:
    case OP_TYPE_EQUAL:
    case OP_TYPE_NOT_EQUAL:
    case OP_TYPE_IN:
    case OP_TYPE_NOT_IN:
    case OP_TYPE_LIKE:
    case OP_TYPE_NOT_LIKE:
    case OP_TYPE_MATCH:
    case OP_TYPE_NMATCH:
1650
    case OP_TYPE_JSON_CONTAINS:
X
Xiaoyu Wang 已提交
1651 1652 1653 1654 1655 1656 1657 1658
    case OP_TYPE_IS_NULL:
    case OP_TYPE_IS_NOT_NULL:
    case OP_TYPE_IS_TRUE:
    case OP_TYPE_IS_FALSE:
    case OP_TYPE_IS_UNKNOWN:
    case OP_TYPE_IS_NOT_TRUE:
    case OP_TYPE_IS_NOT_FALSE:
    case OP_TYPE_IS_NOT_UNKNOWN:
1659 1660 1661 1662 1663
      return true;
    default:
      break;
  }
  return false;
1664 1665
}

1666 1667 1668
bool nodesIsJsonOp(const SOperatorNode* pOp) {
  switch (pOp->opType) {
    case OP_TYPE_JSON_GET_VALUE:
wmmhello's avatar
wmmhello 已提交
1669
    case OP_TYPE_JSON_CONTAINS:
1670 1671 1672 1673 1674 1675
      return true;
    default:
      break;
  }
  return false;
}
1676

X
Xiaoyu Wang 已提交
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689
bool nodesIsRegularOp(const SOperatorNode* pOp) {
  switch (pOp->opType) {
    case OP_TYPE_LIKE:
    case OP_TYPE_NOT_LIKE:
    case OP_TYPE_MATCH:
    case OP_TYPE_NMATCH:
      return true;
    default:
      break;
  }
  return false;
}

X
Xiaoyu Wang 已提交
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
bool nodesIsBitwiseOp(const SOperatorNode* pOp) {
  switch (pOp->opType) {
    case OP_TYPE_BIT_AND:
    case OP_TYPE_BIT_OR:
      return true;
    default:
      break;
  }
  return false;
}

X
Xiaoyu Wang 已提交
1701
typedef struct SCollectColumnsCxt {
1702 1703 1704 1705 1706
  int32_t         errCode;
  const char*     pTableAlias;
  ECollectColType collectType;
  SNodeList*      pCols;
  SHashObj*       pColHash;
X
Xiaoyu Wang 已提交
1707 1708
} SCollectColumnsCxt;

1709
static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pNode) {
X
Xiaoyu Wang 已提交
1710
  char    name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
1711 1712 1713 1714 1715 1716 1717
  int32_t len = 0;
  if ('\0' == pCol->tableAlias[0]) {
    len = sprintf(name, "%s", pCol->colName);
  }
  len = sprintf(name, "%s.%s", pCol->tableAlias, pCol->colName);
  if (NULL == taosHashGet(pCxt->pColHash, name, len)) {
    pCxt->errCode = taosHashPut(pCxt->pColHash, name, len, NULL, 0);
X
Xiaoyu Wang 已提交
1718
    if (TSDB_CODE_SUCCESS == pCxt->errCode) {
1719
      pCxt->errCode = nodesListStrictAppend(pCxt->pCols, nodesCloneNode(pNode));
X
Xiaoyu Wang 已提交
1720 1721 1722 1723 1724 1725
    }
    return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
  }
  return DEAL_RES_CONTINUE;
}

1726 1727 1728 1729 1730 1731
static bool isCollectType(ECollectColType collectType, EColumnType colType) {
  return COLLECT_COL_TYPE_ALL == collectType
             ? true
             : (COLLECT_COL_TYPE_TAG == collectType ? COLUMN_TYPE_TAG == colType : COLUMN_TYPE_TAG != colType);
}

X
Xiaoyu Wang 已提交
1732 1733
static EDealRes collectColumns(SNode* pNode, void* pContext) {
  SCollectColumnsCxt* pCxt = (SCollectColumnsCxt*)pContext;
X
Xiaoyu Wang 已提交
1734
  if (QUERY_NODE_COLUMN == nodeType(pNode)) {
X
Xiaoyu Wang 已提交
1735
    SColumnNode* pCol = (SColumnNode*)pNode;
X
Xiaoyu Wang 已提交
1736
    if (isCollectType(pCxt->collectType, pCol->colType) && 0 != strcmp(pCol->colName, "*") &&
1737
        (NULL == pCxt->pTableAlias || 0 == strcmp(pCxt->pTableAlias, pCol->tableAlias))) {
1738
      return doCollect(pCxt, pCol, pNode);
X
Xiaoyu Wang 已提交
1739 1740 1741 1742 1743
    }
  }
  return DEAL_RES_CONTINUE;
}

1744 1745
int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type,
                            SNodeList** pCols) {
X
Xiaoyu Wang 已提交
1746
  if (NULL == pSelect || NULL == pCols) {
1747
    return TSDB_CODE_FAILED;
X
Xiaoyu Wang 已提交
1748 1749 1750
  }

  SCollectColumnsCxt cxt = {
X
Xiaoyu Wang 已提交
1751 1752
      .errCode = TSDB_CODE_SUCCESS,
      .pTableAlias = pTableAlias,
1753
      .collectType = type,
1754
      .pCols = (NULL == *pCols ? nodesMakeList() : *pCols),
X
Xiaoyu Wang 已提交
1755
      .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)};
1756
  if (NULL == cxt.pCols || NULL == cxt.pColHash) {
X
Xiaoyu Wang 已提交
1757 1758
    return TSDB_CODE_OUT_OF_MEMORY;
  }
1759
  *pCols = NULL;
X
Xiaoyu Wang 已提交
1760
  nodesWalkSelectStmt(pSelect, clause, collectColumns, &cxt);
1761
  taosHashCleanup(cxt.pColHash);
X
Xiaoyu Wang 已提交
1762
  if (TSDB_CODE_SUCCESS != cxt.errCode) {
1763
    nodesDestroyList(cxt.pCols);
X
Xiaoyu Wang 已提交
1764 1765
    return cxt.errCode;
  }
1766 1767 1768
  if (LIST_LENGTH(cxt.pCols) > 0) {
    *pCols = cxt.pCols;
  } else {
1769
    nodesDestroyList(cxt.pCols);
X
Xiaoyu Wang 已提交
1770
  }
1771

X
Xiaoyu Wang 已提交
1772 1773 1774
  return TSDB_CODE_SUCCESS;
}

1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, ECollectColType type, SNodeList** pCols) {
  if (NULL == pCols) {
    return TSDB_CODE_FAILED;
  }
  SCollectColumnsCxt cxt = {
      .errCode = TSDB_CODE_SUCCESS,
      .pTableAlias = pTableAlias,
      .collectType = type,
      .pCols = (NULL == *pCols ? nodesMakeList() : *pCols),
      .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)};
  if (NULL == cxt.pCols || NULL == cxt.pColHash) {
    return TSDB_CODE_OUT_OF_MEMORY;
  }
  *pCols = NULL;

  nodesWalkExpr(node, collectColumns, &cxt);

  taosHashCleanup(cxt.pColHash);
  if (TSDB_CODE_SUCCESS != cxt.errCode) {
    nodesDestroyList(cxt.pCols);
    return cxt.errCode;
  }
  if (LIST_LENGTH(cxt.pCols) > 0) {
    *pCols = cxt.pCols;
  } else {
    nodesDestroyList(cxt.pCols);
  }

  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
1806
typedef struct SCollectFuncsCxt {
X
Xiaoyu Wang 已提交
1807
  int32_t         errCode;
X
Xiaoyu Wang 已提交
1808
  FFuncClassifier classifier;
X
Xiaoyu Wang 已提交
1809
  SNodeList*      pFuncs;
X
Xiaoyu Wang 已提交
1810
  SHashObj*       pFuncsSet;
X
Xiaoyu Wang 已提交
1811 1812 1813 1814
} SCollectFuncsCxt;

static EDealRes collectFuncs(SNode* pNode, void* pContext) {
  SCollectFuncsCxt* pCxt = (SCollectFuncsCxt*)pContext;
1815 1816
  if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId) &&
      !(((SExprNode*)pNode)->orderAlias)) {
X
Xiaoyu Wang 已提交
1817
    SExprNode* pExpr = (SExprNode*)pNode;
X
Xiaoyu Wang 已提交
1818
    if (NULL == taosHashGet(pCxt->pFuncsSet, &pExpr, POINTER_BYTES)) {
X
Xiaoyu Wang 已提交
1819
      pCxt->errCode = nodesListStrictAppend(pCxt->pFuncs, nodesCloneNode(pNode));
X
Xiaoyu Wang 已提交
1820
      taosHashPut(pCxt->pFuncsSet, &pExpr, POINTER_BYTES, &pExpr, POINTER_BYTES);
X
Xiaoyu Wang 已提交
1821
    }
X
Xiaoyu Wang 已提交
1822 1823 1824 1825 1826
    return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
  }
  return DEAL_RES_CONTINUE;
}

X
Xiaoyu Wang 已提交
1827 1828 1829 1830 1831 1832
static uint32_t funcNodeHash(const char* pKey, uint32_t len) {
  SExprNode* pExpr = *(SExprNode**)pKey;
  return MurmurHash3_32(pExpr->aliasName, strlen(pExpr->aliasName));
}

static int32_t funcNodeEqual(const void* pLeft, const void* pRight, size_t len) {
X
Xiaoyu Wang 已提交
1833 1834 1835
  if (0 != strcmp((*(const SExprNode**)pLeft)->aliasName, (*(const SExprNode**)pRight)->aliasName)) {
    return 1;
  }
X
Xiaoyu Wang 已提交
1836 1837 1838
  return nodesEqualNode(*(const SNode**)pLeft, *(const SNode**)pRight) ? 0 : 1;
}

X
Xiaoyu Wang 已提交
1839
int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, FFuncClassifier classifier, SNodeList** pFuncs) {
X
Xiaoyu Wang 已提交
1840
  if (NULL == pSelect || NULL == pFuncs) {
1841
    return TSDB_CODE_FAILED;
X
Xiaoyu Wang 已提交
1842 1843
  }

X
Xiaoyu Wang 已提交
1844 1845 1846 1847 1848
  SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS,
                          .classifier = classifier,
                          .pFuncs = (NULL == *pFuncs ? nodesMakeList() : *pFuncs),
                          .pFuncsSet = taosHashInit(4, funcNodeHash, false, false)};
  if (NULL == cxt.pFuncs || NULL == cxt.pFuncsSet) {
X
Xiaoyu Wang 已提交
1849 1850
    return TSDB_CODE_OUT_OF_MEMORY;
  }
X
Xiaoyu Wang 已提交
1851
  taosHashSetEqualFp(cxt.pFuncsSet, funcNodeEqual);
1852
  *pFuncs = NULL;
X
Xiaoyu Wang 已提交
1853
  nodesWalkSelectStmt(pSelect, clause, collectFuncs, &cxt);
X
Xiaoyu Wang 已提交
1854 1855 1856 1857 1858 1859
  if (TSDB_CODE_SUCCESS == cxt.errCode) {
    if (LIST_LENGTH(cxt.pFuncs) > 0) {
      *pFuncs = cxt.pFuncs;
    } else {
      nodesDestroyList(cxt.pFuncs);
    }
X
Xiaoyu Wang 已提交
1860 1861 1862
  } else {
    nodesDestroyList(cxt.pFuncs);
  }
X
Xiaoyu Wang 已提交
1863
  taosHashCleanup(cxt.pFuncsSet);
X
Xiaoyu Wang 已提交
1864

X
Xiaoyu Wang 已提交
1865
  return cxt.errCode;
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904
}

typedef struct SCollectSpecialNodesCxt {
  int32_t    errCode;
  ENodeType  type;
  SNodeList* pNodes;
} SCollectSpecialNodesCxt;

static EDealRes collectSpecialNodes(SNode* pNode, void* pContext) {
  SCollectSpecialNodesCxt* pCxt = (SCollectSpecialNodesCxt*)pContext;
  if (pCxt->type == nodeType(pNode)) {
    pCxt->errCode = nodesListStrictAppend(pCxt->pNodes, nodesCloneNode(pNode));
    return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
  }
  return DEAL_RES_CONTINUE;
}

int32_t nodesCollectSpecialNodes(SSelectStmt* pSelect, ESqlClause clause, ENodeType type, SNodeList** pNodes) {
  if (NULL == pSelect || NULL == pNodes) {
    return TSDB_CODE_FAILED;
  }

  SCollectSpecialNodesCxt cxt = {
      .errCode = TSDB_CODE_SUCCESS, .type = type, .pNodes = (NULL == *pNodes ? nodesMakeList() : *pNodes)};
  if (NULL == cxt.pNodes) {
    return TSDB_CODE_OUT_OF_MEMORY;
  }
  *pNodes = NULL;
  nodesWalkSelectStmt(pSelect, SQL_CLAUSE_GROUP_BY, collectSpecialNodes, &cxt);
  if (TSDB_CODE_SUCCESS != cxt.errCode) {
    nodesDestroyList(cxt.pNodes);
    return cxt.errCode;
  }
  if (LIST_LENGTH(cxt.pNodes) > 0) {
    *pNodes = cxt.pNodes;
  } else {
    nodesDestroyList(cxt.pNodes);
  }

X
Xiaoyu Wang 已提交
1905 1906
  return TSDB_CODE_SUCCESS;
}
D
dapan1121 已提交
1907

1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
static EDealRes hasColumn(SNode* pNode, void* pContext) {
  if (QUERY_NODE_COLUMN == nodeType(pNode)) {
    *(bool*)pContext = true;
    return DEAL_RES_END;
  }
  return DEAL_RES_CONTINUE;
}

bool nodesExprHasColumn(SNode* pNode) {
  bool hasCol = false;
  nodesWalkExprPostOrder(pNode, hasColumn, &hasCol);
  return hasCol;
}

bool nodesExprsHasColumn(SNodeList* pList) {
  bool hasCol = false;
  nodesWalkExprsPostOrder(pList, hasColumn, &hasCol);
  return hasCol;
}

X
Xiaoyu Wang 已提交
1928
char* nodesGetFillModeString(EFillMode mode) {
D
dapan1121 已提交
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946
  switch (mode) {
    case FILL_MODE_NONE:
      return "none";
    case FILL_MODE_VALUE:
      return "value";
    case FILL_MODE_PREV:
      return "prev";
    case FILL_MODE_NULL:
      return "null";
    case FILL_MODE_LINEAR:
      return "linear";
    case FILL_MODE_NEXT:
      return "next";
    default:
      return "unknown";
  }
}

X
Xiaoyu Wang 已提交
1947
char* nodesGetNameFromColumnNode(SNode* pNode) {
D
dapan1121 已提交
1948 1949 1950
  if (NULL == pNode || QUERY_NODE_COLUMN != pNode->type) {
    return "NULL";
  }
X
Xiaoyu Wang 已提交
1951 1952

  return ((SColumnNode*)pNode)->colName;
D
dapan1121 已提交
1953 1954
}

D
dapan1121 已提交
1955 1956 1957 1958 1959
int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
  if (NULL == pSlots || pSlots->length <= 0) {
    return 0;
  }

X
Xiaoyu Wang 已提交
1960
  SNode*  pNode = NULL;
D
dapan1121 已提交
1961 1962 1963 1964 1965 1966
  int32_t num = 0;
  FOREACH(pNode, pSlots) {
    if (QUERY_NODE_SLOT_DESC != pNode->type) {
      continue;
    }

X
Xiaoyu Wang 已提交
1967
    SSlotDescNode* descNode = (SSlotDescNode*)pNode;
D
dapan1121 已提交
1968 1969 1970 1971 1972 1973 1974 1975
    if (descNode->output) {
      ++num;
    }
  }

  return num;
}

X
Xiaoyu Wang 已提交
1976
void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
1977 1978 1979 1980 1981
  if (pNode->isNull) {
    pVal->nType = TSDB_DATA_TYPE_NULL;
    pVal->nLen = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
    return;
  }
D
dapan1121 已提交
1982 1983 1984 1985
  pVal->nType = pNode->node.resType.type;
  pVal->nLen = pNode->node.resType.bytes;
  switch (pNode->node.resType.type) {
    case TSDB_DATA_TYPE_NULL:
X
Xiaoyu Wang 已提交
1986
      break;
D
dapan1121 已提交
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
    case TSDB_DATA_TYPE_BOOL:
      pVal->i = pNode->datum.b;
      break;
    case TSDB_DATA_TYPE_TINYINT:
    case TSDB_DATA_TYPE_SMALLINT:
    case TSDB_DATA_TYPE_INT:
    case TSDB_DATA_TYPE_BIGINT:
    case TSDB_DATA_TYPE_TIMESTAMP:
      pVal->i = pNode->datum.i;
      break;
    case TSDB_DATA_TYPE_UTINYINT:
    case TSDB_DATA_TYPE_USMALLINT:
    case TSDB_DATA_TYPE_UINT:
    case TSDB_DATA_TYPE_UBIGINT:
      pVal->u = pNode->datum.u;
      break;
    case TSDB_DATA_TYPE_FLOAT:
    case TSDB_DATA_TYPE_DOUBLE:
      pVal->d = pNode->datum.d;
      break;
    case TSDB_DATA_TYPE_NCHAR:
    case TSDB_DATA_TYPE_VARCHAR:
    case TSDB_DATA_TYPE_VARBINARY:
D
dapan1121 已提交
2010 2011 2012
      pVal->pz = taosMemoryMalloc(pVal->nLen + VARSTR_HEADER_SIZE + 1);
      memcpy(pVal->pz, pNode->datum.p, pVal->nLen + VARSTR_HEADER_SIZE);
      pVal->pz[pVal->nLen + VARSTR_HEADER_SIZE] = 0;
D
dapan1121 已提交
2013 2014
      break;
    case TSDB_DATA_TYPE_JSON:
wmmhello's avatar
wmmhello 已提交
2015 2016 2017 2018
      pVal->nLen = getJsonValueLen(pNode->datum.p);
      pVal->pz = taosMemoryMalloc(pVal->nLen);
      memcpy(pVal->pz, pNode->datum.p, pVal->nLen);
      break;
D
dapan1121 已提交
2019 2020 2021 2022 2023 2024 2025
    case TSDB_DATA_TYPE_DECIMAL:
    case TSDB_DATA_TYPE_BLOB:
      // todo
    default:
      break;
  }
}
X
Xiaoyu Wang 已提交
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035

int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc) {
  if (NULL == *pSrc) {
    return TSDB_CODE_SUCCESS;
  }

  if (1 == LIST_LENGTH(*pSrc)) {
    *pDst = nodesListGetNode(*pSrc, 0);
    nodesClearList(*pSrc);
  } else {
2036
    SLogicConditionNode* pLogicCond = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
X
Xiaoyu Wang 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049
    if (NULL == pLogicCond) {
      return TSDB_CODE_OUT_OF_MEMORY;
    }
    pLogicCond->node.resType.type = TSDB_DATA_TYPE_BOOL;
    pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
    pLogicCond->condType = LOGIC_COND_TYPE_AND;
    pLogicCond->pParameterList = *pSrc;
    *pDst = (SNode*)pLogicCond;
  }
  *pSrc = NULL;

  return TSDB_CODE_SUCCESS;
}
X
Xiaoyu Wang 已提交
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065

const char* dataOrderStr(EDataOrderLevel order) {
  switch (order) {
    case DATA_ORDER_LEVEL_NONE:
      return "no order required";
    case DATA_ORDER_LEVEL_IN_BLOCK:
      return "in-datablock order";
    case DATA_ORDER_LEVEL_IN_GROUP:
      return "in-group order";
    case DATA_ORDER_LEVEL_GLOBAL:
      return "global order";
    default:
      break;
  }
  return "unknown";
}