Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
602d2d1c
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看板
提交
602d2d1c
编写于
2月 07, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225] refactor
上级
86bfad2b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
89 addition
and
66 deletion
+89
-66
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+7
-6
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+82
-60
未找到文件。
src/query/inc/qExecutor.h
浏览文件 @
602d2d1c
...
...
@@ -179,6 +179,12 @@ typedef struct {
SArray
*
pResult
;
// SArray<SStddevInterResult>
}
SInterResult
;
typedef
struct
SSDataBlock
{
SDataStatis
*
pBlockStatis
;
SArray
*
pDataBlock
;
SDataBlockInfo
info
;
}
SSDataBlock
;
typedef
struct
SQuery
{
int16_t
numOfCols
;
int16_t
numOfTags
;
...
...
@@ -214,6 +220,7 @@ typedef struct SQuery {
SOrderedPrjQueryInfo
prjInfo
;
// limit value for each vgroup, only available in global order projection query.
SSingleColumnFilterInfo
*
pFilterInfo
;
SSDataBlock
*
ouptputBuf
;
}
SQuery
;
typedef
struct
SQueryRuntimeEnv
{
...
...
@@ -307,12 +314,6 @@ typedef struct SQueryParam {
SSqlGroupbyExpr
*
pGroupbyExpr
;
}
SQueryParam
;
typedef
struct
SSDataBlock
{
SDataStatis
*
pBlockStatis
;
SArray
*
pDataBlock
;
SDataBlockInfo
info
;
}
SSDataBlock
;
typedef
struct
STableScanInfo
{
SQInfo
*
pQInfo
;
void
*
pQueryHandle
;
...
...
src/query/src/qExecutor.c
浏览文件 @
602d2d1c
...
...
@@ -176,6 +176,22 @@ static STableScanInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQ
static
STableScanInfo
*
createTableScanInfo
(
void
*
pTsdbQueryHandle
,
SQInfo
*
pQInfo
,
int32_t
repeatTime
);
static
int32_t
getNumOfScanTimes
(
SQuery
*
pQuery
);
static
SSDataBlock
*
createOutputBuf
(
SQuery
*
pQuery
)
{
// setup the output buffer
SSDataBlock
*
res
=
calloc
(
1
,
sizeof
(
SSDataBlock
));
res
->
info
.
numOfCols
=
pQuery
->
numOfOutput
;
res
->
pDataBlock
=
taosArrayInit
(
pQuery
->
numOfOutput
,
sizeof
(
SColumnInfoData
));
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
SColumnInfoData
idata
=
{
0
};
idata
.
info
.
type
=
pQuery
->
pExpr1
[
i
].
type
;
idata
.
info
.
bytes
=
pQuery
->
pExpr1
[
i
].
bytes
;
idata
.
info
.
colId
=
pQuery
->
pExpr1
[
i
].
base
.
resColId
;
idata
.
pData
=
calloc
(
4096
,
idata
.
info
.
bytes
);
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
}
}
bool
doFilterData
(
SQuery
*
pQuery
,
int32_t
elemPos
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfFilterCols
;
++
k
)
{
SSingleColumnFilterInfo
*
pFilterInfo
=
&
pQuery
->
pFilterInfo
[
k
];
...
...
@@ -1150,6 +1166,36 @@ static void doWindowBorderInterpolation(SQueryRuntimeEnv* pRuntimeEnv, SDataBloc
}
}
static
void
aggApplyFunctions_rv
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataStatis
*
pStatis
,
SDataBlockInfo
*
pDataBlockInfo
,
SArray
*
pDataBlock
)
{
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
TSKEY
*
tsCols
=
NULL
;
if
(
pDataBlock
!=
NULL
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
0
);
tsCols
=
(
TSKEY
*
)(
pColInfo
->
pData
);
}
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
char
*
dataBlock
=
getDataBlock
(
pRuntimeEnv
,
&
pRuntimeEnv
->
sasArray
[
k
],
k
,
pDataBlockInfo
->
rows
,
pDataBlock
);
setExecParams
(
pQuery
,
&
pCtx
[
k
],
dataBlock
,
tsCols
,
pDataBlockInfo
,
pStatis
,
&
pQuery
->
pExpr1
[
k
]);
}
/*
* the sqlfunctionCtx parameters should be set done before all functions are invoked,
* since the selectivity + tag_prj query needs all parameters been set done.
* tag_prj function are changed to be TSDB_FUNC_TAG_DUMMY
*/
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
pCtx
[
k
].
startTs
=
pQuery
->
window
.
skey
;
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
}
}
}
/**
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
* @param pRuntimeEnv
...
...
@@ -5634,37 +5680,46 @@ static void doSecondaryArithmeticProcess(SQuery* pQuery) {
tfree
(
arithSup
.
data
);
}
static
SSDataBlock
*
doTableScan
(
void
*
param
)
{
STableScanInfo
*
pTableScanInfo
=
(
STableScanInfo
*
)
param
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pTableScanInfo
->
pQInfo
->
runtimeEnv
;
static
SSDataBlock
*
doScanImpl
(
STableScanInfo
*
pTableScanInfo
)
{
SSDataBlock
*
pBlock
=
&
pTableScanInfo
->
block
;
while
(
pTableScanInfo
->
current
<
pTableScanInfo
->
times
)
{
while
(
tsdbNextDataBlock
(
pTableScanInfo
->
pQueryHandle
))
{
pTableScanInfo
->
numOfBlocks
+=
1
;
// todo check for query cancel
while
(
tsdbNextDataBlock
(
pTableScanInfo
->
pQueryHandle
))
{
pTableScanInfo
->
numOfBlocks
+=
1
;
tsdbRetrieveDataBlockInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pBlock
->
info
);
// todo check for query cancel
SDataStatis
*
pStatis
=
pBlock
->
pBlockStatis
;
tsdbRetrieveDataBlockInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pBlock
->
info
)
;
// this function never returns error?
tsdbRetrieveDataBlockStatisInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pStatis
);
pTableScanInfo
->
numOfBlockStatis
+=
1
;
SDataStatis
*
pStatis
=
pBlock
->
pBlockStatis
;
if
(
pBlock
->
pBlockStatis
==
NULL
)
{
// data block statistics does not exist, load data block
pBlock
->
pDataBlock
=
tsdbRetrieveDataBlock
(
pTableScanInfo
->
pQueryHandle
,
NULL
);
pTableScanInfo
->
numOfRows
+=
pBlock
->
info
.
rows
;
}
// this function never returns error?
tsdbRetrieveDataBlockStatisInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pStatis
);
pTableScanInfo
->
numOfBlockStatis
+=
1
;
return
pBlock
;
if
(
pBlock
->
pBlockStatis
==
NULL
)
{
// data block statistics does not exist, load data block
pBlock
->
pDataBlock
=
tsdbRetrieveDataBlock
(
pTableScanInfo
->
pQueryHandle
,
NULL
);
pTableScanInfo
->
numOfRows
+=
pBlock
->
info
.
rows
;
}
return
pBlock
;
}
}
static
SSDataBlock
*
doTableScan
(
void
*
param
)
{
STableScanInfo
*
pTableScanInfo
=
(
STableScanInfo
*
)
param
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pTableScanInfo
->
pQInfo
->
runtimeEnv
;
while
(
pTableScanInfo
->
current
<
pTableScanInfo
->
times
)
{
SSDataBlock
*
p
=
doScanImpl
(
pTableScanInfo
);
if
(
p
!=
NULL
)
{
return
p
;
}
if
(
++
pTableScanInfo
->
current
>=
pTableScanInfo
->
times
)
{
return
NULL
;
}
// do prepare for the next round table scan operation
tsdbCleanupQueryHandle
(
pTableScanInfo
->
pQueryHandle
);
STsdbQueryCond
cond
=
createTsdbQueryCond
(
pRuntimeEnv
->
pQuery
,
&
pRuntimeEnv
->
pQuery
->
window
);
pTableScanInfo
->
pQueryHandle
=
...
...
@@ -5697,29 +5752,16 @@ static SSDataBlock* doTableScan(void* param) {
tsdbQueryTables
(
pTableScanInfo
->
pQInfo
->
tsdb
,
&
cond
,
&
pTableScanInfo
->
pQInfo
->
tableGroupInfo
,
pTableScanInfo
->
pQInfo
,
&
pTableScanInfo
->
pQInfo
->
memRef
);
while
(
tsdbNextDataBlock
(
pTableScanInfo
->
pQueryHandle
))
{
pTableScanInfo
->
numOfBlocks
+=
1
;
// todo check for query cancel
tsdbRetrieveDataBlockInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pBlock
->
info
);
SDataStatis
*
pStatis
=
pBlock
->
pBlockStatis
;
// this function never returns error?
tsdbRetrieveDataBlockStatisInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pStatis
);
pTableScanInfo
->
numOfBlockStatis
+=
1
;
qDebug
(
"QInfo:%p start to reverse scan data blocks due to query func required, qrange:%"
PRId64
"-%"
PRId64
,
pTableScanInfo
->
pQInfo
,
cond
.
twindow
.
skey
,
cond
.
twindow
.
ekey
);
if
(
pBlock
->
pBlockStatis
==
NULL
)
{
// data block statistics does not exist, load data block
pBlock
->
pDataBlock
=
tsdbRetrieveDataBlock
(
pTableScanInfo
->
pQueryHandle
,
NULL
);
pTableScanInfo
->
numOfRows
+=
pBlock
->
info
.
rows
;
}
pTableScanInfo
->
times
=
1
;
pTableScanInfo
->
current
=
0
;
return
pBlock
;
SSDataBlock
*
p
=
doScanImpl
(
pTableScanInfo
);
if
(
p
!=
NULL
)
{
return
p
;
}
qDebug
(
"QInfo:%p start to reverse scan data blocks due to query func required, qrange:%"
PRId64
"-%"
PRId64
,
pTableScanInfo
->
pQInfo
,
cond
.
twindow
.
skey
,
cond
.
twindow
.
ekey
);
}
return
NULL
;
...
...
@@ -5761,27 +5803,6 @@ static UNUSED_FUNC int32_t getTableScanTime(STableScanInfo* pTableScanInfo) {
static
SSDataBlock
*
doAggOperator
(
void
*
param
)
{
SAggOperatorInfo
*
pInfo
=
(
SAggOperatorInfo
*
)
param
;
// setup the output buffer
SSDataBlock
*
res
=
calloc
(
1
,
sizeof
(
SSDataBlock
));
SQuery
*
pQuery
=
pInfo
->
pRuntimeEnv
->
pQuery
;
res
->
info
.
numOfCols
=
pQuery
->
numOfOutput
;
res
->
pDataBlock
=
taosArrayInit
(
pQuery
->
numOfOutput
,
sizeof
(
SColumnInfoData
));
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
SColumnInfoData
idata
=
{
0
};
idata
.
info
.
type
=
pQuery
->
pExpr1
[
i
].
type
;
idata
.
info
.
bytes
=
pQuery
->
pExpr1
[
i
].
bytes
;
idata
.
info
.
colId
=
pQuery
->
pExpr1
[
i
].
base
.
resColId
;
idata
.
pData
=
calloc
(
4096
,
idata
.
info
.
bytes
);
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
pInfo
->
pRuntimeEnv
->
pCtx
[
i
].
pOutput
=
idata
.
pData
;
}
pQuery
->
pos
=
0
;
int32_t
countId
=
0
;
while
(
1
)
{
SSDataBlock
*
pBlock
=
pInfo
->
pTableScanInfo
->
apply
(
pInfo
->
pTableScanInfo
);
...
...
@@ -5793,7 +5814,7 @@ static SSDataBlock* doAggOperator(void* param) {
needRepeatScan
(
pInfo
->
pRuntimeEnv
);
}
blockwiseApplyFunctions
(
pInfo
->
pRuntimeEnv
,
pBlock
->
pBlockStatis
,
&
pBlock
->
info
,
pInfo
->
pResultRowInfo
,
binarySearchForKey
,
pBlock
->
pDataBlock
);
aggApplyFunctions_rv
(
pInfo
->
pRuntimeEnv
,
pBlock
->
pBlockStatis
,
&
pBlock
->
info
,
pBlock
->
pDataBlock
);
}
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
...
...
@@ -6872,6 +6893,7 @@ SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGroupbyExpr
}
doUpdateExprColumnIndex
(
pQuery
);
pQuery
->
ouptputBuf
=
createOutputBuf
(
pQuery
);
int32_t
ret
=
createFilterInfo
(
pQInfo
,
pQuery
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录