Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
69f25dbf
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1181
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
69f25dbf
编写于
7月 09, 2021
作者:
W
wpan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support condition rewrite
上级
014740de
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
1088 addition
and
324 deletion
+1088
-324
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+1
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+16
-0
src/query/inc/qFilter.h
src/query/inc/qFilter.h
+57
-23
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-1
src/query/src/qFilter.c
src/query/src/qFilter.c
+851
-204
src/query/tests/rangeMergeTest.cpp
src/query/tests/rangeMergeTest.cpp
+152
-91
src/util/inc/hash.h
src/util/inc/hash.h
+3
-1
src/util/src/hash.c
src/util/src/hash.c
+4
-0
src/util/src/tcompare.c
src/util/src/tcompare.c
+3
-3
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
69f25dbf
...
...
@@ -5006,7 +5006,7 @@ static int32_t getQueryTimeRange(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr
goto
_ret
;
}
ret
=
filterInitFromTree
(
p
,
&
filter
);
ret
=
filterInitFromTree
(
p
,
&
filter
,
FILTER_NO_REWRITE
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
goto
_ret
;
}
...
...
src/client/src/tscUtil.c
浏览文件 @
69f25dbf
...
...
@@ -81,7 +81,23 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le
*
(
str
+
bufSize
+
1
)
=
'"'
;
n
=
bufSize
+
2
;
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
n
=
sprintf
(
str
,
"%d"
,
*
(
uint8_t
*
)
buf
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
n
=
sprintf
(
str
,
"%d"
,
*
(
uint16_t
*
)
buf
);
break
;
case
TSDB_DATA_TYPE_UINT
:
n
=
sprintf
(
str
,
"%u"
,
*
(
uint32_t
*
)
buf
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
n
=
sprintf
(
str
,
"%"
PRIu64
,
*
(
uint64_t
*
)
buf
);
break
;
default:
tscError
(
"unsupported type:%d"
,
type
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
...
...
src/query/inc/qFilter.h
浏览文件 @
69f25dbf
...
...
@@ -22,19 +22,24 @@ extern "C" {
#include "texpr.h"
#define FILTER_DEFAULT_GROUP_SIZE 4
#define FILTER_DEFAULT_UNIT_SIZE 4
#define FILTER_DEFAULT_FIELD_SIZE 4
#define FILTER_DEFAULT_GROUP_UNIT_SIZE 2
enum
{
F_FIELD_COLUMN
=
0
,
F_FIELD_VALUE
,
F_FIELD_MAX
FLD_TYPE_COLUMN
=
1
,
FLD_TYPE_VALUE
=
2
,
FLD_TYPE_MAX
=
3
,
FLD_DESC_NO_FREE
=
4
,
FLD_DATA_NO_FREE
=
8
,
};
enum
{
MR_ST_START
=
1
,
MR_ST_FIN
=
2
,
MR_ALL
=
4
,
MR_NONE
=
8
,
};
enum
{
...
...
@@ -46,17 +51,17 @@ enum {
RA_NULL
=
2
,
};
enum
{
FILTER_ALL
=
1
,
FILTER_NONE
=
2
,
FILTER_NO_REWRITE
=
4
,
};
typedef
struct
OptrStr
{
uint16_t
optr
;
char
*
str
;
}
OptrStr
;
typedef
struct
SFilterColRange
{
uint16_t
idx
;
//column field idx
int64_t
s
;
int64_t
e
;
}
SFilterColRange
;
typedef
struct
SFilterRange
{
char
sflag
;
char
eflag
;
...
...
@@ -64,6 +69,13 @@ typedef struct SFilterRange {
int64_t
e
;
}
SFilterRange
;
typedef
struct
SFilterColRange
{
uint16_t
idx
;
//column field idx
bool
isNull
;
bool
notNull
;
SFilterRange
ra
;
}
SFilterColRange
;
typedef
struct
SFilterRangeNode
{
struct
SFilterRangeNode
*
prev
;
...
...
@@ -81,7 +93,7 @@ typedef struct SFilterRMCtx {
}
SFilterRMCtx
;
typedef
struct
SFilterField
{
uint16_t
type
;
uint16_t
flag
;
void
*
desc
;
void
*
data
;
int64_t
range
[];
...
...
@@ -99,13 +111,21 @@ typedef struct SFilterFieldId {
}
SFilterFieldId
;
typedef
struct
SFilterGroup
{
uint16_t
unitSize
;
uint16_t
unitNum
;
uint16_t
*
unitIdxs
;
uint8_t
*
unitFlags
;
// !unit result
}
SFilterGroup
;
typedef
struct
SFilterGroupCtx
{
uint16_t
num
;
int32_t
*
col
;
SArray
*
colRange
;
}
SFilterGroupCtx
;
typedef
struct
SFilterCompare
{
__compar_fn_t
pCompareFunc
;
int32_t
type
;
uint8_t
optr
;
}
SFilterCompare
;
...
...
@@ -116,10 +136,11 @@ typedef struct SFilterUnit {
}
SFilterUnit
;
typedef
struct
SFilterInfo
{
uint32_t
flags
;
uint16_t
unitSize
;
uint16_t
unitNum
;
uint16_t
groupNum
;
SFilterFields
fields
[
F
_FIELD
_MAX
];
SFilterFields
fields
[
F
LD_TYPE
_MAX
];
SFilterGroup
*
groups
;
SFilterUnit
*
units
;
uint8_t
*
unitRes
;
// result
...
...
@@ -133,16 +154,24 @@ typedef struct SFilterInfo {
#define MR_EMPTY_RES(ctx) (ctx->rs == NULL)
#define MR_GET_FLAG(st, f) (st & f)
#define MR_SET_FLAG(st, f) st |= (f)
#define SET_OPTR(o) do {if (o == TSDB_RELATION_ISNULL) { isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { notnull = true; } } while (0)
#define CHK_OPTR() (isnull == true && notnull == true)
#define FILTER_GET_FLAG(st, f) (st & f)
#define FILTER_SET_FLAG(st, f) st |= (f)
#define FILTER_CLR_FLAG(st, f) st &= (~f)
#define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src)
#define RESET_RANGE(ctx, r) do { r->next = ctx->rf; ctx->rf = r; } while (0)
#define FREE_RANGE(ctx, r) do { if (r->prev) { r->prev->next = r->next; } else { ctx->rs = r->next;} if (r->next) { r->next->prev = r->prev; } RESET_RANGE(ctx, r); } while (0)
#define FREE_FROM_RANGE(ctx, r) do { if (r->prev) { r->prev->next = NULL; } else { ctx->rs = NULL;} while (r) {SFilterRangeNode *n = r->next; RESET_RANGE(ctx, r); r = n; } } while (0)
#define INSERT_RANGE(ctx, r, t, s, e) do { SFilterRangeNode *n = filterNewRange(ctx, t, s, e); n->prev = r->prev; if (r->prev) { r->prev->next = n; } else { ctx->rs = n; } r->prev = n; n->next = r; } while (0)
#define APPEND_RANGE(ctx, r, t, s, e) do { SFilterRangeNode *n = filterNewRange(ctx, t, s, e); n->prev = r; if (r) { r->next = n; } else { ctx->rs = n; } } while (0)
#define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RA_EXCLUDE) || FILTER_GET_FLAG(eflag,RA_EXCLUDE))))
#define FILTER_COPY_RA(dst, src) do { (dst)->sflag = (src)->sflag; (dst)->eflag = (src)->eflag; (dst)->s = (src)->s; (dst)->e = (src)->e; } while (0)
#define RESET_RANGE(ctx, r) do { (r)->next = (ctx)->rf; (ctx)->rf = r; } while (0)
#define FREE_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = (r)->next; } else { (ctx)->rs = (r)->next;} if ((r)->next) { (r)->next->prev = (r)->prev; } RESET_RANGE(ctx, r); } while (0)
#define FREE_FROM_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = NULL; } else { (ctx)->rs = NULL;} while (r) {SFilterRangeNode *n = (r)->next; RESET_RANGE(ctx, r); r = n; } } while (0)
#define INSERT_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r)->prev; if ((r)->prev) { (r)->prev->next = n; } else { (ctx)->rs = n; } (r)->prev = n; n->next = r; } while (0)
#define APPEND_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r); if (r) { (r)->next = n; } else { (ctx)->rs = n; } } while (0)
#define ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0)
#define ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); return _code; } } while (0)
...
...
@@ -155,16 +184,21 @@ typedef struct SFilterInfo {
#define CHK_LRET(c, r,...) do { if (c) { qError(__VA_ARGS__); return r; } } while (0)
#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx]))
#define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx]))
#define FILTER_GET_COL_FIELD_TYPE(fi) (((SSchema *)((fi)->desc))->type)
#define FILTER_GET_COL_FIELD_DESC(fi) ((SSchema *)((fi)->desc))
#define FILTER_GET_COL_FIELD_DATA(fi, ri) ((fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri))
#define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType)
#define FILTER_GET_VAL_FIELD_DATA(fi) ((fi)->data)
#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX)
#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units
[(g)->unitIdxs[uid]
])
#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units
+ (g)->unitIdxs[uid
])
#define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left)
#define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right)
#define FILTER_UNIT_DATA_TYPE(i, u) FILTER_GET_COL_FIELD_TYPE(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_VAL(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u))
#define FILTER_UNIT_DATA_TYPE(u) ((u)->compare.type)
#define FILTER_UNIT_COL_DESC(i, u) FILTER_GET_COL_FIELD_DESC(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_COL_DATA(i, u, ri) FILTER_GET_COL_FIELD_DATA(FILTER_UNIT_LEFT_FIELD(i, u), ri)
#define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u))
#define FILTER_UNIT_COL_IDX(u) ((u)->left.idx)
#define FILTER_UNIT_OPTR(u) ((u)->compare.optr)
...
...
@@ -177,12 +211,12 @@ typedef struct SFilterInfo {
typedef
int32_t
(
*
filter_desc_compare_func
)(
const
void
*
,
const
void
*
);
extern
int32_t
filterInitFromTree
(
tExprNode
*
tree
,
SFilterInfo
**
pinfo
);
extern
int32_t
filterInitFromTree
(
tExprNode
*
tree
,
SFilterInfo
**
pinfo
,
uint32_t
options
);
extern
bool
filterExecute
(
SFilterInfo
*
info
,
int32_t
numOfRows
,
int8_t
*
p
);
extern
int32_t
filterSetColFieldData
(
SFilterInfo
*
info
,
int16_t
colId
,
void
*
data
);
extern
void
*
filterInitMergeRange
(
int32_t
type
,
int32_t
options
);
extern
int32_t
filterGetMergeRangeNum
(
void
*
h
,
int32_t
*
num
);
extern
int32_t
filterGetMergeRangeRes
(
void
*
h
,
void
*
s
,
void
*
e
);
extern
int32_t
filterGetMergeRangeRes
(
void
*
h
,
SFilterRange
*
ra
);
extern
int32_t
filterFreeMergeRange
(
void
*
h
);
extern
int32_t
filterGetTimeRange
(
SFilterInfo
*
info
,
STimeWindow
*
win
);
#ifdef __cplusplus
...
...
src/query/src/qExecutor.c
浏览文件 @
69f25dbf
...
...
@@ -6966,7 +6966,7 @@ int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) {
return
TSDB_CODE_QRY_APP_ERROR
;
}
int32_t
ret
=
filterInitFromTree
(
expr
,
pFilters
);
int32_t
ret
=
filterInitFromTree
(
expr
,
pFilters
,
0
);
tExprTreeDestroy
(
expr
,
NULL
);
return
ret
;
...
...
src/query/src/qFilter.c
浏览文件 @
69f25dbf
此差异已折叠。
点击以展开。
src/query/tests/rangeMergeTest.cpp
浏览文件 @
69f25dbf
...
...
@@ -20,7 +20,7 @@ namespace {
void
intDataTest
()
{
printf
(
"running %s
\n
"
,
__FUNCTION__
);
int32_t
asize
=
0
;
SFilterRange
ra
=
{
0
};
SFilterRange
ra
[
10
]
=
{
0
};
int64_t
*
s
=
NULL
;
int64_t
*
e
=
NULL
;
int64_t
s0
[
3
]
=
{
-
100
,
1
,
3
};
...
...
@@ -34,179 +34,191 @@ void intDataTest() {
int64_t
s4
[
2
]
=
{
10
,
0
};
int64_t
e4
[
2
]
=
{
20
,
5
};
int64_t
s5
[
3
]
=
{
0
,
6
,
7
};
int64_t
e5
[
5
]
=
{
4
,
10
,
20
};
int64_t
e5
[
3
]
=
{
4
,
10
,
20
};
int64_t
rs
[
10
];
int64_t
re
[
10
];
int32_t
num
=
0
;
void
*
h
=
NULL
;
s
=
s0
;
e
=
e0
;
asize
=
sizeof
(
s0
)
/
sizeof
(
s
[
0
]);
void
*
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
asize
=
sizeof
(
s0
)
/
sizeof
(
s
[
0
]);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_AND
);
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
0
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
3
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
-
100
);
ASSERT_EQ
(
r
e
[
0
]
,
0
);
ASSERT_EQ
(
r
s
[
1
]
,
1
);
ASSERT_EQ
(
r
e
[
1
]
,
2
);
ASSERT_EQ
(
r
s
[
2
]
,
3
);
ASSERT_EQ
(
r
e
[
2
]
,
4
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
-
100
);
ASSERT_EQ
(
r
a
[
0
].
e
,
0
);
ASSERT_EQ
(
r
a
[
1
].
s
,
1
);
ASSERT_EQ
(
r
a
[
1
].
e
,
2
);
ASSERT_EQ
(
r
a
[
2
].
s
,
3
);
ASSERT_EQ
(
r
a
[
2
].
e
,
4
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
MR_OPT_TS
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
1
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
-
100
);
ASSERT_EQ
(
r
e
[
0
]
,
4
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
-
100
);
ASSERT_EQ
(
r
a
[
0
].
e
,
4
);
filterFreeMergeRange
(
h
);
s
=
s1
;
e
=
e1
;
asize
=
sizeof
(
s1
)
/
sizeof
(
s
[
0
]);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_AND
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
1
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
3
);
ASSERT_EQ
(
r
e
[
0
]
,
4
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
3
);
ASSERT_EQ
(
r
a
[
0
].
e
,
4
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
1
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
INT64_MIN
);
ASSERT_EQ
(
r
e
[
0
]
,
100
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
INT64_MIN
);
ASSERT_EQ
(
r
a
[
0
].
e
,
100
);
filterFreeMergeRange
(
h
);
s
=
s2
;
e
=
e2
;
asize
=
sizeof
(
s2
)
/
sizeof
(
s
[
0
]);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_AND
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
0
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
1
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
1
);
ASSERT_EQ
(
r
e
[
0
]
,
120
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
1
);
ASSERT_EQ
(
r
a
[
0
].
e
,
120
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
i
%
2
?
TSDB_RELATION_OR
:
TSDB_RELATION_AND
);
filterAddMergeRange
(
h
,
ra
,
i
%
2
?
TSDB_RELATION_OR
:
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
0
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
i
%
2
?
TSDB_RELATION_AND
:
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
i
%
2
?
TSDB_RELATION_AND
:
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
1
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
70
);
ASSERT_EQ
(
r
e
[
0
]
,
120
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
70
);
ASSERT_EQ
(
r
a
[
0
].
e
,
120
);
filterFreeMergeRange
(
h
);
s
=
s3
;
e
=
e3
;
asize
=
sizeof
(
s3
)
/
sizeof
(
s
[
0
]);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_AND
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
0
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
1
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
1
);
ASSERT_EQ
(
r
e
[
0
]
,
100
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
1
);
ASSERT_EQ
(
r
a
[
0
].
e
,
100
);
filterFreeMergeRange
(
h
);
...
...
@@ -215,82 +227,131 @@ void intDataTest() {
s
=
s4
;
e
=
e4
;
asize
=
sizeof
(
s4
)
/
sizeof
(
s
[
0
]);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_AND
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
0
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
2
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
0
);
ASSERT_EQ
(
r
e
[
0
]
,
5
);
ASSERT_EQ
(
r
s
[
1
]
,
10
);
ASSERT_EQ
(
r
e
[
1
]
,
20
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
0
);
ASSERT_EQ
(
r
a
[
0
].
e
,
5
);
ASSERT_EQ
(
r
a
[
1
].
s
,
10
);
ASSERT_EQ
(
r
a
[
1
].
e
,
20
);
filterFreeMergeRange
(
h
);
s
=
s5
;
e
=
e5
;
asize
=
sizeof
(
s5
)
/
sizeof
(
s
[
0
]);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_AND
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
0
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
2
);
filterGetMergeRangeRes
(
h
,
r
s
,
re
);
ASSERT_EQ
(
r
s
[
0
]
,
0
);
ASSERT_EQ
(
r
e
[
0
]
,
4
);
ASSERT_EQ
(
r
s
[
1
]
,
6
);
ASSERT_EQ
(
r
e
[
1
]
,
20
);
filterGetMergeRangeRes
(
h
,
r
a
);
ASSERT_EQ
(
r
a
[
0
].
s
,
0
);
ASSERT_EQ
(
r
a
[
0
].
e
,
4
);
ASSERT_EQ
(
r
a
[
1
].
s
,
6
);
ASSERT_EQ
(
r
a
[
1
].
e
,
20
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
.
s
=
s
[
i
];
ra
.
e
=
e
[
i
];
ra
[
0
]
.
s
=
s
[
i
];
ra
[
0
]
.
e
=
e
[
i
];
filterAddMergeRange
(
h
,
&
ra
,
(
i
==
(
asize
-
1
))
?
TSDB_RELATION_AND
:
TSDB_RELATION_OR
);
filterAddMergeRange
(
h
,
ra
,
(
i
==
(
asize
-
1
))
?
TSDB_RELATION_AND
:
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
1
);
filterGetMergeRangeRes
(
h
,
rs
,
re
);
ASSERT_EQ
(
rs
[
0
],
7
);
ASSERT_EQ
(
re
[
0
],
10
);
filterGetMergeRangeRes
(
h
,
ra
);
ASSERT_EQ
(
ra
[
0
].
s
,
7
);
ASSERT_EQ
(
ra
[
0
].
e
,
10
);
filterFreeMergeRange
(
h
);
int64_t
s6
[
2
]
=
{
0
,
4
};
int64_t
e6
[
2
]
=
{
4
,
6
};
s
=
s6
;
e
=
e6
;
asize
=
sizeof
(
s6
)
/
sizeof
(
s
[
0
]);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
[
0
].
eflag
=
1
;
ra
[
1
].
sflag
=
4
;
ra
[
i
].
s
=
s
[
i
];
ra
[
i
].
e
=
e
[
i
];
filterAddMergeRange
(
h
,
ra
+
i
,
TSDB_RELATION_AND
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
0
);
filterFreeMergeRange
(
h
);
memset
(
ra
,
0
,
sizeof
(
ra
));
h
=
filterInitMergeRange
(
TSDB_DATA_TYPE_BIGINT
,
0
);
for
(
int32_t
i
=
0
;
i
<
asize
;
++
i
)
{
ra
[
0
].
eflag
=
1
;
ra
[
1
].
sflag
=
1
;
ra
[
i
].
s
=
s
[
i
];
ra
[
i
].
e
=
e
[
i
];
filterAddMergeRange
(
h
,
ra
+
i
,
TSDB_RELATION_OR
);
}
filterGetMergeRangeNum
(
h
,
&
num
);
ASSERT_EQ
(
num
,
2
);
ASSERT_EQ
(
ra
[
0
].
s
,
0
);
ASSERT_EQ
(
ra
[
0
].
e
,
4
);
ASSERT_EQ
(
ra
[
0
].
eflag
,
1
);
ASSERT_EQ
(
ra
[
1
].
s
,
4
);
ASSERT_EQ
(
ra
[
1
].
e
,
6
);
ASSERT_EQ
(
ra
[
1
].
sflag
,
1
);
filterFreeMergeRange
(
h
);
}
...
...
src/util/inc/hash.h
浏览文件 @
69f25dbf
...
...
@@ -42,7 +42,7 @@ typedef struct SHashNode {
#define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->dataLen)
#define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode))
#define GET_HASH_PNODE(_n) ((
char*)(_n) - sizeof(SHashNode));
#define GET_HASH_PNODE(_n) ((
SHashNode *)((char*)(_n) - sizeof(SHashNode)))
typedef
enum
SHashLockTypeE
{
HASH_NO_LOCK
=
0
,
...
...
@@ -161,6 +161,8 @@ void *taosHashIterate(SHashObj *pHashObj, void *p);
void
taosHashCancelIterate
(
SHashObj
*
pHashObj
,
void
*
p
);
void
*
taosHashGetDataKey
(
SHashObj
*
pHashObj
,
void
*
data
);
#ifdef __cplusplus
}
#endif
...
...
src/util/src/hash.c
浏览文件 @
69f25dbf
...
...
@@ -695,6 +695,10 @@ size_t taosHashGetMemSize(const SHashObj *pHashObj) {
return
(
pHashObj
->
capacity
*
(
sizeof
(
SHashEntry
)
+
POINTER_BYTES
))
+
sizeof
(
SHashNode
)
*
taosHashGetSize
(
pHashObj
)
+
sizeof
(
SHashObj
);
}
FORCE_INLINE
void
*
taosHashGetDataKey
(
SHashObj
*
pHashObj
,
void
*
data
)
{
return
GET_HASH_NODE_KEY
(
GET_HASH_PNODE
(
data
));
}
// release the pNode, return next pNode, and lock the current entry
static
void
*
taosHashReleaseNode
(
SHashObj
*
pHashObj
,
void
*
p
,
int
*
slot
)
{
...
...
src/util/src/tcompare.c
浏览文件 @
69f25dbf
...
...
@@ -64,21 +64,21 @@ int32_t compareInt8Val(const void *pLeft, const void *pRight) {
}
int32_t
compareUint32Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
left
=
GET_UINT32_VAL
(
pLeft
),
right
=
GET_UINT32_VAL
(
pRight
);
u
int32_t
left
=
GET_UINT32_VAL
(
pLeft
),
right
=
GET_UINT32_VAL
(
pRight
);
if
(
left
>
right
)
return
1
;
if
(
left
<
right
)
return
-
1
;
return
0
;
}
int32_t
compareUint64Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int64_t
left
=
GET_UINT64_VAL
(
pLeft
),
right
=
GET_UINT64_VAL
(
pRight
);
u
int64_t
left
=
GET_UINT64_VAL
(
pLeft
),
right
=
GET_UINT64_VAL
(
pRight
);
if
(
left
>
right
)
return
1
;
if
(
left
<
right
)
return
-
1
;
return
0
;
}
int32_t
compareUint16Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int16_t
left
=
GET_UINT16_VAL
(
pLeft
),
right
=
GET_UINT16_VAL
(
pRight
);
u
int16_t
left
=
GET_UINT16_VAL
(
pLeft
),
right
=
GET_UINT16_VAL
(
pRight
);
if
(
left
>
right
)
return
1
;
if
(
left
<
right
)
return
-
1
;
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录