Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ee16b461
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看板
提交
ee16b461
编写于
5月 18, 2023
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: remove group keys from join operator
上级
03e77288
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
18 addition
and
76 deletion
+18
-76
source/libs/executor/src/joinoperator.c
source/libs/executor/src/joinoperator.c
+18
-76
未找到文件。
source/libs/executor/src/joinoperator.c
浏览文件 @
ee16b461
...
...
@@ -55,12 +55,10 @@ typedef struct SJoinOperatorInfo {
SNode
*
pTagEqualConditions
;
SArray
*
leftTagCols
;
SArray
*
leftTagKeys
;
char
*
leftTagKeyBuf
;
int32_t
leftTagKeyLen
;
SArray
*
rightTagCols
;
SArray
*
rightTagKeys
;
char
*
rightTagKeyBuf
;
int32_t
rightTagKeyLen
;
...
...
@@ -141,27 +139,11 @@ static void extractTagEqualCondCols(SJoinOperatorInfo* pInfo, SOperatorInfo** pD
}
}
static
int32_t
initTagColsGroupkeys
(
SArray
**
pGroupColVals
,
int32_t
*
keyLen
,
char
**
keyBuf
,
const
SArray
*
pGroupColList
)
{
*
pGroupColVals
=
taosArrayInit
(
4
,
sizeof
(
SGroupKeys
));
if
((
*
pGroupColVals
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
static
int32_t
initTagColskeyBuf
(
int32_t
*
keyLen
,
char
**
keyBuf
,
const
SArray
*
pGroupColList
)
{
int32_t
numOfGroupCols
=
taosArrayGetSize
(
pGroupColList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroupCols
;
++
i
)
{
SColumn
*
pCol
=
(
SColumn
*
)
taosArrayGet
(
pGroupColList
,
i
);
(
*
keyLen
)
+=
pCol
->
bytes
;
// actual data + null_flag
SGroupKeys
key
=
{
0
};
key
.
bytes
=
pCol
->
bytes
;
key
.
type
=
pCol
->
type
;
key
.
isNull
=
false
;
key
.
pData
=
taosMemoryCalloc
(
1
,
pCol
->
bytes
);
if
(
key
.
pData
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
taosArrayPush
((
*
pGroupColVals
),
&
key
);
}
int32_t
nullFlagSize
=
sizeof
(
int8_t
)
*
numOfGroupCols
;
...
...
@@ -175,10 +157,11 @@ static int32_t initTagColsGroupkeys(SArray** pGroupColVals, int32_t* keyLen, cha
return
TSDB_CODE_SUCCESS
;
}
static
void
fillGroupKeyValsFromTagCols
(
SArray
*
pCols
,
SArray
*
pGroupKeys
,
SSDataBlock
*
pBlock
,
int32_t
rowIndex
)
{
static
int32_t
fillKeyBufFromTagCols
(
SArray
*
pCols
,
SSDataBlock
*
pBlock
,
int32_t
rowIndex
,
void
*
pKey
)
{
SColumnDataAgg
*
pColAgg
=
NULL
;
size_t
numOfGroupCols
=
taosArrayGetSize
(
pCols
);
char
*
isNull
=
(
char
*
)
pKey
;
char
*
pStart
=
(
char
*
)
pKey
+
sizeof
(
int8_t
)
*
numOfGroupCols
;
for
(
int32_t
i
=
0
;
i
<
numOfGroupCols
;
++
i
)
{
SColumn
*
pCol
=
(
SColumn
*
)
taosArrayGet
(
pCols
,
i
);
...
...
@@ -193,56 +176,24 @@ static void fillGroupKeyValsFromTagCols(SArray* pCols, SArray* pGroupKeys, SSDat
pColAgg
=
pBlock
->
pBlockAgg
[
pCol
->
slotId
];
// TODO is agg data matched?
}
SGroupKeys
*
pkey
=
taosArrayGet
(
pGroupKeys
,
i
);
if
(
colDataIsNull
(
pColInfoData
,
pBlock
->
info
.
rows
,
rowIndex
,
pColAgg
))
{
pkey
->
isNull
=
true
;
isNull
[
i
]
=
1
;
}
else
{
pkey
->
isNull
=
false
;
isNull
[
i
]
=
0
;
char
*
val
=
colDataGetData
(
pColInfoData
,
rowIndex
);
if
(
pkey
->
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
tTagIsJson
(
val
))
{
terrno
=
TSDB_CODE_QRY_JSON_IN_GROUP_ERROR
;
return
;
}
if
(
pCol
->
type
==
TSDB_DATA_TYPE_JSON
)
{
int32_t
dataLen
=
getJsonValueLen
(
val
);
memcpy
(
pkey
->
pData
,
val
,
dataLen
);
}
else
if
(
IS_VAR_DATA_TYPE
(
pkey
->
type
))
{
memcpy
(
pkey
->
pData
,
val
,
varDataTLen
(
val
));
ASSERT
(
varDataTLen
(
val
)
<=
pkey
->
bytes
);
}
else
{
memcpy
(
pkey
->
pData
,
val
,
pkey
->
bytes
);
}
}
}
}
static
int32_t
combineGroupKeysIntoBuf
(
void
*
pKey
,
const
SArray
*
pGroupKeys
)
{
size_t
numOfGroupCols
=
taosArrayGetSize
(
pGroupKeys
);
char
*
isNull
=
(
char
*
)
pKey
;
char
*
pStart
=
(
char
*
)
pKey
+
sizeof
(
int8_t
)
*
numOfGroupCols
;
for
(
int32_t
i
=
0
;
i
<
numOfGroupCols
;
++
i
)
{
SGroupKeys
*
pkey
=
taosArrayGet
(
pGroupKeys
,
i
);
if
(
pkey
->
isNull
)
{
isNull
[
i
]
=
1
;
continue
;
}
isNull
[
i
]
=
0
;
if
(
pkey
->
type
==
TSDB_DATA_TYPE_JSON
)
{
int32_t
dataLen
=
getJsonValueLen
(
pkey
->
pData
);
memcpy
(
pStart
,
(
pkey
->
pData
),
dataLen
);
memcpy
(
pStart
,
val
,
dataLen
);
pStart
+=
dataLen
;
}
else
if
(
IS_VAR_DATA_TYPE
(
pkey
->
type
))
{
varDataCopy
(
pStart
,
pkey
->
pData
);
pStart
+=
varDataTLen
(
pkey
->
pData
);
ASSERT
(
varDataTLen
(
pkey
->
pData
)
<=
pkey
->
bytes
);
}
else
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
varDataCopy
(
pStart
,
val
);
pStart
+=
varDataTLen
(
val
);
}
else
{
memcpy
(
pStart
,
pkey
->
pData
,
pkey
->
bytes
);
pStart
+=
pkey
->
bytes
;
memcpy
(
pStart
,
val
,
pCol
->
bytes
);
pStart
+=
pCol
->
bytes
;
}
}
}
return
(
int32_t
)(
pStart
-
(
char
*
)
pKey
);
}
...
...
@@ -312,8 +263,8 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
pInfo
->
leftTagCols
=
taosArrayInit
(
4
,
sizeof
(
SColumn
));
pInfo
->
rightTagCols
=
taosArrayInit
(
4
,
sizeof
(
SColumn
));
extractTagEqualCondCols
(
pInfo
,
pDownstream
,
pInfo
->
pTagEqualConditions
,
pInfo
->
leftTagCols
,
pInfo
->
rightTagCols
);
initTagCols
Groupkeys
(
&
pInfo
->
leftTagKeys
,
&
pInfo
->
leftTagKeyLen
,
&
pInfo
->
leftTagKeyBuf
,
pInfo
->
leftTagCols
);
initTagCols
Groupkeys
(
&
pInfo
->
rightTagKeys
,
&
pInfo
->
rightTagKeyLen
,
&
pInfo
->
rightTagKeyBuf
,
pInfo
->
rightTagCols
);
initTagCols
keyBuf
(
&
pInfo
->
leftTagKeyLen
,
&
pInfo
->
leftTagKeyBuf
,
pInfo
->
leftTagCols
);
initTagCols
keyBuf
(
&
pInfo
->
rightTagKeyLen
,
&
pInfo
->
rightTagKeyBuf
,
pInfo
->
rightTagCols
);
}
pOperator
->
fpSet
=
createOperatorFpSet
(
optrDummyOpenFn
,
doMergeJoin
,
NULL
,
destroyMergeJoinOperator
,
optrDefaultBufFn
,
NULL
);
code
=
appendDownstream
(
pOperator
,
pDownstream
,
numOfDownstream
);
...
...
@@ -341,20 +292,13 @@ void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode) {
pColumn
->
scale
=
pColumnNode
->
node
.
resType
.
scale
;
}
static
void
freeGroupKeyData
(
void
*
param
)
{
SGroupKeys
*
pKey
=
(
SGroupKeys
*
)
param
;
taosMemoryFree
(
pKey
->
pData
);
}
void
destroyMergeJoinOperator
(
void
*
param
)
{
SJoinOperatorInfo
*
pJoinOperator
=
(
SJoinOperatorInfo
*
)
param
;
if
(
pJoinOperator
->
pTagEqualConditions
!=
NULL
)
{
taosMemoryFreeClear
(
pJoinOperator
->
rightTagKeyBuf
);
taosArrayDestroyEx
(
pJoinOperator
->
rightTagKeys
,
freeGroupKeyData
);
taosArrayDestroy
(
pJoinOperator
->
rightTagCols
);
taosMemoryFreeClear
(
pJoinOperator
->
leftTagKeyBuf
);
taosArrayDestroyEx
(
pJoinOperator
->
leftTagKeys
,
freeGroupKeyData
);
taosArrayDestroy
(
pJoinOperator
->
leftTagCols
);
}
nodesDestroyNode
(
pJoinOperator
->
pCondAfterMerge
);
...
...
@@ -482,8 +426,7 @@ static int32_t mergeJoinCreateBuildTable(SJoinOperatorInfo* pInfo, SArray* right
SSHashObj
*
buildTable
=
tSimpleHashInit
(
buildTableCap
,
hashFn
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
rightRowLocations
);
++
i
)
{
SRowLocation
*
rightRow
=
taosArrayGet
(
rightRowLocations
,
i
);
fillGroupKeyValsFromTagCols
(
pInfo
->
rightTagCols
,
pInfo
->
rightTagKeys
,
rightRow
->
pDataBlock
,
rightRow
->
pos
);
int32_t
keyLen
=
combineGroupKeysIntoBuf
(
pInfo
->
rightTagKeyBuf
,
pInfo
->
rightTagKeys
);
int32_t
keyLen
=
fillKeyBufFromTagCols
(
pInfo
->
rightTagCols
,
rightRow
->
pDataBlock
,
rightRow
->
pos
,
pInfo
->
rightTagKeyBuf
);
SArray
**
ppRows
=
tSimpleHashGet
(
buildTable
,
pInfo
->
rightTagKeyBuf
,
keyLen
);
if
(
!
ppRows
)
{
SArray
*
rows
=
taosArrayInit
(
4
,
sizeof
(
SRowLocation
));
...
...
@@ -511,8 +454,7 @@ static int32_t mergeJoinLeftRowsRightRows(SOperatorInfo* pOperator, SSDataBlock*
SRowLocation
*
leftRow
=
taosArrayGet
(
leftRowLocations
,
i
);
SArray
*
pRightRows
=
NULL
;
if
(
rightTableHash
!=
NULL
)
{
fillGroupKeyValsFromTagCols
(
pJoinInfo
->
leftTagCols
,
pJoinInfo
->
leftTagKeys
,
leftRow
->
pDataBlock
,
leftRow
->
pos
);
int32_t
keyLen
=
combineGroupKeysIntoBuf
(
pJoinInfo
->
leftTagKeyBuf
,
pJoinInfo
->
leftTagKeys
);
int32_t
keyLen
=
fillKeyBufFromTagCols
(
pJoinInfo
->
leftTagCols
,
leftRow
->
pDataBlock
,
leftRow
->
pos
,
pJoinInfo
->
leftTagKeyBuf
);
SArray
**
ppRightRows
=
tSimpleHashGet
(
rightTableHash
,
pJoinInfo
->
leftTagKeyBuf
,
keyLen
);
if
(
!
ppRightRows
)
{
continue
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录