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

taosdata / TDengine / #5028

20 Apr 2026 09:07AM UTC coverage: 72.986% (-0.01%) from 72.996%
#5028

push

travis-ci

web-flow
perf: optimize compact progress query from O(m*n) to O(n+m) (#35115)

104 of 141 new or added lines in 4 files covered. (73.76%)

5170 existing lines in 133 files now uncovered.

273777 of 375111 relevant lines covered (72.99%)

130458474.51 hits per line

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

77.55
/source/libs/executor/src/executorInt.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 "filter.h"
17
#include "function.h"
18
#include "functionMgt.h"
19
#include "../../function/inc/functionResInfoInt.h"
20
#include "os.h"
21
#include "querynodes.h"
22
#include "tfill.h"
23
#include "tname.h"
24

25
#include "tdatablock.h"
26
#include "tmsg.h"
27
#include "ttime.h"
28

29
#include "executorInt.h"
30
#include "index.h"
31
#include "operator.h"
32
#include "query.h"
33
#include "querytask.h"
34
#include "storageapi.h"
35
#include "tcompare.h"
36
#include "thash.h"
37
#include "ttypes.h"
38

39
#define SET_REVERSE_SCAN_FLAG(runtime)    ((runtime)->scanFlag = REVERSE_SCAN)
40
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) != TSDB_ORDER_DESC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
41

42
#if 0
43
static UNUSED_FUNC void *u_malloc (size_t __size) {
44
  uint32_t v = taosRand();
45

46
  if (v % 1000 <= 0) {
47
    return NULL;
48
  } else {
49
    return taosMemoryMalloc(__size);
50
  }
51
}
52

53
static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) {
54
  uint32_t v = taosRand();
55
  if (v % 1000 <= 0) {
56
    return NULL;
57
  } else {
58
    return taosMemoryCalloc(num, __size);
59
  }
60
}
61

62
static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
63
  uint32_t v = taosRand();
64
  if (v % 5 <= 1) {
65
    return NULL;
66
  } else {
67
    return taosMemoryRealloc(p, __size);
68
  }
69
}
70

71
#define calloc  u_calloc
72
#define malloc  u_malloc
73
#define realloc u_realloc
74
#endif
75

76
static int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExpr, SSDataBlock* pBlock);
77

78
static int32_t initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size);
79
static void    doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag);
80

81
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
82
                                   bool createDummyCol);
83

84
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
2,147,483,647✔
85
  SFilePage* pData = NULL;
2,147,483,647✔
86

87
  // in the first scan, new space needed for results
88
  int32_t pageId = -1;
2,147,483,647✔
89
  if (*currentPageId == -1) {
2,147,483,647✔
90
    pData = getNewBufPage(pResultBuf, &pageId);
265,858,850✔
91
    if (pData == NULL) {
265,906,809✔
92
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
93
      return NULL;
×
94
    }
95
    pData->num = sizeof(SFilePage);
265,906,809✔
96
  } else {
97
    pData = getBufPage(pResultBuf, *currentPageId);
2,147,483,647✔
98
    if (pData == NULL) {
2,147,483,647✔
99
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
100
      return NULL;
×
101
    }
102

103
    pageId = *currentPageId;
2,147,483,647✔
104

105
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
2,147,483,647✔
106
      // release current page first, and prepare the next one
107
      releaseBufPage(pResultBuf, pData);
841,521,351✔
108

109
      pData = getNewBufPage(pResultBuf, &pageId);
841,499,216✔
110
      if (pData == NULL) {
841,523,351✔
111
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
112
        return NULL;
×
113
      }
114
      pData->num = sizeof(SFilePage);
841,523,351✔
115
    }
116
  }
117

118
  setBufPageDirty(pData, true);
2,147,483,647✔
119

120
  // set the number of rows in current disk page
121
  SResultRow* pResultRow = (SResultRow*)((char*)pData + pData->num);
2,147,483,647✔
122

123
  memset((char*)pResultRow, 0, interBufSize);
2,147,483,647✔
124
  pResultRow->pageId = pageId;
2,147,483,647✔
125
  pResultRow->offset = (int32_t)pData->num;
2,147,483,647✔
126

127
  *currentPageId = pageId;
2,147,483,647✔
128
  pData->num += interBufSize;
2,147,483,647✔
129
  return pResultRow;
2,147,483,647✔
130
}
131

132
/**
133
 * the struct of key in hash table
134
 * +----------+---------------+
135
 * | group id |   key data    |
136
 * | 8 bytes  | actual length |
137
 * +----------+---------------+
138
 */
139
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
2,147,483,647✔
140
                                   int32_t bytes, bool masterscan, uint64_t groupId, SExecTaskInfo* pTaskInfo,
141
                                   bool isIntervalQuery, SAggSupporter* pSup, bool keepGroup) {
142
  SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId);
2,147,483,647✔
143
  if (!keepGroup) {
2,147,483,647✔
144
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
2,147,483,647✔
145
  }
146

147
  SResultRowPosition* p1 =
148
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
2,147,483,647✔
149

150
  SResultRow* pResult = NULL;
2,147,483,647✔
151

152
  // in case of repeat scan/reverse scan, no new time window added.
153
  if (isIntervalQuery) {
2,147,483,647✔
154
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
2,147,483,647✔
155
      pResult = getResultRowByPos(pResultBuf, p1, true);
1,760,036,405✔
156
      if (pResult == NULL) {
1,760,036,405✔
157
        pTaskInfo->code = terrno;
×
158
        return NULL;
×
159
      }
160

161
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
1,760,036,405✔
162
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
237✔
163
        pTaskInfo->code = terrno;
×
164
        return NULL;
×
165
      }
166
    }
167
  } else {
168
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
169
    // pResultRowInfo object.
170
    if (p1 != NULL) {
2,147,483,647✔
171
      // todo
172
      pResult = getResultRowByPos(pResultBuf, p1, true);
2,147,483,647✔
173
      if (NULL == pResult) {
2,147,483,647✔
174
        pTaskInfo->code = terrno;
×
175
        return NULL;
×
176
      }
177

178
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
2,147,483,647✔
179
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
180
        pTaskInfo->code = terrno;
×
181
        return NULL;
×
182
      }
183
    }
184
  }
185

186
  // 1. close current opened time window
187
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
2,147,483,647✔
188
    SResultRowPosition pos = pResultRowInfo->cur;
2,147,483,647✔
189
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
2,147,483,647✔
190
    if (pPage == NULL) {
2,147,483,647✔
191
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
192
      pTaskInfo->code = terrno;
×
193
      return NULL;
×
194
    }
195
    releaseBufPage(pResultBuf, pPage);
2,147,483,647✔
196
  }
197

198
  // allocate a new buffer page
199
  if (pResult == NULL) {
2,147,483,647✔
200
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
2,147,483,647✔
201
    if (pResult == NULL) {
2,147,483,647✔
202
      pTaskInfo->code = terrno;
×
203
      return NULL;
×
204
    }
205

206
    // add a new result set for a new group
207
    SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
2,147,483,647✔
208
     int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
2,147,483,647✔
209
                                  sizeof(SResultRowPosition));
210
    if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
211
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
212
      pTaskInfo->code = code;
×
213
      return NULL;
×
214
    }
215
  }
216

217
  // 2. set the new time window to be the new active time window
218
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
2,147,483,647✔
219

220
  // too many time window in query
221
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
2,147,483,647✔
222
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
2,147,483,647✔
223
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
224
    return NULL;
×
225
  }
226

227
  return pResult;
2,147,483,647✔
228
}
229

230
//  query_range_start, query_range_end, window_duration, window_start, window_end
231
int32_t initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) {
10,016,122✔
232
  pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
10,016,122✔
233
  pColData->info.bytes = sizeof(int64_t);
10,019,583✔
234

235
  int32_t code = colInfoDataEnsureCapacity(pColData, 6, false);
10,017,279✔
236
  if (code != TSDB_CODE_SUCCESS) {
10,019,655✔
237
    return code;
×
238
  }
239
  colDataSetInt64(pColData, 0, &pQueryWindow->skey);
10,019,655✔
240
  colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
10,014,799✔
241

242
  int64_t interval = 0;
10,021,270✔
243
  colDataSetInt64(pColData, 2, &interval);  // this value may be variable in case of 'n' and 'y'.
244
  colDataSetInt64(pColData, 3, &pQueryWindow->skey);
10,018,322✔
245
  colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
10,014,611✔
246

247
  interval = -1;
10,013,498✔
248
  colDataSetInt64(pColData, 5,  &interval);
249
  return TSDB_CODE_SUCCESS;
10,010,862✔
250
}
251

252
static int32_t doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
24,065,498✔
253
  int32_t         code = TSDB_CODE_SUCCESS;
24,065,498✔
254
  int32_t         lino = 0;
24,065,498✔
255
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
24,065,498✔
256
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
130,074,371✔
257
    pCtx[i].order = order;
105,970,493✔
258
    pCtx[i].input.numOfRows = pBlock->info.rows;
105,962,198✔
259
    code = setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock);
105,986,496✔
260
    QUERY_CHECK_CODE(code, lino, _end);
105,989,020✔
261
    pCtx[i].pSrcBlock = pBlock;
105,989,020✔
262
    pCtx[i].scanFlag = scanFlag;
105,989,647✔
263
  }
264

265
_end:
24,089,169✔
266
  if (code != TSDB_CODE_SUCCESS) {
24,089,169✔
267
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
268
  }
269
  return code;
24,082,731✔
270
}
271

272
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
2,147,483,647✔
273
                          bool createDummyCol) {
274
  if (pBlock->pBlockAgg != NULL) {
2,147,483,647✔
275
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
24,085,978✔
276
  } else {
277
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
2,147,483,647✔
278
  }
279
}
280

281
static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex,
306,006,286✔
282
                                             int32_t numOfRows) {
283
  int32_t          code = TSDB_CODE_SUCCESS;
306,006,286✔
284
  int32_t          lino = 0;
306,006,286✔
285
  SColumnInfoData* pColInfo = NULL;
306,006,286✔
286
  if (pInput->pData[paramIndex] == NULL) {
306,006,286✔
287
    pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
646,256✔
288
    QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno);
646,256✔
289

290
    // Set the correct column info (data type and bytes)
291
    pColInfo->info.type = pFuncParam->param.nType;
646,256✔
292
    pColInfo->info.bytes = pFuncParam->param.nLen;
646,256✔
293

294
    pInput->pData[paramIndex] = pColInfo;
646,256✔
295
  } else {
296
    pColInfo = pInput->pData[paramIndex];
305,463,894✔
297
  }
298

299
  code = colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
306,107,789✔
300
  QUERY_CHECK_CODE(code, lino, _end);
306,077,168✔
301

302
  int8_t type = pFuncParam->param.nType;
306,077,168✔
303
  if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
306,081,871✔
304
    int64_t v = pFuncParam->param.i;
451,021✔
305
    for (int32_t i = 0; i < numOfRows; ++i) {
991,182,443✔
306
      colDataSetInt64(pColInfo, i, &v);
990,727,008✔
307
    }
308
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
305,630,850✔
309
    double v = pFuncParam->param.d;
×
310
    for (int32_t i = 0; i < numOfRows; ++i) {
×
311
      colDataSetDouble(pColInfo, i, &v);
×
312
    }
313
  } else if (type == TSDB_DATA_TYPE_VARCHAR || type == TSDB_DATA_TYPE_GEOMETRY) {
305,630,850✔
314
    char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
9,151✔
315
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
316

317
    STR_WITH_SIZE_TO_VARSTR(tmp, pFuncParam->param.pz, pFuncParam->param.nLen);
×
318
    for (int32_t i = 0; i < numOfRows; ++i) {
×
319
      code = colDataSetVal(pColInfo, i, tmp, false);
×
320
      QUERY_CHECK_CODE(code, lino, _end);
×
321
    }
322
    taosMemoryFree(tmp);
×
323
  }
324

325
_end:
305,621,699✔
326
  if (code != TSDB_CODE_SUCCESS) {
306,077,134✔
327
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
328
  }
329
  return code;
306,037,876✔
330
}
331

332
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
2,147,483,647✔
333
                                   bool createDummyCol) {
334
  int32_t         code = TSDB_CODE_SUCCESS;
2,147,483,647✔
335
  int32_t         lino = 0;
2,147,483,647✔
336
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
2,147,483,647✔
337

338
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
2,147,483,647✔
339
    pCtx[i].order = order;
2,147,483,647✔
340
    pCtx[i].input.numOfRows = pBlock->info.rows;
2,147,483,647✔
341

342
    pCtx[i].pSrcBlock = pBlock;
2,147,483,647✔
343
    pCtx[i].scanFlag = scanFlag;
2,147,483,647✔
344

345
    SInputColumnInfoData* pInput = &pCtx[i].input;
2,147,483,647✔
346
    pInput->uid = pBlock->info.id.uid;
2,147,483,647✔
347
    pInput->colDataSMAIsSet = false;
2,147,483,647✔
348

349
    SExprInfo* pOneExpr = &pExprSup->pExprInfo[i];
2,147,483,647✔
350
    bool       hasPk = pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION && pOneExpr->pExpr->_function.pFunctNode->hasPk;
2,147,483,647✔
351
    pCtx[i].hasPrimaryKey = hasPk;
2,147,483,647✔
352

353
    int16_t tsParamIdx = (!hasPk) ? pOneExpr->base.numOfParams - 1 : pOneExpr->base.numOfParams - 2;
2,147,483,647✔
354
    int16_t pkParamIdx = pOneExpr->base.numOfParams - 1;
2,147,483,647✔
355

356
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
2,147,483,647✔
357
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
2,147,483,647✔
358
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
2,147,483,647✔
359
        int32_t slotId = pFuncParam->pCol->slotId;
2,147,483,647✔
360
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
2,147,483,647✔
361
        pInput->totalRows = pBlock->info.rows;
2,147,483,647✔
362
        pInput->numOfRows = pBlock->info.rows;
2,147,483,647✔
363
        pInput->startRowIndex = 0;
2,147,483,647✔
364
        pInput->blankFill = pBlock->info.blankFill;
2,147,483,647✔
365

366
        // NOTE: the last parameter is the primary timestamp column
367
        // todo: refactor this
368

369
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
2,147,483,647✔
370
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
2,147,483,647✔
371
        }
372
        if (hasPk && (j == pkParamIdx)) {
2,147,483,647✔
373
          pInput->pPrimaryKey = pInput->pData[j];
151,037,601✔
374
        }
375
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
2,147,483,647✔
376
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
658,508,217✔
377
        // todo avoid case: top(k, 12), 12 is the value parameter.
378
        // sum(11), 11 is also the value parameter.
379
        bool needDummyCol = (createDummyCol && pOneExpr->base.numOfParams == 1);
467,814,030✔
380
        // For indefinite-rows functions (e.g. mavg, csum, diff), the first parameter
381
        // is the data-input column.  When that argument is a constant we must expand
382
        // it into a per-row column so the function implementation can iterate over it.
383
        if (!needDummyCol && j == 0 &&
467,811,381✔
384
            pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION &&
46,681,477✔
385
            fmIsIndefiniteRowsFunc(pOneExpr->pExpr->_function.functionId)) {
14,498,953✔
386
          needDummyCol = true;
×
387
        }
388
        if (needDummyCol) {
467,810,559✔
389
          pInput->totalRows = pBlock->info.rows;
306,058,486✔
390
          pInput->numOfRows = pBlock->info.rows;
306,097,085✔
391
          pInput->startRowIndex = 0;
306,096,323✔
392
          pInput->blankFill = pBlock->info.blankFill;
306,076,819✔
393

394
          code = doCreateConstantValColumnInfo(pInput, pFuncParam, j, pBlock->info.rows);
306,082,685✔
395
          QUERY_CHECK_CODE(code, lino, _end);
305,954,143✔
396
        }
397
      }
398
    }
399
  }
400

401
_end:
2,147,483,647✔
402
  if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
403
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
404
  }
405
  return code;
2,147,483,647✔
406
}
407

408
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
2,147,483,647✔
409
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
2,147,483,647✔
410

411
  // in case of timestamp column, always generated results.
412
  int32_t functionId = pCtx->functionId;
2,147,483,647✔
413
  if (functionId == -1) {
2,147,483,647✔
414
    return false;
×
415
  }
416

417
  if (pCtx->scanFlag == PRE_SCAN) {
2,147,483,647✔
418
    return fmIsRepeatScanFunc(pCtx->functionId);
4,250,751✔
419
  }
420

421
  if (isRowEntryCompleted(pResInfo)) {
2,147,483,647✔
UNCOV
422
    return false;
×
423
  }
424

425
  return true;
2,147,483,647✔
426
}
427

428
static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
×
429
                                                int32_t paramIndex, int32_t numOfRows) {
430
  if (pInput->pData[paramIndex] == NULL) {
×
431
    pInput->pData[paramIndex] = taosMemoryCalloc(1, sizeof(SColumnInfoData));
×
432
    if (pInput->pData[paramIndex] == NULL) {
×
433
      return terrno;
×
434
    }
435

436
    // Set the correct column info (data type and bytes)
437
    pInput->pData[paramIndex]->info.type = type;
×
438
    pInput->pData[paramIndex]->info.bytes = tDataTypes[type].bytes;
×
439
  }
440

441
  SColumnDataAgg* da = NULL;
×
442
  if (pInput->pColumnDataAgg[paramIndex] == NULL) {
×
443
    da = taosMemoryCalloc(1, sizeof(SColumnDataAgg));
×
444
    if (!da) {
×
445
      return terrno;
×
446
    }
447
    pInput->pColumnDataAgg[paramIndex] = da;
×
448
  } else {
449
    da = pInput->pColumnDataAgg[paramIndex];
×
450
  }
451

452
  if (type == TSDB_DATA_TYPE_BIGINT) {
×
453
    int64_t v = pFuncParam->param.i;
×
454
    *da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
×
455
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
456
    double v = pFuncParam->param.d;
×
457
    *da = (SColumnDataAgg){.numOfNull = 0};
×
458

459
    *(double*)&da->min = v;
×
460
    *(double*)&da->max = v;
×
461
    *(double*)&da->sum = v * numOfRows;
×
462
  } else if (type == TSDB_DATA_TYPE_BOOL) {  // todo validate this data type
×
463
    bool v = pFuncParam->param.i;
×
464

465
    *da = (SColumnDataAgg){.numOfNull = 0};
×
466
    *(bool*)&da->min = 0;
×
467
    *(bool*)&da->max = v;
×
468
    *(bool*)&da->sum = v * numOfRows;
×
469
  } else if (type == TSDB_DATA_TYPE_TIMESTAMP) {
×
470
    // do nothing
471
  } else {
472
    qError("invalid constant type for sma info");
×
473
  }
474

475
  return TSDB_CODE_SUCCESS;
×
476
}
477

478
int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pBlock) {
105,956,491✔
479
  int32_t code = TSDB_CODE_SUCCESS;
105,956,491✔
480
  int32_t lino = 0;
105,956,491✔
481
  int32_t numOfRows = pBlock->info.rows;
105,956,491✔
482

483
  SInputColumnInfoData* pInput = &pCtx->input;
105,982,019✔
484
  pInput->numOfRows = numOfRows;
105,982,638✔
485
  pInput->totalRows = numOfRows;
105,992,838✔
486

487
  if (pBlock->pBlockAgg != NULL) {
105,994,076✔
488
    pInput->colDataSMAIsSet = true;
106,011,904✔
489

490
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
212,002,853✔
491
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
106,002,355✔
492

493
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
106,008,737✔
494
        int32_t slotId = pFuncParam->pCol->slotId;
106,004,284✔
495
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
106,004,308✔
496
        if (pInput->pColumnDataAgg[j]->colId == -1) {
105,999,783✔
497
          pInput->colDataSMAIsSet = false;
19,954✔
498
        }
499

500
        // Here we set the column info data since the data type for each column data is required, but
501
        // the data in the corresponding SColumnInfoData will not be used.
502
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
106,001,101✔
503
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
×
504
        code = doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
×
505
        QUERY_CHECK_CODE(code, lino, _end);
635✔
506
      }
507
    }
508
  } else {
509
    pInput->colDataSMAIsSet = false;
×
510
  }
511

512
_end:
105,932,417✔
513
  if (code != TSDB_CODE_SUCCESS) {
105,932,417✔
514
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
515
  }
516
  return code;
105,982,646✔
517
}
518

519
/////////////////////////////////////////////////////////////////////////////////////////////
520
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
2,147,483,647✔
521
  STimeWindow win = {0};
2,147,483,647✔
522
  win.skey = taosTimeTruncate(key, pInterval);
2,147,483,647✔
523

524
  /*
525
   * if the realSkey > INT64_MAX - pInterval->interval, the query duration between
526
   * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges.
527
   */
528
  win.ekey = taosTimeGetIntervalEnd(win.skey, pInterval);
2,147,483,647✔
529
  if (win.ekey < win.skey) {
2,147,483,647✔
530
    win.ekey = INT64_MAX;
×
531
  }
532

533
  return win;
2,147,483,647✔
534
}
535

536
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
2,147,483,647✔
537
                            int32_t* rowEntryInfoOffset) {
538
  bool init = false;
2,147,483,647✔
539
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,147,483,647✔
540
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
2,147,483,647✔
541
    if (init) {
2,147,483,647✔
542
      continue;
2,147,483,647✔
543
    }
544

545
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
2,147,483,647✔
546
    
547
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
2,147,483,647✔
548
      continue;
×
549
    }
550

551
    if (pCtx[i].isPseudoFunc) {
2,147,483,647✔
552
      continue;
2,147,483,647✔
553
    }
554

555
    if (!pResInfo->initialized) {
2,147,483,647✔
556
      if (pCtx[i].functionId != -1) {
2,147,483,647✔
557
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
2,147,483,647✔
558
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
2,147,483,647✔
559
          pResInfo->initialized = false;
×
560
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
561
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
562
        } else if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
563
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
564
          return code;
×
565
        }
566
      } else {
567
        pResInfo->initialized = true;
2,147,483,647✔
568
      }
569
    } else {
570
      init = true;
2,147,483,647✔
571
    }
572
  }
573
  return TSDB_CODE_SUCCESS;
2,147,483,647✔
574
}
575

576
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
654,382,619✔
577
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,147,483,647✔
578
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
2,147,483,647✔
579
    if (pResInfo == NULL) {
2,147,483,647✔
580
      continue;
×
581
    }
582

583
    pResInfo->initialized = false;
2,147,483,647✔
584
    pResInfo->numOfRes = 0;
2,147,483,647✔
585
    pResInfo->isNullRes = 0;
2,147,483,647✔
586
    pResInfo->complete = false;
2,147,483,647✔
587
  }
588
}
654,382,201✔
589

590
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo, SColumnInfoData** pRet) {
2,147,483,647✔
591
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
592
  int32_t lino = 0;
2,147,483,647✔
593
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
2,147,483,647✔
594
    return TSDB_CODE_SUCCESS;
2,147,483,647✔
595
  }
596

597
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
190,671,845✔
598
  SColumnInfoData*   p = NULL;
190,655,797✔
599

600
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
190,639,057✔
601
  QUERY_CHECK_CODE(code, lino, _err);
190,651,385✔
602

603
  int32_t status = 0;
190,651,385✔
604
  code =
605
      filterExecute(pFilterInfo, pBlock, pRet != NULL ? pRet : &p, NULL, param1.numOfCols, &status);
190,661,200✔
606
  QUERY_CHECK_CODE(code, lino, _err);
190,643,625✔
607

608
  code = extractQualifiedTupleByFilterResult(pBlock, pRet != NULL ? *pRet : p, status);
189,602,778✔
609
  QUERY_CHECK_CODE(code, lino, _err);
189,617,982✔
610

611
  if (pColMatchInfo != NULL) {
189,617,982✔
612
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
139,276,141✔
613
    for (int32_t i = 0; i < size; ++i) {
139,420,555✔
614
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
139,271,967✔
615
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
139,262,414✔
616
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
139,262,414✔
617
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
139,156,121✔
618
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
139,145,708✔
619
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
139,145,708✔
620
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
139,131,877✔
621
          QUERY_CHECK_CODE(code, lino, _err);
139,128,890✔
622
          break;
139,128,890✔
623
        }
624
      }
625
    }
626
  }
627
  code = blockDataCheck(pBlock);
189,619,319✔
628
  QUERY_CHECK_CODE(code, lino, _err);
189,614,535✔
629
_err:
190,655,382✔
630
  if (code != TSDB_CODE_SUCCESS) {
190,663,513✔
631
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1,040,847✔
632
  }
633
  colDataDestroy(p);
190,663,513✔
634
  taosMemoryFree(p);
190,664,903✔
635
  return code;
190,642,499✔
636
}
637

638
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
189,798,530✔
639
  int32_t code = TSDB_CODE_SUCCESS;
189,798,530✔
640
  int8_t* pIndicator = (int8_t*)p->pData;
189,798,530✔
641
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
189,816,582✔
642
    // here nothing needs to be done
643
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
120,093,191✔
644
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
48,975,192✔
645
    pBlock->info.rows = 0;
48,970,529✔
646
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
71,117,999✔
647
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
71,123,270✔
648
  } else {
649
    qError("unknown filter result type: %d", status);
29✔
650
  }
651
  return code;
189,813,165✔
652
}
653

654
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
2,147,483,647✔
655
  bool returnNotNull = false;
2,147,483,647✔
656
  for (int32_t j = 0; j < numOfExprs; ++j) {
2,147,483,647✔
657
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
2,147,483,647✔
658
    if (!isRowEntryInitialized(pResInfo)) {
2,147,483,647✔
659
      continue;
2,147,483,647✔
660
    } else {
661
    }
662

663
    if (pRow->numOfRows < pResInfo->numOfRes) {
2,147,483,647✔
664
      pRow->numOfRows = pResInfo->numOfRes;
2,147,483,647✔
665
    }
666

667
    if (pCtx[j].isNotNullFunc) {
2,147,483,647✔
668
      returnNotNull = true;
2,147,483,647✔
669
    }
670
  }
671
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
672
  //  except for first/last, which require not null output, output no rows
673
  if (pRow->numOfRows == 0 && !returnNotNull) {
2,147,483,647✔
674
    pRow->numOfRows = 1;
2,147,483,647✔
675
  }
676
}
2,147,483,647✔
677

678
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
2,147,483,647✔
679
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
680
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
681
  int32_t lino = 0;
2,147,483,647✔
682
  int32_t groupKeyIdx = 0;
2,147,483,647✔
683
  for (int32_t j = 0; j < numOfExprs; ++j) {
2,147,483,647✔
684
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
2,147,483,647✔
685

686
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
2,147,483,647✔
687
    if (pCtx[j].fpSet.finalize) {
2,147,483,647✔
688
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
2,147,483,647✔
689
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
2,147,483,647✔
690
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
691
        if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 &&
2,147,483,647✔
692
            pCtx[j].resultInfo->numOfRes == 0 && pTaskInfo->pStreamRuntimeInfo != NULL) {
2,147,483,647✔
693
          SArray* pVals = pTaskInfo->pStreamRuntimeInfo->funcInfo.pStreamPartColVals;
×
694
          if (pVals != NULL && groupKeyIdx < taosArrayGetSize(pVals)) {
×
695
            SStreamGroupValue* pValue = taosArrayGet(pVals, groupKeyIdx);
×
696
            if (pValue != NULL) {
×
697
              SGroupKeyInfo* pInfo = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
×
698
              pInfo->hasResult = true;
×
699
              pInfo->isNull = pValue->isNull;
×
700
              if (!pValue->isNull) {
×
701
                if (IS_VAR_DATA_TYPE(pValue->data.type) || pValue->data.type == TSDB_DATA_TYPE_DECIMAL) {
×
702
                  if (pValue->data.pData != NULL && pValue->data.nData > 0) {
×
703
                    memcpy(pInfo->data, pValue->data.pData, pValue->data.nData);
×
704
                  }
705
                } else {
706
                  memcpy(pInfo->data, &pValue->data.val, pExprInfo[j].base.resSchema.bytes);
×
707
                }
708
              }
709
              pCtx[j].resultInfo->numOfRes = 1;
×
710
            }
711
          }
712
        }
713

714
        if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0) {
2,147,483,647✔
715
          ++groupKeyIdx;
2,147,483,647✔
716
        }
717

718
        // need to match groupkey result for each output row of that function.
719
        if (pCtx[j].resultInfo->numOfRes != 0) {
2,147,483,647✔
720
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
2,147,483,647✔
721
        }
722
      }
723

724
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
2,147,483,647✔
725
      if (TSDB_CODE_SUCCESS != code) {
2,147,483,647✔
726
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
727
        QUERY_CHECK_CODE(code, lino, _end);
3,571,011✔
728
      }
729
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
2,147,483,647✔
730
      // do nothing
731
    } else {
732
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
733
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
734
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
2,147,483,647✔
735
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
2,147,483,647✔
736
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
2,147,483,647✔
737
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {        
2,147,483,647✔
738
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
2,147,483,647✔
739
        QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
740
      }
741
    }
742
  }
743

744
_end:
2,147,483,647✔
745
  if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
746
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
747
  }
748
  return code;
2,147,483,647✔
749
}
750

751
// todo refactor. SResultRow has direct pointer in miainfo
752
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
991,620,435✔
753
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
754
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
991,620,435✔
755
  if (page == NULL) {
991,618,755✔
756
    qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
757
    T_LONG_JMP(pTaskInfo->env, terrno);
×
758
  }
759

760
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
991,618,755✔
761

762
  SqlFunctionCtx* pCtx = pSup->pCtx;
991,617,915✔
763
  SExprInfo*      pExprInfo = pSup->pExprInfo;
991,618,755✔
764
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
991,618,755✔
765

766
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
991,618,755✔
767
  if (pRow->numOfRows == 0) {
991,612,875✔
768
    releaseBufPage(pBuf, page);
×
769
    return;
×
770
  }
771

772
  int32_t size = pBlock->info.capacity;
991,612,455✔
773
  while (pBlock->info.rows + pRow->numOfRows > size) {
991,857,237✔
774
    size = size * 1.25;
243,942✔
775
  }
776

777
  int32_t code = blockDataEnsureCapacity(pBlock, size);
991,614,555✔
778
  if (TAOS_FAILED(code)) {
991,612,455✔
779
    releaseBufPage(pBuf, page);
×
780
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
781
    T_LONG_JMP(pTaskInfo->env, code);
×
782
  }
783

784
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
991,612,455✔
785
  if (TAOS_FAILED(code)) {
991,610,527✔
786
    releaseBufPage(pBuf, page);
×
787
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
788
    T_LONG_JMP(pTaskInfo->env, code);
×
789
  }
790

791
  releaseBufPage(pBuf, page);
991,610,527✔
792
  pBlock->info.rows += pRow->numOfRows;
991,611,787✔
793
}
794

795
void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
2,147,483,647✔
796
                              SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup) {
797
  int32_t         code = TSDB_CODE_SUCCESS;
2,147,483,647✔
798
  int32_t         lino = 0;
2,147,483,647✔
799
  SExprInfo*      pExprInfo = pSup->pExprInfo;
2,147,483,647✔
800
  int32_t         numOfExprs = pSup->numOfExprs;
2,147,483,647✔
801
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
2,147,483,647✔
802
  SqlFunctionCtx* pCtx = pSup->pCtx;
2,147,483,647✔
803

804
  size_t  keyLen = 0;
2,147,483,647✔
805
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
2,147,483,647✔
806

807
  // begin from last iter
808
  void*   pData = pGroupResInfo->dataPos;
2,147,483,647✔
809
  int32_t iter = pGroupResInfo->iter;
2,147,483,647✔
810
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
2,147,483,647✔
811
    void*               key = tSimpleHashGetKey(pData, &keyLen);
2,147,483,647✔
812
    SResultRowPosition* pos = pData;
2,147,483,647✔
813
    uint64_t            groupId = calcGroupId((char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t));
2,147,483,647✔
814

815
    SFilePage* page = getBufPage(pBuf, pos->pageId);
2,147,483,647✔
816
    if (page == NULL) {
2,147,483,647✔
817
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
818
      T_LONG_JMP(pTaskInfo->env, terrno);
×
819
    }
820

821
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
2,147,483,647✔
822

823
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
2,147,483,647✔
824

825
    // no results, continue to check the next one
826
    if (pRow->numOfRows == 0) {
2,147,483,647✔
827
      pGroupResInfo->index += 1;
×
828
      pGroupResInfo->iter = iter;
×
829
      pGroupResInfo->dataPos = pData;
×
830

831
      releaseBufPage(pBuf, page);
×
832
      continue;
×
833
    }
834

835
    if (!ignoreGroup) {
2,147,483,647✔
836
      if (pBlock->info.id.groupId == 0) {
2,147,483,647✔
837
        pBlock->info.id.groupId = groupId;
2,147,483,647✔
838
      } else {
839
        // current value belongs to different group, it can't be packed into one datablock
840
        if (pBlock->info.id.groupId != groupId) {
2,147,483,647✔
841
          releaseBufPage(pBuf, page);
2,147,483,647✔
842
          break;
2,147,483,647✔
843
        }
844
      }
845
    }
846

847
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
2,147,483,647✔
848
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - iter) > 1 ? 1 : 0);
×
849
      code = blockDataEnsureCapacity(pBlock, newSize);
×
850
      QUERY_CHECK_CODE(code, lino, _end);
×
851
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
852
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
853
      // todo set the pOperator->resultInfo size
854
    }
855

856
    pGroupResInfo->index += 1;
2,147,483,647✔
857
    pGroupResInfo->iter = iter;
2,147,483,647✔
858
    pGroupResInfo->dataPos = pData;
2,147,483,647✔
859

860
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
2,147,483,647✔
861
    releaseBufPage(pBuf, page);
2,147,483,647✔
862
    QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
863
    pBlock->info.rows += pRow->numOfRows;
2,147,483,647✔
864
    if (pBlock->info.rows >= threshold) {
2,147,483,647✔
865
      break;
16,904✔
866
    }
867
  }
868

869
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
2,147,483,647✔
870
         pBlock->info.id.groupId);
871
  pBlock->info.dataLoad = 1;
2,147,483,647✔
872
  code = blockDataUpdateTsWindow(pBlock, 0);
2,147,483,647✔
873
  QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
874

875
_end:
2,147,483,647✔
876
  if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
877
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
878
    T_LONG_JMP(pTaskInfo->env, code);
×
879
  }
880
}
2,147,483,647✔
881

882
void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
118,814,967✔
883
                        SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup, STrueForInfo *pTrueForInfo) {
884
  int32_t         code = TSDB_CODE_SUCCESS;
118,814,967✔
885
  int32_t         lino = 0;
118,814,967✔
886
  SExprInfo*      pExprInfo = pSup->pExprInfo;
118,814,967✔
887
  int32_t         numOfExprs = pSup->numOfExprs;
118,816,295✔
888
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
118,815,716✔
889
  SqlFunctionCtx* pCtx = pSup->pCtx;
118,815,947✔
890

891
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
118,816,367✔
892

893
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
2,147,483,647✔
894
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
2,147,483,647✔
895
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
2,147,483,647✔
896
    if (page == NULL) {
2,147,483,647✔
897
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
898
      T_LONG_JMP(pTaskInfo->env, terrno);
×
899
    }
900

901
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
2,147,483,647✔
902

903
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
2,147,483,647✔
904

905
    // no results, continue to check the next one
906
    if (pRow->numOfRows == 0) {
2,147,483,647✔
907
      pGroupResInfo->index += 1;
135,721✔
908
      releaseBufPage(pBuf, page);
135,721✔
909
      continue;
135,721✔
910
    }
911
    // skip the window which is less than the windowMinSize
912
    if (!isTrueForSatisfied(pTrueForInfo, pRow->win.skey, pRow->win.ekey, pRow->nOrigRows)) {
2,147,483,647✔
913
      qDebug("skip small window, groupId: %" PRId64 ", skey: %" PRId64 ", ekey: %" PRId64 ", nrows: %u", pPos->groupId,
45,864✔
914
             pRow->win.skey, pRow->win.ekey, pRow->nOrigRows);
915
      pGroupResInfo->index += 1;
45,864✔
916
      releaseBufPage(pBuf, page);
45,864✔
917
      continue;
45,864✔
918
    }
919

920
    if (!ignoreGroup) {
2,147,483,647✔
921
      if (pBlock->info.id.groupId == 0) {
2,147,483,647✔
922
        pBlock->info.id.groupId = pPos->groupId;
2,147,483,647✔
923
      } else {
924
        // current value belongs to different group, it can't be packed into one datablock
925
        if (pBlock->info.id.groupId != pPos->groupId) {
2,001,529,570✔
926
          releaseBufPage(pBuf, page);
20,009,961✔
927
          break;
20,009,961✔
928
        }
929
      }
930
    }
931

932
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
2,147,483,647✔
933
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - i) > 1 ? 1 : 0);
×
934
      code = blockDataEnsureCapacity(pBlock, newSize);
×
935
      QUERY_CHECK_CODE(code, lino, _end);
×
936
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
937
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
938
      // todo set the pOperator->resultInfo size
939
    }
940

941
    pGroupResInfo->index += 1;
2,147,483,647✔
942
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
2,147,483,647✔
943
    releaseBufPage(pBuf, page);
2,147,483,647✔
944
    QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
945

946
    pBlock->info.rows += pRow->numOfRows;
2,147,483,647✔
947
    if (pBlock->info.rows >= threshold) {
2,147,483,647✔
948
      break;
16,967,553✔
949
    }
950
  }
951

952
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
119,427,935✔
953
         pBlock->info.id.groupId);
954
  pBlock->info.dataLoad = 1;
119,432,798✔
955
  code = blockDataUpdateTsWindow(pBlock, 0);
118,819,026✔
956
  QUERY_CHECK_CODE(code, lino, _end);
118,818,176✔
957

958
_end:
118,818,176✔
959
  if (code != TSDB_CODE_SUCCESS) {
118,818,176✔
960
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
961
    T_LONG_JMP(pTaskInfo->env, code);
×
962
  }
963
}
118,818,176✔
964

965
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
139,647,739✔
966
                            SDiskbasedBuf* pBuf) {
967
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
139,647,739✔
968
  SSDataBlock*   pBlock = pbInfo->pRes;
139,649,000✔
969

970
  // set output datablock version
971
  pBlock->info.version = pTaskInfo->version;
139,648,174✔
972

973
  blockDataCleanup(pBlock);
139,646,432✔
974
  if (!hasRemainResults(pGroupResInfo)) {
139,649,967✔
975
    return;
21,279,002✔
976
  }
977

978
  // clear the existed group id
979
  pBlock->info.id.groupId = 0;
118,370,551✔
980
  if (!pbInfo->mergeResultBlock) {
118,370,308✔
981
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
45,586,684✔
982
                       false, getTrueForInfo(pOperator));
983
  } else {
984
    while (hasRemainResults(pGroupResInfo)) {
135,183,823✔
985
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
72,780,185✔
986
                         true, getTrueForInfo(pOperator));
987
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
72,782,756✔
988
        break;
10,379,915✔
989
      }
990

991
      // clearing group id to continue to merge data that belong to different groups
992
      pBlock->info.id.groupId = 0;
62,403,084✔
993
    }
994

995
    // clear the group id info in SSDataBlock, since the client does not need it
996
    pBlock->info.id.groupId = 0;
72,782,999✔
997
  }
998
}
999

1000
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
419,216,360✔
1001
  for (int32_t i = 0; i < numOfExprs; ++i) {
1,603,630,494✔
1002
    SExprInfo* pExprInfo = &pExpr[i];
1,184,406,790✔
1003
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
2,147,483,647✔
1004
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
1,339,878,007✔
1005
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
1,100,352,376✔
1006
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
239,499,804✔
1007
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
134,869,407✔
1008
      }
1009
    }
1010

1011
    taosMemoryFree(pExprInfo->base.pParam);
1,184,418,807✔
1012
    taosMemoryFree(pExprInfo->pExpr);
1,184,422,269✔
1013
  }
1014
}
419,223,704✔
1015

1016
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
303,049,534✔
1017
  *defaultPgsz = 4096;
303,049,534✔
1018
  uint32_t last = *defaultPgsz;
303,076,091✔
1019
  while (*defaultPgsz < rowSize * 4) {
364,548,786✔
1020
    *defaultPgsz <<= 1u;
61,518,832✔
1021
    if (*defaultPgsz < last) {
61,500,729✔
1022
      return TSDB_CODE_INVALID_PARA;
×
1023
    }
1024
    last = *defaultPgsz;
61,499,775✔
1025
  }
1026

1027
  // The default buffer for each operator in query is 10MB.
1028
  // at least four pages need to be in buffer
1029
  // TODO: make this variable to be configurable.
1030
  *defaultBufsz = 4096 * 2560;
303,007,050✔
1031
  if ((*defaultBufsz) <= (*defaultPgsz)) {
303,068,753✔
1032
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
1033
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
1034
      return TSDB_CODE_INVALID_PARA;
×
1035
    }
1036
  }
1037

1038
  return 0;
303,035,583✔
1039
}
1040

1041
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
644,948,426✔
1042
  if (numOfRows == 0) {
644,948,426✔
1043
    numOfRows = 4096;
×
1044
  }
1045

1046
  pResultInfo->capacity = numOfRows;
644,948,426✔
1047
  pResultInfo->threshold = numOfRows * 0.75;
645,041,787✔
1048

1049
  if (pResultInfo->threshold == 0) {
644,944,570✔
1050
    pResultInfo->threshold = numOfRows;
1,760,674✔
1051
  }
1052
  pResultInfo->totalRows = 0;
644,987,690✔
1053
}
644,957,532✔
1054

1055
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
284,601,380✔
1056
  pInfo->pRes = pBlock;
284,601,380✔
1057
  initResultRowInfo(&pInfo->resultRowInfo);
284,627,936✔
1058
}
284,546,012✔
1059

1060
void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
1,220,429,738✔
1061
  if (pCtx == NULL) {
1,220,429,738✔
1062
    return;
773,686,162✔
1063
  }
1064

1065
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,618,479,794✔
1066
    if (pExpr != NULL) {
1,171,754,486✔
1067
      SExprInfo* pExprInfo = &pExpr[i];
1,171,731,598✔
1068
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
2,147,483,647✔
1069
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
1,326,396,978✔
1070
          colDataDestroy(pCtx[i].input.pData[j]);
132,677,279✔
1071
          taosMemoryFree(pCtx[i].input.pData[j]);
132,677,839✔
1072
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
132,677,720✔
1073
        }
1074
      }
1075
    }
1076
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
2,147,483,647✔
1077
      taosVariantDestroy(&pCtx[i].param[j].param);
1,326,428,027✔
1078
    }
1079

1080
    if(pCtx[i].fpSet.cleanup) {
1,171,768,749✔
1081
      pCtx[i].fpSet.cleanup(&pCtx[i]);
942,774✔
1082
    }
1083

1084
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
1,171,787,803✔
1085
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
1,171,801,669✔
1086
    taosMemoryFree(pCtx[i].input.pData);
1,171,798,073✔
1087
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
1,171,775,406✔
1088

1089
    if (pCtx[i].udfName != NULL) {
1,171,741,677✔
1090
      taosMemoryFree(pCtx[i].udfName);
37,054✔
1091
    }
1092
  }
1093

1094
  taosMemoryFreeClear(pCtx);
446,725,308✔
1095
  return;
446,695,394✔
1096
}
1097

1098
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
444,417,078✔
1099
  pSup->pExprInfo = pExprInfo;
444,417,078✔
1100
  pSup->numOfExprs = numOfExpr;
444,441,200✔
1101
  if (pSup->pExprInfo != NULL) {
444,428,766✔
1102
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
346,059,646✔
1103
    if (pSup->pCtx == NULL) {
345,981,906✔
1104
      return terrno;
×
1105
    }
1106
  }
1107

1108
  return TSDB_CODE_SUCCESS;
444,390,538✔
1109
}
1110

1111
void checkIndefRowsFuncs(SExprSupp* pSup) {
8,776✔
1112
  for (int32_t i = 0; i < pSup->numOfExprs; ++i) {
25,288✔
1113
    if (fmIsIndefiniteRowsFunc(pSup->pCtx[i].functionId)) {
16,512✔
1114
      pSup->hasIndefRowsFunc = true;
×
1115
      break;
×
1116
    }
1117
  }
1118
}
8,776✔
1119

1120
static void cleanupIndefRowsResultRow(SOperatorInfo* pOperator, SResultRow* pRow) {
10,237,524✔
1121
  if (NULL == pOperator || NULL == pRow) {
10,237,524✔
UNCOV
1122
    return;
×
1123
  }
1124

1125
  SExprSupp* pSup = &pOperator->exprSupp;
10,237,524✔
1126
  for (int32_t i = 0; i < pSup->numOfExprs; ++i) {
22,843,466✔
1127
    pSup->pCtx[i].resultInfo = getResultEntryInfo(pRow, i, pSup->rowEntryInfoOffset);
12,605,942✔
1128
    if (pSup->pCtx[i].fpSet.cleanup != NULL) {
12,605,942✔
1129
      pSup->pCtx[i].fpSet.cleanup(&pSup->pCtx[i]);
13,326✔
1130
    }
1131
    pSup->pCtx[i].resultInfo = NULL;
12,605,942✔
1132
  }
1133
}
1134

1135
static void destroyIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsWindowState* pState) {
3,044✔
1136
  if (NULL == pState) {
3,044✔
UNCOV
1137
    return;
×
1138
  }
1139

1140
  cleanupIndefRowsResultRow(pOperator, pState->pRow);
3,044✔
1141
  taosMemoryFreeClear(pState->pRow);
3,044✔
1142

1143
  if (pState->pSealedBlocks != NULL) {
3,044✔
1144
    SListNode* pNode = NULL;
3,044✔
1145
    while ((pNode = tdListPopHead(pState->pSealedBlocks)) != NULL) {
3,044✔
UNCOV
1146
      SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
×
UNCOV
1147
      blockDataDestroy(pBlock);
×
UNCOV
1148
      taosMemoryFree(pNode);
×
1149
    }
1150
    pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
3,044✔
1151
  }
1152

1153
  blockDataDestroy(pState->pCurBlock);
3,044✔
1154
  taosMemoryFreeClear(pState);
3,044✔
1155
}
1156

1157
static void removeIndefRowsOpenState(SSHashObj* pOpenStatesMap, SIndefRowsWindowState* pState) {
10,234,480✔
1158
  if (NULL == pOpenStatesMap || NULL == pState) {
10,234,480✔
UNCOV
1159
    return;
×
1160
  }
1161

1162
  SIndefRowsStateKey key = {.groupId = pState->groupId, .skey = pState->win.skey};
10,234,480✔
1163
  int32_t  code = tSimpleHashRemove(pOpenStatesMap, &key, sizeof(key));
10,234,480✔
1164
  if (code != TSDB_CODE_SUCCESS) {
10,234,480✔
UNCOV
1165
    qError("failed to remove open state for groupId:%" PRIu64 ", skey:%" PRId64 ", code:%s", pState->groupId, pState->win.skey,
×
1166
           tstrerror(code));
1167
  }
1168
}
1169

1170
static int32_t createIndefRowsWindowState(SIndefRowsRuntime* pRuntime, SSDataBlock* pResultTemplate, uint64_t groupId,
10,237,524✔
1171
                                          const STimeWindow* pWin, int32_t resultRowSize,
1172
                                          SIndefRowsWindowState** ppState) {
1173
  int32_t code = TSDB_CODE_SUCCESS;
10,237,524✔
1174
  int32_t lino = 0;
10,237,524✔
1175

1176
  SIndefRowsWindowState* pState = taosMemoryCalloc(1, sizeof(SIndefRowsWindowState));
10,237,524✔
1177
  TSDB_CHECK_NULL(pState, code, lino, _return, terrno);
10,237,524✔
1178

1179
  pState->pRow = taosMemoryCalloc(1, resultRowSize);
10,237,524✔
1180
  QUERY_CHECK_NULL(pState->pRow, code, lino, _return, terrno);
10,237,524✔
1181

1182
  pState->pSealedBlocks = tdListNew(POINTER_BYTES);
10,237,524✔
1183
  QUERY_CHECK_NULL(pState->pSealedBlocks, code, lino, _return, terrno);
10,237,524✔
1184

1185
  code = createOneDataBlock(pResultTemplate, false, &pState->pCurBlock);
10,237,524✔
1186
  QUERY_CHECK_CODE(code, lino, _return);
10,237,524✔
1187

1188
  pState->groupId = groupId;
10,237,524✔
1189
  pState->win = *pWin;
10,237,524✔
1190
  TAOS_SET_POBJ_ALIGNED(&pState->pRow->win, pWin);
10,237,524✔
1191

1192
  SIndefRowsStateKey key = {.groupId = groupId, .skey = pWin->skey};
10,237,524✔
1193
  code = tSimpleHashPut(pRuntime->pOpenStatesMap, &key, sizeof(key), &pState, POINTER_BYTES);
10,237,524✔
1194
  QUERY_CHECK_CODE(code, lino, _return);
10,237,524✔
1195

1196
  *ppState = pState;
10,237,524✔
1197
  return code;
10,237,524✔
1198

UNCOV
1199
_return:
×
1200
  if (NULL != pState) {
×
1201
    taosMemoryFree(pState->pRow);
×
1202
    pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
×
UNCOV
1203
    blockDataDestroy(pState->pCurBlock);
×
UNCOV
1204
    taosMemoryFree(pState);
×
1205
  }
1206

1207
  if (code != TSDB_CODE_SUCCESS) {
×
1208
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1209
  }
1210

UNCOV
1211
  return code;
×
1212
}
1213

1214
static int32_t fillIndefRowsWindowPseudoCols(SOperatorInfo* pOperator, SSDataBlock* pBlock, const STimeWindow* pWin,
1,191,700✔
1215
                                             int32_t startOffset, int32_t rows) {
1216
  int32_t code = TSDB_CODE_SUCCESS;
1,191,700✔
1217
  int32_t lino = 0;
1,191,700✔
1218

1219
  if (rows <= 0) {
1,191,700✔
1220
    return code;
×
1221
  }
1222

1223
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
4,839,342✔
1224
    SqlFunctionCtx* pCtx = &pOperator->exprSupp.pCtx[i];
3,647,642✔
1225
    if (!fmIsPseudoColumnFunc(pCtx->functionId)) {
3,647,642✔
1226
      continue;
1,851,194✔
1227
    }
1228

1229
    const char* pFuncName = pCtx->pExpr->pExpr->_function.functionName;
1,796,448✔
1230
    int64_t     val = 0;
1,796,448✔
1231
    if (strcmp(pFuncName, "_wstart") == 0) {
1,796,448✔
1232
      val = pWin->skey;
738,820✔
1233
    } else if (strcmp(pFuncName, "_wend") == 0) {
1,057,628✔
1234
      val = pWin->ekey;
528,814✔
1235
    } else if (strcmp(pFuncName, "_wduration") == 0) {
528,814✔
1236
      val = pWin->ekey - pWin->skey;
528,814✔
1237
    } else {
1238
      continue;
×
1239
    }
1240

1241
    int32_t slotId = pOperator->exprSupp.pExprInfo[i].base.resSchema.slotId;
1,796,448✔
1242
    SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
1,796,448✔
1243
    QUERY_CHECK_NULL(pCol, code, lino, _return, terrno);
1,796,448✔
1244

1245
    for (int32_t row = 0; row < rows; ++row) {
704,284,504✔
1246
      code = colDataSetVal(pCol, startOffset + row, (const char*)&val, false);
702,487,188✔
1247
      QUERY_CHECK_CODE(code, lino, _return);
702,488,056✔
1248
    }
1249
  }
1250

1251
  return code;
1,191,700✔
1252

UNCOV
1253
_return:
×
UNCOV
1254
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
UNCOV
1255
  return code;
×
1256
}
1257

1258
int32_t initIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SqlFunctionCtx* pCtx, int32_t numOfExprs, int32_t blockCapacity) {
114,626✔
1259
  int32_t code = TSDB_CODE_SUCCESS;
114,626✔
1260
  int32_t lino = 0;
114,626✔
1261

1262
  if (NULL == pRuntime) {
114,626✔
UNCOV
1263
    return TSDB_CODE_INVALID_PARA;
×
1264
  }
1265

1266
  pRuntime->blockCapacity = blockCapacity > 0 ? blockCapacity : 4096;
114,626✔
1267

1268
  pRuntime->pOpenStatesMap = tSimpleHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
114,626✔
1269
  QUERY_CHECK_NULL(pRuntime->pOpenStatesMap, code, lino, _return, terrno);
114,626✔
1270

1271
  pRuntime->pReadyBlocks = tdListNew(POINTER_BYTES);
114,626✔
1272
  QUERY_CHECK_NULL(pRuntime->pReadyBlocks, code, lino, _return, terrno);
114,626✔
1273

1274
  code = setRowTsColumnOutputInfo(pCtx, numOfExprs, &pRuntime->pPseudoColInfo);
114,626✔
1275
  QUERY_CHECK_CODE(code, lino, _return);
114,626✔
1276

1277
  return code;
114,626✔
1278

UNCOV
1279
_return:
×
UNCOV
1280
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
UNCOV
1281
  pRuntime->pReadyBlocks = tdListFree(pRuntime->pReadyBlocks);
×
UNCOV
1282
  tSimpleHashCleanup(pRuntime->pOpenStatesMap);
×
UNCOV
1283
  pRuntime->pOpenStatesMap = NULL;
×
UNCOV
1284
  return code;
×
1285
}
1286

1287
void resetIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
7,968,290✔
1288
  if (NULL == pRuntime) {
7,968,290✔
UNCOV
1289
    return;
×
1290
  }
1291

1292
  if (pRuntime->pReturnedBlock != NULL) {
7,968,290✔
UNCOV
1293
    blockDataDestroy(pRuntime->pReturnedBlock);
×
UNCOV
1294
    pRuntime->pReturnedBlock = NULL;
×
1295
  }
1296

1297
  if (pRuntime->pReadyBlocks != NULL) {
7,968,710✔
1298
    SListNode* pNode = NULL;
114,626✔
1299
    while ((pNode = tdListPopHead(pRuntime->pReadyBlocks)) != NULL) {
114,626✔
UNCOV
1300
      SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
×
UNCOV
1301
      blockDataDestroy(pBlock);
×
1302
      taosMemoryFree(pNode);
×
1303
    }
1304
  }
1305

1306
  if (pRuntime->pOpenStatesMap != NULL) {
7,968,290✔
1307
    int32_t iter = 0;
114,626✔
1308
    void*   pData = NULL;
114,626✔
1309
    while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
117,670✔
1310
      SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
3,044✔
1311
      destroyIndefRowsWindowState(pOperator, pState);
3,044✔
1312
    }
1313
    tSimpleHashClear(pRuntime->pOpenStatesMap);
114,626✔
1314
  }
1315

1316
  if (pRuntime->pTmpBlock != NULL) {
7,968,290✔
1317
    blockDataCleanup(pRuntime->pTmpBlock);
102,324✔
1318
  }
1319
}
1320

1321
void cleanupIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
7,916,936✔
1322
  if (NULL == pRuntime) {
7,916,936✔
UNCOV
1323
    return;
×
1324
  }
1325

1326
  resetIndefRowsRuntime(pRuntime, pOperator);
7,916,936✔
1327
  tSimpleHashCleanup(pRuntime->pOpenStatesMap);
7,916,936✔
1328
  pRuntime->pOpenStatesMap = NULL;
7,916,952✔
1329
  pRuntime->pReadyBlocks = tdListFree(pRuntime->pReadyBlocks);
7,916,952✔
1330
  taosArrayDestroy(pRuntime->pPseudoColInfo);
7,917,087✔
1331
  pRuntime->pPseudoColInfo = NULL;
7,916,381✔
1332
  blockDataDestroy(pRuntime->pTmpBlock);
7,915,961✔
1333
  pRuntime->pTmpBlock = NULL;
7,917,103✔
1334
}
1335

1336
SIndefRowsWindowState* findIndefRowsWindowState(const SIndefRowsRuntime* pRuntime, uint64_t groupId, TSKEY winSKey) {
10,541,676✔
1337
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
10,541,676✔
UNCOV
1338
    return NULL;
×
1339
  }
1340

1341
  SIndefRowsStateKey key = {.groupId = groupId, .skey = winSKey};
10,541,676✔
1342
  SIndefRowsWindowState** ppState = tSimpleHashGet(pRuntime->pOpenStatesMap, &key, sizeof(key));
10,541,676✔
1343
  return ppState ? *ppState : NULL;
10,541,676✔
1344
}
1345

1346
int32_t applyIndefRowsFuncOnWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime,
10,461,068✔
1347
                                        SIndefRowsWindowState** ppState, SSDataBlock* pResultTemplate,
1348
                                        uint64_t groupId, const STimeWindow* pWin, SSDataBlock* pInputBlock,
1349
                                        int32_t startRow, int32_t numRows, int32_t inputTsOrder,
1350
                                        int32_t resultRowSize) {
1351
  int32_t                code = TSDB_CODE_SUCCESS;
10,461,068✔
1352
  int32_t                lino = 0;
10,461,068✔
1353
  SIndefRowsWindowState* pState = NULL;
10,461,068✔
1354

1355
  QRY_PARAM_CHECK(ppState);
10,461,068✔
1356
  if (numRows <= 0) {
10,461,068✔
1357
    return code;
×
1358
  }
1359

1360
  if (NULL == pRuntime || NULL == pRuntime->pPseudoColInfo) {
10,461,068✔
1361
    qError("%s invalid parameter, pRuntime:%p, pPseudoColInfo:%p", __func__, pRuntime, pRuntime ? pRuntime->pPseudoColInfo : NULL);
×
UNCOV
1362
    return TSDB_CODE_INVALID_PARA;
×
1363
  }
1364

1365
  pState = findIndefRowsWindowState(pRuntime, groupId, pWin->skey);
10,461,068✔
1366
  if (NULL == pState) {
10,461,068✔
1367
    code = createIndefRowsWindowState(pRuntime, pResultTemplate, groupId, pWin, resultRowSize, &pState);
10,237,524✔
1368
    QUERY_CHECK_CODE(code, lino, _return);
10,237,524✔
1369
    for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
22,850,856✔
1370
      pOperator->exprSupp.pCtx[i].pOutput = NULL;
12,613,332✔
1371
    }
1372
  } else {
1373
    // Only update ekey — groupId and skey already matched by find
1374
    pState->win.ekey = pWin->ekey;
223,544✔
1375
    pState->pRow->win.ekey = pWin->ekey;
223,544✔
1376
  }
1377

1378
  code = setResultRowInitCtx(pState->pRow, pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs,
10,461,068✔
1379
                             pOperator->exprSupp.rowEntryInfoOffset);
1380
  QUERY_CHECK_CODE(code, lino, _return);
10,461,068✔
1381

1382
  if (NULL == pRuntime->pTmpBlock) {
10,461,068✔
1383
    code = createOneDataBlock(pInputBlock, false, &pRuntime->pTmpBlock);
102,324✔
1384
    QUERY_CHECK_CODE(code, lino, _return);
102,324✔
1385
  } else {
1386
    blockDataCleanup(pRuntime->pTmpBlock);
10,358,744✔
1387
  }
1388

1389
  SSDataBlock* pWindowBlock = pRuntime->pTmpBlock;
10,461,068✔
1390
  code = blockDataEnsureCapacity(pWindowBlock, TMAX(1, numRows));
10,461,068✔
1391
  QUERY_CHECK_CODE(code, lino, _return);
10,461,068✔
1392
  code = blockDataMergeNRows(pWindowBlock, pInputBlock, startRow, numRows);
10,461,068✔
1393
  QUERY_CHECK_CODE(code, lino, _return);
10,461,068✔
1394

1395
  pWindowBlock->info.id = pInputBlock->info.id;
10,461,068✔
1396
  pWindowBlock->info.window = *pWin;
10,461,068✔
1397
  pWindowBlock->info.scanFlag = pInputBlock->info.scanFlag;
10,461,068✔
1398
  pWindowBlock->info.dataLoad = pInputBlock->info.dataLoad;
10,461,068✔
1399

1400
  code = setInputDataBlock(&pOperator->exprSupp, pWindowBlock, inputTsOrder, pWindowBlock->info.scanFlag, false);
10,461,068✔
1401
  QUERY_CHECK_CODE(code, lino, _return);
10,461,068✔
1402

1403
  pState->pCurBlock->info.id = pInputBlock->info.id;
10,461,068✔
1404
  pState->pCurBlock->info.window = *pWin;
10,461,068✔
1405
  pState->pCurBlock->info.scanFlag = pInputBlock->info.scanFlag;
10,461,068✔
1406
  pState->pCurBlock->info.dataLoad = 1;
10,461,068✔
1407
  code = blockDataEnsureCapacity(pState->pCurBlock, pState->pCurBlock->info.rows + pWindowBlock->info.rows);
10,461,068✔
1408
  QUERY_CHECK_CODE(code, lino, _return);
10,461,068✔
1409

1410
  code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pState->pCurBlock, pWindowBlock,
10,461,068✔
1411
                               pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs,
1412
                               pRuntime->pPseudoColInfo,
1413
                               GET_STM_RTINFO(pOperator->pTaskInfo));
10,461,068✔
1414
  QUERY_CHECK_CODE(code, lino, _return);
10,461,068✔
1415

1416
  pState->pRow->nOrigRows += numRows;
10,458,024✔
1417

1418
  // Seal current block if it reached capacity
1419
  if (pState->pCurBlock->info.rows >= pRuntime->blockCapacity) {
10,458,024✔
1420
    code = tdListAppend(pState->pSealedBlocks, &pState->pCurBlock);
301,400✔
1421
    QUERY_CHECK_CODE(code, lino, _return);
301,400✔
1422
    pState->pCurBlock = NULL;
301,400✔
1423
    code = createOneDataBlock(pResultTemplate, false, &pState->pCurBlock);
301,400✔
1424
    QUERY_CHECK_CODE(code, lino, _return);
301,400✔
1425
  }
1426

1427
  *ppState = pState;
10,458,024✔
1428

1429
_return:
10,461,068✔
1430
  if (code != TSDB_CODE_SUCCESS) {
10,461,068✔
1431
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
3,044✔
1432
  }
1433

1434
  return code;
10,461,068✔
1435
}
1436

1437
int32_t closeIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime, SIndefRowsWindowState* pState) {
10,234,480✔
1438
  int32_t code = TSDB_CODE_SUCCESS;
10,234,480✔
1439
  int32_t lino = 0;
10,234,480✔
1440

1441
  if (NULL == pRuntime || NULL == pState) {
10,234,480✔
1442
    return code;
×
1443
  }
1444

1445
  // Phase 1: Seal current block into sealed list (so all blocks are in one place)
1446
  if (pState->pCurBlock != NULL && pState->pCurBlock->info.rows > 0) {
10,234,480✔
1447
    code = tdListAppend(pState->pSealedBlocks, &pState->pCurBlock);
890,300✔
1448
    QUERY_CHECK_CODE(code, lino, _error);
890,300✔
1449
    pState->pCurBlock = NULL;
890,300✔
1450
  } else {
1451
    blockDataDestroy(pState->pCurBlock);
9,344,180✔
1452
    pState->pCurBlock = NULL;
9,344,180✔
1453
  }
1454

1455
  // Phase 2: Process each block — fill pseudo cols, filter, push to readyBlocks
1456
  SListNode* pNode = NULL;
10,234,480✔
1457
  while ((pNode = tdListPopHead(pState->pSealedBlocks)) != NULL) {
11,426,180✔
1458
    SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
1,191,700✔
1459
    taosMemoryFree(pNode);
1,191,700✔
1460

1461
    code = fillIndefRowsWindowPseudoCols(pOperator, pBlock, &pState->win, 0, pBlock->info.rows);
1,191,700✔
1462
    if (code != TSDB_CODE_SUCCESS) {
1,191,700✔
1463
      blockDataDestroy(pBlock);
×
UNCOV
1464
      qError("%s fillPseudoCols failed since %s", __func__, tstrerror(code));
×
UNCOV
1465
      goto _cleanup;
×
1466
    }
1467

1468
    if (pOperator->exprSupp.pFilterInfo != NULL) {
1,191,700✔
UNCOV
1469
      code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL, NULL);
×
UNCOV
1470
      if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
1471
        blockDataDestroy(pBlock);
×
UNCOV
1472
        qError("%s doFilter failed since %s", __func__, tstrerror(code));
×
UNCOV
1473
        goto _cleanup;
×
1474
      }
1475
    }
1476

1477
    if (pBlock->info.rows > 0) {
1,191,700✔
1478
      code = tdListAppend(pRuntime->pReadyBlocks, &pBlock);
1,191,700✔
1479
      if (code != TSDB_CODE_SUCCESS) {
1,191,700✔
1480
        blockDataDestroy(pBlock);
×
UNCOV
1481
        qError("%s append readyBlocks failed since %s", __func__, tstrerror(code));
×
UNCOV
1482
        goto _cleanup;
×
1483
      }
1484
    } else {
UNCOV
1485
      blockDataDestroy(pBlock);
×
1486
    }
1487
  }
1488

1489
  // Phase 3: All succeeded — remove from open states and destroy the state shell
1490
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
10,234,480✔
1491
  cleanupIndefRowsResultRow(pOperator, pState->pRow);
10,234,480✔
1492
  taosMemoryFreeClear(pState->pRow);
10,234,480✔
1493
  pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
10,234,480✔
1494
  taosMemoryFreeClear(pState);
10,234,480✔
1495

1496
  return TSDB_CODE_SUCCESS;
10,234,480✔
1497

UNCOV
1498
_error:
×
1499
  // Seal failed — state still intact in openStates, let dropAll clean up
UNCOV
1500
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
UNCOV
1501
  return code;
×
1502

UNCOV
1503
_cleanup:
×
1504
  // Some blocks already pushed to readyBlocks (they'll be consumed normally).
1505
  // Remaining blocks still in pSealedBlocks — destroy them along with state.
UNCOV
1506
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
×
1507
  destroyIndefRowsWindowState(pOperator, pState);
×
UNCOV
1508
  return code;
×
1509
}
1510

1511
int32_t closeAllIndefRowsWindowStates(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime) {
106,868✔
1512
  int32_t code = TSDB_CODE_SUCCESS;
106,868✔
1513
  int32_t lino = 0;
106,868✔
1514

1515
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
106,868✔
UNCOV
1516
    return code;
×
1517
  }
1518

1519
  // Collect all states first since closeIndefRowsWindowState removes from the map
1520
  int32_t numOpen = tSimpleHashGetSize(pRuntime->pOpenStatesMap);
106,868✔
1521
  if (numOpen == 0) {
106,868✔
1522
    return code;
14,080✔
1523
  }
1524

1525
  SArray* pStates = taosArrayInit(numOpen, POINTER_BYTES);
92,788✔
1526
  QUERY_CHECK_NULL(pStates, code, lino, _return, terrno);
92,788✔
1527

1528
  int32_t iter = 0;
92,788✔
1529
  void*   pData = NULL;
92,788✔
1530
  while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
584,120✔
1531
    SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
491,332✔
1532
    QUERY_CHECK_NULL(taosArrayPush(pStates, &pState), code, lino, _return, terrno);
491,332✔
1533
  }
1534

1535
  for (int32_t i = 0; i < taosArrayGetSize(pStates); ++i) {
584,120✔
1536
    SIndefRowsWindowState* pState = taosArrayGetP(pStates, i);
491,332✔
1537
    code = closeIndefRowsWindowState(pOperator, pRuntime, pState);
491,332✔
1538
    QUERY_CHECK_CODE(code, lino, _return);
491,332✔
1539
  }
1540

1541
_return:
92,788✔
1542
  taosArrayDestroy(pStates);
92,788✔
1543
  if (code != TSDB_CODE_SUCCESS) {
92,788✔
UNCOV
1544
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1545
  }
1546
  return code;
92,788✔
1547
}
1548

UNCOV
1549
void dropIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime, SIndefRowsWindowState* pState) {
×
UNCOV
1550
  if (NULL == pRuntime || NULL == pState) {
×
UNCOV
1551
    return;
×
1552
  }
1553

UNCOV
1554
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
×
UNCOV
1555
  destroyIndefRowsWindowState(pOperator, pState);
×
1556
}
1557

1558
void dropAllIndefRowsWindowStates(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime) {
20,482✔
1559
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
20,482✔
UNCOV
1560
    return;
×
1561
  }
1562

1563
  int32_t openCount = tSimpleHashGetSize(pRuntime->pOpenStatesMap);
20,482✔
1564
  if (openCount > 0) {
20,482✔
UNCOV
1565
    qDebug("%s dropping %d unclosed indefRows window state(s)", GET_TASKID(pOperator->pTaskInfo), openCount);
×
1566
  }
1567

1568
  int32_t iter = 0;
20,482✔
1569
  void*   pData = NULL;
20,482✔
1570
  while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
20,482✔
UNCOV
1571
    SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
×
UNCOV
1572
    destroyIndefRowsWindowState(pOperator, pState);
×
1573
  }
1574
  tSimpleHashClear(pRuntime->pOpenStatesMap);
20,482✔
1575
}
1576

1577
SSDataBlock* getNextIndefRowsResultBlock(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
1,389,116✔
1578
  if (NULL == pRuntime) {
1,389,116✔
UNCOV
1579
    return NULL;
×
1580
  }
1581

1582
  if (pRuntime->pReturnedBlock != NULL) {
1,389,116✔
1583
    blockDataDestroy(pRuntime->pReturnedBlock);
1,191,700✔
1584
    pRuntime->pReturnedBlock = NULL;
1,191,700✔
1585
  }
1586

1587
  if (NULL == pRuntime->pReadyBlocks) {
1,389,116✔
UNCOV
1588
    return NULL;
×
1589
  }
1590

1591
  while (listNEles(pRuntime->pReadyBlocks) > 0) {
1,389,116✔
1592
    SListNode* pNode = tdListPopHead(pRuntime->pReadyBlocks);
1,191,700✔
1593
    if (NULL == pNode) {
1,191,700✔
UNCOV
1594
      return NULL;
×
1595
    }
1596

1597
    SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
1,191,700✔
1598
    taosMemoryFree(pNode);
1,191,700✔
1599
    if (NULL == pBlock) {
1,191,700✔
UNCOV
1600
      continue;
×
1601
    }
1602

1603
    if (pBlock->info.rows > 0) {
1,191,700✔
1604
      pBlock->info.version = pOperator->pTaskInfo->version;
1,191,700✔
1605
      pBlock->info.dataLoad = 1;
1,191,700✔
1606
      pRuntime->pReturnedBlock = pBlock;
1,191,700✔
1607
      return pBlock;
1,191,700✔
1608
    }
1609

UNCOV
1610
    blockDataDestroy(pBlock);
×
1611
  }
1612

1613
  return NULL;
197,416✔
1614
}
1615

1616
void cleanupExprSupp(SExprSupp* pSupp) {
1,106,691,344✔
1617
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
1,106,691,344✔
1618
  if (pSupp->pExprInfo != NULL) {
1,106,642,786✔
1619
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
384,587,338✔
1620
    taosMemoryFreeClear(pSupp->pExprInfo);
384,589,535✔
1621
  }
1622

1623
  if (pSupp->pFilterInfo != NULL) {
1,106,632,321✔
1624
    filterFreeInfo(pSupp->pFilterInfo);
102,665,069✔
1625
    pSupp->pFilterInfo = NULL;
102,663,057✔
1626
  }
1627

1628
  taosMemoryFree(pSupp->rowEntryInfoOffset);
1,106,675,205✔
1629
  memset(pSupp, 0, sizeof(SExprSupp));
1,106,676,436✔
1630
}
1,106,676,436✔
1631

1632
void cleanupExprSuppWithoutFilter(SExprSupp* pSupp) {
113,351,493✔
1633
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
113,351,493✔
1634
  if (pSupp->pExprInfo != NULL) {
113,347,619✔
1635
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
32,212,190✔
1636
    taosMemoryFreeClear(pSupp->pExprInfo);
32,212,711✔
1637
  }
1638

1639
  taosMemoryFreeClear(pSupp->rowEntryInfoOffset);
113,347,371✔
1640
  pSupp->numOfExprs = 0;
113,352,173✔
1641
  pSupp->hasWindowOrGroup = false;
113,353,100✔
1642
  pSupp->pCtx = NULL;
113,345,128✔
1643
}
113,339,924✔
1644

1645
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
288,007,326✔
1646
  blockDataDestroy(pInfo->pRes);
288,007,326✔
1647
  pInfo->pRes = NULL;
288,011,120✔
1648
}
288,012,798✔
1649

1650
bool groupbyTbname(SNodeList* pGroupList) {
254,274,988✔
1651
  bool   bytbname = false;
254,274,988✔
1652
  SNode* pNode = NULL;
254,274,988✔
1653
  FOREACH(pNode, pGroupList) {
261,033,597✔
1654
    if (pNode->type == QUERY_NODE_FUNCTION) {
36,958,288✔
1655
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
30,195,969✔
1656
      break;
30,199,205✔
1657
    }
1658
  }
1659
  return bytbname;
254,276,322✔
1660
}
1661

1662
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
365,637,892✔
1663
  switch (pNode->type) {
365,637,892✔
1664
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
498,215✔
1665
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
498,215✔
1666
      if (NULL == pInserterParam) {
498,215✔
UNCOV
1667
        return terrno;
×
1668
      }
1669
      pInserterParam->readHandle = readHandle;
498,215✔
1670

1671
      *pParam = pInserterParam;
498,215✔
1672
      break;
498,215✔
1673
    }
1674
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
1,904,779✔
1675
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
1,904,779✔
1676
      if (NULL == pDeleterParam) {
1,859,119✔
UNCOV
1677
        return terrno;
×
1678
      }
1679

1680
      SArray* pInfoList = NULL;
1,859,119✔
1681
      int32_t code = getTableListInfo(pTask, &pInfoList);
1,859,119✔
1682
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
1,857,339✔
UNCOV
1683
        taosMemoryFree(pDeleterParam);
×
UNCOV
1684
        return code;
×
1685
      }
1686

1687
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
1,857,339✔
1688
      taosArrayDestroy(pInfoList);
1,858,529✔
1689

1690
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
1,858,519✔
1691

1692
      // TODO extract uid list
1693
      int32_t numOfTables = 0;
1,859,709✔
1694
      code = tableListGetSize(pTableListInfo, &numOfTables);
1,859,709✔
1695
      if (code != TSDB_CODE_SUCCESS) {
1,858,529✔
UNCOV
1696
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
UNCOV
1697
        taosMemoryFree(pDeleterParam);
×
UNCOV
1698
        return code;
×
1699
      }
1700

1701
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
1,858,529✔
1702
      if (NULL == pDeleterParam->pUidList) {
1,858,529✔
UNCOV
1703
        taosMemoryFree(pDeleterParam);
×
UNCOV
1704
        return terrno;
×
1705
      }
1706

1707
      for (int32_t i = 0; i < numOfTables; ++i) {
3,968,848✔
1708
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
2,110,319✔
1709
        if (!pTable) {
2,110,319✔
UNCOV
1710
          taosArrayDestroy(pDeleterParam->pUidList);
×
UNCOV
1711
          taosMemoryFree(pDeleterParam);
×
UNCOV
1712
          return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
1713
        }
1714
        void* tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
2,110,319✔
1715
        if (!tmp) {
2,110,319✔
UNCOV
1716
          taosArrayDestroy(pDeleterParam->pUidList);
×
UNCOV
1717
          taosMemoryFree(pDeleterParam);
×
UNCOV
1718
          return terrno;
×
1719
        }
1720
      }
1721

1722
      *pParam = pDeleterParam;
1,858,529✔
1723
      break;
1,859,709✔
1724
    }
1725
    default:
363,259,988✔
1726
      break;
363,259,988✔
1727
  }
1728

1729
  return TSDB_CODE_SUCCESS;
365,647,989✔
1730
}
1731

UNCOV
1732
void streamOpReleaseState(SOperatorInfo* pOperator) {
×
UNCOV
1733
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
UNCOV
1734
  if (downstream->fpSet.releaseStreamStateFn) {
×
UNCOV
1735
    downstream->fpSet.releaseStreamStateFn(downstream);
×
1736
  }
UNCOV
1737
}
×
1738

UNCOV
1739
void streamOpReloadState(SOperatorInfo* pOperator) {
×
UNCOV
1740
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
UNCOV
1741
  if (downstream->fpSet.reloadStreamStateFn) {
×
UNCOV
1742
    downstream->fpSet.reloadStreamStateFn(downstream);
×
1743
  }
UNCOV
1744
}
×
1745

1746
void freeOperatorParamImpl(SOperatorParam* pParam, SOperatorParamType type) {
138,121,844✔
1747
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
138,121,844✔
1748
  for (int32_t i = 0; i < childrenNum; ++i) {
139,905,587✔
1749
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
1,781,295✔
1750
    freeOperatorParam(pChild, type);
1,781,295✔
1751
  }
1752

1753
  taosArrayDestroy(pParam->pChildren);
138,124,292✔
1754
  pParam->pChildren = NULL;
138,130,620✔
1755

1756
  taosMemoryFreeClear(pParam->value);
138,129,290✔
1757

1758
  taosMemoryFree(pParam);
138,120,507✔
1759
}
138,116,218✔
1760

1761
void freeExchangeGetBasicOperatorParam(void* pParam) {
24,588,589✔
1762
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
24,588,589✔
1763
  if (pBasic->uidList) {
24,588,589✔
1764
    taosArrayDestroy(pBasic->uidList);
20,284,891✔
1765
    pBasic->uidList = NULL;
20,284,891✔
1766
  }
1767
  if (pBasic->orgTbInfo) {
24,588,589✔
1768
    taosArrayDestroy(pBasic->orgTbInfo->colMap);
11,223,198✔
1769
    taosMemoryFreeClear(pBasic->orgTbInfo);
11,223,198✔
1770
  }
1771
  if (pBasic->batchOrgTbInfo) {
24,588,589✔
1772
    taosArrayDestroyEx(pBasic->batchOrgTbInfo, destroySOrgTbInfo);
3,254,340✔
1773
    pBasic->batchOrgTbInfo = NULL;
3,254,340✔
1774
  }
1775
  if (pBasic->tagList) {
24,588,589✔
1776
    taosArrayDestroyEx(pBasic->tagList, destroyTagVal);
858,126✔
1777
    pBasic->tagList = NULL;
858,126✔
1778
  }
1779
}
24,588,589✔
1780

1781
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
23,377,252✔
1782
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
23,377,252✔
1783
  if (pExcParam->multiParams) {
23,377,252✔
1784
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
2,296,427✔
1785
    tSimpleHashSetFreeFp(pExcBatch->pBatchs, freeExchangeGetBasicOperatorParam);
2,296,427✔
1786
    tSimpleHashCleanup(pExcBatch->pBatchs);
2,296,427✔
1787
  } else {
1788
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
21,080,825✔
1789
  }
1790

1791
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
23,377,252✔
1792
}
23,377,252✔
1793

UNCOV
1794
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1795

1796
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
7,895,546✔
1797

UNCOV
1798
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1799

1800
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
3,947,773✔
1801

UNCOV
1802
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1803

1804
void freeTagScanGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
6,226,934✔
1805

1806
void freeMergeGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
4,870,818✔
1807

UNCOV
1808
void freeDynQueryCtrlGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
×
1809

UNCOV
1810
void freeDynQueryCtrlNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1811

UNCOV
1812
void freeInterpFuncGetOperatorParam(SOperatorParam* pParam) {
×
UNCOV
1813
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
×
UNCOV
1814
}
×
1815

UNCOV
1816
void freeInterpFuncNotifyOperatorParam(SOperatorParam* pParam) {
×
UNCOV
1817
  freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM);
×
UNCOV
1818
}
×
1819

1820
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
86,012,652✔
1821
  STableScanOperatorParam* pTableScanParam =
86,012,652✔
1822
    (STableScanOperatorParam*)pParam->value;
1823
  taosArrayDestroy(pTableScanParam->pUidList);
86,017,734✔
1824
  if (pTableScanParam->pOrgTbInfo) {
86,021,208✔
1825
    taosArrayDestroy(pTableScanParam->pOrgTbInfo->colMap);
75,122,734✔
1826
    taosMemoryFreeClear(pTableScanParam->pOrgTbInfo);
75,122,734✔
1827
  }
1828
  if (pTableScanParam->pBatchTbInfo) {
86,020,587✔
1829
    for (int32_t i = 0;
2,669,014✔
1830
      i < taosArrayGetSize(pTableScanParam->pBatchTbInfo); ++i) {
7,720,002✔
1831
      SOrgTbInfo* pOrgTbInfo =
1832
        (SOrgTbInfo*)taosArrayGet(pTableScanParam->pBatchTbInfo, i);
5,050,988✔
1833
      taosArrayDestroy(pOrgTbInfo->colMap);
5,050,988✔
1834
    }
1835
    taosArrayDestroy(pTableScanParam->pBatchTbInfo);
2,669,014✔
1836
    pTableScanParam->pBatchTbInfo = NULL;
2,669,014✔
1837
  }
1838
  if (pTableScanParam->pTagList) {
86,021,790✔
1839
    for (int32_t i = 0;
858,126✔
1840
      i < taosArrayGetSize(pTableScanParam->pTagList); ++i) {
5,314,056✔
1841
      STagVal* pTagVal =
1842
        (STagVal*)taosArrayGet(pTableScanParam->pTagList, i);
4,455,930✔
1843
      if (IS_VAR_DATA_TYPE(pTagVal->type)) {
4,455,930✔
1844
        taosMemoryFreeClear(pTagVal->pData);
1,934,226✔
1845
      }
1846
    }
1847
    taosArrayDestroy(pTableScanParam->pTagList);
858,126✔
1848
    pTableScanParam->pTagList = NULL;
858,126✔
1849
  }
1850
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
86,023,685✔
1851
}
86,006,285✔
1852

UNCOV
1853
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1854

UNCOV
1855
void freeTagScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1856

UNCOV
1857
void freeMergeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1858

1859
void freeOpParamItem(void* pItem) {
16,005,386✔
1860
  SOperatorParam* pParam = *(SOperatorParam**)pItem;
16,005,386✔
1861
  pParam->reUse = false;
16,005,386✔
1862
  freeOperatorParam(pParam, OP_GET_PARAM);
16,005,386✔
1863
}
16,005,386✔
1864

1865
static void destroyRefColIdGroupParam(void* info) {
8,488✔
1866
  SRefColIdGroup* pGroup = (SRefColIdGroup*)info;
8,488✔
1867
  if (pGroup && pGroup->pSlotIdList) {
8,488✔
1868
    taosArrayDestroy(pGroup->pSlotIdList);
8,488✔
1869
    pGroup->pSlotIdList = NULL;
8,488✔
1870
  }
1871
}
8,488✔
1872

1873
void freeExternalWindowGetOperatorParam(SOperatorParam* pParam) {
1,008,801✔
1874
  SExternalWindowOperatorParam *pExtParam = (SExternalWindowOperatorParam*)pParam->value;
1,008,801✔
1875
  taosArrayDestroy(pExtParam->ExtWins);
1,008,801✔
1876
  for (int32_t i = 0; i < taosArrayGetSize(pParam->pChildren); i++) {
1,008,801✔
UNCOV
1877
    SOperatorParam* pChild = *(SOperatorParam**)taosArrayGet(pParam->pChildren, i);
×
UNCOV
1878
    pChild->reUse = false;
×
1879
  }
1880
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
1,008,801✔
1881
}
1,008,801✔
1882

1883
void freeVirtualTableScanGetOperatorParam(SOperatorParam* pParam) {
4,782,188✔
1884
  SVTableScanOperatorParam* pVTableScanParam = (SVTableScanOperatorParam*)pParam->value;
4,782,188✔
1885
  taosArrayDestroyEx(pVTableScanParam->pOpParamArray, freeOpParamItem);
4,782,188✔
1886
  if (pVTableScanParam->pRefColGroups) {
4,782,188✔
1887
    taosArrayDestroyEx(pVTableScanParam->pRefColGroups, destroyRefColIdGroupParam);
5,228✔
1888
    pVTableScanParam->pRefColGroups = NULL;
5,228✔
1889
  }
1890
  freeOpParamItem(&pVTableScanParam->pTagScanOp);
4,782,188✔
1891
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
4,782,188✔
1892
}
4,782,188✔
1893

UNCOV
1894
void freeVTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1895

UNCOV
1896
void freeExternalWindowNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1897

1898
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
802,609,704✔
1899
  if (NULL == pParam || pParam->reUse) {
802,609,704✔
1900
    return;
664,480,160✔
1901
  }
1902

1903
  switch (pParam->opType) {
138,131,427✔
1904
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
23,377,252✔
1905
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
23,377,252✔
1906
      break;
23,377,252✔
1907
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
7,895,546✔
1908
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
7,895,546✔
1909
      break;
7,895,546✔
1910
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
3,947,773✔
1911
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
3,947,773✔
1912
      break;
3,947,773✔
1913
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
86,021,822✔
1914
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
1915
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
86,021,822✔
1916
      break;
86,008,783✔
1917
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
4,782,188✔
1918
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
4,782,188✔
1919
      break;
4,782,188✔
1920
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
6,226,934✔
1921
      type == OP_GET_PARAM ? freeTagScanGetOperatorParam(pParam) : freeTagScanNotifyOperatorParam(pParam);
6,226,934✔
1922
      break;
6,226,934✔
1923
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
4,870,818✔
1924
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
1925
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
1926
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL:
1927
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
1928
      type == OP_GET_PARAM ? freeMergeGetOperatorParam(pParam) : freeMergeNotifyOperatorParam(pParam);
4,870,818✔
1929
      break;
4,868,905✔
1930
    case QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW:
1,008,801✔
1931
      type == OP_GET_PARAM ? freeExternalWindowGetOperatorParam(pParam) : freeExternalWindowNotifyOperatorParam(pParam);
1,008,801✔
1932
      break;
1,008,801✔
UNCOV
1933
    case QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL:
×
UNCOV
1934
      type == OP_GET_PARAM ? freeDynQueryCtrlGetOperatorParam(pParam) : freeDynQueryCtrlNotifyOperatorParam(pParam);
×
UNCOV
1935
      break;
×
UNCOV
1936
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
×
UNCOV
1937
      type == OP_GET_PARAM ? freeInterpFuncGetOperatorParam(pParam) : freeInterpFuncNotifyOperatorParam(pParam);
×
UNCOV
1938
      break;
×
1939
    default:
5,675✔
1940
      qError("%s unsupported op %d param, param type %d, param:%p value:%p children:%p reuse:%d",
5,675✔
1941
             __func__, pParam->opType, type, pParam, pParam->value, pParam->pChildren, pParam->reUse);
UNCOV
1942
      break;
×
1943
  }
1944
}
1945

1946
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
1,726,557,683✔
1947
  SOperatorParam**  ppParam = NULL;
1,726,557,683✔
1948
  SOperatorParam*** pppDownstramParam = NULL;
1,726,557,683✔
1949
  switch (type) {
1,726,557,683✔
1950
    case OP_GET_PARAM:
917,395,942✔
1951
      ppParam = &pOperator->pOperatorGetParam;
917,395,942✔
1952
      pppDownstramParam = &pOperator->pDownstreamGetParams;
917,402,945✔
1953
      break;
917,394,382✔
1954
    case OP_NOTIFY_PARAM:
809,195,931✔
1955
      ppParam = &pOperator->pOperatorNotifyParam;
809,195,931✔
1956
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
809,200,917✔
1957
      break;
809,206,047✔
UNCOV
1958
    default:
×
UNCOV
1959
      return;
×
1960
  }
1961

1962
  if (*ppParam) {
1,726,600,429✔
1963
    qDebug("%s free self param, operator:%s type:%d paramType:%d param:%p", __func__, pOperator->name,
8,817,817✔
1964
           pOperator->operatorType, type, *ppParam);
1965
    freeOperatorParam(*ppParam, type);
8,817,817✔
1966
    *ppParam = NULL;
8,817,817✔
1967
  }
1968

1969
  if (*pppDownstramParam) {
1,726,570,328✔
1970
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
135,151,855✔
1971
      if ((*pppDownstramParam)[i]) {
23,778,453✔
UNCOV
1972
        qDebug("%s free downstream param, operator:%s type:%d idx:%d downstream:%s paramType:%d param:%p", __func__,
×
1973
               pOperator->name, pOperator->operatorType, i, pOperator->pDownstream[i]->name, type,
1974
               (*pppDownstramParam)[i]);
UNCOV
1975
        freeOperatorParam((*pppDownstramParam)[i], type);
×
UNCOV
1976
        (*pppDownstramParam)[i] = NULL;
×
1977
      }
1978
    }
1979
    if (allFree) {
111,374,005✔
1980
      taosMemoryFreeClear(*pppDownstramParam);
21,917,375✔
1981
    }
1982
  }
1983
}
1984

1985
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
1,134,633,788✔
1986
                                                    SSDataBlock** pResBlock) {
1987
  QRY_PARAM_CHECK(pResBlock);
1,134,633,788✔
1988

1989
  int32_t code = 0;
1,134,692,183✔
1990
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
1,134,692,183✔
1991
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
19,496,921✔
1992
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
38,994,371✔
1993
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
19,496,921✔
1994
    if (clearParam && (code == 0)) {
19,496,921✔
1995
      qDebug("%s clear downstream param, operator:%s type:%d idx:%d downstream:%s param:%p", __func__,
7,493,801✔
1996
             pOperator->name, pOperator->operatorType, idx, pOperator->pDownstream[idx]->name,
1997
             pOperator->pDownstreamGetParams[idx]);
1998
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
7,493,801✔
1999
      pOperator->pDownstreamGetParams[idx] = NULL;
7,493,801✔
2000
    }
2001

2002
    if (code) {
19,496,921✔
UNCOV
2003
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
2004
    }
2005
    return code;
19,496,921✔
2006
  }
2007

2008
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
1,115,165,254✔
2009
  if (code) {
1,112,544,636✔
UNCOV
2010
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
2011
  }
2012
  return code;
1,112,538,199✔
2013
}
2014

2015
bool compareVal(const char* v, const SStateKeys* pKey) {
2,147,483,647✔
2016
  if (IS_VAR_DATA_TYPE(pKey->type)) {
2,147,483,647✔
2017
    if (IS_STR_DATA_BLOB(pKey->type)) {
323,545✔
UNCOV
2018
      if (blobDataLen(v) != blobDataLen(pKey->pData)) {
×
UNCOV
2019
        return false;
×
2020
      } else {
UNCOV
2021
        return memcmp(blobDataVal(v), blobDataVal(pKey->pData), blobDataLen(v)) == 0;
×
2022
      }
2023
    } else {
2024
      if (varDataLen(v) != varDataLen(pKey->pData)) {
323,545✔
UNCOV
2025
        return false;
×
2026
      } else {
2027
        return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
323,545✔
2028
      }
2029
    }
2030
  } else {
2031
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
2,147,483,647✔
2032
  }
2033
}
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