diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 0c2e9e6b44..eea30bfb03 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -306,6 +306,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, src, sizeof(float)); *dst = taosMemoryCalloc(1, tlen + 1); tlen = taosEncodeBinary(dst, src, sizeof(float)); + *dst = *dst - tlen; break; case TSDB_DATA_TYPE_UINT: *dst = taosMemoryCalloc(1, sizeof(int64_t) + 1); @@ -319,6 +320,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, src, sizeof(double)); *dst = taosMemoryCalloc(1, tlen + 1); tlen = taosEncodeBinary(dst, src, sizeof(double)); + *dst = *dst - tlen; break; case TSDB_DATA_TYPE_UBIGINT: assert(0); diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index bc3ecea7a5..e2975fb7bc 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -1324,7 +1324,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) { taosArrayPop(sws->inp); } - streamStateDestroy(p); + // streamStateDestroy(p); continue; } FstTransition trn; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index b787da117d..6c59986744 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -410,8 +410,9 @@ static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total); cost = taosGetTimestampUs() - et; - indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid, - tem->colName, tem->colVal, cost); + indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, offset: %" PRIu64 + ", size: %d, time cost: %" PRIu64 "us", + tem->suid, tem->colName, tem->colVal, offset, (int)taosArrayGetSize(tr->total), cost); } fstSliceDestroy(&key); return 0; @@ -941,7 +942,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* // TODO(yihao): opt later WriterCtx* ctx = reader->ctx; // add block cache - char block[1024] = {0}; + char block[4096] = {0}; int32_t nread = ctx->readFrom(ctx, block, sizeof(block), offset); assert(nread >= sizeof(uint32_t)); diff --git a/source/libs/index/test/jsonUT.cc b/source/libs/index/test/jsonUT.cc index d6ff7264d7..ff349b9b24 100644 --- a/source/libs/index/test/jsonUT.cc +++ b/source/libs/index/test/jsonUT.cc @@ -56,6 +56,29 @@ class JsonEnv : public ::testing::Test { SIndexJson* index; }; +static void WriteData(SIndexJson* index, const std::string& colName, int8_t dtype, void* data, int dlen, int tableId, + int8_t operType = ADD_VALUE) { + SIndexTerm* term = + indexTermCreate(1, (SIndexOperOnColumn)operType, dtype, colName.c_str(), colName.size(), (const char*)data, dlen); + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + tIndexJsonPut(index, terms, (int64_t)tableId); + + indexMultiTermDestroy(terms); +} +static void Search(SIndexJson* index, const std::string& colNam, int8_t dtype, void* data, int dlen, int8_t filterType, + SArray** result) { + std::string colName(colNam); + + SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, dtype, colName.c_str(), colName.size(), (const char*)data, dlen); + + SArray* res = taosArrayInit(1, sizeof(uint64_t)); + indexMultiTermQueryAdd(mq, q, (EIndexQueryType)filterType); + tIndexJsonSearch(index, mq, res); + indexMultiTermQueryDestroy(mq); + *result = res; +} TEST_F(JsonEnv, testWrite) { { std::string colName("test"); @@ -329,7 +352,7 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { } } -TEST_F(JsonEnv, testWriteJsonTfileAndCache) { +TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { { std::string colName("test1"); int val = 10; @@ -485,3 +508,73 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache) { indexMultiTermQueryDestroy(mq); } } +TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT2) { + { + int val = 10; + std::string colName("test1"); + for (int i = 0; i < 10000; i++) { + val += 1; + WriteData(index, colName, TSDB_DATA_TYPE_INT, &val, sizeof(val), i); + } + } + { + int val = 10; + std::string colName("test2xxx"); + std::string colVal("xxxxxxxxxxxxxxx"); + for (int i = 0; i < 100000; i++) { + val += 1; + WriteData(index, colName, TSDB_DATA_TYPE_BINARY, (void*)(colVal.c_str()), colVal.size(), i); + } + } + { + SArray* res = NULL; + std::string colName("test1"); + int val = 9; + Search(index, colName, TSDB_DATA_TYPE_INT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res); + EXPECT_EQ(10000, taosArrayGetSize(res)); + } + { + SArray* res = NULL; + std::string colName("test2xxx"); + std::string colVal("xxxxxxxxxxxxxxx"); + Search(index, colName, TSDB_DATA_TYPE_BINARY, (void*)(colVal.c_str()), colVal.size(), QUERY_TERM, &res); + EXPECT_EQ(100000, taosArrayGetSize(res)); + } +} +TEST_F(JsonEnv, testWriteJsonTfileAndCache_FLOAT) { + { + float val = 10.0; + std::string colName("test1"); + for (int i = 0; i < 1000; i++) { + WriteData(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), i); + } + } + { + float val = 2.0; + std::string colName("test1"); + for (int i = 0; i < 1000; i++) { + WriteData(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), i); + } + } + { + SArray* res = NULL; + std::string colName("test1"); + float val = 1.9; + Search(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res); + EXPECT_EQ(2000, taosArrayGetSize(res)); + } + { + SArray* res = NULL; + std::string colName("test1"); + float val = 2.1; + Search(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res); + EXPECT_EQ(1000, taosArrayGetSize(res)); + } + { + std::string colName("test1"); + SArray* res = NULL; + float val = 2.1; + Search(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res); + EXPECT_EQ(1000, taosArrayGetSize(res)); + } +}