Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c9140e54
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
c9140e54
编写于
5月 23, 2023
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix bugs of wrongly use sfltscloperator
上级
77a1de44
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
37 addition
and
39 deletion
+37
-39
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+37
-39
未找到文件。
source/libs/scalar/src/filter.c
浏览文件 @
c9140e54
...
@@ -1841,9 +1841,9 @@ void filterFreeInfo(SFilterInfo *info) {
...
@@ -1841,9 +1841,9 @@ void filterFreeInfo(SFilterInfo *info) {
return
;
return
;
}
}
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
info
->
sclCtx
.
fltSclRange
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
info
->
sclCtx
.
fltSclRange
);
++
i
)
{
SFltSclColumnRange
*
colRange
=
taosArrayGet
(
info
->
sclCtx
.
fltSclRange
,
i
);
SFltSclColumnRange
*
colRange
=
taosArrayGet
(
info
->
sclCtx
.
fltSclRange
,
i
);
nodesDestroyNode
((
SNode
*
)
colRange
->
colNode
);
nodesDestroyNode
((
SNode
*
)
colRange
->
colNode
);
taosArrayDestroy
(
colRange
->
points
);
taosArrayDestroy
(
colRange
->
points
);
}
}
taosArrayDestroy
(
info
->
sclCtx
.
fltSclRange
);
taosArrayDestroy
(
info
->
sclCtx
.
fltSclRange
);
...
@@ -3431,7 +3431,6 @@ _return:
...
@@ -3431,7 +3431,6 @@ _return:
return
code
;
return
code
;
}
}
// compare ranges, null < min < val < max. null=null, min=min, max=max
// compare ranges, null < min < val < max. null=null, min=min, max=max
typedef
enum
{
typedef
enum
{
FLT_SCL_DATUM_KIND_NULL
,
FLT_SCL_DATUM_KIND_NULL
,
...
@@ -3627,7 +3626,6 @@ typedef struct {
...
@@ -3627,7 +3626,6 @@ typedef struct {
EOperatorType
type
;
EOperatorType
type
;
}
SFltSclOperator
;
}
SFltSclOperator
;
SFltSclColumnRange
*
fltSclGetOrCreateColumnRange
(
SColumnNode
*
colNode
,
SArray
*
colRangeList
)
{
SFltSclColumnRange
*
fltSclGetOrCreateColumnRange
(
SColumnNode
*
colNode
,
SArray
*
colRangeList
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
colRangeList
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
colRangeList
);
++
i
)
{
SFltSclColumnRange
*
colRange
=
taosArrayGet
(
colRangeList
,
i
);
SFltSclColumnRange
*
colRange
=
taosArrayGet
(
colRangeList
,
i
);
...
@@ -3635,7 +3633,7 @@ SFltSclColumnRange *fltSclGetOrCreateColumnRange(SColumnNode *colNode, SArray *c
...
@@ -3635,7 +3633,7 @@ SFltSclColumnRange *fltSclGetOrCreateColumnRange(SColumnNode *colNode, SArray *c
return
colRange
;
return
colRange
;
}
}
}
}
SColumnNode
*
pColumnNode
=
(
SColumnNode
*
)
nodesCloneNode
((
SNode
*
)
colNode
);
SColumnNode
*
pColumnNode
=
(
SColumnNode
*
)
nodesCloneNode
((
SNode
*
)
colNode
);
SFltSclColumnRange
newColRange
=
{.
colNode
=
pColumnNode
,
.
points
=
taosArrayInit
(
4
,
sizeof
(
SFltSclPoint
))};
SFltSclColumnRange
newColRange
=
{.
colNode
=
pColumnNode
,
.
points
=
taosArrayInit
(
4
,
sizeof
(
SFltSclPoint
))};
taosArrayPush
(
colRangeList
,
&
newColRange
);
taosArrayPush
(
colRangeList
,
&
newColRange
);
return
taosArrayGetLast
(
colRangeList
);
return
taosArrayGetLast
(
colRangeList
);
...
@@ -3690,7 +3688,7 @@ int32_t fltSclBuildDatumFromValueNode(SFltSclDatum *datum, SValueNode *valNode)
...
@@ -3690,7 +3688,7 @@ int32_t fltSclBuildDatumFromValueNode(SFltSclDatum *datum, SValueNode *valNode)
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
fltSclBuildDatumFromBlockSmaValue
(
SFltSclDatum
*
datum
,
uint8_t
type
,
int64_t
val
)
{
int32_t
fltSclBuildDatumFromBlockSmaValue
(
SFltSclDatum
*
datum
,
uint8_t
type
,
int64_t
val
)
{
switch
(
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
case
TSDB_DATA_TYPE_BOOL
:
{
datum
->
kind
=
FLT_SCL_DATUM_KIND_INT64
;
datum
->
kind
=
FLT_SCL_DATUM_KIND_INT64
;
...
@@ -3702,13 +3700,13 @@ int32_t fltSclBuildDatumFromBlockSmaValue(SFltSclDatum* datum, uint8_t type, int
...
@@ -3702,13 +3700,13 @@ int32_t fltSclBuildDatumFromBlockSmaValue(SFltSclDatum* datum, uint8_t type, int
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
{
case
TSDB_DATA_TYPE_UBIGINT
:
{
datum
->
kind
=
FLT_SCL_DATUM_KIND_UINT64
;
datum
->
kind
=
FLT_SCL_DATUM_KIND_UINT64
;
datum
->
u
=
*
(
uint64_t
*
)
&
val
;
datum
->
u
=
*
(
uint64_t
*
)
&
val
;
break
;
break
;
}
}
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
{
case
TSDB_DATA_TYPE_DOUBLE
:
{
datum
->
kind
=
FLT_SCL_DATUM_KIND_FLOAT64
;
datum
->
kind
=
FLT_SCL_DATUM_KIND_FLOAT64
;
datum
->
d
=
*
(
double
*
)
&
val
;
datum
->
d
=
*
(
double
*
)
&
val
;
break
;
break
;
}
}
// TODO:varchar/nchar/json
// TODO:varchar/nchar/json
...
@@ -3718,11 +3716,11 @@ int32_t fltSclBuildDatumFromBlockSmaValue(SFltSclDatum* datum, uint8_t type, int
...
@@ -3718,11 +3716,11 @@ int32_t fltSclBuildDatumFromBlockSmaValue(SFltSclDatum* datum, uint8_t type, int
}
}
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
fltSclBuildRangeFromBlockSma
(
SFltSclColumnRange
*
colRange
,
SColumnDataAgg
*
pAgg
,
int32_t
numOfRows
,
SArray
*
points
)
{
int32_t
fltSclBuildRangeFromBlockSma
(
SFltSclColumnRange
*
colRange
,
SColumnDataAgg
*
pAgg
,
int32_t
numOfRows
,
SArray
*
points
)
{
if
(
pAgg
->
numOfNull
==
numOfRows
)
{
if
(
pAgg
->
numOfNull
==
numOfRows
)
{
SFltSclDatum
datum
=
{.
kind
=
FLT_SCL_DATUM_KIND_NULL
};
SFltSclDatum
datum
=
{.
kind
=
FLT_SCL_DATUM_KIND_NULL
};
SFltSclPoint
startPt
=
{.
start
=
true
,
.
excl
=
false
,
.
val
=
datum
};
SFltSclPoint
startPt
=
{.
start
=
true
,
.
excl
=
false
,
.
val
=
datum
};
...
@@ -3744,9 +3742,9 @@ int32_t fltSclBuildRangeFromBlockSma(SFltSclColumnRange* colRange, SColumnDataAg
...
@@ -3744,9 +3742,9 @@ int32_t fltSclBuildRangeFromBlockSma(SFltSclColumnRange* colRange, SColumnDataAg
bool
filterRangeExecute
(
SFilterInfo
*
info
,
SColumnDataAgg
**
pDataStatis
,
int32_t
numOfCols
,
int32_t
numOfRows
)
{
bool
filterRangeExecute
(
SFilterInfo
*
info
,
SColumnDataAgg
**
pDataStatis
,
int32_t
numOfCols
,
int32_t
numOfRows
)
{
if
(
info
->
scalarMode
)
{
if
(
info
->
scalarMode
)
{
SArray
*
colRanges
=
info
->
sclCtx
.
fltSclRange
;
SArray
*
colRanges
=
info
->
sclCtx
.
fltSclRange
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
colRanges
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
colRanges
);
++
i
)
{
SFltSclColumnRange
*
colRange
=
taosArrayGet
(
colRanges
,
i
);
SFltSclColumnRange
*
colRange
=
taosArrayGet
(
colRanges
,
i
);
bool
foundCol
=
false
;
bool
foundCol
=
false
;
int32_t
j
=
0
;
int32_t
j
=
0
;
for
(;
j
<
numOfCols
;
++
j
)
{
for
(;
j
<
numOfCols
;
++
j
)
{
...
@@ -3755,10 +3753,10 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
...
@@ -3755,10 +3753,10 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
}
}
}
}
if
(
foundCol
)
{
if
(
foundCol
)
{
SColumnDataAgg
*
pAgg
=
pDataStatis
[
j
];
SColumnDataAgg
*
pAgg
=
pDataStatis
[
j
];
SArray
*
points
=
taosArrayInit
(
2
,
sizeof
(
SFltSclPoint
));
SArray
*
points
=
taosArrayInit
(
2
,
sizeof
(
SFltSclPoint
));
fltSclBuildRangeFromBlockSma
(
colRange
,
pAgg
,
numOfRows
,
points
);
fltSclBuildRangeFromBlockSma
(
colRange
,
pAgg
,
numOfRows
,
points
);
SArray
*
merged
=
taosArrayInit
(
8
,
sizeof
(
SFltSclPoint
));
SArray
*
merged
=
taosArrayInit
(
8
,
sizeof
(
SFltSclPoint
));
fltSclIntersect
(
points
,
colRange
->
points
,
merged
);
fltSclIntersect
(
points
,
colRange
->
points
,
merged
);
bool
isIntersect
=
taosArrayGetSize
(
merged
)
!=
0
;
bool
isIntersect
=
taosArrayGetSize
(
merged
)
!=
0
;
taosArrayDestroy
(
merged
);
taosArrayDestroy
(
merged
);
...
@@ -4381,19 +4379,18 @@ int32_t fltSclProcessCNF(SArray *sclOpListCNF, SArray *colRangeList) {
...
@@ -4381,19 +4379,18 @@ int32_t fltSclProcessCNF(SArray *sclOpListCNF, SArray *colRangeList) {
taosArrayDestroy
(
colRange
->
points
);
taosArrayDestroy
(
colRange
->
points
);
colRange
->
points
=
points
;
colRange
->
points
=
points
;
}
}
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
fltSclCollectOperatorFromNode
(
SNode
*
pNode
,
SArray
*
sclOpList
)
{
static
int32_t
fltSclCollectOperatorFromNode
(
SNode
*
pNode
,
SArray
*
sclOpList
)
{
if
(
nodeType
(
pNode
)
!=
QUERY_NODE_OPERATOR
)
{
if
(
nodeType
(
pNode
)
!=
QUERY_NODE_OPERATOR
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
//TODO: left value node, right column node
//
TODO: left value node, right column node
//TODO: datatype
//
TODO: datatype
//TODO: operator
//
TODO: operator
if
(
pOper
->
pLeft
==
NULL
||
pOper
->
pRight
==
NULL
)
{
if
(
pOper
->
pLeft
==
NULL
||
pOper
->
pRight
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -4401,31 +4398,31 @@ static int32_t fltSclCollectOperatorFromNode(SNode* pNode, SArray* sclOpList) {
...
@@ -4401,31 +4398,31 @@ static int32_t fltSclCollectOperatorFromNode(SNode* pNode, SArray* sclOpList) {
(
pOper
->
opType
==
OP_TYPE_GREATER_THAN
||
pOper
->
opType
==
OP_TYPE_GREATER_EQUAL
||
(
pOper
->
opType
==
OP_TYPE_GREATER_THAN
||
pOper
->
opType
==
OP_TYPE_GREATER_EQUAL
||
pOper
->
opType
==
OP_TYPE_LOWER_THAN
||
pOper
->
opType
==
OP_TYPE_LOWER_EQUAL
||
pOper
->
opType
==
OP_TYPE_LOWER_THAN
||
pOper
->
opType
==
OP_TYPE_LOWER_EQUAL
||
pOper
->
opType
==
OP_TYPE_NOT_EQUAL
||
pOper
->
opType
==
OP_TYPE_EQUAL
))
{
pOper
->
opType
==
OP_TYPE_NOT_EQUAL
||
pOper
->
opType
==
OP_TYPE_EQUAL
))
{
SValueNode
*
valNode
=
(
SValueNode
*
)
pOper
->
pRight
;
SValueNode
*
valNode
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
IS_NUMERIC_TYPE
(
valNode
->
node
.
resType
.
type
)
||
valNode
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
if
(
IS_NUMERIC_TYPE
(
valNode
->
node
.
resType
.
type
)
||
valNode
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
SNode
*
p
=
nodesCloneNode
(
pNode
);
SFltSclOperator
sclOp
=
{
taosArrayPush
(
sclOpList
,
&
p
);
.
colNode
=
nodesCloneNode
(
pOper
->
pLeft
),
.
valNode
=
nodesCloneNode
(
pOper
->
pRight
),
.
type
=
pOper
->
opType
};
taosArrayPush
(
sclOpList
,
&
sclOp
);
}
}
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
fltSclCollectOperatorsFromLogicCond
(
SNode
*
pNode
,
SArray
*
sclOpList
)
{
static
int32_t
fltSclCollectOperatorsFromLogicCond
(
SNode
*
pNode
,
SArray
*
sclOpList
)
{
if
(
nodeType
(
pNode
)
!=
QUERY_NODE_LOGIC_CONDITION
)
{
if
(
nodeType
(
pNode
)
!=
QUERY_NODE_LOGIC_CONDITION
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)
pNode
;
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)
pNode
;
//TODO: support LOGIC_COND_TYPE_OR
//
TODO: support LOGIC_COND_TYPE_OR
if
(
pLogicCond
->
condType
!=
LOGIC_COND_TYPE_AND
)
{
if
(
pLogicCond
->
condType
!=
LOGIC_COND_TYPE_AND
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SNode
*
pExpr
=
NULL
;
SNode
*
pExpr
=
NULL
;
FOREACH
(
pExpr
,
pLogicCond
->
pParameterList
)
{
fltSclCollectOperatorFromNode
(
pExpr
,
sclOpList
);
FOREACH
(
pExpr
,
pLogicCond
->
pParameterList
)
{
fltSclCollectOperatorFromNode
(
pExpr
,
sclOpList
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
fltSclCollectOperators
(
SNode
*
pNode
,
SArray
*
sclOpList
)
{
static
int32_t
fltSclCollectOperators
(
SNode
*
pNode
,
SArray
*
sclOpList
)
{
if
(
nodeType
(
pNode
)
==
QUERY_NODE_OPERATOR
)
{
if
(
nodeType
(
pNode
)
==
QUERY_NODE_OPERATOR
)
{
fltSclCollectOperatorFromNode
(
pNode
,
sclOpList
);
fltSclCollectOperatorFromNode
(
pNode
,
sclOpList
);
}
else
if
(
nodeType
(
pNode
)
==
QUERY_NODE_LOGIC_CONDITION
)
{
}
else
if
(
nodeType
(
pNode
)
==
QUERY_NODE_LOGIC_CONDITION
)
{
...
@@ -4435,15 +4432,16 @@ static int32_t fltSclCollectOperators(SNode *pNode, SArray* sclOpList) {
...
@@ -4435,15 +4432,16 @@ static int32_t fltSclCollectOperators(SNode *pNode, SArray* sclOpList) {
}
}
int32_t
fltOptimizeNodes
(
SFilterInfo
*
pInfo
,
SNode
**
pNode
,
SFltTreeStat
*
pStat
)
{
int32_t
fltOptimizeNodes
(
SFilterInfo
*
pInfo
,
SNode
**
pNode
,
SFltTreeStat
*
pStat
)
{
SArray
*
sclOpList
=
taosArrayInit
(
16
,
POINTER_BYTES
);
SArray
*
sclOpList
=
taosArrayInit
(
16
,
POINTER_BYTES
);
fltSclCollectOperators
(
*
pNode
,
sclOpList
);
fltSclCollectOperators
(
*
pNode
,
sclOpList
);
SArray
*
colRangeList
=
taosArrayInit
(
16
,
sizeof
(
SFltSclColumnRange
));
SArray
*
colRangeList
=
taosArrayInit
(
16
,
sizeof
(
SFltSclColumnRange
));
fltSclProcessCNF
(
sclOpList
,
colRangeList
);
fltSclProcessCNF
(
sclOpList
,
colRangeList
);
pInfo
->
sclCtx
.
fltSclRange
=
colRangeList
;
pInfo
->
sclCtx
.
fltSclRange
=
colRangeList
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
sclOpList
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
sclOpList
);
++
i
)
{
SNode
*
p
=
taosArrayGetP
(
sclOpList
,
i
);
SFltSclOperator
*
sclOp
=
taosArrayGet
(
sclOpList
,
i
);
nodesDestroyNode
(
p
);
nodesDestroyNode
(
sclOp
->
colNode
);
nodesDestroyNode
(
sclOp
->
valNode
);
}
}
taosArrayDestroy
(
sclOpList
);
taosArrayDestroy
(
sclOpList
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录