diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 46f2f7a93b6b9462e851a305cd9ae1f4b1f6c426..b9df2e88ce2a705f13936a9b9e5581c297d45306 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -109,17 +109,15 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { taosThreadMutexInit(&sIdx->mtx, NULL); sIdx->refId = indexAddRef(sIdx); - taosAcquireRef(indexRefMgt, sIdx->refId); + indexAcquireRef(sIdx->refId); *index = sIdx; - return 0; END: if (sIdx != NULL) { indexClose(sIdx); } - *index = NULL; return -1; } diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index d4231619ecfcc4ab3af728eda036e1e3e1a263a6..6cd00f76e1eeae2e1944224d170d416dfcd07049 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -463,7 +463,6 @@ int indexCacheSchedToMerge(IndexCache* pCache) { // schedMsg.thandle = taosMemoryCalloc(1, sizeof(int64_t)); // memcpy((char*)(schedMsg.thandle), (char*)&(pCache->index->refId), sizeof(int64_t)); schedMsg.msg = NULL; - indexAcquireRef(pCache->index->refId); taosScheduleTask(indexQhandle, &schedMsg); diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index ac26ed1fab73fed4b961c1c394f9cfc72562a968..3070659851a4b0b48a7027aa72bda45fa37a3a06 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -39,10 +39,36 @@ static TExeCond tCompareLessEqual(void* a, void* b, int8_t type) { } static TExeCond tCompareGreaterThan(void* a, void* b, int8_t type) { __compar_fn_t func = indexGetCompar(type); + if (type == TSDB_DATA_TYPE_INT) { + char* v1 = (char*)a; + char* v2 = (char*)b; + for (int i = 0; i < sizeof(int32_t); i++) { + if (v1[i] == '0') { + v1[i] = 0; + } + if (v2[i] == '0') { + v2[i] = 0; + } + } + return tDoCommpare(func, QUERY_GREATER_THAN, v1, v2); + } return tDoCommpare(func, QUERY_GREATER_THAN, a, b); } static TExeCond tCompareGreaterEqual(void* a, void* b, int8_t type) { __compar_fn_t func = indexGetCompar(type); + if (type == TSDB_DATA_TYPE_INT) { + char* v1 = (char*)a; + char* v2 = (char*)b; + for (int i = 0; i < sizeof(int32_t); i++) { + if (v1[i] == '0') { + v1[i] = 0; + } + if (v2[i] == '0') { + v2[i] = 0; + } + } + return tDoCommpare(func, QUERY_GREATER_EQUAL, v1, v2); + } return tDoCommpare(func, QUERY_GREATER_EQUAL, a, b); } @@ -216,7 +242,7 @@ int32_t indexConvertData(void* src, int8_t type, void** dst) { } *dst = *dst - tlen; if (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR && type != TSDB_DATA_TYPE_VARBINARY && - type == TSDB_DATA_TYPE_VARCHAR) { + type != TSDB_DATA_TYPE_VARCHAR) { uint8_t* p = *dst; for (int i = 0; i < tlen; i++) { if (p[i] == 0) { diff --git a/source/libs/index/test/jsonUT.cc b/source/libs/index/test/jsonUT.cc index 3de7cb66f20980deef0257ab54310d51b81beee1..eb1eed403eadff45ab6a305611df3182a8a938fd 100644 --- a/source/libs/index/test/jsonUT.cc +++ b/source/libs/index/test/jsonUT.cc @@ -204,9 +204,10 @@ TEST_F(JsonEnv, testWriteMillonData) { TEST_F(JsonEnv, testWriteJsonNumberData) { { std::string colName("test"); - std::string colVal("10"); + // std::string colVal("10"); + int val = 10; SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + (const char*)&val, sizeof(val)); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); @@ -217,9 +218,9 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { } { std::string colName("test2"); - std::string colVal("20"); + int val = 20; SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + (const char*)&val, sizeof(val)); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); @@ -229,10 +230,10 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { indexMultiTermDestroy(terms); } { - std::string colName("test2"); - std::string colVal("15"); + std::string colName("test"); + int val = 15; SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + (const char*)&val, sizeof(val)); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); @@ -243,9 +244,9 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { } { std::string colName("test2"); - std::string colVal("15"); + const char* val = "test"; SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + (const char*)val, strlen(val)); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); @@ -255,12 +256,11 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { indexMultiTermDestroy(terms); } { - std::string colName("test"); - std::string colVal("10"); - + std::string colName("test"); + int val = 15; SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); - SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), - colVal.size()); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_TERM); @@ -270,11 +270,11 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { } { std::string colName("test"); - std::string colVal("10"); + int val = 15; SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); - SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), - colVal.size()); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN); @@ -284,11 +284,12 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { } { std::string colName("test"); - std::string colVal("10"); + int val = 10; + ; SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); - SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), - colVal.size()); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(int)); SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL); @@ -298,11 +299,12 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { } { std::string colName("test"); - std::string colVal("10"); + int val = 10; + // std::string colVal("10"); SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); - SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), - colVal.size()); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_LESS_THAN); @@ -312,11 +314,12 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { } { std::string colName("test"); - std::string colVal("10"); + int val = 10; + // std::string colVal("10"); SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); - SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), - colVal.size()); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_LESS_EQUAL); @@ -329,9 +332,9 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { TEST_F(JsonEnv, testWriteJsonTfileAndCache) { { std::string colName("test1"); - std::string colVal("10"); + int val = 10; SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + (const char*)&val, sizeof(val)); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); @@ -355,11 +358,11 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache) { } { std::string colName("test1"); - std::string colVal("10"); + int val = 10; SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); - SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), - colVal.size()); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_TERM); @@ -369,11 +372,11 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache) { } { std::string colName("test1"); - std::string colVal("10"); + int val = 10; SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); - SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), - colVal.size()); + SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(int)); SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN); @@ -426,6 +429,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache) { { std::string colName("other_column"); std::string colVal("100"); + SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), colVal.c_str(), colVal.size());