batchprepare.c 135.1 KB
Newer Older
1 2 3 4 5 6 7
// TAOS standard API example. The same syntax as MySQL, but only a subet 
// to compile: gcc -o prepare prepare.c -ltaos

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
D
stmt  
dapan1121 已提交
8
#include <pthread.h>
9 10 11
#include <unistd.h>
#include "../../../include/client/taos.h"

D
stmt  
dapan1121 已提交
12 13
int32_t shortColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT};
int32_t fullColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_TINYINT, TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_USMALLINT, TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_UINT, TSDB_DATA_TYPE_BIGINT, TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_BINARY, TSDB_DATA_TYPE_NCHAR};
D
dapan1121 已提交
14 15
int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_NCHAR, TSDB_DATA_TYPE_BOOL};
int32_t optrIdxList[] = {2, 11, 6};
D
dapan1121 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

typedef struct {
  char*   oper;
  int32_t paramNum;
  bool    enclose;
} OperInfo;

OperInfo operInfo[] = {
  {">",        2, false},
  {">=",       2, false},  
  {"<",        2, false},
  {"<=",       2, false},  
  {"=",        2, false},  
  {"<>",       2, false},  
  {"in",       2, true},  
  {"not in",   2, true},  
  
  {"like",     2, false},  
  {"not like", 2, false},  
  {"match",    2, false},  
D
dapan1121 已提交
36
  {"nmatch",   2, false},  
D
dapan1121 已提交
37 38 39 40 41 42 43 44 45 46 47
};

int32_t operatorList[] = {0, 1, 2, 3, 4, 5, 6, 7};
int32_t varoperatorList[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

char *bpStbPrefix = "st";
char *bpTbPrefix = "t";


//char *operatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in"};
//char *varoperatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in", "like", "not like", "match", "nmatch"};
D
stmt  
dapan1121 已提交
48 49 50

#define tListLen(x) (sizeof(x) / sizeof((x)[0]))

51
typedef struct {
D
stmt  
dapan1121 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  int64_t*   tsData;
  bool*      boolData;
  int8_t*    tinyData;
  uint8_t*   utinyData;
  int16_t*   smallData;
  uint16_t*  usmallData;
  int32_t*   intData;
  uint32_t*  uintData;
  int64_t*   bigData;
  uint64_t*  ubigData;
  float*     floatData;
  double*    doubleData;
  char*      binaryData;
  char*      isNull;
  int32_t*   binaryLen;
D
dapan1121 已提交
67
  TAOS_MULTI_BIND* pBind;
D
stmt  
dapan1121 已提交
68 69 70 71 72 73 74 75
  char*         sql;
  int32_t*      colTypes;
  int32_t       colNum;
} BindData;

int32_t gVarCharSize = 10;
int32_t gVarCharLen = 5;

D
stmt  
dapan1121 已提交
76
int32_t gExecLoopTimes = 1; // no change
D
stmt  
dapan1121 已提交
77
int32_t gFullColNum = tListLen(fullColList);
D
stmt  
dapan1121 已提交
78

D
dapan1121 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos);
int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos);
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos);
int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos);

enum {
  TTYPE_INSERT = 1,
  TTYPE_QUERY,
};
D
stmt  
dapan1121 已提交
92 93 94 95

typedef struct {
  char     caseDesc[128];
  int32_t  colNum;
D
stmt  
dapan1121 已提交
96
  int32_t *colList;         // full table column list
D
dapan1121 已提交
97 98
  int32_t  testType;     
  bool     prepareStb;
D
stmt  
dapan1121 已提交
99
  bool     fullCol;
D
dapan1121 已提交
100
  int32_t  (*runFn)(TAOS_STMT*, TAOS*);
D
stmt  
dapan1121 已提交
101 102 103
  int32_t  tblNum;
  int32_t  rowNum;
  int32_t  bindRowNum;
D
stmt  
dapan1121 已提交
104
  int32_t  bindColNum;      // equal colNum in full column case
D
stmt  
dapan1121 已提交
105 106
  int32_t  bindNullNum;
  int32_t  runTimes;
D
dapan1121 已提交
107
  int32_t  preCaseIdx;
D
stmt  
dapan1121 已提交
108 109 110
} CaseCfg;

CaseCfg gCase[] = {
D
dapan1121 已提交
111 112 113 114 115 116 117 118 119 120
  {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1,  1, 10, 10, 0, 0, 1, -1},
  {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 1, -1},

  {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 1, -1},

  {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBSE2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBSE2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
121

D
dapan1121 已提交
122 123 124
  {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
125

D
dapan1121 已提交
126 127 128 129
  // 11
  {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
130

D
dapan1121 已提交
131 132 133
  {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
134

D
dapan1121 已提交
135 136 137
  {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
138

D
dapan1121 已提交
139 140
  {"insert:MPME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMPMETest1, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MPME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMPMETest1, 10, 10, 2, 12, 0, 1, -1},
D
stmt  
dapan1121 已提交
141

D
dapan1121 已提交
142
  // 22
D
dapan1121 已提交
143
  {"query:SUBT-FULL", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, querySUBTTest1, 10, 10, 1, 3, 0, 1, 2},
D
stmt  
dapan1121 已提交
144

D
stmt  
dapan1121 已提交
145 146 147
};

CaseCfg *gCurCase = NULL;
D
stmt  
dapan1121 已提交
148 149

typedef struct {
D
dapan1121 已提交
150
  char     caseCatalog[255];
D
stmt  
dapan1121 已提交
151
  int32_t  bindNullNum;
D
dapan1121 已提交
152
  bool     prepareStb;
D
stmt  
dapan1121 已提交
153
  bool     checkParamNum;
D
stmt  
dapan1121 已提交
154
  bool     printRes;
D
stmt  
dapan1121 已提交
155
  bool     printCreateTblSql;
D
dapan1121 已提交
156 157
  bool     printQuerySql;
  bool     printStmtSql;
D
stmt  
dapan1121 已提交
158
  int32_t  rowNum;               //row num for one table
D
stmt  
dapan1121 已提交
159
  int32_t  bindColNum;
D
stmt  
dapan1121 已提交
160
  int32_t  bindRowNum;           //row num for once bind
D
stmt  
dapan1121 已提交
161 162
  int32_t  bindColTypeNum;
  int32_t* bindColTypeList;
D
dapan1121 已提交
163 164
  int32_t  optrIdxListNum;
  int32_t* optrIdxList;
D
stmt  
dapan1121 已提交
165
  int32_t  runTimes;
D
dapan1121 已提交
166 167 168 169
  int32_t  caseIdx;              // static case idx
  int32_t  caseNum;              // num in static case list
  int32_t  caseRunIdx;           // runtime case idx
  int32_t  caseRunNum;           // total run case num
D
stmt  
dapan1121 已提交
170 171
} CaseCtrl;

D
dapan1121 已提交
172
#if 1
D
dapan1121 已提交
173 174 175 176 177 178 179 180 181
CaseCtrl gCaseCtrl = {
  .bindNullNum = 0,
  .prepareStb = false,
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
  .rowNum = 0,
  .bindColNum = 0,
  .bindRowNum = 0,
D
dapan1121 已提交
182 183 184 185
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
D
dapan1121 已提交
186 187 188 189 190 191 192 193
  .checkParamNum = false,
  .printRes = true,
  .runTimes = 0,
//  .caseIdx = -1,
//  .caseNum = -1,
  .caseRunIdx = -1,
//  .caseRunNum = -1,

D
dapan1121 已提交
194

D
dapan1121 已提交
195 196 197 198
//  .optrIdxListNum = tListLen(optrIdxList),
//  .optrIdxList = optrIdxList,
//  .bindColTypeNum = tListLen(bindColTypeList),
//  .bindColTypeList = bindColTypeList,
D
dapan1121 已提交
199
  .caseIdx = 22,
D
dapan1121 已提交
200 201 202 203 204
  .caseNum = 1,
  .caseRunNum = 1,

};
#else
D
stmt  
dapan1121 已提交
205 206
CaseCtrl gCaseCtrl = {
  .bindNullNum = 0,
D
dapan1121 已提交
207
  .prepareStb = false,
D
stmt  
dapan1121 已提交
208
  .printCreateTblSql = false,
D
dapan1121 已提交
209 210
  .printQuerySql = true,
  .printStmtSql = true,
D
stmt  
dapan1121 已提交
211
  .rowNum = 0,
D
stmt  
dapan1121 已提交
212 213
  .bindColNum = 0,
  .bindRowNum = 0,
D
dapan1121 已提交
214 215
  .bindColTypeNum = tListLen(bindColTypeList),
  .bindColTypeList = bindColTypeList,
D
stmt  
dapan1121 已提交
216
  .checkParamNum = false,
D
stmt  
dapan1121 已提交
217 218
  .printRes = true,
  .runTimes = 0,
D
dapan1121 已提交
219 220
  .caseIdx = 2,
  .caseNum = 1,
D
dapan1121 已提交
221
  .caseRunIdx = -1,
D
dapan1121 已提交
222
  .caseRunNum = 1,
D
stmt  
dapan1121 已提交
223
};
224

D
dapan1121 已提交
225 226
#endif

D
stmt  
dapan1121 已提交
227 228
int32_t taosGetTimeOfDay(struct timeval *tv) {
  return gettimeofday(tv, NULL);
229
}
D
stmt  
dapan1121 已提交
230
void *taosMemoryMalloc(uint64_t size) {
D
stmt  
dapan1121 已提交
231 232 233
  return malloc(size);
}

D
stmt  
dapan1121 已提交
234 235 236 237 238
void *taosMemoryCalloc(int32_t num, int32_t size) {
  return calloc(num, size);
}
void taosMemoryFree(const void *ptr) {
  if (ptr == NULL) return;
239

D
stmt  
dapan1121 已提交
240 241
  return free((void*)ptr);
}
242

D
stmt  
dapan1121 已提交
243 244 245 246 247 248
static int64_t taosGetTimestampMs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
  return (int64_t)systemTime.tv_sec * 1000L + (int64_t)systemTime.tv_usec/1000;
}

D
stmt  
dapan1121 已提交
249 250 251 252 253
static int64_t taosGetTimestampUs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
  return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
}
254

D
dapan1121 已提交
255
bool colExists(TAOS_MULTI_BIND* pBind, int32_t dataType) {
D
stmt  
dapan1121 已提交
256 257 258 259 260 261 262 263 264
  int32_t i = 0;
  while (true) {
    if (0 == pBind[i].buffer_type) {
      return false;
    }

    if (pBind[i].buffer_type == dataType) {
      return true;
    }
D
stmt  
dapan1121 已提交
265

D
stmt  
dapan1121 已提交
266 267 268 269
    ++i;
  }
}

D
stmt  
dapan1121 已提交
270
void generateInsertSQL(BindData *data) {
D
dapan1121 已提交
271 272 273 274 275 276
  int32_t len = 0;
  if (gCurCase->tblNum > 1) {
    len = sprintf(data->sql, "insert into ? ");
  } else {
    len = sprintf(data->sql, "insert into %s0 ", bpTbPrefix);
  }
D
stmt  
dapan1121 已提交
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
  if (!gCurCase->fullCol) {
    len += sprintf(data->sql + len, "(");
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
      if (c) {
        len += sprintf(data->sql + len, ",");
      }
      switch (data->pBind[c].buffer_type) {  
        case TSDB_DATA_TYPE_BOOL:
          len += sprintf(data->sql + len, "booldata");
          break;
        case TSDB_DATA_TYPE_TINYINT:
          len += sprintf(data->sql + len, "tinydata");
          break;
        case TSDB_DATA_TYPE_SMALLINT:
          len += sprintf(data->sql + len, "smalldata");
          break;
        case TSDB_DATA_TYPE_INT:
          len += sprintf(data->sql + len, "intdata");
          break;
        case TSDB_DATA_TYPE_BIGINT:
          len += sprintf(data->sql + len, "bigdata");
          break;
        case TSDB_DATA_TYPE_FLOAT:
          len += sprintf(data->sql + len, "floatdata");
          break;
        case TSDB_DATA_TYPE_DOUBLE:
          len += sprintf(data->sql + len, "doubledata");
          break;
        case TSDB_DATA_TYPE_VARCHAR:
          len += sprintf(data->sql + len, "binarydata");
          break;
        case TSDB_DATA_TYPE_TIMESTAMP:
          len += sprintf(data->sql + len, "ts");
          break;
        case TSDB_DATA_TYPE_NCHAR:
          len += sprintf(data->sql + len, "nchardata");
          break;
        case TSDB_DATA_TYPE_UTINYINT:
          len += sprintf(data->sql + len, "utinydata");
          break;
        case TSDB_DATA_TYPE_USMALLINT:
          len += sprintf(data->sql + len, "usmalldata");
          break;
        case TSDB_DATA_TYPE_UINT:
          len += sprintf(data->sql + len, "uintdata");
          break;
        case TSDB_DATA_TYPE_UBIGINT:
          len += sprintf(data->sql + len, "ubigdata");
          break;
        default:
D
dapan1121 已提交
327
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
stmt  
dapan1121 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
          exit(1);
      }
    }
    
    len += sprintf(data->sql + len, ") ");
  }

  len += sprintf(data->sql + len, "values (");
  for (int c = 0; c < gCurCase->bindColNum; ++c) {
    if (c) {
      len += sprintf(data->sql + len, ",");
    }
    len += sprintf(data->sql + len, "?");
  }
  len += sprintf(data->sql + len, ")");
D
stmt  
dapan1121 已提交
343

D
dapan1121 已提交
344
  if (gCaseCtrl.printStmtSql) {
D
dapan1121 已提交
345
    printf("\tSQL: %s\n", data->sql);
D
stmt  
dapan1121 已提交
346
  }  
D
stmt  
dapan1121 已提交
347
}
D
stmt  
dapan1121 已提交
348

D
dapan1121 已提交
349
void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) {
D
dapan1121 已提交
350
  OperInfo *pInfo = NULL;
D
dapan1121 已提交
351 352 353

  if (gCaseCtrl.optrIdxListNum > 0) {
    pInfo = &operInfo[gCaseCtrl.optrIdxList[idx]];
D
dapan1121 已提交
354
  } else {
D
dapan1121 已提交
355 356 357 358 359
    if (TSDB_DATA_TYPE_VARCHAR == dataType || TSDB_DATA_TYPE_NCHAR == dataType) {
      pInfo = &operInfo[varoperatorList[rand() % tListLen(varoperatorList)]];
    } else {
      pInfo = &operInfo[operatorList[rand() % tListLen(operatorList)]];
    }
D
dapan1121 已提交
360
  }
D
dapan1121 已提交
361
  
D
dapan1121 已提交
362 363 364 365 366 367 368 369 370
  switch (pInfo->paramNum) {
    case 2:
      if (pInfo->enclose) {
        *len += sprintf(data->sql + *len, " %s (?)", pInfo->oper);
      } else {
        *len += sprintf(data->sql + *len, " %s ?", pInfo->oper);
      }
      break;
    default:
D
dapan1121 已提交
371
      printf("!!!invalid paramNum:%d\n", pInfo->paramNum);
D
dapan1121 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
      exit(1);
  }
}

void generateQuerySQL(BindData *data, int32_t tblIdx) {
  int32_t len = sprintf(data->sql, "select * from %s%d where ", bpTbPrefix, tblIdx);
  if (!gCurCase->fullCol) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
      if (c) {
        len += sprintf(data->sql + len, " and ");
      }
      switch (data->pBind[c].buffer_type) {  
        case TSDB_DATA_TYPE_BOOL:
          len += sprintf(data->sql + len, "booldata");
          break;
        case TSDB_DATA_TYPE_TINYINT:
          len += sprintf(data->sql + len, "tinydata");
          break;
        case TSDB_DATA_TYPE_SMALLINT:
          len += sprintf(data->sql + len, "smalldata");
          break;
        case TSDB_DATA_TYPE_INT:
          len += sprintf(data->sql + len, "intdata");
          break;
        case TSDB_DATA_TYPE_BIGINT:
          len += sprintf(data->sql + len, "bigdata");
          break;
        case TSDB_DATA_TYPE_FLOAT:
          len += sprintf(data->sql + len, "floatdata");
          break;
        case TSDB_DATA_TYPE_DOUBLE:
          len += sprintf(data->sql + len, "doubledata");
          break;
        case TSDB_DATA_TYPE_VARCHAR:
          len += sprintf(data->sql + len, "binarydata");
          break;
        case TSDB_DATA_TYPE_TIMESTAMP:
          len += sprintf(data->sql + len, "ts");
          break;
        case TSDB_DATA_TYPE_NCHAR:
          len += sprintf(data->sql + len, "nchardata");
          break;
        case TSDB_DATA_TYPE_UTINYINT:
          len += sprintf(data->sql + len, "utinydata");
          break;
        case TSDB_DATA_TYPE_USMALLINT:
          len += sprintf(data->sql + len, "usmalldata");
          break;
        case TSDB_DATA_TYPE_UINT:
          len += sprintf(data->sql + len, "uintdata");
          break;
        case TSDB_DATA_TYPE_UBIGINT:
          len += sprintf(data->sql + len, "ubigdata");
          break;
        default:
D
dapan1121 已提交
427
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
dapan1121 已提交
428 429 430
          exit(1);
      }
      
D
dapan1121 已提交
431
      bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c);
D
dapan1121 已提交
432 433 434 435
    }
  }

  if (gCaseCtrl.printStmtSql) {
D
dapan1121 已提交
436
    printf("\tSTMT SQL: %s\n", data->sql);
D
dapan1121 已提交
437 438 439 440
  }  
}


D
stmt  
dapan1121 已提交
441 442
void generateDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) {
  if (bindIdx < gCurCase->bindColNum) {
D
stmt  
dapan1121 已提交
443
    if (gCaseCtrl.bindColTypeNum) {
D
stmt  
dapan1121 已提交
444 445
      *dataType = gCaseCtrl.bindColTypeList[colIdx];
      return;
D
stmt  
dapan1121 已提交
446 447 448
    } else if (gCurCase->fullCol) {
      *dataType = gCurCase->colList[bindIdx];
      return;
D
stmt  
dapan1121 已提交
449 450 451 452
    } else if (0 == colIdx) {
      *dataType = TSDB_DATA_TYPE_TIMESTAMP;
      return;
    } else {
D
stmt  
dapan1121 已提交
453 454 455 456 457 458 459
      while (true) {
        *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1;
        if (*dataType == TSDB_DATA_TYPE_JSON || *dataType == TSDB_DATA_TYPE_DECIMAL 
         || *dataType == TSDB_DATA_TYPE_BLOB || *dataType == TSDB_DATA_TYPE_MEDIUMBLOB
         || *dataType == TSDB_DATA_TYPE_VARBINARY) {
          continue;
        }
D
stmt  
dapan1121 已提交
460

D
stmt  
dapan1121 已提交
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
        if (colExists(data->pBind, *dataType)) {
          continue;
        }
        
        break;
      }
    }
  } else {
    *dataType = data->pBind[bindIdx%gCurCase->bindColNum].buffer_type;
  }
}

int32_t prepareColData(BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t colIdx) {
  int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP;

  generateDataType(data, bindIdx, colIdx, &dataType);

  switch (dataType) {  
    case TSDB_DATA_TYPE_BOOL:
      data->pBind[bindIdx].buffer_length = sizeof(bool);
      data->pBind[bindIdx].buffer = data->boolData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
483
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
484 485 486 487 488
      break;
    case TSDB_DATA_TYPE_TINYINT:
      data->pBind[bindIdx].buffer_length = sizeof(int8_t);
      data->pBind[bindIdx].buffer = data->tinyData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
489
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
490 491 492 493 494
      break;
    case TSDB_DATA_TYPE_SMALLINT:
      data->pBind[bindIdx].buffer_length = sizeof(int16_t);
      data->pBind[bindIdx].buffer = data->smallData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
495
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
496 497 498 499 500
      break;
    case TSDB_DATA_TYPE_INT:
      data->pBind[bindIdx].buffer_length = sizeof(int32_t);
      data->pBind[bindIdx].buffer = data->intData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
501
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
502 503 504 505 506
      break;
    case TSDB_DATA_TYPE_BIGINT:
      data->pBind[bindIdx].buffer_length = sizeof(int64_t);
      data->pBind[bindIdx].buffer = data->bigData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
507
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
508 509 510 511 512
      break;
    case TSDB_DATA_TYPE_FLOAT:
      data->pBind[bindIdx].buffer_length = sizeof(float);
      data->pBind[bindIdx].buffer = data->floatData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
513
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
514 515 516 517 518
      break;
    case TSDB_DATA_TYPE_DOUBLE:
      data->pBind[bindIdx].buffer_length = sizeof(double);
      data->pBind[bindIdx].buffer = data->doubleData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
519
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
520 521 522
      break;
    case TSDB_DATA_TYPE_VARCHAR:
      data->pBind[bindIdx].buffer_length = gVarCharSize;
D
stmt  
dapan1121 已提交
523
      data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
D
stmt  
dapan1121 已提交
524
      data->pBind[bindIdx].length = data->binaryLen;
D
stmt  
dapan1121 已提交
525
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
526 527 528 529 530 531 532 533 534
      break;
    case TSDB_DATA_TYPE_TIMESTAMP:
      data->pBind[bindIdx].buffer_length = sizeof(int64_t);
      data->pBind[bindIdx].buffer = data->tsData + rowIdx;
      data->pBind[bindIdx].length = NULL;
      data->pBind[bindIdx].is_null = NULL;
      break;
    case TSDB_DATA_TYPE_NCHAR:
      data->pBind[bindIdx].buffer_length = gVarCharSize;
D
stmt  
dapan1121 已提交
535
      data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
D
stmt  
dapan1121 已提交
536
      data->pBind[bindIdx].length = data->binaryLen;
D
stmt  
dapan1121 已提交
537
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
538 539 540 541 542
      break;
    case TSDB_DATA_TYPE_UTINYINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint8_t);
      data->pBind[bindIdx].buffer = data->utinyData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
543
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
544 545 546 547 548
      break;
    case TSDB_DATA_TYPE_USMALLINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint16_t);
      data->pBind[bindIdx].buffer = data->usmallData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
549
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
550 551 552 553 554
      break;
    case TSDB_DATA_TYPE_UINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint32_t);
      data->pBind[bindIdx].buffer = data->uintData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
555
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
556 557 558 559 560
      break;
    case TSDB_DATA_TYPE_UBIGINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint64_t);
      data->pBind[bindIdx].buffer = data->ubigData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
561
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
562 563
      break;
    default:
D
dapan1121 已提交
564
      printf("!!!invalid col type:%d", dataType);
D
stmt  
dapan1121 已提交
565 566 567 568 569 570 571 572 573 574
      exit(1);
  }

  data->pBind[bindIdx].buffer_type = dataType;
  data->pBind[bindIdx].num = gCurCase->bindRowNum;

  return 0;
}


D
dapan1121 已提交
575
int32_t prepareInsertData(BindData *data) {
D
stmt  
dapan1121 已提交
576 577 578 579 580 581
  static int64_t tsData = 1591060628000;
  uint64_t allRowNum = gCurCase->rowNum * gCurCase->tblNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
D
dapan1121 已提交
582
  data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
stmt  
dapan1121 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
  data->tsData = taosMemoryMalloc(allRowNum * sizeof(int64_t));
  data->boolData = taosMemoryMalloc(allRowNum * sizeof(bool));
  data->tinyData = taosMemoryMalloc(allRowNum * sizeof(int8_t));
  data->utinyData = taosMemoryMalloc(allRowNum * sizeof(uint8_t));
  data->smallData = taosMemoryMalloc(allRowNum * sizeof(int16_t));
  data->usmallData = taosMemoryMalloc(allRowNum * sizeof(uint16_t));
  data->intData = taosMemoryMalloc(allRowNum * sizeof(int32_t));
  data->uintData = taosMemoryMalloc(allRowNum * sizeof(uint32_t));
  data->bigData = taosMemoryMalloc(allRowNum * sizeof(int64_t));
  data->ubigData = taosMemoryMalloc(allRowNum * sizeof(uint64_t));
  data->floatData = taosMemoryMalloc(allRowNum * sizeof(float));
  data->doubleData = taosMemoryMalloc(allRowNum * sizeof(double));
  data->binaryData = taosMemoryMalloc(allRowNum * gVarCharSize);
  data->binaryLen = taosMemoryMalloc(allRowNum * sizeof(int32_t));
  if (gCurCase->bindNullNum) {
    data->isNull = taosMemoryCalloc(allRowNum, sizeof(char));
  }
  
  for (int32_t i = 0; i < allRowNum; ++i) {
    data->tsData[i] = tsData++;
D
dapan1121 已提交
603 604 605 606 607 608 609 610 611 612 613
    data->boolData[i] = (bool)(i % 2);
    data->tinyData[i] = (int8_t)i;
    data->utinyData[i] = (uint8_t)(i+1);
    data->smallData[i] = (int16_t)i;
    data->usmallData[i] = (uint16_t)(i+1);
    data->intData[i] = (int32_t)i;
    data->uintData[i] = (uint32_t)(i+1);
    data->bigData[i] = (int64_t)i;
    data->ubigData[i] = (uint64_t)(i+1);
    data->floatData[i] = (float)i;
    data->doubleData[i] = (double)(i+1);
D
stmt  
dapan1121 已提交
614 615 616 617 618 619 620 621 622 623 624 625 626
    memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
    if (gCurCase->bindNullNum) {
      data->isNull[i] = i % 2;
    }
    data->binaryLen[i] = gVarCharLen;
  }

  for (int b = 0; b < (allRowNum/gCurCase->bindRowNum); b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
      prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
    }
  }

D
stmt  
dapan1121 已提交
627
  generateInsertSQL(data);
D
stmt  
dapan1121 已提交
628 629 630 631
  
  return 0;
}

D
dapan1121 已提交
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
int32_t prepareQueryData(BindData *data, int32_t tblIdx) {
  static int64_t tsData = 1591060628000;
  uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
  data->pBind = taosMemoryCalloc(bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
  data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t));
  data->boolData = taosMemoryMalloc(bindNum * sizeof(bool));
  data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t));
  data->utinyData = taosMemoryMalloc(bindNum * sizeof(uint8_t));
  data->smallData = taosMemoryMalloc(bindNum * sizeof(int16_t));
  data->usmallData = taosMemoryMalloc(bindNum * sizeof(uint16_t));
  data->intData = taosMemoryMalloc(bindNum * sizeof(int32_t));
  data->uintData = taosMemoryMalloc(bindNum * sizeof(uint32_t));
  data->bigData = taosMemoryMalloc(bindNum * sizeof(int64_t));
  data->ubigData = taosMemoryMalloc(bindNum * sizeof(uint64_t));
  data->floatData = taosMemoryMalloc(bindNum * sizeof(float));
  data->doubleData = taosMemoryMalloc(bindNum * sizeof(double));
  data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize);
  data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t));
  if (gCurCase->bindNullNum) {
    data->isNull = taosMemoryCalloc(bindNum, sizeof(char));
  }
  
  for (int32_t i = 0; i < bindNum; ++i) {
    data->tsData[i] = tsData + tblIdx*gCurCase->rowNum + rand()%gCurCase->rowNum;
    data->boolData[i] = (bool)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->tinyData[i] = (int8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->utinyData[i] = (uint8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->smallData[i] = (int16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->usmallData[i] = (uint16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->intData[i] = (int32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->uintData[i] = (uint32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->bigData[i] = (int64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->ubigData[i] = (uint64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->floatData[i] = (float)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->doubleData[i] = (double)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
    if (gCurCase->bindNullNum) {
      data->isNull[i] = i % 2;
    }
    data->binaryLen[i] = gVarCharLen;
  }

  for (int b = 0; b < bindNum; b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
      prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
    }
  }

  generateQuerySQL(data, tblIdx);
  
  return 0;
}


D
stmt  
dapan1121 已提交
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
void destroyData(BindData *data) {
  taosMemoryFree(data->tsData);
  taosMemoryFree(data->boolData);
  taosMemoryFree(data->tinyData);
  taosMemoryFree(data->utinyData);
  taosMemoryFree(data->smallData);
  taosMemoryFree(data->usmallData);
  taosMemoryFree(data->intData);
  taosMemoryFree(data->uintData);
  taosMemoryFree(data->bigData);
  taosMemoryFree(data->ubigData);
  taosMemoryFree(data->floatData);
  taosMemoryFree(data->doubleData);
  taosMemoryFree(data->binaryData);
  taosMemoryFree(data->binaryLen);
  taosMemoryFree(data->isNull);
  taosMemoryFree(data->pBind);
D
stmt  
dapan1121 已提交
707 708 709
  taosMemoryFree(data->colTypes);
}

D
dapan1121 已提交
710 711 712 713 714 715 716 717 718 719 720 721
void bpFetchRows(TAOS_RES *result, bool printr, int32_t *rows) {
  TAOS_ROW    row;
  int         num_fields = taos_num_fields(result);
  TAOS_FIELD *fields = taos_fetch_fields(result);
  char        temp[256];

  // fetch the records row by row
  while ((row = taos_fetch_row(result))) {
    (*rows)++;
    if (printr) {
      memset(temp, 0, sizeof(temp));
      taos_print_row(temp, row, fields, num_fields);
D
dapan1121 已提交
722
      printf("\t[%s]\n", temp);
D
dapan1121 已提交
723 724 725 726 727 728 729 730
    }
  }
}

void bpExecQuery(TAOS    * taos, char* sql, bool printr, int32_t *rows) {
  TAOS_RES *result = taos_query(taos, sql);
  int code = taos_errno(result);
  if (code != 0) {
D
dapan1121 已提交
731
    printf("!!!failed to query table, reason:%s\n", taos_errstr(result));
D
dapan1121 已提交
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
    taos_free_result(result);
    exit(1);
  }

  bpFetchRows(result, printr, rows);

  taos_free_result(result);
}


int32_t bpAppendValueString(char *buf, int type, void *value, int32_t valueLen, int32_t *len) {
  switch (type) {
    case TSDB_DATA_TYPE_NULL:
      *len += sprintf(buf + *len, "null");
      break;

    case TSDB_DATA_TYPE_BOOL:
      *len += sprintf(buf + *len, (*(bool*)value) ? "true" : "false");
      break;

    case TSDB_DATA_TYPE_TINYINT:
      *len += sprintf(buf + *len, "%d", *(int8_t*)value);
      break;

    case TSDB_DATA_TYPE_SMALLINT:
      *len += sprintf(buf + *len, "%d", *(int16_t*)value);
      break;

    case TSDB_DATA_TYPE_INT:
      *len += sprintf(buf + *len, "%d", *(int32_t*)value);
      break;

    case TSDB_DATA_TYPE_BIGINT:
    case TSDB_DATA_TYPE_TIMESTAMP:
      *len += sprintf(buf + *len, "%ld", *(int64_t*)value);
      break;

    case TSDB_DATA_TYPE_FLOAT:
      *len += sprintf(buf + *len, "%e", *(float*)value);
      break;

    case TSDB_DATA_TYPE_DOUBLE:
      *len += sprintf(buf + *len, "%e", *(double*)value);
      break;

    case TSDB_DATA_TYPE_BINARY:
    case TSDB_DATA_TYPE_NCHAR:
      buf[*len] = '\'';
      ++(*len);
      memcpy(buf + *len, value, valueLen);
      *len += valueLen;
      buf[*len] = '\'';
      ++(*len);
      break;

    case TSDB_DATA_TYPE_UTINYINT:
      *len += sprintf(buf + *len, "%d", *(uint8_t*)value);
      break;

    case TSDB_DATA_TYPE_USMALLINT:
      *len += sprintf(buf + *len, "%d", *(uint16_t*)value);
      break;

    case TSDB_DATA_TYPE_UINT:
      *len += sprintf(buf + *len, "%u", *(uint32_t*)value);
      break;

    case TSDB_DATA_TYPE_UBIGINT:
      *len += sprintf(buf + *len, "%lu", *(uint64_t*)value);
      break;

    default:
D
dapan1121 已提交
804
      printf("!!!invalid data type:%d\n", type);
D
dapan1121 已提交
805 806 807 808 809
      exit(1);
  }
}


D
dapan1121 已提交
810
int32_t bpBindParam(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
D
stmt  
dapan1121 已提交
811 812 813 814 815
  static int32_t n = 0;
  
  if (gCurCase->bindRowNum > 1) {
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
816
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
817 818 819 820 821
        exit(1);
      }
    } else {
      for (int32_t i = 0; i < gCurCase->bindColNum; ++i) {
        if (taos_stmt_bind_single_param_batch(stmt, bind++, i)) {
D
dapan1121 已提交
822
          printf("!!!taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
823 824 825 826 827
          exit(1);
        }
      }
    }
  } else {
D
dapan1121 已提交
828 829
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
830
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
831 832 833 834
        exit(1);
      }
    } else {
      if (taos_stmt_bind_param(stmt, bind)) {
D
dapan1121 已提交
835
        printf("!!!taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
836 837
        exit(1);
      }
D
stmt  
dapan1121 已提交
838 839 840 841 842 843
    }
  }

  return 0;
}

D
dapan1121 已提交
844
void bpCheckIsInsert(TAOS_STMT *stmt, int32_t insert) {
D
stmt  
dapan1121 已提交
845 846
  int32_t isInsert = 0;
  if (taos_stmt_is_insert(stmt, &isInsert)) {
D
dapan1121 已提交
847
    printf("!!!taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
848 849 850
    exit(1);
  }

D
dapan1121 已提交
851
  if (insert != isInsert) {
D
dapan1121 已提交
852
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
853 854 855 856 857 858 859
    exit(1);
  }
}

void bpCheckParamNum(TAOS_STMT *stmt) {
  int32_t num = 0;
  if (taos_stmt_num_params(stmt, &num)) {
D
dapan1121 已提交
860
    printf("!!!taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
861 862 863 864
    exit(1);
  }

  if (gCurCase->bindColNum != num) {
D
dapan1121 已提交
865
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
866 867 868 869 870 871 872 873
    exit(1);
  }
}

void bpCheckAffectedRows(TAOS_STMT *stmt, int32_t times) {
  int32_t rows = taos_stmt_affected_rows(stmt);
  int32_t insertNum = gCurCase->rowNum * gCurCase->tblNum * times;
  if (insertNum != rows) {
D
dapan1121 已提交
874
    printf("!!!affected rows %d mis-match with insert num %d\n", rows, insertNum);
D
stmt  
dapan1121 已提交
875 876
    exit(1);
  }
D
stmt  
dapan1121 已提交
877 878
}

D
dapan1121 已提交
879 880 881
void bpCheckAffectedRowsOnce(TAOS_STMT *stmt, int32_t expectedNum) {
  int32_t rows = taos_stmt_affected_rows_once(stmt);
  if (expectedNum != rows) {
D
dapan1121 已提交
882
    printf("!!!affected rows %d mis-match with expected num %d\n", rows, expectedNum);
D
dapan1121 已提交
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
    exit(1);
  }
}

void bpCheckQueryResult(TAOS_STMT *stmt, TAOS *taos, char *stmtSql, TAOS_MULTI_BIND* bind) {
  TAOS_RES* res = taos_stmt_use_result(stmt);
  int32_t sqlResNum = 0;
  int32_t stmtResNum = 0;
  bpFetchRows(res, gCaseCtrl.printRes, &stmtResNum);

  char sql[1024];
  int32_t len = 0;
  char* p = stmtSql;
  char* s = NULL;

  for (int32_t i = 0; true; ++i, p=s+1) {
    s = strchr(p, '?');
    if (NULL == s) {
      strcpy(&sql[len], p);
      break;
    }

    memcpy(&sql[len], p, (int64_t)s - (int64_t)p);
    len += (int64_t)s - (int64_t)p;
    
    if (bind[i].is_null && bind[i].is_null[0]) {
      bpAppendValueString(sql, TSDB_DATA_TYPE_NULL, NULL, 0, &len);
      continue;
    }

    bpAppendValueString(sql, bind[i].buffer_type, bind[i].buffer, (bind[i].length ? bind[i].length[0] : 0), &len);
  }

  if (gCaseCtrl.printQuerySql) {
D
dapan1121 已提交
917
    printf("\tQuery SQL: %s\n", sql);
D
dapan1121 已提交
918 919 920 921
  }

  bpExecQuery(taos, sql, gCaseCtrl.printRes, &sqlResNum);
  if (sqlResNum != stmtResNum) {
D
dapan1121 已提交
922
    printf("!!!sql res num %d mis-match stmt res num %d\n", sqlResNum, stmtResNum);
D
dapan1121 已提交
923 924 925
    exit(1);
  }

D
dapan1121 已提交
926
  printf("***sql res num match stmt res num %d\n", stmtResNum);
D
dapan1121 已提交
927
}
D
stmt  
dapan1121 已提交
928

D
stmt  
dapan1121 已提交
929
/* prepare [settbname [bind add]] exec */
D
dapan1121 已提交
930
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
931
  BindData data = {0};
D
dapan1121 已提交
932
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
933 934

  int code = taos_stmt_prepare(stmt, data.sql, 0);
D
stmt  
dapan1121 已提交
935
  if (code != 0){
D
dapan1121 已提交
936
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
937
    exit(1);
D
stmt  
dapan1121 已提交
938 939
  }

D
dapan1121 已提交
940
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
941

D
stmt  
dapan1121 已提交
942 943 944 945 946 947 948
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
949
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
950 951 952
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
953 954 955 956

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
957 958
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
959
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
960 961 962 963
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
964
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
965 966 967 968 969 970
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
971
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
972 973 974
    exit(1);
  }

D
dapan1121 已提交
975
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
976 977 978 979
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
980 981 982 983
  return 0;
}


D
stmt  
dapan1121 已提交
984
/* prepare [settbname bind add] exec  */
D
dapan1121 已提交
985
int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
986
  BindData data = {0};
D
dapan1121 已提交
987
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
988 989 990

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
991
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
992 993 994
    exit(1);
  }

D
dapan1121 已提交
995
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
996

D
stmt  
dapan1121 已提交
997 998 999 1000 1001 1002 1003 1004 1005
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;

  for (int32_t b = 0; b <bindTimes; ++b) {
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
        code = taos_stmt_set_tbname(stmt, buf);
        if (code != 0){
D
dapan1121 已提交
1006
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1007 1008 1009 1010
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1011
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1012 1013
        exit(1);
      }
D
stmt  
dapan1121 已提交
1014 1015 1016 1017 1018

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1019
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1020
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1021 1022 1023 1024 1025 1026
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1027
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1028 1029 1030
    exit(1);
  }

D
dapan1121 已提交
1031
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1032 1033 1034 1035
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1036 1037 1038 1039
  return 0;
}

/* prepare [settbname [bind add] exec] */
D
dapan1121 已提交
1040
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1041
  BindData data = {0};
D
dapan1121 已提交
1042
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1043 1044 1045
  
  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1046
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1047 1048
    exit(1);
  }
D
stmt  
dapan1121 已提交
1049

D
dapan1121 已提交
1050
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1051

D
stmt  
dapan1121 已提交
1052 1053 1054 1055 1056 1057 1058
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
1059
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1060 1061 1062
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1063 1064 1065 1066

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1067 1068
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1069
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1070 1071 1072 1073
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1074
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1075 1076 1077
        exit(1);
      }
    }
D
stmt  
dapan1121 已提交
1078

D
stmt  
dapan1121 已提交
1079
    if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1080
      printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1081 1082
      exit(1);
    }
D
stmt  
dapan1121 已提交
1083 1084
  }

D
dapan1121 已提交
1085
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1086 1087 1088
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1089

D
stmt  
dapan1121 已提交
1090 1091 1092
  return 0;
}

D
stmt  
dapan1121 已提交
1093
/* prepare [settbname [bind add exec]] */
D
dapan1121 已提交
1094
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1095
  BindData data = {0};
D
dapan1121 已提交
1096
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1097 1098 1099

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1100
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1101 1102 1103
    exit(1);
  }

D
dapan1121 已提交
1104
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1105

D
stmt  
dapan1121 已提交
1106 1107 1108 1109 1110 1111 1112
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
1113
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1114 1115 1116 1117 1118
        exit(1);
      }  
    }
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1119
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1120 1121
        exit(1);
      }
D
stmt  
dapan1121 已提交
1122 1123 1124 1125 1126

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1127
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1128
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1129 1130 1131 1132
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1133
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1134 1135 1136 1137 1138
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1139
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1140 1141 1142
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1143 1144 1145 1146

  return 0;
}

D
stmt  
dapan1121 已提交
1147
/* prepare [settbname [settbname bind add exec]] */
D
dapan1121 已提交
1148
int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1149
  BindData data = {0};
D
dapan1121 已提交
1150
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1151 1152 1153

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1154
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1155 1156 1157
    exit(1);
  }

D
dapan1121 已提交
1158
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1159

D
stmt  
dapan1121 已提交
1160 1161 1162 1163 1164 1165 1166
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
1167
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1168 1169 1170
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1171 1172 1173 1174

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1175 1176 1177 1178 1179 1180 1181
    
    for (int32_t b = 0; b <bindTimes; ++b) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
        code = taos_stmt_set_tbname(stmt, buf);
        if (code != 0){
D
dapan1121 已提交
1182
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1183 1184 1185 1186
          exit(1);
        }  
      }
      
D
stmt  
dapan1121 已提交
1187
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1188 1189 1190 1191
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1192
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1193 1194 1195 1196
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1197
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1198 1199 1200 1201 1202
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1203
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1204 1205 1206
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1207 1208 1209 1210 1211 1212

  return 0;
}


/* prepare [settbname bind add exec]   */
D
dapan1121 已提交
1213
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1214
  BindData data = {0};
D
dapan1121 已提交
1215
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1216 1217 1218

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1219
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1220 1221 1222
    exit(1);
  }

D
dapan1121 已提交
1223
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1224

D
stmt  
dapan1121 已提交
1225 1226 1227 1228 1229 1230 1231 1232 1233
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;

  for (int32_t b = 0; b <bindTimes; ++b) {
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
        code = taos_stmt_set_tbname(stmt, buf);
        if (code != 0){
D
dapan1121 已提交
1234
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1235 1236 1237 1238
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1239
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1240 1241
        exit(1);
      }
D
stmt  
dapan1121 已提交
1242 1243 1244 1245 1246

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1247
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1248
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1249 1250 1251 1252
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1253
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1254 1255 1256 1257 1258
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1259
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1260 1261 1262 1263 1264 1265 1266 1267
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

  return 0;
}

/* [prepare [settbname [bind add] exec]]   */
D
dapan1121 已提交
1268
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1269 1270 1271 1272
  int32_t loop = 0;
  
  while (gCurCase->bindColNum >= 2) {
    BindData data = {0};
D
dapan1121 已提交
1273
    prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1274 1275 1276

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
D
dapan1121 已提交
1277
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1278 1279 1280
      exit(1);
    }

D
dapan1121 已提交
1281
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1282 1283 1284 1285 1286 1287 1288 1289

    int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
        code = taos_stmt_set_tbname(stmt, buf);
        if (code != 0){
D
dapan1121 已提交
1290
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
          exit(1);
        }  
      }

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
      for (int32_t b = 0; b <bindTimes; ++b) {
        if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
          exit(1);
        }
        
        if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1305
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1306 1307 1308 1309 1310
          exit(1);
        }
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1311
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1312 1313 1314 1315
        exit(1);
      }
    }

D
dapan1121 已提交
1316
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1317 1318 1319 1320

    destroyData(&data);

    gCurCase->bindColNum -= 2;
D
stmt  
dapan1121 已提交
1321
    gCurCase->fullCol = false;
D
stmt  
dapan1121 已提交
1322 1323 1324 1325 1326 1327 1328
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
D
stmt  
dapan1121 已提交
1329 1330 1331
  return 0;
}

D
dapan1121 已提交
1332 1333 1334 1335 1336 1337 1338 1339 1340
int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos) {
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
    prepareQueryData(&data, t);

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
D
dapan1121 已提交
1341
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
      exit(1);
    }

    for (int32_t n = 0; n< (gCurCase->rowNum/gCurCase->bindRowNum); ++n) {
      bpCheckIsInsert(stmt, 0);

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
      if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum)) {
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1357
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1358 1359 1360 1361
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1362
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
        exit(1);
      }

      bpCheckQueryResult(stmt, taos, data.sql, data.pBind + n * gCurCase->bindColNum);    
    }
    
    bpCheckIsInsert(stmt, 0);

    destroyData(&data);
  }

  return 0;
}

D
stmt  
dapan1121 已提交
1377

D
stmt  
dapan1121 已提交
1378
#if 0
1379 1380

//1 tables 10 records
D
stmt  
dapan1121 已提交
1381
int stmt_funcb_autoctb1(TAOS_STMT *stmt) {
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
1394
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1395
  
wafwerar's avatar
wafwerar 已提交
1396
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1397

wafwerar's avatar
wafwerar 已提交
1398
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1399
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1400 1401 1402 1403

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1404 1405
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
    tags[i+3].is_null = &one_not_null;
    tags[i+3].length = NULL;

    tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT;
    tags[i+4].buffer = v.v8;
    tags[i+4].is_null = &one_not_null;
    tags[i+4].length = NULL;

    tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+5].buffer = v.f4;
    tags[i+5].is_null = &one_not_null;
    tags[i+5].length = NULL;

    tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    tags[i+6].buffer = v.f8;
    tags[i+6].is_null = &one_not_null;
    tags[i+6].length = NULL;

    tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+7].buffer = v.bin;
    tags[i+7].is_null = &one_not_null;
    tags[i+7].length = (uintptr_t *)lb;

    tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR;
    tags[i+8].buffer = v.bin;
    tags[i+8].is_null = &one_not_null;
    tags[i+8].length = (uintptr_t *)lb;
  }


D
stmt  
dapan1121 已提交
1548
  unsigned long long starttime = taosGetTimestampUs();
1549

D
stmt  
dapan1121 已提交
1550
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

    taos_stmt_bind_param_batch(stmt, params + id * 10);
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
1577
  unsigned long long endtime = taosGetTimestampUs();
1578 1579
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1580 1581 1582 1583 1584 1585
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1586 1587 1588 1589 1590 1591 1592 1593

  return 0;
}




//1 tables 10 records
D
stmt  
dapan1121 已提交
1594
int stmt_funcb_autoctb2(TAOS_STMT *stmt) {
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
1607
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1608
  
wafwerar's avatar
wafwerar 已提交
1609
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1610

wafwerar's avatar
wafwerar 已提交
1611
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1612
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1613 1614 1615 1616

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1617 1618
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
D
stmt  
dapan1121 已提交
1687 1688 1689
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;
1690

D
stmt  
dapan1121 已提交
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
1705 1706 1707 1708 1709 1710 1711 1712 1713
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
D
stmt  
dapan1121 已提交
1714 1715
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
1716 1717 1718
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
1719 1720
    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
1721 1722 1723
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
1724 1725
    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
1726 1727 1728
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
1729 1730
    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
1731
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
    tags[i+3].length = NULL;

    tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT;
    tags[i+4].buffer = v.v8;
    tags[i+4].is_null = &one_not_null;
    tags[i+4].length = NULL;

    tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+5].buffer = v.f4;
    tags[i+5].is_null = &one_not_null;
    tags[i+5].length = NULL;

    tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    tags[i+6].buffer = v.f8;
    tags[i+6].is_null = &one_not_null;
    tags[i+6].length = NULL;

    tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+7].buffer = v.bin;
    tags[i+7].is_null = &one_not_null;
    tags[i+7].length = (uintptr_t *)lb;

    tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR;
    tags[i+8].buffer = v.bin;
    tags[i+8].is_null = &one_not_null;
    tags[i+8].length = (uintptr_t *)lb;
1758 1759 1760
  }


D
stmt  
dapan1121 已提交
1761
  unsigned long long starttime = taosGetTimestampUs();
1762

D
stmt  
dapan1121 已提交
1763
  char *sql = "insert into ? using stb1 tags(1,true,2,3,4,5.0,6.0,'a','b') values(?,?,?,?,?,?,?,?,?,?)";
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

D
stmt  
dapan1121 已提交
1779
    taos_stmt_bind_param_batch(stmt, params + id * 10);
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
1790
  unsigned long long endtime = taosGetTimestampUs();
1791 1792
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1793 1794 1795 1796 1797 1798
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1799 1800 1801 1802 1803 1804 1805 1806 1807

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
1808
int stmt_funcb_autoctb3(TAOS_STMT *stmt) {
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
1821
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1822
  
wafwerar's avatar
wafwerar 已提交
1823
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1824

wafwerar's avatar
wafwerar 已提交
1825
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1826
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1827 1828 1829 1830

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1831 1832
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
    tags[i+3].is_null = &one_not_null;
    tags[i+3].length = (uintptr_t *)lb;
  }


D
stmt  
dapan1121 已提交
1950
  unsigned long long starttime = taosGetTimestampUs();
1951

D
stmt  
dapan1121 已提交
1952
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
1953 1954
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
1955 1956
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

    taos_stmt_bind_param_batch(stmt, params + id * 10);
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
1979
  unsigned long long endtime = taosGetTimestampUs();
1980 1981
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1982 1983 1984 1985 1986 1987
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1988 1989 1990 1991 1992 1993 1994 1995

  return 0;
}





D
stmt  
dapan1121 已提交
1996 1997


1998
//1 tables 10 records
D
stmt  
dapan1121 已提交
1999
int stmt_funcb_autoctb4(TAOS_STMT *stmt) {
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2012
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2013
  
wafwerar's avatar
wafwerar 已提交
2014
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2015

wafwerar's avatar
wafwerar 已提交
2016
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2017
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*5);
2018 2019 2020 2021

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2022 2023
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
D
stmt  
dapan1121 已提交
2039
  for (int i = 0; i < 5; i+=5) {
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

D
stmt  
dapan1121 已提交
2054 2055 2056
    params[i+2].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+2].buffer_length = sizeof(int32_t);
    params[i+2].buffer = v.v4;
2057 2058 2059 2060
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

D
stmt  
dapan1121 已提交
2061 2062 2063
    params[i+3].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+3].buffer_length = sizeof(int64_t);
    params[i+3].buffer = v.v8;
2064 2065 2066 2067
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

D
stmt  
dapan1121 已提交
2068 2069 2070
    params[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+4].buffer_length = sizeof(double);
    params[i+4].buffer = v.f8;
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
D
stmt  
dapan1121 已提交
2083 2084
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
2085 2086 2087
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2088 2089
    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
2090 2091 2092
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2093 2094
    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
2095 2096 2097
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2098 2099
    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
2100
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2101
    tags[i+3].length = (uintptr_t *)lb;
2102 2103 2104
  }


D
stmt  
dapan1121 已提交
2105
  unsigned long long starttime = taosGetTimestampUs();
2106

D
stmt  
dapan1121 已提交
2107
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') (ts,b,v4,v8,f8) values(?,?,?,?,?)";
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2118
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2119
    if (code != 0){
D
stmt  
dapan1121 已提交
2120
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
2121 2122
    }  

D
stmt  
dapan1121 已提交
2123
    taos_stmt_bind_param_batch(stmt, params + id * 5);
2124 2125 2126 2127 2128 2129 2130 2131 2132 2133
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2134
  unsigned long long endtime = taosGetTimestampUs();
2135 2136
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2137 2138 2139 2140 2141 2142
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2143 2144 2145 2146 2147 2148 2149 2150 2151

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
2152
int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) {
2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2165
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2166
  
wafwerar's avatar
wafwerar 已提交
2167
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2168

wafwerar's avatar
wafwerar 已提交
2169
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2170
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2171 2172 2173 2174

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2175 2176
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
D
stmt  
dapan1121 已提交
2272 2273
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
2274 2275 2276
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2277 2278
    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
2279 2280 2281
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2282 2283
    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
2284 2285 2286
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2287 2288
    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
2289
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2290
    tags[i+3].length = (uintptr_t *)lb;
2291 2292 2293
  }


D
stmt  
dapan1121 已提交
2294
  unsigned long long starttime = taosGetTimestampUs();
2295

D
stmt  
dapan1121 已提交
2296
  char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
2297 2298
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2299
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
2300 2301 2302 2303 2304 2305 2306
    return -1;
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2307
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

    taos_stmt_bind_param_batch(stmt, params + id * 10);
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2323
  unsigned long long endtime = taosGetTimestampUs();
2324 2325
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2326 2327 2328 2329 2330 2331
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2332 2333 2334 2335 2336 2337 2338

  return 0;
}




D
stmt  
dapan1121 已提交
2339

2340
//1 tables 10 records
D
stmt  
dapan1121 已提交
2341
int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) {
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2354
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2355
  
wafwerar's avatar
wafwerar 已提交
2356
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2357

wafwerar's avatar
wafwerar 已提交
2358
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2359
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2360 2361 2362 2363

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2364 2365
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
    tags[i+3].is_null = &one_not_null;
    tags[i+3].length = NULL;

    tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT;
    tags[i+4].buffer = v.v8;
    tags[i+4].is_null = &one_not_null;
    tags[i+4].length = NULL;

    tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+5].buffer = v.f4;
    tags[i+5].is_null = &one_not_null;
    tags[i+5].length = NULL;

    tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    tags[i+6].buffer = v.f8;
    tags[i+6].is_null = &one_not_null;
    tags[i+6].length = NULL;

    tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+7].buffer = v.bin;
    tags[i+7].is_null = &one_not_null;
    tags[i+7].length = (uintptr_t *)lb;

    tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR;
    tags[i+8].buffer = v.bin;
    tags[i+8].is_null = &one_not_null;
    tags[i+8].length = (uintptr_t *)lb;
  }


D
stmt  
dapan1121 已提交
2508
  unsigned long long starttime = taosGetTimestampUs();
2509 2510 2511 2512

  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2513
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
2514 2515 2516 2517 2518 2519 2520
    exit(1);
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2521
    code = taos_stmt_set_tbname_tags(stmt, buf, NULL);
2522
    if (code != 0){
D
stmt  
dapan1121 已提交
2523 2524
      printf("failed to execute taos_stmt_set_tbname_tags. code:%s\n", taos_stmt_errstr(stmt));
      return -1;
2525 2526
    }  

D
stmt  
dapan1121 已提交
2527
    taos_stmt_bind_param_batch(stmt, params + id * 10);
2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2538
  unsigned long long endtime = taosGetTimestampUs();
2539 2540
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2541 2542 2543 2544 2545 2546
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2547 2548 2549 2550 2551 2552 2553 2554 2555

  return 0;
}






D
stmt  
dapan1121 已提交
2556

2557
//1 tables 10 records
D
stmt  
dapan1121 已提交
2558
int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) {
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2571
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2572
  
wafwerar's avatar
wafwerar 已提交
2573
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2574

wafwerar's avatar
wafwerar 已提交
2575
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2576
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2577 2578 2579 2580

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2581 2582
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
    tags[i+3].is_null = &one_not_null;
    tags[i+3].length = NULL;

    tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT;
    tags[i+4].buffer = v.v8;
    tags[i+4].is_null = &one_not_null;
    tags[i+4].length = NULL;

    tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+5].buffer = v.f4;
    tags[i+5].is_null = &one_not_null;
    tags[i+5].length = NULL;

    tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    tags[i+6].buffer = v.f8;
    tags[i+6].is_null = &one_not_null;
    tags[i+6].length = NULL;

    tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+7].buffer = v.bin;
    tags[i+7].is_null = &one_not_null;
    tags[i+7].length = (uintptr_t *)lb;

    tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR;
    tags[i+8].buffer = v.bin;
    tags[i+8].is_null = &one_not_null;
    tags[i+8].length = (uintptr_t *)lb;
  }


D
stmt  
dapan1121 已提交
2725
  unsigned long long starttime = taosGetTimestampUs();
2726

D
stmt  
dapan1121 已提交
2727 2728
  char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
2729
  if (code != 0){
D
stmt  
dapan1121 已提交
2730
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt));
2731
    return -1;
D
stmt  
dapan1121 已提交
2732
    //exit(1);
2733 2734 2735 2736 2737 2738
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2739
    code = taos_stmt_set_tbname_tags(stmt, buf, NULL);
2740
    if (code != 0){
D
stmt  
dapan1121 已提交
2741 2742
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
      return -1;
2743 2744
    }  

D
stmt  
dapan1121 已提交
2745
    taos_stmt_bind_param_batch(stmt, params + id * 10);
2746 2747 2748 2749 2750 2751 2752 2753 2754 2755
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2756
  unsigned long long endtime = taosGetTimestampUs();
2757 2758
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2759 2760 2761 2762 2763 2764
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2765 2766 2767 2768 2769 2770

  return 0;
}



D
stmt  
dapan1121 已提交
2771 2772 2773

//1 tables 10 records
int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) {
2774 2775
  struct {
      int64_t *ts;
D
stmt  
dapan1121 已提交
2776 2777 2778 2779 2780 2781 2782 2783
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
2784 2785
  } v = {0};

D
stmt  
dapan1121 已提交
2786
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2787
  
D
stmt  
dapan1121 已提交
2788 2789 2790
  int *lb = taosMemoryMalloc(10 * sizeof(int));

  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2791
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
D
stmt  
dapan1121 已提交
2792 2793 2794

//  int one_null = 1;
  int one_not_null = 0;
2795
  
D
stmt  
dapan1121 已提交
2796 2797
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2798

D
stmt  
dapan1121 已提交
2799
  for (int i = 0; i < 10; ++i) {
2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
D
stmt  
dapan1121 已提交
2813
  for (int i = 0; i < 10; i+=10) {
2814 2815
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
D
stmt  
dapan1121 已提交
2816
    params[i+0].buffer = &v.ts[10*i/10];
2817 2818
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
D
stmt  
dapan1121 已提交
2819
    params[i+0].num = 10;
2820 2821 2822 2823 2824 2825
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
D
stmt  
dapan1121 已提交
2826
    params[i+1].num = 10;
2827 2828 2829 2830 2831 2832

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
D
stmt  
dapan1121 已提交
2833
    params[i+2].num = 10;
2834 2835 2836 2837 2838 2839

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
D
stmt  
dapan1121 已提交
2840
    params[i+3].num = 10;
2841 2842 2843 2844 2845 2846

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
D
stmt  
dapan1121 已提交
2847
    params[i+4].num = 10;
2848 2849 2850 2851 2852 2853

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
D
stmt  
dapan1121 已提交
2854
    params[i+5].num = 10;
2855 2856 2857 2858 2859 2860

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
D
stmt  
dapan1121 已提交
2861
    params[i+6].num = 10;
2862 2863 2864 2865 2866 2867

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
D
stmt  
dapan1121 已提交
2868
    params[i+7].num = 10;
2869 2870 2871 2872 2873 2874

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
D
stmt  
dapan1121 已提交
2875
    params[i+8].num = 10;
2876 2877 2878 2879 2880 2881

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
D
stmt  
dapan1121 已提交
2882
    params[i+9].num = 10;
2883 2884 2885 2886
    
  }

  int64_t tts = 1591060628000;
D
stmt  
dapan1121 已提交
2887
  for (int i = 0; i < 10; ++i) {
2888 2889 2890 2891
    v.ts[i] = tts + i;
  }


D
stmt  
dapan1121 已提交
2892 2893 2894 2895 2896
  for (int i = 0; i < 1; ++i) {
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;
2897

D
stmt  
dapan1121 已提交
2898 2899 2900 2901
    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;
2902

D
stmt  
dapan1121 已提交
2903 2904 2905 2906
    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;
2907

D
stmt  
dapan1121 已提交
2908 2909 2910 2911
    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
    tags[i+3].is_null = &one_not_null;
    tags[i+3].length = NULL;
2912

D
stmt  
dapan1121 已提交
2913 2914 2915 2916
    tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT;
    tags[i+4].buffer = v.v8;
    tags[i+4].is_null = &one_not_null;
    tags[i+4].length = NULL;
2917

D
stmt  
dapan1121 已提交
2918 2919 2920 2921
    tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+5].buffer = v.f4;
    tags[i+5].is_null = &one_not_null;
    tags[i+5].length = NULL;
2922

D
stmt  
dapan1121 已提交
2923 2924 2925 2926
    tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    tags[i+6].buffer = v.f8;
    tags[i+6].is_null = &one_not_null;
    tags[i+6].length = NULL;
2927

D
stmt  
dapan1121 已提交
2928 2929 2930 2931
    tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+7].buffer = v.bin;
    tags[i+7].is_null = &one_not_null;
    tags[i+7].length = (uintptr_t *)lb;
2932

D
stmt  
dapan1121 已提交
2933 2934 2935 2936
    tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR;
    tags[i+8].buffer = v.bin;
    tags[i+8].is_null = &one_not_null;
    tags[i+8].length = (uintptr_t *)lb;
2937 2938
  }

D
stmt  
dapan1121 已提交
2939

D
stmt  
dapan1121 已提交
2940
  unsigned long long starttime = taosGetTimestampUs();
2941

D
stmt  
dapan1121 已提交
2942
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
2943 2944
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2945 2946
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt));
    exit(1);
2947 2948 2949
  }

  int id = 0;
D
stmt  
dapan1121 已提交
2950 2951 2952 2953 2954 2955 2956 2957
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }  
2958

D
stmt  
dapan1121 已提交
2959 2960 2961 2962
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
2963
    }
D
stmt  
dapan1121 已提交
2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976
    
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
      return -1;
    }
    
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
2977 2978
  }

D
stmt  
dapan1121 已提交
2979 2980
  ++id;

D
stmt  
dapan1121 已提交
2981
  unsigned long long endtime = taosGetTimestampUs();
D
stmt  
dapan1121 已提交
2982
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));
2983

wafwerar's avatar
wafwerar 已提交
2984 2985 2986 2987 2988
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
2989
  taosMemoryFree(tags);
2990 2991 2992 2993 2994

  return 0;
}


D
stmt  
dapan1121 已提交
2995 2996 2997 2998 2999 3000




//1 tables 10 records
int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) {
3001 3002
  struct {
      int64_t *ts;
D
stmt  
dapan1121 已提交
3003 3004 3005 3006 3007 3008 3009 3010
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
3011 3012
  } v = {0};

D
stmt  
dapan1121 已提交
3013
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
3014
  
D
stmt  
dapan1121 已提交
3015 3016 3017
  int *lb = taosMemoryMalloc(10 * sizeof(int));

  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
3018
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
D
stmt  
dapan1121 已提交
3019 3020 3021

//  int one_null = 1;
  int one_not_null = 0;
3022
  
D
stmt  
dapan1121 已提交
3023 3024
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
3025

D
stmt  
dapan1121 已提交
3026
  for (int i = 0; i < 10; ++i) {
3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
D
stmt  
dapan1121 已提交
3040
  for (int i = 0; i < 10; i+=10) {
3041 3042
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
D
stmt  
dapan1121 已提交
3043
    params[i+0].buffer = &v.ts[10*i/10];
3044 3045
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
D
stmt  
dapan1121 已提交
3046
    params[i+0].num = 10;
3047 3048 3049 3050 3051 3052
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
D
stmt  
dapan1121 已提交
3053
    params[i+1].num = 10;
3054 3055 3056 3057 3058 3059

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
D
stmt  
dapan1121 已提交
3060
    params[i+2].num = 10;
3061 3062 3063 3064 3065 3066

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
D
stmt  
dapan1121 已提交
3067
    params[i+3].num = 10;
3068 3069 3070 3071 3072 3073

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
D
stmt  
dapan1121 已提交
3074
    params[i+4].num = 10;
3075 3076 3077 3078 3079 3080

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
D
stmt  
dapan1121 已提交
3081
    params[i+5].num = 10;
3082 3083 3084 3085 3086 3087

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
D
stmt  
dapan1121 已提交
3088
    params[i+6].num = 10;
3089 3090 3091 3092 3093 3094

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
D
stmt  
dapan1121 已提交
3095
    params[i+7].num = 10;
3096 3097 3098 3099 3100 3101

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
D
stmt  
dapan1121 已提交
3102
    params[i+8].num = 10;
3103 3104 3105 3106 3107 3108

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
D
stmt  
dapan1121 已提交
3109
    params[i+9].num = 10;
3110 3111 3112 3113
    
  }

  int64_t tts = 1591060628000;
D
stmt  
dapan1121 已提交
3114
  for (int i = 0; i < 10; ++i) {
3115 3116 3117
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166

  for (int i = 0; i < 1; ++i) {
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
    tags[i+3].is_null = &one_not_null;
    tags[i+3].length = NULL;

    tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT;
    tags[i+4].buffer = v.v8;
    tags[i+4].is_null = &one_not_null;
    tags[i+4].length = NULL;

    tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+5].buffer = v.f4;
    tags[i+5].is_null = &one_not_null;
    tags[i+5].length = NULL;

    tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    tags[i+6].buffer = v.f8;
    tags[i+6].is_null = &one_not_null;
    tags[i+6].length = NULL;

    tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+7].buffer = v.bin;
    tags[i+7].is_null = &one_not_null;
    tags[i+7].length = (uintptr_t *)lb;

    tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR;
    tags[i+8].buffer = v.bin;
    tags[i+8].is_null = &one_not_null;
    tags[i+8].length = (uintptr_t *)lb;
  }


D
stmt  
dapan1121 已提交
3167
  unsigned long long starttime = taosGetTimestampUs();
3168

D
stmt  
dapan1121 已提交
3169 3170
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(NULL, sql, 0);
3171
  if (code != 0){
D
stmt  
dapan1121 已提交
3172 3173
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(NULL));
    return -1;
3174 3175 3176
  }

  int id = 0;
D
stmt  
dapan1121 已提交
3177 3178 3179 3180 3181 3182 3183 3184
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }  
3185

D
stmt  
dapan1121 已提交
3186 3187 3188
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
3189 3190
      exit(1);
    }
D
stmt  
dapan1121 已提交
3191 3192 3193 3194 3195 3196 3197 3198 3199
    
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
      return -1;
    }
    
    taos_stmt_add_batch(stmt);
  }
3200

D
stmt  
dapan1121 已提交
3201 3202 3203
  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
3204 3205
  }

D
stmt  
dapan1121 已提交
3206 3207
  ++id;

D
stmt  
dapan1121 已提交
3208
  unsigned long long endtime = taosGetTimestampUs();
D
stmt  
dapan1121 已提交
3209
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));
3210

wafwerar's avatar
wafwerar 已提交
3211 3212 3213 3214 3215
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
3216
  taosMemoryFree(tags);
3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234

  return 0;
}

//samets
int stmt_funcb4(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int8_t b[60];
      int8_t v1[60];
      int16_t v2[60];
      int32_t v4[60];
      int64_t v8[60];
      float f4[60];
      double f8[60];
      char bin[60][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
3235
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3236
  
wafwerar's avatar
wafwerar 已提交
3237
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3238
  
D
dapan1121 已提交
3239
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3240 3241
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334

  for (int i = 0; i < 60; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 9000000; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[60*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 60;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 60;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 60;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 60;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 60;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 60;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 60;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 60;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 60;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 60;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 54000000; ++i) {
    v.ts[i] = tts;
  }

D
stmt  
dapan1121 已提交
3335
  unsigned long long starttime = taosGetTimestampUs();
3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364

  char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
  }

  int id = 0;
  for (int l = 0; l < 3000; l++) {
    for (int zz = 0; zz < 300; zz++) {
      char buf[32];
      sprintf(buf, "m%d", zz);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
        printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
      }  

      taos_stmt_bind_param_batch(stmt, params + id * 10);
      taos_stmt_add_batch(stmt);
    }
 
    if (taos_stmt_execute(stmt) != 0) {
      printf("failed to execute insert statement.\n");
      exit(1);
    }

    ++id;
  }

D
stmt  
dapan1121 已提交
3365
  unsigned long long endtime = taosGetTimestampUs();
3366 3367
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));

wafwerar's avatar
wafwerar 已提交
3368 3369 3370 3371 3372
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393

  return 0;
}




//1table 18000 reocrds
int stmt_funcb5(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int8_t b[18000];
      int8_t v1[18000];
      int16_t v2[18000];
      int32_t v4[18000];
      int64_t v8[18000];
      float f4[18000];
      double f8[18000];
      char bin[18000][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
3394
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3395
  
wafwerar's avatar
wafwerar 已提交
3396
  int *lb = taosMemoryMalloc(18000 * sizeof(int));
3397
  
D
dapan1121 已提交
3398
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10);
wafwerar's avatar
wafwerar 已提交
3399 3400
  char* is_null = taosMemoryMalloc(sizeof(char) * 18000);
  char* no_null = taosMemoryMalloc(sizeof(char) * 18000);
3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493

  for (int i = 0; i < 18000; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 30000; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[18000*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 18000;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 18000;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 18000;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 18000;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 18000;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 18000;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 18000;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 18000;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 18000;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 18000;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 54000000; ++i) {
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
3494
  unsigned long long starttime = taosGetTimestampUs();
3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517

  char *sql = "insert into m0 values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
  }

  int id = 0;
  for (int l = 0; l < 10; l++) {
    for (int zz = 0; zz < 1; zz++) {
      taos_stmt_bind_param_batch(stmt, params + id * 10);
      taos_stmt_add_batch(stmt);

      if (taos_stmt_execute(stmt) != 0) {
        printf("failed to execute insert statement.\n");
        exit(1);
      }
      ++id;

    }
 
  }

D
stmt  
dapan1121 已提交
3518
  unsigned long long endtime = taosGetTimestampUs();
3519 3520
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));

wafwerar's avatar
wafwerar 已提交
3521 3522 3523 3524 3525
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537

  return 0;
}


//1table 200000 reocrds
int stmt_funcb_ssz1(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int b[30000];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
3538
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 30000 * 3000);
3539
  
wafwerar's avatar
wafwerar 已提交
3540
  int *lb = taosMemoryMalloc(30000 * sizeof(int));
3541
  
D
dapan1121 已提交
3542
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10);
wafwerar's avatar
wafwerar 已提交
3543
  char* no_null = taosMemoryMalloc(sizeof(int) * 200000);
3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571

  for (int i = 0; i < 30000; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    v.b[i] = (int8_t)(i % 2);
  }
  
  for (int i = 0; i < 30000; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[30000*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 30000;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+1].buffer_length = sizeof(int);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = no_null;
    params[i+1].num = 30000;
  }

  int64_t tts = 0;
  for (int64_t i = 0; i < 90000000LL; ++i) {
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
3572
  unsigned long long starttime = taosGetTimestampUs();
3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602

  char *sql = "insert into ? values(?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
  }

  int id = 0;
  for (int l = 0; l < 10; l++) {
    for (int zz = 0; zz < 300; zz++) {
      char buf[32];
      sprintf(buf, "m%d", zz);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
        printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
      }  

      taos_stmt_bind_param_batch(stmt, params + id * 10);
      taos_stmt_add_batch(stmt);

      if (taos_stmt_execute(stmt) != 0) {
        printf("failed to execute insert statement.\n");
        exit(1);
      }
      ++id;

    }
 
  }

D
stmt  
dapan1121 已提交
3603
  unsigned long long endtime = taosGetTimestampUs();
3604 3605
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));

wafwerar's avatar
wafwerar 已提交
3606 3607 3608 3609
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(no_null);
3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628

  return 0;
}


//one table 60 records one time
int stmt_funcb_s1(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int8_t b[60];
      int8_t v1[60];
      int16_t v2[60];
      int32_t v4[60];
      int64_t v8[60];
      float f4[60];
      double f8[60];
      char bin[60][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
3629
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3630
  
wafwerar's avatar
wafwerar 已提交
3631
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3632
  
D
dapan1121 已提交
3633
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3634 3635
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728

  for (int i = 0; i < 60; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 9000000; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[60*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 60;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 60;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 60;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 60;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 60;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 60;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 60;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 60;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 60;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 60;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 54000000; ++i) {
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
3729
  unsigned long long starttime = taosGetTimestampUs();
3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759

  char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
  }

  int id = 0;
  for (int l = 0; l < 3000; l++) {
    for (int zz = 0; zz < 300; zz++) {
      char buf[32];
      sprintf(buf, "m%d", zz);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
        printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
      }  

      taos_stmt_bind_param_batch(stmt, params + id * 10);
      taos_stmt_add_batch(stmt);

      if (taos_stmt_execute(stmt) != 0) {
        printf("failed to execute insert statement.\n");
        exit(1);
      }
      
      ++id;
    }
 
  }

D
stmt  
dapan1121 已提交
3760
  unsigned long long endtime = taosGetTimestampUs();
3761 3762
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));

wafwerar's avatar
wafwerar 已提交
3763 3764 3765 3766 3767
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790

  return 0;
}






//300 tables 60 records single column bind
int stmt_funcb_sc1(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int8_t b[60];
      int8_t v1[60];
      int16_t v2[60];
      int32_t v4[60];
      int64_t v8[60];
      float f4[60];
      double f8[60];
      char bin[60][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
3791
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3792
  
wafwerar's avatar
wafwerar 已提交
3793
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3794
  
D
dapan1121 已提交
3795
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3796 3797
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890

  for (int i = 0; i < 60; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 9000000; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[60*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 60;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 60;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 60;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 60;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 60;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 60;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 60;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 60;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 60;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 60;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 54000000; ++i) {
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
3891
  unsigned long long starttime = taosGetTimestampUs();
3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921

  char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
  }

  int id = 0;
  for (int l = 0; l < 3000; l++) {
    for (int zz = 0; zz < 300; zz++) {
      char buf[32];
      sprintf(buf, "m%d", zz);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
        printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
      }  

      for (int col=0; col < 10; ++col) {
        taos_stmt_bind_single_param_batch(stmt, params + id++, col);
      }
      
      taos_stmt_add_batch(stmt);
    }
 
    if (taos_stmt_execute(stmt) != 0) {
      printf("failed to execute insert statement.\n");
      exit(1);
    }
  }

D
stmt  
dapan1121 已提交
3922
  unsigned long long endtime = taosGetTimestampUs();
3923 3924
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));

wafwerar's avatar
wafwerar 已提交
3925 3926 3927 3928 3929
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948

  return 0;
}


//1 tables 60 records single column bind
int stmt_funcb_sc2(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int8_t b[60];
      int8_t v1[60];
      int16_t v2[60];
      int32_t v4[60];
      int64_t v8[60];
      float f4[60];
      double f8[60];
      char bin[60][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
3949
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3950
  
wafwerar's avatar
wafwerar 已提交
3951
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3952
  
D
dapan1121 已提交
3953
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3954 3955
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048

  for (int i = 0; i < 60; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 9000000; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[60*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 60;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 60;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 60;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 60;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 60;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 60;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 60;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 60;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 60;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 60;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 54000000; ++i) {
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
4049
  unsigned long long starttime = taosGetTimestampUs();
4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081

  char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
  }

  int id = 0;
  for (int l = 0; l < 3000; l++) {
    for (int zz = 0; zz < 300; zz++) {
      char buf[32];
      sprintf(buf, "m%d", zz);
      code = taos_stmt_set_tbname(stmt, buf);
      if (code != 0){
        printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
      }  

      for (int col=0; col < 10; ++col) {
        taos_stmt_bind_single_param_batch(stmt, params + id++, col);
      }
      
      taos_stmt_add_batch(stmt);

      if (taos_stmt_execute(stmt) != 0) {
        printf("failed to execute insert statement.\n");
        exit(1);
      }

    }
 
  }

D
stmt  
dapan1121 已提交
4082
  unsigned long long endtime = taosGetTimestampUs();
4083 4084
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));

wafwerar's avatar
wafwerar 已提交
4085 4086 4087 4088 4089
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108

  return 0;
}


//10 tables [1...10] records single column bind
int stmt_funcb_sc3(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int8_t b[60];
      int8_t v1[60];
      int16_t v2[60];
      int32_t v4[60];
      int64_t v8[60];
      float f4[60];
      double f8[60];
      char bin[60][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
4109
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 60);
4110
  
wafwerar's avatar
wafwerar 已提交
4111
  int *lb = taosMemoryMalloc(60 * sizeof(int));
4112
  
D
dapan1121 已提交
4113
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 60*10);
wafwerar's avatar
wafwerar 已提交
4114 4115
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209

  for (int i = 0; i < 60; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }

  int g = 0;
  for (int i = 0; i < 600; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = g%10+1;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = g%10+1;
    
    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = g%10+1;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = g%10+1;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = g%10+1;
    
    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = g%10+1;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = g%10+1;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = g%10+1;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = g%10+1;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = g%10+1;
    ++g;
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 60; ++i) {
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
4210
  unsigned long long starttime = taosGetTimestampUs();
4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238

  char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
  }

  int id = 0;
  for (int zz = 0; zz < 10; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname(stmt, buf);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
    }  

    for (int col=0; col < 10; ++col) {
      taos_stmt_bind_single_param_batch(stmt, params + id++, col);
    }
    
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

D
stmt  
dapan1121 已提交
4239
  unsigned long long endtime = taosGetTimestampUs();
4240 4241
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));

wafwerar's avatar
wafwerar 已提交
4242 4243 4244 4245 4246
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
4247 4248 4249

  return 0;
}
D
stmt  
dapan1121 已提交
4250
#endif
4251 4252


D
dapan1121 已提交
4253 4254 4255 4256
void prepareCheckResultImpl(TAOS     * taos, char *tname, bool printr, int expected, bool silent) {
  char sql[255] = "SELECT * FROM ";
  int32_t rows = 0;
  
4257
  strcat(sql, tname);
D
dapan1121 已提交
4258
  bpExecQuery(taos, sql, printr, &rows);
4259 4260
  
  if (rows == expected) {
D
dapan1121 已提交
4261
    if (!silent) {
D
dapan1121 已提交
4262
      printf("***%d rows are fetched as expected from %s\n", rows, tname);
D
dapan1121 已提交
4263
    }
4264
  } else {
D
dapan1121 已提交
4265
    printf("!!!expect rows %d mis-match rows %d fetched from %s\n", expected, rows, tname);
4266 4267 4268 4269 4270
    exit(1);
  }
}


D
dapan1121 已提交
4271
void prepareCheckResult(TAOS     *taos, bool silent) {
D
stmt  
dapan1121 已提交
4272 4273 4274
  char buf[32];
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
D
dapan1121 已提交
4275
      sprintf(buf, "%s%d", bpTbPrefix, t);
D
stmt  
dapan1121 已提交
4276
    } else {
D
dapan1121 已提交
4277
      sprintf(buf, "%s%d", bpTbPrefix, 0);
D
stmt  
dapan1121 已提交
4278 4279
    }

D
dapan1121 已提交
4280
    prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes, silent);
D
stmt  
dapan1121 已提交
4281
  }
D
stmt  
dapan1121 已提交
4282 4283

  gExecLoopTimes = 1;
D
stmt  
dapan1121 已提交
4284 4285 4286
}


4287 4288 4289 4290 4291 4292 4293

//120table 60 record each table
int sql_perf1(TAOS     *taos) {
  char *sql[3000] = {0};
  TAOS_RES *result;

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
4294
    sql[i] = taosMemoryCalloc(1, 1048576);
4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309
  }

  int len = 0;
  int tss = 0;
  for (int l = 0; l < 3000; ++l) {
    len = sprintf(sql[l], "insert into ");
    for (int t = 0; t < 120; ++t) {
      len += sprintf(sql[l] + len, "m%d values ", t);
      for (int m = 0; m < 60; ++m) {
        len += sprintf(sql[l] + len, "(%d, %d, %d, %d, %d, %d, %f, %f, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") ", tss++, m, m, m, m, m, m+1.0, m+1.0);
      }
    }
  }


D
stmt  
dapan1121 已提交
4310
  int64_t starttime = taosGetTimestampUs();
4311 4312 4313 4314
  for (int i = 0; i < 3000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
4315
        printf("%d failed to query table, reason:%s\n", taos_errstr(result));
4316 4317 4318 4319 4320 4321
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
4322
  int64_t endtime = taosGetTimestampUs();
4323 4324 4325
  printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
4326
    taosMemoryFree(sql[i]);
4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337
  }

  return 0;
}





//one table 60 records one time
int sql_perf_s1(TAOS     *taos) {
D
stmt  
dapan1121 已提交
4338
  char **sql = calloc(1, sizeof(char*) * 360000);
4339 4340 4341
  TAOS_RES *result;

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
4342
    sql[i] = taosMemoryCalloc(1, 9000);
4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362
  }

  int len = 0;
  int tss = 0;
  int id = 0;
  for (int t = 0; t < 120; ++t) {
    for (int l = 0; l < 3000; ++l) {
      len = sprintf(sql[id], "insert into m%d values ", t);
      for (int m = 0; m < 60; ++m) {
        len += sprintf(sql[id] + len, "(%d, %d, %d, %d, %d, %d, %f, %f, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") ", tss++, m, m, m, m, m, m+1.0, m+1.0);
      }
      if (len >= 9000) {
        printf("sql:%s,len:%d\n", sql[id], len);
        exit(1);
      }
      ++id;
    }
  }


D
stmt  
dapan1121 已提交
4363
  unsigned long long starttime = taosGetTimestampUs();
4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374
  for (int i = 0; i < 360000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
        printf("failed to query table, reason:%s\n", taos_errstr(result));
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
4375
  unsigned long long endtime = taosGetTimestampUs();
4376 4377 4378
  printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
4379
    taosMemoryFree(sql[i]);
4380 4381
  }

wafwerar's avatar
wafwerar 已提交
4382
  taosMemoryFree(sql);
4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393

  return 0;
}


//small record size
int sql_s_perf1(TAOS     *taos) {
  char *sql[3000] = {0};
  TAOS_RES *result;

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
4394
    sql[i] = taosMemoryCalloc(1, 1048576);
4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409
  }

  int len = 0;
  int tss = 0;
  for (int l = 0; l < 3000; ++l) {
    len = sprintf(sql[l], "insert into ");
    for (int t = 0; t < 120; ++t) {
      len += sprintf(sql[l] + len, "m%d values ", t);
      for (int m = 0; m < 60; ++m) {
        len += sprintf(sql[l] + len, "(%d, %d) ", tss++, m%2);
      }
    }
  }


D
stmt  
dapan1121 已提交
4410
  unsigned long long starttime = taosGetTimestampUs();
4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421
  for (int i = 0; i < 3000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
        printf("failed to query table, reason:%s\n", taos_errstr(result));
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
4422
  unsigned long long endtime = taosGetTimestampUs();
4423 4424 4425
  printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
4426
    taosMemoryFree(sql[i]);
4427 4428 4429 4430 4431
  }

  return 0;
}

D
stmt  
dapan1121 已提交
4432 4433
void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) {
  int32_t blen = 0;
D
dapan1121 已提交
4434
  blen = sprintf(buf, "create table %s%d ", (stable ? bpStbPrefix : bpTbPrefix), tblIdx);
D
stmt  
dapan1121 已提交
4435 4436 4437
  if (stable) {
    blen += sprintf(buf + blen, "tags (");
    for (int c = 0; c < colNum; ++c) {
D
stmt  
dapan1121 已提交
4438 4439 4440
      if (c > 0) {
        blen += sprintf(buf + blen, ",");
      }
D
stmt  
dapan1121 已提交
4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495
      switch (colList[c]) {  
        case TSDB_DATA_TYPE_BOOL:
          blen += sprintf(buf + blen, "tbooldata bool");
          break;
        case TSDB_DATA_TYPE_TINYINT:
          blen += sprintf(buf + blen, "ttinydata tinyint");
          break;
        case TSDB_DATA_TYPE_SMALLINT:
          blen += sprintf(buf + blen, "tsmalldata smallint");
          break;
        case TSDB_DATA_TYPE_INT:
          blen += sprintf(buf + blen, "tintdata int");
          break;
        case TSDB_DATA_TYPE_BIGINT:
          blen += sprintf(buf + blen, "tbigdata bigint");
          break;
        case TSDB_DATA_TYPE_FLOAT:
          blen += sprintf(buf + blen, "tfloatdata float");
          break;
        case TSDB_DATA_TYPE_DOUBLE:
          blen += sprintf(buf + blen, "tdoubledata double");
          break;
        case TSDB_DATA_TYPE_VARCHAR:
          blen += sprintf(buf + blen, "tbinarydata binary(%d)", gVarCharSize);
          break;
        case TSDB_DATA_TYPE_TIMESTAMP:
          blen += sprintf(buf + blen, "tts ts");
          break;
        case TSDB_DATA_TYPE_NCHAR:
          blen += sprintf(buf + blen, "tnchardata nchar(%d)", gVarCharSize);
          break;
        case TSDB_DATA_TYPE_UTINYINT:
          blen += sprintf(buf + blen, "tutinydata tinyint unsigned");
          break;
        case TSDB_DATA_TYPE_USMALLINT:
          blen += sprintf(buf + blen, "tusmalldata smallint unsigned");
          break;
        case TSDB_DATA_TYPE_UINT:
          blen += sprintf(buf + blen, "tuintdata int unsigned");
          break;
        case TSDB_DATA_TYPE_UBIGINT:
          blen += sprintf(buf + blen, "tubigdata bigint unsigned");
          break;
        default:
          printf("invalid col type:%d", colList[c]);
          exit(1);
      }      
    }

    blen += sprintf(buf + blen, ")");    
  }

  blen += sprintf(buf + blen, " (");
  
  for (int c = 0; c < colNum; ++c) {
D
stmt  
dapan1121 已提交
4496 4497 4498 4499
    if (c > 0) {
      blen += sprintf(buf + blen, ",");
    }
  
D
stmt  
dapan1121 已提交
4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525
    switch (colList[c]) {  
      case TSDB_DATA_TYPE_BOOL:
        blen += sprintf(buf + blen, "booldata bool");
        break;
      case TSDB_DATA_TYPE_TINYINT:
        blen += sprintf(buf + blen, "tinydata tinyint");
        break;
      case TSDB_DATA_TYPE_SMALLINT:
        blen += sprintf(buf + blen, "smalldata smallint");
        break;
      case TSDB_DATA_TYPE_INT:
        blen += sprintf(buf + blen, "intdata int");
        break;
      case TSDB_DATA_TYPE_BIGINT:
        blen += sprintf(buf + blen, "bigdata bigint");
        break;
      case TSDB_DATA_TYPE_FLOAT:
        blen += sprintf(buf + blen, "floatdata float");
        break;
      case TSDB_DATA_TYPE_DOUBLE:
        blen += sprintf(buf + blen, "doubledata double");
        break;
      case TSDB_DATA_TYPE_VARCHAR:
        blen += sprintf(buf + blen, "binarydata binary(%d)", gVarCharSize);
        break;
      case TSDB_DATA_TYPE_TIMESTAMP:
D
stmt  
dapan1121 已提交
4526
        blen += sprintf(buf + blen, "ts timestamp");
D
stmt  
dapan1121 已提交
4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549
        break;
      case TSDB_DATA_TYPE_NCHAR:
        blen += sprintf(buf + blen, "nchardata nchar(%d)", gVarCharSize);
        break;
      case TSDB_DATA_TYPE_UTINYINT:
        blen += sprintf(buf + blen, "utinydata tinyint unsigned");
        break;
      case TSDB_DATA_TYPE_USMALLINT:
        blen += sprintf(buf + blen, "usmalldata smallint unsigned");
        break;
      case TSDB_DATA_TYPE_UINT:
        blen += sprintf(buf + blen, "uintdata int unsigned");
        break;
      case TSDB_DATA_TYPE_UBIGINT:
        blen += sprintf(buf + blen, "ubigdata bigint unsigned");
        break;
      default:
        printf("invalid col type:%d", colList[c]);
        exit(1);
    }      
  }

  blen += sprintf(buf + blen, ")");
D
stmt  
dapan1121 已提交
4550

D
stmt  
dapan1121 已提交
4551
  if (gCaseCtrl.printCreateTblSql) {
D
dapan1121 已提交
4552
    printf("\tCreate Table SQL:%s\n", buf);
D
stmt  
dapan1121 已提交
4553
  }
D
stmt  
dapan1121 已提交
4554
}
4555

D
dapan1121 已提交
4556
void prepare(TAOS     *taos, int32_t colNum, int32_t *colList, int prepareStb) {
4557 4558 4559 4560 4561 4562 4563 4564 4565
  TAOS_RES *result;
  int      code;

  result = taos_query(taos, "drop database demo"); 
  taos_free_result(result);

  result = taos_query(taos, "create database demo keep 36500");
  code = taos_errno(result);
  if (code != 0) {
D
dapan1121 已提交
4566
    printf("!!!failed to create database, reason:%s\n", taos_errstr(result));
4567 4568 4569 4570 4571 4572 4573 4574
    taos_free_result(result);
    exit(1);
  }
  taos_free_result(result);

  result = taos_query(taos, "use demo");
  taos_free_result(result);

D
dapan1121 已提交
4575
  if (!prepareStb) {
4576
    // create table
D
stmt  
dapan1121 已提交
4577
    for (int i = 0 ; i < 10; i++) {
4578
      char buf[1024];
D
stmt  
dapan1121 已提交
4579
      generateCreateTableSQL(buf, i, colNum, colList, false);
4580 4581 4582
      result = taos_query(taos, buf);
      code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
4583
        printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
4584 4585 4586 4587 4588 4589 4590
        taos_free_result(result);
        exit(1);
      }
      taos_free_result(result);
    }
  } else {
    char buf[1024];
D
stmt  
dapan1121 已提交
4591
    generateCreateTableSQL(buf, 1, colNum, colList, true);
4592 4593 4594 4595
    
    result = taos_query(taos, buf);
    code = taos_errno(result);
    if (code != 0) {
D
dapan1121 已提交
4596
      printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
4597 4598 4599 4600 4601 4602 4603 4604
      taos_free_result(result);
      exit(1);
    }
    taos_free_result(result);
  }

}

D
dapan1121 已提交
4605
int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) {
D
stmt  
dapan1121 已提交
4606
  TAOS_STMT *stmt = NULL;
D
dapan1121 已提交
4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622
  int64_t beginUs, endUs, totalUs;  
  CaseCfg cfg = gCase[caseIdx];
  gCurCase = &cfg;
  
  if ((gCaseCtrl.bindColTypeNum || gCaseCtrl.bindColNum) && (gCurCase->colNum != gFullColNum)) {
    return 1;
  }

  if (gCurCase->preCaseIdx >= 0) {
    bool printRes = gCaseCtrl.printRes;
    bool printStmtSql = gCaseCtrl.printStmtSql;
    gCaseCtrl.printRes = false;
    gCaseCtrl.printStmtSql = false;
    runCase(taos, gCurCase->preCaseIdx, caseRunIdx, true);
    gCaseCtrl.printRes = printRes;
    gCaseCtrl.printStmtSql = printStmtSql;
D
dapan1121 已提交
4623
    
D
stmt  
dapan1121 已提交
4624
    gCurCase = &cfg;
D
dapan1121 已提交
4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651
  }
  
  if (gCaseCtrl.runTimes) {
    gCurCase->runTimes = gCaseCtrl.runTimes;
  }
  
  if (gCaseCtrl.rowNum) {
    gCurCase->rowNum = gCaseCtrl.rowNum;
  }
  
  if (gCurCase->fullCol) {
    gCurCase->bindColNum = gCurCase->colNum;
  }
  
  gCurCase->bindNullNum = gCaseCtrl.bindNullNum;
  gCurCase->prepareStb = gCaseCtrl.prepareStb;
  if (gCaseCtrl.bindColNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColNum;
    gCurCase->fullCol = false;
  }
  if (gCaseCtrl.bindRowNum) {
    gCurCase->bindRowNum = gCaseCtrl.bindRowNum;
  }
  if (gCaseCtrl.bindColTypeNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColTypeNum;
    gCurCase->fullCol = false;
  }
D
stmt  
dapan1121 已提交
4652

D
dapan1121 已提交
4653 4654 4655 4656 4657 4658 4659 4660
  if (!silent) {
    printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc);
  }
  
  totalUs = 0;
  for (int32_t n = 0; n < gCurCase->runTimes; ++n) {
    if (gCurCase->preCaseIdx < 0) {
      prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->prepareStb);
D
stmt  
dapan1121 已提交
4661 4662
    }
    
D
dapan1121 已提交
4663 4664 4665 4666
    beginUs = taosGetTimestampUs();
   
    stmt = taos_stmt_init(taos);
    if (NULL == stmt) {
D
dapan1121 已提交
4667
      printf("!!!taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
4668
      exit(1);
D
stmt  
dapan1121 已提交
4669
    }
D
dapan1121 已提交
4670 4671 4672 4673 4674 4675 4676
  
    (*gCurCase->runFn)(stmt, taos);
  
    taos_stmt_close(stmt);
  
    endUs = taosGetTimestampUs();
    totalUs += (endUs - beginUs);
D
dapan1121 已提交
4677

D
dapan1121 已提交
4678 4679
    prepareCheckResult(taos, silent);
  }
D
dapan1121 已提交
4680

D
dapan1121 已提交
4681 4682 4683 4684 4685 4686
  if (!silent) {  
    printf("* Case %d - [%s]%s [AvgTime:%.3fms] End *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc, ((double)totalUs)/1000/gCurCase->runTimes);
  }
  
  return 0;
}
D
dapan1121 已提交
4687

D
dapan1121 已提交
4688 4689 4690 4691 4692
void* runCaseList(TAOS *taos) {
  static int32_t caseRunIdx = 0;
  static int32_t caseRunNum = 0;
  int32_t caseNum = 0;
  int32_t caseIdx = (gCaseCtrl.caseIdx >= 0) ? gCaseCtrl.caseIdx : 0;
4693

D
dapan1121 已提交
4694 4695 4696 4697
  for (int32_t i = caseIdx; i < sizeof(gCase)/sizeof(gCase[0]); ++i) {
    if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) {
      break;
    }
4698

D
dapan1121 已提交
4699 4700 4701
    if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) {
      break;
    }
D
dapan1121 已提交
4702

D
dapan1121 已提交
4703 4704 4705 4706
    if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) {
      caseRunIdx++;
      continue;
    }
D
dapan1121 已提交
4707

D
dapan1121 已提交
4708 4709
    if (runCase(taos, i, caseRunIdx, false)) {
      continue;
4710
    }
D
stmt  
dapan1121 已提交
4711

D
dapan1121 已提交
4712 4713
    caseRunIdx++;
    caseNum++;
D
dapan1121 已提交
4714
    caseRunNum++;
D
stmt  
dapan1121 已提交
4715
  }
4716

D
stmt  
dapan1121 已提交
4717 4718
  return NULL;
}
D
stmt  
dapan1121 已提交
4719

D
stmt  
dapan1121 已提交
4720
void runAll(TAOS *taos) {
D
dapan1121 已提交
4721 4722
  strcpy(gCaseCtrl.caseCatalog, "Normal Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
dapan1121 已提交
4723
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4724

D
dapan1121 已提交
4725 4726
  strcpy(gCaseCtrl.caseCatalog, "Null Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4727
  gCaseCtrl.bindNullNum = 1;
D
dapan1121 已提交
4728
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4729
  gCaseCtrl.bindNullNum = 0;
D
stmt  
dapan1121 已提交
4730

D
dapan1121 已提交
4731 4732
  strcpy(gCaseCtrl.caseCatalog, "Bind Row Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4733
  gCaseCtrl.bindRowNum = 1;
D
dapan1121 已提交
4734
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4735
  gCaseCtrl.bindRowNum = 0;
D
stmt  
dapan1121 已提交
4736

D
dapan1121 已提交
4737 4738
  strcpy(gCaseCtrl.caseCatalog, "Row Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4739
  gCaseCtrl.rowNum = 1000;
D
stmt  
dapan1121 已提交
4740
  gCaseCtrl.printRes = false;
D
dapan1121 已提交
4741
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4742 4743
  gCaseCtrl.rowNum = 0;
  gCaseCtrl.printRes = true;
D
stmt  
dapan1121 已提交
4744

D
dapan1121 已提交
4745 4746
  strcpy(gCaseCtrl.caseCatalog, "Runtimes Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4747
  gCaseCtrl.runTimes = 2;
D
dapan1121 已提交
4748
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4749
  gCaseCtrl.runTimes = 0;
4750

D
dapan1121 已提交
4751 4752
  strcpy(gCaseCtrl.caseCatalog, "Check Param Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4753
  gCaseCtrl.checkParamNum = true;
D
dapan1121 已提交
4754
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4755
  gCaseCtrl.checkParamNum = false;
4756

D
dapan1121 已提交
4757 4758
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4759
  gCaseCtrl.bindColNum = 6;
D
dapan1121 已提交
4760
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4761
  gCaseCtrl.bindColNum = 0;
4762

D
dapan1121 已提交
4763 4764
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4765
  gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList);
D
stmt  
dapan1121 已提交
4766
  gCaseCtrl.bindColTypeList = bindColTypeList;  
D
dapan1121 已提交
4767
  runCaseList(taos);
D
dapan1121 已提交
4768 4769
  
  printf("All Test End\n");  
4770 4771 4772 4773
}

int main(int argc, char *argv[])
{
D
stmt  
dapan1121 已提交
4774
  TAOS     *taos = NULL;
4775

D
stmt  
dapan1121 已提交
4776 4777
  srand(time(NULL));
  
4778 4779 4780 4781 4782 4783
  // connect to server
  if (argc < 2) {
    printf("please input server ip \n");
    return 0;
  }

D
stmt  
dapan1121 已提交
4784
  taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
4785 4786 4787 4788 4789
  if (taos == NULL) {
    printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
    exit(1);
  }   

D
stmt  
dapan1121 已提交
4790
  runAll(taos);
4791 4792 4793 4794

  return 0;
}