batchprepare.c 134.6 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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP};

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},  
  {"nmake",    2, false},  
};

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 已提交
47 48 49

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

50
typedef struct {
D
stmt  
dapan1121 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  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 已提交
66
  TAOS_MULTI_BIND* pBind;
D
stmt  
dapan1121 已提交
67 68 69 70 71 72 73 74
  char*         sql;
  int32_t*      colTypes;
  int32_t       colNum;
} BindData;

int32_t gVarCharSize = 10;
int32_t gVarCharLen = 5;

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

D
dapan1121 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90
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 已提交
91 92 93 94

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

CaseCfg gCase[] = {
D
dapan1121 已提交
110 111 112 113 114 115 116 117 118 119
  {"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 已提交
120

D
dapan1121 已提交
121 122 123
  {"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 已提交
124

D
dapan1121 已提交
125 126 127 128
  // 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 已提交
129

D
dapan1121 已提交
130 131 132
  {"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 已提交
133

D
dapan1121 已提交
134 135 136
  {"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 已提交
137

D
dapan1121 已提交
138 139
  {"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 已提交
140

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

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

D
stmt  
dapan1121 已提交
146 147 148
};

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

typedef struct {
D
dapan1121 已提交
151
  char     caseCatalog[255];
D
stmt  
dapan1121 已提交
152
  int32_t  bindNullNum;
D
dapan1121 已提交
153
  bool     prepareStb;
D
stmt  
dapan1121 已提交
154
  bool     checkParamNum;
D
stmt  
dapan1121 已提交
155
  bool     printRes;
D
stmt  
dapan1121 已提交
156
  bool     printCreateTblSql;
D
dapan1121 已提交
157 158
  bool     printQuerySql;
  bool     printStmtSql;
D
stmt  
dapan1121 已提交
159
  int32_t  rowNum;               //row num for one table
D
stmt  
dapan1121 已提交
160
  int32_t  bindColNum;
D
stmt  
dapan1121 已提交
161
  int32_t  bindRowNum;           //row num for once bind
D
stmt  
dapan1121 已提交
162 163
  int32_t  bindColTypeNum;
  int32_t* bindColTypeList;
D
stmt  
dapan1121 已提交
164
  int32_t  runTimes;
D
dapan1121 已提交
165 166 167 168
  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 已提交
169 170
} CaseCtrl;

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

  .bindColTypeNum = tListLen(bindColTypeList),
  .bindColTypeList = bindColTypeList,
D
dapan1121 已提交
193
  .caseIdx = 22,
D
dapan1121 已提交
194 195 196 197 198
  .caseNum = 1,
  .caseRunNum = 1,

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

D
dapan1121 已提交
219 220
#endif

D
stmt  
dapan1121 已提交
221 222
int32_t taosGetTimeOfDay(struct timeval *tv) {
  return gettimeofday(tv, NULL);
223
}
D
stmt  
dapan1121 已提交
224
void *taosMemoryMalloc(uint64_t size) {
D
stmt  
dapan1121 已提交
225 226 227
  return malloc(size);
}

D
stmt  
dapan1121 已提交
228 229 230 231 232
void *taosMemoryCalloc(int32_t num, int32_t size) {
  return calloc(num, size);
}
void taosMemoryFree(const void *ptr) {
  if (ptr == NULL) return;
233

D
stmt  
dapan1121 已提交
234 235
  return free((void*)ptr);
}
236

D
stmt  
dapan1121 已提交
237 238 239 240 241 242
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 已提交
243 244 245 246 247
static int64_t taosGetTimestampUs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
  return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
}
248

D
dapan1121 已提交
249
bool colExists(TAOS_MULTI_BIND* pBind, int32_t dataType) {
D
stmt  
dapan1121 已提交
250 251 252 253 254 255 256 257 258
  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 已提交
259

D
stmt  
dapan1121 已提交
260 261 262 263
    ++i;
  }
}

D
stmt  
dapan1121 已提交
264
void generateInsertSQL(BindData *data) {
D
dapan1121 已提交
265 266 267 268 269 270
  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 已提交
271 272 273 274 275 276 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 327 328 329 330 331 332 333 334 335 336
  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:
          printf("invalid col type:%d", data->pBind[c].buffer_type);
          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 已提交
337

D
dapan1121 已提交
338
  if (gCaseCtrl.printStmtSql) {
D
stmt  
dapan1121 已提交
339 340
    printf("SQL: %s\n", data->sql);
  }  
D
stmt  
dapan1121 已提交
341
}
D
stmt  
dapan1121 已提交
342

D
dapan1121 已提交
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 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 427 428 429 430
void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType) {
  OperInfo *pInfo = NULL;
  
  if (TSDB_DATA_TYPE_VARCHAR == dataType || TSDB_DATA_TYPE_NCHAR == dataType) {
    pInfo = &operInfo[varoperatorList[rand() % tListLen(varoperatorList)]];
  } else {
    pInfo = &operInfo[operatorList[rand() % tListLen(operatorList)]];
  }

  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:
      printf("invalid paramNum:%d\n", pInfo->paramNum);
      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:
          printf("invalid col type:%d", data->pBind[c].buffer_type);
          exit(1);
      }
      
      bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type);
    }
  }

  if (gCaseCtrl.printStmtSql) {
    printf("SQL: %s\n", data->sql);
  }  
}


D
stmt  
dapan1121 已提交
431 432
void generateDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) {
  if (bindIdx < gCurCase->bindColNum) {
D
stmt  
dapan1121 已提交
433
    if (gCaseCtrl.bindColTypeNum) {
D
stmt  
dapan1121 已提交
434 435
      *dataType = gCaseCtrl.bindColTypeList[colIdx];
      return;
D
stmt  
dapan1121 已提交
436 437 438
    } else if (gCurCase->fullCol) {
      *dataType = gCurCase->colList[bindIdx];
      return;
D
stmt  
dapan1121 已提交
439 440 441 442
    } else if (0 == colIdx) {
      *dataType = TSDB_DATA_TYPE_TIMESTAMP;
      return;
    } else {
D
stmt  
dapan1121 已提交
443 444 445 446 447 448 449
      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 已提交
450

D
stmt  
dapan1121 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
        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 已提交
473
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
474 475 476 477 478
      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 已提交
479
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
480 481 482 483 484
      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 已提交
485
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
486 487 488 489 490
      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 已提交
491
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
492 493 494 495 496
      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 已提交
497
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
498 499 500 501 502
      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 已提交
503
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
504 505 506 507 508
      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 已提交
509
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
510 511 512
      break;
    case TSDB_DATA_TYPE_VARCHAR:
      data->pBind[bindIdx].buffer_length = gVarCharSize;
D
stmt  
dapan1121 已提交
513
      data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
D
stmt  
dapan1121 已提交
514
      data->pBind[bindIdx].length = data->binaryLen;
D
stmt  
dapan1121 已提交
515
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
516 517 518 519 520 521 522 523 524
      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 已提交
525
      data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
D
stmt  
dapan1121 已提交
526
      data->pBind[bindIdx].length = data->binaryLen;
D
stmt  
dapan1121 已提交
527
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
528 529 530 531 532
      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 已提交
533
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
534 535 536 537 538
      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 已提交
539
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
540 541 542 543 544
      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 已提交
545
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
546 547 548 549 550
      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 已提交
551
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
552 553 554 555 556 557 558 559 560 561 562 563 564
      break;
    default:
      printf("invalid col type:%d", dataType);
      exit(1);
  }

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

  return 0;
}


D
dapan1121 已提交
565
int32_t prepareInsertData(BindData *data) {
D
stmt  
dapan1121 已提交
566 567 568 569 570 571
  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 已提交
572
  data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
stmt  
dapan1121 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
  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 已提交
593 594 595 596 597 598 599 600 601 602 603
    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 已提交
604 605 606 607 608 609 610 611 612 613 614 615 616
    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 已提交
617
  generateInsertSQL(data);
D
stmt  
dapan1121 已提交
618 619 620 621
  
  return 0;
}

D
dapan1121 已提交
622 623 624 625 626 627 628 629 630 631 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
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 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
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 已提交
697 698 699
  taosMemoryFree(data->colTypes);
}

D
dapan1121 已提交
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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
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);
      printf("[%s]\n", temp);
    }
  }
}

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) {
    printf("failed to query table, reason:%s\n", taos_errstr(result));
    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:
      printf("invalid data type:%d\n", type);
      exit(1);
  }
}


D
dapan1121 已提交
800
int32_t bpBindParam(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
D
stmt  
dapan1121 已提交
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
  static int32_t n = 0;
  
  if (gCurCase->bindRowNum > 1) {
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
        printf("taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    } else {
      for (int32_t i = 0; i < gCurCase->bindColNum; ++i) {
        if (taos_stmt_bind_single_param_batch(stmt, bind++, i)) {
          printf("taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
      }
    }
  } else {
D
dapan1121 已提交
818 819 820 821 822 823 824 825 826 827
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
        printf("taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    } else {
      if (taos_stmt_bind_param(stmt, bind)) {
        printf("taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
D
stmt  
dapan1121 已提交
828 829 830 831 832 833
    }
  }

  return 0;
}

D
dapan1121 已提交
834
void bpCheckIsInsert(TAOS_STMT *stmt, int32_t insert) {
D
stmt  
dapan1121 已提交
835 836 837 838 839 840
  int32_t isInsert = 0;
  if (taos_stmt_is_insert(stmt, &isInsert)) {
    printf("taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

D
dapan1121 已提交
841
  if (insert != isInsert) {
D
stmt  
dapan1121 已提交
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
    printf("is insert failed\n");
    exit(1);
  }
}

void bpCheckParamNum(TAOS_STMT *stmt) {
  int32_t num = 0;
  if (taos_stmt_num_params(stmt, &num)) {
    printf("taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

  if (gCurCase->bindColNum != num) {
    printf("is insert failed\n");
    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) {
    printf("affected rows %d mis-match with insert num %d\n", rows, insertNum);
    exit(1);
  }
D
stmt  
dapan1121 已提交
867 868
}

D
dapan1121 已提交
869 870 871 872 873 874 875 876 877 878 879 880 881 882 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 917
void bpCheckAffectedRowsOnce(TAOS_STMT *stmt, int32_t expectedNum) {
  int32_t rows = taos_stmt_affected_rows_once(stmt);
  if (expectedNum != rows) {
    printf("affected rows %d mis-match with expected num %d\n", rows, expectedNum);
    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) {
    printf("Query SQL: %s\n", sql);
  }

  bpExecQuery(taos, sql, gCaseCtrl.printRes, &sqlResNum);
  if (sqlResNum != stmtResNum) {
    printf("sql res num %d mis-match stmt res num %d\n", sqlResNum, stmtResNum);
    exit(1);
  }

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

D
stmt  
dapan1121 已提交
919
/* prepare [settbname [bind add]] exec */
D
dapan1121 已提交
920
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
921
  BindData data = {0};
D
dapan1121 已提交
922
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
923 924

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

D
dapan1121 已提交
930
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
931

D
stmt  
dapan1121 已提交
932 933 934 935 936 937 938 939 940 941 942
  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){
        printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
943 944 945 946

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
947 948
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
949
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
        printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

D
dapan1121 已提交
965
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
966 967 968 969
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
970 971 972 973
  return 0;
}


D
stmt  
dapan1121 已提交
974
/* prepare [settbname bind add] exec  */
D
dapan1121 已提交
975
int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
976
  BindData data = {0};
D
dapan1121 已提交
977
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
978 979 980 981 982 983 984

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

D
dapan1121 已提交
985
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
986

D
stmt  
dapan1121 已提交
987 988 989 990 991 992 993 994 995 996 997 998 999 1000
  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){
          printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1001
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1002 1003
        exit(1);
      }
D
stmt  
dapan1121 已提交
1004 1005 1006 1007 1008

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
      if (taos_stmt_add_batch(stmt)) {
        printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

D
dapan1121 已提交
1021
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1022 1023 1024 1025
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1026 1027 1028 1029
  return 0;
}

/* prepare [settbname [bind add] exec] */
D
dapan1121 已提交
1030
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1031
  BindData data = {0};
D
dapan1121 已提交
1032
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1033 1034 1035 1036 1037 1038
  
  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }
D
stmt  
dapan1121 已提交
1039

D
dapan1121 已提交
1040
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1041

D
stmt  
dapan1121 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
  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){
        printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1053 1054 1055 1056

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1057 1058
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1059
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1060 1061 1062 1063 1064 1065 1066 1067
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
        printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }
D
stmt  
dapan1121 已提交
1068

D
stmt  
dapan1121 已提交
1069 1070 1071 1072
    if (taos_stmt_execute(stmt) != 0) {
      printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }
D
stmt  
dapan1121 已提交
1073 1074
  }

D
dapan1121 已提交
1075
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1076 1077 1078
  bpCheckAffectedRows(stmt, 1);

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

D
stmt  
dapan1121 已提交
1080 1081 1082
  return 0;
}

D
stmt  
dapan1121 已提交
1083
/* prepare [settbname [bind add exec]] */
D
dapan1121 已提交
1084
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1085
  BindData data = {0};
D
dapan1121 已提交
1086
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1087 1088 1089 1090 1091 1092 1093

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

D
dapan1121 已提交
1094
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1095

D
stmt  
dapan1121 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
  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){
        printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }  
    }
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1109
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1110 1111
        exit(1);
      }
D
stmt  
dapan1121 已提交
1112 1113 1114 1115 1116

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
      if (taos_stmt_add_batch(stmt)) {
        printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
        printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1129
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1130 1131 1132
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1133 1134 1135 1136

  return 0;
}

D
stmt  
dapan1121 已提交
1137
/* prepare [settbname [settbname bind add exec]] */
D
dapan1121 已提交
1138
int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1139
  BindData data = {0};
D
dapan1121 已提交
1140
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1141 1142 1143 1144 1145 1146 1147

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

D
dapan1121 已提交
1148
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1149

D
stmt  
dapan1121 已提交
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
  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){
        printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1161 1162 1163 1164

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
    
    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){
          printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }  
      }
      
D
stmt  
dapan1121 已提交
1177
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
        printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
        printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1193
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1194 1195 1196
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1197 1198 1199 1200 1201 1202

  return 0;
}


/* prepare [settbname bind add exec]   */
D
dapan1121 已提交
1203
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1204
  BindData data = {0};
D
dapan1121 已提交
1205
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1206 1207 1208 1209 1210 1211 1212

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

D
dapan1121 已提交
1213
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1214

D
stmt  
dapan1121 已提交
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
  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){
          printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1229
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1230 1231
        exit(1);
      }
D
stmt  
dapan1121 已提交
1232 1233 1234 1235 1236

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
      if (taos_stmt_add_batch(stmt)) {
        printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
        printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1249
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1250 1251 1252 1253 1254 1255 1256 1257
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

  return 0;
}

/* [prepare [settbname [bind add] exec]]   */
D
dapan1121 已提交
1258
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1259 1260 1261 1262
  int32_t loop = 0;
  
  while (gCurCase->bindColNum >= 2) {
    BindData data = {0};
D
dapan1121 已提交
1263
    prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1264 1265 1266 1267 1268 1269 1270

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
      printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }

D
dapan1121 已提交
1271
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305

    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){
          printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
          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)) {
          printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
      }

      if (taos_stmt_execute(stmt) != 0) {
        printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }

D
dapan1121 已提交
1306
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1307 1308 1309 1310

    destroyData(&data);

    gCurCase->bindColNum -= 2;
D
stmt  
dapan1121 已提交
1311
    gCurCase->fullCol = false;
D
stmt  
dapan1121 已提交
1312 1313 1314 1315 1316 1317 1318
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
D
stmt  
dapan1121 已提交
1319 1320 1321
  return 0;
}

D
dapan1121 已提交
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
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){
      printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
      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)) {
        printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
        printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }

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

    destroyData(&data);
  }

  return 0;
}

D
stmt  
dapan1121 已提交
1367

D
stmt  
dapan1121 已提交
1368
#if 0
1369 1370

//1 tables 10 records
D
stmt  
dapan1121 已提交
1371
int stmt_funcb_autoctb1(TAOS_STMT *stmt) {
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
  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 已提交
1384
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1385
  
wafwerar's avatar
wafwerar 已提交
1386
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1387

wafwerar's avatar
wafwerar 已提交
1388
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1389
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1390 1391 1392 1393

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1394 1395
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 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

  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 已提交
1538
  unsigned long long starttime = taosGetTimestampUs();
1539

D
stmt  
dapan1121 已提交
1540
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
  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 已提交
1567
  unsigned long long endtime = taosGetTimestampUs();
1568 1569
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1570 1571 1572 1573 1574 1575
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1576 1577 1578 1579 1580 1581 1582 1583

  return 0;
}




//1 tables 10 records
D
stmt  
dapan1121 已提交
1584
int stmt_funcb_autoctb2(TAOS_STMT *stmt) {
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
  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 已提交
1597
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1598
  
wafwerar's avatar
wafwerar 已提交
1599
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1600

wafwerar's avatar
wafwerar 已提交
1601
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1602
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1603 1604 1605 1606

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1607 1608
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 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

  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 已提交
1677 1678 1679
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;
1680

D
stmt  
dapan1121 已提交
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
    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;
    
1695 1696 1697 1698 1699 1700 1701 1702 1703
  }

  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 已提交
1704 1705
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
1706 1707 1708
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
1709 1710
    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
1711 1712 1713
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
1714 1715
    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
1716 1717 1718
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
1719 1720
    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
1721
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
    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;
1748 1749 1750
  }


D
stmt  
dapan1121 已提交
1751
  unsigned long long starttime = taosGetTimestampUs();
1752

D
stmt  
dapan1121 已提交
1753
  char *sql = "insert into ? using stb1 tags(1,true,2,3,4,5.0,6.0,'a','b') values(?,?,?,?,?,?,?,?,?,?)";
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
  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 已提交
1769
    taos_stmt_bind_param_batch(stmt, params + id * 10);
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779
    taos_stmt_add_batch(stmt);
  }

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

  ++id;

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

wafwerar's avatar
wafwerar 已提交
1783 1784 1785 1786 1787 1788
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1789 1790 1791 1792 1793 1794 1795 1796 1797

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
1798
int stmt_funcb_autoctb3(TAOS_STMT *stmt) {
1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810
  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 已提交
1811
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1812
  
wafwerar's avatar
wafwerar 已提交
1813
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1814

wafwerar's avatar
wafwerar 已提交
1815
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1816
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1817 1818 1819 1820

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1821 1822
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 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

  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 已提交
1940
  unsigned long long starttime = taosGetTimestampUs();
1941

D
stmt  
dapan1121 已提交
1942
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
1943 1944
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
1945 1946
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968
  }

  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 已提交
1969
  unsigned long long endtime = taosGetTimestampUs();
1970 1971
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1972 1973 1974 1975 1976 1977
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1978 1979 1980 1981 1982 1983 1984 1985

  return 0;
}





D
stmt  
dapan1121 已提交
1986 1987


1988
//1 tables 10 records
D
stmt  
dapan1121 已提交
1989
int stmt_funcb_autoctb4(TAOS_STMT *stmt) {
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001
  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 已提交
2002
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2003
  
wafwerar's avatar
wafwerar 已提交
2004
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2005

wafwerar's avatar
wafwerar 已提交
2006
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2007
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*5);
2008 2009 2010 2011

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2012 2013
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028

  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 已提交
2029
  for (int i = 0; i < 5; i+=5) {
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043
    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 已提交
2044 2045 2046
    params[i+2].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+2].buffer_length = sizeof(int32_t);
    params[i+2].buffer = v.v4;
2047 2048 2049 2050
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

D
stmt  
dapan1121 已提交
2051 2052 2053
    params[i+3].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+3].buffer_length = sizeof(int64_t);
    params[i+3].buffer = v.v8;
2054 2055 2056 2057
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

D
stmt  
dapan1121 已提交
2058 2059 2060
    params[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+4].buffer_length = sizeof(double);
    params[i+4].buffer = v.f8;
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072
    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 已提交
2073 2074
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
2075 2076 2077
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2078 2079
    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
2080 2081 2082
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2083 2084
    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
2085 2086 2087
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2088 2089
    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
2090
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2091
    tags[i+3].length = (uintptr_t *)lb;
2092 2093 2094
  }


D
stmt  
dapan1121 已提交
2095
  unsigned long long starttime = taosGetTimestampUs();
2096

D
stmt  
dapan1121 已提交
2097
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') (ts,b,v4,v8,f8) values(?,?,?,?,?)";
2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
  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 已提交
2108
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2109
    if (code != 0){
D
stmt  
dapan1121 已提交
2110
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
2111 2112
    }  

D
stmt  
dapan1121 已提交
2113
    taos_stmt_bind_param_batch(stmt, params + id * 5);
2114 2115 2116 2117 2118 2119 2120 2121 2122 2123
    taos_stmt_add_batch(stmt);
  }

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

  ++id;

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

wafwerar's avatar
wafwerar 已提交
2127 2128 2129 2130 2131 2132
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2133 2134 2135 2136 2137 2138 2139 2140 2141

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
2142
int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) {
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
  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 已提交
2155
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2156
  
wafwerar's avatar
wafwerar 已提交
2157
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2158

wafwerar's avatar
wafwerar 已提交
2159
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2160
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2161 2162 2163 2164

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2165 2166
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 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

  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 已提交
2262 2263
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
2264 2265 2266
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2267 2268
    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
2269 2270 2271
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2272 2273
    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
2274 2275 2276
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2277 2278
    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
2279
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2280
    tags[i+3].length = (uintptr_t *)lb;
2281 2282 2283
  }


D
stmt  
dapan1121 已提交
2284
  unsigned long long starttime = taosGetTimestampUs();
2285

D
stmt  
dapan1121 已提交
2286
  char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
2287 2288
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2289
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
2290 2291 2292 2293 2294 2295 2296
    return -1;
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2297
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312
    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 已提交
2313
  unsigned long long endtime = taosGetTimestampUs();
2314 2315
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2316 2317 2318 2319 2320 2321
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2322 2323 2324 2325 2326 2327 2328

  return 0;
}




D
stmt  
dapan1121 已提交
2329

2330
//1 tables 10 records
D
stmt  
dapan1121 已提交
2331
int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) {
2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343
  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 已提交
2344
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2345
  
wafwerar's avatar
wafwerar 已提交
2346
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2347

wafwerar's avatar
wafwerar 已提交
2348
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2349
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2350 2351 2352 2353

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2354 2355
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 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

  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 已提交
2498
  unsigned long long starttime = taosGetTimestampUs();
2499 2500 2501 2502

  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2503
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
2504 2505 2506 2507 2508 2509 2510
    exit(1);
  }

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

D
stmt  
dapan1121 已提交
2517
    taos_stmt_bind_param_batch(stmt, params + id * 10);
2518 2519 2520 2521 2522 2523 2524 2525 2526 2527
    taos_stmt_add_batch(stmt);
  }

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

  ++id;

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

wafwerar's avatar
wafwerar 已提交
2531 2532 2533 2534 2535 2536
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2537 2538 2539 2540 2541 2542 2543 2544 2545

  return 0;
}






D
stmt  
dapan1121 已提交
2546

2547
//1 tables 10 records
D
stmt  
dapan1121 已提交
2548
int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) {
2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560
  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 已提交
2561
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2562
  
wafwerar's avatar
wafwerar 已提交
2563
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2564

wafwerar's avatar
wafwerar 已提交
2565
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2566
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2567 2568 2569 2570

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2571 2572
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 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

  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 已提交
2715
  unsigned long long starttime = taosGetTimestampUs();
2716

D
stmt  
dapan1121 已提交
2717 2718
  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);
2719
  if (code != 0){
D
stmt  
dapan1121 已提交
2720
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt));
2721
    return -1;
D
stmt  
dapan1121 已提交
2722
    //exit(1);
2723 2724 2725 2726 2727 2728
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2729
    code = taos_stmt_set_tbname_tags(stmt, buf, NULL);
2730
    if (code != 0){
D
stmt  
dapan1121 已提交
2731 2732
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
      return -1;
2733 2734
    }  

D
stmt  
dapan1121 已提交
2735
    taos_stmt_bind_param_batch(stmt, params + id * 10);
2736 2737 2738 2739 2740 2741 2742 2743 2744 2745
    taos_stmt_add_batch(stmt);
  }

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

  ++id;

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

wafwerar's avatar
wafwerar 已提交
2749 2750 2751 2752 2753 2754
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2755 2756 2757 2758 2759 2760

  return 0;
}



D
stmt  
dapan1121 已提交
2761 2762 2763

//1 tables 10 records
int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) {
2764 2765
  struct {
      int64_t *ts;
D
stmt  
dapan1121 已提交
2766 2767 2768 2769 2770 2771 2772 2773
      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];
2774 2775
  } v = {0};

D
stmt  
dapan1121 已提交
2776
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2777
  
D
stmt  
dapan1121 已提交
2778 2779 2780
  int *lb = taosMemoryMalloc(10 * sizeof(int));

  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2781
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
D
stmt  
dapan1121 已提交
2782 2783 2784

//  int one_null = 1;
  int one_not_null = 0;
2785
  
D
stmt  
dapan1121 已提交
2786 2787
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2788

D
stmt  
dapan1121 已提交
2789
  for (int i = 0; i < 10; ++i) {
2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802
    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 已提交
2803
  for (int i = 0; i < 10; i+=10) {
2804 2805
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
D
stmt  
dapan1121 已提交
2806
    params[i+0].buffer = &v.ts[10*i/10];
2807 2808
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
D
stmt  
dapan1121 已提交
2809
    params[i+0].num = 10;
2810 2811 2812 2813 2814 2815
    
    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 已提交
2816
    params[i+1].num = 10;
2817 2818 2819 2820 2821 2822

    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 已提交
2823
    params[i+2].num = 10;
2824 2825 2826 2827 2828 2829

    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 已提交
2830
    params[i+3].num = 10;
2831 2832 2833 2834 2835 2836

    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 已提交
2837
    params[i+4].num = 10;
2838 2839 2840 2841 2842 2843

    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 已提交
2844
    params[i+5].num = 10;
2845 2846 2847 2848 2849 2850

    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 已提交
2851
    params[i+6].num = 10;
2852 2853 2854 2855 2856 2857

    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 已提交
2858
    params[i+7].num = 10;
2859 2860 2861 2862 2863 2864

    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 已提交
2865
    params[i+8].num = 10;
2866 2867 2868 2869 2870 2871

    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 已提交
2872
    params[i+9].num = 10;
2873 2874 2875 2876
    
  }

  int64_t tts = 1591060628000;
D
stmt  
dapan1121 已提交
2877
  for (int i = 0; i < 10; ++i) {
2878 2879 2880 2881
    v.ts[i] = tts + i;
  }


D
stmt  
dapan1121 已提交
2882 2883 2884 2885 2886
  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;
2887

D
stmt  
dapan1121 已提交
2888 2889 2890 2891
    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;
2892

D
stmt  
dapan1121 已提交
2893 2894 2895 2896
    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;
2897

D
stmt  
dapan1121 已提交
2898 2899 2900 2901
    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;
2902

D
stmt  
dapan1121 已提交
2903 2904 2905 2906
    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;
2907

D
stmt  
dapan1121 已提交
2908 2909 2910 2911
    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;
2912

D
stmt  
dapan1121 已提交
2913 2914 2915 2916
    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;
2917

D
stmt  
dapan1121 已提交
2918 2919 2920 2921
    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;
2922

D
stmt  
dapan1121 已提交
2923 2924 2925 2926
    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;
2927 2928
  }

D
stmt  
dapan1121 已提交
2929

D
stmt  
dapan1121 已提交
2930
  unsigned long long starttime = taosGetTimestampUs();
2931

D
stmt  
dapan1121 已提交
2932
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
2933 2934
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2935 2936
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt));
    exit(1);
2937 2938 2939
  }

  int id = 0;
D
stmt  
dapan1121 已提交
2940 2941 2942 2943 2944 2945 2946 2947
  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);
    }  
2948

D
stmt  
dapan1121 已提交
2949 2950 2951 2952
    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);
2953
    }
D
stmt  
dapan1121 已提交
2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966
    
    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);
2967 2968
  }

D
stmt  
dapan1121 已提交
2969 2970
  ++id;

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

wafwerar's avatar
wafwerar 已提交
2974 2975 2976 2977 2978
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
2979
  taosMemoryFree(tags);
2980 2981 2982 2983 2984

  return 0;
}


D
stmt  
dapan1121 已提交
2985 2986 2987 2988 2989 2990




//1 tables 10 records
int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) {
2991 2992
  struct {
      int64_t *ts;
D
stmt  
dapan1121 已提交
2993 2994 2995 2996 2997 2998 2999 3000
      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];
3001 3002
  } v = {0};

D
stmt  
dapan1121 已提交
3003
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
3004
  
D
stmt  
dapan1121 已提交
3005 3006 3007
  int *lb = taosMemoryMalloc(10 * sizeof(int));

  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
3008
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
D
stmt  
dapan1121 已提交
3009 3010 3011

//  int one_null = 1;
  int one_not_null = 0;
3012
  
D
stmt  
dapan1121 已提交
3013 3014
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
3015

D
stmt  
dapan1121 已提交
3016
  for (int i = 0; i < 10; ++i) {
3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029
    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 已提交
3030
  for (int i = 0; i < 10; i+=10) {
3031 3032
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
D
stmt  
dapan1121 已提交
3033
    params[i+0].buffer = &v.ts[10*i/10];
3034 3035
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
D
stmt  
dapan1121 已提交
3036
    params[i+0].num = 10;
3037 3038 3039 3040 3041 3042
    
    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 已提交
3043
    params[i+1].num = 10;
3044 3045 3046 3047 3048 3049

    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 已提交
3050
    params[i+2].num = 10;
3051 3052 3053 3054 3055 3056

    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 已提交
3057
    params[i+3].num = 10;
3058 3059 3060 3061 3062 3063

    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 已提交
3064
    params[i+4].num = 10;
3065 3066 3067 3068 3069 3070

    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 已提交
3071
    params[i+5].num = 10;
3072 3073 3074 3075 3076 3077

    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 已提交
3078
    params[i+6].num = 10;
3079 3080 3081 3082 3083 3084

    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 已提交
3085
    params[i+7].num = 10;
3086 3087 3088 3089 3090 3091

    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 已提交
3092
    params[i+8].num = 10;
3093 3094 3095 3096 3097 3098

    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 已提交
3099
    params[i+9].num = 10;
3100 3101 3102 3103
    
  }

  int64_t tts = 1591060628000;
D
stmt  
dapan1121 已提交
3104
  for (int i = 0; i < 10; ++i) {
3105 3106 3107
    v.ts[i] = tts + i;
  }

D
stmt  
dapan1121 已提交
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 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

  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 已提交
3157
  unsigned long long starttime = taosGetTimestampUs();
3158

D
stmt  
dapan1121 已提交
3159 3160
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(NULL, sql, 0);
3161
  if (code != 0){
D
stmt  
dapan1121 已提交
3162 3163
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(NULL));
    return -1;
3164 3165 3166
  }

  int id = 0;
D
stmt  
dapan1121 已提交
3167 3168 3169 3170 3171 3172 3173 3174
  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);
    }  
3175

D
stmt  
dapan1121 已提交
3176 3177 3178
    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));
3179 3180
      exit(1);
    }
D
stmt  
dapan1121 已提交
3181 3182 3183 3184 3185 3186 3187 3188 3189
    
    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);
  }
3190

D
stmt  
dapan1121 已提交
3191 3192 3193
  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
3194 3195
  }

D
stmt  
dapan1121 已提交
3196 3197
  ++id;

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

wafwerar's avatar
wafwerar 已提交
3201 3202 3203 3204 3205
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
3206
  taosMemoryFree(tags);
3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224

  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 已提交
3225
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3226
  
wafwerar's avatar
wafwerar 已提交
3227
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3228
  
D
dapan1121 已提交
3229
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3230 3231
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 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

  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 已提交
3325
  unsigned long long starttime = taosGetTimestampUs();
3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354

  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 已提交
3355
  unsigned long long endtime = taosGetTimestampUs();
3356 3357
  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 已提交
3358 3359 3360 3361 3362
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383

  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 已提交
3384
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3385
  
wafwerar's avatar
wafwerar 已提交
3386
  int *lb = taosMemoryMalloc(18000 * sizeof(int));
3387
  
D
dapan1121 已提交
3388
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10);
wafwerar's avatar
wafwerar 已提交
3389 3390
  char* is_null = taosMemoryMalloc(sizeof(char) * 18000);
  char* no_null = taosMemoryMalloc(sizeof(char) * 18000);
3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 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

  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 已提交
3484
  unsigned long long starttime = taosGetTimestampUs();
3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507

  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 已提交
3508
  unsigned long long endtime = taosGetTimestampUs();
3509 3510
  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 已提交
3511 3512 3513 3514 3515
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527

  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 已提交
3528
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 30000 * 3000);
3529
  
wafwerar's avatar
wafwerar 已提交
3530
  int *lb = taosMemoryMalloc(30000 * sizeof(int));
3531
  
D
dapan1121 已提交
3532
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10);
wafwerar's avatar
wafwerar 已提交
3533
  char* no_null = taosMemoryMalloc(sizeof(int) * 200000);
3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561

  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 已提交
3562
  unsigned long long starttime = taosGetTimestampUs();
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592

  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 已提交
3593
  unsigned long long endtime = taosGetTimestampUs();
3594 3595
  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 已提交
3596 3597 3598 3599
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(no_null);
3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618

  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 已提交
3619
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3620
  
wafwerar's avatar
wafwerar 已提交
3621
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3622
  
D
dapan1121 已提交
3623
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3624 3625
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 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

  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 已提交
3719
  unsigned long long starttime = taosGetTimestampUs();
3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749

  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 已提交
3750
  unsigned long long endtime = taosGetTimestampUs();
3751 3752
  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 已提交
3753 3754 3755 3756 3757
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780

  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 已提交
3781
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3782
  
wafwerar's avatar
wafwerar 已提交
3783
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3784
  
D
dapan1121 已提交
3785
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3786 3787
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 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

  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 已提交
3881
  unsigned long long starttime = taosGetTimestampUs();
3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911

  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 已提交
3912
  unsigned long long endtime = taosGetTimestampUs();
3913 3914
  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 已提交
3915 3916 3917 3918 3919
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938

  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 已提交
3939
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
3940
  
wafwerar's avatar
wafwerar 已提交
3941
  int *lb = taosMemoryMalloc(60 * sizeof(int));
3942
  
D
dapan1121 已提交
3943
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
wafwerar's avatar
wafwerar 已提交
3944 3945
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 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

  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 已提交
4039
  unsigned long long starttime = taosGetTimestampUs();
4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071

  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 已提交
4072
  unsigned long long endtime = taosGetTimestampUs();
4073 4074
  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 已提交
4075 4076 4077 4078 4079
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098

  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 已提交
4099
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 60);
4100
  
wafwerar's avatar
wafwerar 已提交
4101
  int *lb = taosMemoryMalloc(60 * sizeof(int));
4102
  
D
dapan1121 已提交
4103
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 60*10);
wafwerar's avatar
wafwerar 已提交
4104 4105
  char* is_null = taosMemoryMalloc(sizeof(char) * 60);
  char* no_null = taosMemoryMalloc(sizeof(char) * 60);
4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 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

  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 已提交
4200
  unsigned long long starttime = taosGetTimestampUs();
4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228

  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 已提交
4229
  unsigned long long endtime = taosGetTimestampUs();
4230 4231
  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 已提交
4232 4233 4234 4235 4236
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
4237 4238 4239

  return 0;
}
D
stmt  
dapan1121 已提交
4240
#endif
4241 4242


D
dapan1121 已提交
4243 4244 4245 4246
void prepareCheckResultImpl(TAOS     * taos, char *tname, bool printr, int expected, bool silent) {
  char sql[255] = "SELECT * FROM ";
  int32_t rows = 0;
  
4247
  strcat(sql, tname);
D
dapan1121 已提交
4248
  bpExecQuery(taos, sql, printr, &rows);
4249 4250
  
  if (rows == expected) {
D
dapan1121 已提交
4251 4252 4253
    if (!silent) {
      printf("%d rows are fetched as expected from %s\n", rows, tname);
    }
4254
  } else {
D
stmt  
dapan1121 已提交
4255
    printf("!!!expect %d rows, but %d rows are fetched from %s\n", expected, rows, tname);
4256 4257 4258 4259 4260
    exit(1);
  }
}


D
dapan1121 已提交
4261
void prepareCheckResult(TAOS     *taos, bool silent) {
D
stmt  
dapan1121 已提交
4262 4263 4264
  char buf[32];
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
D
dapan1121 已提交
4265
      sprintf(buf, "%s%d", bpTbPrefix, t);
D
stmt  
dapan1121 已提交
4266
    } else {
D
dapan1121 已提交
4267
      sprintf(buf, "%s%d", bpTbPrefix, 0);
D
stmt  
dapan1121 已提交
4268 4269
    }

D
dapan1121 已提交
4270
    prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes, silent);
D
stmt  
dapan1121 已提交
4271
  }
D
stmt  
dapan1121 已提交
4272 4273

  gExecLoopTimes = 1;
D
stmt  
dapan1121 已提交
4274 4275 4276
}


4277 4278 4279 4280 4281 4282 4283

//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 已提交
4284
    sql[i] = taosMemoryCalloc(1, 1048576);
4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299
  }

  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 已提交
4300
  int64_t starttime = taosGetTimestampUs();
4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311
  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 已提交
4312
  int64_t endtime = taosGetTimestampUs();
4313 4314 4315
  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 已提交
4316
    taosMemoryFree(sql[i]);
4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327
  }

  return 0;
}





//one table 60 records one time
int sql_perf_s1(TAOS     *taos) {
D
stmt  
dapan1121 已提交
4328
  char **sql = calloc(1, sizeof(char*) * 360000);
4329 4330 4331
  TAOS_RES *result;

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
4332
    sql[i] = taosMemoryCalloc(1, 9000);
4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352
  }

  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 已提交
4353
  unsigned long long starttime = taosGetTimestampUs();
4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364
  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 已提交
4365
  unsigned long long endtime = taosGetTimestampUs();
4366 4367 4368
  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 已提交
4369
    taosMemoryFree(sql[i]);
4370 4371
  }

wafwerar's avatar
wafwerar 已提交
4372
  taosMemoryFree(sql);
4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383

  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 已提交
4384
    sql[i] = taosMemoryCalloc(1, 1048576);
4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399
  }

  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 已提交
4400
  unsigned long long starttime = taosGetTimestampUs();
4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411
  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 已提交
4412
  unsigned long long endtime = taosGetTimestampUs();
4413 4414 4415
  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 已提交
4416
    taosMemoryFree(sql[i]);
4417 4418 4419 4420 4421
  }

  return 0;
}

D
stmt  
dapan1121 已提交
4422 4423
void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) {
  int32_t blen = 0;
D
dapan1121 已提交
4424
  blen = sprintf(buf, "create table %s%d ", (stable ? bpStbPrefix : bpTbPrefix), tblIdx);
D
stmt  
dapan1121 已提交
4425 4426 4427
  if (stable) {
    blen += sprintf(buf + blen, "tags (");
    for (int c = 0; c < colNum; ++c) {
D
stmt  
dapan1121 已提交
4428 4429 4430
      if (c > 0) {
        blen += sprintf(buf + blen, ",");
      }
D
stmt  
dapan1121 已提交
4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 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
      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 已提交
4486 4487 4488 4489
    if (c > 0) {
      blen += sprintf(buf + blen, ",");
    }
  
D
stmt  
dapan1121 已提交
4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515
    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 已提交
4516
        blen += sprintf(buf + blen, "ts timestamp");
D
stmt  
dapan1121 已提交
4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539
        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 已提交
4540

D
stmt  
dapan1121 已提交
4541 4542 4543
  if (gCaseCtrl.printCreateTblSql) {
    printf("Create Table SQL:%s\n", buf);
  }
D
stmt  
dapan1121 已提交
4544
}
4545

D
dapan1121 已提交
4546
void prepare(TAOS     *taos, int32_t colNum, int32_t *colList, int prepareStb) {
4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564
  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) {
    printf("failed to create database, reason:%s\n", taos_errstr(result));
    taos_free_result(result);
    exit(1);
  }
  taos_free_result(result);

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

D
dapan1121 已提交
4565
  if (!prepareStb) {
4566
    // create table
D
stmt  
dapan1121 已提交
4567
    for (int i = 0 ; i < 10; i++) {
4568
      char buf[1024];
D
stmt  
dapan1121 已提交
4569
      generateCreateTableSQL(buf, i, colNum, colList, false);
4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580
      result = taos_query(taos, buf);
      code = taos_errno(result);
      if (code != 0) {
        printf("failed to create table, reason:%s\n", taos_errstr(result));
        taos_free_result(result);
        exit(1);
      }
      taos_free_result(result);
    }
  } else {
    char buf[1024];
D
stmt  
dapan1121 已提交
4581
    generateCreateTableSQL(buf, 1, colNum, colList, true);
4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594
    
    result = taos_query(taos, buf);
    code = taos_errno(result);
    if (code != 0) {
      printf("failed to create table, reason:%s\n", taos_errstr(result));
      taos_free_result(result);
      exit(1);
    }
    taos_free_result(result);
  }

}

D
dapan1121 已提交
4595
int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) {
D
stmt  
dapan1121 已提交
4596
  TAOS_STMT *stmt = NULL;
D
dapan1121 已提交
4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612
  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 已提交
4613
    
D
stmt  
dapan1121 已提交
4614
    gCurCase = &cfg;
D
dapan1121 已提交
4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641
  }
  
  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 已提交
4642

D
dapan1121 已提交
4643 4644 4645 4646 4647 4648 4649 4650
  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 已提交
4651 4652
    }
    
D
dapan1121 已提交
4653 4654 4655 4656 4657 4658
    beginUs = taosGetTimestampUs();
   
    stmt = taos_stmt_init(taos);
    if (NULL == stmt) {
      printf("taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
D
stmt  
dapan1121 已提交
4659
    }
D
dapan1121 已提交
4660 4661 4662 4663 4664 4665 4666
  
    (*gCurCase->runFn)(stmt, taos);
  
    taos_stmt_close(stmt);
  
    endUs = taosGetTimestampUs();
    totalUs += (endUs - beginUs);
D
dapan1121 已提交
4667

D
dapan1121 已提交
4668 4669
    prepareCheckResult(taos, silent);
  }
D
dapan1121 已提交
4670

D
dapan1121 已提交
4671 4672 4673 4674 4675 4676
  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 已提交
4677

D
dapan1121 已提交
4678 4679 4680 4681 4682
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;
4683

D
dapan1121 已提交
4684 4685 4686 4687
  for (int32_t i = caseIdx; i < sizeof(gCase)/sizeof(gCase[0]); ++i) {
    if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) {
      break;
    }
4688

D
dapan1121 已提交
4689 4690 4691
    if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) {
      break;
    }
D
dapan1121 已提交
4692

D
dapan1121 已提交
4693 4694 4695 4696
    if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) {
      caseRunIdx++;
      continue;
    }
D
dapan1121 已提交
4697

D
dapan1121 已提交
4698 4699
    if (runCase(taos, i, caseRunIdx, false)) {
      continue;
4700
    }
D
stmt  
dapan1121 已提交
4701

D
dapan1121 已提交
4702 4703
    caseRunIdx++;
    caseNum++;
D
dapan1121 已提交
4704
    caseRunNum++;
D
stmt  
dapan1121 已提交
4705
  }
4706

D
stmt  
dapan1121 已提交
4707 4708
  return NULL;
}
D
stmt  
dapan1121 已提交
4709

D
stmt  
dapan1121 已提交
4710
void runAll(TAOS *taos) {
D
dapan1121 已提交
4711 4712
  strcpy(gCaseCtrl.caseCatalog, "Normal Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
dapan1121 已提交
4713
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4714

D
dapan1121 已提交
4715 4716
  strcpy(gCaseCtrl.caseCatalog, "Null Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4717
  gCaseCtrl.bindNullNum = 1;
D
dapan1121 已提交
4718
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4719
  gCaseCtrl.bindNullNum = 0;
D
stmt  
dapan1121 已提交
4720

D
dapan1121 已提交
4721 4722
  strcpy(gCaseCtrl.caseCatalog, "Bind Row Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4723
  gCaseCtrl.bindRowNum = 1;
D
dapan1121 已提交
4724
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4725
  gCaseCtrl.bindRowNum = 0;
D
stmt  
dapan1121 已提交
4726

D
dapan1121 已提交
4727 4728
  strcpy(gCaseCtrl.caseCatalog, "Row Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4729
  gCaseCtrl.rowNum = 1000;
D
stmt  
dapan1121 已提交
4730
  gCaseCtrl.printRes = false;
D
dapan1121 已提交
4731
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4732 4733
  gCaseCtrl.rowNum = 0;
  gCaseCtrl.printRes = true;
D
stmt  
dapan1121 已提交
4734

D
dapan1121 已提交
4735 4736
  strcpy(gCaseCtrl.caseCatalog, "Runtimes Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4737
  gCaseCtrl.runTimes = 2;
D
dapan1121 已提交
4738
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4739
  gCaseCtrl.runTimes = 0;
4740

D
dapan1121 已提交
4741 4742
  strcpy(gCaseCtrl.caseCatalog, "Check Param Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4743
  gCaseCtrl.checkParamNum = true;
D
dapan1121 已提交
4744
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4745
  gCaseCtrl.checkParamNum = false;
4746

D
dapan1121 已提交
4747 4748
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4749
  gCaseCtrl.bindColNum = 6;
D
dapan1121 已提交
4750
  runCaseList(taos);
D
stmt  
dapan1121 已提交
4751
  gCaseCtrl.bindColNum = 0;
4752

D
dapan1121 已提交
4753 4754
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
4755
  gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList);
D
stmt  
dapan1121 已提交
4756
  gCaseCtrl.bindColTypeList = bindColTypeList;  
D
dapan1121 已提交
4757
  runCaseList(taos);
D
dapan1121 已提交
4758 4759
  
  printf("All Test End\n");  
4760 4761 4762 4763
}

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

D
stmt  
dapan1121 已提交
4766 4767
  srand(time(NULL));
  
4768 4769 4770 4771 4772 4773
  // connect to server
  if (argc < 2) {
    printf("please input server ip \n");
    return 0;
  }

D
stmt  
dapan1121 已提交
4774
  taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
4775 4776 4777 4778 4779
  if (taos == NULL) {
    printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
    exit(1);
  }   

D
stmt  
dapan1121 已提交
4780
  runAll(taos);
4781 4782 4783 4784

  return 0;
}