Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f5710472
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看板
提交
f5710472
编写于
10月 31, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-1844]
上级
d371c840
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
123 addition
and
48 deletion
+123
-48
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+123
-48
未找到文件。
src/client/src/tscSubquery.c
浏览文件 @
f5710472
...
...
@@ -32,11 +32,15 @@ typedef struct SInsertSupporter {
static
void
freeJoinSubqueryObj
(
SSqlObj
*
pSql
);
static
bool
tscHasRemainDataInSubqueryResultSet
(
SSqlObj
*
pSql
);
static
bool
tsCompare
(
int32_t
order
,
int64_t
left
,
int64_t
right
)
{
static
int32_t
tsCompare
(
int32_t
order
,
int64_t
left
,
int64_t
right
)
{
if
(
left
==
right
)
{
return
0
;
}
if
(
order
==
TSDB_ORDER_ASC
)
{
return
left
<
right
;
return
left
<
right
?
-
1
:
1
;
}
else
{
return
left
>
right
;
return
left
>
right
?
-
1
:
1
;
}
}
...
...
@@ -51,10 +55,10 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ
SLimitVal
*
pLimit
=
&
pQueryInfo
->
limit
;
int32_t
order
=
pQueryInfo
->
order
.
order
;
SQueryInfo
*
pSubQueryInfo1
=
tscGetQueryInfoDetail
(
&
pSql
->
pSubs
[
0
]
->
cmd
,
0
);
SQueryInfo
*
pSubQueryInfo2
=
tscGetQueryInfoDetail
(
&
pSql
->
pSubs
[
1
]
->
cmd
,
0
);
pSubQueryInfo1
->
tsBuf
=
output1
;
pSubQueryInfo2
->
tsBuf
=
output2
;
...
...
@@ -88,59 +92,106 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ
int64_t
numOfInput1
=
1
;
int64_t
numOfInput2
=
1
;
while
(
1
)
{
STSElem
elem1
=
tsBufGetElem
(
pSupporter1
->
pTSBuf
)
;
STSElem
elem2
=
tsBufGetElem
(
pSupporter2
->
pTSBuf
);
int32_t
numOfVnodes
=
0
;
int32_t
*
idList
=
NULL
;
tsBufGetVnodeIdList
(
pSupporter2
->
pTSBuf
,
&
numOfVnodes
,
&
idList
);
#ifdef _DEBUG_VIEW
tscInfo
(
"%"
PRId64
", tags:%"
PRId64
"
\t
%"
PRId64
", tags:%"
PRId64
,
elem1
.
ts
,
elem1
.
tag
.
i64Key
,
elem2
.
ts
,
elem2
.
tag
.
i64Key
);
#endif
bool
completed
=
false
;
while
(
1
)
{
STSElem
elem
=
tsBufGetElem
(
pSupporter1
->
pTSBuf
);
int32_t
res
=
tVariantCompare
(
elem1
.
tag
,
elem2
.
tag
);
if
(
res
==
-
1
||
(
res
==
0
&&
tsCompare
(
order
,
elem1
.
ts
,
elem2
.
ts
)))
{
if
(
!
tsBufNextPos
(
pSupporter1
->
pTSBuf
))
{
break
;
}
// no data in pSupporter1 anymore, jump out of loop
if
(
elem
.
vnode
<
0
||
completed
)
{
break
;
}
numOfInput1
++
;
}
else
if
((
res
>
0
)
||
(
res
==
0
&&
tsCompare
(
order
,
elem2
.
ts
,
elem1
.
ts
)))
{
if
(
!
tsBufNextPos
(
pSupporter2
->
pTSBuf
))
{
bool
f
=
false
;
for
(
int32_t
i
=
0
;
i
<
numOfVnodes
;
++
i
)
{
STSElem
el
=
tsBufGetElemStartPos
(
pSupporter2
->
pTSBuf
,
idList
[
i
],
elem
.
tag
);
if
(
el
.
vnode
==
idList
[
i
])
{
f
=
true
;
break
;
}
}
numOfInput2
++
;
}
else
{
/*
* in case of stable query, limit/offset is not applied here. the limit/offset is applied to the
* final results which is acquired after the secondry merge of in the client.
*/
if
(
pLimit
->
offset
==
0
||
pQueryInfo
->
interval
.
interval
>
0
||
QUERY_IS_STABLE_QUERY
(
pQueryInfo
->
type
))
{
if
(
win
->
skey
>
elem1
.
ts
)
{
win
->
skey
=
elem1
.
ts
;
}
if
(
win
->
ekey
<
elem1
.
ts
)
{
win
->
ekey
=
elem1
.
ts
;
}
tsBufAppend
(
output1
,
elem1
.
vnode
,
elem1
.
tag
,
(
const
char
*
)
&
elem1
.
ts
,
sizeof
(
elem1
.
ts
));
tsBufAppend
(
output2
,
elem2
.
vnode
,
elem2
.
tag
,
(
const
char
*
)
&
elem2
.
ts
,
sizeof
(
elem2
.
ts
));
/**
* there are elements in pSupporter2 with the same tag, continue
*/
if
(
f
)
{
while
(
1
)
{
STSElem
elem1
=
tsBufGetElem
(
pSupporter1
->
pTSBuf
);
STSElem
elem2
=
tsBufGetElem
(
pSupporter2
->
pTSBuf
);
/*
* in case of stable query, limit/offset is not applied here. the limit/offset is applied to the
* final results which is acquired after the secondry merge of in the client.
*/
int32_t
re
=
tsCompare
(
order
,
elem1
.
ts
,
elem2
.
ts
);
if
(
re
<
0
)
{
if
(
!
tsBufNextPos
(
pSupporter1
->
pTSBuf
))
{
completed
=
true
;
break
;
}
}
else
{
pLimit
->
offset
-=
1
;
}
numOfInput1
++
;
}
else
if
(
re
>
0
)
{
if
(
!
tsBufNextPos
(
pSupporter2
->
pTSBuf
))
{
completed
=
true
;
break
;
}
if
(
!
tsBufNextPos
(
pSupporter1
->
pTSBuf
))
{
break
;
numOfInput2
++
;
}
else
{
if
(
pLimit
->
offset
==
0
||
pQueryInfo
->
interval
.
interval
>
0
||
QUERY_IS_STABLE_QUERY
(
pQueryInfo
->
type
))
{
if
(
win
->
skey
>
elem1
.
ts
)
{
win
->
skey
=
elem1
.
ts
;
}
if
(
win
->
ekey
<
elem1
.
ts
)
{
win
->
ekey
=
elem1
.
ts
;
}
tsBufAppend
(
output1
,
elem1
.
vnode
,
elem1
.
tag
,
(
const
char
*
)
&
elem1
.
ts
,
sizeof
(
elem1
.
ts
));
tsBufAppend
(
output2
,
elem2
.
vnode
,
elem2
.
tag
,
(
const
char
*
)
&
elem2
.
ts
,
sizeof
(
elem2
.
ts
));
}
else
{
pLimit
->
offset
-=
1
;
}
if
(
!
tsBufNextPos
(
pSupporter1
->
pTSBuf
))
{
completed
=
true
;
break
;
}
numOfInput1
++
;
if
(
!
tsBufNextPos
(
pSupporter2
->
pTSBuf
))
{
completed
=
true
;
break
;
}
numOfInput2
++
;
}
}
}
else
{
// no data in pSupporter2, ignore current data in pSupporter2
tVariant
tag
=
{
0
};
tVariantAssign
(
&
tag
,
elem
.
tag
);
numOfInput1
++
;
// ignore all records with the same tag
while
(
tsBufNextPos
(
pSupporter1
->
pTSBuf
))
{
STSElem
el1
=
tsBufGetElem
(
pSupporter1
->
pTSBuf
);
int32_t
res
=
tVariantCompare
(
el1
.
tag
,
&
tag
);
if
(
!
tsBufNextPos
(
pSupporter2
->
pTSBuf
))
{
break
;
// it is a record with new tag
if
(
res
!=
0
)
{
break
;
}
}
numOfInput2
++
;
STSElem
el1
=
tsBufGetElem
(
pSupporter1
->
pTSBuf
);
if
(
el1
.
vnode
<
0
)
{
// no data exists, abort
completed
=
true
;
break
;
}
}
}
...
...
@@ -162,8 +213,9 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ
TSKEY
et
=
taosGetTimestampUs
();
tscDebug
(
"%p input1:%"
PRId64
", input2:%"
PRId64
", final:%"
PRId64
" in %d vnodes for secondary query after ts blocks "
"intersecting, skey:%"
PRId64
", ekey:%"
PRId64
", numOfVnode:%d, elasped time:%"
PRId64
" us"
,
pSql
,
numOfInput1
,
numOfInput2
,
output1
->
numOfTotal
,
output1
->
numOfVnodes
,
win
->
skey
,
win
->
ekey
,
tsBufGetNumOfVnodes
(
output1
),
et
-
st
);
"intersecting, skey:%"
PRId64
", ekey:%"
PRId64
", numOfVnode:%d, elapsed time:%"
PRId64
" us"
,
pSql
,
numOfInput1
,
numOfInput2
,
output1
->
numOfTotal
,
output1
->
numOfVnodes
,
win
->
skey
,
win
->
ekey
,
tsBufGetNumOfVnodes
(
output1
),
et
-
st
);
return
output1
->
numOfTotal
;
}
...
...
@@ -517,18 +569,29 @@ void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArr
vgTables
=
taosArrayInit
(
4
,
sizeof
(
STableIdInfo
));
info
.
itemList
=
vgTables
;
if
(
taosArrayGetSize
(
result
)
>
0
)
{
SVgroupTableInfo
*
prevGroup
=
taosArrayGet
(
result
,
taosArrayGetSize
(
result
)
-
1
);
tscDebug
(
"%p vgId:%d, tables:%"
PRId64
,
pSql
,
prevGroup
->
vgInfo
.
vgId
,
taosArrayGetSize
(
prevGroup
->
itemList
));
}
taosArrayPush
(
result
,
&
info
);
}
STableIdInfo
item
=
{.
uid
=
tt
->
uid
,
.
tid
=
tt
->
tid
,
.
key
=
INT64_MIN
};
taosArrayPush
(
vgTables
,
&
item
);
tsc
Debug
(
"%p tid:%d, uid:%"
PRIu64
",vgId:%d added, total:%d"
,
pSql
,
tt
->
tid
,
tt
->
uid
,
tt
->
vgId
,
(
int32_t
)
taosArrayGetSize
(
vgTables
)
);
tsc
Trace
(
"%p tid:%d, uid:%"
PRIu64
",vgId:%d added"
,
pSql
,
tt
->
tid
,
tt
->
uid
,
tt
->
vgId
);
prev
=
tt
;
}
pTableMetaInfo
->
pVgroupTables
=
result
;
pTableMetaInfo
->
vgroupIndex
=
0
;
if
(
taosArrayGetSize
(
result
)
>
0
)
{
SVgroupTableInfo
*
g
=
taosArrayGet
(
result
,
taosArrayGetSize
(
result
)
-
1
);
tscDebug
(
"%p vgId:%d, tables:%"
PRId64
,
pSql
,
g
->
vgInfo
.
vgId
,
taosArrayGetSize
(
g
->
itemList
));
}
}
static
void
issueTSCompQuery
(
SSqlObj
*
pSql
,
SJoinSupporter
*
pSupporter
,
SSqlObj
*
pParent
)
{
...
...
@@ -656,6 +719,18 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar
qsort
((
*
s1
)
->
pData
,
t1
,
size
,
tidTagsCompar
);
qsort
((
*
s2
)
->
pData
,
t2
,
size
,
tidTagsCompar
);
#if 0
for(int32_t k = 0; k < t1; ++k) {
STidTags* p = (*s1)->pData + size * k;
printf("%d, tag:%s\n", p->vgId, ((tstr*)(p->tag))->data);
}
for(int32_t k = 0; k < t1; ++k) {
STidTags* p = (*s2)->pData + size * k;
printf("%d, tag:%s\n", p->vgId, ((tstr*)(p->tag))->data);
}
#endif
tscDebug
(
"%p tags match complete, result: %"
PRId64
", %"
PRId64
,
pParentSql
,
t1
,
t2
);
return
TSDB_CODE_SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录