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

taosdata / TDengine / #3653

14 Mar 2025 08:10AM UTC coverage: 22.565% (-41.0%) from 63.596%
#3653

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

49248 of 302527 branches covered (16.28%)

Branch coverage included in aggregate %.

53 of 99 new or added lines in 12 files covered. (53.54%)

155872 existing lines in 443 files now uncovered.

87359 of 302857 relevant lines covered (28.84%)

570004.22 hits per line

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

0.0
/source/client/src/clientStmt2.c
1
#include "clientInt.h"
2
#include "clientLog.h"
3
#include "tdef.h"
4

5
#include "clientStmt.h"
6
#include "clientStmt2.h"
7
/*
8
char* gStmtStatusStr[] = {"unknown",     "init", "prepare", "settbname", "settags",
9
                          "fetchFields", "bind", "bindCol", "addBatch",  "exec"};
10
*/
11
static FORCE_INLINE int32_t stmtAllocQNodeFromBuf(STableBufInfo* pTblBuf, void** pBuf) {
UNCOV
12
  if (pTblBuf->buffOffset < pTblBuf->buffSize) {
×
UNCOV
13
    *pBuf = (char*)pTblBuf->pCurBuff + pTblBuf->buffOffset;
×
UNCOV
14
    pTblBuf->buffOffset += pTblBuf->buffUnit;
×
15
  } else if (pTblBuf->buffIdx < taosArrayGetSize(pTblBuf->pBufList)) {
×
16
    pTblBuf->pCurBuff = taosArrayGetP(pTblBuf->pBufList, pTblBuf->buffIdx++);
×
17
    if (NULL == pTblBuf->pCurBuff) {
×
18
      return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
19
    }
20
    *pBuf = pTblBuf->pCurBuff;
×
21
    pTblBuf->buffOffset = pTblBuf->buffUnit;
×
22
  } else {
23
    void* buff = taosMemoryMalloc(pTblBuf->buffSize);
×
24
    if (NULL == buff) {
×
25
      return terrno;
×
26
    }
27

28
    if (taosArrayPush(pTblBuf->pBufList, &buff) == NULL) {
×
29
      return terrno;
×
30
    }
31

32
    pTblBuf->buffIdx++;
×
33
    pTblBuf->pCurBuff = buff;
×
34
    *pBuf = buff;
×
35
    pTblBuf->buffOffset = pTblBuf->buffUnit;
×
36
  }
37

UNCOV
38
  return TSDB_CODE_SUCCESS;
×
39
}
40

UNCOV
41
static bool stmtDequeue(STscStmt2* pStmt, SStmtQNode** param) {
×
UNCOV
42
  int i = 0;
×
UNCOV
43
  while (0 == atomic_load_64((int64_t*)&pStmt->queue.qRemainNum)) {
×
UNCOV
44
    if (i < 10) {
×
UNCOV
45
      taosUsleep(1);
×
UNCOV
46
      i++;
×
47
    } else {
UNCOV
48
      (void)taosThreadMutexLock(&pStmt->queue.mutex);
×
UNCOV
49
      if (0 == atomic_load_64((int64_t*)&pStmt->queue.qRemainNum)) {
×
UNCOV
50
        (void)taosThreadCondWait(&pStmt->queue.waitCond, &pStmt->queue.mutex);
×
51
      }
UNCOV
52
      (void)taosThreadMutexUnlock(&pStmt->queue.mutex);
×
53
    }
54
  }
UNCOV
55
  if (pStmt->queue.stopQueue) {
×
UNCOV
56
    return false;
×
57
  }
UNCOV
58
  SStmtQNode* orig = pStmt->queue.head;
×
UNCOV
59
  SStmtQNode* node = pStmt->queue.head->next;
×
UNCOV
60
  pStmt->queue.head = pStmt->queue.head->next;
×
UNCOV
61
  *param = node;
×
62

UNCOV
63
  (void)atomic_sub_fetch_64((int64_t*)&pStmt->queue.qRemainNum, 1);
×
64

UNCOV
65
  return true;
×
66
}
67

UNCOV
68
static void stmtEnqueue(STscStmt2* pStmt, SStmtQNode* param) {
×
UNCOV
69
  pStmt->queue.tail->next = param;
×
UNCOV
70
  pStmt->queue.tail = param;
×
71

UNCOV
72
  pStmt->stat.bindDataNum++;
×
73

UNCOV
74
  (void)taosThreadMutexLock(&pStmt->queue.mutex);
×
UNCOV
75
  (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1);
×
UNCOV
76
  (void)taosThreadCondSignal(&(pStmt->queue.waitCond));
×
UNCOV
77
  (void)taosThreadMutexUnlock(&pStmt->queue.mutex);
×
UNCOV
78
}
×
79

UNCOV
80
static int32_t stmtCreateRequest(STscStmt2* pStmt) {
×
UNCOV
81
  int32_t code = 0;
×
82

UNCOV
83
  if (pStmt->exec.pRequest == NULL) {
×
UNCOV
84
    code = buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false, &pStmt->exec.pRequest,
×
85
                        pStmt->reqid);
UNCOV
86
    if (pStmt->reqid != 0) {
×
87
      pStmt->reqid++;
×
88
    }
UNCOV
89
    if (pStmt->db != NULL) {
×
UNCOV
90
      taosMemoryFreeClear(pStmt->exec.pRequest->pDb); 
×
UNCOV
91
      pStmt->exec.pRequest->pDb = taosStrdup(pStmt->db);
×
92
    }
UNCOV
93
    if (TSDB_CODE_SUCCESS == code) {
×
UNCOV
94
      pStmt->exec.pRequest->syncQuery = true;
×
UNCOV
95
      pStmt->exec.pRequest->isStmtBind = true;
×
96
    }
97
  }
98

UNCOV
99
  return code;
×
100
}
101

UNCOV
102
static int32_t stmtSwitchStatus(STscStmt2* pStmt, STMT_STATUS newStatus) {
×
UNCOV
103
  int32_t code = 0;
×
104

UNCOV
105
  if (newStatus >= STMT_INIT && newStatus < STMT_MAX) {
×
UNCOV
106
    STMT_LOG_SEQ(newStatus);
×
107
  }
108

UNCOV
109
  if (pStmt->errCode && newStatus != STMT_PREPARE) {
×
110
    STMT_DLOG("stmt already failed with err:%s", tstrerror(pStmt->errCode));
×
111
    return pStmt->errCode;
×
112
  }
113

UNCOV
114
  switch (newStatus) {
×
UNCOV
115
    case STMT_PREPARE:
×
UNCOV
116
      pStmt->errCode = 0;
×
UNCOV
117
      break;
×
UNCOV
118
    case STMT_SETTBNAME:
×
UNCOV
119
      if (STMT_STATUS_EQ(INIT)) {
×
120
        code = TSDB_CODE_TSC_STMT_API_ERROR;
×
121
      }
UNCOV
122
      if (!pStmt->sql.stbInterlaceMode && (STMT_STATUS_EQ(BIND) || STMT_STATUS_EQ(BIND_COL))) {
×
123
        code = TSDB_CODE_TSC_STMT_API_ERROR;
×
124
      }
UNCOV
125
      break;
×
UNCOV
126
    case STMT_SETTAGS:
×
UNCOV
127
      if (STMT_STATUS_EQ(INIT)) {
×
128
        code = TSDB_CODE_TSC_STMT_API_ERROR;
×
129
      }
UNCOV
130
      break;
×
UNCOV
131
    case STMT_FETCH_FIELDS:
×
UNCOV
132
      if (STMT_STATUS_EQ(INIT)) {
×
133
        code = TSDB_CODE_TSC_STMT_API_ERROR;
×
134
      }
UNCOV
135
      break;
×
UNCOV
136
    case STMT_BIND:
×
UNCOV
137
      if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND_COL)) {
×
138
        code = TSDB_CODE_TSC_STMT_API_ERROR;
×
139
      }
140
      /*
141
            if ((pStmt->sql.type == STMT_TYPE_MULTI_INSERT) && ()) {
142
              code = TSDB_CODE_TSC_STMT_API_ERROR;
143
            }
144
      */
UNCOV
145
      break;
×
146
    case STMT_BIND_COL:
×
147
      if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND)) {
×
148
        code = TSDB_CODE_TSC_STMT_API_ERROR;
×
149
      }
150
      break;
×
UNCOV
151
    case STMT_ADD_BATCH:
×
UNCOV
152
      if (STMT_STATUS_NE(BIND) && STMT_STATUS_NE(BIND_COL) && STMT_STATUS_NE(FETCH_FIELDS)) {
×
153
        code = TSDB_CODE_TSC_STMT_API_ERROR;
×
154
      }
UNCOV
155
      break;
×
UNCOV
156
    case STMT_EXECUTE:
×
UNCOV
157
      if (STMT_TYPE_QUERY == pStmt->sql.type) {
×
UNCOV
158
        if (STMT_STATUS_NE(ADD_BATCH) && STMT_STATUS_NE(FETCH_FIELDS) && STMT_STATUS_NE(BIND) &&
×
159
            STMT_STATUS_NE(BIND_COL)) {
×
160
          code = TSDB_CODE_TSC_STMT_API_ERROR;
×
161
        }
162
      } else {
UNCOV
163
        if (STMT_STATUS_NE(ADD_BATCH) && STMT_STATUS_NE(FETCH_FIELDS)) {
×
UNCOV
164
          code = TSDB_CODE_TSC_STMT_API_ERROR;
×
165
        }
166
      }
UNCOV
167
      break;
×
168
    default:
×
169
      code = TSDB_CODE_APP_ERROR;
×
170
      break;
×
171
  }
172

UNCOV
173
  STMT_ERR_RET(code);
×
174

UNCOV
175
  pStmt->sql.status = newStatus;
×
176

UNCOV
177
  return TSDB_CODE_SUCCESS;
×
178
}
179

UNCOV
180
static int32_t stmtGetTbName(TAOS_STMT2* stmt, char** tbName) {
×
UNCOV
181
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
182

UNCOV
183
  pStmt->sql.type = STMT_TYPE_MULTI_INSERT;
×
184

UNCOV
185
  if ('\0' == pStmt->bInfo.tbName[0]) {
×
UNCOV
186
    tscWarn("no table name set, OK if it is a stmt get fields");
×
UNCOV
187
    STMT_ERR_RET(TSDB_CODE_TSC_STMT_TBNAME_ERROR);
×
188
  }
189

UNCOV
190
  *tbName = pStmt->bInfo.tbName;
×
191

UNCOV
192
  return TSDB_CODE_SUCCESS;
×
193
}
194

UNCOV
195
static int32_t stmtUpdateBindInfo(TAOS_STMT2* stmt, STableMeta* pTableMeta, void* tags, SName* tbName,
×
196
                                  const char* sTableName, bool autoCreateTbl, bool preCtbname) {
UNCOV
197
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
198
  char       tbFName[TSDB_TABLE_FNAME_LEN];
UNCOV
199
  int32_t    code = tNameExtractFullName(tbName, tbFName);
×
UNCOV
200
  if (code != 0) {
×
201
    return code;
×
202
  }
203

UNCOV
204
  (void)memcpy(&pStmt->bInfo.sname, tbName, sizeof(*tbName));
×
UNCOV
205
  tstrncpy(pStmt->bInfo.tbFName, tbFName, sizeof(pStmt->bInfo.tbFName));
×
UNCOV
206
  pStmt->bInfo.tbFName[sizeof(pStmt->bInfo.tbFName) - 1] = 0;
×
207

UNCOV
208
  pStmt->bInfo.tbUid = autoCreateTbl ? 0 : pTableMeta->uid;
×
UNCOV
209
  pStmt->bInfo.tbSuid = pTableMeta->suid;
×
UNCOV
210
  pStmt->bInfo.tbVgId = pTableMeta->vgId;
×
UNCOV
211
  pStmt->bInfo.tbType = pTableMeta->tableType;
×
212

UNCOV
213
  if (!pStmt->bInfo.tagsCached) {
×
UNCOV
214
    qDestroyBoundColInfo(pStmt->bInfo.boundTags);
×
UNCOV
215
    taosMemoryFreeClear(pStmt->bInfo.boundTags);
×
216
  }
217

UNCOV
218
  pStmt->bInfo.boundTags = tags;
×
UNCOV
219
  pStmt->bInfo.tagsCached = false;
×
UNCOV
220
  pStmt->bInfo.preCtbname = preCtbname;
×
UNCOV
221
  tstrncpy(pStmt->bInfo.stbFName, sTableName, sizeof(pStmt->bInfo.stbFName));
×
222

UNCOV
223
  return TSDB_CODE_SUCCESS;
×
224
}
225

UNCOV
226
static int32_t stmtUpdateExecInfo(TAOS_STMT2* stmt, SHashObj* pVgHash, SHashObj* pBlockHash) {
×
UNCOV
227
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
228

UNCOV
229
  pStmt->sql.pVgHash = pVgHash;
×
UNCOV
230
  pStmt->exec.pBlockHash = pBlockHash;
×
231

UNCOV
232
  return TSDB_CODE_SUCCESS;
×
233
}
234

UNCOV
235
static int32_t stmtUpdateInfo(TAOS_STMT2* stmt, STableMeta* pTableMeta, void* tags, SName* tbName, bool autoCreateTbl,
×
236
                              SHashObj* pVgHash, SHashObj* pBlockHash, const char* sTableName, bool preCtbname) {
UNCOV
237
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
238

UNCOV
239
  STMT_ERR_RET(stmtUpdateBindInfo(stmt, pTableMeta, tags, tbName, sTableName, autoCreateTbl, preCtbname));
×
UNCOV
240
  STMT_ERR_RET(stmtUpdateExecInfo(stmt, pVgHash, pBlockHash));
×
241

UNCOV
242
  pStmt->sql.autoCreateTbl = autoCreateTbl;
×
243

UNCOV
244
  return TSDB_CODE_SUCCESS;
×
245
}
246

UNCOV
247
static int32_t stmtGetExecInfo(TAOS_STMT2* stmt, SHashObj** pVgHash, SHashObj** pBlockHash) {
×
UNCOV
248
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
249

250
  *pVgHash = pStmt->sql.pVgHash;
×
251
  pStmt->sql.pVgHash = NULL;
×
252

253
  *pBlockHash = pStmt->exec.pBlockHash;
×
254
  pStmt->exec.pBlockHash = NULL;
×
255

256
  return TSDB_CODE_SUCCESS;
×
257
}
258

259
static int32_t stmtParseSql(STscStmt2* pStmt) {
×
UNCOV
260
  pStmt->exec.pCurrBlock = NULL;
×
261

UNCOV
262
  SStmtCallback stmtCb = {
×
263
      .pStmt = pStmt,
264
      .getTbNameFn = stmtGetTbName,
265
      .setInfoFn = stmtUpdateInfo,
266
      .getExecInfoFn = stmtGetExecInfo,
267
  };
268

UNCOV
269
  STMT_ERR_RET(stmtCreateRequest(pStmt));
×
270

UNCOV
271
  pStmt->stat.parseSqlNum++;
×
UNCOV
272
  STMT_ERR_RET(parseSql(pStmt->exec.pRequest, false, &pStmt->sql.pQuery, &stmtCb));
×
UNCOV
273
  pStmt->sql.siInfo.pQuery = pStmt->sql.pQuery;
×
274

UNCOV
275
  pStmt->bInfo.needParse = false;
×
276

UNCOV
277
  if (pStmt->sql.pQuery->pRoot && 0 == pStmt->sql.type) {
×
UNCOV
278
    pStmt->sql.type = STMT_TYPE_INSERT;
×
UNCOV
279
    pStmt->sql.stbInterlaceMode = false;
×
UNCOV
280
  } else if (pStmt->sql.pQuery->pPrepareRoot) {
×
UNCOV
281
    pStmt->sql.type = STMT_TYPE_QUERY;
×
UNCOV
282
    pStmt->sql.stbInterlaceMode = false;
×
283

UNCOV
284
    return TSDB_CODE_SUCCESS;
×
285
  }
286

287
  STableDataCxt** pSrc =
UNCOV
288
      (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
UNCOV
289
  if (NULL == pSrc || NULL == *pSrc) {
×
UNCOV
290
    return terrno;
×
291
  }
292

293
  STableDataCxt* pTableCtx = *pSrc;
×
294
  // if (pStmt->sql.stbInterlaceMode) {
295
  //   int16_t lastIdx = -1;
296

297
  //   for (int32_t i = 0; i < pTableCtx->boundColsInfo.numOfBound; ++i) {
298
  //     if (pTableCtx->boundColsInfo.pColIndex[i] < lastIdx) {
299
  //       pStmt->sql.stbInterlaceMode = false;
300
  //       break;
301
  //     }
302

303
  //     lastIdx = pTableCtx->boundColsInfo.pColIndex[i];
304
  //   }
305
  // }
306

UNCOV
307
  if (NULL == pStmt->sql.pBindInfo) {
×
UNCOV
308
    pStmt->sql.pBindInfo = taosMemoryMalloc(pTableCtx->boundColsInfo.numOfBound * sizeof(*pStmt->sql.pBindInfo));
×
UNCOV
309
    if (NULL == pStmt->sql.pBindInfo) {
×
UNCOV
310
      return terrno;
×
311
    }
312
  }
313

UNCOV
314
  return TSDB_CODE_SUCCESS;
×
315
}
316

UNCOV
317
static int32_t stmtCleanBindInfo(STscStmt2* pStmt) {
×
UNCOV
318
  pStmt->bInfo.tbUid = 0;
×
UNCOV
319
  pStmt->bInfo.tbVgId = -1;
×
UNCOV
320
  pStmt->bInfo.tbType = 0;
×
UNCOV
321
  pStmt->bInfo.needParse = true;
×
UNCOV
322
  pStmt->bInfo.inExecCache = false;
×
323

UNCOV
324
  pStmt->bInfo.tbName[0] = 0;
×
UNCOV
325
  pStmt->bInfo.tbFName[0] = 0;
×
UNCOV
326
  if (!pStmt->bInfo.tagsCached) {
×
UNCOV
327
    qDestroyBoundColInfo(pStmt->bInfo.boundTags);
×
UNCOV
328
    taosMemoryFreeClear(pStmt->bInfo.boundTags);
×
329
  }
UNCOV
330
  if (!pStmt->sql.autoCreateTbl) {
×
UNCOV
331
    pStmt->bInfo.stbFName[0] = 0;
×
UNCOV
332
    pStmt->bInfo.tbSuid = 0;
×
333
  }
334

UNCOV
335
  return TSDB_CODE_SUCCESS;
×
336
}
337

UNCOV
338
static void stmtFreeTableBlkList(STableColsData* pTb) {
×
339
  (void)qResetStmtColumns(pTb->aCol, true);
×
340
  taosArrayDestroy(pTb->aCol);
×
341
}
×
342

UNCOV
343
static void stmtResetQueueTableBuf(STableBufInfo* pTblBuf, SStmtQueue* pQueue) {
×
UNCOV
344
  pTblBuf->pCurBuff = taosArrayGetP(pTblBuf->pBufList, 0);
×
UNCOV
345
  if (NULL == pTblBuf->pCurBuff) {
×
UNCOV
346
    tscError("QInfo:%p, failed to get buffer from list", pTblBuf);
×
347
    return;
×
348
  }
UNCOV
349
  pTblBuf->buffIdx = 1;
×
UNCOV
350
  pTblBuf->buffOffset = sizeof(*pQueue->head);
×
351

UNCOV
352
  pQueue->head = pQueue->tail = pTblBuf->pCurBuff;
×
UNCOV
353
  pQueue->qRemainNum = 0;
×
UNCOV
354
  pQueue->head->next = NULL;
×
355
}
356

UNCOV
357
static int32_t stmtCleanExecInfo(STscStmt2* pStmt, bool keepTable, bool deepClean) {
×
UNCOV
358
  if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
359
    if (deepClean) {
×
UNCOV
360
      taosHashCleanup(pStmt->exec.pBlockHash);
×
UNCOV
361
      pStmt->exec.pBlockHash = NULL;
×
362

UNCOV
363
      if (NULL != pStmt->exec.pCurrBlock) {
×
UNCOV
364
        taosMemoryFreeClear(pStmt->exec.pCurrBlock->pData);
×
UNCOV
365
        qDestroyStmtDataBlock(pStmt->exec.pCurrBlock);
×
366
      }
367
    } else {
UNCOV
368
      pStmt->sql.siInfo.pTableColsIdx = 0;
×
UNCOV
369
      stmtResetQueueTableBuf(&pStmt->sql.siInfo.tbBuf, &pStmt->queue);
×
370
    }
UNCOV
371
    if (NULL != pStmt->exec.pRequest) {
×
UNCOV
372
      pStmt->exec.pRequest->body.resInfo.numOfRows = 0;
×
373
    }
374
  } else {
UNCOV
375
    if (STMT_TYPE_QUERY != pStmt->sql.type || deepClean) {
×
376
      // if (!pStmt->options.asyncExecFn) {
UNCOV
377
      taos_free_result(pStmt->exec.pRequest);
×
UNCOV
378
      pStmt->exec.pRequest = NULL;
×
379
      //}
380
    }
381

UNCOV
382
    size_t keyLen = 0;
×
UNCOV
383
    void*  pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
×
UNCOV
384
    while (pIter) {
×
UNCOV
385
      STableDataCxt* pBlocks = *(STableDataCxt**)pIter;
×
UNCOV
386
      char*          key = taosHashGetKey(pIter, &keyLen);
×
UNCOV
387
      STableMeta*    pMeta = qGetTableMetaInDataBlock(pBlocks);
×
388

UNCOV
389
      if (keepTable && pBlocks == pStmt->exec.pCurrBlock) {
×
UNCOV
390
        TSWAP(pBlocks->pData, pStmt->exec.pCurrTbData);
×
UNCOV
391
        STMT_ERR_RET(qResetStmtDataBlock(pBlocks, false));
×
392

UNCOV
393
        pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
×
UNCOV
394
        continue;
×
395
      }
396

UNCOV
397
      qDestroyStmtDataBlock(pBlocks);
×
UNCOV
398
      STMT_ERR_RET(taosHashRemove(pStmt->exec.pBlockHash, key, keyLen));
×
399

UNCOV
400
      pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
×
401
    }
402

UNCOV
403
    if (keepTable) {
×
UNCOV
404
      return TSDB_CODE_SUCCESS;
×
405
    }
406

UNCOV
407
    taosHashCleanup(pStmt->exec.pBlockHash);
×
UNCOV
408
    pStmt->exec.pBlockHash = NULL;
×
409

UNCOV
410
    tDestroySubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
×
UNCOV
411
    taosMemoryFreeClear(pStmt->exec.pCurrTbData);
×
412
  }
413

UNCOV
414
  STMT_ERR_RET(stmtCleanBindInfo(pStmt));
×
415

UNCOV
416
  return TSDB_CODE_SUCCESS;
×
417
}
418

UNCOV
419
static void stmtFreeTbBuf(void* buf) {
×
UNCOV
420
  void* pBuf = *(void**)buf;
×
UNCOV
421
  taosMemoryFree(pBuf);
×
UNCOV
422
}
×
423

UNCOV
424
static void stmtFreeTbCols(void* buf) {
×
UNCOV
425
  SArray* pCols = *(SArray**)buf;
×
UNCOV
426
  taosArrayDestroy(pCols);
×
UNCOV
427
}
×
428

UNCOV
429
static int32_t stmtCleanSQLInfo(STscStmt2* pStmt) {
×
UNCOV
430
  STMT_DLOG_E("start to free SQL info");
×
431

UNCOV
432
  taosMemoryFreeClear(pStmt->db);
×
UNCOV
433
  taosMemoryFree(pStmt->sql.pBindInfo);
×
UNCOV
434
  taosMemoryFree(pStmt->sql.queryRes.fields);
×
UNCOV
435
  taosMemoryFree(pStmt->sql.queryRes.userFields);
×
UNCOV
436
  taosMemoryFree(pStmt->sql.sqlStr);
×
UNCOV
437
  qDestroyQuery(pStmt->sql.pQuery);
×
UNCOV
438
  taosArrayDestroy(pStmt->sql.nodeList);
×
UNCOV
439
  taosHashCleanup(pStmt->sql.pVgHash);
×
UNCOV
440
  pStmt->sql.pVgHash = NULL;
×
UNCOV
441
  if (pStmt->sql.fixValueTags) {
×
UNCOV
442
    tdDestroySVCreateTbReq(pStmt->sql.fixValueTbReq);
×
443
  }
444

UNCOV
445
  void* pIter = taosHashIterate(pStmt->sql.pTableCache, NULL);
×
UNCOV
446
  while (pIter) {
×
UNCOV
447
    SStmtTableCache* pCache = (SStmtTableCache*)pIter;
×
448

UNCOV
449
    qDestroyStmtDataBlock(pCache->pDataCtx);
×
UNCOV
450
    qDestroyBoundColInfo(pCache->boundTags);
×
UNCOV
451
    taosMemoryFreeClear(pCache->boundTags);
×
452

UNCOV
453
    pIter = taosHashIterate(pStmt->sql.pTableCache, pIter);
×
454
  }
UNCOV
455
  taosHashCleanup(pStmt->sql.pTableCache);
×
UNCOV
456
  pStmt->sql.pTableCache = NULL;
×
457

UNCOV
458
  STMT_ERR_RET(stmtCleanExecInfo(pStmt, false, true));
×
UNCOV
459
  STMT_ERR_RET(stmtCleanBindInfo(pStmt));
×
460

UNCOV
461
  taos_free_result(pStmt->sql.siInfo.pRequest);
×
UNCOV
462
  taosHashCleanup(pStmt->sql.siInfo.pVgroupHash);
×
UNCOV
463
  tSimpleHashCleanup(pStmt->sql.siInfo.pTableHash);
×
UNCOV
464
  taosArrayDestroyEx(pStmt->sql.siInfo.tbBuf.pBufList, stmtFreeTbBuf);
×
UNCOV
465
  taosMemoryFree(pStmt->sql.siInfo.pTSchema);
×
UNCOV
466
  qDestroyStmtDataBlock(pStmt->sql.siInfo.pDataCtx);
×
UNCOV
467
  taosArrayDestroyEx(pStmt->sql.siInfo.pTableCols, stmtFreeTbCols);
×
468

UNCOV
469
  (void)memset(&pStmt->sql, 0, sizeof(pStmt->sql));
×
UNCOV
470
  pStmt->sql.siInfo.tableColsReady = true;
×
471

UNCOV
472
  STMT_DLOG_E("end to free SQL info");
×
473

UNCOV
474
  return TSDB_CODE_SUCCESS;
×
475
}
476

UNCOV
477
static int32_t stmtTryAddTableVgroupInfo(STscStmt2* pStmt, int32_t* vgId) {
×
UNCOV
478
  if (*vgId >= 0 && taosHashGet(pStmt->sql.pVgHash, (const char*)vgId, sizeof(*vgId))) {
×
UNCOV
479
    return TSDB_CODE_SUCCESS;
×
480
  }
481

UNCOV
482
  SVgroupInfo      vgInfo = {0};
×
UNCOV
483
  SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
×
UNCOV
484
                           .requestId = pStmt->exec.pRequest->requestId,
×
UNCOV
485
                           .requestObjRefId = pStmt->exec.pRequest->self,
×
UNCOV
486
                           .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
×
487

488
  int32_t code = catalogGetTableHashVgroup(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &vgInfo);
×
UNCOV
489
  if (TSDB_CODE_SUCCESS != code) {
×
UNCOV
490
    return code;
×
491
  }
492

493
  code =
494
      taosHashPut(pStmt->sql.pVgHash, (const char*)&vgInfo.vgId, sizeof(vgInfo.vgId), (char*)&vgInfo, sizeof(vgInfo));
×
UNCOV
495
  if (TSDB_CODE_SUCCESS != code) {
×
UNCOV
496
    return code;
×
497
  }
498

UNCOV
499
  *vgId = vgInfo.vgId;
×
500

UNCOV
501
  return TSDB_CODE_SUCCESS;
×
502
}
503

UNCOV
504
static int32_t stmtRebuildDataBlock(STscStmt2* pStmt, STableDataCxt* pDataBlock, STableDataCxt** newBlock, uint64_t uid,
×
505
                                    uint64_t suid, int32_t vgId) {
UNCOV
506
  STMT_ERR_RET(stmtTryAddTableVgroupInfo(pStmt, &vgId));
×
UNCOV
507
  STMT_ERR_RET(qRebuildStmtDataBlock(newBlock, pDataBlock, uid, suid, vgId, pStmt->sql.autoCreateTbl));
×
508

UNCOV
509
  STMT_DLOG("uid:%" PRId64 ", rebuild table data context, vgId:%d", uid, vgId);
×
510

UNCOV
511
  return TSDB_CODE_SUCCESS;
×
512
}
513

514
static int32_t stmtGetFromCache(STscStmt2* pStmt) {
×
515
  if (pStmt->sql.stbInterlaceMode && pStmt->sql.siInfo.pDataCtx) {
×
516
    pStmt->bInfo.needParse = false;
×
UNCOV
517
    pStmt->bInfo.inExecCache = false;
×
UNCOV
518
    return TSDB_CODE_SUCCESS;
×
519
  }
520

UNCOV
521
  pStmt->bInfo.needParse = true;
×
UNCOV
522
  pStmt->bInfo.inExecCache = false;
×
523

UNCOV
524
  STableDataCxt** pCxtInExec = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
UNCOV
525
  if (pCxtInExec) {
×
UNCOV
526
    pStmt->bInfo.needParse = false;
×
UNCOV
527
    pStmt->bInfo.inExecCache = true;
×
528

UNCOV
529
    pStmt->exec.pCurrBlock = *pCxtInExec;
×
530

UNCOV
531
    if (pStmt->sql.autoCreateTbl) {
×
UNCOV
532
      tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName);
×
UNCOV
533
      return TSDB_CODE_SUCCESS;
×
534
    }
535
  }
536

UNCOV
537
  if (NULL == pStmt->pCatalog) {
×
UNCOV
538
    STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &pStmt->pCatalog));
×
UNCOV
539
    pStmt->sql.siInfo.pCatalog = pStmt->pCatalog;
×
540
  }
541

542
  if (NULL == pStmt->sql.pTableCache || taosHashGetSize(pStmt->sql.pTableCache) <= 0) {
×
543
    if (pStmt->bInfo.inExecCache) {
×
544
      pStmt->bInfo.needParse = false;
×
UNCOV
545
      tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName);
×
UNCOV
546
      return TSDB_CODE_SUCCESS;
×
547
    }
548

UNCOV
549
    tscDebug("no stmt block cache for tb %s", pStmt->bInfo.tbFName);
×
UNCOV
550
    return TSDB_CODE_SUCCESS;
×
551
  }
552

UNCOV
553
  if (pStmt->sql.autoCreateTbl) {
×
UNCOV
554
    SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pStmt->bInfo.tbSuid, sizeof(pStmt->bInfo.tbSuid));
×
UNCOV
555
    if (pCache) {
×
UNCOV
556
      pStmt->bInfo.needParse = false;
×
UNCOV
557
      pStmt->bInfo.tbUid = 0;
×
558

UNCOV
559
      STableDataCxt* pNewBlock = NULL;
×
UNCOV
560
      STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataCtx, &pNewBlock, 0, pStmt->bInfo.tbSuid, -1));
×
561

562
      if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock,
×
563
                      POINTER_BYTES)) {
UNCOV
564
        STMT_ERR_RET(terrno);
×
565
      }
566

UNCOV
567
      pStmt->exec.pCurrBlock = pNewBlock;
×
568

UNCOV
569
      tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64, pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid);
×
570

UNCOV
571
      return TSDB_CODE_SUCCESS;
×
572
    }
573

UNCOV
574
    STMT_RET(stmtCleanBindInfo(pStmt));
×
575
  }
576

577
  uint64_t uid, suid;
578
  int32_t  vgId;
579
  int8_t   tableType;
580

UNCOV
581
  STableMeta*      pTableMeta = NULL;
×
UNCOV
582
  SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
×
UNCOV
583
                           .requestId = pStmt->exec.pRequest->requestId,
×
UNCOV
584
                           .requestObjRefId = pStmt->exec.pRequest->self,
×
UNCOV
585
                           .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
×
UNCOV
586
  int32_t          code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta);
×
587

UNCOV
588
  pStmt->stat.ctgGetTbMetaNum++;
×
589

590
  if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
×
UNCOV
591
    tscDebug("tb %s not exist", pStmt->bInfo.tbFName);
×
592
    STMT_ERR_RET(stmtCleanBindInfo(pStmt));
×
593

UNCOV
594
    STMT_ERR_RET(code);
×
595
  }
596

UNCOV
597
  STMT_ERR_RET(code);
×
598

UNCOV
599
  uid = pTableMeta->uid;
×
UNCOV
600
  suid = pTableMeta->suid;
×
UNCOV
601
  tableType = pTableMeta->tableType;
×
UNCOV
602
  pStmt->bInfo.tbVgId = pTableMeta->vgId;
×
UNCOV
603
  vgId = pTableMeta->vgId;
×
604

UNCOV
605
  taosMemoryFree(pTableMeta);
×
606

UNCOV
607
  uint64_t cacheUid = (TSDB_CHILD_TABLE == tableType) ? suid : uid;
×
608

UNCOV
609
  if (uid == pStmt->bInfo.tbUid) {
×
610
    pStmt->bInfo.needParse = false;
×
611

612
    tscDebug("tb %s is current table", pStmt->bInfo.tbFName);
×
613

UNCOV
614
    return TSDB_CODE_SUCCESS;
×
615
  }
616

UNCOV
617
  if (pStmt->bInfo.inExecCache) {
×
618
    SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid));
×
UNCOV
619
    if (NULL == pCache) {
×
UNCOV
620
      tscError("table [%s, %" PRIx64 ", %" PRIx64 "] found in exec blockHash, but not in sql blockHash",
×
621
               pStmt->bInfo.tbFName, uid, cacheUid);
622

UNCOV
623
      STMT_ERR_RET(TSDB_CODE_APP_ERROR);
×
624
    }
625

UNCOV
626
    pStmt->bInfo.needParse = false;
×
627

UNCOV
628
    pStmt->bInfo.tbUid = uid;
×
UNCOV
629
    pStmt->bInfo.tbSuid = suid;
×
UNCOV
630
    pStmt->bInfo.tbType = tableType;
×
UNCOV
631
    pStmt->bInfo.boundTags = pCache->boundTags;
×
UNCOV
632
    pStmt->bInfo.tagsCached = true;
×
633

UNCOV
634
    tscDebug("tb %s in execBlock list, set to current", pStmt->bInfo.tbFName);
×
635

UNCOV
636
    return TSDB_CODE_SUCCESS;
×
637
  }
638

UNCOV
639
  SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid));
×
UNCOV
640
  if (pCache) {
×
UNCOV
641
    pStmt->bInfo.needParse = false;
×
642

UNCOV
643
    pStmt->bInfo.tbUid = uid;
×
UNCOV
644
    pStmt->bInfo.tbSuid = suid;
×
UNCOV
645
    pStmt->bInfo.tbType = tableType;
×
UNCOV
646
    pStmt->bInfo.boundTags = pCache->boundTags;
×
UNCOV
647
    pStmt->bInfo.tagsCached = true;
×
648

UNCOV
649
    STableDataCxt* pNewBlock = NULL;
×
UNCOV
650
    STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataCtx, &pNewBlock, uid, suid, vgId));
×
651

652
    if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock,
×
653
                    POINTER_BYTES)) {
UNCOV
654
      STMT_ERR_RET(terrno);
×
655
    }
656

UNCOV
657
    pStmt->exec.pCurrBlock = pNewBlock;
×
658

UNCOV
659
    tscDebug("tb %s in sqlBlock list, set to current", pStmt->bInfo.tbFName);
×
660

UNCOV
661
    return TSDB_CODE_SUCCESS;
×
662
  }
663

664
  STMT_ERR_RET(stmtCleanBindInfo(pStmt));
×
665

UNCOV
666
  return TSDB_CODE_SUCCESS;
×
667
}
668

UNCOV
669
static int32_t stmtResetStmt(STscStmt2* pStmt) {
×
UNCOV
670
  STMT_ERR_RET(stmtCleanSQLInfo(pStmt));
×
671

672
  pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
×
UNCOV
673
  if (NULL == pStmt->sql.pTableCache) {
×
UNCOV
674
    STMT_ERR_RET(terrno);
×
675
  }
676

UNCOV
677
  pStmt->sql.status = STMT_INIT;
×
678

UNCOV
679
  return TSDB_CODE_SUCCESS;
×
680
}
681

UNCOV
682
static int32_t stmtAsyncOutput(STscStmt2* pStmt, void* param) {
×
UNCOV
683
  SStmtQNode* pParam = (SStmtQNode*)param;
×
684

UNCOV
685
  if (pParam->restoreTbCols) {
×
UNCOV
686
    for (int32_t i = 0; i < pStmt->sql.siInfo.pTableColsIdx; ++i) {
×
UNCOV
687
      SArray** p = (SArray**)TARRAY_GET_ELEM(pStmt->sql.siInfo.pTableCols, i);
×
688
      *p = taosArrayInit(20, POINTER_BYTES);
×
UNCOV
689
      if (*p == NULL) {
×
UNCOV
690
        STMT_ERR_RET(terrno);
×
691
      }
692
    }
693

UNCOV
694
    atomic_store_8((int8_t*)&pStmt->sql.siInfo.tableColsReady, true);
×
695
  } else {
UNCOV
696
    int code = qAppendStmtTableOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, &pParam->tblData, pStmt->exec.pCurrBlock,
×
697
                                      &pStmt->sql.siInfo, pParam->pCreateTbReq);
698
    // taosMemoryFree(pParam->pTbData);
UNCOV
699
    (void)atomic_sub_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1);
×
UNCOV
700
    STMT_ERR_RET(code);
×
701
  }
UNCOV
702
  return TSDB_CODE_SUCCESS;
×
703
}
704

UNCOV
705
static void* stmtBindThreadFunc(void* param) {
×
UNCOV
706
  setThreadName("stmtBind");
×
707

UNCOV
708
  qInfo("stmt bind thread started");
×
709

UNCOV
710
  STscStmt2* pStmt = (STscStmt2*)param;
×
711

UNCOV
712
  while (true) {
×
UNCOV
713
    if (pStmt->queue.stopQueue) {
×
UNCOV
714
      break;
×
715
    }
716

UNCOV
717
    SStmtQNode* asyncParam = NULL;
×
UNCOV
718
    if (!stmtDequeue(pStmt, &asyncParam)) {
×
UNCOV
719
      continue;
×
720
    }
721

722
    if (stmtAsyncOutput(pStmt, asyncParam) != 0) {
×
UNCOV
723
      qError("stmt async output failed");
×
724
    }
725
  }
726

UNCOV
727
  qInfo("stmt bind thread stopped");
×
728

UNCOV
729
  return NULL;
×
730
}
731

UNCOV
732
static int32_t stmtStartBindThread(STscStmt2* pStmt) {
×
733
  TdThreadAttr thAttr;
734
  if (taosThreadAttrInit(&thAttr) != 0) {
×
UNCOV
735
    return TSDB_CODE_TSC_INTERNAL_ERROR;
×
736
  }
737
  if (taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE) != 0) {
×
UNCOV
738
    return TSDB_CODE_TSC_INTERNAL_ERROR;
×
739
  }
740

741
  if (taosThreadCreate(&pStmt->bindThread, &thAttr, stmtBindThreadFunc, pStmt) != 0) {
×
742
    terrno = TAOS_SYSTEM_ERROR(ERRNO);
×
UNCOV
743
    STMT_ERR_RET(terrno);
×
744
  }
745

UNCOV
746
  pStmt->bindThreadInUse = true;
×
747

UNCOV
748
  (void)taosThreadAttrDestroy(&thAttr);
×
UNCOV
749
  return TSDB_CODE_SUCCESS;
×
750
}
751

UNCOV
752
static int32_t stmtInitQueue(STscStmt2* pStmt) {
×
UNCOV
753
  (void)taosThreadCondInit(&pStmt->queue.waitCond, NULL);
×
UNCOV
754
  (void)taosThreadMutexInit(&pStmt->queue.mutex, NULL);
×
UNCOV
755
  STMT_ERR_RET(stmtAllocQNodeFromBuf(&pStmt->sql.siInfo.tbBuf, (void**)&pStmt->queue.head));
×
UNCOV
756
  pStmt->queue.tail = pStmt->queue.head;
×
757

UNCOV
758
  return TSDB_CODE_SUCCESS;
×
759
}
760

UNCOV
761
static int32_t stmtIniAsyncBind(STscStmt2* pStmt) {
×
UNCOV
762
  (void)taosThreadCondInit(&pStmt->asyncBindParam.waitCond, NULL);
×
UNCOV
763
  (void)taosThreadMutexInit(&pStmt->asyncBindParam.mutex, NULL);
×
UNCOV
764
  pStmt->asyncBindParam.asyncBindNum = 0;
×
765

UNCOV
766
  return TSDB_CODE_SUCCESS;
×
767
}
768

UNCOV
769
static int32_t stmtInitTableBuf(STableBufInfo* pTblBuf) {
×
UNCOV
770
  pTblBuf->buffUnit = sizeof(SStmtQNode);
×
UNCOV
771
  pTblBuf->buffSize = pTblBuf->buffUnit * 1000;
×
UNCOV
772
  pTblBuf->pBufList = taosArrayInit(100, POINTER_BYTES);
×
773
  if (NULL == pTblBuf->pBufList) {
×
UNCOV
774
    return terrno;
×
775
  }
UNCOV
776
  void* buff = taosMemoryMalloc(pTblBuf->buffSize);
×
777
  if (NULL == buff) {
×
UNCOV
778
    return terrno;
×
779
  }
780

781
  if (taosArrayPush(pTblBuf->pBufList, &buff) == NULL) {
×
UNCOV
782
    return terrno;
×
783
  }
784

UNCOV
785
  pTblBuf->pCurBuff = buff;
×
UNCOV
786
  pTblBuf->buffIdx = 1;
×
UNCOV
787
  pTblBuf->buffOffset = 0;
×
788

UNCOV
789
  return TSDB_CODE_SUCCESS;
×
790
}
791

UNCOV
792
TAOS_STMT2* stmtInit2(STscObj* taos, TAOS_STMT2_OPTION* pOptions) {
×
UNCOV
793
  STscObj*   pObj = (STscObj*)taos;
×
UNCOV
794
  STscStmt2* pStmt = NULL;
×
UNCOV
795
  int32_t    code = 0;
×
796

UNCOV
797
  pStmt = taosMemoryCalloc(1, sizeof(STscStmt2));
×
798
  if (NULL == pStmt) {
×
UNCOV
799
    return NULL;
×
800
  }
801

UNCOV
802
  pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
×
803
  if (NULL == pStmt->sql.pTableCache) {
×
804
    taosMemoryFree(pStmt);
×
UNCOV
805
    return NULL;
×
806
  }
807

UNCOV
808
  pStmt->taos = pObj;
×
UNCOV
809
  pStmt->bInfo.needParse = true;
×
UNCOV
810
  pStmt->sql.status = STMT_INIT;
×
UNCOV
811
  pStmt->errCode = TSDB_CODE_SUCCESS;
×
812

UNCOV
813
  if (NULL != pOptions) {
×
UNCOV
814
    (void)memcpy(&pStmt->options, pOptions, sizeof(pStmt->options));
×
UNCOV
815
    if (pOptions->singleStbInsert && pOptions->singleTableBindOnce) {
×
UNCOV
816
      pStmt->stbInterlaceMode = true;
×
817
    }
818

UNCOV
819
    pStmt->reqid = pOptions->reqid;
×
820
  }
821

UNCOV
822
  if (pStmt->stbInterlaceMode) {
×
UNCOV
823
    pStmt->sql.siInfo.transport = taos->pAppInfo->pTransporter;
×
UNCOV
824
    pStmt->sql.siInfo.acctId = taos->acctId;
×
UNCOV
825
    pStmt->sql.siInfo.dbname = taos->db;
×
UNCOV
826
    pStmt->sql.siInfo.mgmtEpSet = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp);
×
UNCOV
827
    pStmt->sql.siInfo.pTableHash = tSimpleHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
×
828
    if (NULL == pStmt->sql.siInfo.pTableHash) {
×
829
      (void)stmtClose2(pStmt);
×
UNCOV
830
      return NULL;
×
831
    }
UNCOV
832
    pStmt->sql.siInfo.pTableCols = taosArrayInit(STMT_TABLE_COLS_NUM, POINTER_BYTES);
×
833
    if (NULL == pStmt->sql.siInfo.pTableCols) {
×
834
      terrno = terrno;
×
835
      (void)stmtClose2(pStmt);
×
UNCOV
836
      return NULL;
×
837
    }
838

UNCOV
839
    code = stmtInitTableBuf(&pStmt->sql.siInfo.tbBuf);
×
UNCOV
840
    if (TSDB_CODE_SUCCESS == code) {
×
UNCOV
841
      code = stmtInitQueue(pStmt);
×
842
    }
UNCOV
843
    if (TSDB_CODE_SUCCESS == code) {
×
UNCOV
844
      code = stmtStartBindThread(pStmt);
×
845
    }
846
    if (TSDB_CODE_SUCCESS != code) {
×
847
      terrno = code;
×
848
      (void)stmtClose2(pStmt);
×
UNCOV
849
      return NULL;
×
850
    }
851
  }
852

UNCOV
853
  pStmt->sql.siInfo.tableColsReady = true;
×
UNCOV
854
  if (pStmt->options.asyncExecFn) {
×
855
    if (tsem_init(&pStmt->asyncExecSem, 0, 1) != 0) {
×
856
      terrno = TAOS_SYSTEM_ERROR(ERRNO);
×
857
      (void)stmtClose2(pStmt);
×
UNCOV
858
      return NULL;
×
859
    }
860
  }
UNCOV
861
  code = stmtIniAsyncBind(pStmt);
×
862
  if (TSDB_CODE_SUCCESS != code) {
×
863
    terrno = code;
×
864
    (void)stmtClose2(pStmt);
×
UNCOV
865
    return NULL;
×
866
  }
867

UNCOV
868
  pStmt->execSemWaited = false;
×
869

UNCOV
870
  STMT_LOG_SEQ(STMT_INIT);
×
871

UNCOV
872
  tscDebug("stmt:%p initialized", pStmt);
×
873

UNCOV
874
  return pStmt;
×
875
}
876

UNCOV
877
static int stmtSetDbName2(TAOS_STMT2* stmt, const char* dbName) {
×
UNCOV
878
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
879

UNCOV
880
  STMT_DLOG("start to set dbName:%s", dbName);
×
881

UNCOV
882
  pStmt->db = taosStrdup(dbName);
×
UNCOV
883
  (void)strdequote(pStmt->db);
×
UNCOV
884
  STMT_ERR_RET(stmtCreateRequest(pStmt));
×
885

886
  // The SQL statement specifies a database name, overriding the previously specified database
UNCOV
887
  taosMemoryFreeClear(pStmt->exec.pRequest->pDb);
×
UNCOV
888
  pStmt->exec.pRequest->pDb = taosStrdup(pStmt->db);
×
889
  if (pStmt->exec.pRequest->pDb == NULL) {
×
UNCOV
890
    return terrno;
×
891
  }
UNCOV
892
  return TSDB_CODE_SUCCESS;
×
893
}
894

UNCOV
895
int stmtPrepare2(TAOS_STMT2* stmt, const char* sql, unsigned long length) {
×
UNCOV
896
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
897

UNCOV
898
  STMT_DLOG_E("start to prepare");
×
899

UNCOV
900
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
901
    return pStmt->errCode;
×
902
  }
903

UNCOV
904
  if (pStmt->sql.status >= STMT_PREPARE) {
×
UNCOV
905
    STMT_ERR_RET(stmtResetStmt(pStmt));
×
906
  }
907

UNCOV
908
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_PREPARE));
×
909

UNCOV
910
  if (length <= 0) {
×
UNCOV
911
    length = strlen(sql);
×
912
  }
913

UNCOV
914
  pStmt->sql.sqlStr = taosStrndup(sql, length);
×
915
  if (!pStmt->sql.sqlStr) {
×
UNCOV
916
    return terrno;
×
917
  }
UNCOV
918
  pStmt->sql.sqlLen = length;
×
UNCOV
919
  pStmt->sql.stbInterlaceMode = pStmt->stbInterlaceMode;
×
920

UNCOV
921
  char* dbName = NULL;
×
UNCOV
922
  if (qParseDbName(sql, length, &dbName)) {
×
UNCOV
923
    STMT_ERR_RET(stmtSetDbName2(stmt, dbName));
×
UNCOV
924
    taosMemoryFreeClear(dbName);
×
925
  }
926

UNCOV
927
  return TSDB_CODE_SUCCESS;
×
928
}
929

UNCOV
930
static int32_t stmtInitStbInterlaceTableInfo(STscStmt2* pStmt) {
×
UNCOV
931
  STableDataCxt** pSrc = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
932
  if (!pSrc) {
×
UNCOV
933
    return terrno;
×
934
  }
UNCOV
935
  STableDataCxt* pDst = NULL;
×
936

UNCOV
937
  STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc, true));
×
UNCOV
938
  pStmt->sql.siInfo.pDataCtx = pDst;
×
939

UNCOV
940
  SArray* pTblCols = NULL;
×
UNCOV
941
  for (int32_t i = 0; i < STMT_TABLE_COLS_NUM; i++) {
×
UNCOV
942
    pTblCols = taosArrayInit(20, POINTER_BYTES);
×
943
    if (NULL == pTblCols) {
×
UNCOV
944
      return terrno;
×
945
    }
946

947
    if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) {
×
UNCOV
948
      return terrno;
×
949
    }
950
  }
951

UNCOV
952
  pStmt->sql.siInfo.boundTags = pStmt->bInfo.boundTags;
×
953

UNCOV
954
  return TSDB_CODE_SUCCESS;
×
955
}
956

UNCOV
957
int stmtIsInsert2(TAOS_STMT2* stmt, int* insert) {
×
UNCOV
958
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
959

UNCOV
960
  STMT_DLOG_E("start is insert");
×
961

UNCOV
962
  if (pStmt->sql.type) {
×
UNCOV
963
    *insert = (STMT_TYPE_INSERT == pStmt->sql.type || STMT_TYPE_MULTI_INSERT == pStmt->sql.type);
×
964
  } else {
UNCOV
965
    *insert = qIsInsertValuesSql(pStmt->sql.sqlStr, pStmt->sql.sqlLen);
×
966
  }
967

UNCOV
968
  return TSDB_CODE_SUCCESS;
×
969
}
970

UNCOV
971
int stmtSetTbName2(TAOS_STMT2* stmt, const char* tbName) {
×
UNCOV
972
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
973

UNCOV
974
  int64_t startUs = taosGetTimestampUs();
×
975

UNCOV
976
  STMT_DLOG("start to set tbName:%s", tbName);
×
977

978
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
979
    return pStmt->errCode;
×
980
  }
981

UNCOV
982
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME));
×
983

UNCOV
984
  int32_t insert = 0;
×
UNCOV
985
  STMT_ERR_RET(stmtIsInsert2(stmt, &insert));
×
986
  if (0 == insert) {
×
987
    tscError("set tb name not available for none insert statement");
×
UNCOV
988
    STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
×
989
  }
990

UNCOV
991
  if (!pStmt->sql.stbInterlaceMode || NULL == pStmt->sql.siInfo.pDataCtx) {
×
UNCOV
992
    STMT_ERR_RET(stmtCreateRequest(pStmt));
×
993

UNCOV
994
    STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb,
×
995
                              pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
UNCOV
996
    STMT_ERR_RET(tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName));
×
997

UNCOV
998
    STMT_ERR_RET(stmtGetFromCache(pStmt));
×
999

UNCOV
1000
    if (pStmt->bInfo.needParse) {
×
UNCOV
1001
      tstrncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName));
×
UNCOV
1002
      pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0;
×
1003

UNCOV
1004
      STMT_ERR_RET(stmtParseSql(pStmt));
×
1005
    }
1006
  } else {
UNCOV
1007
    tstrncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName));
×
UNCOV
1008
    pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0;
×
UNCOV
1009
    pStmt->exec.pRequest->requestId++;
×
UNCOV
1010
    pStmt->bInfo.needParse = false;
×
1011
  }
1012

UNCOV
1013
  if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) {
×
UNCOV
1014
    STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt));
×
1015
  }
1016

UNCOV
1017
  int64_t startUs2 = taosGetTimestampUs();
×
UNCOV
1018
  pStmt->stat.setTbNameUs += startUs2 - startUs;
×
1019

UNCOV
1020
  return TSDB_CODE_SUCCESS;
×
1021
}
1022

UNCOV
1023
int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags, SVCreateTbReq** pCreateTbReq) {
×
UNCOV
1024
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
1025

UNCOV
1026
  STMT_DLOG_E("start to set tbTags");
×
1027

1028
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
1029
    return pStmt->errCode;
×
1030
  }
1031

UNCOV
1032
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS));
×
1033

1034
  if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
×
1035
      STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
×
UNCOV
1036
    pStmt->bInfo.needParse = false;
×
1037
  }
UNCOV
1038
  STMT_ERR_RET(stmtCreateRequest(pStmt));
×
1039

1040
  if (pStmt->bInfo.needParse) {
×
UNCOV
1041
    STMT_ERR_RET(stmtParseSql(pStmt));
×
1042
  }
1043
  if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) {
×
UNCOV
1044
    STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt));
×
1045
  }
1046

UNCOV
1047
  SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags;
×
1048
  // if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) {
1049
  //   tscWarn("no tags or cols bound in sql, will not bound tags");
1050
  //   return TSDB_CODE_SUCCESS;
1051
  // }
UNCOV
1052
  if (pStmt->sql.autoCreateTbl && pStmt->sql.stbInterlaceMode) {
×
UNCOV
1053
    STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, pStmt->bInfo.tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb,
×
1054
                              pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
1055
    STMT_ERR_RET(tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName));
×
1056
  }
1057

UNCOV
1058
  STableDataCxt** pDataBlock = NULL;
×
UNCOV
1059
  if (pStmt->exec.pCurrBlock) {
×
1060
    pDataBlock = &pStmt->exec.pCurrBlock;
×
1061
  } else {
1062
    pDataBlock =
UNCOV
1063
        (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
UNCOV
1064
    if (NULL == pDataBlock) {
×
UNCOV
1065
      tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
×
UNCOV
1066
      STMT_ERR_RET(TSDB_CODE_TSC_STMT_CACHE_ERROR);
×
1067
    }
1068
    // pStmt->exec.pCurrBlock = *pDataBlock;
1069
    // if (pStmt->sql.stbInterlaceMode) {
1070
    //   taosArrayDestroy(pStmt->exec.pCurrBlock->pData->aCol);
1071
    //   (*pDataBlock)->pData->aCol = NULL;
1072
    // }
1073
  }
UNCOV
1074
  if (pStmt->bInfo.inExecCache && !pStmt->sql.autoCreateTbl) {
×
UNCOV
1075
    return TSDB_CODE_SUCCESS;
×
1076
  }
1077

1078
  tscDebug("start to bind stmt tag values");
×
1079

UNCOV
1080
  void* boundTags = NULL;
×
1081
  if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1082
    boundTags = pStmt->sql.siInfo.boundTags;
×
1083
    *pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
1084
    if (NULL == pCreateTbReq) {
×
UNCOV
1085
      return terrno;
×
1086
    }
1087
    int32_t vgId = -1;
×
1088
    STMT_ERR_RET(stmtTryAddTableVgroupInfo(pStmt, &vgId));
×
1089
    (*pCreateTbReq)->uid = vgId;
×
1090
  } else {
UNCOV
1091
    boundTags = pStmt->bInfo.boundTags;
×
1092
  }
1093

1094
  STMT_ERR_RET(qBindStmtTagsValue2(*pDataBlock, boundTags, pStmt->bInfo.tbSuid, pStmt->bInfo.stbFName,
×
1095
                                   pStmt->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf,
1096
                                   pStmt->exec.pRequest->msgBufLen, pStmt->taos->optionInfo.charsetCxt, *pCreateTbReq));
1097

UNCOV
1098
  return TSDB_CODE_SUCCESS;
×
1099
}
1100

UNCOV
1101
int stmtCheckTags2(TAOS_STMT2* stmt, SVCreateTbReq** pCreateTbReq) {
×
UNCOV
1102
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
1103

1104
  STMT_DLOG_E("start to set tbTags");
×
1105

UNCOV
1106
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
1107
    return pStmt->errCode;
×
1108
  }
1109

UNCOV
1110
  if (!pStmt->sql.stbInterlaceMode) {
×
UNCOV
1111
    return TSDB_CODE_SUCCESS;
×
1112
  }
1113

UNCOV
1114
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS));
×
1115

UNCOV
1116
  if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
×
UNCOV
1117
      STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
×
UNCOV
1118
    pStmt->bInfo.needParse = false;
×
1119
  }
1120
  STMT_ERR_RET(stmtCreateRequest(pStmt));
×
1121

UNCOV
1122
  if (pStmt->bInfo.needParse) {
×
UNCOV
1123
    STMT_ERR_RET(stmtParseSql(pStmt));
×
UNCOV
1124
    if (!pStmt->sql.autoCreateTbl) {
×
UNCOV
1125
      return TSDB_CODE_SUCCESS;
×
1126
    }
1127
  }
1128

UNCOV
1129
  if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) {
×
1130
    STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt));
×
1131
  }
1132

UNCOV
1133
  STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, pStmt->bInfo.tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb,
×
1134
                            pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
UNCOV
1135
  STMT_ERR_RET(tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName));
×
1136

UNCOV
1137
  STableDataCxt** pDataBlock = NULL;
×
UNCOV
1138
  if (pStmt->exec.pCurrBlock) {
×
UNCOV
1139
    pDataBlock = &pStmt->exec.pCurrBlock;
×
1140
  } else {
1141
    pDataBlock =
UNCOV
1142
        (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
UNCOV
1143
    if (NULL == pDataBlock) {
×
UNCOV
1144
      tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
×
UNCOV
1145
      STMT_ERR_RET(TSDB_CODE_TSC_STMT_CACHE_ERROR);
×
1146
    }
1147
  }
1148

UNCOV
1149
  if (!((*pDataBlock)->pData->flags & SUBMIT_REQ_AUTO_CREATE_TABLE)) {
×
UNCOV
1150
    return TSDB_CODE_SUCCESS;
×
1151
  }
1152

UNCOV
1153
  if (pStmt->sql.fixValueTags) {
×
UNCOV
1154
    STMT_ERR_RET(cloneSVreateTbReq(pStmt->sql.fixValueTbReq, pCreateTbReq));
×
UNCOV
1155
    if ((*pCreateTbReq)->name) {
×
UNCOV
1156
      taosMemoryFree((*pCreateTbReq)->name);
×
1157
    }
UNCOV
1158
    (*pCreateTbReq)->name = taosStrdup(pStmt->bInfo.tbName);
×
UNCOV
1159
    int32_t vgId = -1;
×
UNCOV
1160
    STMT_ERR_RET(stmtTryAddTableVgroupInfo(pStmt, &vgId));
×
UNCOV
1161
    (*pCreateTbReq)->uid = vgId;
×
UNCOV
1162
    return TSDB_CODE_SUCCESS;
×
1163
  }
1164

UNCOV
1165
  if ((*pDataBlock)->pData->pCreateTbReq) {
×
UNCOV
1166
    pStmt->sql.fixValueTags = true;
×
UNCOV
1167
    STMT_ERR_RET(cloneSVreateTbReq((*pDataBlock)->pData->pCreateTbReq, &pStmt->sql.fixValueTbReq));
×
UNCOV
1168
    STMT_ERR_RET(cloneSVreateTbReq(pStmt->sql.fixValueTbReq, pCreateTbReq));
×
UNCOV
1169
    (*pCreateTbReq)->uid = (*pDataBlock)->pMeta->vgId;
×
1170
  }
1171

1172
  return TSDB_CODE_SUCCESS;
×
1173
}
1174

UNCOV
1175
static int stmtFetchColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields) {
×
UNCOV
1176
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
1177
    return pStmt->errCode;
×
1178
  }
1179

UNCOV
1180
  if (STMT_TYPE_QUERY == pStmt->sql.type) {
×
UNCOV
1181
    tscError("invalid operation to get query column fileds");
×
UNCOV
1182
    STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
×
1183
  }
1184

UNCOV
1185
  STableDataCxt** pDataBlock = NULL;
×
1186

UNCOV
1187
  if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1188
    pDataBlock = &pStmt->sql.siInfo.pDataCtx;
×
1189
  } else {
1190
    pDataBlock =
UNCOV
1191
        (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
UNCOV
1192
    if (NULL == pDataBlock) {
×
UNCOV
1193
      tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
×
UNCOV
1194
      STMT_ERR_RET(TSDB_CODE_APP_ERROR);
×
1195
    }
1196
  }
1197

UNCOV
1198
  STMT_ERR_RET(qBuildStmtColFields(*pDataBlock, fieldNum, fields));
×
1199

UNCOV
1200
  return TSDB_CODE_SUCCESS;
×
1201
}
1202

UNCOV
1203
static int stmtFetchStbColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_ALL** fields) {
×
UNCOV
1204
  int32_t    code = 0;
×
1205
  int32_t    preCode = pStmt->errCode;
×
1206

1207
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
1208
    return pStmt->errCode;
×
1209
  }
1210

UNCOV
1211
  if (STMT_TYPE_QUERY == pStmt->sql.type) {
×
1212
    tscError("invalid operation to get query column fileds");
×
1213
    STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR);
×
1214
  }
1215

UNCOV
1216
  STableDataCxt** pDataBlock = NULL;
×
UNCOV
1217
  bool            cleanStb = false;
×
1218

UNCOV
1219
  if (pStmt->sql.stbInterlaceMode && pStmt->sql.siInfo.pDataCtx != NULL) {
×
UNCOV
1220
    pDataBlock = &pStmt->sql.siInfo.pDataCtx;
×
1221
  } else {
UNCOV
1222
    cleanStb = true;
×
1223
    pDataBlock =
UNCOV
1224
        (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
1225
  }
1226

UNCOV
1227
  if (NULL == pDataBlock || NULL == *pDataBlock) {
×
UNCOV
1228
    tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
×
UNCOV
1229
    STMT_ERRI_JRET(TSDB_CODE_APP_ERROR);
×
1230
  }
1231

UNCOV
1232
  STMT_ERRI_JRET(
×
1233
      qBuildStmtStbColFields(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.preCtbname, fieldNum, fields));
UNCOV
1234
  if (pStmt->bInfo.tbType == TSDB_SUPER_TABLE && cleanStb) {
×
UNCOV
1235
    pStmt->bInfo.needParse = true;
×
1236
    qDestroyStmtDataBlock(*pDataBlock);
×
UNCOV
1237
    *pDataBlock = NULL;
×
UNCOV
1238
    if (taosHashRemove(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)) != 0) {
×
UNCOV
1239
      tscError("get fileds %s remove exec blockHash fail", pStmt->bInfo.tbFName);
×
UNCOV
1240
      STMT_ERRI_JRET(TSDB_CODE_APP_ERROR);
×
1241
    }
1242
  }
1243

UNCOV
1244
_return:
×
1245

UNCOV
1246
  pStmt->errCode = preCode;
×
1247

1248
  return code;
×
1249
}
1250
/*
1251
SArray* stmtGetFreeCol(STscStmt2* pStmt, int32_t* idx) {
1252
  while (true) {
1253
    if (pStmt->exec.smInfo.pColIdx >= STMT_COL_BUF_SIZE) {
1254
      pStmt->exec.smInfo.pColIdx = 0;
1255
    }
1256

1257
    if ((pStmt->exec.smInfo.pColIdx + 1) == atomic_load_32(&pStmt->exec.smInfo.pColFreeIdx)) {
1258
      taosUsleep(1);
1259
      continue;
1260
    }
1261

1262
    *idx = pStmt->exec.smInfo.pColIdx;
1263
    return pStmt->exec.smInfo.pCols[pStmt->exec.smInfo.pColIdx++];
1264
  }
1265
}
1266
*/
UNCOV
1267
static int32_t stmtAppendTablePostHandle(STscStmt2* pStmt, SStmtQNode* param) {
×
1268
  if (NULL == pStmt->sql.siInfo.pVgroupHash) {
×
UNCOV
1269
    pStmt->sql.siInfo.pVgroupHash =
×
UNCOV
1270
        taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
×
1271
  }
UNCOV
1272
  if (NULL == pStmt->sql.siInfo.pVgroupList) {
×
UNCOV
1273
    pStmt->sql.siInfo.pVgroupList = taosArrayInit(64, POINTER_BYTES);
×
1274
  }
1275

UNCOV
1276
  if (NULL == pStmt->sql.siInfo.pRequest) {
×
UNCOV
1277
    STMT_ERR_RET(buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false,
×
1278
                              (SRequestObj**)&pStmt->sql.siInfo.pRequest, pStmt->reqid));
1279

UNCOV
1280
    if (pStmt->reqid != 0) {
×
UNCOV
1281
      pStmt->reqid++;
×
1282
    }
UNCOV
1283
    pStmt->exec.pRequest->syncQuery = true;
×
1284

UNCOV
1285
    pStmt->sql.siInfo.requestId = ((SRequestObj*)pStmt->sql.siInfo.pRequest)->requestId;
×
UNCOV
1286
    pStmt->sql.siInfo.requestSelf = ((SRequestObj*)pStmt->sql.siInfo.pRequest)->self;
×
1287
  }
1288

UNCOV
1289
  if (!pStmt->sql.siInfo.tbFromHash && pStmt->sql.siInfo.firstName[0] &&
×
UNCOV
1290
      0 == strcmp(pStmt->sql.siInfo.firstName, pStmt->bInfo.tbName)) {
×
UNCOV
1291
    pStmt->sql.siInfo.tbFromHash = true;
×
1292
  }
1293

UNCOV
1294
  if (0 == pStmt->sql.siInfo.firstName[0]) {
×
UNCOV
1295
    tstrncpy(pStmt->sql.siInfo.firstName, pStmt->bInfo.tbName, TSDB_TABLE_NAME_LEN);
×
1296
  }
1297

UNCOV
1298
  param->tblData.getFromHash = pStmt->sql.siInfo.tbFromHash;
×
UNCOV
1299
  param->next = NULL;
×
1300

UNCOV
1301
  (void)atomic_add_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1);
×
1302

UNCOV
1303
  stmtEnqueue(pStmt, param);
×
1304

UNCOV
1305
  return TSDB_CODE_SUCCESS;
×
1306
}
1307

1308
static FORCE_INLINE int32_t stmtGetTableColsFromCache(STscStmt2* pStmt, SArray** pTableCols) {
1309
  while (true) {
UNCOV
1310
    if (pStmt->sql.siInfo.pTableColsIdx < taosArrayGetSize(pStmt->sql.siInfo.pTableCols)) {
×
UNCOV
1311
      *pTableCols = (SArray*)taosArrayGetP(pStmt->sql.siInfo.pTableCols, pStmt->sql.siInfo.pTableColsIdx++);
×
UNCOV
1312
      break;
×
1313
    } else {
UNCOV
1314
      SArray* pTblCols = NULL;
×
UNCOV
1315
      for (int32_t i = 0; i < 100; i++) {
×
UNCOV
1316
        pTblCols = taosArrayInit(20, POINTER_BYTES);
×
UNCOV
1317
        if (NULL == pTblCols) {
×
UNCOV
1318
          return terrno;
×
1319
        }
1320

UNCOV
1321
        if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) {
×
UNCOV
1322
          return terrno;
×
1323
        }
1324
      }
1325
    }
1326
  }
1327

UNCOV
1328
  return TSDB_CODE_SUCCESS;
×
1329
}
1330

UNCOV
1331
static int32_t stmtCacheBlock(STscStmt2* pStmt) {
×
UNCOV
1332
  if (pStmt->sql.type != STMT_TYPE_MULTI_INSERT) {
×
UNCOV
1333
    return TSDB_CODE_SUCCESS;
×
1334
  }
1335

UNCOV
1336
  uint64_t uid = pStmt->bInfo.tbUid;
×
UNCOV
1337
  uint64_t cacheUid = (TSDB_CHILD_TABLE == pStmt->bInfo.tbType) ? pStmt->bInfo.tbSuid : uid;
×
1338

UNCOV
1339
  if (taosHashGet(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid))) {
×
UNCOV
1340
    return TSDB_CODE_SUCCESS;
×
1341
  }
1342

UNCOV
1343
  STableDataCxt** pSrc = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
UNCOV
1344
  if (!pSrc) {
×
UNCOV
1345
    return terrno;
×
1346
  }
UNCOV
1347
  STableDataCxt* pDst = NULL;
×
1348

UNCOV
1349
  STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc, true));
×
1350

UNCOV
1351
  SStmtTableCache cache = {
×
1352
      .pDataCtx = pDst,
1353
      .boundTags = pStmt->bInfo.boundTags,
×
1354
  };
1355

UNCOV
1356
  if (taosHashPut(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid), &cache, sizeof(cache))) {
×
UNCOV
1357
    return terrno;
×
1358
  }
1359

UNCOV
1360
  if (pStmt->sql.autoCreateTbl) {
×
UNCOV
1361
    pStmt->bInfo.tagsCached = true;
×
1362
  } else {
UNCOV
1363
    pStmt->bInfo.boundTags = NULL;
×
1364
  }
1365

UNCOV
1366
  return TSDB_CODE_SUCCESS;
×
1367
}
1368

UNCOV
1369
static int stmtAddBatch2(TAOS_STMT2* stmt) {
×
UNCOV
1370
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
1371

UNCOV
1372
  int64_t startUs = taosGetTimestampUs();
×
1373

UNCOV
1374
  STMT_DLOG_E("start to add batch");
×
1375

UNCOV
1376
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
1377
    return pStmt->errCode;
×
1378
  }
1379

UNCOV
1380
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_ADD_BATCH));
×
1381

UNCOV
1382
  if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1383
    int64_t startUs2 = taosGetTimestampUs();
×
UNCOV
1384
    pStmt->stat.addBatchUs += startUs2 - startUs;
×
1385

UNCOV
1386
    pStmt->sql.siInfo.tableColsReady = false;
×
1387

UNCOV
1388
    SStmtQNode* param = NULL;
×
UNCOV
1389
    STMT_ERR_RET(stmtAllocQNodeFromBuf(&pStmt->sql.siInfo.tbBuf, (void**)&param));
×
UNCOV
1390
    param->restoreTbCols = true;
×
UNCOV
1391
    param->next = NULL;
×
1392

UNCOV
1393
    if (pStmt->sql.autoCreateTbl) {
×
UNCOV
1394
      pStmt->bInfo.tagsCached = true;
×
1395
    }
1396

UNCOV
1397
    stmtEnqueue(pStmt, param);
×
1398

UNCOV
1399
    return TSDB_CODE_SUCCESS;
×
1400
  }
1401

UNCOV
1402
  STMT_ERR_RET(stmtCacheBlock(pStmt));
×
1403

UNCOV
1404
  return TSDB_CODE_SUCCESS;
×
1405
}
1406
/*
1407
static int32_t stmtBackupQueryFields(STscStmt2* pStmt) {
1408
  SStmtQueryResInfo* pRes = &pStmt->sql.queryRes;
1409
  pRes->numOfCols = pStmt->exec.pRequest->body.resInfo.numOfCols;
1410
  pRes->precision = pStmt->exec.pRequest->body.resInfo.precision;
1411

1412
  int32_t size = pRes->numOfCols * sizeof(TAOS_FIELD);
1413
  pRes->fields = taosMemoryMalloc(size);
1414
  pRes->userFields = taosMemoryMalloc(size);
1415
  if (NULL == pRes->fields || NULL == pRes->userFields) {
1416
    STMT_ERR_RET(terrno);
1417
  }
1418
  (void)memcpy(pRes->fields, pStmt->exec.pRequest->body.resInfo.fields, size);
1419
  (void)memcpy(pRes->userFields, pStmt->exec.pRequest->body.resInfo.userFields, size);
1420

1421
  return TSDB_CODE_SUCCESS;
1422
}
1423

1424
static int32_t stmtRestoreQueryFields(STscStmt2* pStmt) {
1425
  SStmtQueryResInfo* pRes = &pStmt->sql.queryRes;
1426
  int32_t            size = pRes->numOfCols * sizeof(TAOS_FIELD);
1427

1428
  pStmt->exec.pRequest->body.resInfo.numOfCols = pRes->numOfCols;
1429
  pStmt->exec.pRequest->body.resInfo.precision = pRes->precision;
1430

1431
  if (NULL == pStmt->exec.pRequest->body.resInfo.fields) {
1432
    pStmt->exec.pRequest->body.resInfo.fields = taosMemoryMalloc(size);
1433
    if (NULL == pStmt->exec.pRequest->body.resInfo.fields) {
1434
      STMT_ERR_RET(terrno);
1435
    }
1436
    (void)memcpy(pStmt->exec.pRequest->body.resInfo.fields, pRes->fields, size);
1437
  }
1438

1439
  if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) {
1440
    pStmt->exec.pRequest->body.resInfo.userFields = taosMemoryMalloc(size);
1441
    if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) {
1442
      STMT_ERR_RET(terrno);
1443
    }
1444
    (void)memcpy(pStmt->exec.pRequest->body.resInfo.userFields, pRes->userFields, size);
1445
  }
1446

1447
  return TSDB_CODE_SUCCESS;
1448
}
1449
*/
UNCOV
1450
int stmtBindBatch2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* bind, int32_t colIdx, SVCreateTbReq* pCreateTbReq) {
×
UNCOV
1451
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
UNCOV
1452
  int32_t    code = 0;
×
1453

UNCOV
1454
  int64_t startUs = taosGetTimestampUs();
×
1455

UNCOV
1456
  STMT_DLOG("start to bind stmt data, colIdx:%d", colIdx);
×
1457

UNCOV
1458
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
1459
    return pStmt->errCode;
×
1460
  }
1461

UNCOV
1462
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND));
×
1463

UNCOV
1464
  if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
×
UNCOV
1465
      STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
×
UNCOV
1466
    pStmt->bInfo.needParse = false;
×
1467
  }
1468

UNCOV
1469
  if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
×
UNCOV
1470
    taos_free_result(pStmt->exec.pRequest);
×
UNCOV
1471
    pStmt->exec.pRequest = NULL;
×
1472
  }
1473

UNCOV
1474
  STMT_ERR_RET(stmtCreateRequest(pStmt));
×
1475

UNCOV
1476
  if (pStmt->bInfo.needParse) {
×
UNCOV
1477
    STMT_ERR_RET(stmtParseSql(pStmt));
×
1478
  }
1479

1480
  if (STMT_TYPE_QUERY == pStmt->sql.type) {
×
1481
    STMT_ERR_RET(qStmtBindParams2(pStmt->sql.pQuery, bind, colIdx, pStmt->taos->optionInfo.charsetCxt));
×
1482

UNCOV
1483
    SParseContext ctx = {.requestId = pStmt->exec.pRequest->requestId,
×
UNCOV
1484
                         .acctId = pStmt->taos->acctId,
×
1485
                         .db = pStmt->exec.pRequest->pDb,
×
1486
                         .topicQuery = false,
UNCOV
1487
                         .pSql = pStmt->sql.sqlStr,
×
UNCOV
1488
                         .sqlLen = pStmt->sql.sqlLen,
×
UNCOV
1489
                         .pMsg = pStmt->exec.pRequest->msgBuf,
×
1490
                         .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
1491
                         .pTransporter = pStmt->taos->pAppInfo->pTransporter,
×
1492
                         .pStmtCb = NULL,
UNCOV
1493
                         .pUser = pStmt->taos->user};
×
UNCOV
1494
    ctx.mgmtEpSet = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp);
×
UNCOV
1495
    STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &ctx.pCatalog));
×
1496

UNCOV
1497
    STMT_ERR_RET(qStmtParseQuerySql(&ctx, pStmt->sql.pQuery));
×
1498

UNCOV
1499
    if (pStmt->sql.pQuery->haveResultSet) {
×
UNCOV
1500
      STMT_ERR_RET(setResSchemaInfo(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->pResSchema,
×
1501
                                    pStmt->sql.pQuery->numOfResCols));
UNCOV
1502
      taosMemoryFreeClear(pStmt->sql.pQuery->pResSchema);
×
1503
      setResPrecision(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->precision);
×
1504
    }
1505

UNCOV
1506
    TSWAP(pStmt->exec.pRequest->dbList, pStmt->sql.pQuery->pDbList);
×
UNCOV
1507
    TSWAP(pStmt->exec.pRequest->tableList, pStmt->sql.pQuery->pTableList);
×
UNCOV
1508
    TSWAP(pStmt->exec.pRequest->targetTableList, pStmt->sql.pQuery->pTargetTableList);
×
1509

1510
    // if (STMT_TYPE_QUERY == pStmt->sql.queryRes) {
1511
    //   STMT_ERR_RET(stmtRestoreQueryFields(pStmt));
1512
    // }
1513

1514
    // STMT_ERR_RET(stmtBackupQueryFields(pStmt));
1515

UNCOV
1516
    return TSDB_CODE_SUCCESS;
×
1517
  }
1518

UNCOV
1519
  if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) {
×
UNCOV
1520
    STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt));
×
1521
  }
1522

UNCOV
1523
  STableDataCxt** pDataBlock = NULL;
×
1524

UNCOV
1525
  if (pStmt->exec.pCurrBlock) {
×
UNCOV
1526
    pDataBlock = &pStmt->exec.pCurrBlock;
×
1527
  } else {
1528
    pDataBlock =
UNCOV
1529
        (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
×
UNCOV
1530
    if (NULL == pDataBlock) {
×
UNCOV
1531
      tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
×
UNCOV
1532
      STMT_ERR_RET(TSDB_CODE_TSC_STMT_CACHE_ERROR);
×
1533
    }
UNCOV
1534
    pStmt->exec.pCurrBlock = *pDataBlock;
×
UNCOV
1535
    if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1536
      taosArrayDestroy(pStmt->exec.pCurrBlock->pData->aCol);
×
UNCOV
1537
      (*pDataBlock)->pData->aCol = NULL;
×
1538
    }
UNCOV
1539
    if (colIdx < -1) {
×
UNCOV
1540
      pStmt->sql.bindRowFormat = true;
×
UNCOV
1541
      taosArrayDestroy((*pDataBlock)->pData->aCol);
×
UNCOV
1542
      (*pDataBlock)->pData->aCol = taosArrayInit(20, POINTER_BYTES);
×
1543
    }
1544
  }
1545

UNCOV
1546
  int64_t startUs2 = taosGetTimestampUs();
×
UNCOV
1547
  pStmt->stat.bindDataUs1 += startUs2 - startUs;
×
1548

UNCOV
1549
  SStmtQNode* param = NULL;
×
UNCOV
1550
  if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1551
    STMT_ERR_RET(stmtAllocQNodeFromBuf(&pStmt->sql.siInfo.tbBuf, (void**)&param));
×
UNCOV
1552
    STMT_ERR_RET(stmtGetTableColsFromCache(pStmt, &param->tblData.aCol));
×
UNCOV
1553
    taosArrayClear(param->tblData.aCol);
×
1554

1555
    // param->tblData.aCol = taosArrayInit(20, POINTER_BYTES);
1556

UNCOV
1557
    param->restoreTbCols = false;
×
UNCOV
1558
    tstrncpy(param->tblData.tbName, pStmt->bInfo.tbName, TSDB_TABLE_NAME_LEN);
×
1559

UNCOV
1560
    param->pCreateTbReq = pCreateTbReq;
×
1561
  }
1562

UNCOV
1563
  int64_t startUs3 = taosGetTimestampUs();
×
UNCOV
1564
  pStmt->stat.bindDataUs2 += startUs3 - startUs2;
×
1565

UNCOV
1566
  SArray* pCols = pStmt->sql.stbInterlaceMode ? param->tblData.aCol : (*pDataBlock)->pData->aCol;
×
1567

UNCOV
1568
  if (colIdx < 0) {
×
UNCOV
1569
    if (pStmt->sql.stbInterlaceMode) {
×
1570
      // (*pDataBlock)->pData->flags = 0;
UNCOV
1571
      (*pDataBlock)->pData->flags &= ~SUBMIT_REQ_COLUMN_DATA_FORMAT;
×
UNCOV
1572
      code = qBindStmtStbColsValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf,
×
UNCOV
1573
                                    pStmt->exec.pRequest->msgBufLen, &pStmt->sql.siInfo.pTSchema, pStmt->sql.pBindInfo,
×
UNCOV
1574
                                    pStmt->taos->optionInfo.charsetCxt);
×
1575
    } else {
UNCOV
1576
      if (colIdx == -1) {
×
UNCOV
1577
        if (pStmt->sql.bindRowFormat) {
×
UNCOV
1578
          tscError("can't mix bind row format and bind column format");
×
UNCOV
1579
          STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
×
1580
        }
UNCOV
1581
        code = qBindStmtColsValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf,
×
UNCOV
1582
                                   pStmt->exec.pRequest->msgBufLen, pStmt->taos->optionInfo.charsetCxt);
×
1583
      } else {
UNCOV
1584
        code = qBindStmt2RowValue(*pDataBlock, (*pDataBlock)->pData->aRowP, bind, pStmt->exec.pRequest->msgBuf,
×
UNCOV
1585
                                  pStmt->exec.pRequest->msgBufLen, &pStmt->sql.siInfo.pTSchema, pStmt->sql.pBindInfo,
×
UNCOV
1586
                                  pStmt->taos->optionInfo.charsetCxt);
×
1587
      }
1588
    }
1589

UNCOV
1590
    if (code) {
×
UNCOV
1591
      tscError("qBindStmtColsValue failed, error:%s", tstrerror(code));
×
UNCOV
1592
      STMT_ERR_RET(code);
×
1593
    }
1594
  } else {
UNCOV
1595
    if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1596
      tscError("bind single column not allowed in stb insert mode");
×
UNCOV
1597
      STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
×
1598
    }
1599

UNCOV
1600
    if (pStmt->sql.bindRowFormat) {
×
UNCOV
1601
      tscError("can't mix bind row format and bind column format");
×
UNCOV
1602
      STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
×
1603
    }
1604

UNCOV
1605
    if (colIdx != (pStmt->bInfo.sBindLastIdx + 1) && colIdx != 0) {
×
UNCOV
1606
      tscError("bind column index not in sequence");
×
UNCOV
1607
      STMT_ERR_RET(TSDB_CODE_APP_ERROR);
×
1608
    }
1609

UNCOV
1610
    pStmt->bInfo.sBindLastIdx = colIdx;
×
1611

UNCOV
1612
    if (0 == colIdx) {
×
UNCOV
1613
      pStmt->bInfo.sBindRowNum = bind->num;
×
1614
    }
1615

UNCOV
1616
    code = qBindStmtSingleColValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf,
×
UNCOV
1617
                                    pStmt->exec.pRequest->msgBufLen, colIdx, pStmt->bInfo.sBindRowNum, pStmt->taos->optionInfo.charsetCxt);
×
UNCOV
1618
    if (code) {
×
UNCOV
1619
      tscError("qBindStmtSingleColValue failed, error:%s", tstrerror(code));
×
UNCOV
1620
      STMT_ERR_RET(code);
×
1621
    }
1622
  }
1623

UNCOV
1624
  int64_t startUs4 = taosGetTimestampUs();
×
UNCOV
1625
  pStmt->stat.bindDataUs3 += startUs4 - startUs3;
×
1626

UNCOV
1627
  if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1628
    STMT_ERR_RET(stmtAppendTablePostHandle(pStmt, param));
×
1629
  } else {
UNCOV
1630
    STMT_ERR_RET(stmtAddBatch2(pStmt));
×
1631
  }
1632

UNCOV
1633
  pStmt->stat.bindDataUs4 += taosGetTimestampUs() - startUs4;
×
1634

UNCOV
1635
  return TSDB_CODE_SUCCESS;
×
1636
}
1637
/*
1638
int stmtUpdateTableUid(STscStmt2* pStmt, SSubmitRsp* pRsp) {
1639
  tscDebug("stmt start to update tbUid, blockNum:%d", pRsp->nBlocks);
1640

1641
  int32_t code = 0;
1642
  int32_t finalCode = 0;
1643
  size_t  keyLen = 0;
1644
  void*   pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
1645
  while (pIter) {
1646
    STableDataCxt* pBlock = *(STableDataCxt**)pIter;
1647
    char*          key = taosHashGetKey(pIter, &keyLen);
1648

1649
    STableMeta* pMeta = qGetTableMetaInDataBlock(pBlock);
1650
    if (pMeta->uid) {
1651
      pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
1652
      continue;
1653
    }
1654

1655
    SSubmitBlkRsp* blkRsp = NULL;
1656
    int32_t        i = 0;
1657
    for (; i < pRsp->nBlocks; ++i) {
1658
      blkRsp = pRsp->pBlocks + i;
1659
      if (strlen(blkRsp->tblFName) != keyLen) {
1660
        continue;
1661
      }
1662

1663
      if (strncmp(blkRsp->tblFName, key, keyLen)) {
1664
        continue;
1665
      }
1666

1667
      break;
1668
    }
1669

1670
    if (i < pRsp->nBlocks) {
1671
      tscDebug("auto created table %s uid updated from %" PRIx64 " to %" PRIx64, blkRsp->tblFName, pMeta->uid,
1672
               blkRsp->uid);
1673

1674
      pMeta->uid = blkRsp->uid;
1675
      pStmt->bInfo.tbUid = blkRsp->uid;
1676
    } else {
1677
      tscDebug("table %s not found in submit rsp, will update from catalog", pStmt->bInfo.tbFName);
1678
      if (NULL == pStmt->pCatalog) {
1679
        code = catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &pStmt->pCatalog);
1680
        if (code) {
1681
          pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
1682
          finalCode = code;
1683
          continue;
1684
        }
1685
      }
1686

1687
      code = stmtCreateRequest(pStmt);
1688
      if (code) {
1689
        pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
1690
        finalCode = code;
1691
        continue;
1692
      }
1693

1694
      STableMeta*      pTableMeta = NULL;
1695
      SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
1696
                               .requestId = pStmt->exec.pRequest->requestId,
1697
                               .requestObjRefId = pStmt->exec.pRequest->self,
1698
                               .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
1699
      code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta);
1700

1701
      pStmt->stat.ctgGetTbMetaNum++;
1702

1703
      taos_free_result(pStmt->exec.pRequest);
1704
      pStmt->exec.pRequest = NULL;
1705

1706
      if (code || NULL == pTableMeta) {
1707
        pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
1708
        finalCode = code;
1709
        taosMemoryFree(pTableMeta);
1710
        continue;
1711
      }
1712

1713
      pMeta->uid = pTableMeta->uid;
1714
      pStmt->bInfo.tbUid = pTableMeta->uid;
1715
      taosMemoryFree(pTableMeta);
1716
    }
1717

1718
    pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
1719
  }
1720

1721
  return finalCode;
1722
}
1723
*/
1724
/*
1725
int stmtStaticModeExec(TAOS_STMT* stmt) {
1726
  STscStmt2*   pStmt = (STscStmt2*)stmt;
1727
  int32_t     code = 0;
1728
  SSubmitRsp* pRsp = NULL;
1729
  if (pStmt->sql.staticMode) {
1730
    return TSDB_CODE_TSC_STMT_API_ERROR;
1731
  }
1732

1733
  STMT_DLOG_E("start to exec");
1734

1735
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE));
1736

1737
  STMT_ERR_RET(qBuildStmtOutputFromTbList(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->exec.pTbBlkList,
1738
pStmt->exec.pCurrBlock, pStmt->exec.tbBlkNum));
1739

1740
  launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
1741

1742
  if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) {
1743
    code = refreshMeta(pStmt->exec.pRequest->pTscObj, pStmt->exec.pRequest);
1744
    if (code) {
1745
      pStmt->exec.pRequest->code = code;
1746
    } else {
1747
      tFreeSSubmitRsp(pRsp);
1748
      STMT_ERR_RET(stmtResetStmt(pStmt));
1749
      STMT_ERR_RET(TSDB_CODE_NEED_RETRY);
1750
    }
1751
  }
1752

1753
  STMT_ERR_JRET(pStmt->exec.pRequest->code);
1754

1755
  pStmt->exec.affectedRows = taos_affected_rows(pStmt->exec.pRequest);
1756
  pStmt->affectedRows += pStmt->exec.affectedRows;
1757

1758
_return:
1759

1760
  stmtCleanExecInfo(pStmt, (code ? false : true), false);
1761

1762
  tFreeSSubmitRsp(pRsp);
1763

1764
  ++pStmt->sql.runTimes;
1765

1766
  STMT_RET(code);
1767
}
1768
*/
1769

UNCOV
1770
static int32_t createParseContext(const SRequestObj* pRequest, SParseContext** pCxt, SSqlCallbackWrapper* pWrapper) {
×
UNCOV
1771
  const STscObj* pTscObj = pRequest->pTscObj;
×
1772

UNCOV
1773
  *pCxt = taosMemoryCalloc(1, sizeof(SParseContext));
×
UNCOV
1774
  if (*pCxt == NULL) {
×
UNCOV
1775
    return terrno;
×
1776
  }
1777

1778
  **pCxt = (SParseContext){.requestId = pRequest->requestId,
×
UNCOV
1779
                           .requestRid = pRequest->self,
×
UNCOV
1780
                           .acctId = pTscObj->acctId,
×
UNCOV
1781
                           .db = pRequest->pDb,
×
1782
                           .topicQuery = false,
UNCOV
1783
                           .pSql = pRequest->sqlstr,
×
UNCOV
1784
                           .sqlLen = pRequest->sqlLen,
×
UNCOV
1785
                           .pMsg = pRequest->msgBuf,
×
1786
                           .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
1787
                           .pTransporter = pTscObj->pAppInfo->pTransporter,
×
1788
                           .pStmtCb = NULL,
UNCOV
1789
                           .pUser = pTscObj->user,
×
UNCOV
1790
                           .pEffectiveUser = pRequest->effectiveUser,
×
UNCOV
1791
                           .isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
×
UNCOV
1792
                           .enableSysInfo = pTscObj->sysInfo,
×
1793
                           .async = true,
UNCOV
1794
                           .svrVer = pTscObj->sVer,
×
UNCOV
1795
                           .nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes),
×
UNCOV
1796
                           .allocatorId = pRequest->allocatorRefId,
×
1797
                           .parseSqlFp = clientParseSql,
1798
                           .parseSqlParam = pWrapper};
UNCOV
1799
  int8_t biMode = atomic_load_8(&((STscObj*)pTscObj)->biMode);
×
UNCOV
1800
  (*pCxt)->biMode = biMode;
×
UNCOV
1801
  return TSDB_CODE_SUCCESS;
×
1802
}
1803

UNCOV
1804
static void asyncQueryCb(void* userdata, TAOS_RES* res, int code) {
×
UNCOV
1805
  STscStmt2*        pStmt = userdata;
×
UNCOV
1806
  __taos_async_fn_t fp = pStmt->options.asyncExecFn;
×
1807

UNCOV
1808
  pStmt->exec.affectedRows = taos_affected_rows(pStmt->exec.pRequest);
×
UNCOV
1809
  pStmt->affectedRows += pStmt->exec.affectedRows;
×
1810

UNCOV
1811
  fp(pStmt->options.userdata, res, code);
×
1812

UNCOV
1813
  while (0 == atomic_load_8((int8_t*)&pStmt->sql.siInfo.tableColsReady)) {
×
UNCOV
1814
    taosUsleep(1);
×
1815
  }
UNCOV
1816
  (void)stmtCleanExecInfo(pStmt, (code ? false : true), false);
×
UNCOV
1817
  ++pStmt->sql.runTimes;
×
1818

UNCOV
1819
  if (tsem_post(&pStmt->asyncExecSem) != 0) {
×
UNCOV
1820
    tscError("failed to post asyncExecSem");
×
1821
  }
UNCOV
1822
}
×
1823

UNCOV
1824
int stmtExec2(TAOS_STMT2* stmt, int* affected_rows) {
×
UNCOV
1825
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
UNCOV
1826
  int32_t    code = 0;
×
UNCOV
1827
  int64_t    startUs = taosGetTimestampUs();
×
1828

UNCOV
1829
  STMT_DLOG_E("start to exec");
×
1830

UNCOV
1831
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
1832
    return pStmt->errCode;
×
1833
  }
1834

UNCOV
1835
  TSC_ERR_RET(taosThreadMutexLock(&pStmt->asyncBindParam.mutex));
×
UNCOV
1836
  while (atomic_load_8((int8_t*)&pStmt->asyncBindParam.asyncBindNum) > 0) {
×
UNCOV
1837
    (void)taosThreadCondWait(&pStmt->asyncBindParam.waitCond, &pStmt->asyncBindParam.mutex);
×
1838
  }
UNCOV
1839
  TSC_ERR_RET(taosThreadMutexUnlock(&pStmt->asyncBindParam.mutex));
×
1840

UNCOV
1841
  if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1842
    STMT_ERR_RET(stmtAddBatch2(pStmt));
×
1843
  }
1844

UNCOV
1845
  STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE));
×
1846

UNCOV
1847
  if (STMT_TYPE_QUERY != pStmt->sql.type) {
×
UNCOV
1848
    if (pStmt->sql.stbInterlaceMode) {
×
UNCOV
1849
      int64_t startTs = taosGetTimestampUs();
×
UNCOV
1850
      while (atomic_load_64(&pStmt->sql.siInfo.tbRemainNum)) {
×
UNCOV
1851
        taosUsleep(1);
×
1852
      }
UNCOV
1853
      pStmt->stat.execWaitUs += taosGetTimestampUs() - startTs;
×
1854

UNCOV
1855
      STMT_ERR_RET(qBuildStmtFinOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->sql.siInfo.pVgroupList));
×
UNCOV
1856
      taosHashCleanup(pStmt->sql.siInfo.pVgroupHash);
×
UNCOV
1857
      pStmt->sql.siInfo.pVgroupHash = NULL;
×
UNCOV
1858
      pStmt->sql.siInfo.pVgroupList = NULL;
×
1859
    } else {
UNCOV
1860
      tDestroySubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
×
UNCOV
1861
      taosMemoryFreeClear(pStmt->exec.pCurrTbData);
×
1862

UNCOV
1863
      STMT_ERR_RET(qCloneCurrentTbData(pStmt->exec.pCurrBlock, &pStmt->exec.pCurrTbData));
×
1864

UNCOV
1865
      STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->exec.pBlockHash));
×
1866
    }
1867
  }
1868

UNCOV
1869
  SRequestObj*      pRequest = pStmt->exec.pRequest;
×
UNCOV
1870
  __taos_async_fn_t fp = pStmt->options.asyncExecFn;
×
1871

UNCOV
1872
  if (!fp) {
×
UNCOV
1873
    launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
×
1874

UNCOV
1875
    if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) {
×
1876
      code = refreshMeta(pStmt->exec.pRequest->pTscObj, pStmt->exec.pRequest);
×
UNCOV
1877
      if (code) {
×
UNCOV
1878
        pStmt->exec.pRequest->code = code;
×
1879
      } else {
UNCOV
1880
        STMT_ERR_RET(stmtResetStmt(pStmt));
×
UNCOV
1881
        STMT_ERR_RET(TSDB_CODE_NEED_RETRY);
×
1882
      }
1883
    }
1884

UNCOV
1885
    STMT_ERR_JRET(pStmt->exec.pRequest->code);
×
1886

UNCOV
1887
    pStmt->exec.affectedRows = taos_affected_rows(pStmt->exec.pRequest);
×
UNCOV
1888
    if (affected_rows) {
×
UNCOV
1889
      *affected_rows = pStmt->exec.affectedRows;
×
1890
    }
UNCOV
1891
    pStmt->affectedRows += pStmt->exec.affectedRows;
×
1892

UNCOV
1893
    while (0 == atomic_load_8((int8_t*)&pStmt->sql.siInfo.tableColsReady)) {
×
UNCOV
1894
      taosUsleep(1);
×
1895
    }
1896

UNCOV
1897
    STMT_ERR_RET(stmtCleanExecInfo(pStmt, (code ? false : true), false));
×
1898

UNCOV
1899
    ++pStmt->sql.runTimes;
×
1900
  } else {
UNCOV
1901
    SSqlCallbackWrapper* pWrapper = taosMemoryCalloc(1, sizeof(SSqlCallbackWrapper));
×
1902
    if (pWrapper == NULL) {
×
1903
      code = terrno;
×
1904
    } else {
UNCOV
1905
      pWrapper->pRequest = pRequest;
×
UNCOV
1906
      pRequest->pWrapper = pWrapper;
×
1907
    }
1908
    if (TSDB_CODE_SUCCESS == code) {
×
1909
      code = createParseContext(pRequest, &pWrapper->pParseCtx, pWrapper);
×
1910
    }
UNCOV
1911
    pRequest->syncQuery = false;
×
UNCOV
1912
    pRequest->body.queryFp = asyncQueryCb;
×
UNCOV
1913
    ((SSyncQueryParam*)(pRequest)->body.interParam)->userParam = pStmt;
×
1914

UNCOV
1915
    pStmt->execSemWaited = false;
×
UNCOV
1916
    launchAsyncQuery(pRequest, pStmt->sql.pQuery, NULL, pWrapper);
×
1917
  }
1918

UNCOV
1919
_return:
×
UNCOV
1920
  pStmt->stat.execUseUs += taosGetTimestampUs() - startUs;
×
1921

UNCOV
1922
  STMT_RET(code);
×
1923
}
1924

UNCOV
1925
int stmtClose2(TAOS_STMT2* stmt) {
×
UNCOV
1926
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
1927

UNCOV
1928
  STMT_DLOG_E("start to free stmt");
×
1929

UNCOV
1930
  pStmt->queue.stopQueue = true;
×
1931

UNCOV
1932
  (void)taosThreadMutexLock(&pStmt->queue.mutex);
×
UNCOV
1933
  (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1);
×
UNCOV
1934
  (void)taosThreadCondSignal(&(pStmt->queue.waitCond));
×
UNCOV
1935
  (void)taosThreadMutexUnlock(&pStmt->queue.mutex);
×
1936

UNCOV
1937
  if (pStmt->bindThreadInUse) {
×
UNCOV
1938
    (void)taosThreadJoin(pStmt->bindThread, NULL);
×
UNCOV
1939
    pStmt->bindThreadInUse = false;
×
1940
  }
1941

1942
  TSC_ERR_RET(taosThreadMutexLock(&pStmt->asyncBindParam.mutex));
×
UNCOV
1943
  while (atomic_load_8((int8_t*)&pStmt->asyncBindParam.asyncBindNum) > 0) {
×
UNCOV
1944
    (void)taosThreadCondWait(&pStmt->asyncBindParam.waitCond, &pStmt->asyncBindParam.mutex);
×
1945
  }
UNCOV
1946
  TSC_ERR_RET(taosThreadMutexUnlock(&pStmt->asyncBindParam.mutex));
×
1947

1948
  (void)taosThreadCondDestroy(&pStmt->queue.waitCond);
×
1949
  (void)taosThreadMutexDestroy(&pStmt->queue.mutex);
×
1950

UNCOV
1951
  (void)taosThreadCondDestroy(&pStmt->asyncBindParam.waitCond);
×
UNCOV
1952
  (void)taosThreadMutexDestroy(&pStmt->asyncBindParam.mutex);
×
1953

1954
  if (pStmt->options.asyncExecFn && !pStmt->execSemWaited) {
×
UNCOV
1955
    if (tsem_wait(&pStmt->asyncExecSem) != 0) {
×
UNCOV
1956
      tscError("failed to wait asyncExecSem");
×
1957
    }
1958
  }
1959

UNCOV
1960
  STMT_DLOG("stmt %p closed, stbInterlaceMode:%d, statInfo: ctgGetTbMetaNum=>%" PRId64 ", getCacheTbInfo=>%" PRId64
×
1961
            ", parseSqlNum=>%" PRId64 ", pStmt->stat.bindDataNum=>%" PRId64
1962
            ", settbnameAPI:%u, bindAPI:%u, addbatchAPI:%u, execAPI:%u"
1963
            ", setTbNameUs:%" PRId64 ", bindDataUs:%" PRId64 ",%" PRId64 ",%" PRId64 ",%" PRId64 " addBatchUs:%" PRId64
1964
            ", execWaitUs:%" PRId64 ", execUseUs:%" PRId64,
1965
            pStmt, pStmt->sql.stbInterlaceMode, pStmt->stat.ctgGetTbMetaNum, pStmt->stat.getCacheTbInfo,
1966
            pStmt->stat.parseSqlNum, pStmt->stat.bindDataNum, pStmt->seqIds[STMT_SETTBNAME], pStmt->seqIds[STMT_BIND],
1967
            pStmt->seqIds[STMT_ADD_BATCH], pStmt->seqIds[STMT_EXECUTE], pStmt->stat.setTbNameUs,
1968
            pStmt->stat.bindDataUs1, pStmt->stat.bindDataUs2, pStmt->stat.bindDataUs3, pStmt->stat.bindDataUs4,
1969
            pStmt->stat.addBatchUs, pStmt->stat.execWaitUs, pStmt->stat.execUseUs);
1970

UNCOV
1971
  STMT_ERR_RET(stmtCleanSQLInfo(pStmt));
×
1972

UNCOV
1973
  if (pStmt->options.asyncExecFn) {
×
UNCOV
1974
    if (tsem_destroy(&pStmt->asyncExecSem) != 0) {
×
UNCOV
1975
      tscError("failed to destroy asyncExecSem");
×
1976
    }
1977
  }
UNCOV
1978
  taosMemoryFree(stmt);
×
1979

UNCOV
1980
  return TSDB_CODE_SUCCESS;
×
1981
}
1982

1983
const char* stmtErrstr2(TAOS_STMT2* stmt) {
×
UNCOV
1984
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
1985

UNCOV
1986
  if (stmt == NULL || NULL == pStmt->exec.pRequest) {
×
UNCOV
1987
    return (char*)tstrerror(terrno);
×
1988
  }
1989

UNCOV
1990
  pStmt->exec.pRequest->code = terrno;
×
1991

UNCOV
1992
  return taos_errstr(pStmt->exec.pRequest);
×
1993
}
1994
/*
1995
int stmtAffectedRows(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->affectedRows; }
1996

1997
int stmtAffectedRowsOnce(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->exec.affectedRows; }
1998
*/
1999

UNCOV
2000
int stmtParseColFields2(TAOS_STMT2* stmt) {
×
UNCOV
2001
  int32_t    code = 0;
×
UNCOV
2002
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
UNCOV
2003
  int32_t    preCode = pStmt->errCode;
×
2004

UNCOV
2005
  STMT_DLOG_E("start to get col fields");
×
2006

UNCOV
2007
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
2008
    return pStmt->errCode;
×
2009
  }
2010

UNCOV
2011
  if (STMT_TYPE_QUERY == pStmt->sql.type) {
×
UNCOV
2012
    STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR);
×
2013
  }
2014

UNCOV
2015
  STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
×
2016

UNCOV
2017
  if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
×
UNCOV
2018
      STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
×
UNCOV
2019
    pStmt->bInfo.needParse = false;
×
2020
  }
2021

UNCOV
2022
  if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
×
UNCOV
2023
    taos_free_result(pStmt->exec.pRequest);
×
UNCOV
2024
    pStmt->exec.pRequest = NULL;
×
UNCOV
2025
    STMT_ERRI_JRET(stmtCreateRequest(pStmt));
×
2026
  }
2027

UNCOV
2028
  STMT_ERRI_JRET(stmtCreateRequest(pStmt));
×
2029

UNCOV
2030
  if (pStmt->bInfo.needParse) {
×
UNCOV
2031
    STMT_ERRI_JRET(stmtParseSql(pStmt));
×
2032
  }
2033

UNCOV
2034
_return:
×
2035

UNCOV
2036
  pStmt->errCode = preCode;
×
2037

UNCOV
2038
  return code;
×
2039
}
2040

UNCOV
2041
int stmtGetStbColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_ALL** fields) {
×
UNCOV
2042
  int32_t code = stmtParseColFields2(stmt);
×
UNCOV
2043
  if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
2044
    return code;
×
2045
  }
2046

UNCOV
2047
  return stmtFetchStbColFields2(stmt, nums, fields);
×
2048
}
2049

UNCOV
2050
int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) {
×
UNCOV
2051
  int32_t    code = 0;
×
UNCOV
2052
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
UNCOV
2053
  int32_t    preCode = pStmt->errCode;
×
2054

UNCOV
2055
  STMT_DLOG_E("start to get param num");
×
2056

UNCOV
2057
  if (pStmt->errCode != TSDB_CODE_SUCCESS) {
×
UNCOV
2058
    return pStmt->errCode;
×
2059
  }
2060

UNCOV
2061
  STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
×
2062

UNCOV
2063
  if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
×
UNCOV
2064
      STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
×
UNCOV
2065
    pStmt->bInfo.needParse = false;
×
2066
  }
2067

UNCOV
2068
  if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
×
UNCOV
2069
    taos_free_result(pStmt->exec.pRequest);
×
UNCOV
2070
    pStmt->exec.pRequest = NULL;
×
2071
  }
2072

UNCOV
2073
  STMT_ERRI_JRET(stmtCreateRequest(pStmt));
×
2074

UNCOV
2075
  if (pStmt->bInfo.needParse) {
×
UNCOV
2076
    STMT_ERRI_JRET(stmtParseSql(pStmt));
×
2077
  }
2078

UNCOV
2079
  if (STMT_TYPE_QUERY == pStmt->sql.type) {
×
UNCOV
2080
    *nums = taosArrayGetSize(pStmt->sql.pQuery->pPlaceholderValues);
×
2081
  } else {
UNCOV
2082
    STMT_ERRI_JRET(stmtFetchColFields2(stmt, nums, NULL));
×
2083
  }
2084

UNCOV
2085
_return:
×
2086

UNCOV
2087
  pStmt->errCode = preCode;
×
2088

UNCOV
2089
  return code;
×
2090
}
2091

UNCOV
2092
TAOS_RES* stmtUseResult2(TAOS_STMT2* stmt) {
×
UNCOV
2093
  STscStmt2* pStmt = (STscStmt2*)stmt;
×
2094

UNCOV
2095
  STMT_DLOG_E("start to use result");
×
2096

UNCOV
2097
  if (STMT_TYPE_QUERY != pStmt->sql.type) {
×
UNCOV
2098
    tscError("useResult only for query statement");
×
UNCOV
2099
    return NULL;
×
2100
  }
2101

UNCOV
2102
  return pStmt->exec.pRequest;
×
2103
}
2104

UNCOV
2105
int32_t stmtAsyncBindThreadFunc(void* args) {
×
UNCOV
2106
  qInfo("async stmt bind thread started");
×
2107

UNCOV
2108
  ThreadArgs* targs = (ThreadArgs*)args;
×
UNCOV
2109
  STscStmt2*  pStmt = (STscStmt2*)targs->stmt;
×
2110

UNCOV
2111
  int code = taos_stmt2_bind_param(targs->stmt, targs->bindv, targs->col_idx);
×
UNCOV
2112
  targs->fp(targs->param, NULL, code);
×
UNCOV
2113
  (void)taosThreadMutexLock(&(pStmt->asyncBindParam.mutex));
×
UNCOV
2114
  (void)atomic_sub_fetch_8(&pStmt->asyncBindParam.asyncBindNum, 1);
×
UNCOV
2115
  (void)taosThreadCondSignal(&(pStmt->asyncBindParam.waitCond));
×
UNCOV
2116
  (void)taosThreadMutexUnlock(&(pStmt->asyncBindParam.mutex));
×
UNCOV
2117
  taosMemoryFree(args);
×
2118

UNCOV
2119
  qInfo("async stmt bind thread stopped");
×
2120

UNCOV
2121
  return code;
×
2122
}
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