Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
~笨蛋陪你哭
TDengine
提交
98ba80a9
T
TDengine
项目概览
~笨蛋陪你哭
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
98ba80a9
编写于
11月 23, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-225] refactor codes.
上级
d0e85228
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
63 addition
and
46 deletion
+63
-46
src/query/inc/qUtil.h
src/query/inc/qUtil.h
+2
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+34
-20
src/query/src/qResultbuf.c
src/query/src/qResultbuf.c
+1
-1
src/query/src/qUtil.c
src/query/src/qUtil.c
+26
-25
未找到文件。
src/query/inc/qUtil.h
浏览文件 @
98ba80a9
...
...
@@ -80,5 +80,7 @@ void* destroyResultRowPool(SResultRowPool* p);
int32_t
getNumOfAllocatedResultRows
(
SResultRowPool
*
p
);
int32_t
getNumOfUsedResultRows
(
SResultRowPool
*
p
);
uint64_t
getResultInfoUId
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
#endif // TDENGINE_QUERYUTIL_H
src/query/src/qExecutor.c
浏览文件 @
98ba80a9
...
...
@@ -186,7 +186,7 @@ static void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void* inputData,
static
void
initCtxOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
static
void
destroyTableQueryInfoImpl
(
STableQueryInfo
*
pTableQueryInfo
);
static
void
reset
Ctx
OutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
static
void
reset
DefaultResInfo
OutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
static
bool
hasMainOutput
(
SQuery
*
pQuery
);
static
void
buildTagQueryResult
(
SQInfo
*
pQInfo
);
...
...
@@ -283,8 +283,8 @@ void updateNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOfRes) {
}
}
static
UNUSED_FUNC
int32_t
getGroupResult
Id
(
int32_t
groupIndex
)
{
int32_t
base
=
2
0000000
;
static
int32_t
getMergeResultGroup
Id
(
int32_t
groupIndex
)
{
int32_t
base
=
5
0000000
;
return
base
+
(
groupIndex
*
10000
);
}
...
...
@@ -1115,7 +1115,7 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
// not assign result buffer yet, add new result buffer
// not assign result buffer yet, add new result buffer
, TODO remove it
char
*
d
=
pData
;
int16_t
len
=
bytes
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
@@ -1128,7 +1128,7 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
}
uint64_t
uid
=
groupIndex
;
// uid is always set to be 0.
uint64_t
uid
=
groupIndex
;
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
d
,
len
,
true
,
uid
);
if
(
pResultRow
==
NULL
)
{
return
-
1
;
...
...
@@ -1714,7 +1714,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
// if it is group by normal column, do not set output buffer, the output buffer is pResult
// fixed output query/multi-output query for normal table
if
(
!
pRuntimeEnv
->
groupbyNormalCol
&&
!
pRuntimeEnv
->
stableQuery
&&
!
QUERY_IS_INTERVAL_QUERY
(
pRuntimeEnv
->
pQuery
))
{
reset
Ctx
OutputBuf
(
pRuntimeEnv
);
reset
DefaultResInfo
OutputBuf
(
pRuntimeEnv
);
}
if
(
setCtxTagColumnInfo
(
pRuntimeEnv
,
pRuntimeEnv
->
pCtx
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -2936,10 +2936,24 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) {
assert
(
size
==
pGroupResInfo
->
numOfDataPages
);
bool
done
=
false
;
//TODO add API for release none-dirty pages
// SPageInfo* prev = NULL;
for
(
int32_t
j
=
pGroupResInfo
->
pageId
;
j
<
size
;
++
j
)
{
SPageInfo
*
pi
=
*
(
SPageInfo
**
)
taosArrayGet
(
list
,
j
);
tFilePage
*
pData
=
getResBufPage
(
pResultBuf
,
pi
->
pageId
);
// release previous buffer pages
// if (prev == NULL) {
// prev = pi;
// } else {
// if (prev->pageId != pi->pageId) {
// releaseResBufPageInfo(pResultBuf, prev);
// prev = pi;
// }
// }
assert
(
pData
->
num
>
0
&&
pData
->
num
<=
pRuntimeEnv
->
numOfRowsPerPage
&&
pGroupResInfo
->
rowId
<
pData
->
num
);
int32_t
numOfRes
=
(
int32_t
)(
pData
->
num
-
pGroupResInfo
->
rowId
);
...
...
@@ -3058,7 +3072,7 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) {
SResultRow
*
pRow
=
getNewResultRow
(
pRuntimeEnv
->
pool
);
resetMergeResultBuf
(
pRuntimeEnv
,
pRuntimeEnv
->
pCtx
,
pRow
);
pQInfo
->
groupResInfo
.
groupId
=
get
GroupResult
Id
(
pQInfo
->
groupIndex
);
pQInfo
->
groupResInfo
.
groupId
=
get
MergeResultGroup
Id
(
pQInfo
->
groupIndex
);
// todo add windowRes iterator
int64_t
lastTimestamp
=
-
1
;
...
...
@@ -3339,12 +3353,12 @@ int32_t initResultRow(SResultRow *pResultRow) {
return
TSDB_CODE_SUCCESS
;
}
void
reset
Ctx
OutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
void
reset
DefaultResInfo
OutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int32_t
groupIndex
=
0
;
int
32_t
uid
=
0
;
SResultRow
*
pRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
(
char
*
)
&
groupIndex
,
sizeof
(
groupIndex
),
true
,
uid
);
int32_t
tid
=
0
;
int
64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
)
;
SResultRow
*
pRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
(
char
*
)
&
tid
,
sizeof
(
tid
),
true
,
uid
);
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
i
];
...
...
@@ -3427,7 +3441,7 @@ void skipResults(SQueryRuntimeEnv *pRuntimeEnv) {
pQuery
->
limit
.
offset
-=
pQuery
->
rec
.
rows
;
pQuery
->
rec
.
rows
=
0
;
reset
Ctx
OutputBuf
(
pRuntimeEnv
);
reset
DefaultResInfo
OutputBuf
(
pRuntimeEnv
);
// clear the buffer full flag if exists
CLEAR_QUERY_STATUS
(
pQuery
,
QUERY_RESBUF_FULL
);
...
...
@@ -3792,7 +3806,7 @@ void setExecutionContext(SQInfo *pQInfo, int32_t groupIndex, TSKEY nextKey) {
return
;
}
uint64_t
uid
=
0
;
// uid is always set to be 0
uint64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
);
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pWindowResInfo
,
(
char
*
)
&
groupIndex
,
sizeof
(
groupIndex
),
true
,
uid
);
if
(
pResultRow
==
NULL
)
{
...
...
@@ -4629,10 +4643,10 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
int32_t
ps
=
DEFAULT_PAGE_SIZE
;
int32_t
rowsize
=
0
;
getIntermediateBufInfo
(
pRuntimeEnv
,
&
ps
,
&
rowsize
);
int32_t
T
WOMB
=
1024
*
1024
*
2
;
int32_t
T
ENMB
=
1024
*
1024
*
10
;
if
(
isSTableQuery
&&
!
onlyQueryTags
(
pRuntimeEnv
->
pQuery
))
{
code
=
createDiskbasedResultBuffer
(
&
pRuntimeEnv
->
pResultBuf
,
rowsize
,
ps
,
T
WO
MB
,
pQInfo
);
code
=
createDiskbasedResultBuffer
(
&
pRuntimeEnv
->
pResultBuf
,
rowsize
,
ps
,
T
EN
MB
,
pQInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -4660,7 +4674,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
}
else
if
(
pRuntimeEnv
->
groupbyNormalCol
||
QUERY_IS_INTERVAL_QUERY
(
pQuery
)
||
(
!
isSTableQuery
))
{
int32_t
numOfResultRows
=
getInitialPageNum
(
pQInfo
);
getIntermediateBufInfo
(
pRuntimeEnv
,
&
ps
,
&
rowsize
);
code
=
createDiskbasedResultBuffer
(
&
pRuntimeEnv
->
pResultBuf
,
rowsize
,
ps
,
T
WO
MB
,
pQInfo
);
code
=
createDiskbasedResultBuffer
(
&
pRuntimeEnv
->
pResultBuf
,
rowsize
,
ps
,
T
EN
MB
,
pQInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -4930,7 +4944,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
size_t
numOfGroups
=
GET_NUM_OF_TABLEGROUP
(
pQInfo
);
if
(
isPointInterpoQuery
(
pQuery
))
{
reset
Ctx
OutputBuf
(
pRuntimeEnv
);
reset
DefaultResInfo
OutputBuf
(
pRuntimeEnv
);
assert
(
pQuery
->
limit
.
offset
==
0
&&
pQuery
->
limit
.
limit
!=
0
);
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
...
...
@@ -5096,7 +5110,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
return
;
}
reset
Ctx
OutputBuf
(
pRuntimeEnv
);
reset
DefaultResInfo
OutputBuf
(
pRuntimeEnv
);
resetTimeWindowInfo
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
);
SArray
*
group
=
GET_TABLEGROUP
(
pQInfo
,
0
);
...
...
@@ -5456,7 +5470,7 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
// for ts_comp query, re-initialized is not allowed
if
(
!
isTSCompQuery
(
pQuery
))
{
reset
Ctx
OutputBuf
(
pRuntimeEnv
);
reset
DefaultResInfo
OutputBuf
(
pRuntimeEnv
);
}
// skip blocks without load the actual data block from file if no filter condition present
...
...
@@ -5486,7 +5500,7 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
qDebug
(
"QInfo:%p skip current result, offset:%"
PRId64
", next qrange:%"
PRId64
"-%"
PRId64
,
pQInfo
,
pQuery
->
limit
.
offset
,
pQuery
->
current
->
lastKey
,
pQuery
->
current
->
win
.
ekey
);
reset
Ctx
OutputBuf
(
pRuntimeEnv
);
reset
DefaultResInfo
OutputBuf
(
pRuntimeEnv
);
}
limitResults
(
pRuntimeEnv
);
...
...
src/query/src/qResultbuf.c
浏览文件 @
98ba80a9
...
...
@@ -407,7 +407,7 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) {
}
if
(
pResultBuf
->
file
!=
NULL
)
{
qDebug
(
"QInfo:%p res output buffer closed, total:%.2f Kb, inmem size:%.2f Kb, file size:%.2f"
,
qDebug
(
"QInfo:%p res output buffer closed, total:%.2f Kb, inmem size:%.2f Kb, file size:%.2f
Kb
"
,
pResultBuf
->
handle
,
pResultBuf
->
totalBufSize
/
1024
.
0
,
listNEles
(
pResultBuf
->
lruList
)
*
pResultBuf
->
pageSize
/
1024
.
0
,
pResultBuf
->
fileSize
/
1024
.
0
);
...
...
src/query/src/qUtil.c
浏览文件 @
98ba80a9
...
...
@@ -20,6 +20,18 @@
#include "qExecutor.h"
#include "qUtil.h"
static
int32_t
getResultRowKeyInfo
(
SResultRow
*
pResult
,
int16_t
type
,
char
**
key
,
int16_t
*
bytes
)
{
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
*
key
=
varDataVal
(
pResult
->
key
);
*
bytes
=
varDataLen
(
pResult
->
key
);
}
else
{
*
key
=
(
char
*
)
&
pResult
->
win
.
skey
;
*
bytes
=
tDataTypeDesc
[
type
].
nSize
;
}
return
0
;
}
int32_t
getOutputInterResultBufSize
(
SQuery
*
pQuery
)
{
int32_t
size
=
0
;
...
...
@@ -94,12 +106,8 @@ void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
pWindowResInfo
);
assert
(
num
>=
0
&&
num
<=
numOfClosed
);
int16_t
type
=
pWindowResInfo
->
type
;
STableId
*
id
=
TSDB_TABLEID
(
pRuntimeEnv
->
pQuery
->
current
->
pTable
);
// uid is always set to be 0.
int64_t
uid
=
id
->
uid
;
if
(
pRuntimeEnv
->
groupbyNormalCol
)
{
uid
=
0
;
}
int16_t
type
=
pWindowResInfo
->
type
;
int64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
);
char
*
key
=
NULL
;
int16_t
bytes
=
-
1
;
...
...
@@ -107,16 +115,7 @@ void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SResultRow
*
pResult
=
pWindowResInfo
->
pResult
[
i
];
if
(
pResult
->
closed
)
{
// remove the window slot from hash table
// todo refactor
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
key
=
varDataVal
(
pResult
->
key
);
bytes
=
varDataLen
(
pResult
->
key
);
}
else
{
key
=
(
char
*
)
&
pResult
->
win
.
skey
;
bytes
=
tDataTypeDesc
[
pWindowResInfo
->
type
].
nSize
;
}
getResultRowKeyInfo
(
pResult
,
type
,
&
key
,
&
bytes
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
taosHashRemove
(
pRuntimeEnv
->
pResultRowHashTable
,
(
const
char
*
)
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
));
}
else
{
...
...
@@ -141,16 +140,9 @@ void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
for
(
int32_t
k
=
0
;
k
<
pWindowResInfo
->
size
;
++
k
)
{
SResultRow
*
pResult
=
pWindowResInfo
->
pResult
[
k
];
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
key
=
varDataVal
(
pResult
->
key
);
bytes
=
varDataLen
(
pResult
->
key
);
}
else
{
key
=
(
char
*
)
&
pResult
->
win
.
skey
;
bytes
=
tDataTypeDesc
[
pWindowResInfo
->
type
].
nSize
;
}
getResultRowKeyInfo
(
pResult
,
type
,
&
key
,
&
bytes
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
int32_t
*
p
=
(
int32_t
*
)
taosHashGet
(
pRuntimeEnv
->
pResultRowHashTable
,
(
const
char
*
)
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
));
assert
(
p
!=
NULL
);
...
...
@@ -379,3 +371,12 @@ void* destroyResultRowPool(SResultRowPool* p) {
tfree
(
p
);
return
NULL
;
}
uint64_t
getResultInfoUId
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
if
(
!
pRuntimeEnv
->
stableQuery
)
{
return
0
;
// for simple table query, the uid is always set to be 0;
}
STableId
*
id
=
TSDB_TABLEID
(
pRuntimeEnv
->
pQuery
->
current
);
return
id
->
uid
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录