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

taosdata / TDengine / #5049

11 May 2026 06:30AM UTC coverage: 73.313% (+0.09%) from 73.222%
#5049

push

travis-ci

web-flow
feat: refactor taosdump code to improve backup speed and compression ratio (#35292)

6625 of 8435 new or added lines in 28 files covered. (78.54%)

2491 existing lines in 142 files now uncovered.

281233 of 383605 relevant lines covered (73.31%)

132489999.79 hits per line

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

76.9
/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);
284,217,809✔
91
    if (pData == NULL) {
284,210,973✔
92
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
93
      return NULL;
×
94
    }
95
    pData->num = sizeof(SFilePage);
284,210,973✔
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);
986,503,102✔
108

109
      pData = getNewBufPage(pResultBuf, &pageId);
986,538,682✔
110
      if (pData == NULL) {
986,371,501✔
111
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
112
        return NULL;
×
113
      }
114
      pData->num = sizeof(SFilePage);
986,371,501✔
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,842,086,991✔
156
      if (pResult == NULL) {
1,842,086,991✔
157
        pTaskInfo->code = terrno;
×
158
        return NULL;
×
159
      }
160

161
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
1,842,086,991✔
162
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
3,385✔
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;
228✔
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));
13✔
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) {
11,211,616✔
232
  pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
11,211,616✔
233
  pColData->info.bytes = sizeof(int64_t);
11,214,522✔
234

235
  int32_t code = colInfoDataEnsureCapacity(pColData, 6, false);
11,209,664✔
236
  if (code != TSDB_CODE_SUCCESS) {
11,214,516✔
237
    return code;
×
238
  }
239
  colDataSetInt64(pColData, 0, &pQueryWindow->skey);
11,214,516✔
240
  colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
11,210,546✔
241

242
  int64_t interval = 0;
11,208,063✔
243
  colDataSetInt64(pColData, 2, &interval);  // this value may be variable in case of 'n' and 'y'.
244
  colDataSetInt64(pColData, 3, &pQueryWindow->skey);
11,206,651✔
245
  colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
11,205,422✔
246

247
  interval = -1;
11,205,019✔
248
  colDataSetInt64(pColData, 5,  &interval);
249
  return TSDB_CODE_SUCCESS;
11,205,123✔
250
}
251

252
static int32_t doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
26,202,955✔
253
  int32_t         code = TSDB_CODE_SUCCESS;
26,202,955✔
254
  int32_t         lino = 0;
26,202,955✔
255
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
26,202,955✔
256
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
143,237,497✔
257
    pCtx[i].order = order;
116,983,617✔
258
    pCtx[i].input.numOfRows = pBlock->info.rows;
116,991,765✔
259
    code = setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock);
116,997,245✔
260
    QUERY_CHECK_CODE(code, lino, _end);
117,010,049✔
261
    pCtx[i].pSrcBlock = pBlock;
117,010,049✔
262
    pCtx[i].scanFlag = scanFlag;
117,002,496✔
263
  }
264

265
_end:
26,250,500✔
266
  if (code != TSDB_CODE_SUCCESS) {
26,250,500✔
267
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
268
  }
269
  return code;
26,253,222✔
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);
26,249,143✔
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,
340,122,702✔
282
                                             int32_t numOfRows) {
283
  int32_t          code = TSDB_CODE_SUCCESS;
340,122,702✔
284
  int32_t          lino = 0;
340,122,702✔
285
  SColumnInfoData* pColInfo = NULL;
340,122,702✔
286
  if (pInput->pData[paramIndex] == NULL) {
340,122,702✔
287
    pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
766,947✔
288
    QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno);
766,947✔
289

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

294
    pInput->pData[paramIndex] = pColInfo;
766,947✔
295
  } else {
296
    pColInfo = pInput->pData[paramIndex];
339,388,379✔
297
  }
298

299
  code = colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
340,156,151✔
300
  QUERY_CHECK_CODE(code, lino, _end);
340,116,351✔
301

302
  int8_t type = pFuncParam->param.nType;
340,116,351✔
303
  if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
340,129,414✔
304
    int64_t v = pFuncParam->param.i;
537,453✔
305
    for (int32_t i = 0; i < numOfRows; ++i) {
1,084,561,172✔
306
      colDataSetInt64(pColInfo, i, &v);
1,084,050,488✔
307
    }
308
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
339,591,961✔
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) {
339,591,961✔
UNCOV
314
    char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
×
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:
339,619,638✔
326
  if (code != TSDB_CODE_SUCCESS) {
340,130,322✔
327
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
328
  }
329
  return code;
340,099,674✔
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];
158,841,381✔
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) {
717,626,356✔
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);
514,955,184✔
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 &&
514,936,844✔
384
            pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION &&
49,473,099✔
385
            fmIsIndefiniteRowsFunc(pOneExpr->pExpr->_function.functionId)) {
15,323,329✔
386
          needDummyCol = true;
×
387
        }
388
        if (needDummyCol) {
514,926,836✔
389
          pInput->totalRows = pBlock->info.rows;
340,101,066✔
390
          pInput->numOfRows = pBlock->info.rows;
340,135,666✔
391
          pInput->startRowIndex = 0;
340,127,227✔
392
          pInput->blankFill = pBlock->info.blankFill;
340,122,040✔
393

394
          code = doCreateConstantValColumnInfo(pInput, pFuncParam, j, pBlock->info.rows);
340,149,439✔
395
          QUERY_CHECK_CODE(code, lino, _end);
325,982,480✔
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,720,931✔
419
  }
420

421
  if (isRowEntryCompleted(pResInfo)) {
2,147,483,647✔
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) {
116,967,438✔
479
  int32_t code = TSDB_CODE_SUCCESS;
116,967,438✔
480
  int32_t lino = 0;
116,967,438✔
481
  int32_t numOfRows = pBlock->info.rows;
116,967,438✔
482

483
  SInputColumnInfoData* pInput = &pCtx->input;
117,007,381✔
484
  pInput->numOfRows = numOfRows;
117,006,709✔
485
  pInput->totalRows = numOfRows;
117,010,080✔
486

487
  if (pBlock->pBlockAgg != NULL) {
117,015,488✔
488
    pInput->colDataSMAIsSet = true;
117,020,229✔
489

490
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
234,028,281✔
491
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
117,022,275✔
492

493
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
117,028,350✔
494
        int32_t slotId = pFuncParam->pCol->slotId;
117,034,434✔
495
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
117,033,046✔
496
        if (pInput->pColumnDataAgg[j]->colId == -1) {
117,029,666✔
497
          pInput->colDataSMAIsSet = false;
21,351✔
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);
117,024,943✔
503
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
×
504
        code = doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
×
UNCOV
505
        QUERY_CHECK_CODE(code, lino, _end);
×
506
      }
507
    }
508
  } else {
509
    pInput->colDataSMAIsSet = false;
×
510
  }
511

512
_end:
116,764,788✔
513
  if (code != TSDB_CODE_SUCCESS) {
116,764,788✔
514
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
515
  }
516
  return code;
116,992,338✔
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) {
685,639,915✔
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
}
685,639,915✔
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};
207,482,450✔
598
  SColumnInfoData*   p = NULL;
207,476,754✔
599

600
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
207,466,312✔
601
  QUERY_CHECK_CODE(code, lino, _err);
207,479,439✔
602

603
  int32_t status = 0;
207,479,439✔
604
  code =
605
      filterExecute(pFilterInfo, pBlock, pRet != NULL ? pRet : &p, NULL, param1.numOfCols, &status);
207,479,754✔
606
  QUERY_CHECK_CODE(code, lino, _err);
207,448,773✔
607

608
  code = extractQualifiedTupleByFilterResult(pBlock, pRet != NULL ? *pRet : p, status);
206,342,799✔
609
  QUERY_CHECK_CODE(code, lino, _err);
206,365,277✔
610

611
  if (pColMatchInfo != NULL) {
206,365,277✔
612
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
152,026,538✔
613
    for (int32_t i = 0; i < size; ++i) {
152,190,196✔
614
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
152,020,513✔
615
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
152,015,709✔
616
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
152,015,709✔
617
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
151,859,343✔
618
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
151,843,396✔
619
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
151,843,396✔
620
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
151,852,449✔
621
          QUERY_CHECK_CODE(code, lino, _err);
151,849,591✔
622
          break;
151,849,591✔
623
        }
624
      }
625
    }
626
  }
627
  code = blockDataCheck(pBlock);
206,358,013✔
628
  QUERY_CHECK_CODE(code, lino, _err);
206,360,667✔
629
_err:
207,466,641✔
630
  if (code != TSDB_CODE_SUCCESS) {
207,493,693✔
631
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1,105,974✔
632
  }
633
  colDataDestroy(p);
207,493,693✔
634
  taosMemoryFree(p);
207,481,675✔
635
  return code;
207,458,192✔
636
}
637

638
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
206,557,394✔
639
  int32_t code = TSDB_CODE_SUCCESS;
206,557,394✔
640
  int8_t* pIndicator = (int8_t*)p->pData;
206,557,394✔
641
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
206,574,345✔
642
    // here nothing needs to be done
643
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
129,470,578✔
644
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
53,435,721✔
645
    pBlock->info.rows = 0;
53,441,818✔
646
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
76,034,857✔
647
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
76,044,176✔
648
  } else {
649
    qError("unknown filter result type: %d", status);
×
650
  }
651
  return code;
206,570,866✔
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);
862,580✔
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
bool resultRowGetGroupKeyResult(const SResultRow* pRow, int32_t index, const int32_t* rowEntryOffset,
22,950✔
752
                                const void** ppData, bool* pIsNull) {
753
  if (pRow == NULL) {
22,950✔
754
    return false;
×
755
  }
756

757
  SResultRowEntryInfo* pEntryInfo = getResultEntryInfo(pRow, index, rowEntryOffset);
22,950✔
758
  SGroupKeyInfo*       pGroupKey = GET_ROWCELL_INTERBUF(pEntryInfo);
22,950✔
759

760
  if (ppData != NULL) {
22,950✔
761
    *ppData = pGroupKey->data;
22,950✔
762
  }
763
  if (pIsNull != NULL) {
22,950✔
764
    *pIsNull = pGroupKey->isNull;
22,950✔
765
  }
766

767
  return pGroupKey->hasResult;
22,950✔
768
}
769

770
bool resultRowCopyGroupKeyResult(SResultRow* pDstRow, int32_t dstIndex, const SResultRow* pSrcRow, int32_t srcIndex,
×
771
                                 const int32_t* rowEntryOffset, int32_t interBufSize) {
772
  if (pDstRow == NULL || pSrcRow == NULL) {
×
773
    return false;
×
774
  }
775

776
  SResultRowEntryInfo* pSrcEntry = getResultEntryInfo(pSrcRow, srcIndex, rowEntryOffset);
×
777
  SGroupKeyInfo*       pSrcGroupKey = GET_ROWCELL_INTERBUF(pSrcEntry);
×
778
  if (!pSrcGroupKey->hasResult) {
×
779
    return false;
×
780
  }
781

782
  SResultRowEntryInfo* pDstEntry = getResultEntryInfo(pDstRow, dstIndex, rowEntryOffset);
×
783
  memcpy(GET_ROWCELL_INTERBUF(pDstEntry), pSrcGroupKey, interBufSize);
×
784
  pDstEntry->numOfRes = 1;
×
785
  pDstEntry->isNullRes = pSrcGroupKey->isNull ? 1 : 0;
×
786

787
  return true;
×
788
}
789

790
// todo refactor. SResultRow has direct pointer in miainfo
791
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
1,044,553,543✔
792
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
793
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
1,044,553,543✔
794
  if (page == NULL) {
1,044,552,445✔
795
    qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
796
    T_LONG_JMP(pTaskInfo->env, terrno);
×
797
  }
798

799
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
1,044,552,445✔
800

801
  SqlFunctionCtx* pCtx = pSup->pCtx;
1,044,554,004✔
802
  SExprInfo*      pExprInfo = pSup->pExprInfo;
1,044,555,197✔
803
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
1,044,557,033✔
804

805
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
1,044,556,940✔
806
  if (pRow->numOfRows == 0) {
1,044,554,829✔
807
    releaseBufPage(pBuf, page);
×
808
    return;
×
809
  }
810

811
  int32_t size = pBlock->info.capacity;
1,044,552,627✔
812
  while (pBlock->info.rows + pRow->numOfRows > size) {
1,044,793,182✔
813
    size = size * 1.25;
240,373✔
814
  }
815

816
  int32_t code = blockDataEnsureCapacity(pBlock, size);
1,044,554,186✔
817
  if (TAOS_FAILED(code)) {
1,044,550,698✔
818
    releaseBufPage(pBuf, page);
×
819
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
820
    T_LONG_JMP(pTaskInfo->env, code);
×
821
  }
822

823
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
1,044,550,698✔
824
  if (TAOS_FAILED(code)) {
1,044,550,241✔
825
    releaseBufPage(pBuf, page);
×
826
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
827
    T_LONG_JMP(pTaskInfo->env, code);
×
828
  }
829

830
  releaseBufPage(pBuf, page);
1,044,550,241✔
831
  pBlock->info.rows += pRow->numOfRows;
1,044,550,152✔
832
}
833

834
void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
2,147,483,647✔
835
                              SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup) {
836
  int32_t         code = TSDB_CODE_SUCCESS;
2,147,483,647✔
837
  int32_t         lino = 0;
2,147,483,647✔
838
  SExprInfo*      pExprInfo = pSup->pExprInfo;
2,147,483,647✔
839
  int32_t         numOfExprs = pSup->numOfExprs;
2,147,483,647✔
840
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
2,147,483,647✔
841
  SqlFunctionCtx* pCtx = pSup->pCtx;
2,147,483,647✔
842

843
  size_t  keyLen = 0;
2,147,483,647✔
844
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
2,147,483,647✔
845

846
  // begin from last iter
847
  void*   pData = pGroupResInfo->dataPos;
2,147,483,647✔
848
  int32_t iter = pGroupResInfo->iter;
2,147,483,647✔
849
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
2,147,483,647✔
850
    void*               key = tSimpleHashGetKey(pData, &keyLen);
2,147,483,647✔
851
    SResultRowPosition* pos = pData;
2,147,483,647✔
852
    uint64_t            groupId = calcGroupId((char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t));
2,147,483,647✔
853

854
    SFilePage* page = getBufPage(pBuf, pos->pageId);
2,147,483,647✔
855
    if (page == NULL) {
2,147,483,647✔
856
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
857
      T_LONG_JMP(pTaskInfo->env, terrno);
×
858
    }
859

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

862
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
2,147,483,647✔
863

864
    // no results, continue to check the next one
865
    if (pRow->numOfRows == 0) {
2,147,483,647✔
866
      pGroupResInfo->index += 1;
×
867
      pGroupResInfo->iter = iter;
×
868
      pGroupResInfo->dataPos = pData;
×
869

870
      releaseBufPage(pBuf, page);
×
871
      continue;
×
872
    }
873

874
    if (!ignoreGroup) {
2,147,483,647✔
875
      if (pBlock->info.id.groupId == 0) {
2,147,483,647✔
876
        pBlock->info.id.groupId = groupId;
2,147,483,647✔
877
      } else {
878
        // current value belongs to different group, it can't be packed into one datablock
879
        if (pBlock->info.id.groupId != groupId) {
2,147,483,647✔
880
          releaseBufPage(pBuf, page);
2,147,483,647✔
881
          break;
2,147,483,647✔
882
        }
883
      }
884
    }
885

886
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
2,147,483,647✔
887
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - iter) > 1 ? 1 : 0);
×
888
      code = blockDataEnsureCapacity(pBlock, newSize);
×
889
      QUERY_CHECK_CODE(code, lino, _end);
×
890
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
891
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
892
      // todo set the pOperator->resultInfo size
893
    }
894

895
    pGroupResInfo->index += 1;
2,147,483,647✔
896
    pGroupResInfo->iter = iter;
2,147,483,647✔
897
    pGroupResInfo->dataPos = pData;
2,147,483,647✔
898

899
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
2,147,483,647✔
900
    releaseBufPage(pBuf, page);
2,147,483,647✔
901
    QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
902
    pBlock->info.rows += pRow->numOfRows;
2,147,483,647✔
903
    if (pBlock->info.rows >= threshold) {
2,147,483,647✔
904
      break;
18,056✔
905
    }
906
  }
907

908
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
2,147,483,647✔
909
         pBlock->info.id.groupId);
910
  pBlock->info.dataLoad = 1;
2,147,483,647✔
911
  code = blockDataUpdateTsWindow(pBlock, 0);
2,147,483,647✔
912
  QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
913

914
_end:
2,147,483,647✔
915
  if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
916
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
917
    T_LONG_JMP(pTaskInfo->env, code);
×
918
  }
919
}
2,147,483,647✔
920

921
void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
128,578,400✔
922
                        SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup, STrueForInfo *pTrueForInfo) {
923
  int32_t         code = TSDB_CODE_SUCCESS;
128,578,400✔
924
  int32_t         lino = 0;
128,578,400✔
925
  SExprInfo*      pExprInfo = pSup->pExprInfo;
128,578,400✔
926
  int32_t         numOfExprs = pSup->numOfExprs;
128,578,961✔
927
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
128,571,562✔
928
  SqlFunctionCtx* pCtx = pSup->pCtx;
128,576,390✔
929

930
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
128,578,370✔
931

932
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
2,147,483,647✔
933
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
2,147,483,647✔
934
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
2,147,483,647✔
935
    if (page == NULL) {
2,147,483,647✔
936
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
937
      T_LONG_JMP(pTaskInfo->env, terrno);
×
938
    }
939

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

942
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
2,147,483,647✔
943

944
    // no results, continue to check the next one
945
    if (pRow->numOfRows == 0) {
2,147,483,647✔
946
      pGroupResInfo->index += 1;
131,195✔
947
      releaseBufPage(pBuf, page);
131,195✔
948
      continue;
131,195✔
949
    }
950
    // skip the window which is less than the windowMinSize
951
    if (!isTrueForSatisfied(pTrueForInfo, pRow->win.skey, pRow->win.ekey, pRow->nOrigRows)) {
2,147,483,647✔
952
      qDebug("skip small window, groupId: %" PRId64 ", skey: %" PRId64 ", ekey: %" PRId64 ", nrows: %u", pPos->groupId,
51,870✔
953
             pRow->win.skey, pRow->win.ekey, pRow->nOrigRows);
954
      pGroupResInfo->index += 1;
51,870✔
955
      releaseBufPage(pBuf, page);
51,870✔
956
      continue;
51,870✔
957
    }
958

959
    if (!ignoreGroup) {
2,147,483,647✔
960
      if (pBlock->info.id.groupId == 0) {
2,147,483,647✔
961
        pBlock->info.id.groupId = pPos->groupId;
2,147,483,647✔
962
      } else {
963
        // current value belongs to different group, it can't be packed into one datablock
964
        if (pBlock->info.id.groupId != pPos->groupId) {
2,147,483,647✔
965
          releaseBufPage(pBuf, page);
21,476,581✔
966
          break;
21,476,581✔
967
        }
968
      }
969
    }
970

971
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
2,147,483,647✔
972
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - i) > 1 ? 1 : 0);
×
973
      code = blockDataEnsureCapacity(pBlock, newSize);
×
974
      QUERY_CHECK_CODE(code, lino, _end);
×
975
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
976
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
977
      // todo set the pOperator->resultInfo size
978
    }
979

980
    pGroupResInfo->index += 1;
2,147,483,647✔
981
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
2,147,483,647✔
982
    releaseBufPage(pBuf, page);
2,147,483,647✔
983
    QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
984

985
    pBlock->info.rows += pRow->numOfRows;
2,147,483,647✔
986
    if (pBlock->info.rows >= threshold) {
2,147,483,647✔
987
      break;
18,726,198✔
988
    }
989
  }
990

991
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
128,415,133✔
992
         pBlock->info.id.groupId);
993
  pBlock->info.dataLoad = 1;
128,428,160✔
994
  code = blockDataUpdateTsWindow(pBlock, 0);
128,588,491✔
995
  QUERY_CHECK_CODE(code, lino, _end);
128,584,541✔
996

997
_end:
128,584,541✔
998
  if (code != TSDB_CODE_SUCCESS) {
128,584,541✔
999
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1000
    T_LONG_JMP(pTaskInfo->env, code);
×
1001
  }
1002
}
128,584,541✔
1003

1004
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
151,183,164✔
1005
                            SDiskbasedBuf* pBuf) {
1006
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
151,183,164✔
1007
  SSDataBlock*   pBlock = pbInfo->pRes;
151,187,667✔
1008

1009
  // set output datablock version
1010
  pBlock->info.version = pTaskInfo->version;
151,185,100✔
1011

1012
  blockDataCleanup(pBlock);
151,183,762✔
1013
  if (!hasRemainResults(pGroupResInfo)) {
151,192,285✔
1014
    return;
23,074,988✔
1015
  }
1016

1017
  // clear the existed group id
1018
  pBlock->info.id.groupId = 0;
128,113,453✔
1019
  if (!pbInfo->mergeResultBlock) {
128,112,797✔
1020
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
49,754,967✔
1021
                       false, getTrueForInfo(pOperator));
1022
  } else {
1023
    while (hasRemainResults(pGroupResInfo)) {
145,684,545✔
1024
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
78,354,766✔
1025
                         true, getTrueForInfo(pOperator));
1026
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
78,354,621✔
1027
        break;
11,026,463✔
1028
      }
1029

1030
      // clearing group id to continue to merge data that belong to different groups
1031
      pBlock->info.id.groupId = 0;
67,329,408✔
1032
    }
1033

1034
    // clear the group id info in SSDataBlock, since the client does not need it
1035
    pBlock->info.id.groupId = 0;
78,355,863✔
1036
  }
1037
}
1038

1039
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
451,207,077✔
1040
  for (int32_t i = 0; i < numOfExprs; ++i) {
1,745,928,304✔
1041
    SExprInfo* pExprInfo = &pExpr[i];
1,294,681,238✔
1042
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
2,147,483,647✔
1043
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
1,466,731,315✔
1044
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
1,208,325,218✔
1045
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
258,378,164✔
1046
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
147,796,928✔
1047
      }
1048
    }
1049

1050
    taosMemoryFree(pExprInfo->base.pParam);
1,294,746,135✔
1051
    taosMemoryFree(pExprInfo->pExpr);
1,294,801,940✔
1052
  }
1053
}
451,247,066✔
1054

1055
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
324,428,297✔
1056
  *defaultPgsz = 4096;
324,428,297✔
1057
  uint32_t last = *defaultPgsz;
324,438,834✔
1058
  while (*defaultPgsz < rowSize * 4) {
391,067,589✔
1059
    *defaultPgsz <<= 1u;
66,651,087✔
1060
    if (*defaultPgsz < last) {
66,632,462✔
1061
      return TSDB_CODE_INVALID_PARA;
×
1062
    }
1063
    last = *defaultPgsz;
66,633,767✔
1064
  }
1065

1066
  // The default buffer for each operator in query is 10MB.
1067
  // at least four pages need to be in buffer
1068
  // TODO: make this variable to be configurable.
1069
  *defaultBufsz = 4096 * 2560;
324,227,478✔
1070
  if ((*defaultBufsz) <= (*defaultPgsz)) {
324,384,492✔
1071
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
1072
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
1073
      return TSDB_CODE_INVALID_PARA;
×
1074
    }
1075
  }
1076

1077
  return 0;
324,367,760✔
1078
}
1079

1080
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
691,667,591✔
1081
  if (numOfRows == 0) {
691,667,591✔
1082
    numOfRows = 4096;
×
1083
  }
1084

1085
  pResultInfo->capacity = numOfRows;
691,667,591✔
1086
  pResultInfo->threshold = numOfRows * 0.75;
691,857,301✔
1087

1088
  if (pResultInfo->threshold == 0) {
691,803,247✔
1089
    pResultInfo->threshold = numOfRows;
2,039,898✔
1090
  }
1091
  pResultInfo->totalRows = 0;
691,855,101✔
1092
}
691,702,914✔
1093

1094
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
305,170,451✔
1095
  pInfo->pRes = pBlock;
305,170,451✔
1096
  initResultRowInfo(&pInfo->resultRowInfo);
305,228,692✔
1097
}
305,081,064✔
1098

1099
void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
1,311,186,673✔
1100
  if (pCtx == NULL) {
1,311,186,673✔
1101
    return;
830,355,923✔
1102
  }
1103

1104
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,762,089,843✔
1105
    if (pExpr != NULL) {
1,281,288,831✔
1106
      SExprInfo* pExprInfo = &pExpr[i];
1,281,267,172✔
1107
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
2,147,483,647✔
1108
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
1,452,384,370✔
1109
          colDataDestroy(pCtx[i].input.pData[j]);
145,357,048✔
1110
          taosMemoryFree(pCtx[i].input.pData[j]);
145,363,059✔
1111
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
145,348,110✔
1112
        }
1113
      }
1114
    }
1115
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
2,147,483,647✔
1116
      taosVariantDestroy(&pCtx[i].param[j].param);
1,452,386,402✔
1117
    }
1118

1119
    if(pCtx[i].fpSet.cleanup) {
1,281,314,517✔
1120
      pCtx[i].fpSet.cleanup(&pCtx[i]);
1,012,219✔
1121
    }
1122

1123
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
1,281,331,623✔
1124
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
1,281,315,951✔
1125
    taosMemoryFree(pCtx[i].input.pData);
1,281,335,080✔
1126
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
1,281,260,503✔
1127

1128
    if (pCtx[i].udfName != NULL) {
1,281,273,207✔
1129
      taosMemoryFree(pCtx[i].udfName);
52,306✔
1130
    }
1131
  }
1132

1133
  taosMemoryFreeClear(pCtx);
480,801,012✔
1134
  return;
480,813,445✔
1135
}
1136

1137
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
476,564,883✔
1138
  pSup->pExprInfo = pExprInfo;
476,564,883✔
1139
  pSup->numOfExprs = numOfExpr;
476,601,884✔
1140
  if (pSup->pExprInfo != NULL) {
476,524,998✔
1141
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
371,220,759✔
1142
    if (pSup->pCtx == NULL) {
371,116,513✔
1143
      return terrno;
×
1144
    }
1145
  }
1146

1147
  return TSDB_CODE_SUCCESS;
476,358,856✔
1148
}
1149

1150
void checkIndefRowsFuncs(SExprSupp* pSup) {
9,547✔
1151
  for (int32_t i = 0; i < pSup->numOfExprs; ++i) {
27,580✔
1152
    if (fmIsIndefiniteRowsFunc(pSup->pCtx[i].functionId)) {
18,033✔
1153
      pSup->hasIndefRowsFunc = true;
×
1154
      break;
×
1155
    }
1156
  }
1157
}
9,547✔
1158

1159
static void cleanupIndefRowsResultRow(SOperatorInfo* pOperator, SResultRow* pRow) {
11,081,787✔
1160
  if (NULL == pOperator || NULL == pRow) {
11,081,787✔
1161
    return;
×
1162
  }
1163

1164
  SExprSupp* pSup = &pOperator->exprSupp;
11,081,787✔
1165
  for (int32_t i = 0; i < pSup->numOfExprs; ++i) {
24,745,932✔
1166
    pSup->pCtx[i].resultInfo = getResultEntryInfo(pRow, i, pSup->rowEntryInfoOffset);
13,664,145✔
1167
    if (pSup->pCtx[i].fpSet.cleanup != NULL) {
13,664,145✔
1168
      pSup->pCtx[i].fpSet.cleanup(&pSup->pCtx[i]);
14,502✔
1169
    }
1170
    pSup->pCtx[i].resultInfo = NULL;
13,664,145✔
1171
  }
1172
}
1173

1174
static void destroyIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsWindowState* pState) {
3,312✔
1175
  if (NULL == pState) {
3,312✔
1176
    return;
×
1177
  }
1178

1179
  cleanupIndefRowsResultRow(pOperator, pState->pRow);
3,312✔
1180
  taosMemoryFreeClear(pState->pRow);
3,312✔
1181

1182
  if (pState->pSealedBlocks != NULL) {
3,312✔
1183
    SListNode* pNode = NULL;
3,312✔
1184
    while ((pNode = tdListPopHead(pState->pSealedBlocks)) != NULL) {
3,312✔
1185
      SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
×
1186
      blockDataDestroy(pBlock);
×
1187
      taosMemoryFree(pNode);
×
1188
    }
1189
    pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
3,312✔
1190
  }
1191

1192
  blockDataDestroy(pState->pCurBlock);
3,312✔
1193
  taosMemoryFreeClear(pState);
3,312✔
1194
}
1195

1196
static void removeIndefRowsOpenState(SSHashObj* pOpenStatesMap, SIndefRowsWindowState* pState) {
11,078,475✔
1197
  if (NULL == pOpenStatesMap || NULL == pState) {
11,078,475✔
1198
    return;
×
1199
  }
1200

1201
  SIndefRowsStateKey key = {.groupId = pState->groupId, .skey = pState->win.skey};
11,078,475✔
1202
  int32_t  code = tSimpleHashRemove(pOpenStatesMap, &key, sizeof(key));
11,078,475✔
1203
  if (code != TSDB_CODE_SUCCESS) {
11,078,475✔
1204
    qError("failed to remove open state for groupId:%" PRIu64 ", skey:%" PRId64 ", code:%s", pState->groupId, pState->win.skey,
×
1205
           tstrerror(code));
1206
  }
1207
}
1208

1209
static int32_t createIndefRowsWindowState(SIndefRowsRuntime* pRuntime, SSDataBlock* pResultTemplate, uint64_t groupId,
11,081,787✔
1210
                                          const STimeWindow* pWin, int32_t resultRowSize,
1211
                                          SIndefRowsWindowState** ppState) {
1212
  int32_t code = TSDB_CODE_SUCCESS;
11,081,787✔
1213
  int32_t lino = 0;
11,081,787✔
1214

1215
  SIndefRowsWindowState* pState = taosMemoryCalloc(1, sizeof(SIndefRowsWindowState));
11,081,787✔
1216
  TSDB_CHECK_NULL(pState, code, lino, _return, terrno);
11,081,787✔
1217

1218
  pState->pRow = taosMemoryCalloc(1, resultRowSize);
11,081,787✔
1219
  QUERY_CHECK_NULL(pState->pRow, code, lino, _return, terrno);
11,081,787✔
1220

1221
  pState->pSealedBlocks = tdListNew(POINTER_BYTES);
11,081,787✔
1222
  QUERY_CHECK_NULL(pState->pSealedBlocks, code, lino, _return, terrno);
11,081,787✔
1223

1224
  code = createOneDataBlock(pResultTemplate, false, &pState->pCurBlock);
11,081,787✔
1225
  QUERY_CHECK_CODE(code, lino, _return);
11,081,787✔
1226

1227
  pState->groupId = groupId;
11,081,787✔
1228
  pState->win = *pWin;
11,081,787✔
1229
  TAOS_SET_POBJ_ALIGNED(&pState->pRow->win, pWin);
11,081,787✔
1230

1231
  SIndefRowsStateKey key = {.groupId = groupId, .skey = pWin->skey};
11,081,787✔
1232
  code = tSimpleHashPut(pRuntime->pOpenStatesMap, &key, sizeof(key), &pState, POINTER_BYTES);
11,081,787✔
1233
  QUERY_CHECK_CODE(code, lino, _return);
11,081,787✔
1234

1235
  *ppState = pState;
11,081,787✔
1236
  return code;
11,081,787✔
1237

1238
_return:
×
1239
  if (NULL != pState) {
×
1240
    taosMemoryFree(pState->pRow);
×
1241
    pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
×
1242
    blockDataDestroy(pState->pCurBlock);
×
1243
    taosMemoryFree(pState);
×
1244
  }
1245

1246
  if (code != TSDB_CODE_SUCCESS) {
×
1247
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1248
  }
1249

1250
  return code;
×
1251
}
1252

1253
static int32_t fillIndefRowsWindowPseudoCols(SOperatorInfo* pOperator, SSDataBlock* pBlock, const STimeWindow* pWin,
1,295,574✔
1254
                                             int32_t startOffset, int32_t rows) {
1255
  int32_t code = TSDB_CODE_SUCCESS;
1,295,574✔
1256
  int32_t lino = 0;
1,295,574✔
1257

1258
  if (rows <= 0) {
1,295,574✔
1259
    return code;
×
1260
  }
1261

1262
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
5,268,978✔
1263
    SqlFunctionCtx* pCtx = &pOperator->exprSupp.pCtx[i];
3,973,404✔
1264
    if (!fmIsPseudoColumnFunc(pCtx->functionId)) {
3,973,404✔
1265
      continue;
2,014,686✔
1266
    }
1267

1268
    const char* pFuncName = pCtx->pExpr->pExpr->_function.functionName;
1,958,718✔
1269
    int64_t     val = 0;
1,958,718✔
1270
    if (strcmp(pFuncName, "_wstart") == 0) {
1,958,718✔
1271
      val = pWin->skey;
805,614✔
1272
    } else if (strcmp(pFuncName, "_wend") == 0) {
1,153,104✔
1273
      val = pWin->ekey;
576,552✔
1274
    } else if (strcmp(pFuncName, "_wduration") == 0) {
576,552✔
1275
      val = pWin->ekey - pWin->skey;
576,552✔
1276
    } else {
1277
      continue;
×
1278
    }
1279

1280
    int32_t slotId = pOperator->exprSupp.pExprInfo[i].base.resSchema.slotId;
1,958,718✔
1281
    SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
1,958,718✔
1282
    QUERY_CHECK_NULL(pCol, code, lino, _return, terrno);
1,958,718✔
1283

1284
    for (int32_t row = 0; row < rows; ++row) {
768,213,324✔
1285
      code = colDataSetVal(pCol, startOffset + row, (const char*)&val, false);
766,254,606✔
1286
      QUERY_CHECK_CODE(code, lino, _return);
766,254,606✔
1287
    }
1288
  }
1289

1290
  return code;
1,295,574✔
1291

1292
_return:
×
1293
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1294
  return code;
×
1295
}
1296

1297
int32_t initIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SqlFunctionCtx* pCtx, int32_t numOfExprs, int32_t blockCapacity) {
124,957✔
1298
  int32_t code = TSDB_CODE_SUCCESS;
124,957✔
1299
  int32_t lino = 0;
124,957✔
1300

1301
  if (NULL == pRuntime) {
124,957✔
1302
    return TSDB_CODE_INVALID_PARA;
×
1303
  }
1304

1305
  pRuntime->blockCapacity = blockCapacity > 0 ? blockCapacity : 4096;
124,957✔
1306

1307
  pRuntime->pOpenStatesMap = tSimpleHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
124,957✔
1308
  QUERY_CHECK_NULL(pRuntime->pOpenStatesMap, code, lino, _return, terrno);
124,957✔
1309

1310
  pRuntime->pReadyBlocks = tdListNew(POINTER_BYTES);
124,957✔
1311
  QUERY_CHECK_NULL(pRuntime->pReadyBlocks, code, lino, _return, terrno);
124,957✔
1312

1313
  code = setRowTsColumnOutputInfo(pCtx, numOfExprs, &pRuntime->pPseudoColInfo);
124,957✔
1314
  QUERY_CHECK_CODE(code, lino, _return);
124,957✔
1315

1316
  return code;
124,957✔
1317

1318
_return:
×
1319
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1320
  pRuntime->pReadyBlocks = tdListFree(pRuntime->pReadyBlocks);
×
1321
  tSimpleHashCleanup(pRuntime->pOpenStatesMap);
×
1322
  pRuntime->pOpenStatesMap = NULL;
×
1323
  return code;
×
1324
}
1325

1326
void resetIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
8,815,747✔
1327
  if (NULL == pRuntime) {
8,815,747✔
1328
    return;
×
1329
  }
1330

1331
  if (pRuntime->pReturnedBlock != NULL) {
8,815,747✔
1332
    blockDataDestroy(pRuntime->pReturnedBlock);
×
1333
    pRuntime->pReturnedBlock = NULL;
×
1334
  }
1335

1336
  if (pRuntime->pReadyBlocks != NULL) {
8,815,747✔
1337
    SListNode* pNode = NULL;
124,957✔
1338
    while ((pNode = tdListPopHead(pRuntime->pReadyBlocks)) != NULL) {
124,957✔
1339
      SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
×
1340
      blockDataDestroy(pBlock);
×
1341
      taosMemoryFree(pNode);
×
1342
    }
1343
  }
1344

1345
  if (pRuntime->pOpenStatesMap != NULL) {
8,815,548✔
1346
    int32_t iter = 0;
124,957✔
1347
    void*   pData = NULL;
124,957✔
1348
    while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
128,269✔
1349
      SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
3,312✔
1350
      destroyIndefRowsWindowState(pOperator, pState);
3,312✔
1351
    }
1352
    tSimpleHashClear(pRuntime->pOpenStatesMap);
124,957✔
1353
  }
1354

1355
  if (pRuntime->pTmpBlock != NULL) {
8,814,998✔
1356
    blockDataCleanup(pRuntime->pTmpBlock);
111,541✔
1357
  }
1358
}
1359

1360
void cleanupIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
8,712,743✔
1361
  if (NULL == pRuntime) {
8,712,743✔
1362
    return;
×
1363
  }
1364

1365
  resetIndefRowsRuntime(pRuntime, pOperator);
8,712,743✔
1366
  tSimpleHashCleanup(pRuntime->pOpenStatesMap);
8,711,230✔
1367
  pRuntime->pOpenStatesMap = NULL;
8,713,318✔
1368
  pRuntime->pReadyBlocks = tdListFree(pRuntime->pReadyBlocks);
8,712,436✔
1369
  taosArrayDestroy(pRuntime->pPseudoColInfo);
8,715,307✔
1370
  pRuntime->pPseudoColInfo = NULL;
8,713,481✔
1371
  blockDataDestroy(pRuntime->pTmpBlock);
8,713,058✔
1372
  pRuntime->pTmpBlock = NULL;
8,711,410✔
1373
}
1374

1375
SIndefRowsWindowState* findIndefRowsWindowState(const SIndefRowsRuntime* pRuntime, uint64_t groupId, TSKEY winSKey) {
11,413,389✔
1376
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
11,413,389✔
1377
    return NULL;
×
1378
  }
1379

1380
  SIndefRowsStateKey key = {.groupId = groupId, .skey = winSKey};
11,413,389✔
1381
  SIndefRowsWindowState** ppState = tSimpleHashGet(pRuntime->pOpenStatesMap, &key, sizeof(key));
11,413,389✔
1382
  return ppState ? *ppState : NULL;
11,413,389✔
1383
}
1384

1385
int32_t applyIndefRowsFuncOnWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime,
11,325,645✔
1386
                                        SIndefRowsWindowState** ppState, SSDataBlock* pResultTemplate,
1387
                                        uint64_t groupId, const STimeWindow* pWin, SSDataBlock* pInputBlock,
1388
                                        int32_t startRow, int32_t numRows, int32_t inputTsOrder,
1389
                                        int32_t resultRowSize) {
1390
  int32_t                code = TSDB_CODE_SUCCESS;
11,325,645✔
1391
  int32_t                lino = 0;
11,325,645✔
1392
  SIndefRowsWindowState* pState = NULL;
11,325,645✔
1393

1394
  QRY_PARAM_CHECK(ppState);
11,325,645✔
1395
  if (numRows <= 0) {
11,325,645✔
1396
    return code;
×
1397
  }
1398

1399
  if (NULL == pRuntime || NULL == pRuntime->pPseudoColInfo) {
11,325,645✔
1400
    qError("%s invalid parameter, pRuntime:%p, pPseudoColInfo:%p", __func__, pRuntime, pRuntime ? pRuntime->pPseudoColInfo : NULL);
×
1401
    return TSDB_CODE_INVALID_PARA;
×
1402
  }
1403

1404
  pState = findIndefRowsWindowState(pRuntime, groupId, pWin->skey);
11,325,645✔
1405
  if (NULL == pState) {
11,325,645✔
1406
    code = createIndefRowsWindowState(pRuntime, pResultTemplate, groupId, pWin, resultRowSize, &pState);
11,081,787✔
1407
    QUERY_CHECK_CODE(code, lino, _return);
11,081,787✔
1408
    for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
24,753,972✔
1409
      pOperator->exprSupp.pCtx[i].pOutput = NULL;
13,672,185✔
1410
    }
1411
  } else {
1412
    // Only update ekey — groupId and skey already matched by find
1413
    pState->win.ekey = pWin->ekey;
243,858✔
1414
    pState->pRow->win.ekey = pWin->ekey;
243,858✔
1415
  }
1416

1417
  code = setResultRowInitCtx(pState->pRow, pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs,
11,325,645✔
1418
                             pOperator->exprSupp.rowEntryInfoOffset);
1419
  QUERY_CHECK_CODE(code, lino, _return);
11,325,645✔
1420

1421
  if (NULL == pRuntime->pTmpBlock) {
11,325,645✔
1422
    code = createOneDataBlock(pInputBlock, false, &pRuntime->pTmpBlock);
111,541✔
1423
    QUERY_CHECK_CODE(code, lino, _return);
111,541✔
1424
  } else {
1425
    blockDataCleanup(pRuntime->pTmpBlock);
11,214,104✔
1426
  }
1427

1428
  SSDataBlock* pWindowBlock = pRuntime->pTmpBlock;
11,325,645✔
1429
  code = blockDataEnsureCapacity(pWindowBlock, TMAX(1, numRows));
11,325,645✔
1430
  QUERY_CHECK_CODE(code, lino, _return);
11,325,645✔
1431
  code = blockDataMergeNRows(pWindowBlock, pInputBlock, startRow, numRows);
11,325,645✔
1432
  QUERY_CHECK_CODE(code, lino, _return);
11,325,645✔
1433

1434
  pWindowBlock->info.id = pInputBlock->info.id;
11,325,645✔
1435
  pWindowBlock->info.window = *pWin;
11,325,645✔
1436
  pWindowBlock->info.scanFlag = pInputBlock->info.scanFlag;
11,325,645✔
1437
  pWindowBlock->info.dataLoad = pInputBlock->info.dataLoad;
11,325,645✔
1438

1439
  code = setInputDataBlock(&pOperator->exprSupp, pWindowBlock, inputTsOrder, pWindowBlock->info.scanFlag, false);
11,325,645✔
1440
  QUERY_CHECK_CODE(code, lino, _return);
11,325,645✔
1441

1442
  pState->pCurBlock->info.id = pInputBlock->info.id;
11,325,645✔
1443
  pState->pCurBlock->info.window = *pWin;
11,325,645✔
1444
  pState->pCurBlock->info.scanFlag = pInputBlock->info.scanFlag;
11,325,645✔
1445
  pState->pCurBlock->info.dataLoad = 1;
11,325,645✔
1446
  code = blockDataEnsureCapacity(pState->pCurBlock, pState->pCurBlock->info.rows + pWindowBlock->info.rows);
11,325,645✔
1447
  QUERY_CHECK_CODE(code, lino, _return);
11,325,645✔
1448

1449
  code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pState->pCurBlock, pWindowBlock,
22,651,290✔
1450
                               pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs,
1451
                               pRuntime->pPseudoColInfo,
1452
                               GET_STM_RTINFO(pOperator->pTaskInfo), pOperator->pTaskInfo);
11,325,645✔
1453
  QUERY_CHECK_CODE(code, lino, _return);
11,325,645✔
1454

1455
  pState->pRow->nOrigRows += numRows;
11,322,333✔
1456

1457
  // Seal current block if it reached capacity
1458
  if (pState->pCurBlock->info.rows >= pRuntime->blockCapacity) {
11,322,333✔
1459
    code = tdListAppend(pState->pSealedBlocks, &pState->pCurBlock);
328,800✔
1460
    QUERY_CHECK_CODE(code, lino, _return);
328,800✔
1461
    pState->pCurBlock = NULL;
328,800✔
1462
    code = createOneDataBlock(pResultTemplate, false, &pState->pCurBlock);
328,800✔
1463
    QUERY_CHECK_CODE(code, lino, _return);
328,800✔
1464
  }
1465

1466
  *ppState = pState;
11,322,333✔
1467

1468
_return:
11,325,645✔
1469
  if (code != TSDB_CODE_SUCCESS) {
11,325,645✔
1470
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
3,312✔
1471
  }
1472

1473
  return code;
11,325,645✔
1474
}
1475

1476
int32_t closeIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime, SIndefRowsWindowState* pState) {
11,078,475✔
1477
  int32_t code = TSDB_CODE_SUCCESS;
11,078,475✔
1478
  int32_t lino = 0;
11,078,475✔
1479

1480
  if (NULL == pRuntime || NULL == pState) {
11,078,475✔
1481
    return code;
×
1482
  }
1483

1484
  // Phase 1: Seal current block into sealed list (so all blocks are in one place)
1485
  if (pState->pCurBlock != NULL && pState->pCurBlock->info.rows > 0) {
11,078,475✔
1486
    code = tdListAppend(pState->pSealedBlocks, &pState->pCurBlock);
966,774✔
1487
    QUERY_CHECK_CODE(code, lino, _error);
966,774✔
1488
    pState->pCurBlock = NULL;
966,774✔
1489
  } else {
1490
    blockDataDestroy(pState->pCurBlock);
10,111,701✔
1491
    pState->pCurBlock = NULL;
10,111,701✔
1492
  }
1493

1494
  // Phase 2: Process each block — fill pseudo cols, filter, push to readyBlocks
1495
  SListNode* pNode = NULL;
11,078,475✔
1496
  while ((pNode = tdListPopHead(pState->pSealedBlocks)) != NULL) {
12,374,049✔
1497
    SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
1,295,574✔
1498
    taosMemoryFree(pNode);
1,295,574✔
1499

1500
    code = fillIndefRowsWindowPseudoCols(pOperator, pBlock, &pState->win, 0, pBlock->info.rows);
1,295,574✔
1501
    if (code != TSDB_CODE_SUCCESS) {
1,295,574✔
1502
      blockDataDestroy(pBlock);
×
1503
      qError("%s fillPseudoCols failed since %s", __func__, tstrerror(code));
×
1504
      goto _cleanup;
×
1505
    }
1506

1507
    if (pOperator->exprSupp.pFilterInfo != NULL) {
1,295,574✔
1508
      code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL, NULL);
×
1509
      if (code != TSDB_CODE_SUCCESS) {
×
1510
        blockDataDestroy(pBlock);
×
1511
        qError("%s doFilter failed since %s", __func__, tstrerror(code));
×
1512
        goto _cleanup;
×
1513
      }
1514
    }
1515

1516
    if (pBlock->info.rows > 0) {
1,295,574✔
1517
      code = tdListAppend(pRuntime->pReadyBlocks, &pBlock);
1,295,574✔
1518
      if (code != TSDB_CODE_SUCCESS) {
1,295,574✔
1519
        blockDataDestroy(pBlock);
×
1520
        qError("%s append readyBlocks failed since %s", __func__, tstrerror(code));
×
1521
        goto _cleanup;
×
1522
      }
1523
    } else {
1524
      blockDataDestroy(pBlock);
×
1525
    }
1526
  }
1527

1528
  // Phase 3: All succeeded — remove from open states and destroy the state shell
1529
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
11,078,475✔
1530
  cleanupIndefRowsResultRow(pOperator, pState->pRow);
11,078,475✔
1531
  taosMemoryFreeClear(pState->pRow);
11,078,475✔
1532
  pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
11,078,475✔
1533
  taosMemoryFreeClear(pState);
11,078,475✔
1534

1535
  return TSDB_CODE_SUCCESS;
11,078,475✔
1536

1537
_error:
×
1538
  // Seal failed — state still intact in openStates, let dropAll clean up
1539
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1540
  return code;
×
1541

1542
_cleanup:
×
1543
  // Some blocks already pushed to readyBlocks (they'll be consumed normally).
1544
  // Remaining blocks still in pSealedBlocks — destroy them along with state.
1545
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
×
1546
  destroyIndefRowsWindowState(pOperator, pState);
×
1547
  return code;
×
1548
}
1549

1550
int32_t closeAllIndefRowsWindowStates(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime) {
116,533✔
1551
  int32_t code = TSDB_CODE_SUCCESS;
116,533✔
1552
  int32_t lino = 0;
116,533✔
1553

1554
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
116,533✔
1555
    return code;
×
1556
  }
1557

1558
  // Collect all states first since closeIndefRowsWindowState removes from the map
1559
  int32_t numOpen = tSimpleHashGetSize(pRuntime->pOpenStatesMap);
116,533✔
1560
  if (numOpen == 0) {
116,533✔
1561
    return code;
15,360✔
1562
  }
1563

1564
  SArray* pStates = taosArrayInit(numOpen, POINTER_BYTES);
101,173✔
1565
  QUERY_CHECK_NULL(pStates, code, lino, _return, terrno);
101,173✔
1566

1567
  int32_t iter = 0;
101,173✔
1568
  void*   pData = NULL;
101,173✔
1569
  while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
637,070✔
1570
    SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
535,897✔
1571
    QUERY_CHECK_NULL(taosArrayPush(pStates, &pState), code, lino, _return, terrno);
535,897✔
1572
  }
1573

1574
  for (int32_t i = 0; i < taosArrayGetSize(pStates); ++i) {
637,070✔
1575
    SIndefRowsWindowState* pState = taosArrayGetP(pStates, i);
535,897✔
1576
    code = closeIndefRowsWindowState(pOperator, pRuntime, pState);
535,897✔
1577
    QUERY_CHECK_CODE(code, lino, _return);
535,897✔
1578
  }
1579

1580
_return:
101,173✔
1581
  taosArrayDestroy(pStates);
101,173✔
1582
  if (code != TSDB_CODE_SUCCESS) {
101,173✔
1583
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1584
  }
1585
  return code;
101,173✔
1586
}
1587

1588
void dropIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime, SIndefRowsWindowState* pState) {
×
1589
  if (NULL == pRuntime || NULL == pState) {
×
1590
    return;
×
1591
  }
1592

1593
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
×
1594
  destroyIndefRowsWindowState(pOperator, pState);
×
1595
}
1596

1597
void dropAllIndefRowsWindowStates(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime) {
22,296✔
1598
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
22,296✔
1599
    return;
×
1600
  }
1601

1602
  int32_t openCount = tSimpleHashGetSize(pRuntime->pOpenStatesMap);
22,296✔
1603
  if (openCount > 0) {
22,296✔
1604
    qDebug("%s dropping %d unclosed indefRows window state(s)", GET_TASKID(pOperator->pTaskInfo), openCount);
×
1605
  }
1606

1607
  int32_t iter = 0;
22,296✔
1608
  void*   pData = NULL;
22,296✔
1609
  while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
22,296✔
1610
    SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
×
1611
    destroyIndefRowsWindowState(pOperator, pState);
×
1612
  }
1613
  tSimpleHashClear(pRuntime->pOpenStatesMap);
22,296✔
1614
}
1615

1616
SSDataBlock* getNextIndefRowsResultBlock(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
1,510,651✔
1617
  if (NULL == pRuntime) {
1,510,651✔
1618
    return NULL;
×
1619
  }
1620

1621
  if (pRuntime->pReturnedBlock != NULL) {
1,510,651✔
1622
    blockDataDestroy(pRuntime->pReturnedBlock);
1,295,574✔
1623
    pRuntime->pReturnedBlock = NULL;
1,295,574✔
1624
  }
1625

1626
  if (NULL == pRuntime->pReadyBlocks) {
1,510,651✔
1627
    return NULL;
×
1628
  }
1629

1630
  while (listNEles(pRuntime->pReadyBlocks) > 0) {
1,510,651✔
1631
    SListNode* pNode = tdListPopHead(pRuntime->pReadyBlocks);
1,295,574✔
1632
    if (NULL == pNode) {
1,295,574✔
1633
      return NULL;
×
1634
    }
1635

1636
    SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
1,295,574✔
1637
    taosMemoryFree(pNode);
1,295,574✔
1638
    if (NULL == pBlock) {
1,295,574✔
1639
      continue;
×
1640
    }
1641

1642
    if (pBlock->info.rows > 0) {
1,295,574✔
1643
      pBlock->info.version = pOperator->pTaskInfo->version;
1,295,574✔
1644
      pBlock->info.dataLoad = 1;
1,295,574✔
1645
      pRuntime->pReturnedBlock = pBlock;
1,295,574✔
1646
      return pBlock;
1,295,574✔
1647
    }
1648

1649
    blockDataDestroy(pBlock);
×
1650
  }
1651

1652
  return NULL;
215,077✔
1653
}
1654

1655
void cleanupExprSupp(SExprSupp* pSupp) {
1,189,269,804✔
1656
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
1,189,269,804✔
1657
  if (pSupp->pExprInfo != NULL) {
1,189,266,559✔
1658
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
413,832,588✔
1659
    taosMemoryFreeClear(pSupp->pExprInfo);
413,837,196✔
1660
  }
1661

1662
  if (pSupp->pFilterInfo != NULL) {
1,189,273,754✔
1663
    filterFreeInfo(pSupp->pFilterInfo);
109,434,425✔
1664
    pSupp->pFilterInfo = NULL;
109,424,151✔
1665
  }
1666

1667
  taosMemoryFree(pSupp->rowEntryInfoOffset);
1,189,271,422✔
1668
  memset(pSupp, 0, sizeof(SExprSupp));
1,189,308,482✔
1669
}
1,189,308,482✔
1670

1671
void cleanupExprSuppWithoutFilter(SExprSupp* pSupp) {
121,492,035✔
1672
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
121,492,035✔
1673
  if (pSupp->pExprInfo != NULL) {
121,483,752✔
1674
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
34,775,560✔
1675
    taosMemoryFreeClear(pSupp->pExprInfo);
34,776,857✔
1676
  }
1677

1678
  taosMemoryFreeClear(pSupp->rowEntryInfoOffset);
121,483,201✔
1679
  pSupp->numOfExprs = 0;
121,484,774✔
1680
  pSupp->hasWindowOrGroup = false;
121,501,305✔
1681
  pSupp->pCtx = NULL;
121,497,866✔
1682
}
121,489,342✔
1683

1684
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
308,841,256✔
1685
  blockDataDestroy(pInfo->pRes);
308,841,256✔
1686
  pInfo->pRes = NULL;
308,869,293✔
1687
}
308,877,181✔
1688

1689
bool groupbyTbname(SNodeList* pGroupList) {
271,271,066✔
1690
  bool   bytbname = false;
271,271,066✔
1691
  SNode* pNode = NULL;
271,271,066✔
1692
  FOREACH(pNode, pGroupList) {
278,879,034✔
1693
    if (pNode->type == QUERY_NODE_FUNCTION) {
40,567,637✔
1694
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
32,958,623✔
1695
      break;
32,964,828✔
1696
    }
1697
  }
1698
  return bytbname;
271,266,082✔
1699
}
1700

1701
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
392,265,378✔
1702
  switch (pNode->type) {
392,265,378✔
1703
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
527,801✔
1704
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
527,801✔
1705
      if (NULL == pInserterParam) {
527,801✔
1706
        return terrno;
×
1707
      }
1708
      pInserterParam->readHandle = readHandle;
527,801✔
1709

1710
      *pParam = pInserterParam;
527,801✔
1711
      break;
527,801✔
1712
    }
1713
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
2,037,432✔
1714
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
2,037,432✔
1715
      if (NULL == pDeleterParam) {
1,997,890✔
1716
        return terrno;
×
1717
      }
1718

1719
      SArray* pInfoList = NULL;
1,997,890✔
1720
      int32_t code = getTableListInfo(pTask, &pInfoList);
1,997,890✔
1721
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
1,998,529✔
UNCOV
1722
        taosMemoryFree(pDeleterParam);
×
1723
        return code;
×
1724
      }
1725

1726
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
1,999,165✔
1727
      taosArrayDestroy(pInfoList);
1,999,165✔
1728

1729
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
1,995,985✔
1730

1731
      // TODO extract uid list
1732
      int32_t numOfTables = 0;
1,997,890✔
1733
      code = tableListGetSize(pTableListInfo, &numOfTables);
1,997,890✔
1734
      if (code != TSDB_CODE_SUCCESS) {
1,996,618✔
1735
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1736
        taosMemoryFree(pDeleterParam);
×
1737
        return code;
×
1738
      }
1739

1740
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
1,996,618✔
1741
      if (NULL == pDeleterParam->pUidList) {
1,998,529✔
1742
        taosMemoryFree(pDeleterParam);
×
1743
        return terrno;
×
1744
      }
1745

1746
      for (int32_t i = 0; i < numOfTables; ++i) {
4,262,993✔
1747
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
2,267,017✔
1748
        if (!pTable) {
2,267,017✔
1749
          taosArrayDestroy(pDeleterParam->pUidList);
×
1750
          taosMemoryFree(pDeleterParam);
×
1751
          return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
1752
        }
1753
        void* tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
2,267,017✔
1754
        if (!tmp) {
2,267,017✔
1755
          taosArrayDestroy(pDeleterParam->pUidList);
×
1756
          taosMemoryFree(pDeleterParam);
×
1757
          return terrno;
×
1758
        }
1759
      }
1760

1761
      *pParam = pDeleterParam;
1,995,976✔
1762
      break;
1,998,526✔
1763
    }
1764
    default:
389,713,751✔
1765
      break;
389,713,751✔
1766
  }
1767

1768
  return TSDB_CODE_SUCCESS;
392,312,376✔
1769
}
1770

1771
void streamOpReleaseState(SOperatorInfo* pOperator) {
×
1772
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1773
  if (downstream->fpSet.releaseStreamStateFn) {
×
1774
    downstream->fpSet.releaseStreamStateFn(downstream);
×
1775
  }
1776
}
×
1777

1778
void streamOpReloadState(SOperatorInfo* pOperator) {
×
1779
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1780
  if (downstream->fpSet.reloadStreamStateFn) {
×
1781
    downstream->fpSet.reloadStreamStateFn(downstream);
×
1782
  }
1783
}
×
1784

1785
void freeOperatorParamImpl(SOperatorParam* pParam, SOperatorParamType type) {
149,577,477✔
1786
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
149,577,477✔
1787
  for (int32_t i = 0; i < childrenNum; ++i) {
151,474,110✔
1788
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
1,893,386✔
1789
    freeOperatorParam(pChild, type);
1,893,386✔
1790
  }
1791

1792
  taosArrayDestroy(pParam->pChildren);
149,580,724✔
1793
  pParam->pChildren = NULL;
149,581,643✔
1794

1795
  taosMemoryFreeClear(pParam->value);
149,581,581✔
1796

1797
  taosMemoryFree(pParam);
149,597,362✔
1798
}
149,585,463✔
1799

1800
void freeExchangeGetBasicOperatorParam(void* pParam) {
26,594,786✔
1801
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
26,594,786✔
1802
  if (pBasic->uidList) {
26,594,786✔
1803
    taosArrayDestroy(pBasic->uidList);
22,003,936✔
1804
    pBasic->uidList = NULL;
22,003,936✔
1805
  }
1806
  if (pBasic->orgTbInfo) {
26,594,786✔
1807
    taosArrayDestroy(pBasic->orgTbInfo->colMap);
12,079,052✔
1808
    taosMemoryFreeClear(pBasic->orgTbInfo);
12,079,052✔
1809
  }
1810
  if (pBasic->batchOrgTbInfo) {
26,594,786✔
1811
    taosArrayDestroyEx(pBasic->batchOrgTbInfo, destroySOrgTbInfo);
3,501,248✔
1812
    pBasic->batchOrgTbInfo = NULL;
3,501,248✔
1813
  }
1814
  if (pBasic->tagList) {
26,594,786✔
1815
    taosArrayDestroyEx(pBasic->tagList, destroyTagVal);
912,848✔
1816
    pBasic->tagList = NULL;
912,848✔
1817
  }
1818
}
26,594,786✔
1819

1820
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
25,276,035✔
1821
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
25,276,035✔
1822
  if (pExcParam->multiParams) {
25,276,035✔
1823
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
2,456,674✔
1824
    tSimpleHashSetFreeFp(pExcBatch->pBatchs, freeExchangeGetBasicOperatorParam);
2,456,674✔
1825
    tSimpleHashCleanup(pExcBatch->pBatchs);
2,456,674✔
1826
  } else {
1827
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
22,819,361✔
1828
  }
1829

1830
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
25,276,035✔
1831
}
25,276,035✔
1832

1833
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1834

1835
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
8,555,876✔
1836

1837
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1838

1839
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
4,277,938✔
1840

1841
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1842

1843
void freeTagScanGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
6,673,780✔
1844

1845
void freeMergeGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
5,223,476✔
1846

1847
void freeDynQueryCtrlGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
×
1848

1849
void freeDynQueryCtrlNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1850

1851
void freeInterpFuncGetOperatorParam(SOperatorParam* pParam) {
×
1852
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
×
1853
}
×
1854

1855
void freeInterpFuncNotifyOperatorParam(SOperatorParam* pParam) {
×
1856
  freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM);
×
1857
}
×
1858

1859
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
93,155,402✔
1860
  STableScanOperatorParam* pTableScanParam =
93,155,402✔
1861
    (STableScanOperatorParam*)pParam->value;
1862
  taosArrayDestroy(pTableScanParam->pUidList);
93,159,573✔
1863
  if (pTableScanParam->pOrgTbInfo) {
93,158,797✔
1864
    taosArrayDestroy(pTableScanParam->pOrgTbInfo->colMap);
81,203,018✔
1865
    taosMemoryFreeClear(pTableScanParam->pOrgTbInfo);
81,203,018✔
1866
  }
1867
  if (pTableScanParam->pBatchTbInfo) {
93,161,461✔
1868
    for (int32_t i = 0;
2,894,292✔
1869
      i < taosArrayGetSize(pTableScanParam->pBatchTbInfo); ++i) {
8,414,206✔
1870
      SOrgTbInfo* pOrgTbInfo =
1871
        (SOrgTbInfo*)taosArrayGet(pTableScanParam->pBatchTbInfo, i);
5,519,914✔
1872
      taosArrayDestroy(pOrgTbInfo->colMap);
5,519,914✔
1873
    }
1874
    taosArrayDestroy(pTableScanParam->pBatchTbInfo);
2,894,292✔
1875
    pTableScanParam->pBatchTbInfo = NULL;
2,894,292✔
1876
  }
1877
  if (pTableScanParam->pTagList) {
93,163,953✔
1878
    for (int32_t i = 0;
912,848✔
1879
      i < taosArrayGetSize(pTableScanParam->pTagList); ++i) {
5,656,944✔
1880
      STagVal* pTagVal =
1881
        (STagVal*)taosArrayGet(pTableScanParam->pTagList, i);
4,744,096✔
1882
      if (IS_VAR_DATA_TYPE(pTagVal->type)) {
4,744,096✔
1883
        taosMemoryFreeClear(pTagVal->pData);
2,059,728✔
1884
      }
1885
    }
1886
    taosArrayDestroy(pTableScanParam->pTagList);
912,848✔
1887
    pTableScanParam->pTagList = NULL;
912,848✔
1888
  }
1889
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
93,166,569✔
1890
}
93,157,894✔
1891

1892
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1893

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

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

1898
void freeOpParamItem(void* pItem) {
17,286,475✔
1899
  SOperatorParam* pParam = *(SOperatorParam**)pItem;
17,286,475✔
1900
  pParam->reUse = false;
17,286,475✔
1901
  freeOperatorParam(pParam, OP_GET_PARAM);
17,286,475✔
1902
}
17,286,475✔
1903

1904
static void destroyRefColIdGroupParam(void* info) {
9,051✔
1905
  SRefColIdGroup* pGroup = (SRefColIdGroup*)info;
9,051✔
1906
  if (pGroup && pGroup->pSlotIdList) {
9,051✔
1907
    taosArrayDestroy(pGroup->pSlotIdList);
9,051✔
1908
    pGroup->pSlotIdList = NULL;
9,051✔
1909
  }
1910
}
9,051✔
1911

1912
void freeExternalWindowGetOperatorParam(SOperatorParam* pParam) {
1,211,778✔
1913
  SExternalWindowOperatorParam *pExtParam = (SExternalWindowOperatorParam*)pParam->value;
1,211,778✔
1914
  taosArrayDestroy(pExtParam->ExtWins);
1,211,778✔
1915
  for (int32_t i = 0; i < taosArrayGetSize(pParam->pChildren); i++) {
1,211,778✔
1916
    SOperatorParam* pChild = *(SOperatorParam**)taosArrayGet(pParam->pChildren, i);
×
1917
    pChild->reUse = false;
×
1918
  }
1919
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
1,211,778✔
1920
}
1,211,778✔
1921

1922
void freeVirtualTableScanGetOperatorParam(SOperatorParam* pParam) {
5,207,423✔
1923
  SVTableScanOperatorParam* pVTableScanParam = (SVTableScanOperatorParam*)pParam->value;
5,207,423✔
1924
  taosArrayDestroyEx(pVTableScanParam->pOpParamArray, freeOpParamItem);
5,207,423✔
1925
  if (pVTableScanParam->pRefColGroups) {
5,207,423✔
1926
    taosArrayDestroyEx(pVTableScanParam->pRefColGroups, destroyRefColIdGroupParam);
5,576✔
1927
    pVTableScanParam->pRefColGroups = NULL;
5,576✔
1928
  }
1929
  freeOpParamItem(&pVTableScanParam->pTagScanOp);
5,207,423✔
1930
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
5,207,423✔
1931
}
5,207,423✔
1932

1933
void freeVTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1934

1935
void freeExternalWindowNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1936

1937
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
863,528,520✔
1938
  if (NULL == pParam || pParam->reUse) {
863,528,520✔
1939
    return;
713,960,441✔
1940
  }
1941

1942
  switch (pParam->opType) {
149,571,976✔
1943
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
25,276,035✔
1944
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
25,276,035✔
1945
      break;
25,276,035✔
1946
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
8,555,876✔
1947
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
8,555,876✔
1948
      break;
8,555,876✔
1949
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
4,277,938✔
1950
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
4,277,938✔
1951
      break;
4,277,938✔
1952
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
93,163,211✔
1953
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
1954
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
93,163,211✔
1955
      break;
93,161,221✔
1956
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
5,207,423✔
1957
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
5,207,423✔
1958
      break;
5,207,423✔
1959
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
6,673,780✔
1960
      type == OP_GET_PARAM ? freeTagScanGetOperatorParam(pParam) : freeTagScanNotifyOperatorParam(pParam);
6,673,780✔
1961
      break;
6,673,780✔
1962
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
5,224,810✔
1963
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
1964
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
1965
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL:
1966
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
1967
      type == OP_GET_PARAM ? freeMergeGetOperatorParam(pParam) : freeMergeNotifyOperatorParam(pParam);
5,224,810✔
1968
      break;
5,224,125✔
1969
    case QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW:
1,211,778✔
1970
      type == OP_GET_PARAM ? freeExternalWindowGetOperatorParam(pParam) : freeExternalWindowNotifyOperatorParam(pParam);
1,211,778✔
1971
      break;
1,211,778✔
1972
    case QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL:
×
1973
      type == OP_GET_PARAM ? freeDynQueryCtrlGetOperatorParam(pParam) : freeDynQueryCtrlNotifyOperatorParam(pParam);
×
1974
      break;
×
1975
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
×
1976
      type == OP_GET_PARAM ? freeInterpFuncGetOperatorParam(pParam) : freeInterpFuncNotifyOperatorParam(pParam);
×
1977
      break;
×
1978
    default:
9,216✔
1979
      qError("%s unsupported op %d param, param type %d, param:%p value:%p children:%p reuse:%d",
9,216✔
1980
             __func__, pParam->opType, type, pParam, pParam->value, pParam->pChildren, pParam->reUse);
1981
      break;
×
1982
  }
1983
}
1984

1985
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
1,850,604,552✔
1986
  SOperatorParam**  ppParam = NULL;
1,850,604,552✔
1987
  SOperatorParam*** pppDownstramParam = NULL;
1,850,604,552✔
1988
  switch (type) {
1,850,604,552✔
1989
    case OP_GET_PARAM:
983,910,172✔
1990
      ppParam = &pOperator->pOperatorGetParam;
983,910,172✔
1991
      pppDownstramParam = &pOperator->pDownstreamGetParams;
983,923,981✔
1992
      break;
983,916,394✔
1993
    case OP_NOTIFY_PARAM:
866,728,152✔
1994
      ppParam = &pOperator->pOperatorNotifyParam;
866,728,152✔
1995
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
866,720,109✔
1996
      break;
866,726,701✔
1997
    default:
×
1998
      return;
×
1999
  }
2000

2001
  if (*ppParam) {
1,850,643,095✔
2002
    qDebug("%s free self param, operator:%s type:%d paramType:%d param:%p", __func__, pOperator->name,
9,576,767✔
2003
           pOperator->operatorType, type, *ppParam);
2004
    freeOperatorParam(*ppParam, type);
9,576,767✔
2005
    *ppParam = NULL;
9,576,767✔
2006
  }
2007

2008
  if (*pppDownstramParam) {
1,850,564,840✔
2009
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
146,407,762✔
2010
      if ((*pppDownstramParam)[i]) {
25,856,489✔
2011
        qDebug("%s free downstream param, operator:%s type:%d idx:%d downstream:%s paramType:%d param:%p", __func__,
×
2012
               pOperator->name, pOperator->operatorType, i, pOperator->pDownstream[i]->name, type,
2013
               (*pppDownstramParam)[i]);
2014
        freeOperatorParam((*pppDownstramParam)[i], type);
×
2015
        (*pppDownstramParam)[i] = NULL;
×
2016
      }
2017
    }
2018
    if (allFree) {
120,550,768✔
2019
      taosMemoryFreeClear(*pppDownstramParam);
23,948,568✔
2020
    }
2021
  }
2022
}
2023

2024
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
1,220,955,321✔
2025
                                                    SSDataBlock** pResBlock) {
2026
  QRY_PARAM_CHECK(pResBlock);
1,220,955,321✔
2027

2028
  int32_t code = 0;
1,221,051,298✔
2029
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
1,221,051,298✔
2030
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
20,996,494✔
2031
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
41,995,606✔
2032
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
20,998,080✔
2033
    if (clearParam && (code == 0)) {
20,997,608✔
2034
      qDebug("%s clear downstream param, operator:%s type:%d idx:%d downstream:%s param:%p", __func__,
7,991,016✔
2035
             pOperator->name, pOperator->operatorType, idx, pOperator->pDownstream[idx]->name,
2036
             pOperator->pDownstreamGetParams[idx]);
2037
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
7,991,488✔
2038
      pOperator->pDownstreamGetParams[idx] = NULL;
7,991,488✔
2039
    }
2040

2041
    if (code) {
20,998,080✔
2042
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
2043
    }
2044
    return code;
20,998,080✔
2045
  }
2046

2047
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
1,200,025,574✔
2048
  if (code) {
1,197,404,324✔
2049
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
2050
  }
2051
  return code;
1,197,347,347✔
2052
}
2053

2054
bool compareVal(const char* v, const SStateKeys* pKey) {
2,147,483,647✔
2055
  if (IS_VAR_DATA_TYPE(pKey->type)) {
2,147,483,647✔
2056
    if (IS_STR_DATA_BLOB(pKey->type)) {
491,977✔
2057
      if (blobDataLen(v) != blobDataLen(pKey->pData)) {
×
2058
        return false;
×
2059
      } else {
2060
        return memcmp(blobDataVal(v), blobDataVal(pKey->pData), blobDataLen(v)) == 0;
×
2061
      }
2062
    } else {
2063
      if (varDataLen(v) != varDataLen(pKey->pData)) {
491,977✔
2064
        return false;
456✔
2065
      } else {
2066
        return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
491,521✔
2067
      }
2068
    }
2069
  } else {
2070
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
2,147,483,647✔
2071
  }
2072
}
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