Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
14d4a81e
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看板
提交
14d4a81e
编写于
5月 18, 2023
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: build hash table is created during creating join operator
上级
ee16b461
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
30 deletion
+32
-30
source/libs/executor/src/joinoperator.c
source/libs/executor/src/joinoperator.c
+32
-30
未找到文件。
source/libs/executor/src/joinoperator.c
浏览文件 @
14d4a81e
...
...
@@ -35,7 +35,7 @@ typedef struct SJoinRowCtx {
int32_t
leftRowIdx
;
int32_t
rightRowIdx
;
SSHashObj
*
buildTableTSRang
e
;
bool
rightUseBuildTabl
e
;
SArray
*
rightRowLocations
;
}
SJoinRowCtx
;
...
...
@@ -62,6 +62,7 @@ typedef struct SJoinOperatorInfo {
char
*
rightTagKeyBuf
;
int32_t
rightTagKeyLen
;
SSHashObj
*
rightBuildTable
;
SJoinRowCtx
rowCtx
;
}
SJoinOperatorInfo
;
...
...
@@ -265,6 +266,8 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
extractTagEqualCondCols
(
pInfo
,
pDownstream
,
pInfo
->
pTagEqualConditions
,
pInfo
->
leftTagCols
,
pInfo
->
rightTagCols
);
initTagColskeyBuf
(
&
pInfo
->
leftTagKeyLen
,
&
pInfo
->
leftTagKeyBuf
,
pInfo
->
leftTagCols
);
initTagColskeyBuf
(
&
pInfo
->
rightTagKeyLen
,
&
pInfo
->
rightTagKeyBuf
,
pInfo
->
rightTagCols
);
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
pInfo
->
rightBuildTable
=
tSimpleHashInit
(
256
,
hashFn
);
}
pOperator
->
fpSet
=
createOperatorFpSet
(
optrDummyOpenFn
,
doMergeJoin
,
NULL
,
destroyMergeJoinOperator
,
optrDefaultBufFn
,
NULL
);
code
=
appendDownstream
(
pOperator
,
pDownstream
,
numOfDownstream
);
...
...
@@ -292,9 +295,22 @@ void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode) {
pColumn
->
scale
=
pColumnNode
->
node
.
resType
.
scale
;
}
static
void
mergeJoinDestoryBuildTable
(
SSHashObj
*
pBuildTable
)
{
void
*
p
=
NULL
;
int32_t
iter
=
0
;
while
((
p
=
tSimpleHashIterate
(
pBuildTable
,
p
,
&
iter
))
!=
NULL
)
{
SArray
*
rows
=
(
*
(
SArray
**
)
p
);
taosArrayDestroy
(
rows
);
}
tSimpleHashCleanup
(
pBuildTable
);
}
void
destroyMergeJoinOperator
(
void
*
param
)
{
SJoinOperatorInfo
*
pJoinOperator
=
(
SJoinOperatorInfo
*
)
param
;
if
(
pJoinOperator
->
pTagEqualConditions
!=
NULL
)
{
mergeJoinDestoryBuildTable
(
pJoinOperator
->
rightBuildTable
);
taosMemoryFreeClear
(
pJoinOperator
->
rightTagKeyBuf
);
taosArrayDestroy
(
pJoinOperator
->
rightTagCols
);
...
...
@@ -420,10 +436,7 @@ static int32_t mergeJoinGetDownStreamRowsEqualTimeStamp(SOperatorInfo* pOperator
return
0
;
}
static
int32_t
mergeJoinCreateBuildTable
(
SJoinOperatorInfo
*
pInfo
,
SArray
*
rightRowLocations
,
SSHashObj
**
ppHashObj
)
{
int32_t
buildTableCap
=
TMIN
(
taosArrayGetSize
(
rightRowLocations
),
256
);
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
SSHashObj
*
buildTable
=
tSimpleHashInit
(
buildTableCap
,
hashFn
);
static
int32_t
mergeJoinFillBuildTable
(
SJoinOperatorInfo
*
pInfo
,
SArray
*
rightRowLocations
,
SSHashObj
*
buildTable
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
rightRowLocations
);
++
i
)
{
SRowLocation
*
rightRow
=
taosArrayGet
(
rightRowLocations
,
i
);
int32_t
keyLen
=
fillKeyBufFromTagCols
(
pInfo
->
rightTagCols
,
rightRow
->
pDataBlock
,
rightRow
->
pos
,
pInfo
->
rightTagKeyBuf
);
...
...
@@ -436,13 +449,12 @@ static int32_t mergeJoinCreateBuildTable(SJoinOperatorInfo* pInfo, SArray* right
taosArrayPush
(
*
ppRows
,
rightRow
);
}
}
*
ppHashObj
=
buildTable
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mergeJoinLeftRowsRightRows
(
SOperatorInfo
*
pOperator
,
SSDataBlock
*
pRes
,
int32_t
*
nRows
,
const
SArray
*
leftRowLocations
,
int32_t
leftRowIdx
,
int32_t
rightRowIdx
,
SSHashObj
*
rightTableHash
,
SArray
*
rightRowLocations
,
bool
*
pReachThreshold
)
{
int32_t
rightRowIdx
,
bool
useBuildTableTSRange
,
SArray
*
rightRowLocations
,
bool
*
pReachThreshold
)
{
*
pReachThreshold
=
false
;
uint32_t
limitRowNum
=
pOperator
->
resultInfo
.
threshold
;
SJoinOperatorInfo
*
pJoinInfo
=
pOperator
->
info
;
...
...
@@ -453,9 +465,9 @@ static int32_t mergeJoinLeftRowsRightRows(SOperatorInfo* pOperator, SSDataBlock*
for
(
i
=
leftRowIdx
;
i
<
leftNumJoin
;
++
i
,
rightRowIdx
=
0
)
{
SRowLocation
*
leftRow
=
taosArrayGet
(
leftRowLocations
,
i
);
SArray
*
pRightRows
=
NULL
;
if
(
rightTableHash
!=
NULL
)
{
if
(
useBuildTableTSRange
)
{
int32_t
keyLen
=
fillKeyBufFromTagCols
(
pJoinInfo
->
leftTagCols
,
leftRow
->
pDataBlock
,
leftRow
->
pos
,
pJoinInfo
->
leftTagKeyBuf
);
SArray
**
ppRightRows
=
tSimpleHashGet
(
rightTableHash
,
pJoinInfo
->
leftTagKeyBuf
,
keyLen
);
SArray
**
ppRightRows
=
tSimpleHashGet
(
pJoinInfo
->
rightBuildTable
,
pJoinInfo
->
leftTagKeyBuf
,
keyLen
);
if
(
!
ppRightRows
)
{
continue
;
}
...
...
@@ -488,20 +500,8 @@ static int32_t mergeJoinLeftRowsRightRows(SOperatorInfo* pOperator, SSDataBlock*
return
TSDB_CODE_SUCCESS
;
}
static
void
mergeJoinDestoryBuildTable
(
SSHashObj
*
pBuildTable
)
{
void
*
p
=
NULL
;
int32_t
iter
=
0
;
while
((
p
=
tSimpleHashIterate
(
pBuildTable
,
p
,
&
iter
))
!=
NULL
)
{
SArray
*
rows
=
(
*
(
SArray
**
)
p
);
taosArrayDestroy
(
rows
);
}
tSimpleHashCleanup
(
pBuildTable
);
}
static
void
mergeJoinDestroyTSRangeCtx
(
SJoinOperatorInfo
*
pJoinInfo
,
SArray
*
leftRowLocations
,
SArray
*
leftCreatedBlocks
,
SArray
*
rightCreatedBlocks
,
SSHashObj
*
rightTableHash
,
SArray
*
rightRowLocations
)
{
SArray
*
rightCreatedBlocks
,
bool
rightUseBuildTable
,
SArray
*
rightRowLocations
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
rightCreatedBlocks
);
++
i
)
{
SSDataBlock
*
pBlock
=
taosArrayGetP
(
rightCreatedBlocks
,
i
);
blockDataDestroy
(
pBlock
);
...
...
@@ -514,8 +514,8 @@ static void mergeJoinDestroyTSRangeCtx(SJoinOperatorInfo* pJoinInfo, SArray* lef
if
(
rightRowLocations
!=
NULL
)
{
taosArrayDestroy
(
rightRowLocations
);
}
if
(
right
TableHash
!=
NULL
)
{
mergeJoinDestoryBuildTable
(
rightTableHash
);
if
(
right
UseBuildTable
)
{
tSimpleHashClear
(
pJoinInfo
->
rightBuildTable
);
}
taosArrayDestroy
(
leftCreatedBlocks
);
...
...
@@ -525,7 +525,7 @@ static void mergeJoinDestroyTSRangeCtx(SJoinOperatorInfo* pJoinInfo, SArray* lef
pJoinInfo
->
rowCtx
.
leftRowLocations
=
NULL
;
pJoinInfo
->
rowCtx
.
leftCreatedBlocks
=
NULL
;
pJoinInfo
->
rowCtx
.
rightCreatedBlocks
=
NULL
;
pJoinInfo
->
rowCtx
.
buildTableTSRange
=
NULL
;
pJoinInfo
->
rowCtx
.
rightUseBuildTable
=
false
;
pJoinInfo
->
rowCtx
.
rightRowLocations
=
NULL
;
}
...
...
@@ -540,11 +540,12 @@ static int32_t mergeJoinJoinDownstreamTsRanges(SOperatorInfo* pOperator, int64_t
int32_t
leftRowIdx
=
0
;
int32_t
rightRowIdx
=
0
;
SSHashObj
*
rightTableHash
=
NULL
;
bool
rightUseBuildTable
=
false
;
if
(
pJoinInfo
->
rowCtx
.
rowRemains
)
{
leftRowLocations
=
pJoinInfo
->
rowCtx
.
leftRowLocations
;
leftCreatedBlocks
=
pJoinInfo
->
rowCtx
.
leftCreatedBlocks
;
right
TableHash
=
pJoinInfo
->
rowCtx
.
buildTableTSRang
e
;
right
UseBuildTable
=
pJoinInfo
->
rowCtx
.
rightUseBuildTabl
e
;
rightRowLocations
=
pJoinInfo
->
rowCtx
.
rightRowLocations
;
rightCreatedBlocks
=
pJoinInfo
->
rowCtx
.
rightCreatedBlocks
;
leftRowIdx
=
pJoinInfo
->
rowCtx
.
leftRowIdx
;
...
...
@@ -561,7 +562,8 @@ static int32_t mergeJoinJoinDownstreamTsRanges(SOperatorInfo* pOperator, int64_t
mergeJoinGetDownStreamRowsEqualTimeStamp
(
pOperator
,
1
,
pJoinInfo
->
rightCol
.
slotId
,
pJoinInfo
->
pRight
,
pJoinInfo
->
rightPos
,
timestamp
,
rightRowLocations
,
rightCreatedBlocks
);
if
(
pJoinInfo
->
pTagEqualConditions
!=
NULL
&&
taosArrayGetSize
(
rightRowLocations
)
>
16
)
{
mergeJoinCreateBuildTable
(
pJoinInfo
,
rightRowLocations
,
&
rightTableHash
);
mergeJoinFillBuildTable
(
pJoinInfo
,
rightRowLocations
,
pJoinInfo
->
rightBuildTable
);
rightUseBuildTable
=
true
;
taosArrayDestroy
(
rightRowLocations
);
rightRowLocations
=
NULL
;
}
...
...
@@ -578,12 +580,12 @@ static int32_t mergeJoinJoinDownstreamTsRanges(SOperatorInfo* pOperator, int64_t
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mergeJoinLeftRowsRightRows
(
pOperator
,
pRes
,
nRows
,
leftRowLocations
,
leftRowIdx
,
rightRowIdx
,
right
TableHash
,
rightRowLocations
,
&
reachThreshold
);
rightRowIdx
,
right
UseBuildTable
,
rightRowLocations
,
&
reachThreshold
);
}
if
(
!
reachThreshold
)
{
mergeJoinDestroyTSRangeCtx
(
pJoinInfo
,
leftRowLocations
,
leftCreatedBlocks
,
rightCreatedBlocks
,
right
TableHash
,
rightRowLocations
);
right
UseBuildTable
,
rightRowLocations
);
}
else
{
pJoinInfo
->
rowCtx
.
rowRemains
=
true
;
...
...
@@ -591,7 +593,7 @@ static int32_t mergeJoinJoinDownstreamTsRanges(SOperatorInfo* pOperator, int64_t
pJoinInfo
->
rowCtx
.
leftRowLocations
=
leftRowLocations
;
pJoinInfo
->
rowCtx
.
leftCreatedBlocks
=
leftCreatedBlocks
;
pJoinInfo
->
rowCtx
.
rightCreatedBlocks
=
rightCreatedBlocks
;
pJoinInfo
->
rowCtx
.
buildTableTSRange
=
rightTableHash
;
pJoinInfo
->
rowCtx
.
rightUseBuildTable
=
true
;
pJoinInfo
->
rowCtx
.
rightRowLocations
=
rightRowLocations
;
}
return
TSDB_CODE_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录