From 1f5ad0f1ec433628b4b7dede710e313fa44af435 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 8 Jun 2022 18:29:51 +0800 Subject: [PATCH] enh: index support between --- source/libs/index/inc/indexComm.h | 9 ++++---- source/libs/index/src/.indexFilter.c.swo | Bin 0 -> 16384 bytes source/libs/index/src/index.c | 4 ++-- source/libs/index/src/indexComm.c | 27 ++++++++++++++--------- source/libs/index/src/indexFilter.c | 2 ++ source/libs/index/src/indexTfile.c | 9 ++------ source/libs/index/test/utilUT.cc | 4 ++-- tests/script/tsim/stable/tag_filter.sim | 2 +- 8 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 source/libs/index/src/.indexFilter.c.swo diff --git a/source/libs/index/inc/indexComm.h b/source/libs/index/inc/indexComm.h index c338300b57..bcf76b4f20 100644 --- a/source/libs/index/inc/indexComm.h +++ b/source/libs/index/inc/indexComm.h @@ -39,13 +39,14 @@ TExeCond tDoCompare(__compar_fn_t func, int8_t cmpType, void* a, void* b); _cache_range_compare indexGetCompare(RangeType ty); -int32_t indexConvertData(void* src, int8_t type, void** dst); -int32_t indexConvertDataToStr(void* src, int8_t type, void** dst); +int32_t idxConvertData(void* src, int8_t type, void** dst); +int32_t idxConvertDataToStr(void* src, int8_t type, void** dst); -int32_t indexGetDataByteLen(int8_t type); +int32_t idxGetDataByteLen(int8_t type); -char* indexInt2str(int64_t val, char* dst, int radix); +char* idxInt2str(int64_t val, char* dst, int radix); +int idxUidCompare(const void* a, const void* b); #ifdef __cplusplus } #endif diff --git a/source/libs/index/src/.indexFilter.c.swo b/source/libs/index/src/.indexFilter.c.swo new file mode 100644 index 0000000000000000000000000000000000000000..c61d5e7793e4ca891ef2b8cc1e5b63c72f1431a8 GIT binary patch literal 16384 zcmeHNU5q4E6)r#pTo(|GBpSkHfK7MXGrha)!m`6I)b@1G6x&nX+g;5%L1?SHZci6m zUDedj{IIMB4AEdBFFcxv3DFl;i80X^<8RccG2sFKP%#=!e31u?8gvMGd;s1 z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A#{YeO<7lLZN7BLm0;gOFVo z(b4u$k4P9xOYRdH#4U1ggA+ljYFVn|WMrh8XQI*ERti*RQZJ%mJeMR|!^lO`=|pr_ z-f73=e8hyd5`dx%1f88jHU!_fzD$nfSv)6{$&}!^(KtIULnYlz#dJw$GDi^R*pG0p zo1xgA@&f-+HQPC)}8$Y*L=ZS?BD&fi&$}RnsY_cVfjTHN<9*X(cpG z3d~XR4VkfH2vmaE_&O&%&k^-X8Xjc6=i=iVjt%qn?nlY0IEjML+1Mp^O=O2G;Zb7^AVZrG+!H&=tD!_8NQICbi`64GP*NOW zpNFsm5Ce7=c-O>R7pkFzEBR%)&kL%d%9mv)v_+^AHmz$Sd7o!XYGVm*xK*hZPm1xu zdl6|!42E&e3d-=ue)tZVMWxY^LWSqRly>1`>MKa01>+l^m|UC&8>;1&#gZ0}zd;;1 z3KP4Ob~1hh#MZEr0VdN=)azfc!im!Xsw?#*5xw2>4;F%O_Ba}1pD3LGE0quE_)ol9 Bh%x{G literal 0 HcmV?d00001 diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 058f3c1915..a5b158c00c 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -289,7 +289,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy tm->nColName = nColName; char* buf = NULL; - int32_t len = indexConvertDataToStr((void*)colVal, INDEX_TYPE_GET_TYPE(colType), (void**)&buf); + int32_t len = idxConvertDataToStr((void*)colVal, INDEX_TYPE_GET_TYPE(colType), (void**)&buf); assert(len != -1); tm->colVal = buf; @@ -625,7 +625,7 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf) { char* p = buf; char tbuf[65] = {0}; - indexInt2str((int64_t)key->suid, tbuf, 0); + idxInt2str((int64_t)key->suid, tbuf, 0); SERIALIZE_STR_VAR_TO_BUF(buf, tbuf, strlen(tbuf)); SERIALIZE_VAR_TO_BUF(buf, '_', char); diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index d30147d70f..ca9d429e68 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -48,7 +48,7 @@ char JSON_COLUMN[] = "JSON"; char JSON_VALUE_DELIM = '&'; -char* indexInt2str(int64_t val, char* dst, int radix) { +char* idxInt2str(int64_t val, char* dst, int radix) { char buffer[65] = {0}; char* p; int64_t new_val; @@ -257,7 +257,12 @@ char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) { return buf; } -int32_t indexConvertData(void* src, int8_t type, void** dst) { +int idxUidCompare(const void* a, const void* b) { + uint64_t l = *(uint64_t*)a; + uint64_t r = *(uint64_t*)b; + return l - r; +} +int32_t idxConvertData(void* src, int8_t type, void** dst) { int tlen = -1; switch (type) { case TSDB_DATA_TYPE_TIMESTAMP: @@ -342,44 +347,44 @@ int32_t indexConvertData(void* src, int8_t type, void** dst) { // indexMayFillNumbericData(*dst, tlen); return tlen; } -int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { +int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { int tlen = tDataTypes[type].bytes; int32_t bufSize = 64; switch (type) { case TSDB_DATA_TYPE_TIMESTAMP: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int64_t*)src, *dst, -1); + idxInt2str(*(int64_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_UTINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint8_t*)src, *dst, 1); + idxInt2str(*(uint8_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_TINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int8_t*)src, *dst, 1); + idxInt2str(*(int8_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_SMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int16_t*)src, *dst, -1); + idxInt2str(*(int16_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_USMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint16_t*)src, *dst, -1); + idxInt2str(*(uint16_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_INT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int32_t*)src, *dst, -1); + idxInt2str(*(int32_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_UINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint32_t*)src, *dst, 1); + idxInt2str(*(uint32_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BIGINT: @@ -389,7 +394,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { break; case TSDB_DATA_TYPE_UBIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint64_t*)src, *dst, 1); + idxInt2str(*(uint64_t*)src, *dst, 1); tlen = strlen(*dst); case TSDB_DATA_TYPE_FLOAT: *dst = taosMemoryCalloc(1, bufSize + 1); diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index fd2d6a5c8b..2cf83b52e4 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -547,6 +547,8 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou } else if (node->condType == LOGIC_COND_TYPE_NOT) { // taosArrayAddAll(output->result, params[m].result); } + taosArraySort(output->result, idxUidCompare); + taosArrayRemoveDuplicate(output->result, idxUidCompare, NULL); } } else { for (int32_t m = 0; m < node->pParameterList->length; m++) { diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 0145df4676..9600b1172e 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -578,8 +578,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // ugly code, refactor later for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); - taosArraySort(v->tableId, tfileUidCompare); - taosArrayRemoveDuplicate(v->tableId, tfileUidCompare, NULL); + taosArraySort(v->tableId, idxUidCompare); + taosArrayRemoveDuplicate(v->tableId, idxUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } @@ -791,11 +791,6 @@ TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { return rd; } -static int tfileUidCompare(const void* a, const void* b) { - uint64_t l = *(uint64_t*)a; - uint64_t r = *(uint64_t*)b; - return l - r; -} static int tfileStrCompare(const void* a, const void* b) { int ret = strcmp((char*)a, (char*)b); if (ret == 0) { diff --git a/source/libs/index/test/utilUT.cc b/source/libs/index/test/utilUT.cc index 4a30160244..6858d31325 100644 --- a/source/libs/index/test/utilUT.cc +++ b/source/libs/index/test/utilUT.cc @@ -327,13 +327,13 @@ TEST_F(UtilEnv, testFill) { for (int i = 0; i < 1000000; i++) { int64_t val = i; char buf[65] = {0}; - indexInt2str(val, buf, 1); + idxInt2str(val, buf, 1); EXPECT_EQ(val, taosStr2int64(buf)); } for (int i = 0; i < 1000000; i++) { int64_t val = 0 - i; char buf[65] = {0}; - indexInt2str(val, buf, -1); + idxInt2str(val, buf, -1); EXPECT_EQ(val, taosStr2int64(buf)); } } diff --git a/tests/script/tsim/stable/tag_filter.sim b/tests/script/tsim/stable/tag_filter.sim index c8edfb1ee3..9a2c8abc57 100644 --- a/tests/script/tsim/stable/tag_filter.sim +++ b/tests/script/tsim/stable/tag_filter.sim @@ -25,7 +25,7 @@ sql insert into db.ctb5 values(now, 5, "2") sql create table db.ctb6 using db.stb tags(6, "102") sql insert into db.ctb6 values(now, 6, "2") - +// int sql select * from db.stb where t1 = 1 if $rows != 1 then return -1