Skip to content

Commit

Permalink
Merge pull request #737 from taosdata/feat/TD-29400
Browse files Browse the repository at this point in the history
feat: support composite primary key
  • Loading branch information
DuanKuanJun committed Apr 8, 2024
2 parents c84009b + 1dc83e1 commit 7b6c86e
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 43 deletions.
69 changes: 69 additions & 0 deletions case/insertPrimaryKey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 1000,
"create_table_thread_count": 2,
"thread_count": 10,
"confirm_parameter_prompt": "no",
"databases": [
{
"dbinfo": {
"name": "primary",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms"
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 1000,
"insert_rows": 10000000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"primary_key":1,
"repeat_ts_min": 0,
"repeat_ts_max": 10,
"columns": [
{ "type": "int", "name": "pk", "max": 100, "min": 0 },
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
],
"sqls" : [
"select count(*) from primary.meters",
"select max(pk) from primary.meters",
"create topic tp1 as * from primary.meters"
]
}
]
}
]
}
13 changes: 13 additions & 0 deletions inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,11 @@ typedef struct SChildTable_S {
char *sampleDataBuf;
uint64_t insertRows;
BArray *childCols;
int32_t pkCur;
int32_t pkCnt;
} SChildTable;

#define PRIMARY_KEY "PRIMARY KEY"
typedef struct SSuperTable_S {
char *stbName;
bool random_data_source; // rand_gen or sample
Expand Down Expand Up @@ -728,6 +731,13 @@ typedef struct SSuperTable_S {
int ttl;
int32_t keep_trying;
uint32_t trying_interval;
// primary key
bool primary_key;
int repeat_ts_min;
int repeat_ts_max;

// execute sqls after create super table
char **sqls;
} SSuperTable;

typedef struct SDbCfg_S {
Expand Down Expand Up @@ -1117,5 +1127,8 @@ int32_t benchParseArgsNoArgp(int argc, char* argv[]);
#endif

int32_t execInsert(threadInfo *pThreadInfo, uint32_t k);
// if return true, timestmap must add timestap_step, else timestamp no need changed
bool needChangeTs(SSuperTable * stbInfo, int32_t *pkCur, int32_t *pkCnt);


#endif // INC_BENCH_H_
2 changes: 1 addition & 1 deletion inc/benchData.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int generateRandData(SSuperTable *stbInfo, char *sampleDataBuf,
bool tag, BArray *childCols);
int prepareStmt(SSuperTable *stbInfo, TAOS_STMT *stmt, char* tagData, uint64_t tableSeq);
uint32_t bindParamBatch(threadInfo *pThreadInfo,
uint32_t batch, int64_t startTime, SChildTable *childTbl);
uint32_t batch, int64_t startTime, SChildTable *childTbl, int32_t *pkCur, int32_t *pkCnt, int32_t *n);
int prepareSampleData(SDataBase* database, SSuperTable* stbInfo);
void generateSmlJsonTags(tools_cJSON *tagsList,
char **sml_tags_json_array,
Expand Down
16 changes: 11 additions & 5 deletions src/benchData.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,8 @@ static int fillStmt(
}
}
skip_stmt:
*(sampleDataBuf + pos - 1) = 0;
if (pos > 0)
*(sampleDataBuf + pos - 1) = 0;
}
return 0;
}
Expand Down Expand Up @@ -1780,7 +1781,7 @@ int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, int disorderRatio,

uint32_t bindParamBatch(threadInfo *pThreadInfo,
uint32_t batch, int64_t startTime,
SChildTable *childTbl) {
SChildTable *childTbl, int32_t *pkCur, int32_t *pkCnt, int32_t *n) {
TAOS_STMT *stmt = pThreadInfo->conn->stmt;
SSuperTable *stbInfo = pThreadInfo->stbInfo;
uint32_t columnCount = stbInfo->cols->size;
Expand Down Expand Up @@ -1822,16 +1823,21 @@ uint32_t bindParamBatch(threadInfo *pThreadInfo,
param->num = batch;
}

// set ts array values
for (uint32_t k = 0; k < batch; k++) {
/* columnCount + 1 (ts) */
if (stbInfo->disorderRatio) {
*(pThreadInfo->bind_ts_array + k) =
startTime + getTSRandTail(stbInfo->timestamp_step, k,
startTime + getTSRandTail(stbInfo->timestamp_step, *n,
stbInfo->disorderRatio,
stbInfo->disorderRange);
} else {
*(pThreadInfo->bind_ts_array + k) =
startTime + stbInfo->timestamp_step * k;
*(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timestamp_step * (*n);
}

// check n need add
if (!stbInfo->primary_key || needChangeTs(stbInfo, pkCur, pkCnt)) {
*n = *n + 1;
}
}

Expand Down
Loading

0 comments on commit 7b6c86e

Please sign in to comment.