Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9b224d9b
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9b224d9b
编写于
2月 12, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225] refactor
上级
40bdfdb2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
151 addition
and
51 deletion
+151
-51
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+16
-11
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+135
-40
未找到文件。
src/query/inc/qExecutor.h
浏览文件 @
9b224d9b
...
@@ -237,6 +237,17 @@ typedef struct SQuery {
...
@@ -237,6 +237,17 @@ typedef struct SQuery {
STableGroupInfo
tableGroupInfo
;
// table <tid, last_key> list SArray<STableKeyInfo>
STableGroupInfo
tableGroupInfo
;
// table <tid, last_key> list SArray<STableKeyInfo>
}
SQuery
;
}
SQuery
;
typedef
SSDataBlock
*
(
*
__operator_fn_t
)(
void
*
param
);
typedef
struct
SOperatorInfo
{
char
*
name
;
bool
blockingOptr
;
void
*
optInfo
;
__operator_fn_t
exec
;
struct
SOperatorInfo
*
upstream
;
}
SOperatorInfo
;
typedef
struct
SQueryRuntimeEnv
{
typedef
struct
SQueryRuntimeEnv
{
jmp_buf
env
;
jmp_buf
env
;
SQuery
*
pQuery
;
SQuery
*
pQuery
;
...
@@ -329,8 +340,6 @@ typedef struct SQueryParam {
...
@@ -329,8 +340,6 @@ typedef struct SQueryParam {
SSqlGroupbyExpr
*
pGroupbyExpr
;
SSqlGroupbyExpr
*
pGroupbyExpr
;
}
SQueryParam
;
}
SQueryParam
;
typedef
SSDataBlock
*
(
*
__operator_fn_t
)(
void
*
param
);
typedef
struct
STableScanInfo
{
typedef
struct
STableScanInfo
{
SQueryRuntimeEnv
*
pRuntimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
void
*
pQueryHandle
;
void
*
pQueryHandle
;
...
@@ -350,23 +359,19 @@ typedef struct STableScanInfo {
...
@@ -350,23 +359,19 @@ typedef struct STableScanInfo {
int64_t
elapsedTime
;
int64_t
elapsedTime
;
}
STableScanInfo
;
}
STableScanInfo
;
typedef
struct
SOperatorInfo
{
char
*
name
;
bool
blockingOptr
;
void
*
optInfo
;
__operator_fn_t
exec
;
}
SOperatorInfo
;
SOperatorInfo
optrList
[
5
];
SOperatorInfo
optrList
[
5
];
typedef
struct
SAggOperatorInfo
{
typedef
struct
SAggOperatorInfo
{
SResultRowInfo
*
pResultRowInfo
;
SResultRowInfo
*
pResultRowInfo
;
STableQueryInfo
*
pTableQueryInfo
;
STableQueryInfo
*
pTableQueryInfo
;
SOperatorInfo
*
prevOptr
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
}
SAggOperatorInfo
;
}
SAggOperatorInfo
;
typedef
struct
SArithOperatorInfo
{
STableQueryInfo
*
pTableQueryInfo
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
}
SArithOperatorInfo
;
void
freeParam
(
SQueryParam
*
param
);
void
freeParam
(
SQueryParam
*
param
);
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
SQueryParam
*
param
);
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
SQueryParam
*
param
);
int32_t
createQueryFuncExprFromMsg
(
SQueryTableMsg
*
pQueryMsg
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
SSqlFuncMsg
**
pExprMsg
,
int32_t
createQueryFuncExprFromMsg
(
SQueryTableMsg
*
pQueryMsg
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
SSqlFuncMsg
**
pExprMsg
,
...
...
src/query/src/qExecutor.c
浏览文件 @
9b224d9b
...
@@ -173,8 +173,8 @@ static void doRowwiseTimeWindowInterpolation(SQueryRuntimeEnv* pRuntimeEnv, SArr
...
@@ -173,8 +173,8 @@ static void doRowwiseTimeWindowInterpolation(SQueryRuntimeEnv* pRuntimeEnv, SArr
static
STsdbQueryCond
createTsdbQueryCond
(
SQuery
*
pQuery
,
STimeWindow
*
win
);
static
STsdbQueryCond
createTsdbQueryCond
(
SQuery
*
pQuery
,
STimeWindow
*
win
);
static
STableIdInfo
createTableIdInfo
(
SQuery
*
pQuery
);
static
STableIdInfo
createTableIdInfo
(
SQuery
*
pQuery
);
static
S
TableScan
Info
*
createBiDirectionTableScanInfo
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
);
static
S
Operator
Info
*
createBiDirectionTableScanInfo
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
);
static
S
TableScan
Info
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
);
static
S
Operator
Info
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
);
static
int32_t
getNumOfScanTimes
(
SQuery
*
pQuery
);
static
int32_t
getNumOfScanTimes
(
SQuery
*
pQuery
);
static
SSDataBlock
*
createOutputBuf
(
SQuery
*
pQuery
)
{
static
SSDataBlock
*
createOutputBuf
(
SQuery
*
pQuery
)
{
...
@@ -1220,6 +1220,63 @@ static void aggApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pSData
...
@@ -1220,6 +1220,63 @@ static void aggApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pSData
}
}
}
}
static
void
arithmeticApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pSDataBlock
)
{
SArithmeticSupport
arithSup
=
{
0
};
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
// create the output result buffer
tFilePage
**
data
=
calloc
(
pQuery
->
numOfExpr2
,
POINTER_BYTES
);
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfExpr2
;
++
i
)
{
int32_t
bytes
=
pQuery
->
pExpr2
[
i
].
bytes
;
data
[
i
]
=
(
tFilePage
*
)
malloc
((
size_t
)(
bytes
*
pQuery
->
rec
.
rows
)
+
sizeof
(
tFilePage
));
}
arithSup
.
numOfCols
=
(
int32_t
)
pSDataBlock
->
info
.
numOfCols
;
arithSup
.
exprList
=
pQuery
->
pExpr1
;
arithSup
.
data
=
calloc
(
arithSup
.
numOfCols
,
POINTER_BYTES
);
// set the input column data
for
(
int32_t
f
=
0
;
f
<
arithSup
.
numOfCols
;
++
f
)
{
SColumnInfoData
*
pColumnInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
f
);
arithSup
.
data
[
f
]
=
pColumnInfoData
->
pData
;
}
// output result number of columns
for
(
int32_t
k
=
0
;
k
<
pRuntimeEnv
->
outputBuf
->
info
.
numOfCols
;
++
k
)
{
for
(
int
i
=
0
;
i
<
pQuery
->
numOfExpr2
;
++
i
)
{
SExprInfo
*
pExpr
=
&
pQuery
->
pExpr2
[
i
];
// calculate the result from several other columns
SSqlFuncMsg
*
pSqlFunc
=
&
pExpr
->
base
;
if
(
pSqlFunc
->
functionId
!=
TSDB_FUNC_ARITHM
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
if
(
pSqlFunc
->
functionId
==
pQuery
->
pExpr1
[
j
].
base
.
functionId
&&
pSqlFunc
->
colInfo
.
colId
==
pQuery
->
pExpr1
[
j
].
base
.
colInfo
.
colId
)
{
memcpy
(
data
[
i
]
->
data
,
pQuery
->
sdata
[
j
]
->
data
,
(
size_t
)(
pQuery
->
pExpr1
[
j
].
bytes
*
pSDataBlock
->
info
.
rows
));
break
;
}
}
}
else
{
arithSup
.
pArithExpr
=
pExpr
;
arithmeticTreeTraverse
(
arithSup
.
pArithExpr
->
pExpr
,
(
int32_t
)
pQuery
->
rec
.
rows
,
data
[
i
]
->
data
,
&
arithSup
,
TSDB_ORDER_ASC
,
getArithemicInputSrc
);
}
}
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfExpr2
;
++
i
)
{
memcpy
(
pQuery
->
sdata
[
i
]
->
data
,
data
[
i
]
->
data
,
(
size_t
)(
pQuery
->
pExpr2
[
i
].
bytes
*
pQuery
->
rec
.
rows
));
}
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfExpr2
;
++
i
)
{
tfree
(
data
[
i
]);
}
tfree
(
data
);
tfree
(
arithSup
.
data
);
}
}
/**
/**
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
* @param pRuntimeEnv
* @param pRuntimeEnv
...
@@ -5890,17 +5947,16 @@ static UNUSED_FUNC SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle
...
@@ -5890,17 +5947,16 @@ static UNUSED_FUNC SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle
pOptr
->
name
=
"SeqScanTableOp"
;
pOptr
->
name
=
"SeqScanTableOp"
;
pOptr
->
blockingOptr
=
false
;
pOptr
->
blockingOptr
=
false
;
pOptr
->
optInfo
=
pInfo
;
pOptr
->
optInfo
=
pInfo
;
pOptr
->
exec
=
do
ScanTable
;
pOptr
->
exec
=
do
TableScan
;
return
pOptr
;
return
pOptr
;
}
}
static
S
TableScan
Info
*
createBiDirectionTableScanInfo
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
)
{
static
S
Operator
Info
*
createBiDirectionTableScanInfo
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
)
{
assert
(
repeatTime
>
0
);
assert
(
repeatTime
>
0
);
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
pInfo
->
exec
=
doTableScan
;
pInfo
->
times
=
repeatTime
;
pInfo
->
times
=
repeatTime
;
pInfo
->
reverseTimes
=
reverseTime
;
pInfo
->
reverseTimes
=
reverseTime
;
...
@@ -5908,7 +5964,14 @@ static STableScanInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQ
...
@@ -5908,7 +5964,14 @@ static STableScanInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQ
pInfo
->
order
=
pRuntimeEnv
->
pQuery
->
order
.
order
;
pInfo
->
order
=
pRuntimeEnv
->
pQuery
->
order
.
order
;
pInfo
->
pRuntimeEnv
=
pRuntimeEnv
;
pInfo
->
pRuntimeEnv
=
pRuntimeEnv
;
return
pInfo
;
SOperatorInfo
*
pOptr
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOptr
->
name
=
"BidirectionSeqScanTableOp"
;
pOptr
->
blockingOptr
=
false
;
pOptr
->
optInfo
=
pInfo
;
pOptr
->
exec
=
doTableScan
;
return
pOptr
;
}
}
static
UNUSED_FUNC
int32_t
getTableScanId
(
STableScanInfo
*
pTableScanInfo
)
{
static
UNUSED_FUNC
int32_t
getTableScanId
(
STableScanInfo
*
pTableScanInfo
)
{
...
@@ -5920,34 +5983,53 @@ static UNUSED_FUNC int32_t getTableScanOrder(STableScanInfo* pTableScanInfo) {
...
@@ -5920,34 +5983,53 @@ static UNUSED_FUNC int32_t getTableScanOrder(STableScanInfo* pTableScanInfo) {
}
}
// this is a blocking operator
// this is a blocking operator
static
SSDataBlock
*
doAggOperator
(
void
*
param
)
{
static
SSDataBlock
*
doAggregation
(
void
*
param
)
{
SAggOperatorInfo
*
pInfo
=
(
SAggOperatorInfo
*
)
param
;
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
pInfo
->
pRuntimeEnv
;
STableScanInfo
*
pTableScanInfo
=
pInfo
->
pTableScanInfo
;
int32_t
countId
=
0
;
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
optInfo
;
int32_t
order
=
getTableScanOrder
(
pInfo
->
pTableScanInfo
)
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
pAggInfo
->
pRuntimeEnv
;
resetDefaultResInfoOutputBuf_rv
(
pInfo
->
pRuntimeEnv
);
SOperatorInfo
*
upstream
=
pOperator
->
upstream
;
resetDefaultResInfoOutputBuf_rv
(
pRuntimeEnv
);
pRuntimeEnv
->
pQuery
->
pos
=
0
;
pRuntimeEnv
->
pQuery
->
pos
=
0
;
while
(
1
)
{
while
(
1
)
{
SSDataBlock
*
pBlock
=
pTableScanInfo
->
exec
(
pTableScan
Info
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
upstream
->
opt
Info
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
}
}
if
(
countId
!=
getTableScanId
(
pTableScanInfo
)
&&
order
==
getTableScanOrder
(
pTableScanInfo
))
{
// the pDataBlock are always the same one, no need to call this again
prepareRepeatTableScan
(
pRuntimeEnv
);
setInputSDataBlock
(
pRuntimeEnv
,
pBlock
);
countId
=
getTableScanId
(
pTableScanInfo
);
aggApplyFunctions
(
pRuntimeEnv
,
pBlock
);
}
}
setQueryStatus
(
pRuntimeEnv
->
pQuery
,
QUERY_COMPLETED
);
finalizeQueryResult
(
pRuntimeEnv
);
pRuntimeEnv
->
outputBuf
->
info
.
rows
=
getNumOfResult
(
pRuntimeEnv
);
return
pRuntimeEnv
->
outputBuf
;
}
static
SSDataBlock
*
doArithmeticOperation
(
void
*
param
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SArithOperatorInfo
*
pArithInfo
=
pOperator
->
optInfo
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
pArithInfo
->
pRuntimeEnv
;
// the order has changed
SOperatorInfo
*
upstream
=
pOperator
->
upstream
;
if
(
order
!=
getTableScanOrder
(
pTableScanInfo
))
{
order
=
getTableScanOrder
(
pTableScanInfo
);
resetDefaultResInfoOutputBuf_rv
(
pRuntimeEnv
);
pRuntimeEnv
->
pQuery
->
pos
=
0
;
while
(
1
)
{
SSDataBlock
*
pBlock
=
upstream
->
exec
(
upstream
->
optInfo
);
if
(
pBlock
==
NULL
)
{
break
;
}
}
// the pDataBlock are alway the same one, no need to call this again
// the pDataBlock are alway
s
the same one, no need to call this again
setInputSDataBlock
(
pRuntimeEnv
,
pBlock
);
setInputSDataBlock
(
pRuntimeEnv
,
pBlock
);
aggApplyFunctions
(
pRuntimeEnv
,
pBlock
);
aggApplyFunctions
(
pRuntimeEnv
,
pBlock
);
}
}
...
@@ -5971,29 +6053,43 @@ static int32_t getNumOfScanTimes(SQuery* pQuery) {
...
@@ -5971,29 +6053,43 @@ static int32_t getNumOfScanTimes(SQuery* pQuery) {
return
1
;
return
1
;
}
}
//void createBasicOperatorInfo() {
static
UNUSED_FUNC
SOperatorInfo
*
createAggOperatorInfo
(
SResultRowInfo
*
pResultRowInfo
,
STableQueryInfo
*
pTableQueryInfo
,
// optrList[0].name = "SeqScanTableOp";
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
inputOptr
)
{
// optrList[0].blockingOptr = false;
// optrList[0].exec = doTableScan;
//
// optrList[0].name = "SeqScanTableOp";
// optrList[0].blockingOptr = false;
// optrList[0].exec = doTableScan;
//}
static
UNUSED_FUNC
SAggOperatorInfo
*
createAggOperatorInfo
(
SResultRowInfo
*
pResultRowInfo
,
STableQueryInfo
*
pTableQueryInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableScanInfo
*
pTableScanInfo
)
{
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
pInfo
->
pResultRowInfo
=
pResultRowInfo
;
pInfo
->
pResultRowInfo
=
pResultRowInfo
;
pInfo
->
pTableQueryInfo
=
pTableQueryInfo
;
pInfo
->
pTableQueryInfo
=
pTableQueryInfo
;
pInfo
->
pTableScanInfo
=
pTableScanInfo
;
pInfo
->
pRuntimeEnv
=
pRuntimeEnv
;
pInfo
->
pRuntimeEnv
=
pRuntimeEnv
;
pInfo
->
apply
=
doAggOperator
;
return
pInfo
;
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"AggregationOp"
;
pOperator
->
blockingOptr
=
true
;
pOperator
->
optInfo
=
pInfo
;
pOperator
->
upstream
=
inputOptr
;
pOperator
->
exec
=
doAggregation
;
return
pOperator
;
}
}
static
UNUSED_FUNC
SOperatorInfo
*
createArithOperatorInfo
(
SResultRowInfo
*
pResultRowInfo
,
STableQueryInfo
*
pTableQueryInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
inputOptr
)
{
SArithOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SArithOperatorInfo
));
pInfo
->
pTableQueryInfo
=
pTableQueryInfo
;
pInfo
->
pRuntimeEnv
=
pRuntimeEnv
;
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"ArithmeticOp"
;
pOperator
->
blockingOptr
=
false
;
pOperator
->
optInfo
=
pInfo
;
pOperator
->
upstream
=
inputOptr
;
pOperator
->
exec
=
doArithmeticOperation
;
return
pOperator
;
}
static
/*
/*
* in each query, this function will be called only once, no retry for further result.
* in each query, this function will be called only once, no retry for further result.
*
*
...
@@ -6008,10 +6104,9 @@ static void tableAggregationProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
...
@@ -6008,10 +6104,9 @@ static void tableAggregationProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
return
;
return
;
}
}
S
Agg
OperatorInfo
*
pAggInfo
=
createAggOperatorInfo
(
&
pRuntimeEnv
->
resultRowInfo
,
pQuery
->
current
,
pRuntimeEnv
,
pRuntimeEnv
->
pi
);
SOperatorInfo
*
pAggInfo
=
createAggOperatorInfo
(
&
pRuntimeEnv
->
resultRowInfo
,
pQuery
->
current
,
pRuntimeEnv
,
pRuntimeEnv
->
pi
);
SSDataBlock
*
pResBlock
=
pAggInfo
->
apply
(
pAgg
Info
);
SSDataBlock
*
pResBlock
=
pAggInfo
->
exec
(
pAggInfo
->
opt
Info
);
// since the numOfRows must be identical for all functions that are allowed to be executed simutaneously.
pQuery
->
rec
.
rows
=
pResBlock
->
info
.
rows
;
pQuery
->
rec
.
rows
=
pResBlock
->
info
.
rows
;
// doSecondaryArithmeticProcess(pQuery);
// doSecondaryArithmeticProcess(pQuery);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录