Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b68bb2a8
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看板
提交
b68bb2a8
编写于
7月 15, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-5037]<fix>: fix the last query performance worse then previous problem.
上级
e1fd86ac
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
23 deletion
+37
-23
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+1
-1
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+22
-18
src/query/src/queryMain.c
src/query/src/queryMain.c
+1
-1
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+13
-3
未找到文件。
src/query/inc/qExecutor.h
浏览文件 @
b68bb2a8
...
...
@@ -589,7 +589,7 @@ int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t nu
SGroupbyExpr
*
createGroupbyExprFromMsg
(
SQueryTableMsg
*
pQueryMsg
,
SColIndex
*
pColIndex
,
int32_t
*
code
);
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
SGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
SExprInfo
*
pSecExprs
,
STableGroupInfo
*
pTableGroupInfo
,
SColumnInfo
*
pTagCols
,
int32_t
vgId
,
char
*
sql
,
uint64_t
*
qId
);
SExprInfo
*
pSecExprs
,
STableGroupInfo
*
pTableGroupInfo
,
SColumnInfo
*
pTagCols
,
int32_t
vgId
,
char
*
sql
,
uint64_t
qId
);
int32_t
initQInfo
(
STsBufInfo
*
pTsBufInfo
,
void
*
tsdb
,
void
*
sourceOptr
,
SQInfo
*
pQInfo
,
SQueryParam
*
param
,
char
*
start
,
int32_t
prevResultLen
,
void
*
merger
);
...
...
src/query/src/qExecutor.c
浏览文件 @
b68bb2a8
...
...
@@ -2268,10 +2268,11 @@ static int32_t updateBlockLoadStatus(SQueryAttr *pQuery, int32_t status) {
return
status
;
}
static
void
doExchangeTimeWindow
(
SQInfo
*
pQInfo
,
STimeWindow
*
win
)
{
SQueryAttr
*
pQueryAttr
=
&
pQInfo
->
query
;
size_t
t
=
taosArrayGetSize
(
pQueryAttr
->
tableGroupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
t
;
++
i
)
{
static
void
doUpdateLastKey
(
SQueryAttr
*
pQueryAttr
)
{
STimeWindow
*
win
=
&
pQueryAttr
->
window
;
size_t
num
=
taosArrayGetSize
(
pQueryAttr
->
tableGroupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SArray
*
p1
=
taosArrayGetP
(
pQueryAttr
->
tableGroupInfo
.
pGroupList
,
i
);
size_t
len
=
taosArrayGetSize
(
p1
);
...
...
@@ -2286,7 +2287,7 @@ static void doExchangeTimeWindow(SQInfo* pQInfo, STimeWindow* win) {
}
}
static
void
changeExecuteScan
Order
(
SQInfo
*
pQInfo
,
SQueryTableMsg
*
pQueryMsg
,
bool
stableQuery
)
{
static
void
updateDataCheck
Order
(
SQInfo
*
pQInfo
,
SQueryTableMsg
*
pQueryMsg
,
bool
stableQuery
)
{
SQueryAttr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
// in case of point-interpolation query, use asc order scan
...
...
@@ -2303,6 +2304,7 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bo
SWAP
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
TSKEY
);
}
pQueryAttr
->
needReverseScan
=
false
;
return
;
}
...
...
@@ -2312,7 +2314,8 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bo
SWAP
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
TSKEY
);
}
doExchangeTimeWindow
(
pQInfo
,
&
pQueryAttr
->
window
);
pQueryAttr
->
needReverseScan
=
false
;
doUpdateLastKey
(
pQueryAttr
);
return
;
}
...
...
@@ -2333,7 +2336,7 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bo
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
skey
);
SWAP
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
TSKEY
);
do
ExchangeTimeWindow
(
pQInfo
,
&
pQueryAttr
->
window
);
do
UpdateLastKey
(
pQueryAttr
);
}
pQueryAttr
->
order
.
order
=
TSDB_ORDER_ASC
;
...
...
@@ -2343,12 +2346,13 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bo
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
skey
);
SWAP
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
TSKEY
);
do
ExchangeTimeWindow
(
pQInfo
,
&
pQueryAttr
->
window
);
do
UpdateLastKey
(
pQueryAttr
);
}
pQueryAttr
->
order
.
order
=
TSDB_ORDER_DESC
;
}
pQueryAttr
->
needReverseScan
=
false
;
}
else
{
// interval query
if
(
stableQuery
)
{
if
(
onlyFirstQuery
(
pQueryAttr
))
{
...
...
@@ -2357,20 +2361,22 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bo
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
skey
);
SWAP
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
TSKEY
);
do
ExchangeTimeWindow
(
pQInfo
,
&
pQueryAttr
->
window
);
do
UpdateLastKey
(
pQueryAttr
);
}
pQueryAttr
->
order
.
order
=
TSDB_ORDER_ASC
;
pQueryAttr
->
needReverseScan
=
false
;
}
else
if
(
onlyLastQuery
(
pQueryAttr
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryAttr
))
{
qDebug
(
msg
,
pQInfo
,
"only-last stable"
,
pQueryAttr
->
order
.
order
,
TSDB_ORDER_DESC
,
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
ekey
,
pQueryAttr
->
window
.
skey
);
SWAP
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
TSKEY
);
do
ExchangeTimeWindow
(
pQInfo
,
&
pQueryAttr
->
window
);
do
UpdateLastKey
(
pQueryAttr
);
}
pQueryAttr
->
order
.
order
=
TSDB_ORDER_DESC
;
pQueryAttr
->
needReverseScan
=
false
;
}
}
}
...
...
@@ -2388,9 +2394,6 @@ static void getIntermediateBufInfo(SQueryRuntimeEnv* pRuntimeEnv, int32_t* ps, i
while
(((
*
rowsize
)
*
MIN_ROWS_PER_PAGE
)
>
(
*
ps
)
-
overhead
)
{
*
ps
=
((
*
ps
)
<<
1u
);
}
// pRuntimeEnv->numOfRowsPerPage = ((*ps) - sizeof(tFilePage)) / (*rowsize);
// assert(pRuntimeEnv->numOfRowsPerPage <= MAX_ROWS_PER_RESBUF_PAGE);
}
#define IS_PREFILTER_TYPE(_t) ((_t) != TSDB_DATA_TYPE_BINARY && (_t) != TSDB_DATA_TYPE_NCHAR)
...
...
@@ -4382,7 +4385,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
break
;
}
case
OP_DataBlocksOptScan
:
{
pRuntimeEnv
->
proot
=
createDataBlocksOptScanInfo
(
pRuntimeEnv
->
pQueryHandle
,
pRuntimeEnv
,
getNumOfScanTimes
(
pQueryAttr
),
1
);
pRuntimeEnv
->
proot
=
createDataBlocksOptScanInfo
(
pRuntimeEnv
->
pQueryHandle
,
pRuntimeEnv
,
getNumOfScanTimes
(
pQueryAttr
),
pQueryAttr
->
needReverseScan
?
1
:
0
);
break
;
}
case
OP_TableScan
:
{
...
...
@@ -4420,8 +4423,10 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
if
(
pQInfo
->
summary
.
queryProfEvents
==
NULL
)
{
qDebug
(
"QInfo:0x%"
PRIx64
" failed to allocate query prof events array"
,
pQInfo
->
qId
);
}
pQInfo
->
summary
.
operatorProfResults
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_TINYINT
),
true
,
HASH_NO_LOCK
);
if
(
pQInfo
->
summary
.
operatorProfResults
==
NULL
)
{
qDebug
(
"QInfo:0x%"
PRIx64
" failed to allocate operator prof results hash"
,
pQInfo
->
qId
);
}
...
...
@@ -4814,7 +4819,6 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime
pInfo
->
reverseTimes
=
reverseTime
;
pInfo
->
current
=
0
;
pInfo
->
order
=
pRuntimeEnv
->
pQueryAttr
->
order
.
order
;
// pInfo->prevGroupId = -1;
SOperatorInfo
*
pOptr
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOptr
->
name
=
"DataBlocksOptimizedScanOperator"
;
...
...
@@ -7366,7 +7370,7 @@ FORCE_INLINE bool checkQIdEqual(void *qHandle, uint64_t qId) {
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
SGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
SExprInfo
*
pSecExprs
,
STableGroupInfo
*
pTableGroupInfo
,
SColumnInfo
*
pTagCols
,
int32_t
vgId
,
char
*
sql
,
uint64_t
*
qId
)
{
char
*
sql
,
uint64_t
qId
)
{
int16_t
numOfCols
=
pQueryMsg
->
numOfCols
;
int16_t
numOfOutput
=
pQueryMsg
->
numOfOutput
;
...
...
@@ -7375,7 +7379,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
goto
_cleanup_qinfo
;
}
pQInfo
->
qId
=
*
qId
;
pQInfo
->
qId
=
qId
;
// to make sure third party won't overwrite this structure
pQInfo
->
signature
=
pQInfo
;
...
...
@@ -7485,7 +7489,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
tsem_init
(
&
pQInfo
->
ready
,
0
,
0
);
pQueryAttr
->
window
=
pQueryMsg
->
window
;
changeExecuteScan
Order
(
pQInfo
,
pQueryMsg
,
pQueryAttr
->
stableQuery
);
updateDataCheck
Order
(
pQInfo
,
pQueryMsg
,
pQueryAttr
->
stableQuery
);
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
STimeWindow
window
=
pQueryAttr
->
window
;
...
...
src/query/src/queryMain.c
浏览文件 @
b68bb2a8
...
...
@@ -162,7 +162,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
assert
(
pQueryMsg
->
stableQuery
==
isSTableQuery
);
(
*
pQInfo
)
=
createQInfoImpl
(
pQueryMsg
,
param
.
pGroupbyExpr
,
param
.
pExprs
,
param
.
pSecExprs
,
&
tableGroupInfo
,
param
.
pTagColumnInfo
,
vgId
,
param
.
sql
,
qId
);
param
.
pTagColumnInfo
,
vgId
,
param
.
sql
,
*
qId
);
param
.
sql
=
NULL
;
param
.
pExprs
=
NULL
;
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
b68bb2a8
...
...
@@ -98,6 +98,8 @@ typedef struct SIOCostSummary {
int64_t
blockLoadTime
;
int64_t
statisInfoLoadTime
;
int64_t
checkForNextTime
;
int64_t
headFileLoad
;
int64_t
headFileLoadTime
;
}
SIOCostSummary
;
typedef
struct
STsdbQueryHandle
{
...
...
@@ -1045,15 +1047,21 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
int32_t
code
=
TSDB_CODE_SUCCESS
;
*
numOfBlocks
=
0
;
pQueryHandle
->
cost
.
headFileLoad
+=
1
;
int64_t
s
=
taosGetTimestampUs
();
size_t
numOfTables
=
0
;
if
(
pQueryHandle
->
loadType
==
BLOCK_LOAD_TABLE_SEQ_ORDER
)
{
code
=
loadBlockInfo
(
pQueryHandle
,
pQueryHandle
->
activeIndex
,
numOfBlocks
);
code
=
loadBlockInfo
(
pQueryHandle
,
pQueryHandle
->
activeIndex
,
numOfBlocks
);
}
else
if
(
pQueryHandle
->
loadType
==
BLOCK_LOAD_OFFSET_SEQ_ORDER
)
{
numOfTables
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfTables
;
++
i
)
{
code
=
loadBlockInfo
(
pQueryHandle
,
i
,
numOfBlocks
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
int64_t
e
=
taosGetTimestampUs
();
pQueryHandle
->
cost
.
headFileLoadTime
+=
(
e
-
s
);
return
code
;
}
}
...
...
@@ -1061,6 +1069,8 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
assert
(
0
);
}
int64_t
e
=
taosGetTimestampUs
();
pQueryHandle
->
cost
.
headFileLoadTime
+=
(
e
-
s
);
return
code
;
}
...
...
@@ -3731,8 +3741,8 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
pQueryHandle
->
next
=
doFreeColumnInfoData
(
pQueryHandle
->
next
);
SIOCostSummary
*
pCost
=
&
pQueryHandle
->
cost
;
tsdbDebug
(
"%p :io-cost summary: statis-info:%"
PRId64
" us, datablock:%"
PRId64
" us, check data:%"
PRId64
" us, 0x%"
PRIx64
,
pQueryHandle
,
pCost
->
statisInfoLoadTime
,
pCost
->
blockLoadTime
,
pCost
->
checkForNextTime
,
pQueryHandle
->
qId
);
tsdbDebug
(
"%p :io-cost summary:
head-file read cnt:%"
PRIu64
", head-file time:%"
PRIu64
" us,
statis-info:%"
PRId64
" us, datablock:%"
PRId64
" us, check data:%"
PRId64
" us, 0x%"
PRIx64
,
pQueryHandle
,
pCost
->
headFileLoad
,
pCost
->
headFileLoadTime
,
pCost
->
statisInfoLoadTime
,
pCost
->
blockLoadTime
,
pCost
->
checkForNextTime
,
pQueryHandle
->
qId
);
tfree
(
pQueryHandle
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录