diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index ae0a6c775e413cb95198b246fb5b74e3da41aca0..744f6ca70bb5dbbb2b7233e188044ae626da61cd 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -341,6 +341,8 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result // TODO: iterator mem and tidex STermValueType s = kTypeValue; + int64_t st = taosGetTimestampUs(); + SIdxTempResult* tr = sIdxTempResultCreate(); if (0 == indexCacheSearch(cache, query, tr, &s)) { if (s == kTypeDeletion) { @@ -348,17 +350,23 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result // coloum already drop by other oper, no need to query tindex return 0; } else { + st = taosGetTimestampUs(); if (0 != indexTFileSearch(sIdx->tindex, query, tr)) { indexError("corrupt at index(TFile) col:%s val: %s", term->colName, term->colVal); goto END; } + int64_t tfCost = taosGetTimestampUs() - st; + indexInfo("tfile search cost: %" PRIu64 "us", tfCost); } } else { indexError("corrupt at index(cache) col:%s val: %s", term->colName, term->colVal); goto END; } + int64_t cost = taosGetTimestampUs() - st; + indexInfo("search cost: %" PRIu64 "us", cost); sIdxTempResultMergeTo(*result, tr); + sIdxTempResultDestroy(tr); return 0; END: diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index d3b25afdbcd7d198d738eb2a5bce2ba6b43a2e4b..e601740e350876d867262ad29e40d2735ca3e978 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -276,14 +276,19 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SI } else if (c->operaType == DEL_VALUE) { INDEX_MERGE_ADD_DEL(tr->added, tr->deled, c->uid) } + } else { + break; } - } + } else if (qtype == QUERY_PREFIX) { + } else if (qtype == QUERY_SUFFIX) { + } else if (qtype == QUERY_RANGE) } } tSkipListDestroyIter(iter); return 0; } int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result, STermValueType* s) { + int64_t st = taosGetTimestampUs(); if (cache == NULL) { return 0; } @@ -312,12 +317,14 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result // continue search in imm ret = indexQueryMem(imm, &ct, qtype, result, s); } + if (hasJson) { tfree(p); } indexMemUnRef(mem); indexMemUnRef(imm); + indexInfo("cache search, time cost %" PRIu64 "us", taosGetTimestampUs() - st); return ret; } diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index fd267fbf03d5742ab838581e735e7ba19f1a6254..2396b6af5b3de4b7b7fc9c50acc791f02be44c1d 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -189,8 +189,8 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON); EIndexQueryType qtype = query->qType; - SArray* result = taosArrayInit(16, sizeof(uint64_t)); - int ret = -1; + // SArray* result = taosArrayInit(16, sizeof(uint64_t)); + int ret = -1; // refactor to callback later if (qtype == QUERY_TERM) { uint64_t offset; @@ -200,11 +200,18 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul p = indexPackJsonData(term); sz = strlen(p); } + int64_t st = taosGetTimestampUs(); FstSlice key = fstSliceCreate(p, sz); if (fstGet(reader->fst, &key, &offset)) { - indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex", term->suid, term->colName, - term->colVal); - ret = tfileReaderLoadTableIds(reader, offset, result); + int64_t et = taosGetTimestampUs(); + int64_t cost = et - st; + indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us", + term->suid, term->colName, term->colVal, cost); + + ret = tfileReaderLoadTableIds(reader, offset, tr->total); + cost = taosGetTimestampUs() - et; + indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", term->suid, + term->colName, term->colVal, cost); } else { indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName, term->colVal); @@ -225,8 +232,8 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul } tfileReaderUnRef(reader); - taosArrayAddAll(tr->total, result); - taosArrayDestroy(result); + // taosArrayAddAll(tr->total, result); + // taosArrayDestroy(result); return ret; } @@ -391,6 +398,7 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTempResult* result return ret; } + int64_t st = taosGetTimestampUs(); IndexTFile* pTfile = tfile; SIndexTerm* term = query->term; @@ -399,6 +407,8 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTempResult* result if (reader == NULL) { return 0; } + int64_t cost = taosGetTimestampUs() - st; + indexInfo("index tfile stage 1 cost: %" PRId64 "", cost); return tfileReaderSearch(reader, query, result); } diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index ce3f7fe25e3e1b58cdf50fe6fda861edd5795b9e..90ed1b26b8295f965238171658aaa7f8b288edd8 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -768,7 +768,7 @@ class IndexObj { int64_t s = taosGetTimestampUs(); if (Search(mq, result) == 0) { int64_t e = taosGetTimestampUs(); - std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName + std::cout << "search one successfully and time cost:" << e - s << "us\tquery col:" << colName << "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl; } else { } @@ -1106,8 +1106,10 @@ TEST_F(IndexEnv2, testIndex_del) { } index->Del("tag10", "Hello", 12); index->Del("tag10", "Hello", 11); + EXPECT_EQ(98, index->SearchOne("tag10", "Hello")); index->WriteMultiMillonData("tag10", "xxxxxxxxxxxxxx", 100 * 10000); index->Del("tag10", "Hello", 17); + EXPECT_EQ(97, index->SearchOne("tag10", "Hello")); }