Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzh_me
TDengine
提交
faea042f
TDengine
项目概览
lzh_me
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
faea042f
编写于
2月 23, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-2895] refactor
上级
df667dea
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
184 addition
and
203 deletion
+184
-203
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+15
-12
src/query/inc/qResultbuf.h
src/query/inc/qResultbuf.h
+1
-10
src/query/inc/qUtil.h
src/query/inc/qUtil.h
+7
-10
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+141
-151
src/query/src/qPercentile.c
src/query/src/qPercentile.c
+1
-1
src/query/src/qResultbuf.c
src/query/src/qResultbuf.c
+1
-5
src/query/src/qUtil.c
src/query/src/qUtil.c
+15
-11
src/query/tests/resultBufferTest.cpp
src/query/tests/resultBufferTest.cpp
+3
-3
未找到文件。
src/query/inc/qExecutor.h
浏览文件 @
faea042f
...
...
@@ -86,7 +86,7 @@ typedef struct SSqlGroupbyExpr {
typedef
struct
SResultRow
{
int32_t
pageId
;
// pageId & rowId is the position of current result in disk-based output buffer
int32_t
rowId
:
29
;
// row index in buffer page
int32_t
offset
:
29
;
// row index in buffer page
bool
startInterp
;
// the time window start timestamp has done the interpolation already.
bool
endInterp
;
// the time window end timestamp has done the interpolation already.
bool
closed
;
// this result status: closed or opened
...
...
@@ -247,6 +247,8 @@ typedef struct SOperatorInfo {
bool
completed
;
void
*
optInfo
;
SExprInfo
*
pExpr
;
int32_t
*
rowCellInfoOffset
;
int32_t
numOfOutput
;
__operator_fn_t
exec
;
...
...
@@ -258,10 +260,8 @@ typedef struct SQueryRuntimeEnv {
jmp_buf
env
;
SQuery
*
pQuery
;
void
*
qinfo
;
// SQLFunctionCtx* pCtx;
int32_t
numOfRowsPerPage
;
uint16_t
*
offset
;
// int32_t numOfRowsPerPage;
// uint16_t* offset;
uint16_t
scanFlag
;
// denotes reversed scan of data or not
SFillInfo
*
pFillInfo
;
void
*
pQueryHandle
;
...
...
@@ -272,7 +272,7 @@ typedef struct SQueryRuntimeEnv {
char
*
keyBuf
;
// window key buffer
SResultRowPool
*
pool
;
// window result object pool
int32_t
*
rowCellInfoOffset
;
// offset value for each row result cell info
//
int32_t* rowCellInfoOffset;// offset value for each row result cell info
char
**
prevRow
;
SArray
*
prevResult
;
// intermediate result, SArray<SInterResult>
...
...
@@ -355,11 +355,11 @@ typedef struct STableScanInfo {
SSDataBlock
block
;
SQLFunctionCtx
*
pCtx
;
// next operator query context
SResultRowInfo
*
pResultRowInfo
;
SQLFunctionCtx
*
pCtx
;
// next operator query context
SResultRowInfo
*
pResultRowInfo
;
int32_t
numOfOutput
;
int64_t
elapsedTime
;
int32_t
*
rowCellInfoOffset
;
int64_t
elapsedTime
;
}
STableScanInfo
;
typedef
struct
STagScanInfo
{
...
...
@@ -373,14 +373,15 @@ typedef struct SAggOperatorInfo {
STableQueryInfo
*
pTableQueryInfo
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
SQLFunctionCtx
*
pCtx
;
SSDataBlock
*
pRes
;
int32_t
*
rowCellInfoOffset
;
SSDataBlock
*
pRes
;
}
SAggOperatorInfo
;
typedef
struct
SArithOperatorInfo
{
STableQueryInfo
*
pTableQueryInfo
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
SQLFunctionCtx
*
pCtx
;
int32_t
*
rowCellInfoOffset
;
SResultRowInfo
resultRowInfo
;
SSDataBlock
*
pOutput
;
int32_t
bufCapacity
;
...
...
@@ -402,6 +403,7 @@ typedef struct SHashIntervalOperatorInfo {
STableQueryInfo
*
pTableQueryInfo
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
SQLFunctionCtx
*
pCtx
;
int32_t
*
rowCellInfoOffset
;
SResultRowInfo
resultRowInfo
;
SSDataBlock
*
pRes
;
}
SHashIntervalOperatorInfo
;
...
...
@@ -415,6 +417,7 @@ typedef struct SHashGroupbyOperatorInfo {
STableQueryInfo
*
pTableQueryInfo
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
SQLFunctionCtx
*
pCtx
;
int32_t
*
rowCellInfoOffset
;
SResultRowInfo
resultRowInfo
;
SSDataBlock
*
pRes
;
int32_t
colIndex
;
...
...
src/query/inc/qResultbuf.h
浏览文件 @
faea042f
...
...
@@ -55,7 +55,6 @@ typedef struct SResultBufStatis {
}
SResultBufStatis
;
typedef
struct
SDiskbasedResultBuf
{
int32_t
numOfRowsPerPage
;
int32_t
numOfPages
;
int64_t
totalBufSize
;
int64_t
fileSize
;
// disk file size
...
...
@@ -89,8 +88,7 @@ typedef struct SDiskbasedResultBuf {
* @param handle
* @return
*/
int32_t
createDiskbasedResultBuffer
(
SDiskbasedResultBuf
**
pResultBuf
,
int32_t
rowSize
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
const
void
*
handle
);
int32_t
createDiskbasedResultBuffer
(
SDiskbasedResultBuf
**
pResultBuf
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
const
void
*
handle
);
/**
*
...
...
@@ -101,13 +99,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro
*/
tFilePage
*
getNewDataBuf
(
SDiskbasedResultBuf
*
pResultBuf
,
int32_t
groupId
,
int32_t
*
pageId
);
/**
*
* @param pResultBuf
* @return
*/
size_t
getNumOfRowsPerPage
(
const
SDiskbasedResultBuf
*
pResultBuf
);
/**
*
* @param pResultBuf
...
...
src/query/inc/qUtil.h
浏览文件 @
faea042f
...
...
@@ -44,22 +44,19 @@ void closeResultRow(SResultRowInfo* pResultRowInfo, int32_t slot);
bool
isResultRowClosed
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
);
void
clearResultRow
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int16_t
type
);
SResultRowCellInfo
*
getResultCell
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
const
SResultRow
*
pRow
,
int32_t
index
);
SResultRowCellInfo
*
getResultCell
(
const
SResultRow
*
pRow
,
int32_t
index
,
int32_t
*
offset
);
static
FORCE_INLINE
SResultRow
*
getResultRow
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
)
{
assert
(
pResultRowInfo
!=
NULL
&&
slot
>=
0
&&
slot
<
pResultRowInfo
->
size
);
return
pResultRowInfo
->
pResult
[
slot
];
}
static
FORCE_INLINE
char
*
getPosInResultPage
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
columnIndex
,
SResultRow
*
pResult
,
tFilePage
*
page
)
{
assert
(
pResult
!=
NULL
&&
pRuntimeEnv
!=
NULL
);
static
FORCE_INLINE
char
*
getPosInResultPage
(
SQuery
*
pQuery
,
tFilePage
*
page
,
int32_t
rowOffset
,
int16_t
offset
)
{
assert
(
rowOffset
>=
0
&&
pQuery
!=
NULL
);
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int32_t
realRowId
=
(
int32_t
)(
pResult
->
rowId
*
GET_ROW_PARAM_FOR_MULTIOUTPUT
(
pQuery
,
pQuery
->
topBotQuery
,
pQuery
->
stableQuery
));
return
((
char
*
)
page
->
data
)
+
pRuntimeEnv
->
offset
[
columnIndex
]
*
pRuntimeEnv
->
numOfRowsPerPage
+
pQuery
->
pExpr1
[
columnIndex
].
bytes
*
realRowId
;
// int32_t realRowId = (int32_t)(rowId * GET_ROW_PARAM_FOR_MULTIOUTPUT(pQuery, pQuery->topBotQuery, pQuery->stableQuery));
// return ((char *)page->data) + offset * numOfRowsPerPage + bytes * realRowId;
return
((
char
*
)
page
->
data
)
+
rowOffset
+
offset
;
}
bool
isNullOperator
(
SColumnFilterElem
*
pFilter
,
const
char
*
minval
,
const
char
*
maxval
,
int16_t
type
);
...
...
@@ -91,6 +88,6 @@ bool hasRemainData(SGroupResInfo* pGroupResInfo);
bool
incNextGroup
(
SGroupResInfo
*
pGroupResInfo
);
int32_t
getNumOfTotalRes
(
SGroupResInfo
*
pGroupResInfo
);
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
);
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
*
offset
);
#endif // TDENGINE_QUERYUTIL_H
src/query/src/qExecutor.c
浏览文件 @
faea042f
此差异已折叠。
点击以展开。
src/query/src/qPercentile.c
浏览文件 @
faea042f
...
...
@@ -254,7 +254,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval,
resetSlotInfo
(
pBucket
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pBucket
->
pBuffer
,
pBucket
->
b
ytes
,
pBucket
->
b
ufPageSize
,
pBucket
->
bufPageSize
*
512
,
NULL
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pBucket
->
pBuffer
,
pBucket
->
bufPageSize
,
pBucket
->
bufPageSize
*
512
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tMemBucketDestroy
(
pBucket
);
return
NULL
;
...
...
src/query/src/qResultbuf.c
浏览文件 @
faea042f
...
...
@@ -9,8 +9,7 @@
#define GET_DATA_PAYLOAD(_p) ((char *)(_p)->pData + POINTER_BYTES)
#define NO_IN_MEM_AVAILABLE_PAGES(_b) (listNEles((_b)->lruList) >= (_b)->inMemPages)
int32_t
createDiskbasedResultBuffer
(
SDiskbasedResultBuf
**
pResultBuf
,
int32_t
rowSize
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
const
void
*
handle
)
{
int32_t
createDiskbasedResultBuffer
(
SDiskbasedResultBuf
**
pResultBuf
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
const
void
*
handle
)
{
*
pResultBuf
=
calloc
(
1
,
sizeof
(
SDiskbasedResultBuf
));
SDiskbasedResultBuf
*
pResBuf
=
*
pResultBuf
;
...
...
@@ -31,7 +30,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro
// at least more than 2 pages must be in memory
assert
(
inMemBufSize
>=
pagesize
*
2
);
pResBuf
->
numOfRowsPerPage
=
(
pagesize
-
sizeof
(
tFilePage
))
/
rowSize
;
pResBuf
->
lruList
=
tdListNew
(
POINTER_BYTES
);
// init id hash table
...
...
@@ -387,8 +385,6 @@ void releaseResBufPageInfo(SDiskbasedResultBuf* pResultBuf, SPageInfo* pi) {
pResultBuf
->
statis
.
releasePages
+=
1
;
}
size_t
getNumOfRowsPerPage
(
const
SDiskbasedResultBuf
*
pResultBuf
)
{
return
pResultBuf
->
numOfRowsPerPage
;
}
size_t
getNumOfResultBufGroupId
(
const
SDiskbasedResultBuf
*
pResultBuf
)
{
return
taosHashGetSize
(
pResultBuf
->
groupSet
);
}
size_t
getResBufSize
(
const
SDiskbasedResultBuf
*
pResultBuf
)
{
return
(
size_t
)
pResultBuf
->
totalBufSize
;
}
...
...
src/query/src/qUtil.c
浏览文件 @
faea042f
...
...
@@ -135,20 +135,22 @@ void clearResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16
if
(
pResultRow
->
pageId
>=
0
)
{
tFilePage
*
page
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResultRow
->
pageId
);
int16_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
pRuntimeEnv
->
pQuery
->
numOfOutput
;
++
i
)
{
SResultRowCellInfo
*
pResultInfo
=
&
pResultRow
->
pCellInfo
[
i
];
char
*
s
=
getPosInResultPage
(
pRuntimeEnv
,
i
,
pResultRow
,
page
);
size_t
size
=
pRuntimeEnv
->
pQuery
->
pExpr1
[
i
].
bytes
;
char
*
s
=
getPosInResultPage
(
pRuntimeEnv
->
pQuery
,
page
,
pResultRow
->
offset
,
offset
);
memset
(
s
,
0
,
size
);
offset
+=
size
;
RESET_RESULT_INFO
(
pResultInfo
);
}
}
pResultRow
->
numOfRows
=
0
;
pResultRow
->
pageId
=
-
1
;
pResultRow
->
rowId
=
-
1
;
pResultRow
->
offset
=
-
1
;
pResultRow
->
closed
=
false
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
@@ -158,9 +160,10 @@ void clearResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16
}
}
SResultRowCellInfo
*
getResultCell
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
const
SResultRow
*
pRow
,
int32_t
index
)
{
assert
(
index
>=
0
&&
index
<
pRuntimeEnv
->
pQuery
->
numOfOutput
);
return
(
SResultRowCellInfo
*
)((
char
*
)
pRow
->
pCellInfo
+
pRuntimeEnv
->
rowCellInfoOffset
[
index
]);
// TODO refactor: use macro
SResultRowCellInfo
*
getResultCell
(
const
SResultRow
*
pRow
,
int32_t
index
,
int32_t
*
offset
)
{
assert
(
index
>=
0
&&
offset
!=
NULL
);
return
(
SResultRowCellInfo
*
)((
char
*
)
pRow
->
pCellInfo
+
offset
[
index
]);
}
size_t
getResultRowSize
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
...
...
@@ -373,7 +376,7 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) {
return
taosArrayGetSize
(
pGroupResInfo
->
pRows
);
}
static
int64_t
getNumOfResultWindowRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
)
{
static
int64_t
getNumOfResultWindowRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int32_t
*
rowCellInfoOffset
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
...
...
@@ -387,7 +390,7 @@ static int64_t getNumOfResultWindowRes(SQueryRuntimeEnv* pRuntimeEnv, SResultRow
continue
;
}
SResultRowCellInfo
*
pResultInfo
=
getResultCell
(
pR
untimeEnv
,
pResultRow
,
j
);
SResultRowCellInfo
*
pResultInfo
=
getResultCell
(
pR
esultRow
,
j
,
rowCellInfoOffset
);
assert
(
pResultInfo
!=
NULL
);
if
(
pResultInfo
->
numOfRes
>
0
)
{
...
...
@@ -438,7 +441,8 @@ static int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *
}
}
static
int32_t
mergeIntoGroupResultImpl
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
SArray
*
pTableList
)
{
static
int32_t
mergeIntoGroupResultImpl
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
SArray
*
pTableList
,
int32_t
*
rowCellInfoOffset
)
{
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pRuntimeEnv
->
pQuery
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -492,7 +496,7 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes
SResultRowInfo
*
pWindowResInfo
=
&
pTableQueryInfoList
[
tableIndex
]
->
resInfo
;
SResultRow
*
pWindowRes
=
getResultRow
(
pWindowResInfo
,
cs
.
rowIndex
[
tableIndex
]);
int64_t
num
=
getNumOfResultWindowRes
(
pRuntimeEnv
,
pWindowRes
);
int64_t
num
=
getNumOfResultWindowRes
(
pRuntimeEnv
,
pWindowRes
,
rowCellInfoOffset
);
if
(
num
<=
0
)
{
cs
.
rowIndex
[
tableIndex
]
+=
1
;
...
...
@@ -539,13 +543,13 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes
return
code
;
}
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
*
offset
)
{
int64_t
st
=
taosGetTimestampUs
();
while
(
pGroupResInfo
->
currentGroup
<
pGroupResInfo
->
totalGroup
)
{
SArray
*
group
=
GET_TABLEGROUP
(
pRuntimeEnv
,
pGroupResInfo
->
currentGroup
);
int32_t
ret
=
mergeIntoGroupResultImpl
(
pRuntimeEnv
,
pGroupResInfo
,
group
);
int32_t
ret
=
mergeIntoGroupResultImpl
(
pRuntimeEnv
,
pGroupResInfo
,
group
,
offset
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
src/query/tests/resultBufferTest.cpp
浏览文件 @
faea042f
...
...
@@ -10,7 +10,7 @@ namespace {
// simple test
void
simpleTest
()
{
SDiskbasedResultBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
64
,
1024
,
4096
,
NULL
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4096
,
NULL
);
int32_t
pageId
=
0
;
int32_t
groupId
=
0
;
...
...
@@ -52,7 +52,7 @@ void simpleTest() {
void
writeDownTest
()
{
SDiskbasedResultBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
64
,
1024
,
4
*
1024
,
NULL
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
NULL
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
...
...
@@ -99,7 +99,7 @@ void writeDownTest() {
void
recyclePageTest
()
{
SDiskbasedResultBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
64
,
1024
,
4
*
1024
,
NULL
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
NULL
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录