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

taosdata / TDengine / #5034

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

push

travis-ci

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

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

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

14149 existing lines in 164 files now uncovered.

275896 of 377640 relevant lines covered (73.06%)

132944440.29 hits per line

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

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,
811,597,888✔
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,
811,597,888✔
44
      .cleanupFn = cleanup,
45
      .closeFn = closeFn,
46
      .reqBufFn = reqBufFn,
47
      .getExplainFn = explain,
48
      ._nextExtFn = nextExtFn,
49
      .getNextExtFn = (nextExtFn != NULL) ? optrGetNextExtFnWithExecRecord : NULL,
811,597,888✔
50
      .notifyFn = notifyFn,
51
      .releaseStreamStateFn = NULL,
52
      .reloadStreamStateFn = NULL,
53
      ._resetFn = NULL,
54
      .resetStateFn = NULL,
55
  };
56

57
  return fpSet;
811,597,888✔
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,
120,587,683✔
73
                                              SOperatorParam* pParam,
74
                                              SSDataBlock** pResBlock) {
75
  QRY_PARAM_CHECK(pResBlock);
120,587,683✔
76

77
  recordOpExecBegin(pOperator);
120,587,683✔
78
  int32_t code = pOperator->fpSet._nextExtFn(pOperator, pParam, pResBlock);
120,587,072✔
79
  size_t  rows = (TSDB_CODE_SUCCESS == code && *pResBlock != NULL) ?
120,568,997✔
80
                 (*pResBlock)->info.rows : 0;
241,137,176✔
81
  recordOpExecEnd(pOperator, rows);
120,569,224✔
82
  return code;
120,568,580✔
83
}
84

85
static int32_t optrResetStateFnWithExecRecord(SOperatorInfo* pOperator) {
34,286,507✔
86
  int32_t code = pOperator->fpSet._resetFn(pOperator);
34,286,507✔
87
  resetOperatorCostInfo(pOperator);
34,284,847✔
88
  return code;
34,285,449✔
89
}
90

91
void setOperatorStreamStateFn(SOperatorInfo* pOperator, __optr_state_fn_t relaseFn, __optr_state_fn_t reloadFn) {
152,844,253✔
92
  pOperator->fpSet.releaseStreamStateFn = relaseFn;
152,844,253✔
93
  pOperator->fpSet.reloadStreamStateFn = reloadFn;
152,839,631✔
94
}
152,830,561✔
95

96
void setOperatorResetStateFn(SOperatorInfo* pOperator, __optr_reset_state_fn_t resetFn) {
809,399,718✔
97
  pOperator->fpSet._resetFn = resetFn;
809,399,718✔
98
  pOperator->fpSet.resetStateFn = (resetFn != NULL) ? optrResetStateFnWithExecRecord : NULL;
809,295,611✔
99
}
809,442,175✔
100

101
int32_t optrDummyOpenFn(SOperatorInfo* pOperator) {
76,626,549✔
102
  OPTR_SET_OPENED(pOperator);
76,626,549✔
103
  return TSDB_CODE_SUCCESS;
76,602,781✔
104
}
105

106
int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num) {
375,244,438✔
107
  p->pDownstream = taosMemoryCalloc(1, num * POINTER_BYTES);
375,244,438✔
108
  if (p->pDownstream == NULL) {
375,241,842✔
109
    return terrno;
×
110
  }
111

112
  memcpy(p->pDownstream, pDownstream, num * POINTER_BYTES);
375,040,261✔
113
  p->numOfDownstream = num;
375,281,361✔
114
  p->numOfRealDownstream = num;
375,203,257✔
115
  return TSDB_CODE_SUCCESS;
375,265,383✔
116
}
117

118
void setOperatorCompleted(SOperatorInfo* pOperator) {
919,029,398✔
119
  pOperator->status = OP_EXEC_DONE;
919,029,398✔
120
  setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
919,050,785✔
121
}
919,030,632✔
122

123
void setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status,
811,546,776✔
124
                     void* pInfo, SExecTaskInfo* pTaskInfo) {
125
  pOperator->name = (char*)name;
811,546,776✔
126
  pOperator->operatorType = type;
811,630,037✔
127
  pOperator->blocking = blocking;
811,385,479✔
128
  pOperator->status = status;
811,492,740✔
129
  pOperator->info = pInfo;
811,530,132✔
130
  pOperator->pTaskInfo = pTaskInfo;
811,636,035✔
131
}
811,616,465✔
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) {
359,417,345✔
158
  if (pOperator == NULL) {
359,417,345✔
UNCOV
159
    return;
×
160
  }
161

162
  ERetType ret = fn(pOperator, pParam, id);
359,417,345✔
163
  if (ret == OPTR_FN_RET_ABORT || pParam->code != TSDB_CODE_SUCCESS) {
359,413,639✔
164
    return;
183,864,495✔
165
  }
166

167
  for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
351,131,333✔
168
    traverseOperatorTree(pOperator->pDownstream[i], fn, pParam, id);
175,569,909✔
169
    if (pParam->code != 0) {
175,549,693✔
170
      break;
×
171
    }
172
  }
173
}
174

175
ERetType extractOperatorInfo(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdStr) {
359,275,098✔
176
  STraverParam* p = pParam;
359,275,098✔
177
  if (pOperator->operatorType == *(int32_t*)p->pParam) {
359,275,098✔
178
    p->pRet = pOperator;
183,795,434✔
179
    return OPTR_FN_RET_ABORT;
183,796,983✔
180
  } else {
181
    return OPTR_FN_RET_CONTINUE;
175,502,430✔
182
  }
183
}
184

185
// QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
186
int32_t extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id, SOperatorInfo** pOptrInfo) {
183,774,949✔
187
  QRY_PARAM_CHECK(pOptrInfo);
183,774,949✔
188

189
  if (pOperator == NULL) {
183,793,772✔
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};
183,793,772✔
195
  traverseOperatorTree(pOperator, extractOperatorInfo, &p, id);
183,792,095✔
196
  if (p.code == 0) {
183,788,424✔
197
    *pOptrInfo = p.pRet;
183,793,531✔
198
  }
199
  return p.code;
183,792,726✔
200
}
201

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

UNCOV
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 ||
×
UNCOV
213
      type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN ||
×
UNCOV
214
      type == QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN) {
×
215
    pInfo->order = TSDB_ORDER_ASC;
×
UNCOV
216
    pInfo->scanFlag = MAIN_SCAN;
×
UNCOV
217
    return OPTR_FN_RET_ABORT;
×
UNCOV
218
  } else if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE) {
×
UNCOV
219
    if (!pInfo->inheritUsOrder) {
×
UNCOV
220
      pInfo->order = TSDB_ORDER_ASC;
×
221
    }
UNCOV
222
    pInfo->scanFlag = MAIN_SCAN;
×
UNCOV
223
    return OPTR_FN_RET_ABORT;
×
UNCOV
224
  } else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
×
UNCOV
225
    STableScanInfo* pTableScanInfo = pOperator->info;
×
UNCOV
226
    pInfo->order = pTableScanInfo->base.cond.order;
×
UNCOV
227
    pInfo->scanFlag = pTableScanInfo->base.scanFlag;
×
228
    return OPTR_FN_RET_ABORT;
×
UNCOV
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 {
UNCOV
235
    return OPTR_FN_RET_CONTINUE;
×
236
  }
237
}
238

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

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

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

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

261
    if (pInfo->base.dataReader != NULL) {
74,571✔
262
      pAPI->tsdReader.tsdReaderNotifyClosing(pInfo->base.dataReader);
74,571✔
263
    }
264
    return OPTR_FN_RET_ABORT;
74,571✔
265
  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
60,960✔
UNCOV
266
    STmqQueryScanInfo* pInfo = pOperator->info;
×
267

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

UNCOV
275
    return OPTR_FN_RET_ABORT;
×
276
  }
277

278
  return OPTR_FN_RET_CONTINUE;
60,960✔
279
}
280

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

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

292
  int32_t     code = 0;
811,813,591✔
293
  int32_t     type = nodeType(pPhyNode);
811,813,591✔
294
  const char* idstr = GET_TASKID(pTaskInfo);
811,825,906✔
295

296
  if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
811,822,365✔
297
    SOperatorInfo* pOperator = NULL;
435,994,487✔
298
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
435,917,101✔
299
      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
256,495,360✔
300
      // NOTE: this is an patch to fix the physical plan
301
      // TODO remove it later
302
      if (pTableScanNode->scan.node.pLimit != NULL) {
256,495,360✔
303
        pTableScanNode->groupSort = true;
5,182,933✔
304
      }
305

306
      STableListInfo* pTableListInfo = tableListCreate();
256,508,737✔
307
      if (!pTableListInfo) {
256,530,950✔
UNCOV
308
        pTaskInfo->code = terrno;
×
UNCOV
309
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
UNCOV
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) {
256,530,950✔
316
        code = initQueriedTableSchemaInfo(pHandle, &pTableScanNode->scan, dbname, pTaskInfo);
247,548,249✔
317
        if (code) {
247,410,374✔
UNCOV
318
          pTaskInfo->code = code;
×
UNCOV
319
          tableListDestroy(pTableListInfo);
×
UNCOV
320
          return code;
×
321
        }
322
      }
323

324
      if (pTableScanNode->scan.node.dynamicOp) {
256,391,725✔
325
        pTaskInfo->dynamicTask = true;
14,898,976✔
326
        pTableListInfo->idInfo.suid = pTableScanNode->scan.suid;
14,900,163✔
327
        pTableListInfo->idInfo.tableType = pTableScanNode->scan.tableType;
14,896,779✔
328
      } else {
329
        code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
241,502,235✔
330
                                       pHandle, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo, NULL);
331
        if (code) {
241,622,434✔
332
          pTaskInfo->code = code;
1,008✔
333
          tableListDestroy(pTableListInfo);
1,008✔
334
          qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
1,008✔
335
          return code;
1,008✔
336
        }
337
      }
338

339
      code = createTableScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo, &pOperator);
256,520,333✔
340
      if (NULL == pOperator || code != 0) {
256,451,984✔
341
        pTaskInfo->code = code;
124,557✔
342
        tableListDestroy(pTableListInfo);
24,590✔
343
        return code;
24,590✔
344
      }
345

346
      STableScanInfo* pScanInfo = pOperator->info;
256,327,427✔
347
      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
256,414,901✔
348
    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
179,421,741✔
349
      STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
28,563,366✔
350
      STableListInfo*           pTableListInfo = tableListCreate();
28,563,366✔
351
      if (!pTableListInfo) {
28,582,303✔
UNCOV
352
        pTaskInfo->code = terrno;
×
UNCOV
353
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
UNCOV
354
        return terrno;
×
355
      }
356

357
      if (pTableScanNode->scan.node.dynamicOp) {
28,582,303✔
358
        pTaskInfo->dynamicTask = true;
174,768✔
359
        pTableListInfo->idInfo.suid = pTableScanNode->scan.suid;
174,768✔
360
        pTableListInfo->idInfo.tableType = pTableScanNode->scan.tableType;
174,153✔
361
      } else {
362
        code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, true, pHandle, pTableListInfo,
28,407,535✔
363
                                       pTagCond, pTagIndexCond, pTaskInfo, NULL);
364
        if (code) {
28,404,954✔
UNCOV
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,404,954✔
372
        if (code) {
28,368,824✔
UNCOV
373
          pTaskInfo->code = code;
×
UNCOV
374
          tableListDestroy(pTableListInfo);
×
375
          return code;
×
376
        }
377
      }
378

379
      code = createTableMergeScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo, &pOperator);
28,543,592✔
380
      if (NULL == pOperator || code != 0) {
28,530,112✔
381
        pTaskInfo->code = code;
35,977✔
UNCOV
382
        tableListDestroy(pTableListInfo);
×
UNCOV
383
        return code;
×
384
      }
385

386
      STableMergeScanInfo* pScanInfo = pOperator->info;
28,494,135✔
387
      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
28,489,247✔
388
    } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) {
150,858,375✔
389
      code = createExchangeOperatorInfo(pHandle ? pHandle->pMsgCb->clientRpc : NULL, (SExchangePhysiNode*)pPhyNode,
115,127,145✔
390
                                        pTaskInfo, &pOperator);
391
    } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
35,731,230✔
392
      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
364,769✔
393
      STableListInfo*      pTableListInfo = tableListCreate();
364,769✔
394
      if (!pTableListInfo) {
364,769✔
UNCOV
395
        pTaskInfo->code = terrno;
×
UNCOV
396
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
UNCOV
397
        return terrno;
×
398
      }
399

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

411
      code = createTmqScanOperatorInfo(pHandle, pTableScanNode, pTagCond, pTableListInfo, pTaskInfo, &pOperator);
364,769✔
412
      if (code) {
364,769✔
UNCOV
413
        pTaskInfo->code = code;
×
UNCOV
414
        tableListDestroy(pTableListInfo);
×
415
        return code;
×
416
      }
417
    } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
35,366,461✔
418
      SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
23,506,319✔
419
      if (pSysScanPhyNode->scan.virtualStableScan) {
23,506,319✔
420
        STableListInfo*           pTableListInfo = tableListCreate();
11,525,697✔
421
        if (!pTableListInfo) {
11,531,054✔
UNCOV
422
          pTaskInfo->code = terrno;
×
UNCOV
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,
11,531,054✔
428
                                       pTagIndexCond, pTaskInfo, NULL);
429
        if (code != TSDB_CODE_SUCCESS) {
11,526,850✔
UNCOV
430
          pTaskInfo->code = code;
×
UNCOV
431
          tableListDestroy(pTableListInfo);
×
UNCOV
432
          return code;
×
433
        }
434

435
        code = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pTableListInfo, pUser, pTaskInfo, &pOperator);
11,526,850✔
436
      } else {
437
        code = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, NULL, pUser, pTaskInfo, &pOperator);
11,985,747✔
438
      }
439
    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN == type) {
11,860,142✔
440
      STableCountScanPhysiNode* pTblCountScanNode = (STableCountScanPhysiNode*)pPhyNode;
32,184✔
441
      code = createTableCountScanOperatorInfo(pHandle, pTblCountScanNode, pTaskInfo, &pOperator);
32,184✔
442
    } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
11,827,958✔
443
      STagScanPhysiNode* pTagScanPhyNode = (STagScanPhysiNode*)pPhyNode;
8,310,092✔
444
      STableListInfo*    pTableListInfo = tableListCreate();
8,310,092✔
445
      if (!pTableListInfo) {
8,311,272✔
UNCOV
446
        pTaskInfo->code = terrno;
×
UNCOV
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,311,272✔
452
      if (code != TSDB_CODE_SUCCESS) {
8,305,773✔
UNCOV
453
        pTaskInfo->code = code;
×
UNCOV
454
        tableListDestroy(pTableListInfo);
×
UNCOV
455
        return code;
×
456
      }
457

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

469
      if (pTagScanPhyNode->scan.node.dynamicOp) {
8,303,619✔
470
        pTaskInfo->dynamicTask = true;
2,197,147✔
471
        pTableListInfo->idInfo.suid = pTagScanPhyNode->scan.suid;
2,197,693✔
472
        pTableListInfo->idInfo.tableType = pTagScanPhyNode->scan.tableType;
2,196,596✔
473
      }
474

475
      code = createTagScanOperatorInfo(pHandle, pTagScanPhyNode, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo,
8,306,611✔
476
                                       &pOperator);
477
      if (code) {
8,309,153✔
UNCOV
478
        pTaskInfo->code = code;
×
UNCOV
479
        tableListDestroy(pTableListInfo);
×
UNCOV
480
        return code;
×
481
      }
482
    } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) {
3,517,866✔
483
      SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode;
5,761✔
484
      STableListInfo*          pTableListInfo = tableListCreate();
5,761✔
485
      if (!pTableListInfo) {
5,761✔
UNCOV
486
        pTaskInfo->code = terrno;
×
UNCOV
487
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
UNCOV
488
        return terrno;
×
489
      }
490

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

501
        size_t num = taosArrayGetSize(pList);
4,906✔
502
        for (int32_t i = 0; i < num; ++i) {
10,550✔
503
          uint64_t* id = taosArrayGet(pList, i);
5,644✔
504
          if (id == NULL) {
5,644✔
UNCOV
505
            continue;
×
506
          }
507

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

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

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

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

550
      code = initQueriedTableSchemaInfo(pHandle, &pScanNode->scan, dbname, pTaskInfo);
1,548,070✔
551
      if (code != TSDB_CODE_SUCCESS) {
1,547,614✔
UNCOV
552
        pTaskInfo->code = code;
×
UNCOV
553
        tableListDestroy(pTableListInfo);
×
UNCOV
554
        return code;
×
555
      }
556

557
      code = createCacherowsScanOperator(pScanNode, pHandle, pTableListInfo, pTaskInfo, &pOperator);
1,547,614✔
558
      if (code) {
1,548,070✔
UNCOV
559
        tableListDestroy(pTableListInfo);
×
UNCOV
560
        pTaskInfo->code = code;
×
UNCOV
561
        return code;
×
562
      }
563
    } else if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
1,964,035✔
564
      code = createProjectOperatorInfo(NULL, (SProjectPhysiNode*)pPhyNode, pTaskInfo, &pOperator);
1,943,830✔
565
    } else if (QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN == type) {
20,205✔
566
      // NOTE: this is an patch to fix the physical plan
567
      code = createVirtualTableMergeOperatorInfo(NULL, 0, (SVirtualScanPhysiNode*)pPhyNode, pTaskInfo, &pOperator);
19,725✔
568
    } else {
569
      code = TSDB_CODE_INVALID_PARA;
520✔
570
      pTaskInfo->code = code;
520✔
UNCOV
571
      return code;
×
572
    }
573

574
    if (pOperator != NULL) {  // todo moved away
435,555,917✔
575
      pOperator->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
435,833,690✔
576
    }
577

578
    *pOptrInfo = pOperator;
435,500,578✔
579
    return code;
435,744,708✔
580
  }
581

582
  size_t          size = LIST_LENGTH(pPhyNode->pChildren);
375,831,923✔
583
  SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES);
375,869,926✔
584
  if (ops == NULL) {
375,847,368✔
UNCOV
585
    code = terrno;
×
586
    pTaskInfo->code = code;
×
587
    return code;
×
588
  }
589

590
  for (int32_t i = 0; i < size; ++i) {
802,895,242✔
591
    SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i);
427,334,001✔
592
    // For external window parent, pre-initialize runtime from subquery before building children
593
    if (QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW == type && i == 0) {
427,292,501✔
594
      // best-effort pre-init; ignore errors here and let later construction handle them
UNCOV
595
      (void)extWinPreInitFromSubquery(pPhyNode, pTaskInfo);
×
596
    }
597
    code = createOperator(pChildNode, pTaskInfo, pHandle, pTagCond, pTagIndexCond, pUser, dbname, &ops[i], model);
427,292,501✔
598
    if (ops[i] == NULL || code != 0) {
427,265,073✔
599
      for (int32_t j = 0; j < i; ++j) {
77,120✔
UNCOV
600
        destroyOperator(ops[j]);
×
601
      }
602
      taosMemoryFree(ops);
77,120✔
603
      return code;
77,120✔
604
    }
605
  }
606

607
  SOperatorInfo* pOptr = NULL;
375,561,241✔
608
  if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
375,572,015✔
609
    code = createProjectOperatorInfo(ops[0], (SProjectPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
151,048,273✔
610
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) {
224,523,742✔
611
    SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode;
131,171,690✔
612
    if (pAggNode->pGroupKeys != NULL) {
131,171,690✔
613
      code = createGroupOperatorInfo(ops[0], pAggNode, pTaskInfo, &pOptr);
33,149,218✔
614
    } else {
615
      code = createAggregateOperatorInfo(ops[0], pAggNode, pTaskInfo, &pOptr);
98,025,436✔
616
    }
617
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) {
93,352,052✔
618
    SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
5,116,586✔
619
    code = createIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo, &pOptr);
5,116,586✔
620
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == type) {
88,235,466✔
621
    SMergeAlignedIntervalPhysiNode* pIntervalPhyNode = (SMergeAlignedIntervalPhysiNode*)pPhyNode;
839,478✔
622
    code = createMergeAlignedIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo, &pOptr);
839,478✔
623
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL == type) {
87,395,988✔
UNCOV
624
    SMergeIntervalPhysiNode* pIntervalPhyNode = (SMergeIntervalPhysiNode*)pPhyNode;
×
UNCOV
625
    code = createMergeIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo, &pOptr);
×
626
  } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) {
87,395,988✔
627
    code = createSortOperatorInfo(ops[0], (SSortPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
34,534,909✔
628
  } else if (QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT == type) {
52,861,079✔
629
    code = createGroupSortOperatorInfo(ops[0], (SGroupSortPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
82,074✔
630
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == type) {
52,779,005✔
631
    SMergePhysiNode* pMergePhyNode = (SMergePhysiNode*)pPhyNode;
14,560,572✔
632
    code = createMultiwayMergeOperatorInfo(ops, size, pMergePhyNode, pTaskInfo, &pOptr);
14,560,572✔
633
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION == type) {
38,218,433✔
634
    SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
600,146✔
635
    code = createSessionAggOperatorInfo(ops[0], pSessionNode, pTaskInfo, &pOptr);
600,146✔
636
  } else if (QUERY_NODE_PHYSICAL_PLAN_PARTITION == type) {
37,618,287✔
637
    code = createPartitionOperatorInfo(ops[0], (SPartitionPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
3,112,810✔
638
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE == type) {
34,505,477✔
639
    SStateWindowPhysiNode* pStateNode = (SStateWindowPhysiNode*)pPhyNode;
1,033,340✔
640
    code = createStatewindowOperatorInfo(ops[0], pStateNode, pTaskInfo, &pOptr);
1,033,340✔
641
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN == type) {
33,472,137✔
642
    code = createMergeJoinOperatorInfo(ops, size, (SSortMergeJoinPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
13,499,060✔
643
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN == type) {
19,973,077✔
644
    code = createHashJoinOperatorInfo(ops, size, (SHashJoinPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
1,277,668✔
645
  } else if (QUERY_NODE_PHYSICAL_PLAN_FILL == type) {
18,695,409✔
646
    code = createFillOperatorInfo(ops[0], (SFillPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
600,318✔
647
  } else if (QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC == type) {
18,095,091✔
648
    code = createIndefinitOutputOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
3,288,169✔
649
  } else if (QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC == type) {
14,806,922✔
650
    code = createTimeSliceOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
3,619,238✔
651
  } else if (QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC == type) {
11,187,684✔
UNCOV
652
    code = createForecastOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
×
653
  } else if (QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC == type) {
11,187,684✔
654
    code = createGenericAnalysisOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
×
655
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT == type) {
11,187,684✔
656
    code = createEventwindowOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
339,671✔
657
  } else if (QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE == type) {
10,848,013✔
658
    code = createGroupCacheOperatorInfo(ops, size, (SGroupCachePhysiNode*)pPhyNode, pTaskInfo, &pOptr);
1,276,850✔
659
  } else if (QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL == type) {
9,571,163✔
660
    code = createDynQueryCtrlOperatorInfo(ops, size, (SDynQueryCtrlPhysiNode*)pPhyNode, pTaskInfo, pHandle->pMsgCb, &pOptr);
3,563,068✔
661
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT == type) {
6,008,095✔
662
    code = createCountwindowOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
276,803✔
663
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY == type) {
5,731,292✔
UNCOV
664
    code = createAnomalywindowOperatorInfo(ops[0], pPhyNode, pTaskInfo, &pOptr);
×
665
  } else if (QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN == type) {
5,731,292✔
666
    SVirtualScanPhysiNode* pVirtualTableScanNode = (SVirtualScanPhysiNode*)pPhyNode;
4,061,874✔
667
    // NOTE: this is an patch to fix the physical plan
668

669
    if (pVirtualTableScanNode->scan.node.pLimit != NULL) {
4,061,874✔
UNCOV
670
      pVirtualTableScanNode->groupSort = true;
×
671
    }
672
    code = createVirtualTableMergeOperatorInfo(ops, size, (SVirtualScanPhysiNode*)pPhyNode, pTaskInfo, &pOptr);
4,061,874✔
673
  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL == type) {
1,669,418✔
674
    if (pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
1,594,627✔
675
      code = createStreamExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
174,391✔
676
    } else {
677
      code = createExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
1,420,648✔
678
    }
679
  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL == type) {
75,214✔
680
    if (pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
74,788✔
681
      code = createStreamMergeAlignedExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
20,816✔
682
    } else {
683
      code = createMergeAlignedExternalWindowOperator(ops[0], pPhyNode, pTaskInfo, &pOptr);
53,972✔
684
    }
685
  } else {
686
    code = TSDB_CODE_INVALID_PARA;
426✔
687
    pTaskInfo->code = code;
426✔
UNCOV
688
    for (int32_t i = 0; i < size; ++i) {
×
UNCOV
689
      destroyOperator(ops[i]);
×
690
    }
UNCOV
691
    taosMemoryFree(ops);
×
UNCOV
692
    qError("invalid operator type %d", type);
×
UNCOV
693
    return code;
×
694
  }
695

696
  taosMemoryFree(ops);
375,722,786✔
697
  if (pOptr) {
375,664,555✔
698
    pOptr->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
375,264,205✔
699
  }
700

701
  *pOptrInfo = pOptr;
375,598,841✔
702
  return code;
375,672,449✔
703
}
704

705
void destroyOperator(SOperatorInfo* pOperator) {
812,756,780✔
706
  if (pOperator == NULL) {
812,756,780✔
707
    return;
488,450✔
708
  }
709

710
  freeResetOperatorParams(pOperator, OP_GET_PARAM, true);
812,268,330✔
711
  freeResetOperatorParams(pOperator, OP_NOTIFY_PARAM, true);
812,230,631✔
712

713
  if (pOperator->pDownstream != NULL) {
812,223,246✔
714
    for (int32_t i = 0; i < pOperator->numOfRealDownstream; ++i) {
802,110,905✔
715
      destroyOperator(pOperator->pDownstream[i]);
426,823,735✔
716
    }
717

718
    taosMemoryFreeClear(pOperator->pDownstream);
375,327,560✔
719
    pOperator->numOfDownstream = 0;
375,314,477✔
720
  }
721

722
  cleanupExprSupp(&pOperator->exprSupp);
812,218,859✔
723

724
  if (pOperator->fpSet.closeFn != NULL && pOperator->info != NULL) {
812,231,874✔
725
    pOperator->fpSet.closeFn(pOperator->info);
811,759,611✔
726
    pOperator->info = NULL;
811,648,856✔
727
  }
728

729
  taosMemoryFreeClear(pOperator);
812,168,971✔
730
}
731

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

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

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

756
  pExplainInfo->numOfRows = operatorInfo->resultInfo.totalRows;
7,445,575✔
757
  pExplainInfo->verboseLen = 0;
7,445,575✔
758
  pExplainInfo->verboseInfo = NULL;
7,445,166✔
759
  pExplainInfo->vgId = operatorInfo->pTaskInfo->id.vgId;
7,443,089✔
760
  pExplainInfo->execCreate = operatorInfo->cost.execCreate;
7,445,992✔
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,443,097✔
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,290,054✔
771
    pExplainInfo->execLastRow = operatorInfo->cost.execLastRow - operatorInfo->cost.execCreate;
6,288,394✔
772
  }
773

774
  pExplainInfo->execTimes = operatorInfo->cost.execTimes;
7,443,915✔
775
  if (operatorInfo->cost.execTimes > 0) {
7,445,992✔
776
    pExplainInfo->execStart = operatorInfo->cost.execStart - operatorInfo->cost.execCreate;
7,440,337✔
777
    pExplainInfo->execElapsed = operatorInfo->cost.execElapsed;
7,441,989✔
778
    pExplainInfo->inputWaitElapsed = operatorInfo->cost.inputWaitElapsed;
7,440,337✔
779
    pExplainInfo->outputWaitElapsed = operatorInfo->cost.outputWaitElapsed;
7,440,746✔
780
    pExplainInfo->inputRows = operatorInfo->cost.inputRows;
7,439,920✔
781
  }
782

783
  if (operatorInfo->fpSet.getExplainFn) {
7,444,340✔
784
    int32_t code =
785
        operatorInfo->fpSet.getExplainFn(operatorInfo, &pExplainInfo->verboseInfo, &pExplainInfo->verboseLen);
4,943,417✔
786
    if (code) {
4,944,660✔
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,445,575✔
793
  for (int32_t i = 0; i < operatorInfo->numOfDownstream; ++i) {
11,655,780✔
794
    code = getOperatorExplainExecInfo(operatorInfo->pDownstream[i], pExecInfoList);
4,210,205✔
795
    if (code != TSDB_CODE_SUCCESS) {
4,210,205✔
796
      //      taosMemoryFreeClear(*pRes);
797
      return code;
×
798
    }
799
  }
800

801
  return TSDB_CODE_SUCCESS;
7,445,575✔
802
}
803

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

810
  switch (pDst->opType) {
×
811
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: {
×
UNCOV
812
      SExchangeOperatorParam* pDExc = pDst->value;
×
UNCOV
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) {
×
UNCOV
820
        if (pDExc->basic.paramType != DYN_TYPE_EXCHANGE_PARAM) {
×
UNCOV
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

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

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

UNCOV
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));
UNCOV
848
          if (code) {
×
UNCOV
849
            return code;
×
850
          }
851

UNCOV
852
          taosMemoryFree(pDst->value);
×
UNCOV
853
          pDst->value = pBatch;
×
854
        } else {
UNCOV
855
          void* p = taosArrayAddAll(pDExc->basic.uidList, pSExc->basic.uidList);
×
UNCOV
856
          if (p == NULL) {
×
857
            return terrno;
×
858
          }
859
        }
860
      } else {
861
        SExchangeOperatorBatchParam* pBatch = pDst->value;
×
862
        SExchangeOperatorBasicParam* pBasic =
UNCOV
863
            tSimpleHashGet(pBatch->pBatchs, &pSExc->basic.vgId, sizeof(pSExc->basic.vgId));
×
UNCOV
864
        if (pBasic) {
×
UNCOV
865
          void* p = taosArrayAddAll(pBasic->uidList, pSExc->basic.uidList);
×
UNCOV
866
          if (p == NULL) {
×
UNCOV
867
            return terrno;
×
868
          }
869
        } else {
UNCOV
870
          int32_t code = tSimpleHashPut(pBatch->pBatchs, &pSExc->basic.vgId, sizeof(pSExc->basic.vgId), &pSExc->basic,
×
871
                                        sizeof(pSExc->basic));
UNCOV
872
          if (code) {
×
UNCOV
873
            return code;
×
874
          }
875
        }
876
      }
UNCOV
877
      break;
×
878
    }
UNCOV
879
    default:
×
UNCOV
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) {
108,385,910✔
888
  SOperatorParam**  ppParam = NULL;
108,385,910✔
889
  SOperatorParam*** pppDownstramParam = NULL;
108,385,910✔
890
  switch (type) {
108,385,910✔
891
    case OP_GET_PARAM:
108,385,910✔
892
      ppParam = &pOperator->pOperatorGetParam;
108,385,910✔
893
      pppDownstramParam = &pOperator->pDownstreamGetParams;
108,385,910✔
894
      break;
108,387,821✔
UNCOV
895
    case OP_NOTIFY_PARAM:
×
UNCOV
896
      ppParam = &pOperator->pOperatorNotifyParam;
×
897
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
×
UNCOV
898
      break;
×
UNCOV
899
    default:
×
UNCOV
900
      return TSDB_CODE_INVALID_PARA;
×
901
  }
902

903
  freeResetOperatorParams(pOperator, type, false);
108,387,821✔
904

905
  if (NULL == pInput) {
108,390,979✔
UNCOV
906
    return TSDB_CODE_SUCCESS;
×
907
  }
908

909
  *ppParam = (pInput->opType == pOperator->operatorType) ? pInput : NULL;
108,390,979✔
910

911
  if (NULL == *pppDownstramParam) {
108,391,594✔
912
    *pppDownstramParam = taosMemoryCalloc(pOperator->numOfDownstream, POINTER_BYTES);
18,750,801✔
913
    if (NULL == *pppDownstramParam) {
18,750,801✔
UNCOV
914
      return terrno;
×
915
    }
916
  }
917

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

925
  memset(*pppDownstramParam, 0, pOperator->numOfDownstream * POINTER_BYTES);
108,390,950✔
926

927
  int32_t childrenNum = taosArrayGetSize((*ppParam)->pChildren);
108,390,290✔
928
  if (childrenNum <= 0) {
108,389,675✔
929
    return TSDB_CODE_SUCCESS;
100,225,091✔
930
  }
931

932
  for (int32_t i = 0; i < childrenNum; ++i) {
21,039,439✔
933
    SOperatorParam* pChild = *(SOperatorParam**)taosArrayGet((*ppParam)->pChildren, i);
12,875,507✔
934
    if (pChild == NULL) {
12,874,847✔
UNCOV
935
      return terrno;
×
936
    }
937

938
    if ((*pppDownstramParam)[pChild->downstreamIdx]) {
12,874,847✔
UNCOV
939
      int32_t code = mergeOperatorParams((*pppDownstramParam)[pChild->downstreamIdx], pChild);
×
UNCOV
940
      if (code) {
×
UNCOV
941
        return code;
×
942
      }
943
    } else {
944
      (*pppDownstramParam)[pChild->downstreamIdx] = pChild;
12,875,499✔
945
    }
946
  }
947

948
  taosArrayDestroy((*ppParam)->pChildren);
8,163,932✔
949
  (*ppParam)->pChildren = NULL;
8,165,244✔
950

951
  return TSDB_CODE_SUCCESS;
8,165,888✔
952
}
953

954
SSDataBlock* getNextBlockFromDownstream(struct SOperatorInfo* pOperator, int32_t idx) {
1,097,564,699✔
955
  recordOpExecBeforeDownstream(pOperator);
1,097,564,699✔
956
  SSDataBlock* p = NULL;
1,097,481,525✔
957
  int32_t      code = getNextBlockFromDownstreamImpl(pOperator, idx, true, &p);
1,097,498,259✔
958
  if (code == TSDB_CODE_SUCCESS) {
1,094,887,573✔
959
    code = blockDataCheck(p);
1,094,897,076✔
960
    if (code != TSDB_CODE_SUCCESS) {
1,095,039,761✔
UNCOV
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,094,978,673✔
966
  return (code == TSDB_CODE_SUCCESS) ? p : NULL;
1,094,993,880✔
967
}
968

969
SSDataBlock* getNextBlockFromDownstreamRemain(struct SOperatorInfo* pOperator, int32_t idx) {
74,300,705✔
970
  recordOpExecBeforeDownstream(pOperator);
74,300,705✔
971
  SSDataBlock* p = NULL;
74,301,753✔
972
  int32_t      code = getNextBlockFromDownstreamImpl(pOperator, idx, false, &p);
74,301,753✔
973
  if (code == TSDB_CODE_SUCCESS) {
74,290,827✔
974
    code = blockDataCheck(p);
74,290,827✔
975
    if (code != TSDB_CODE_SUCCESS) {
74,291,351✔
UNCOV
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);
74,290,827✔
981
  return (code == TSDB_CODE_SUCCESS) ? p : NULL;
74,291,351✔
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);
591,631,638✔
996

997
  int32_t code = TSDB_CODE_SUCCESS;
591,605,922✔
998
  int32_t lino = 0;
591,605,922✔
999

1000
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
595,368,162✔
1001
    SOperatorParam* pGetParam = pOperator->pDownstreamGetParams[idx];
3,767,352✔
1002
    pOperator->pDownstreamGetParams[idx] = NULL;
3,766,704✔
1003
    // Once detached from the parent operator, downstream must own/free this param.
1004
    pGetParam->reUse = false;
3,767,352✔
1005

1006
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
3,768,640✔
1007
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx], pGetParam, pResBlock);
3,768,640✔
1008
    QUERY_CHECK_CODE(code, lino, _return);
3,762,240✔
1009
  } else {
1010
    code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
587,936,167✔
1011
    QUERY_CHECK_CODE(code, lino, _return);
586,294,940✔
1012
  }
1013

1014
_return:
586,294,940✔
1015
  if (code) {
590,057,180✔
UNCOV
1016
    qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, lino, tstrerror(code));
×
1017
  }
1018
  return code;
590,048,427✔
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) {
591,669,151✔
1030
  SSDataBlock* p = NULL;
591,669,151✔
1031
  int32_t      code = TSDB_CODE_SUCCESS;
591,693,483✔
1032
  int32_t      lino = 0;
591,693,483✔
1033
  recordOpExecBeforeDownstream(pOperator);
591,693,483✔
1034

1035
  code = getNextBlockFromDownstreamRemainDetachImpl(pOperator, idx, &p);
590,048,427✔
1036
  QUERY_CHECK_CODE(code, lino, _return);
590,048,427✔
1037

1038
  code = blockDataCheck(p);
590,048,427✔
1039
  QUERY_CHECK_CODE(code, lino, _return);
590,094,677✔
1040

1041
_return:
590,094,677✔
1042
  recordOpExecAfterDownstream(pOperator, p && code == TSDB_CODE_SUCCESS ? p->info.rows : 0);
590,103,675✔
1043
  if (code) {
590,089,325✔
1044
    qError("failed to get next data block from downstream at %s, line:%d code:%s", __func__, lino, tstrerror(code));
14,126✔
UNCOV
1045
    return NULL;
×
1046
  }
1047
  return p;
590,075,435✔
1048
}
1049

1050
int32_t optrDefaultGetNextExtFn(struct SOperatorInfo* pOperator, SOperatorParam* pParam, SSDataBlock** pRes) {
108,390,954✔
1051
  QRY_PARAM_CHECK(pRes);
108,390,954✔
1052

1053
  int32_t lino = 0;
108,390,945✔
1054
  int32_t code = setOperatorParams(pOperator, pParam, OP_GET_PARAM);
108,390,945✔
1055
  QUERY_CHECK_CODE(code, lino, _end);
108,388,453✔
1056
  code = pOperator->fpSet.getNextFn(pOperator, pRes);
108,388,453✔
1057
  QUERY_CHECK_CODE(code, lino, _end);
108,370,806✔
1058

1059
_end:
108,370,806✔
1060
  if (code != TSDB_CODE_SUCCESS) {
108,370,806✔
UNCOV
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;
108,370,806✔
1067
}
1068

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

UNCOV
1090
  return code;
×
1091
}
1092

1093
int64_t getOperatorResultBlockId(struct SOperatorInfo* pOperator, int32_t idx) {
30,376,230✔
1094
  if (pOperator->transparent) {
30,376,230✔
1095
    return getOperatorResultBlockId(pOperator->pDownstream[idx], 0);
2,553,700✔
1096
  }
1097
  return pOperator->resultDataBlockId;
27,822,530✔
1098
}
1099

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

1104
void resetBasicOperatorState(SOptrBasicInfo *pBasicInfo) {
16,805,342✔
1105
  if (pBasicInfo->pRes) blockDataCleanup(pBasicInfo->pRes);
16,805,342✔
1106
  initResultRowInfo(&pBasicInfo->resultRowInfo);
16,806,849✔
1107
}
16,807,111✔
1108

1109
int32_t resetAggSup(SExprSupp* pExprSupp, SAggSupporter* pSup, SExecTaskInfo* pTaskInfo,
14,634,898✔
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;
14,634,898✔
1113
  SExprInfo* pExprInfo = NULL;
14,634,898✔
1114
  cleanupExprSuppWithoutFilter(pExprSupp);
14,634,898✔
1115
  cleanupAggSup(pSup);
14,632,114✔
1116
  code = createExprInfo(pNodeList, pGroupKeys, &pExprInfo, &num);
14,633,901✔
1117
  QUERY_CHECK_CODE(code, lino, _error);
14,633,332✔
1118
  code = initAggSup(pExprSupp, pSup, pExprInfo, num, keyBufSize, pKey, pState, pStore);
14,633,332✔
1119
  QUERY_CHECK_CODE(code, lino, _error);
14,632,864✔
1120
  return code;
14,632,864✔
UNCOV
1121
_error:
×
UNCOV
1122
  if (code != TSDB_CODE_SUCCESS) {
×
1123
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
UNCOV
1124
    pTaskInfo->code = code;
×
1125
  }
UNCOV
1126
  return code;
×
1127
}
1128

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

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

1154
  for (int32_t i = 0; i < numOfCols; ++i) {
9,660,990✔
1155
    STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i);
8,243,522✔
1156
    if (nodeType(pNode->pExpr) == QUERY_NODE_COLUMN && ((SColumnNode*)pNode->pExpr)->dataBlockId == targetBlkId) {
8,243,522✔
1157
      SColumnInfoData* pDstCol = taosArrayGet(pDst->pDataBlock, pNode->slotId);
4,385,963✔
1158
      QUERY_CHECK_NULL(pDstCol, code, lino, _return, terrno)
4,385,963✔
1159

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

1166
        code = colDataAssign(pDstCol, pSrcCol, pSrc->info.rows, &pDst->info);
4,385,963✔
1167

1168
        QUERY_CHECK_CODE(code, lino, _return);
4,385,963✔
1169
        if (pSrc->info.rows < totalRows) {
4,385,963✔
1170
          colDataSetNNULL(pDstCol, pSrc->info.rows, totalRows - pSrc->info.rows);
83,175✔
1171
        }
1172
      }
1173
    }
1174
  }
1175

1176
  return code;
1,417,468✔
UNCOV
1177
_return:
×
UNCOV
1178
  qError("failed to copy columns value, line:%d code:%s", lino, tstrerror(code));
×
UNCOV
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) {
812,167,997✔
1188
  pOperator->cost.execCreate = taosGetTimestampUs();
812,217,257✔
1189
  resetOperatorCostInfo(pOperator);
812,224,099✔
1190
}
812,198,088✔
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();
20,638,890✔
1203
    // calculate output wait time (time since last call returned)
1204
    if (pOperator->cost.execLastRow > 0) {
20,640,955✔
1205
      pOperator->cost.outputWaitElapsed +=
26,227,359✔
1206
        pOperator->cost.startTs - pOperator->cost.execLastRow;
13,113,201✔
1207
    }
1208
    // record the first time nextFn is called
1209
    if (pOperator->cost.execStart == 0) {
20,635,266✔
1210
      pOperator->cost.execStart = pOperator->cost.startTs;
7,505,011✔
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,094,979,107✔
1222
  if (QUERY_ENABLE_EXPLAIN(pOperator->pTaskInfo)) {
2,094,979,107✔
1223
    pOperator->cost.endTs = taosGetTimestampUs();
11,662,753✔
1224
    if (UNLIKELY(pOperator->cost.startTs == 0)) {
11,662,753✔
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
      */
UNCOV
1230
      pOperator->cost.startTs = pOperator->cost.endTs;
×
1231
    }
1232
    pOperator->cost.execElapsed +=
23,320,824✔
1233
      pOperator->cost.endTs - pOperator->cost.startTs;
11,661,649✔
1234
  }
1235
}
2,095,122,270✔
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,090,778,638✔
1244
  if (QUERY_ENABLE_EXPLAIN(pOperator->pTaskInfo)) {
2,090,778,638✔
1245
    pOperator->cost.startTs = taosGetTimestampUs();
11,661,085✔
1246
    pOperator->cost.inputWaitElapsed +=
23,321,615✔
1247
      pOperator->cost.startTs - pOperator->cost.endTs;
11,659,981✔
1248
    pOperator->cost.inputRows += inputRows;
11,661,082✔
1249
  }
1250
}
2,090,961,858✔
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();
20,622,143✔
1264
    pOperator->cost.execTimes++;
20,623,799✔
1265
    pOperator->cost.execElapsed +=
41,246,378✔
1266
      pOperator->cost.endTs - pOperator->cost.startTs;
20,621,591✔
1267

1268
    if (rows > 0) {
20,623,247✔
1269
      // record the first time data is returned
1270
      if (pOperator->cost.execFirstRow == 0) {
13,155,114✔
1271
        pOperator->cost.execFirstRow = pOperator->cost.endTs;
6,330,685✔
1272
      }
1273
      pOperator->cost.execLastRow = pOperator->cost.endTs;
13,155,114✔
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) {
846,484,001✔
1285
  /* keep execCreate UNCHANGED!!! */
1286
  pOperator->cost.execStart = 0;
846,484,001✔
1287
  pOperator->cost.execFirstRow = 0;
846,529,592✔
1288
  pOperator->cost.execLastRow = 0;
846,517,286✔
1289
  pOperator->cost.execTimes = 0;
846,468,687✔
1290
  pOperator->cost.execElapsed = 0;
846,491,275✔
1291
  pOperator->cost.inputWaitElapsed = 0;
846,507,960✔
1292
  pOperator->cost.outputWaitElapsed = 0;
846,499,560✔
1293
  pOperator->cost.inputRows = 0;
846,418,207✔
1294
}
846,502,255✔
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