Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c962e9b8
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看板
提交
c962e9b8
编写于
7月 28, 2022
作者:
S
slzhou@taodata.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add support for join operator when multiple rows with same ts
上级
c061cd2f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
90 addition
and
10 deletion
+90
-10
source/libs/executor/src/joinoperator.c
source/libs/executor/src/joinoperator.c
+90
-10
未找到文件。
source/libs/executor/src/joinoperator.c
浏览文件 @
c962e9b8
...
...
@@ -130,7 +130,7 @@ static void mergeJoinJoinLeftRight(struct SOperatorInfo* pOperator, SSDataBlock*
int32_t
rowIndex
=
-
1
;
SColumnInfoData
*
pSrc
=
NULL
;
if
(
p
JoinInfo
->
pLeft
->
info
.
blockId
==
blockId
)
{
if
(
p
LeftBlock
->
info
.
blockId
==
blockId
)
{
pSrc
=
taosArrayGet
(
pLeftBlock
->
pDataBlock
,
slotId
);
rowIndex
=
leftPos
;
}
else
{
...
...
@@ -151,8 +151,9 @@ typedef struct SRowLocation {
int32_t
pos
;
}
SRowLocation
;
// pBlock[tsSlotId][startPos, endPos) == timestamp,
static
int32_t
mergeJoinGetBlockRowsEqualTs
(
SSDataBlock
*
pBlock
,
int16_t
tsSlotId
,
int32_t
startPos
,
int64_t
timestamp
,
int32_t
*
pEndPos
,
SArray
*
pR
owLocations
,
SArray
*
createdBlocks
)
{
int32_t
*
pEndPos
,
SArray
*
r
owLocations
,
SArray
*
createdBlocks
)
{
int32_t
numRows
=
pBlock
->
info
.
rows
;
ASSERT
(
startPos
<
numRows
);
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
tsSlotId
);
...
...
@@ -167,25 +168,107 @@ static int32_t mergeJoinGetBlockRowsEqualTs(SSDataBlock* pBlock, int16_t tsSlotI
int32_t
endPos
=
i
;
*
pEndPos
=
endPos
;
if
(
endPos
-
startPos
==
0
)
{
return
0
;
}
SSDataBlock
*
block
=
pBlock
;
bool
createdNewBlock
=
false
;
if
(
endPos
==
numRows
)
{
block
=
blockDataExtractBlock
(
pBlock
,
startPos
,
endPos
-
startPos
);
block
=
blockDataExtractBlock
(
pBlock
,
startPos
,
endPos
-
startPos
);
taosArrayPush
(
createdBlocks
,
&
block
);
createdNewBlock
=
true
;
}
SRowLocation
location
=
{
0
};
for
(
int32_t
j
=
startPos
;
j
<
endPos
;
++
j
)
{
location
.
pDataBlock
=
block
;
location
.
pos
=
j
;
taosArrayPush
(
pR
owLocations
,
&
location
);
location
.
pos
=
(
createdNewBlock
?
j
-
startPos
:
j
)
;
taosArrayPush
(
r
owLocations
,
&
location
);
}
return
0
;
}
static
int32_t
mergeJoinGetRowsEqualTimeStamp
(
SJoinOperatorInfo
*
pJoinInfo
,
SArray
*
pPosArray
)
{
// whichChild == 0, left child of join; whichChild ==1, right child of join
static
int32_t
mergeJoinGetDownStreamRowsEqualTimeStamp
(
SOperatorInfo
*
pOperator
,
int32_t
whichChild
,
int16_t
tsSlotId
,
SSDataBlock
*
startDataBlock
,
int32_t
startPos
,
int64_t
timestamp
,
SArray
*
rowLocations
,
SArray
*
createdBlocks
)
{
ASSERT
(
whichChild
==
0
||
whichChild
==
1
);
SJoinOperatorInfo
*
pJoinInfo
=
pOperator
->
info
;
int32_t
endPos
=
-
1
;
SSDataBlock
*
dataBlock
=
startDataBlock
;
mergeJoinGetBlockRowsEqualTs
(
dataBlock
,
tsSlotId
,
startPos
,
timestamp
,
&
endPos
,
rowLocations
,
createdBlocks
);
while
(
endPos
==
dataBlock
->
info
.
rows
)
{
SOperatorInfo
*
ds
=
pOperator
->
pDownstream
[
whichChild
];
dataBlock
=
ds
->
fpSet
.
getNextFn
(
ds
);
if
(
whichChild
==
0
)
{
pJoinInfo
->
leftPos
=
0
;
pJoinInfo
->
pLeft
=
dataBlock
;
}
else
if
(
whichChild
==
1
)
{
pJoinInfo
->
rightPos
=
0
;
pJoinInfo
->
pRight
=
dataBlock
;
}
if
(
dataBlock
==
NULL
)
{
setTaskStatus
(
pOperator
->
pTaskInfo
,
TASK_COMPLETED
);
endPos
=
-
1
;
break
;
}
mergeJoinGetBlockRowsEqualTs
(
dataBlock
,
tsSlotId
,
0
,
timestamp
,
&
endPos
,
rowLocations
,
createdBlocks
);
}
if
(
endPos
!=
-
1
)
{
if
(
whichChild
==
0
)
{
pJoinInfo
->
leftPos
=
endPos
;
}
else
if
(
whichChild
==
1
)
{
pJoinInfo
->
rightPos
=
endPos
;
}
}
return
0
;
}
static
int32_t
mergeJoinJoinDownstreamTsRanges
(
SOperatorInfo
*
pOperator
,
int64_t
timestamp
,
SSDataBlock
*
pRes
,
int32_t
*
nRows
)
{
SJoinOperatorInfo
*
pJoinInfo
=
pOperator
->
info
;
SArray
*
leftRowLocations
=
taosArrayInit
(
8
,
sizeof
(
SRowLocation
));
SArray
*
leftCreatedBlocks
=
taosArrayInit
(
8
,
POINTER_BYTES
);
SArray
*
rightRowLocations
=
taosArrayInit
(
8
,
sizeof
(
SRowLocation
));
SArray
*
rightCreatedBlocks
=
taosArrayInit
(
8
,
POINTER_BYTES
);
mergeJoinGetDownStreamRowsEqualTimeStamp
(
pOperator
,
0
,
pJoinInfo
->
leftCol
.
slotId
,
pJoinInfo
->
pLeft
,
pJoinInfo
->
leftPos
,
timestamp
,
leftRowLocations
,
leftCreatedBlocks
);
mergeJoinGetDownStreamRowsEqualTimeStamp
(
pOperator
,
1
,
pJoinInfo
->
rightCol
.
slotId
,
pJoinInfo
->
pRight
,
pJoinInfo
->
rightPos
,
timestamp
,
rightRowLocations
,
rightCreatedBlocks
);
size_t
leftNumJoin
=
taosArrayGetSize
(
leftRowLocations
);
size_t
rightNumJoin
=
taosArrayGetSize
(
rightRowLocations
);
for
(
int32_t
i
=
0
;
i
<
leftNumJoin
;
++
i
)
{
for
(
int32_t
j
=
0
;
j
<
rightNumJoin
;
++
j
)
{
SRowLocation
*
leftRow
=
taosArrayGet
(
leftRowLocations
,
i
);
SRowLocation
*
rightRow
=
taosArrayGet
(
rightRowLocations
,
j
);
mergeJoinJoinLeftRight
(
pOperator
,
pRes
,
*
nRows
,
leftRow
->
pDataBlock
,
leftRow
->
pos
,
rightRow
->
pDataBlock
,
rightRow
->
pos
);
++*
nRows
;
}
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
rightCreatedBlocks
);
++
i
)
{
SSDataBlock
*
pBlock
=
taosArrayGetP
(
rightCreatedBlocks
,
i
);
blockDataDestroy
(
pBlock
);
}
taosArrayDestroy
(
rightCreatedBlocks
);
taosArrayDestroy
(
rightRowLocations
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
leftCreatedBlocks
);
++
i
)
{
SSDataBlock
*
pBlock
=
taosArrayGetP
(
leftCreatedBlocks
,
i
);
blockDataDestroy
(
pBlock
);
}
taosArrayDestroy
(
leftCreatedBlocks
);
taosArrayDestroy
(
leftRowLocations
);
return
TSDB_CODE_SUCCESS
;
}
static
bool
mergeJoinGetNextTimestamp
(
SOperatorInfo
*
pOperator
,
int64_t
*
pLeftTs
,
int64_t
*
pRightTs
)
{
SJoinOperatorInfo
*
pJoinInfo
=
pOperator
->
info
;
...
...
@@ -242,10 +325,7 @@ static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes)
if
(
leftTs
==
rightTs
)
{
mergeJoinJoinLeftRight
(
pOperator
,
pRes
,
nrows
,
pJoinInfo
->
pLeft
,
pJoinInfo
->
leftPos
,
pJoinInfo
->
pRight
,
pJoinInfo
->
rightPos
);
pJoinInfo
->
leftPos
+=
1
;
pJoinInfo
->
rightPos
+=
1
;
nrows
+=
1
;
mergeJoinJoinDownstreamTsRanges
(
pOperator
,
leftTs
,
pRes
,
&
nrows
);
}
else
if
(
asc
&&
leftTs
<
rightTs
||
!
asc
&&
leftTs
>
rightTs
)
{
pJoinInfo
->
leftPos
+=
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录