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

taosdata / TDengine / #5052

13 May 2026 12:00PM UTC coverage: 73.338% (-0.02%) from 73.358%
#5052

push

travis-ci

web-flow
feat: taosdump support stream backup/restore (#35326)

139 of 170 new or added lines in 3 files covered. (81.76%)

761 existing lines in 163 files now uncovered.

281469 of 383795 relevant lines covered (73.34%)

134502812.98 hits per line

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

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

16
#include "executorInt.h"
17
#include "executor.h"
18
#include "function.h"
19
#include "operator.h"
20
#include "osTime.h"
21
#include "query.h"
22
#include "querytask.h"
23
#include "storageapi.h"
24
#include "taoserror.h"
25
#include "tdatablock.h"
26
#include "tdef.h"
27
#include "tglobal.h"
28
#include "tutil.h"
29

30
static int32_t optrGetNextFnWithExecRecord(SOperatorInfo* pOperator,
31
                                           SSDataBlock** pResBlock);
32
static int32_t optrGetNextExtFnWithExecRecord(SOperatorInfo* pOperator,
33
                                              SOperatorParam* pParam,
34
                                              SSDataBlock** pResBlock);
35
static int32_t optrResetStateFnWithExecRecord(SOperatorInfo* pParam);
36

37
SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup,
852,753,766✔
38
                                   __optr_close_fn_t closeFn, __optr_reqBuf_fn_t reqBufFn, __optr_explain_fn_t explain,
39
                                   __optr_get_ext_fn_t nextExtFn, __optr_notify_fn_t notifyFn) {
40
  SOperatorFpSet fpSet = {
2,147,483,647✔
41
      ._openFn = openFn,
42
      ._nextFn = nextFn,
43
      .getNextFn = (nextFn != NULL) ? optrGetNextFnWithExecRecord : NULL,
852,753,766✔
44
      .cleanupFn = cleanup,
45
      .closeFn = closeFn,
46
      .reqBufFn = reqBufFn,
47
      .getExplainFn = explain,
48
      ._nextExtFn = nextExtFn,
49
      .getNextExtFn = (nextExtFn != NULL) ? optrGetNextExtFnWithExecRecord : NULL,
852,753,766✔
50
      .notifyFn = notifyFn,
51
      .releaseStreamStateFn = NULL,
52
      .reloadStreamStateFn = NULL,
53
      ._resetFn = NULL,
54
      .resetStateFn = NULL,
55
  };
56

57
  return fpSet;
852,753,766✔
58
}
59

60
static int32_t optrGetNextFnWithExecRecord(SOperatorInfo* pOperator,
2,147,483,647✔
61
                                           SSDataBlock** pResBlock) {
62
  QRY_PARAM_CHECK(pResBlock);
2,147,483,647✔
63

64
  recordOpExecBegin(pOperator);
2,147,483,647✔
65
  int32_t code = pOperator->fpSet._nextFn(pOperator, pResBlock);
2,147,483,647✔
66
  size_t  rows = (TSDB_CODE_SUCCESS == code && *pResBlock != NULL) ?
2,147,483,647✔
67
                 (*pResBlock)->info.rows : 0;
2,147,483,647✔
68
  recordOpExecEnd(pOperator, rows);
2,147,483,647✔
69
  return code;
2,147,483,647✔
70
}
71

72
static int32_t optrGetNextExtFnWithExecRecord(SOperatorInfo* pOperator,
131,117,297✔
73
                                              SOperatorParam* pParam,
74
                                              SSDataBlock** pResBlock) {
75
  QRY_PARAM_CHECK(pResBlock);
131,117,297✔
76

77
  recordOpExecBegin(pOperator);
131,117,297✔
78
  int32_t code = pOperator->fpSet._nextExtFn(pOperator, pParam, pResBlock);
131,112,030✔
79
  size_t  rows = (TSDB_CODE_SUCCESS == code && *pResBlock != NULL) ?
131,097,788✔
80
                 (*pResBlock)->info.rows : 0;
262,196,254✔
81
  recordOpExecEnd(pOperator, rows);
131,096,215✔
82
  return code;
131,098,014✔
83
}
84

85
static int32_t optrResetStateFnWithExecRecord(SOperatorInfo* pOperator) {
41,297,424✔
86
  int32_t code = pOperator->fpSet._resetFn(pOperator);
41,297,424✔
87
  resetOperatorCostInfo(pOperator);
41,293,108✔
88
  return code;
41,290,594✔
89
}
90

91
void setOperatorStreamStateFn(SOperatorInfo* pOperator, __optr_state_fn_t relaseFn, __optr_state_fn_t reloadFn) {
161,782,095✔
92
  pOperator->fpSet.releaseStreamStateFn = relaseFn;
161,782,095✔
93
  pOperator->fpSet.reloadStreamStateFn = reloadFn;
161,789,118✔
94
}
161,780,294✔
95

96
void setOperatorResetStateFn(SOperatorInfo* pOperator, __optr_reset_state_fn_t resetFn) {
850,153,745✔
97
  pOperator->fpSet._resetFn = resetFn;
850,153,745✔
98
  pOperator->fpSet.resetStateFn = (resetFn != NULL) ? optrResetStateFnWithExecRecord : NULL;
850,089,450✔
99
}
850,169,671✔
100

101
int32_t optrDummyOpenFn(SOperatorInfo* pOperator) {
77,991,346✔
102
  OPTR_SET_OPENED(pOperator);
77,991,346✔
103
  return TSDB_CODE_SUCCESS;
77,989,751✔
104
}
105

106
int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num) {
395,144,535✔
107
  p->pDownstream = taosMemoryCalloc(1, num * POINTER_BYTES);
395,144,535✔
108
  if (p->pDownstream == NULL) {
395,133,450✔
109
    return terrno;
×
110
  }
111

112
  memcpy(p->pDownstream, pDownstream, num * POINTER_BYTES);
395,038,365✔
113
  p->numOfDownstream = num;
395,111,819✔
114
  p->numOfRealDownstream = num;
395,166,746✔
115
  return TSDB_CODE_SUCCESS;
395,053,180✔
116
}
117

118
void setOperatorCompleted(SOperatorInfo* pOperator) {
955,762,643✔
119
  pOperator->status = OP_EXEC_DONE;
955,762,643✔
120
  setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
955,796,157✔
121
}
955,743,371✔
122

123
void setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status,
852,721,828✔
124
                     void* pInfo, SExecTaskInfo* pTaskInfo) {
125
  pOperator->name = (char*)name;
852,721,828✔
126
  pOperator->operatorType = type;
852,865,741✔
127
  pOperator->blocking = blocking;
852,521,146✔
128
  pOperator->status = status;
852,708,619✔
129
  pOperator->info = pInfo;
852,668,621✔
130
  pOperator->pTaskInfo = pTaskInfo;
852,507,564✔
131
}
852,775,417✔
132

133
// each operator should be set their own function to return total cost buffer
134
int32_t optrDefaultBufFn(SOperatorInfo* pOperator) {
×
135
  if (pOperator->blocking) {
×
136
    return -1;
×
137
  } else {
138
    return 0;
×
139
  }
140
}
141

142

143
typedef enum {
144
  OPTR_FN_RET_CONTINUE = 0x1,
145
  OPTR_FN_RET_ABORT = 0x2,
146
} ERetType;
147

148
typedef struct STraverParam {
149
  void*   pRet;
150
  int32_t code;
151
  void*   pParam;
152
} STraverParam;
153

154
// iterate the operator tree helper
155
typedef ERetType (*optr_fn_t)(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdstr);
156

157
void traverseOperatorTree(SOperatorInfo* pOperator, optr_fn_t fn, STraverParam* pParam, const char* id) {
357,130,948✔
158
  if (pOperator == NULL) {
357,130,948✔
159
    return;
×
160
  }
161

162
  ERetType ret = fn(pOperator, pParam, id);
357,130,948✔
163
  if (ret == OPTR_FN_RET_ABORT || pParam->code != TSDB_CODE_SUCCESS) {
357,091,857✔
164
    return;
182,914,028✔
165
  }
166

167
  for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
348,424,110✔
168
    traverseOperatorTree(pOperator->pDownstream[i], fn, pParam, id);
174,199,361✔
169
    if (pParam->code != 0) {
174,171,141✔
170
      break;
×
171
    }
172
  }
173
}
174

175
ERetType extractOperatorInfo(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdStr) {
356,940,634✔
176
  STraverParam* p = pParam;
356,940,634✔
177
  if (pOperator->operatorType == *(int32_t*)p->pParam) {
356,940,634✔
178
    p->pRet = pOperator;
182,838,749✔
179
    return OPTR_FN_RET_ABORT;
182,845,065✔
180
  } else {
181
    return OPTR_FN_RET_CONTINUE;
174,120,941✔
182
  }
183
}
184

185
// QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
186
int32_t extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id, SOperatorInfo** pOptrInfo) {
182,855,875✔
187
  QRY_PARAM_CHECK(pOptrInfo);
182,855,875✔
188

189
  if (pOperator == NULL) {
182,878,187✔
190
    qError("invalid operator, failed to find tableScanOperator %s", id);
×
191
    return TSDB_CODE_STREAM_INTERNAL_ERROR;
×
192
  }
193

194
  STraverParam p = {.pParam = &type, .pRet = NULL};
182,878,187✔
195
  traverseOperatorTree(pOperator, extractOperatorInfo, &p, id);
182,862,642✔
196
  if (p.code == 0) {
182,815,162✔
197
    *pOptrInfo = p.pRet;
182,845,877✔
198
  }
199
  return p.code;
182,817,996✔
200
}
201

202
typedef struct SExtScanInfo {
203
  int32_t order;
204
  int32_t scanFlag;
205
  int32_t inheritUsOrder;
206
} SExtScanInfo;
207

208
static ERetType extractScanInfo(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdStr) {
×
209
  int32_t       type = pOperator->operatorType;
×
210
  SExtScanInfo* pInfo = pParam->pParam;
×
211

212
  if (type == QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN ||
×
213
      type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN ||
×
214
      type == QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN) {
×
215
    pInfo->order = TSDB_ORDER_ASC;
×
216
    pInfo->scanFlag = MAIN_SCAN;
×
217
    return OPTR_FN_RET_ABORT;
×
218
  } else if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE) {
×
219
    if (!pInfo->inheritUsOrder) {
×
220
      pInfo->order = TSDB_ORDER_ASC;
×
221
    }
222
    pInfo->scanFlag = MAIN_SCAN;
×
223
    return OPTR_FN_RET_ABORT;
×
224
  } else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
×
225
    STableScanInfo* pTableScanInfo = pOperator->info;
×
226
    pInfo->order = pTableScanInfo->base.cond.order;
×
227
    pInfo->scanFlag = pTableScanInfo->base.scanFlag;
×
228
    return OPTR_FN_RET_ABORT;
×
229
  } else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN) {
×
230
    STableMergeScanInfo* pTableScanInfo = pOperator->info;
×
231
    pInfo->order = pTableScanInfo->base.cond.order;
×
232
    pInfo->scanFlag = pTableScanInfo->base.scanFlag;
×
233
    return OPTR_FN_RET_ABORT;
×
234
  } else {
235
    return OPTR_FN_RET_CONTINUE;
×
236
  }
237
}
238

239
int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scanFlag, bool inheritUsOrder) {
×
240
  SExtScanInfo info = {.inheritUsOrder = inheritUsOrder, .order = *order};
×
241
  STraverParam p = {.pParam = &info};
×
242

243
  traverseOperatorTree(pOperator, extractScanInfo, &p, NULL);
×
244
  *order = info.order;
×
245
  *scanFlag = info.scanFlag;
×
246

247
  if (p.code == TSDB_CODE_SUCCESS) {
×
248
    if (!(*order == TSDB_ORDER_ASC || *order == TSDB_ORDER_DESC)) {
×
249
      qError("operator failed at: %s:%d", __func__, __LINE__);
×
250
      p.code = TSDB_CODE_INVALID_PARA;
×
251
    }
252
  }
253
  return p.code;
×
254
}
255

256
static ERetType doStopDataReader(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdStr) {
190,188✔
257
  SStorageAPI* pAPI = pParam->pParam;
190,188✔
258
  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
190,188✔
259
    STableScanInfo* pInfo = pOperator->info;
83,418✔
260

261
    if (pInfo->base.dataReader != NULL) {
83,418✔
262
      pAPI->tsdReader.tsdReaderNotifyClosing(pInfo->base.dataReader);
81,130✔
263
    }
264
    return OPTR_FN_RET_ABORT;
83,418✔
265
  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
106,770✔
266
    STmqQueryScanInfo* pInfo = pOperator->info;
×
267

268
    if (pInfo->pTableScanOp != NULL) {
×
269
      STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info;
×
270
      if (pTableScanInfo != NULL && pTableScanInfo->base.dataReader != NULL) {
×
271
        pAPI->tsdReader.tsdReaderNotifyClosing(pTableScanInfo->base.dataReader);
×
272
      }
273
    }
274

275
    return OPTR_FN_RET_ABORT;
×
276
  }
277

278
  return OPTR_FN_RET_CONTINUE;
106,770✔
279
}
280

281
int32_t stopTableScanOperator(SOperatorInfo* pOperator, const char* pIdStr, SStorageAPI* pAPI) {
120,592✔
282
  STraverParam p = {.pParam = pAPI};
120,592✔
283
  traverseOperatorTree(pOperator, doStopDataReader, &p, pIdStr);
120,592✔
284
  return p.code;
120,592✔
285
}
286

287
int32_t createOperator(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond,
853,007,788✔
288
                       SNode* pTagIndexCond, const char* pUser, const char* dbname, SOperatorInfo** pOptrInfo,
289
                       EOPTR_EXEC_MODEL model) {
290
  QRY_PARAM_CHECK(pOptrInfo);
853,007,788✔
291

292
  int32_t     code = 0;
853,085,547✔
293
  int32_t     type = nodeType(pPhyNode);
853,085,547✔
294
  const char* idstr = GET_TASKID(pTaskInfo);
853,095,344✔
295

296
  if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
853,113,546✔
297
    SOperatorInfo* pOperator = NULL;
457,273,392✔
298
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
457,231,941✔
299
      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
268,985,681✔
300
      // NOTE: this is an patch to fix the physical plan
301
      // TODO remove it later
302
      if (pTableScanNode->scan.node.pLimit != NULL) {
268,985,681✔
303
        pTableScanNode->groupSort = true;
4,807,375✔
304
      }
305

306
      STableListInfo* pTableListInfo = tableListCreate();
268,992,600✔
307
      if (!pTableListInfo) {
269,017,992✔
308
        pTaskInfo->code = terrno;
×
309
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
310
        return terrno;
×
311
      }
312

313
      // Since virtual stable scan use virtual super table's uid in scan operator, the origin table might be stored on
314
      // different vnode, so we should not get table schema for virtual stable scan.
315
      if (!pTableScanNode->scan.virtualStableScan) {
269,017,992✔
316
        code = initQueriedTableSchemaInfo(pHandle, &pTableScanNode->scan, dbname, pTaskInfo);
259,210,959✔
317
        if (code) {
259,032,195✔
318
          pTaskInfo->code = code;
×
319
          tableListDestroy(pTableListInfo);
×
320
          return code;
×
321
        }
322
      }
323

324
      if (pTableScanNode->scan.node.dynamicOp) {
268,837,559✔
325
        pTaskInfo->dynamicTask = true;
16,201,696✔
326
        pTableListInfo->idInfo.suid = pTableScanNode->scan.suid;
16,201,155✔
327
        pTableListInfo->idInfo.tableType = pTableScanNode->scan.tableType;
16,201,133✔
328
      } else {
329
        code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
252,662,690✔
330
                                       pHandle, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo, NULL);
331
        if (code) {
252,788,011✔
332
          pTaskInfo->code = code;
1,092✔
333
          tableListDestroy(pTableListInfo);
1,092✔
334
          qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
1,092✔
335
          return code;
1,092✔
336
        }
337
      }
338

339
      code = createTableScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo, &pOperator);
268,987,084✔
340
      if (NULL == pOperator || code != 0) {
268,888,416✔
341
        pTaskInfo->code = code;
24,213✔
342
        tableListDestroy(pTableListInfo);
25,938✔
343
        return code;
25,938✔
344
      }
345

346
      STableScanInfo* pScanInfo = pOperator->info;
268,864,216✔
347
      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
268,914,998✔
348
    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
188,246,260✔
349
      STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
28,497,138✔
350
      STableListInfo*           pTableListInfo = tableListCreate();
28,497,138✔
351
      if (!pTableListInfo) {
28,528,937✔
352
        pTaskInfo->code = terrno;
×
353
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
354
        return terrno;
×
355
      }
356

357
      if (pTableScanNode->scan.node.dynamicOp) {
28,528,937✔
358
        pTaskInfo->dynamicTask = true;
180,550✔
359
        pTableListInfo->idInfo.suid = pTableScanNode->scan.suid;
180,550✔
360
        pTableListInfo->idInfo.tableType = pTableScanNode->scan.tableType;
180,550✔
361
      } else {
362
        code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, true, pHandle, pTableListInfo,
28,345,418✔
363
                                       pTagCond, pTagIndexCond, pTaskInfo, NULL);
364
        if (code) {
28,342,493✔
365
          pTaskInfo->code = code;
×
366
          tableListDestroy(pTableListInfo);
×
367
          qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
×
368
          return code;
×
369
        }
370

371
        code = initQueriedTableSchemaInfo(pHandle, &pTableScanNode->scan, dbname, pTaskInfo);
28,342,493✔
372
        if (code) {
28,286,456✔
373
          pTaskInfo->code = code;
×
374
          tableListDestroy(pTableListInfo);
×
375
          return code;
×
376
        }
377
      }
378

379
      code = createTableMergeScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo, &pOperator);
28,467,006✔
380
      if (NULL == pOperator || code != 0) {
28,454,585✔
381
        pTaskInfo->code = code;
31,831✔
382
        tableListDestroy(pTableListInfo);
×
383
        return code;
×
384
      }
385

386
      STableMergeScanInfo* pScanInfo = pOperator->info;
28,422,754✔
387
      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
28,473,121✔
388
    } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) {
159,749,122✔
389
      code = createExchangeOperatorInfo(pHandle ? pHandle->pMsgCb->clientRpc : NULL, (SExchangePhysiNode*)pPhyNode,
120,704,630✔
390
                                        pTaskInfo, &pOperator);
391
    } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
39,044,492✔
392
      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
392,279✔
393
      STableListInfo*      pTableListInfo = tableListCreate();
392,279✔
394
      if (!pTableListInfo) {
392,279✔
395
        pTaskInfo->code = terrno;
×
396
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
397
        return terrno;
×
398
      }
399

400
      if (pHandle->vnode && (pTaskInfo->pSubplan->pVTables == NULL)) {
392,279✔
401
        code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
392,279✔
402
                                       pHandle, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo, NULL);
403
        if (code) {
392,279✔
404
          pTaskInfo->code = code;
×
405
          tableListDestroy(pTableListInfo);
×
406
          qError("failed to createScanTableListInfo, code:%s", tstrerror(code));
×
407
          return code;
×
408
        }
409
      }
410

411
      code = createTmqScanOperatorInfo(pHandle, pTableScanNode, pTagCond, pTableListInfo, pTaskInfo, &pOperator);
392,279✔
412
      if (code) {
391,549✔
413
        pTaskInfo->code = code;
×
414
        tableListDestroy(pTableListInfo);
×
415
        return code;
×
416
      }
417
    } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
38,652,213✔
418
      SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
25,760,828✔
419
      if (pSysScanPhyNode->scan.virtualStableScan) {
25,760,828✔
420
        STableListInfo*           pTableListInfo = tableListCreate();
12,610,554✔
421
        if (!pTableListInfo) {
12,614,420✔
422
          pTaskInfo->code = terrno;
×
423
          qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
424
          return terrno;
×
425
        }
426

427
        code = createScanTableListInfo((SScanPhysiNode*)pSysScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond,
12,614,420✔
428
                                       pTagIndexCond, pTaskInfo, NULL);
429
        if (code != TSDB_CODE_SUCCESS) {
12,610,568✔
430
          pTaskInfo->code = code;
×
431
          tableListDestroy(pTableListInfo);
×
432
          return code;
×
433
        }
434

435
        code = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pTableListInfo, pUser, pTaskInfo, &pOperator);
12,610,568✔
436
      } else {
437
        code = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, NULL, pUser, pTaskInfo, &pOperator);
13,152,824✔
438
      }
439
    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN == type) {
12,891,385✔
440
      STableCountScanPhysiNode* pTblCountScanNode = (STableCountScanPhysiNode*)pPhyNode;
34,629✔
441
      code = createTableCountScanOperatorInfo(pHandle, pTblCountScanNode, pTaskInfo, &pOperator);
34,629✔
442
    } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
12,856,756✔
443
      STagScanPhysiNode* pTagScanPhyNode = (STagScanPhysiNode*)pPhyNode;
8,823,404✔
444
      STableListInfo*    pTableListInfo = tableListCreate();
8,823,404✔
445
      if (!pTableListInfo) {
8,828,593✔
446
        pTaskInfo->code = terrno;
×
447
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
448
        return terrno;
×
449
      }
450

451
      code = initQueriedTableSchemaInfo(pHandle, &pTagScanPhyNode->scan, dbname, pTaskInfo);
8,828,593✔
452
      if (code != TSDB_CODE_SUCCESS) {
8,824,305✔
453
        pTaskInfo->code = code;
×
454
        tableListDestroy(pTableListInfo);
×
455
        return code;
×
456
      }
457

458
      if (!pTagScanPhyNode->onlyMetaCtbIdx) {
8,824,305✔
459
        code = createScanTableListInfo((SScanPhysiNode*)pTagScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond,
3,329,803✔
460
                                       pTagIndexCond, pTaskInfo, NULL);
461
        if (code != TSDB_CODE_SUCCESS) {
3,324,000✔
462
          pTaskInfo->code = code;
×
463
          qError("failed to getTableList, code:%s", tstrerror(code));
×
464
          tableListDestroy(pTableListInfo);
×
465
          return code;
×
466
        }
467
      }
468

469
      if (pTagScanPhyNode->scan.node.dynamicOp) {
8,818,323✔
470
        pTaskInfo->dynamicTask = true;
2,333,136✔
471
        pTableListInfo->idInfo.suid = pTagScanPhyNode->scan.suid;
2,333,801✔
472
        pTableListInfo->idInfo.tableType = pTagScanPhyNode->scan.tableType;
2,335,781✔
473
      }
474

475
      code = createTagScanOperatorInfo(pHandle, pTagScanPhyNode, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo,
8,816,188✔
476
                                       &pOperator);
477
      if (code) {
8,822,336✔
478
        pTaskInfo->code = code;
×
479
        tableListDestroy(pTableListInfo);
×
480
        return code;
×
481
      }
482
    } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) {
4,033,352✔
483
      SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode;
6,284✔
484
      STableListInfo*          pTableListInfo = tableListCreate();
6,284✔
485
      if (!pTableListInfo) {
6,284✔
486
        pTaskInfo->code = terrno;
×
487
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
488
        return terrno;
×
489
      }
490

491
      if (pBlockNode->tableType == TSDB_SUPER_TABLE) {
6,284✔
492
        SArray* pList = taosArrayInit(4, sizeof(uint64_t));
5,353✔
493
        code = pTaskInfo->storageAPI.metaFn.getChildTableList(pHandle->vnode, pBlockNode->uid, pList);
5,353✔
494
        if (code != TSDB_CODE_SUCCESS) {
5,353✔
495
          pTaskInfo->code = code;
×
496
          taosArrayDestroy(pList);
×
497
          tableListDestroy(pTableListInfo);
×
498
          return code;
×
499
        }
500

501
        size_t num = taosArrayGetSize(pList);
5,353✔
502
        for (int32_t i = 0; i < num; ++i) {
11,537✔
503
          uint64_t* id = taosArrayGet(pList, i);
6,184✔
504
          if (id == NULL) {
6,184✔
505
            continue;
×
506
          }
507

508
          code = tableListAddTableInfo(pTableListInfo, *id, 0);
6,184✔
509
          if (code) {
6,184✔
510
            pTaskInfo->code = code;
×
511
            tableListDestroy(pTableListInfo);
×
512
            taosArrayDestroy(pList);
×
513
            return code;
×
514
          }
515
        }
516

517
        taosArrayDestroy(pList);
5,353✔
518
      } else {  // Create group with only one table
519
        code = tableListAddTableInfo(pTableListInfo, pBlockNode->uid, 0);
931✔
520
        if (code) {
931✔
521
          pTaskInfo->code = code;
×
522
          tableListDestroy(pTableListInfo);
×
523
          return code;
×
524
        }
525
      }
526

527
      code = createDataBlockInfoScanOperator(pHandle, pBlockNode, pTableListInfo, pTaskInfo, &pOperator);
6,284✔
528
      if (code) {
6,284✔
529
        pTaskInfo->code = code;
×
530
        tableListDestroy(pTableListInfo);
×
531
        return code;
×
532
      }
533
    } else if (QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN == type) {
4,027,068✔
534
      SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode;
1,963,171✔
535
      STableListInfo*        pTableListInfo = tableListCreate();
1,963,171✔
536
      if (!pTableListInfo) {
1,963,171✔
537
        pTaskInfo->code = terrno;
×
538
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
539
        return terrno;
×
540
      }
541

542
      code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo, pTagCond,
1,963,171✔
543
                                     pTagIndexCond, pTaskInfo, NULL);
544
      if (code != TSDB_CODE_SUCCESS) {
1,963,171✔
545
        pTaskInfo->code = code;
×
546
        tableListDestroy(pTableListInfo);
×
547
        return code;
×
548
      }
549

550
      code = initQueriedTableSchemaInfo(pHandle, &pScanNode->scan, dbname, pTaskInfo);
1,963,171✔
551
      if (code != TSDB_CODE_SUCCESS) {
1,961,226✔
552
        pTaskInfo->code = code;
×
553
        tableListDestroy(pTableListInfo);
×
554
        return code;
×
555
      }
556

557
      code = createCacherowsScanOperator(pScanNode, pHandle, pTableListInfo, pTaskInfo, &pOperator);
1,961,226✔
558
      if (code) {
1,962,685✔
559
        tableListDestroy(pTableListInfo);
×
560
        pTaskInfo->code = code;
×
561
        return code;
×
562
      }
563
    } else if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
2,063,897✔
564
      code = createProjectOperatorInfo(NULL, (SProjectPhysiNode*)pPhyNode, pTaskInfo, &pOperator);
2,038,732✔
565
    } else if (QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN == type) {
25,165✔
566
      // NOTE: this is an patch to fix the physical plan
567
      code = createVirtualTableMergeOperatorInfo(NULL, 0, (SVirtualScanPhysiNode*)pPhyNode, pTaskInfo, &pOperator);
20,794✔
568
    } else {
569
      code = TSDB_CODE_INVALID_PARA;
4,393✔
570
      pTaskInfo->code = code;
4,393✔
571
      return code;
×
572
    }
573

574
    if (pOperator != NULL) {  // todo moved away
456,747,443✔
575
      pOperator->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
457,053,378✔
576
    }
577

578
    *pOptrInfo = pOperator;
456,740,816✔
579
    return code;
457,015,822✔
580
  }
581

582
  size_t          size = LIST_LENGTH(pPhyNode->pChildren);
395,777,400✔
583
  SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES);
395,882,328✔
584
  if (ops == NULL) {
395,817,706✔
585
    code = terrno;
×
586
    pTaskInfo->code = code;
×
587
    return code;
×
588
  }
589

590
  for (int32_t i = 0; i < size; ++i) {
844,455,701✔
591
    SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i);
449,011,136✔
592
    // For external window parent, pre-initialize runtime from subquery before building children
593
    if (QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW == type && i == 0) {
448,989,795✔
594
      // best-effort pre-init; ignore errors here and let later construction handle them
595
      (void)extWinPreInitFromSubquery(pPhyNode, pTaskInfo);
×
596
    }
597
    code = createOperator(pChildNode, pTaskInfo, pHandle, pTagCond, pTagIndexCond, pUser, dbname, &ops[i], model);
448,989,795✔
598
    if (ops[i] == NULL || code != 0) {
448,788,392✔
599
      for (int32_t j = 0; j < i; ++j) {
82,191✔
600
        destroyOperator(ops[j]);
×
601
      }
602
      taosMemoryFree(ops);
82,191✔
603
      return code;
82,191✔
604
    }
605
  }
606

607
  SOperatorInfo* pOptr = NULL;
395,444,565✔
608
  if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
395,450,338✔
609
    code = createProjectOperatorInfo(ops[0], (SProjectPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
159,973,177✔
610
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) {
235,477,161✔
611
    SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode;
136,064,827✔
612
    if (pAggNode->pGroupKeys != NULL) {
136,064,827✔
613
      code = createGroupOperatorInfo(ops[0], pAggNode, pTaskInfo, &pOptr);
34,666,990✔
614
    } else {
615
      code = createAggregateOperatorInfo(ops[0], pAggNode, pTaskInfo, &pOptr);
101,507,309✔
616
    }
617
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) {
99,412,334✔
618
    SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
5,055,069✔
619
    code = createIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo, &pOptr);
5,055,069✔
620
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == type) {
94,357,265✔
621
    SMergeAlignedIntervalPhysiNode* pIntervalPhyNode = (SMergeAlignedIntervalPhysiNode*)pPhyNode;
785,449✔
622
    code = createMergeAlignedIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo, &pOptr);
785,449✔
623
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL == type) {
93,571,816✔
624
    SMergeIntervalPhysiNode* pIntervalPhyNode = (SMergeIntervalPhysiNode*)pPhyNode;
×
625
    code = createMergeIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo, &pOptr);
×
626
  } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) {
93,571,816✔
627
    code = createSortOperatorInfo(ops[0], (SSortPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
37,004,983✔
628
  } else if (QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT == type) {
56,566,833✔
629
    code = createGroupSortOperatorInfo(ops[0], (SGroupSortPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
86,882✔
630
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == type) {
56,479,951✔
631
    SMergePhysiNode* pMergePhyNode = (SMergePhysiNode*)pPhyNode;
15,410,127✔
632
    code = createMultiwayMergeOperatorInfo(ops, size, pMergePhyNode, pTaskInfo, &pOptr);
15,410,127✔
633
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION == type) {
41,069,824✔
634
    SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
637,627✔
635
    code = createSessionAggOperatorInfo(ops[0], pSessionNode, pTaskInfo, &pOptr);
637,627✔
636
  } else if (QUERY_NODE_PHYSICAL_PLAN_PARTITION == type) {
40,432,197✔
637
    code = createPartitionOperatorInfo(ops[0], (SPartitionPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
3,305,046✔
638
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE == type) {
37,127,151✔
639
    SStateWindowPhysiNode* pStateNode = (SStateWindowPhysiNode*)pPhyNode;
1,272,840✔
640
    code = createStatewindowOperatorInfo(ops[0], pStateNode, pTaskInfo, &pOptr);
1,272,840✔
641
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN == type) {
35,854,311✔
642
    code = createMergeJoinOperatorInfo(ops, size, (SSortMergeJoinPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
14,376,547✔
643
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN == type) {
21,477,764✔
644
    code = createHashJoinOperatorInfo(ops, size, (SHashJoinPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
1,354,418✔
645
  } else if (QUERY_NODE_PHYSICAL_PLAN_FILL == type) {
20,123,346✔
646
    code = createFillOperatorInfo(ops[0], (SFillPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
576,857✔
647
  } else if (QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC == type) {
19,546,489✔
648
    code = createIndefinitOutputOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
3,495,019✔
649
  } else if (QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC == type) {
16,051,470✔
650
    code = createTimeSliceOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
3,810,090✔
651
  } else if (QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC == type) {
12,241,380✔
652
    code = createForecastOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
×
653
  } else if (QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC == type) {
12,241,380✔
654
    code = createGenericAnalysisOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
×
655
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT == type) {
12,241,380✔
656
    code = createEventwindowOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
357,893✔
657
  } else if (QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE == type) {
11,883,487✔
658
    code = createGroupCacheOperatorInfo(ops, size, (SGroupCachePhysiNode*)pPhyNode, pTaskInfo, &pOptr);
1,353,522✔
659
  } else if (QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL == type) {
10,529,965✔
660
    code = createDynQueryCtrlOperatorInfo(ops, size, (SDynQueryCtrlPhysiNode*)pPhyNode, pTaskInfo, pHandle->pMsgCb, &pOptr);
3,880,512✔
661
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT == type) {
6,649,453✔
662
    code = createCountwindowOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
292,164✔
663
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY == type) {
6,357,289✔
664
    code = createAnomalywindowOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
×
665
  } else if (QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN == type) {
6,357,289✔
666
    SVirtualScanPhysiNode* pVirtualTableScanNode = (SVirtualScanPhysiNode*)pPhyNode;
4,402,710✔
667
    // NOTE: this is an patch to fix the physical plan
668

669
    if (pVirtualTableScanNode->scan.node.pLimit != NULL) {
4,402,710✔
670
      pVirtualTableScanNode->groupSort = true;
×
671
    }
672
    code = createVirtualTableMergeOperatorInfo(ops, size, (SVirtualScanPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
4,402,710✔
673
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL == type) {
1,954,579✔
674
    if (pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
1,886,146✔
675
      code = createStreamExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
211,062✔
676
    } else {
677
      code = createExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
1,675,532✔
678
    }
679
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL == type) {
71,302✔
680
    if (pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
85,652✔
681
      code = createStreamMergeAlignedExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
22,036✔
682
    } else {
683
      code = createMergeAlignedExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
63,616✔
684
    }
685
  } else {
UNCOV
686
    code = TSDB_CODE_INVALID_PARA;
×
UNCOV
687
    pTaskInfo->code = code;
×
688
    for (int32_t i = 0; i < size; ++i) {
×
689
      destroyOperator(ops[i]);
×
690
    }
691
    taosMemoryFree(ops);
×
692
    qError("invalid operator type %d", type);
×
693
    return code;
×
694
  }
695

696
  taosMemoryFree(ops);
395,628,214✔
697
  if (pOptr) {
395,562,353✔
698
    pOptr->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
395,075,178✔
699
  }
700

701
  *pOptrInfo = pOptr;
395,528,643✔
702
  return code;
395,579,601✔
703
}
704

705
void destroyOperator(SOperatorInfo* pOperator) {
854,120,815✔
706
  if (pOperator == NULL) {
854,120,815✔
707
    return;
523,447✔
708
  }
709

710
  freeResetOperatorParams(pOperator, OP_GET_PARAM, true);
853,597,368✔
711
  freeResetOperatorParams(pOperator, OP_NOTIFY_PARAM, true);
853,516,192✔
712

713
  if (pOperator->pDownstream != NULL) {
853,506,672✔
714
    for (int32_t i = 0; i < pOperator->numOfRealDownstream; ++i) {
843,674,692✔
715
      destroyOperator(pOperator->pDownstream[i]);
448,488,707✔
716
    }
717

718
    taosMemoryFreeClear(pOperator->pDownstream);
395,252,879✔
719
    pOperator->numOfDownstream = 0;
395,224,654✔
720
  }
721

722
  cleanupExprSupp(&pOperator->exprSupp);
853,505,446✔
723

724
  if (pOperator->fpSet.closeFn != NULL && pOperator->info != NULL) {
853,522,162✔
725
    pOperator->fpSet.closeFn(pOperator->info);
853,053,987✔
726
    pOperator->info = NULL;
852,919,850✔
727
  }
728

729
  taosMemoryFreeClear(pOperator);
853,458,301✔
730
}
731

732
void destroyOperatorAndDownstreams(SOperatorInfo* pOperator, SOperatorInfo** downstreams, int32_t num) {
496,417✔
733
  if (downstreams != NULL) {
496,417✔
734
    for (int i = 0; i < num; i++) {
992,834✔
735
      destroyOperator(downstreams[i]);
496,417✔
736
    }
737
  }
738

739
  if (pOperator != NULL) {
496,417✔
740
    pOperator->info = NULL;
496,417✔
741
    if (pOperator->pDownstream != NULL) {
496,417✔
742
      taosMemoryFreeClear(pOperator->pDownstream);
×
743
      pOperator->pDownstream = NULL;
×
744
    }
745
    destroyOperator(pOperator);
496,417✔
746
  }
747
}
496,417✔
748

749
int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInfoList) {
7,984,878✔
750
  SExplainExecInfo  execInfo = {0};
7,984,878✔
751
  SExplainExecInfo* pExplainInfo = taosArrayPush(pExecInfoList, &execInfo);
7,985,605✔
752
  if (pExplainInfo == NULL) {
7,985,605✔
753
    return terrno;
×
754
  }
755

756
  pExplainInfo->numOfRows = operatorInfo->resultInfo.totalRows;
7,985,605✔
757
  pExplainInfo->verboseLen = 0;
7,986,518✔
758
  pExplainInfo->verboseInfo = NULL;
7,986,066✔
759
  pExplainInfo->vgId = operatorInfo->pTaskInfo->id.vgId;
7,985,623✔
760
  pExplainInfo->execCreate = operatorInfo->cost.execCreate;
7,985,478✔
761

762
  /*
763
    For the start, first and last row ts, we need to subtract the execCreate time
764
    to compute the real elapsed time since the operator is created.
765
  */
766
  if (operatorInfo->resultInfo.totalRows > 0) {
7,987,404✔
767
    /*
768
      When there is no data returned, keep execFirstRow and execLastRow as 0.
769
    */
770
    pExplainInfo->execFirstRow = operatorInfo->cost.execFirstRow - operatorInfo->cost.execCreate;
6,739,672✔
771
    pExplainInfo->execLastRow = operatorInfo->cost.execLastRow - operatorInfo->cost.execCreate;
6,737,891✔
772
  }
773

774
  pExplainInfo->execTimes = operatorInfo->cost.execTimes;
7,984,574✔
775
  if (operatorInfo->cost.execTimes > 0) {
7,986,518✔
776
    pExplainInfo->execStart = operatorInfo->cost.execStart - operatorInfo->cost.execCreate;
7,980,460✔
777
    pExplainInfo->execElapsed = operatorInfo->cost.execElapsed;
7,979,095✔
778
    pExplainInfo->inputWaitElapsed = operatorInfo->cost.inputWaitElapsed;
7,982,259✔
779
    pExplainInfo->outputWaitElapsed = operatorInfo->cost.outputWaitElapsed;
7,980,451✔
780
    pExplainInfo->inputRows = operatorInfo->cost.inputRows;
7,979,854✔
781
  }
782

783
  if (operatorInfo->fpSet.getExplainFn) {
7,983,959✔
784
    int32_t code =
785
        operatorInfo->fpSet.getExplainFn(operatorInfo, &pExplainInfo->verboseInfo, &pExplainInfo->verboseLen);
5,319,467✔
786
    if (code) {
5,319,919✔
787
      qError("%s operator getExplainFn failed, code:%s", GET_TASKID(operatorInfo->pTaskInfo), tstrerror(code));
×
788
      return code;
×
789
    }
790
  }
791

792
  int32_t code = 0;
7,986,527✔
793
  for (int32_t i = 0; i < operatorInfo->numOfDownstream; ++i) {
12,503,875✔
794
    code = getOperatorExplainExecInfo(operatorInfo->pDownstream[i], pExecInfoList);
4,516,317✔
795
    if (code != TSDB_CODE_SUCCESS) {
4,517,348✔
796
      //      taosMemoryFreeClear(*pRes);
797
      return code;
×
798
    }
799
  }
800

801
  return TSDB_CODE_SUCCESS;
7,986,075✔
802
}
803

804
int32_t mergeOperatorParams(SOperatorParam* pDst, SOperatorParam* pSrc) {
×
805
  if (pDst->opType != pSrc->opType) {
×
806
    qError("different optype %d:%d for merge operator params", pDst->opType, pSrc->opType);
×
807
    return TSDB_CODE_INVALID_PARA;
×
808
  }
809

810
  switch (pDst->opType) {
×
811
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: {
×
812
      SExchangeOperatorParam* pDExc = pDst->value;
×
813
      SExchangeOperatorParam* pSExc = pSrc->value;
×
814
      if (pSExc->basic.paramType != DYN_TYPE_EXCHANGE_PARAM) {
×
815
        qError("%s, invalid exchange operator param type %d for "
×
816
          "source operator", __func__, pSExc->basic.paramType);
817
        return TSDB_CODE_INVALID_PARA;
×
818
      }
819
      if (!pDExc->multiParams) {
×
820
        if (pDExc->basic.paramType != DYN_TYPE_EXCHANGE_PARAM) {
×
821
          qError("%s, invalid exchange operator param type %d for "
×
822
            "destination operator", __func__, pDExc->basic.paramType);
823
          return TSDB_CODE_INVALID_PARA;
×
824
        }
825
        if (pSExc->basic.vgId != pDExc->basic.vgId) {
×
826
          SExchangeOperatorBatchParam* pBatch = taosMemoryMalloc(sizeof(SExchangeOperatorBatchParam));
×
827
          if (NULL == pBatch) {
×
828
            return terrno;
×
829
          }
830

831
          pBatch->multiParams = true;
×
832
          pBatch->pBatchs = tSimpleHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT));
×
833
          if (NULL == pBatch->pBatchs) {
×
834
            taosMemoryFree(pBatch);
×
835
            return terrno;
×
836
          }
837

838
          tSimpleHashSetFreeFp(pBatch->pBatchs, freeExchangeGetBasicOperatorParam);
×
839

840
          int32_t code = tSimpleHashPut(pBatch->pBatchs, &pDExc->basic.vgId, sizeof(pDExc->basic.vgId), &pDExc->basic,
×
841
                                        sizeof(pDExc->basic));
842
          if (code) {
×
843
            return code;
×
844
          }
845

846
          code = tSimpleHashPut(pBatch->pBatchs, &pSExc->basic.vgId, sizeof(pSExc->basic.vgId), &pSExc->basic,
×
847
                                sizeof(pSExc->basic));
848
          if (code) {
×
849
            return code;
×
850
          }
851

852
          taosMemoryFree(pDst->value);
×
853
          pDst->value = pBatch;
×
854
        } else {
855
          void* p = taosArrayAddAll(pDExc->basic.uidList, pSExc->basic.uidList);
×
856
          if (p == NULL) {
×
857
            return terrno;
×
858
          }
859
        }
860
      } else {
861
        SExchangeOperatorBatchParam* pBatch = pDst->value;
×
862
        SExchangeOperatorBasicParam* pBasic =
863
            tSimpleHashGet(pBatch->pBatchs, &pSExc->basic.vgId, sizeof(pSExc->basic.vgId));
×
864
        if (pBasic) {
×
865
          void* p = taosArrayAddAll(pBasic->uidList, pSExc->basic.uidList);
×
866
          if (p == NULL) {
×
867
            return terrno;
×
868
          }
869
        } else {
870
          int32_t code = tSimpleHashPut(pBatch->pBatchs, &pSExc->basic.vgId, sizeof(pSExc->basic.vgId), &pSExc->basic,
×
871
                                        sizeof(pSExc->basic));
872
          if (code) {
×
873
            return code;
×
874
          }
875
        }
876
      }
877
      break;
×
878
    }
879
    default:
×
880
      qError("invalid optype %d for merge operator params", pDst->opType);
×
881
      return TSDB_CODE_INVALID_PARA;
×
882
  }
883

884
  return TSDB_CODE_SUCCESS;
×
885
}
886

887
int32_t setOperatorParams(struct SOperatorInfo* pOperator, SOperatorParam* pInput, SOperatorParamType type) {
118,075,413✔
888
  SOperatorParam**  ppParam = NULL;
118,075,413✔
889
  SOperatorParam*** pppDownstramParam = NULL;
118,075,413✔
890
  switch (type) {
118,075,413✔
891
    case OP_GET_PARAM:
118,074,475✔
892
      ppParam = &pOperator->pOperatorGetParam;
118,074,475✔
893
      pppDownstramParam = &pOperator->pDownstreamGetParams;
118,076,049✔
894
      break;
118,076,727✔
895
    case OP_NOTIFY_PARAM:
×
896
      ppParam = &pOperator->pOperatorNotifyParam;
×
897
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
×
898
      break;
×
899
    default:
938✔
900
      return TSDB_CODE_INVALID_PARA;
938✔
901
  }
902

903
  freeResetOperatorParams(pOperator, type, false);
118,076,727✔
904

905
  if (NULL == pInput) {
118,077,436✔
906
    return TSDB_CODE_SUCCESS;
×
907
  }
908

909
  *ppParam = (pInput->opType == pOperator->operatorType) ? pInput : NULL;
118,077,436✔
910

911
  if (NULL == *pppDownstramParam) {
118,078,803✔
912
    *pppDownstramParam = taosMemoryCalloc(pOperator->numOfDownstream, POINTER_BYTES);
20,670,576✔
913
    if (NULL == *pppDownstramParam) {
20,671,232✔
914
      return terrno;
×
915
    }
916
  }
917

918
  if (NULL == *ppParam) {
118,078,134✔
919
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
×
920
      (*pppDownstramParam)[i] = pInput;
×
921
    }
922
    return TSDB_CODE_SUCCESS;
×
923
  }
924

925
  memset(*pppDownstramParam, 0, pOperator->numOfDownstream * POINTER_BYTES);
118,078,072✔
926

927
  int32_t childrenNum = taosArrayGetSize((*ppParam)->pChildren);
118,078,072✔
928
  if (childrenNum <= 0) {
118,078,178✔
929
    return TSDB_CODE_SUCCESS;
109,226,421✔
930
  }
931

932
  for (int32_t i = 0; i < childrenNum; ++i) {
22,793,809✔
933
    SOperatorParam* pChild = *(SOperatorParam**)taosArrayGet((*ppParam)->pChildren, i);
13,940,685✔
934
    if (pChild == NULL) {
13,941,374✔
935
      return terrno;
×
936
    }
937

938
    if ((*pppDownstramParam)[pChild->downstreamIdx]) {
13,941,374✔
939
      int32_t code = mergeOperatorParams((*pppDownstramParam)[pChild->downstreamIdx], pChild);
×
940
      if (code) {
×
941
        return code;
×
942
      }
943
    } else {
944
      (*pppDownstramParam)[pChild->downstreamIdx] = pChild;
13,939,318✔
945
    }
946
  }
947

948
  taosArrayDestroy((*ppParam)->pChildren);
8,853,124✔
949
  (*ppParam)->pChildren = NULL;
8,849,690✔
950

951
  return TSDB_CODE_SUCCESS;
8,850,379✔
952
}
953

954
SSDataBlock* getNextBlockFromDownstream(struct SOperatorInfo* pOperator, int32_t idx) {
1,110,871,213✔
955
  recordOpExecBeforeDownstream(pOperator);
1,110,871,213✔
956
  SSDataBlock* p = NULL;
1,110,710,602✔
957
  int32_t      code = getNextBlockFromDownstreamImpl(pOperator, idx, true, &p);
1,110,834,265✔
958
  if (code == TSDB_CODE_SUCCESS) {
1,107,684,484✔
959
    code = blockDataCheck(p);
1,107,723,901✔
960
    if (code != TSDB_CODE_SUCCESS) {
1,107,922,210✔
961
      qError("%s, %s failed at line %d, code:%s", GET_TASKID(pOperator->pTaskInfo),
×
962
             __func__, __LINE__, tstrerror(code));
963
    }
964
  }
965
  recordOpExecAfterDownstream(pOperator, p && code == TSDB_CODE_SUCCESS ? p->info.rows : 0);
1,107,787,450✔
966
  return (code == TSDB_CODE_SUCCESS) ? p : NULL;
1,107,784,631✔
967
}
968

969
SSDataBlock* getNextBlockFromDownstreamRemain(struct SOperatorInfo* pOperator, int32_t idx) {
80,613,714✔
970
  recordOpExecBeforeDownstream(pOperator);
80,613,714✔
971
  SSDataBlock* p = NULL;
80,614,157✔
972
  int32_t      code = getNextBlockFromDownstreamImpl(pOperator, idx, false, &p);
80,614,157✔
973
  if (code == TSDB_CODE_SUCCESS) {
80,600,960✔
974
    code = blockDataCheck(p);
80,600,960✔
975
    if (code != TSDB_CODE_SUCCESS) {
80,601,388✔
976
      qError("%s, %s failed at line %d, code:%s", GET_TASKID(pOperator->pTaskInfo),
×
977
             __func__, __LINE__, tstrerror(code));
978
    }
979
  }
980
  recordOpExecAfterDownstream(pOperator, p && code == TSDB_CODE_SUCCESS ? p->info.rows : 0);
80,600,832✔
981
  return (code == TSDB_CODE_SUCCESS) ? p : NULL;
80,601,412✔
982
}
983

984
/*
985
 * Fetch one block from downstream without preserving reused get-param ownership.
986
 *
987
 * @param pOperator Current operator.
988
 * @param idx Downstream index.
989
 * @param pResBlock Output result block pointer.
990
 *
991
 * @return TSDB_CODE_SUCCESS on success, otherwise error code.
992
 */
993
static FORCE_INLINE int32_t getNextBlockFromDownstreamRemainDetachImpl(struct SOperatorInfo* pOperator, int32_t idx,
994
                                                                       SSDataBlock** pResBlock) {
995
  QRY_PARAM_CHECK(pResBlock);
638,667,344✔
996

997
  int32_t code = TSDB_CODE_SUCCESS;
638,685,537✔
998
  int32_t lino = 0;
638,685,537✔
999

1000
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
642,790,406✔
1001
    SOperatorParam* pGetParam = pOperator->pDownstreamGetParams[idx];
4,111,622✔
1002
    pOperator->pDownstreamGetParams[idx] = NULL;
4,110,944✔
1003
    // Once detached from the parent operator, downstream must own/free this param.
1004
    pGetParam->reUse = false;
4,109,555✔
1005

1006
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
4,110,944✔
1007
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx], pGetParam, pResBlock);
4,110,944✔
1008
    QUERY_CHECK_CODE(code, lino, _return);
4,104,869✔
1009
  } else {
1010
    code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
634,614,869✔
1011
    QUERY_CHECK_CODE(code, lino, _return);
632,607,422✔
1012
  }
1013

1014
_return:
632,607,422✔
1015
  if (code) {
636,712,291✔
1016
    qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, lino, tstrerror(code));
×
1017
  }
1018
  return code;
636,698,437✔
1019
}
1020

1021
/*
1022
 * Fetch and validate one downstream block while detaching one-shot get-param.
1023
 *
1024
 * @param pOperator Current operator.
1025
 * @param idx Downstream index.
1026
 *
1027
 * @return Valid block pointer on success, or NULL on failure.
1028
 */
1029
SSDataBlock* getNextBlockFromDownstreamRemainDetach(struct SOperatorInfo* pOperator, int32_t idx) {
638,709,671✔
1030
  SSDataBlock* p = NULL;
638,709,671✔
1031
  int32_t      code = TSDB_CODE_SUCCESS;
638,749,920✔
1032
  int32_t      lino = 0;
638,749,920✔
1033
  recordOpExecBeforeDownstream(pOperator);
638,749,920✔
1034

1035
  code = getNextBlockFromDownstreamRemainDetachImpl(pOperator, idx, &p);
636,698,437✔
1036
  QUERY_CHECK_CODE(code, lino, _return);
636,698,437✔
1037

1038
  code = blockDataCheck(p);
636,698,437✔
1039
  QUERY_CHECK_CODE(code, lino, _return);
636,732,032✔
1040

1041
_return:
636,732,032✔
1042
  recordOpExecAfterDownstream(pOperator, p && code == TSDB_CODE_SUCCESS ? p->info.rows : 0);
636,758,500✔
1043
  if (code) {
636,718,649✔
1044
    qError("failed to get next data block from downstream at %s, line:%d code:%s", __func__, lino, tstrerror(code));
467✔
1045
    return NULL;
×
1046
  }
1047
  return p;
636,721,432✔
1048
}
1049

1050
int32_t optrDefaultGetNextExtFn(struct SOperatorInfo* pOperator, SOperatorParam* pParam, SSDataBlock** pRes) {
118,079,450✔
1051
  QRY_PARAM_CHECK(pRes);
118,079,450✔
1052

1053
  int32_t lino = 0;
118,080,128✔
1054
  int32_t code = setOperatorParams(pOperator, pParam, OP_GET_PARAM);
118,080,128✔
1055
  QUERY_CHECK_CODE(code, lino, _end);
118,077,436✔
1056
  code = pOperator->fpSet.getNextFn(pOperator, pRes);
118,077,436✔
1057
  QUERY_CHECK_CODE(code, lino, _end);
118,059,695✔
1058

1059
_end:
118,059,695✔
1060
  if (code != TSDB_CODE_SUCCESS) {
118,059,695✔
1061
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1062
    pOperator->pTaskInfo->code = code;
×
1063
    T_LONG_JMP(pOperator->pTaskInfo->env, code);
×
1064
  }
1065

1066
  return code;
118,059,695✔
1067
}
1068

1069
int32_t optrDefaultNotifyFn(struct SOperatorInfo* pOperator, SOperatorParam* pParam) {
×
1070
  int32_t code = setOperatorParams(pOperator, pParam, OP_NOTIFY_PARAM);
×
1071
  if (TSDB_CODE_SUCCESS == code && pOperator->fpSet.notifyFn && pOperator->pOperatorNotifyParam) {
×
1072
    code = pOperator->fpSet.notifyFn(pOperator, pOperator->pOperatorNotifyParam);
×
1073
  }
1074
  if (TSDB_CODE_SUCCESS == code) {
×
1075
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
×
1076
      if (pOperator->pDownstreamNotifyParams[i]) {
×
1077
        code = optrDefaultNotifyFn(pOperator->pDownstream[i], pOperator->pDownstreamNotifyParams[i]);
×
1078
        if (TSDB_CODE_SUCCESS != code) {
×
1079
          break;
×
1080
        }
1081
        pOperator->pDownstreamNotifyParams[i] = NULL;
×
1082
      }
1083
    }
1084
  }
1085
  if (TSDB_CODE_SUCCESS != code) {
×
1086
    pOperator->pTaskInfo->code = code;
×
1087
    T_LONG_JMP(pOperator->pTaskInfo->env, pOperator->pTaskInfo->code);
×
1088
  }
1089

1090
  return code;
×
1091
}
1092

1093
int64_t getOperatorResultBlockId(struct SOperatorInfo* pOperator, int32_t idx) {
32,446,772✔
1094
  if (pOperator->transparent) {
32,446,772✔
1095
    return getOperatorResultBlockId(pOperator->pDownstream[idx], 0);
2,707,044✔
1096
  }
1097
  return pOperator->resultDataBlockId;
29,740,727✔
1098
}
1099

1100
void resetOperatorState(SOperatorInfo *pOper) {
×
1101
  pOper->status = OP_NOT_OPENED;
×
1102
}
×
1103

1104
void resetBasicOperatorState(SOptrBasicInfo *pBasicInfo) {
20,325,573✔
1105
  if (pBasicInfo->pRes) blockDataCleanup(pBasicInfo->pRes);
20,325,573✔
1106
  initResultRowInfo(&pBasicInfo->resultRowInfo);
20,326,944✔
1107
}
20,326,681✔
1108

1109
int32_t resetAggSup(SExprSupp* pExprSupp, SAggSupporter* pSup, SExecTaskInfo* pTaskInfo,
17,444,345✔
1110
                    SNodeList* pNodeList, SNodeList* pGroupKeys, size_t keyBufSize, const char* pKey, void* pState,
1111
                    SFunctionStateStore* pStore) {
1112
  int32_t    code = 0, lino = 0, num = 0;
17,444,345✔
1113
  SExprInfo* pExprInfo = NULL;
17,444,345✔
1114
  cleanupExprSuppWithoutFilter(pExprSupp);
17,444,613✔
1115
  cleanupAggSup(pSup);
17,444,706✔
1116
  code = createExprInfo(pNodeList, pGroupKeys, &pExprInfo, &num);
17,445,373✔
1117
  QUERY_CHECK_CODE(code, lino, _error);
17,445,074✔
1118
  code = initAggSup(pExprSupp, pSup, pExprInfo, num, keyBufSize, pKey, pState, pStore);
17,445,074✔
1119
  QUERY_CHECK_CODE(code, lino, _error);
17,444,047✔
1120
  return code;
17,444,047✔
1121
_error:
×
1122
  if (code != TSDB_CODE_SUCCESS) {
×
1123
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1124
    pTaskInfo->code = code;
×
1125
  }
1126
  return code;
×
1127
}
1128

1129
int32_t resetExprSupp(SExprSupp* pExprSupp, SExecTaskInfo* pTaskInfo, SNodeList* pNodeList,
7,155,282✔
1130
                      SNodeList* pGroupKeys, SFunctionStateStore* pStore) {
1131
  int32_t code = 0, lino = 0, num = 0;
7,155,282✔
1132
  SExprInfo* pExprInfo = NULL;
7,155,282✔
1133
  cleanupExprSuppWithoutFilter(pExprSupp);
7,155,282✔
1134
  code = createExprInfo(pNodeList, pGroupKeys, &pExprInfo, &num);
7,155,014✔
1135
  QUERY_CHECK_CODE(code, lino, _error);
7,153,934✔
1136
  code = initExprSupp(pExprSupp, pExprInfo, num, pStore);
7,153,934✔
1137
  QUERY_CHECK_CODE(code, lino, _error);
7,154,746✔
1138
  return code;
7,154,746✔
1139
_error:
×
1140
  if (code != TSDB_CODE_SUCCESS) {
×
1141
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1142
    pTaskInfo->code = code;
×
1143
  }
1144
  return code;
×
1145
}
1146

1147
int32_t copyColumnsValue(SNodeList* pNodeList, int64_t targetBlkId, SSDataBlock* pDst, SSDataBlock* pSrc, int32_t totalRows) {
1,679,195✔
1148
  bool    isNull = (NULL == pSrc || pSrc->info.rows <= 0);
1,679,195✔
1149
  size_t  numOfCols = LIST_LENGTH(pNodeList);
1,679,195✔
1150
  int64_t numOfRows = isNull ? 0 : pSrc->info.rows;
1,679,195✔
1151
  int32_t code = 0;
1,679,195✔
1152
  int32_t lino = 0;
1,679,195✔
1153

1154
  for (int32_t i = 0; i < numOfCols; ++i) {
11,318,142✔
1155
    STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i);
9,638,947✔
1156
    if (nodeType(pNode->pExpr) == QUERY_NODE_COLUMN && ((SColumnNode*)pNode->pExpr)->dataBlockId == targetBlkId) {
9,638,947✔
1157
      SColumnInfoData* pDstCol = taosArrayGet(pDst->pDataBlock, pNode->slotId);
5,114,026✔
1158
      QUERY_CHECK_NULL(pDstCol, code, lino, _return, terrno)
5,114,026✔
1159

1160
      if (isNull) {
5,114,026✔
1161
        colDataSetNNULL(pDstCol, 0, totalRows);
×
1162
      } else {
1163
        SColumnInfoData* pSrcCol = taosArrayGet(pSrc->pDataBlock, ((SColumnNode*)pNode->pExpr)->slotId);
5,114,026✔
1164
        QUERY_CHECK_NULL(pSrcCol, code, lino, _return, terrno)
5,114,026✔
1165

1166
        code = colDataAssign(pDstCol, pSrcCol, pSrc->info.rows, &pDst->info);
5,114,026✔
1167

1168
        QUERY_CHECK_CODE(code, lino, _return);
5,114,026✔
1169
        if (pSrc->info.rows < totalRows) {
5,114,026✔
1170
          colDataSetNNULL(pDstCol, pSrc->info.rows, totalRows - pSrc->info.rows);
86,082✔
1171
        }
1172
      }
1173
    }
1174
  }
1175

1176
  return code;
1,679,195✔
1177
_return:
×
1178
  qError("failed to copy columns value, line:%d code:%s", lino, tstrerror(code));
×
1179
  return code;
×
1180
}
1181

1182
/**
1183
  @brief Record the create time of the operator and do initialization
1184
  to other metrics. This function will be called at the beginning of
1185
  creation of operators.
1186
*/
1187
void initOperatorCostInfo(SOperatorInfo* pOperator) {
853,407,882✔
1188
  pOperator->cost.execCreate = taosGetTimestampUs();
853,495,737✔
1189
  resetOperatorCostInfo(pOperator);
853,495,479✔
1190
}
853,370,552✔
1191

1192
/**
1193
  @brief Record the performance metrics at the beginning of the
1194
  operator execution:
1195
  - record the start time of the operator execution
1196
  - calculate the output wait time (time since last call returned)
1197
  - record the first time nextFn interface is called
1198
  Only record the metrics in explain analyze mode.
1199
*/
1200
void recordOpExecBegin(SOperatorInfo* pOperator) {
2,147,483,647✔
1201
  if (QUERY_ENABLE_EXPLAIN(pOperator->pTaskInfo)) {
2,147,483,647✔
1202
    pOperator->cost.startTs = taosGetTimestampUs();
22,080,407✔
1203
    // calculate output wait time (time since last call returned)
1204
    if (pOperator->cost.execLastRow > 0) {
22,079,060✔
1205
      pOperator->cost.outputWaitElapsed +=
28,016,582✔
1206
        pOperator->cost.startTs - pOperator->cost.execLastRow;
14,009,773✔
1207
    }
1208
    // record the first time nextFn is called
1209
    if (pOperator->cost.execStart == 0) {
22,079,076✔
1210
      pOperator->cost.execStart = pOperator->cost.startTs;
8,048,370✔
1211
    }
1212
  }
1213
}
2,147,483,647✔
1214

1215
/**
1216
  @brief Record the performance metrics before the downstream execution:
1217
  - record the elapsed time since the operator execution started
1218
  - update the start time of the operator execution
1219
  Only record the metrics in explain analyze mode.
1220
*/
1221
void recordOpExecBeforeDownstream(SOperatorInfo* pOperator) {
2,147,483,647✔
1222
  if (QUERY_ENABLE_EXPLAIN(pOperator->pTaskInfo)) {
2,147,483,647✔
1223
    pOperator->cost.endTs = taosGetTimestampUs();
12,463,745✔
1224
    if (UNLIKELY(pOperator->cost.startTs == 0)) {
12,463,159✔
1225
      /**
1226
        As long as getNextBlockFromDownstream() is called inside getNextFn(),
1227
        startTs must be initialized before endTs so that this condition should
1228
        always be false.
1229
      */
1230
      pOperator->cost.startTs = pOperator->cost.endTs;
×
1231
    }
1232
    pOperator->cost.execElapsed +=
24,920,069✔
1233
      pOperator->cost.endTs - pOperator->cost.startTs;
12,459,159✔
1234
  }
1235
}
2,147,483,647✔
1236

1237
/**
1238
  @brief Record the performance metrics after the downstream execution:
1239
  - record the elapsed time since the downstream execution started
1240
  - update the end time of the downstream execution
1241
  Only record the metrics in explain analyze mode.
1242
*/
1243
void recordOpExecAfterDownstream(SOperatorInfo* pOperator, size_t inputRows) {
2,147,483,647✔
1244
  if (QUERY_ENABLE_EXPLAIN(pOperator->pTaskInfo)) {
2,147,483,647✔
1245
    pOperator->cost.startTs = taosGetTimestampUs();
12,459,049✔
1246
    pOperator->cost.inputWaitElapsed +=
24,918,061✔
1247
      pOperator->cost.startTs - pOperator->cost.endTs;
12,457,421✔
1248
    pOperator->cost.inputRows += inputRows;
12,458,883✔
1249
  }
1250
}
2,147,483,647✔
1251

1252
/**
1253
  @brief Record the performance metrics at the end of the
1254
  operator execution:
1255
  - record the number of times the operator's next interface is called
1256
  - record the elapsed time for executing the operator's nextFn interface
1257
  - record the time when the first row is returned
1258
  - record the time when the last row is returned
1259
  Only record the metrics in explain analyze mode.
1260
*/
1261
void recordOpExecEnd(SOperatorInfo* pOperator, size_t rows) {
2,147,483,647✔
1262
  if (QUERY_ENABLE_EXPLAIN(pOperator->pTaskInfo)) {
2,147,483,647✔
1263
    pOperator->cost.endTs = taosGetTimestampUs();
22,064,948✔
1264
    pOperator->cost.execTimes++;
22,062,298✔
1265
    pOperator->cost.execElapsed +=
44,127,107✔
1266
      pOperator->cost.endTs - pOperator->cost.startTs;
22,064,955✔
1267

1268
    if (rows > 0) {
22,062,600✔
1269
      // record the first time data is returned
1270
      if (pOperator->cost.execFirstRow == 0) {
14,049,553✔
1271
        pOperator->cost.execFirstRow = pOperator->cost.endTs;
6,782,056✔
1272
      }
1273
      pOperator->cost.execLastRow = pOperator->cost.endTs;
14,051,412✔
1274
    }
1275
  }
1276
  
1277
  /* accumulate output total rows even not in explain mode */
1278
  pOperator->resultInfo.totalRows += rows;
2,147,483,647✔
1279
}
2,147,483,647✔
1280

1281
/**
1282
  @brief Reset operator's cost info but keep create time unchanged.
1283
*/
1284
void resetOperatorCostInfo(SOperatorInfo* pOperator) {
894,756,345✔
1285
  /* keep execCreate UNCHANGED!!! */
1286
  pOperator->cost.execStart = 0;
894,756,345✔
1287
  pOperator->cost.execFirstRow = 0;
894,843,869✔
1288
  pOperator->cost.execLastRow = 0;
894,787,261✔
1289
  pOperator->cost.execTimes = 0;
894,836,067✔
1290
  pOperator->cost.execElapsed = 0;
894,806,970✔
1291
  pOperator->cost.inputWaitElapsed = 0;
894,739,494✔
1292
  pOperator->cost.outputWaitElapsed = 0;
894,776,022✔
1293
  pOperator->cost.inputRows = 0;
894,878,108✔
1294
}
894,815,715✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc