Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fac3fad4
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fac3fad4
编写于
2月 24, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
2月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10390 from taosdata/feature/indexUpdate
add multi tag query
上级
e1943fd6
930d09dc
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
273 addition
and
19 deletion
+273
-19
source/libs/index/inc/index_util.h
source/libs/index/inc/index_util.h
+22
-12
source/libs/index/src/index.c
source/libs/index/src/index.c
+11
-6
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+1
-1
source/libs/index/src/index_util.c
source/libs/index/src/index_util.c
+70
-0
source/libs/index/test/CMakeLists.txt
source/libs/index/test/CMakeLists.txt
+20
-0
source/libs/index/test/utilUT.cc
source/libs/index/test/utilUT.cc
+149
-0
未找到文件。
source/libs/index/inc/index_util.h
浏览文件 @
fac3fad4
...
...
@@ -15,36 +15,46 @@
#ifndef __INDEX_UTIL_H__
#define __INDEX_UTIL_H__
#include "tarray.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#define SERIALIZE_MEM_TO_BUF(buf, key, mem) \
do { \
memcpy((void
*)buf, (void
*)(&key->mem), sizeof(key->mem)); \
buf += sizeof(key->mem); \
#define SERIALIZE_MEM_TO_BUF(buf, key, mem)
\
do {
\
memcpy((void
*)buf, (void
*)(&key->mem), sizeof(key->mem)); \
buf += sizeof(key->mem);
\
} while (0)
#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \
do { \
memcpy((void
*)buf, (void*)key->mem, len);
\
memcpy((void
*)buf, (void *)key->mem, len);
\
buf += len; \
} while (0)
#define SERIALIZE_VAR_TO_BUF(buf, var, type) \
do { \
type c = var; \
assert(sizeof(type) == sizeof(c)); \
memcpy((void
*)buf, (void
*)&c, sizeof(c)); \
buf += sizeof(c); \
#define SERIALIZE_VAR_TO_BUF(buf, var, type)
\
do {
\
type c = var;
\
assert(sizeof(type) == sizeof(c));
\
memcpy((void
*)buf, (void
*)&c, sizeof(c)); \
buf += sizeof(c);
\
} while (0)
#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
do { \
memcpy((void
*)buf, (void*)var, len);
\
memcpy((void
*)buf, (void *)var, len);
\
buf += len; \
} while (0)
/* multi sorted result intersection
* input: [1, 2, 4, 5]
* [2, 3, 4, 5]
* [1, 4, 5]
* output:[4, 5]
*/
void
iIntersection
(
SArray
*
interResults
,
SArray
*
finalResult
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/index/src/index.c
浏览文件 @
fac3fad4
...
...
@@ -370,22 +370,27 @@ static void indexInterResultsDestroy(SArray* results) {
}
taosArrayDestroy
(
results
);
}
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
fResults
)
{
// refactor, merge interResults into fResults by oType
SArray
*
first
=
taosArrayGetP
(
interResults
,
0
);
taosArraySort
(
first
,
uidCompare
);
taosArrayRemoveDuplicate
(
first
,
uidCompare
,
NULL
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
interResults
);
i
--
)
{
SArray
*
t
=
taosArrayGetP
(
interResults
,
i
);
taosArraySort
(
t
,
uidCompare
);
taosArrayRemoveDuplicate
(
t
,
uidCompare
,
NULL
);
}
if
(
oType
==
MUST
)
{
iIntersection
(
interResults
,
fResults
);
// just one column index, enhance later
taosArrayAddAll
(
fResults
,
first
);
// taosArrayAddAll(fResults, interResults
);
}
else
if
(
oType
==
SHOULD
)
{
// just one column index, enhance later
taosArrayAddAll
(
fResults
,
first
);
taosArrayAddAll
(
fResults
,
interResults
);
// tag1 condistion || tag2 condition
}
else
if
(
oType
==
NOT
)
{
// just one column index, enhance later
taosArrayAddAll
(
fResults
,
first
);
taosArrayAddAll
(
fResults
,
interResults
);
// not use currently
}
return
0
;
...
...
source/libs/index/src/index_tfile.c
浏览文件 @
fac3fad4
...
...
@@ -371,7 +371,7 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) {
return
ret
;
}
IndexTFile
*
pTfile
=
(
IndexTFile
*
)
tfile
;
IndexTFile
*
pTfile
=
tfile
;
SIndexTerm
*
term
=
query
->
term
;
ICacheKey
key
=
{.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
};
...
...
source/libs/index/src/index_util.c
0 → 100644
浏览文件 @
fac3fad4
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "index_util.h"
#include "index.h"
typedef
struct
MergeIndex
{
int
idx
;
int
len
;
}
MergeIndex
;
static
int
iBinarySearch
(
SArray
*
arr
,
int
s
,
int
e
,
uint64_t
k
)
{
uint64_t
v
;
int32_t
m
;
while
(
s
<=
e
)
{
m
=
s
+
(
e
-
s
)
/
2
;
v
=
*
(
uint64_t
*
)
taosArrayGet
(
arr
,
m
);
if
(
v
>=
k
)
{
e
=
m
-
1
;
}
else
{
s
=
m
+
1
;
}
}
return
s
;
}
void
iIntersection
(
SArray
*
inters
,
SArray
*
final
)
{
int32_t
sz
=
taosArrayGetSize
(
inters
);
if
(
sz
<=
0
)
{
return
;
}
MergeIndex
*
mi
=
calloc
(
sz
,
sizeof
(
MergeIndex
));
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SArray
*
t
=
taosArrayGetP
(
inters
,
i
);
mi
[
i
].
len
=
taosArrayGetSize
(
t
);
mi
[
i
].
idx
=
0
;
}
SArray
*
base
=
taosArrayGetP
(
inters
,
0
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
base
);
i
++
)
{
uint64_t
tgt
=
*
(
uint64_t
*
)
taosArrayGet
(
base
,
i
);
bool
has
=
true
;
for
(
int
j
=
1
;
j
<
taosArrayGetSize
(
inters
);
j
++
)
{
SArray
*
oth
=
taosArrayGetP
(
inters
,
j
);
int
mid
=
iBinarySearch
(
oth
,
mi
[
j
].
idx
,
mi
[
j
].
len
-
1
,
tgt
);
if
(
mid
>=
0
&&
mid
<
mi
[
j
].
len
)
{
uint64_t
val
=
*
(
uint64_t
*
)
taosArrayGet
(
oth
,
mid
);
has
=
(
val
==
tgt
?
true
:
false
);
mi
[
j
].
idx
=
mid
;
}
else
{
has
=
false
;
}
}
if
(
has
==
true
)
{
taosArrayPush
(
final
,
&
tgt
);
}
}
tfree
(
mi
);
}
source/libs/index/test/CMakeLists.txt
浏览文件 @
fac3fad4
add_executable
(
indexTest
""
)
add_executable
(
fstTest
""
)
add_executable
(
fstUT
""
)
add_executable
(
UtilUT
""
)
target_sources
(
indexTest
PRIVATE
...
...
@@ -15,6 +16,11 @@ target_sources(fstUT
PRIVATE
"fstUT.cc"
)
target_sources
(
UtilUT
PRIVATE
"utilUT.cc"
)
target_include_directories
(
indexTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/index"
...
...
@@ -31,6 +37,12 @@ target_include_directories ( fstUT
"
${
CMAKE_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
UtilUT
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
indexTest
os
util
...
...
@@ -53,6 +65,14 @@ target_link_libraries (fstUT
index
)
target_link_libraries
(
UtilUT
os
util
common
gtest_main
index
)
#add_test(
# NAME index_test
...
...
source/libs/index/test/utilUT.cc
0 → 100644
浏览文件 @
fac3fad4
#include <gtest/gtest.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include "index.h"
#include "indexInt.h"
#include "index_cache.h"
#include "index_fst.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#include "index_tfile.h"
#include "index_util.h"
#include "tglobal.h"
#include "tskiplist.h"
#include "tutil.h"
class
UtilEnv
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
src
=
(
SArray
*
)
taosArrayInit
(
2
,
sizeof
(
void
*
));
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
SArray
*
m
=
taosArrayInit
(
10
,
sizeof
(
uint64_t
));
taosArrayPush
(
src
,
&
m
);
}
rslt
=
(
SArray
*
)
taosArrayInit
(
10
,
sizeof
(
uint64_t
));
}
virtual
void
TearDown
()
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
src
);
i
++
)
{
SArray
*
m
=
(
SArray
*
)
taosArrayGetP
(
src
,
i
);
taosArrayDestroy
(
m
);
}
taosArrayDestroy
(
src
);
}
SArray
*
src
;
SArray
*
rslt
;
};
static
void
clearSourceArray
(
SArray
*
p
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
p
);
i
++
)
{
SArray
*
m
=
(
SArray
*
)
taosArrayGetP
(
p
,
i
);
taosArrayClear
(
m
);
}
}
static
void
clearFinalArray
(
SArray
*
p
)
{
taosArrayClear
(
p
);
}
TEST_F
(
UtilEnv
,
intersectionSimpleResult
)
{
SArray
*
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
0
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
uint64_t
val
=
i
;
taosArrayPush
(
f
,
&
val
);
}
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
1
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
uint64_t
val
=
i
;
taosArrayPush
(
f
,
&
val
);
}
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
2
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
uint64_t
val
=
i
;
taosArrayPush
(
f
,
&
val
);
}
iIntersection
(
src
,
rslt
);
assert
(
taosArrayGetSize
(
rslt
)
==
10
);
clearSourceArray
(
src
);
clearFinalArray
(
rslt
);
}
TEST_F
(
UtilEnv
,
intersectMultiEmptyResult
)
{
SArray
*
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
0
);
for
(
int
i
=
10
;
i
<
20
;
i
++
)
{
uint64_t
val
=
i
;
taosArrayPush
(
f
,
&
val
);
}
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
1
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
uint64_t
val
=
i
;
taosArrayPush
(
f
,
&
val
);
}
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
2
);
for
(
int
i
=
20
;
i
<
30
;
i
++
)
{
uint64_t
val
=
i
;
taosArrayPush
(
f
,
&
val
);
}
// empty source
iIntersection
(
src
,
rslt
);
assert
(
taosArrayGetSize
(
rslt
)
==
0
);
clearSourceArray
(
src
);
clearFinalArray
(
rslt
);
}
TEST_F
(
UtilEnv
,
intersectSimpleEmpty
)
{
clearSourceArray
(
src
);
clearFinalArray
(
rslt
);
iIntersection
(
src
,
rslt
);
assert
(
taosArrayGetSize
(
rslt
)
==
0
);
}
TEST_F
(
UtilEnv
,
intersect01
)
{
clearSourceArray
(
src
);
clearFinalArray
(
rslt
);
uint64_t
arr1
[]
=
{
2
,
3
,
4
,
5
};
SArray
*
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
0
);
for
(
int
i
=
0
;
i
<
sizeof
(
arr1
)
/
sizeof
(
arr1
[
0
]);
i
++
)
{
taosArrayPush
(
f
,
&
arr1
[
i
]);
}
uint64_t
arr2
[]
=
{
1
,
2
,
3
,
5
};
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
1
);
for
(
int
i
=
0
;
i
<
sizeof
(
arr2
)
/
sizeof
(
arr2
[
0
]);
i
++
)
{
taosArrayPush
(
f
,
&
arr2
[
i
]);
}
uint64_t
arr3
[]
=
{
3
,
5
,
10
,
11
};
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
2
);
for
(
int
i
=
0
;
i
<
sizeof
(
arr3
)
/
sizeof
(
arr3
[
0
]);
i
++
)
{
taosArrayPush
(
f
,
&
arr3
[
i
]);
}
iIntersection
(
src
,
rslt
);
assert
(
taosArrayGetSize
(
rslt
)
==
2
);
}
TEST_F
(
UtilEnv
,
intersect02
)
{
clearSourceArray
(
src
);
clearFinalArray
(
rslt
);
uint64_t
arr1
[]
=
{
13
,
14
,
15
};
SArray
*
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
0
);
for
(
int
i
=
0
;
i
<
sizeof
(
arr1
)
/
sizeof
(
arr1
[
0
]);
i
++
)
{
taosArrayPush
(
f
,
&
arr1
[
i
]);
}
uint64_t
arr2
[]
=
{
8
,
10
,
12
,
13
};
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
1
);
for
(
int
i
=
0
;
i
<
sizeof
(
arr2
)
/
sizeof
(
arr2
[
0
]);
i
++
)
{
taosArrayPush
(
f
,
&
arr2
[
i
]);
}
uint64_t
arr3
[]
=
{
9
,
10
,
11
};
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
2
);
for
(
int
i
=
0
;
i
<
sizeof
(
arr3
)
/
sizeof
(
arr3
[
0
]);
i
++
)
{
taosArrayPush
(
f
,
&
arr3
[
i
]);
}
iIntersection
(
src
,
rslt
);
assert
(
taosArrayGetSize
(
rslt
)
==
0
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录