Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
921eaa1c
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看板
提交
921eaa1c
编写于
2月 26, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-2895] refactor.
上级
f54f210e
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
207 addition
and
149 deletion
+207
-149
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+19
-11
src/query/inc/qUtil.h
src/query/inc/qUtil.h
+2
-0
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+43
-5
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+121
-125
src/query/src/qFill.c
src/query/src/qFill.c
+11
-6
src/query/src/qUtil.c
src/query/src/qUtil.c
+9
-1
src/query/src/queryMain.c
src/query/src/queryMain.c
+1
-1
tests/script/general/parser/limit1_stb.sim
tests/script/general/parser/limit1_stb.sim
+1
-0
未找到文件。
src/query/inc/qExecutor.h
浏览文件 @
921eaa1c
...
...
@@ -274,19 +274,27 @@ typedef struct SQueryRuntimeEnv {
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
struct
SOperatorInfo
*
proot
;
SGroupResInfo
groupResInfo
;
int64_t
currentOffset
;
// dynamic offset value
}
SQueryRuntimeEnv
;
enum
{
OP_IN_EXECUTING
=
1
,
OP_RES_TO_RETURN
=
2
,
OP_EXEC_DONE
=
3
,
};
typedef
struct
SOperatorInfo
{
char
*
nam
e
;
bool
blockingOptr
;
bool
completed
;
void
*
info
;
SExprInfo
*
pExpr
;
int32_t
numOfOutput
;
S
QueryRuntimeEnv
*
pRuntimeEnv
;
struct
SOperatorInfo
*
upstream
;
uint8_t
operatorTyp
e
;
bool
blockingOptr
;
// block operator or not
uint8_t
completed
;
// denote if current operator is completed
uint32_t
seed
;
// operator seed
int32_t
numOfOutput
;
// number of columns of the current operator results
char
*
name
;
// name, used to show the query execution plan
void
*
info
;
// extension attribution
S
ExprInfo
*
pExpr
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
struct
SOperatorInfo
*
upstream
;
__operator_fn_t
exec
;
__optr_cleanup_fn_t
cleanup
;
}
SOperatorInfo
;
...
...
@@ -391,11 +399,11 @@ typedef struct SLimitOperatorInfo {
typedef
struct
SOffsetOperatorInfo
{
int64_t
offset
;
int64_t
currentOffset
;
}
SOffsetOperatorInfo
;
typedef
struct
SFillOperatorInfo
{
SSDataBlock
*
pRes
;
SSDataBlock
*
pRes
;
int64_t
totalInputRows
;
}
SFillOperatorInfo
;
typedef
struct
SHashGroupbyOperatorInfo
{
...
...
src/query/inc/qUtil.h
浏览文件 @
921eaa1c
...
...
@@ -84,7 +84,9 @@ void freeInterResult(void* param);
void
initGroupResInfo
(
SGroupResInfo
*
pGroupResInfo
,
SResultRowInfo
*
pResultInfo
,
int32_t
offset
);
void
cleanupGroupResInfo
(
SGroupResInfo
*
pGroupResInfo
);
bool
hasRemainDataInCurrentGroup
(
SGroupResInfo
*
pGroupResInfo
);
bool
hasRemainData
(
SGroupResInfo
*
pGroupResInfo
);
bool
incNextGroup
(
SGroupResInfo
*
pGroupResInfo
);
int32_t
getNumOfTotalRes
(
SGroupResInfo
*
pGroupResInfo
);
...
...
src/query/src/qAggMain.c
浏览文件 @
921eaa1c
...
...
@@ -1439,7 +1439,20 @@ static void stddev_function_f(SQLFunctionCtx *pCtx, int32_t index) {
// the second stage to calculate standard deviation
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SStddevInfo
*
pStd
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pCtx
->
currentStage
==
REPEAT_SCAN
&&
pStd
->
stage
==
0
)
{
pStd
->
stage
++
;
avg_finalizer
(
pCtx
);
pResInfo
->
initialized
=
true
;
// set it initialized to avoid re-initialization
// save average value into tmpBuf, for second stage scan
SAvgInfo
*
pAvg
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
pStd
->
avg
=
GET_DOUBLE_VAL
(
pCtx
->
pOutput
);
assert
((
isnan
(
pAvg
->
sum
)
&&
pAvg
->
num
==
0
)
||
(
pStd
->
num
==
pAvg
->
num
&&
pStd
->
avg
==
pAvg
->
sum
));
}
/* the first stage is to calculate average value */
if
(
pStd
->
stage
==
0
)
{
avg_function_f
(
pCtx
,
index
);
...
...
@@ -2695,19 +2708,34 @@ static void percentile_function(SQLFunctionCtx *pCtx) {
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pCtx
->
currentStage
==
REPEAT_SCAN
&&
pInfo
->
stage
==
0
)
{
// all data are null, set it completed
if
(
pInfo
->
numOfElems
==
0
)
{
pResInfo
->
complete
=
true
;
}
else
{
pInfo
->
pMemBucket
=
tMemBucketCreate
(
pCtx
->
inputBytes
,
pCtx
->
inputType
,
pInfo
->
minval
,
pInfo
->
maxval
);
}
pInfo
->
stage
+=
1
;
}
// the first stage, only acquire the min/max value
if
(
pInfo
->
stage
==
0
)
{
if
(
pCtx
->
preAggVals
.
isSet
)
{
double
tmin
=
0
.
0
,
tmax
=
0
.
0
;
if
(
pCtx
->
inputType
>=
TSDB_DATA_TYPE_TINYINT
&&
pCtx
->
inputType
<=
TSDB_DATA_TYPE_BIGINT
)
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
pCtx
->
inputType
)
)
{
tmin
=
(
double
)
GET_INT64_VAL
(
&
pCtx
->
preAggVals
.
statis
.
min
);
tmax
=
(
double
)
GET_INT64_VAL
(
&
pCtx
->
preAggVals
.
statis
.
max
);
}
else
if
(
pCtx
->
inputType
==
TSDB_DATA_TYPE_DOUBLE
||
pCtx
->
inputType
==
TSDB_DATA_TYPE_FLOAT
)
{
}
else
if
(
IS_FLOAT_TYPE
(
pCtx
->
inputType
)
)
{
tmin
=
GET_DOUBLE_VAL
(
&
pCtx
->
preAggVals
.
statis
.
min
);
tmax
=
GET_DOUBLE_VAL
(
&
pCtx
->
preAggVals
.
statis
.
max
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pCtx
->
inputType
))
{
tmin
=
(
double
)
GET_UINT64_VAL
(
pCtx
->
preAggVals
.
statis
.
min
);
tmax
=
(
double
)
GET_UINT64_VAL
(
pCtx
->
preAggVals
.
statis
.
max
);
}
else
{
assert
(
true
);
}
if
(
GET_DOUBLE_VAL
(
&
pInfo
->
minval
)
>
tmin
)
{
SET_DOUBLE_VAL
(
&
pInfo
->
minval
,
tmin
);
}
...
...
@@ -2764,10 +2792,20 @@ static void percentile_function_f(SQLFunctionCtx *pCtx, int32_t index) {
}
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SPercentileInfo
*
pInfo
=
(
SPercentileInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pInfo
->
stage
==
0
)
{
if
(
pCtx
->
currentStage
==
REPEAT_SCAN
&&
pInfo
->
stage
==
0
)
{
// all data are null, set it completed
if
(
pInfo
->
numOfElems
==
0
)
{
pResInfo
->
complete
=
true
;
}
else
{
pInfo
->
pMemBucket
=
tMemBucketCreate
(
pCtx
->
inputBytes
,
pCtx
->
inputType
,
pInfo
->
minval
,
pInfo
->
maxval
);
}
pInfo
->
stage
+=
1
;
}
if
(
pInfo
->
stage
==
0
)
{
double
v
=
0
;
GET_TYPED_DATA
(
v
,
double
,
pCtx
->
inputType
,
pData
);
...
...
src/query/src/qExecutor.c
浏览文件 @
921eaa1c
此差异已折叠。
点击以展开。
src/query/src/qFill.c
浏览文件 @
921eaa1c
...
...
@@ -376,11 +376,12 @@ void* taosDestroyFillInfo(SFillInfo* pFillInfo) {
tfree
(
pFillInfo
->
prevValues
);
tfree
(
pFillInfo
->
nextValues
);
tfree
(
pFillInfo
->
pTags
);
// for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
// tfree(pFillInfo->pData[i]);
// }
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfTags
;
++
i
)
{
tfree
(
pFillInfo
->
pTags
[
i
].
tagVal
);
}
tfree
(
pFillInfo
->
pTags
);
tfree
(
pFillInfo
->
pData
);
tfree
(
pFillInfo
->
pFillCol
);
...
...
@@ -435,12 +436,16 @@ void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, const tFilePage*
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
const
char
*
data
=
pInput
->
data
+
pCol
->
col
.
offset
*
pInput
->
num
;
memcpy
(
pFillInfo
->
pData
[
i
],
data
,
(
size_t
)(
pInput
->
num
*
pCol
->
col
.
bytes
));
if
(
pFillInfo
->
pData
[
i
]
==
NULL
)
{
pFillInfo
->
pData
[
i
]
=
calloc
(
4096
,
pCol
->
col
.
bytes
);
}
memcpy
(
pFillInfo
->
pData
[
i
],
data
,
pCol
->
col
.
bytes
*
pInput
->
num
);
// pFillInfo->pData[i] = (char*) data;
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
))
{
// copy the tag value to tag value buffer
SFillTagColInfo
*
pTag
=
&
pFillInfo
->
pTags
[
pCol
->
tagIndex
];
assert
(
pTag
->
col
.
colId
==
pCol
->
col
.
colId
);
memcpy
(
pTag
->
tagVal
,
data
,
pCol
->
col
.
bytes
);
memcpy
(
pTag
->
tagVal
,
data
,
pCol
->
col
.
bytes
);
// TODO not memcpy??
}
}
}
...
...
src/query/src/qUtil.c
浏览文件 @
921eaa1c
...
...
@@ -355,7 +355,7 @@ void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo,
assert
(
pGroupResInfo
->
index
<=
getNumOfTotalRes
(
pGroupResInfo
));
}
bool
hasRemainData
(
SGroupResInfo
*
pGroupResInfo
)
{
bool
hasRemainData
InCurrentGroup
(
SGroupResInfo
*
pGroupResInfo
)
{
if
(
pGroupResInfo
->
pRows
==
NULL
)
{
return
false
;
}
...
...
@@ -363,6 +363,14 @@ bool hasRemainData(SGroupResInfo* pGroupResInfo) {
return
pGroupResInfo
->
index
<
taosArrayGetSize
(
pGroupResInfo
->
pRows
);
}
bool
hasRemainData
(
SGroupResInfo
*
pGroupResInfo
)
{
if
(
hasRemainDataInCurrentGroup
(
pGroupResInfo
))
{
return
true
;
}
return
pGroupResInfo
->
currentGroup
<
pGroupResInfo
->
totalGroup
;
}
bool
incNextGroup
(
SGroupResInfo
*
pGroupResInfo
)
{
return
(
++
pGroupResInfo
->
currentGroup
)
<
pGroupResInfo
->
totalGroup
;
}
...
...
src/query/src/queryMain.c
浏览文件 @
921eaa1c
...
...
@@ -326,7 +326,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
(
*
pRsp
)
->
numOfRows
=
htonl
((
int32_t
)
pQuery
->
rec
.
rows
);
if
(
pQInfo
->
code
==
TSDB_CODE_SUCCESS
)
{
(
*
pRsp
)
->
offset
=
htobe64
(
pQ
uery
->
limit
.
o
ffset
);
(
*
pRsp
)
->
offset
=
htobe64
(
pQ
Info
->
runtimeEnv
.
currentO
ffset
);
(
*
pRsp
)
->
useconds
=
htobe64
(
pQInfo
->
summary
.
elapsedTime
);
}
else
{
(
*
pRsp
)
->
offset
=
0
;
...
...
tests/script/general/parser/limit1_stb.sim
浏览文件 @
921eaa1c
...
...
@@ -538,6 +538,7 @@ $offset = $offset + 1
sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit $offset offset $offset
$val = $rowNum - $offset
if $rows != $val then
print expect $val, actual:$rows
return -1
endi
if $data00 != @18-10-22 02:30:00.000@ then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录