Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
db48f118
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看板
提交
db48f118
编写于
7月 25, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(query): add selectivity for diff function
TD-17659
上级
f0f52c6e
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
49 addition
and
3 deletion
+49
-3
include/libs/function/function.h
include/libs/function/function.h
+1
-0
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+5
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+1
-1
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+42
-2
未找到文件。
include/libs/function/function.h
浏览文件 @
db48f118
...
@@ -143,6 +143,7 @@ typedef struct SqlFunctionCtx {
...
@@ -143,6 +143,7 @@ typedef struct SqlFunctionCtx {
struct
SExprInfo
*
pExpr
;
struct
SExprInfo
*
pExpr
;
struct
SDiskbasedBuf
*
pBuf
;
struct
SDiskbasedBuf
*
pBuf
;
struct
SSDataBlock
*
pSrcBlock
;
struct
SSDataBlock
*
pSrcBlock
;
struct
SSDataBlock
*
pDstBlock
;
// used by indifinite rows function to set selectivity
int32_t
curBufPage
;
int32_t
curBufPage
;
bool
increase
;
bool
increase
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
db48f118
...
@@ -651,6 +651,11 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
...
@@ -651,6 +651,11 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
pfCtx
->
pTsOutput
=
(
SColumnInfoData
*
)
pCtx
[
*
outputColIndex
].
pOutput
;
pfCtx
->
pTsOutput
=
(
SColumnInfoData
*
)
pCtx
[
*
outputColIndex
].
pOutput
;
}
}
// link pDstBlock to set selectivity value
if
(
pfCtx
->
subsidiaries
.
num
>
0
)
{
pfCtx
->
pDstBlock
=
pResult
;
}
numOfRows
=
pfCtx
->
fpSet
.
process
(
pfCtx
);
numOfRows
=
pfCtx
->
fpSet
.
process
(
pfCtx
);
}
else
if
(
fmIsAggFunc
(
pfCtx
->
functionId
))
{
}
else
if
(
fmIsAggFunc
(
pfCtx
->
functionId
))
{
// _group_key function for "partition by tbname" + csum(col_name) query
// _group_key function for "partition by tbname" + csum(col_name) query
...
...
source/libs/function/src/builtins.c
浏览文件 @
db48f118
...
@@ -2425,7 +2425,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -2425,7 +2425,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
{
.
name
=
"diff"
,
.
name
=
"diff"
,
.
type
=
FUNCTION_TYPE_DIFF
,
.
type
=
FUNCTION_TYPE_DIFF
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_
SELECT_FUNC
|
FUNC_MGT_
TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
translateFunc
=
translateDiff
,
.
translateFunc
=
translateDiff
,
.
getEnvFunc
=
getDiffFuncEnv
,
.
getEnvFunc
=
getDiffFuncEnv
,
.
initFunc
=
diffFunctionSetup
,
.
initFunc
=
diffFunctionSetup
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
db48f118
...
@@ -1624,6 +1624,10 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
...
@@ -1624,6 +1624,10 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
}
}
void
setNullSelectivityValue
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
rowIndex
)
{
void
setNullSelectivityValue
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
rowIndex
)
{
if
(
pCtx
->
subsidiaries
.
num
<=
0
)
{
return
;
}
for
(
int32_t
j
=
0
;
j
<
pCtx
->
subsidiaries
.
num
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pCtx
->
subsidiaries
.
num
;
++
j
)
{
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
j
];
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
j
];
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
...
@@ -1655,8 +1659,6 @@ void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuple
...
@@ -1655,8 +1659,6 @@ void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuple
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
int32_t
ps
=
0
;
SColumnInfoData
*
pDstCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
dstSlotId
);
SColumnInfoData
*
pDstCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
dstSlotId
);
ASSERT
(
pc
->
pExpr
->
base
.
resSchema
.
bytes
==
pDstCol
->
info
.
bytes
);
ASSERT
(
pc
->
pExpr
->
base
.
resSchema
.
bytes
==
pDstCol
->
info
.
bytes
);
if
(
nullList
[
j
])
{
if
(
nullList
[
j
])
{
...
@@ -1678,6 +1680,39 @@ void releaseSource(STuplePos* pPos) {
...
@@ -1678,6 +1680,39 @@ void releaseSource(STuplePos* pPos) {
// Todo(liuyao) relase row
// Todo(liuyao) relase row
}
}
// This function append the selectivity to subsidiaries function context directly, without fetching data
// from intermediate disk based buf page
void
appendSelectivityValue
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
)
{
if
(
pCtx
->
subsidiaries
.
num
<=
0
)
{
return
;
}
for
(
int32_t
j
=
0
;
j
<
pCtx
->
subsidiaries
.
num
;
++
j
)
{
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
j
];
// get data from source col
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
int32_t
srcSlotId
=
pFuncParam
->
pCol
->
slotId
;
SColumnInfoData
*
pSrcCol
=
taosArrayGet
(
pCtx
->
pSrcBlock
->
pDataBlock
,
srcSlotId
);
char
*
pData
=
colDataGetData
(
pSrcCol
,
rowIndex
);
// append to dest col
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pDstCol
=
taosArrayGet
(
pCtx
->
pDstBlock
->
pDataBlock
,
dstSlotId
);
ASSERT
(
pc
->
pExpr
->
base
.
resSchema
.
bytes
==
pDstCol
->
info
.
bytes
);
if
(
colDataIsNull_s
(
pSrcCol
,
rowIndex
)
==
true
)
{
colDataAppendNULL
(
pDstCol
,
rowIndex
);
}
else
{
colDataAppend
(
pDstCol
,
rowIndex
,
pData
,
false
);
}
}
}
void
replaceTupleData
(
STuplePos
*
pDestPos
,
STuplePos
*
pSourcePos
)
{
void
replaceTupleData
(
STuplePos
*
pDestPos
,
STuplePos
*
pSourcePos
)
{
releaseSource
(
pDestPos
);
releaseSource
(
pDestPos
);
*
pDestPos
=
*
pSourcePos
;
*
pDestPos
=
*
pSourcePos
;
...
@@ -3154,6 +3189,7 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo
...
@@ -3154,6 +3189,7 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo
colDataAppendInt64
(
pOutput
,
pos
,
&
delta
);
colDataAppendInt64
(
pOutput
,
pos
,
&
delta
);
}
}
pDiffInfo
->
prev
.
i64
=
v
;
pDiffInfo
->
prev
.
i64
=
v
;
break
;
break
;
}
}
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_BOOL
:
...
@@ -3247,6 +3283,8 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
...
@@ -3247,6 +3283,8 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
if
(
pDiffInfo
->
hasPrev
)
{
if
(
pDiffInfo
->
hasPrev
)
{
doHandleDiff
(
pDiffInfo
,
pInputCol
->
info
.
type
,
pv
,
pOutput
,
pos
,
pCtx
->
order
);
doHandleDiff
(
pDiffInfo
,
pInputCol
->
info
.
type
,
pv
,
pOutput
,
pos
,
pCtx
->
order
);
// handle selectivity
appendSelectivityValue
(
pCtx
,
pos
);
numOfElems
++
;
numOfElems
++
;
}
else
{
}
else
{
...
@@ -3273,6 +3311,8 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
...
@@ -3273,6 +3311,8 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
// there is a row of previous data block to be handled in the first place.
// there is a row of previous data block to be handled in the first place.
if
(
pDiffInfo
->
hasPrev
)
{
if
(
pDiffInfo
->
hasPrev
)
{
doHandleDiff
(
pDiffInfo
,
pInputCol
->
info
.
type
,
pv
,
pOutput
,
pos
,
pCtx
->
order
);
doHandleDiff
(
pDiffInfo
,
pInputCol
->
info
.
type
,
pv
,
pOutput
,
pos
,
pCtx
->
order
);
// handle selectivity
appendSelectivityValue
(
pCtx
,
pos
);
numOfElems
++
;
numOfElems
++
;
}
else
{
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录