提交 5bc1a121 编写于 作者: S shenglian zhou

schemaless: performance optimization: no hash table for each point/kv

上级 5bdb3bf4
...@@ -32,6 +32,8 @@ typedef struct { ...@@ -32,6 +32,8 @@ typedef struct {
uint8_t type; uint8_t type;
int16_t length; int16_t length;
char* value; char* value;
uint32_t fieldSchemaIdx;
} TAOS_SML_KV; } TAOS_SML_KV;
typedef struct { typedef struct {
...@@ -44,6 +46,8 @@ typedef struct { ...@@ -44,6 +46,8 @@ typedef struct {
// first kv must be timestamp // first kv must be timestamp
TAOS_SML_KV* fields; TAOS_SML_KV* fields;
int32_t fieldNum; int32_t fieldNum;
uint32_t schemaIdx;
} TAOS_SML_DATA_POINT; } TAOS_SML_DATA_POINT;
typedef enum { typedef enum {
...@@ -56,7 +60,6 @@ typedef enum { ...@@ -56,7 +60,6 @@ typedef enum {
typedef struct { typedef struct {
uint64_t id; uint64_t id;
SHashObj* smlDataToSchema;
} SSmlLinesInfo; } SSmlLinesInfo;
//================================================================================================= //=================================================================================================
...@@ -175,8 +178,7 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra ...@@ -175,8 +178,7 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
taosHashPut(hash, field.name, tagKeyLen, &fieldIdx, sizeof(fieldIdx)); taosHashPut(hash, field.name, tagKeyLen, &fieldIdx, sizeof(fieldIdx));
} }
uintptr_t valPointer = (uintptr_t)smlKv; smlKv->fieldSchemaIdx = (uint32_t)fieldIdx;
taosHashPut(info->smlDataToSchema, &valPointer, sizeof(uintptr_t), &fieldIdx, sizeof(fieldIdx));
return 0; return 0;
} }
...@@ -270,8 +272,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -270,8 +272,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
} }
} }
uintptr_t valPointer = (uintptr_t)point; point->schemaIdx = (uint32_t)stableIdx;
taosHashPut(info->smlDataToSchema, &valPointer, sizeof(uintptr_t), &stableIdx, sizeof(stableIdx));
} }
size_t numStables = taosArrayGetSize(stableSchemas); size_t numStables = taosArrayGetSize(stableSchemas);
...@@ -916,10 +917,7 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu ...@@ -916,10 +917,7 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu
SHashObj* cname2points, SArray* stableSchemas, SSmlLinesInfo* info) { SHashObj* cname2points, SArray* stableSchemas, SSmlLinesInfo* info) {
for (int32_t i = 0; i < numPoints; ++i) { for (int32_t i = 0; i < numPoints; ++i) {
TAOS_SML_DATA_POINT * point = points + i; TAOS_SML_DATA_POINT * point = points + i;
uintptr_t valPointer = (uintptr_t)point; SSmlSTableSchema* stableSchema = taosArrayGet(stableSchemas, point->schemaIdx);
size_t* pSchemaIndex = taosHashGet(info->smlDataToSchema, &valPointer, sizeof(uintptr_t));
assert(pSchemaIndex != NULL);
SSmlSTableSchema* stableSchema = taosArrayGet(stableSchemas, *pSchemaIndex);
for (int j = 0; j < point->tagNum; ++j) { for (int j = 0; j < point->tagNum; ++j) {
TAOS_SML_KV* kv = point->tags + j; TAOS_SML_KV* kv = point->tags + j;
...@@ -963,10 +961,7 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam ...@@ -963,10 +961,7 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam
TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i); TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i);
for (int j = 0; j < pDataPoint->tagNum; ++j) { for (int j = 0; j < pDataPoint->tagNum; ++j) {
TAOS_SML_KV* kv = pDataPoint->tags + j; TAOS_SML_KV* kv = pDataPoint->tags + j;
uintptr_t valPointer = (uintptr_t)kv; tagKVs[kv->fieldSchemaIdx] = kv;
size_t* pFieldSchemaIdx = taosHashGet(info->smlDataToSchema, &valPointer, sizeof(uintptr_t));
assert(pFieldSchemaIdx != NULL);
tagKVs[*pFieldSchemaIdx] = kv;
} }
} }
...@@ -980,10 +975,7 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam ...@@ -980,10 +975,7 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam
for (int j = 0; j < numTags; ++j) { for (int j = 0; j < numTags; ++j) {
if (tagKVs[j] == NULL) continue; if (tagKVs[j] == NULL) continue;
TAOS_SML_KV* kv = tagKVs[j]; TAOS_SML_KV* kv = tagKVs[j];
uintptr_t valPointer = (uintptr_t)kv; TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx);
size_t* pFieldSchemaIdx = taosHashGet(info->smlDataToSchema, &valPointer, sizeof(uintptr_t));
assert(pFieldSchemaIdx != NULL);
TAOS_BIND* bind = taosArrayGet(tagBinds, *pFieldSchemaIdx);
bind->buffer_type = kv->type; bind->buffer_type = kv->type;
bind->length = malloc(sizeof(uintptr_t*)); bind->length = malloc(sizeof(uintptr_t*));
*bind->length = kv->length; *bind->length = kv->length;
...@@ -1026,10 +1018,7 @@ static int32_t applyChildTableFields(TAOS* taos, SSmlSTableSchema* sTableSchema, ...@@ -1026,10 +1018,7 @@ static int32_t applyChildTableFields(TAOS* taos, SSmlSTableSchema* sTableSchema,
} }
for (int j = 0; j < point->fieldNum; ++j) { for (int j = 0; j < point->fieldNum; ++j) {
TAOS_SML_KV* kv = point->fields + j; TAOS_SML_KV* kv = point->fields + j;
uintptr_t valPointer = (uintptr_t)kv; TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx;
size_t* pFieldSchemaIdx = taosHashGet(info->smlDataToSchema, &valPointer, sizeof(uintptr_t));
assert(pFieldSchemaIdx != NULL);
TAOS_BIND* bind = colBinds + *pFieldSchemaIdx;
bind->buffer_type = kv->type; bind->buffer_type = kv->type;
bind->length = malloc(sizeof(uintptr_t*)); bind->length = malloc(sizeof(uintptr_t*));
*bind->length = kv->length; *bind->length = kv->length;
...@@ -1067,10 +1056,7 @@ static int32_t applyDataPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t ...@@ -1067,10 +1056,7 @@ static int32_t applyDataPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t
SArray* cTablePoints = *pCTablePoints; SArray* cTablePoints = *pCTablePoints;
TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, 0); TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, 0);
uintptr_t valPointer = (uintptr_t)point; SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, point->schemaIdx);
size_t* pSchemaIndex = taosHashGet(info->smlDataToSchema, &valPointer, sizeof(uintptr_t));
assert(pSchemaIndex != NULL);
SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, *pSchemaIndex);
tscDebug("SML:0x%"PRIx64" apply child table tags. child table: %s", info->id, point->childTableName); tscDebug("SML:0x%"PRIx64" apply child table tags. child table: %s", info->id, point->childTableName);
code = applyChildTableTags(taos, point->childTableName, point->stableName, sTableSchema, cTablePoints, info); code = applyChildTableTags(taos, point->childTableName, point->stableName, sTableSchema, cTablePoints, info);
...@@ -1113,7 +1099,6 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine ...@@ -1113,7 +1099,6 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine
tscDebug("SML:0x%"PRIx64" taos_sml_insert. number of points: %d", info->id, numPoint); tscDebug("SML:0x%"PRIx64" taos_sml_insert. number of points: %d", info->id, numPoint);
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
info->smlDataToSchema = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, false);
tscDebug("SML:0x%"PRIx64" build data point schemas", info->id); tscDebug("SML:0x%"PRIx64" build data point schemas", info->id);
SArray* stableSchemas = taosArrayInit(32, sizeof(SSmlSTableSchema)); // SArray<STableColumnsSchema> SArray* stableSchemas = taosArrayInit(32, sizeof(SSmlSTableSchema)); // SArray<STableColumnsSchema>
...@@ -1143,11 +1128,10 @@ clean_up: ...@@ -1143,11 +1128,10 @@ clean_up:
taosArrayDestroy(schema->tags); taosArrayDestroy(schema->tags);
} }
taosArrayDestroy(stableSchemas); taosArrayDestroy(stableSchemas);
taosHashCleanup(info->smlDataToSchema);
return code; return code;
} }
int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { int tsc_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
SSmlLinesInfo* info = calloc(1, sizeof(SSmlLinesInfo)); SSmlLinesInfo* info = calloc(1, sizeof(SSmlLinesInfo));
info->id = genLinesSmlId(); info->id = genLinesSmlId();
int code = tscSmlInsert(taos, points, numPoint, info); int code = tscSmlInsert(taos, points, numPoint, info);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册