Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
0e3d3ddb
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0e3d3ddb
编写于
6月 03, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225] add query cost statistics.
上级
b91c7048
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
46 deletion
+40
-46
src/client/src/tscProfile.c
src/client/src/tscProfile.c
+2
-2
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+7
-6
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+31
-38
未找到文件。
src/client/src/tscProfile.c
浏览文件 @
0e3d3ddb
...
...
@@ -100,7 +100,7 @@ void tscSaveSlowQuery(SSqlObj *pSql) {
char
*
sql
=
malloc
(
sqlSize
);
if
(
sql
==
NULL
)
{
tscError
(
"%p failed to allocate memory to sent slow to dnode"
,
pSql
);
tscError
(
"%p failed to allocate memory to sent slow
query
to dnode"
,
pSql
);
return
;
}
...
...
@@ -112,8 +112,8 @@ void tscSaveSlowQuery(SSqlObj *pSql) {
}
else
{
sqlLen
+=
len
;
}
strcpy
(
sql
+
sqlLen
,
"')"
);
taosTmrStart
(
tscSaveSlowQueryFp
,
200
,
sql
,
tscTmr
);
}
...
...
src/query/inc/qExecutor.h
浏览文件 @
0e3d3ddb
...
...
@@ -116,11 +116,14 @@ typedef struct SQueryCostInfo {
uint64_t
loadDataInCacheSize
;
uint64_t
loadDataTime
;
uint64_t
dataInRows
;
uint64_t
checkRows
;
uint32_t
dataBlocks
;
uint64_t
totalRows
;
uint64_t
totalCheckedRows
;
uint32_t
totalBlocks
;
uint32_t
loadBlocks
;
uint32_t
loadBlockStatis
;
uint32_t
discardBlocks
;
uint64_t
elapsedTime
;
uint64_t
computTime
;
}
SQueryCostInfo
;
typedef
struct
SGroupItem
{
...
...
@@ -168,7 +171,7 @@ typedef struct SQueryRuntimeEnv {
SWindowResInfo
windowResInfo
;
STSBuf
*
pTSBuf
;
STSCursor
cur
;
SQueryCostInfo
summary
;
SQueryCostInfo
summary
;
bool
stableQuery
;
// super table query or not
void
*
pQueryHandle
;
void
*
pSecQueryHandle
;
// another thread for
...
...
@@ -177,8 +180,6 @@ typedef struct SQueryRuntimeEnv {
typedef
struct
SQInfo
{
void
*
signature
;
TSKEY
startTime
;
TSKEY
elapsedTime
;
int32_t
pointsInterpo
;
int32_t
code
;
// error code to returned to client
sem_t
dataReady
;
...
...
src/query/src/qExecutor.c
浏览文件 @
0e3d3ddb
...
...
@@ -1183,6 +1183,7 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
STableQueryInfo
*
pTableQInfo
=
pQuery
->
current
;
SWindowResInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
pQuery
->
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
rows
-
1
;
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTSBuf
!=
NULL
||
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
rowwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
pDataBlock
);
...
...
@@ -1190,10 +1191,10 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
blockwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
searchFn
,
pDataBlock
);
}
// update the lastkey of current table
TSKEY
lastKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
pTableQInfo
->
lastKey
=
lastKey
+
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
// interval query with limit applied
int32_t
numOfRes
=
0
;
...
...
@@ -2013,7 +2014,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, void* pQueryHandle,
if
(
*
pStatis
==
NULL
)
{
// data block statistics does not exist, load data block
pDataBlock
=
tsdbRetrieveDataBlock
(
pQueryHandle
,
NULL
);
pRuntimeEnv
->
summary
.
check
Rows
+=
pBlockInfo
->
rows
;
pRuntimeEnv
->
summary
.
totalChecked
Rows
+=
pBlockInfo
->
rows
;
}
}
else
{
assert
(
r
==
BLK_DATA_ALL_NEEDED
);
...
...
@@ -2032,7 +2033,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, void* pQueryHandle,
// return DISK_DATA_DISCARDED;
}
pRuntimeEnv
->
summary
.
check
Rows
+=
pBlockInfo
->
rows
;
pRuntimeEnv
->
summary
.
totalChecked
Rows
+=
pBlockInfo
->
rows
;
pDataBlock
=
tsdbRetrieveDataBlock
(
pQueryHandle
,
NULL
);
}
...
...
@@ -2149,7 +2150,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
TsdbQueryHandleT
pQueryHandle
=
IS_MASTER_SCAN
(
pRuntimeEnv
)
?
pRuntimeEnv
->
pQueryHandle
:
pRuntimeEnv
->
pSecQueryHandle
;
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
pRuntimeEnv
->
summary
.
data
Blocks
+=
1
;
pRuntimeEnv
->
summary
.
total
Blocks
+=
1
;
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
return
0
;
}
...
...
@@ -2185,12 +2186,10 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
ensureOutputBuffer
(
pRuntimeEnv
,
&
blockInfo
);
SDataStatis
*
pStatis
=
NULL
;
pQuery
->
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
blockInfo
.
rows
-
1
;
SArray
*
pDataBlock
=
loadDataBlockOnDemand
(
pRuntimeEnv
,
pQueryHandle
,
&
blockInfo
,
&
pStatis
);
int32_t
numOfRes
=
tableApplyFunctionsOnBlock
(
pRuntimeEnv
,
&
blockInfo
,
pStatis
,
binarySearchForKey
,
pDataBlock
);
pRuntimeEnv
->
summary
.
dataIn
Rows
+=
blockInfo
.
rows
;
pRuntimeEnv
->
summary
.
total
Rows
+=
blockInfo
.
rows
;
qTrace
(
"QInfo:%p check data block, brange:%"
PRId64
"-%"
PRId64
", numOfRows:%d, numOfRes:%d, lastKey:%"
PRId64
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
ekey
,
blockInfo
.
rows
,
numOfRes
,
pQuery
->
current
->
lastKey
);
...
...
@@ -3247,7 +3246,7 @@ void destroyTableQueryInfo(STableQueryInfo *pTableQueryInfo, int32_t numOfCols)
free
(
pTableQueryInfo
);
}
void
restoreIntervalQueryRang
e
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableQueryInfo
*
pTableQueryInfo
)
{
void
setCurrentQueryTabl
e
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableQueryInfo
*
pTableQueryInfo
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
pQuery
->
current
=
pTableQueryInfo
;
...
...
@@ -3316,7 +3315,7 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
STableId
*
pTableId
,
STableQueryInfo
*
pTableQueryInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
assert
(
pTableQueryInfo
->
lastKey
>=
0
);
assert
(
pTableQueryInfo
->
lastKey
>=
TSKEY_INITIAL_VAL
);
setTagVal
(
pRuntimeEnv
,
pTableId
,
pQInfo
->
tsdb
);
...
...
@@ -3528,10 +3527,11 @@ static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv, STableQueryIn
}
}
void
stableApplyFunctionsOnBlock
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableQueryInfo
*
pTableQueryInfo
,
SDataBlockInfo
*
pDataBlockInfo
,
SDataStatis
*
pStatis
,
SArray
*
pDataBlock
,
__block_search_fn_t
searchFn
)
{
void
stableApplyFunctionsOnBlock
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
SDataStatis
*
pStatis
,
SArray
*
pDataBlock
,
__block_search_fn_t
searchFn
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
STableQueryInfo
*
pTableQueryInfo
=
pQuery
->
current
;
SWindowResInfo
*
pWindowResInfo
=
&
pTableQueryInfo
->
windowResInfo
;
pQuery
->
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
rows
-
1
;
...
...
@@ -3685,8 +3685,9 @@ static void queryCostStatis(SQInfo *pQInfo) {
// pQInfo, pSummary->readDiskBlocks, pSummary->totalBlockSize, pSummary->loadBlocksUs / 1000.0,
// pSummary->skippedFileBlocks, pSummary->totalGenData);
qTrace
(
"QInfo:%p cost: check blocks:%d, statis:%d, rows:%"
PRId64
", check rows:%"
PRId64
,
pQInfo
,
pSummary
->
dataBlocks
,
pSummary
->
loadBlockStatis
,
pSummary
->
dataInRows
,
pSummary
->
checkRows
);
qTrace
(
"QInfo:%p :cost summary: elpased time:%"
PRId64
" us, total blocks:%d, use block statis:%d, use block data:%d, "
"total rows:%"
PRId64
", check rows:%"
PRId64
,
pQInfo
,
pSummary
->
elapsedTime
,
pSummary
->
totalBlocks
,
pSummary
->
loadBlockStatis
,
pSummary
->
loadBlocks
,
pSummary
->
totalRows
,
pSummary
->
totalCheckedRows
);
// qTrace("QInfo:%p cost: temp file:%d Bytes", pQInfo, pSummary->tmpBufferInDisk);
//
...
...
@@ -4082,12 +4083,13 @@ static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
static
int64_t
queryOnDataBlocks
(
SQInfo
*
pQInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQueryCostInfo
*
summary
=
&
pRuntimeEnv
->
summary
;
int64_t
st
=
taosGetTimestampMs
();
TsdbQueryHandleT
pQueryHandle
=
IS_MASTER_SCAN
(
pRuntimeEnv
)
?
pRuntimeEnv
->
pQueryHandle
:
pRuntimeEnv
->
pSecQueryHandle
;
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
summary
->
totalBlocks
+=
1
;
if
(
isQueryKilled
(
pQInfo
))
{
break
;
}
...
...
@@ -4119,11 +4121,9 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
}
assert
(
pTableQueryInfo
!=
NULL
);
restoreIntervalQueryRange
(
pRuntimeEnv
,
pTableQueryInfo
);
printf
(
"table:%d, groupIndex:%d, rows:%d
\n
"
,
pTableQueryInfo
->
id
.
tid
,
pTableQueryInfo
->
groupIndex
,
blockInfo
.
tid
);
setCurrentQueryTable
(
pRuntimeEnv
,
pTableQueryInfo
);
SDataStatis
*
pStatis
=
NULL
;
SArray
*
pDataBlock
=
loadDataBlockOnDemand
(
pRuntimeEnv
,
pQueryHandle
,
&
blockInfo
,
&
pStatis
);
if
(
!
isIntervalQuery
(
pQuery
))
{
...
...
@@ -4132,15 +4132,14 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) {
}
else
{
// interval query
TSKEY
nextKey
=
blockInfo
.
window
.
skey
;
setIntervalQueryRange
(
pQInfo
,
nextKey
);
int32_t
ret
=
setAdditionalInfo
(
pQInfo
,
&
pTableQueryInfo
->
id
,
pTableQueryInfo
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
pQInfo
->
code
=
ret
;
return
taosGetTimestampMs
()
-
st
;
}
/*int32_t ret = */
setAdditionalInfo
(
pQInfo
,
&
pTableQueryInfo
->
id
,
pTableQueryInfo
);
}
stableApplyFunctionsOnBlock
(
pRuntimeEnv
,
pTableQueryInfo
,
&
blockInfo
,
pStatis
,
pDataBlock
,
binarySearchForKey
);
summary
->
totalRows
+=
blockInfo
.
rows
;
stableApplyFunctionsOnBlock
(
pRuntimeEnv
,
&
blockInfo
,
pStatis
,
pDataBlock
,
binarySearchForKey
);
qTrace
(
"QInfo:%p check data block, brange:%"
PRId64
"-%"
PRId64
", numOfRows:%d, lastKey:%"
PRId64
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
ekey
,
blockInfo
.
rows
,
pQuery
->
current
->
lastKey
);
}
int64_t
et
=
taosGetTimestampMs
();
...
...
@@ -4502,10 +4501,6 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
}
if
(
pQuery
->
rec
.
rows
==
0
)
{
// queryCostStatis(pSupporter);
}
qTrace
(
"QInfo:%p current:%lld, total:%lld"
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
return
;
}
...
...
@@ -4810,7 +4805,7 @@ static void tableQueryImpl(SQInfo *pQInfo) {
}
// record the total elapsed time
p
QInfo
->
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
p
RuntimeEnv
->
summary
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
assert
(
pQInfo
->
groupInfo
.
numOfTables
==
1
);
/* check if query is killed or not */
...
...
@@ -4840,13 +4835,10 @@ static void stableQueryImpl(SQInfo *pQInfo) {
}
// record the total elapsed time
pQInfo
->
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
// taosFillSetStartInfo(&pQInfo->runtimeEnv.pFillInfo, pQuery->size, pQInfo->query.fillType);
pQInfo
->
runtimeEnv
.
summary
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
if
(
pQuery
->
rec
.
rows
==
0
)
{
qTrace
(
"QInfo:%p over, %d tables queried, %d points are returned"
,
pQInfo
,
pQInfo
->
groupInfo
.
numOfTables
,
pQuery
->
rec
.
total
);
// queryCostStatis(pSupporter);
qTrace
(
"QInfo:%p over, %d tables queried, %d rows are returned"
,
pQInfo
,
pQInfo
->
groupInfo
.
numOfTables
,
pQuery
->
rec
.
total
);
}
}
...
...
@@ -5949,6 +5941,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
return
TSDB_CODE_INVALID_QHANDLE
;
}
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
size_t
size
=
getResultSize
(
pQInfo
,
&
pQuery
->
rec
.
rows
);
size
+=
sizeof
(
int32_t
);
...
...
@@ -5962,7 +5955,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
int32_t
code
=
pQInfo
->
code
;
if
(
code
==
TSDB_CODE_SUCCESS
)
{
(
*
pRsp
)
->
offset
=
htobe64
(
pQuery
->
limit
.
offset
);
(
*
pRsp
)
->
useconds
=
htobe64
(
p
QInfo
->
elapsedTime
);
(
*
pRsp
)
->
useconds
=
htobe64
(
p
RuntimeEnv
->
summary
.
elapsedTime
);
}
else
{
(
*
pRsp
)
->
offset
=
0
;
(
*
pRsp
)
->
useconds
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录