Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
378aaf38
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
378aaf38
编写于
2月 15, 2022
作者:
H
Haojun Liao
提交者:
GitHub
2月 15, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10259 from taosdata/feature/3.0_liaohj
Feature/3.0 liaohj
上级
f9644ffd
ef3b41e2
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
4100 addition
and
1630 deletion
+4100
-1630
2.0/src/query/inc/qExecutor.h
2.0/src/query/inc/qExecutor.h
+3
-3
2.0/src/query/src/qExecutor.c
2.0/src/query/src/qExecutor.c
+12
-12
2.0/src/query/tests/resultBufferTest.cpp
2.0/src/query/tests/resultBufferTest.cpp
+27
-27
include/common/common.h
include/common/common.h
+33
-14
include/common/tep.h
include/common/tep.h
+81
-0
include/common/trow.h
include/common/trow.h
+1
-1
include/libs/planner/plannerOp.h
include/libs/planner/plannerOp.h
+1
-1
include/util/tlosertree.h
include/util/tlosertree.h
+16
-13
include/util/tpagedbuf.h
include/util/tpagedbuf.h
+171
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+1
-1
source/client/src/tmq.c
source/client/src/tmq.c
+1
-1
source/common/src/tep.c
source/common/src/tep.c
+979
-36
source/common/src/tname.c
source/common/src/tname.c
+3
-1
source/common/src/ttszip.c
source/common/src/ttszip.c
+2
-2
source/common/test/commonTests.cpp
source/common/test/commonTests.cpp
+197
-1
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+8
-8
source/libs/executor/inc/executil.h
source/libs/executor/inc/executil.h
+8
-1
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+406
-351
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+6
-7
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+1001
-903
source/libs/executor/test/executorTests.cpp
source/libs/executor/test/executorTests.cpp
+294
-175
source/libs/function/inc/thistogram.h
source/libs/function/inc/thistogram.h
+1
-1
source/libs/function/inc/tpercentile.h
source/libs/function/inc/tpercentile.h
+2
-2
source/libs/function/src/thistogram.c
source/libs/function/src/thistogram.c
+12
-12
source/libs/function/src/tpercentile.c
source/libs/function/src/tpercentile.c
+10
-10
source/libs/planner/src/physicalPlan.c
source/libs/planner/src/physicalPlan.c
+2
-2
source/libs/planner/src/physicalPlanJson.c
source/libs/planner/src/physicalPlanJson.c
+3
-3
source/util/src/tlosertree.c
source/util/src/tlosertree.c
+57
-42
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+597
-0
source/util/test/pageBufferTest.cpp
source/util/test/pageBufferTest.cpp
+165
-0
未找到文件。
2.0/src/query/inc/qExecutor.h
浏览文件 @
378aaf38
...
@@ -582,9 +582,9 @@ typedef struct SOrderOperatorInfo {
...
@@ -582,9 +582,9 @@ typedef struct SOrderOperatorInfo {
void
appendUpstream
(
SOperatorInfo
*
p
,
SOperatorInfo
*
pUpstream
);
void
appendUpstream
(
SOperatorInfo
*
p
,
SOperatorInfo
*
pUpstream
);
SOperatorInfo
*
create
DataBlocksOptScan
Info
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
);
SOperatorInfo
*
create
TableScanOperator
Info
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
);
SOperatorInfo
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
);
SOperatorInfo
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
);
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createTableSeqScanOperator
Info
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createAggregateOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAggregateOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createProjectOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createProjectOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
...
@@ -622,7 +622,7 @@ void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p);
...
@@ -622,7 +622,7 @@ void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p);
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
);
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
);
void
*
destroyOutputBuf
(
SSDataBlock
*
pBlock
);
void
*
blockDataDestroy
(
SSDataBlock
*
pBlock
);
void
*
doDestroyFilterInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
);
void
*
doDestroyFilterInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
);
void
setInputDataBlock
(
SOperatorInfo
*
pOperator
,
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
order
);
void
setInputDataBlock
(
SOperatorInfo
*
pOperator
,
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
order
);
...
...
2.0/src/query/src/qExecutor.c
浏览文件 @
378aaf38
...
@@ -336,7 +336,7 @@ SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numO
...
@@ -336,7 +336,7 @@ SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numO
return
res
;
return
res
;
}
}
void
*
destroyOutputBuf
(
SSDataBlock
*
pBlock
)
{
void
*
blockDataDestroy
(
SSDataBlock
*
pBlock
)
{
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -4835,11 +4835,11 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
...
@@ -4835,11 +4835,11 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
break
;
break
;
}
}
case
OP_TableSeqScan
:
{
case
OP_TableSeqScan
:
{
pRuntimeEnv
->
proot
=
createTableSeqScanOperator
(
pRuntimeEnv
->
pTsdbReadHandle
,
pRuntimeEnv
);
pRuntimeEnv
->
proot
=
createTableSeqScanOperator
Info
(
pRuntimeEnv
->
pTsdbReadHandle
,
pRuntimeEnv
);
break
;
break
;
}
}
case
OP_DataBlocksOptScan
:
{
case
OP_DataBlocksOptScan
:
{
pRuntimeEnv
->
proot
=
create
DataBlocksOptScan
Info
(
pRuntimeEnv
->
pTsdbReadHandle
,
pRuntimeEnv
,
getNumOfScanTimes
(
pQueryAttr
),
pQueryAttr
->
needReverseScan
?
1
:
0
);
pRuntimeEnv
->
proot
=
create
TableScanOperator
Info
(
pRuntimeEnv
->
pTsdbReadHandle
,
pRuntimeEnv
,
getNumOfScanTimes
(
pQueryAttr
),
pQueryAttr
->
needReverseScan
?
1
:
0
);
break
;
break
;
}
}
case
OP_TableScan
:
{
case
OP_TableScan
:
{
...
@@ -5162,7 +5162,7 @@ SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv*
...
@@ -5162,7 +5162,7 @@ SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv*
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SOperatorInfo
*
createTableSeqScanOperator
Info
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
pInfo
->
pTsdbReadHandle
=
pTsdbQueryHandle
;
pInfo
->
pTsdbReadHandle
=
pTsdbQueryHandle
;
...
@@ -5267,7 +5267,7 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf
...
@@ -5267,7 +5267,7 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf
}
}
}
}
SOperatorInfo
*
create
DataBlocksOptScan
Info
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
)
{
SOperatorInfo
*
create
TableScanOperator
Info
(
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
));
...
@@ -5278,7 +5278,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime
...
@@ -5278,7 +5278,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime
pInfo
->
order
=
pRuntimeEnv
->
pQueryAttr
->
order
.
order
;
pInfo
->
order
=
pRuntimeEnv
->
pQueryAttr
->
order
.
order
;
SOperatorInfo
*
pOptr
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOptr
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOptr
->
name
=
"
DataBlocksOptimized
ScanOperator"
;
pOptr
->
name
=
"
Table
ScanOperator"
;
pOptr
->
operatorType
=
OP_DataBlocksOptScan
;
pOptr
->
operatorType
=
OP_DataBlocksOptScan
;
pOptr
->
pRuntimeEnv
=
pRuntimeEnv
;
pOptr
->
pRuntimeEnv
=
pRuntimeEnv
;
pOptr
->
blockingOptr
=
false
;
pOptr
->
blockingOptr
=
false
;
...
@@ -5373,7 +5373,7 @@ static void destroyGlobalAggOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -5373,7 +5373,7 @@ static void destroyGlobalAggOperatorInfo(void* param, int32_t numOfOutput) {
static
void
destroySlimitOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroySlimitOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SSLimitOperatorInfo
*
pInfo
=
(
SSLimitOperatorInfo
*
)
param
;
SSLimitOperatorInfo
*
pInfo
=
(
SSLimitOperatorInfo
*
)
param
;
taosArrayDestroy
(
pInfo
->
orderColumnList
);
taosArrayDestroy
(
pInfo
->
orderColumnList
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
tfree
(
pInfo
->
prevRow
);
tfree
(
pInfo
->
prevRow
);
}
}
...
@@ -6566,7 +6566,7 @@ static void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput) {
...
@@ -6566,7 +6566,7 @@ static void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput) {
tfree
(
pInfo
->
rowCellInfoOffset
);
tfree
(
pInfo
->
rowCellInfoOffset
);
cleanupResultRowInfo
(
&
pInfo
->
resultRowInfo
);
cleanupResultRowInfo
(
&
pInfo
->
resultRowInfo
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
}
}
static
void
destroyBasicOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyBasicOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
...
@@ -6590,7 +6590,7 @@ static void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -6590,7 +6590,7 @@ static void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) {
static
void
destroySFillOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroySFillOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SFillOperatorInfo
*
pInfo
=
(
SFillOperatorInfo
*
)
param
;
SFillOperatorInfo
*
pInfo
=
(
SFillOperatorInfo
*
)
param
;
pInfo
->
pFillInfo
=
taosDestroyFillInfo
(
pInfo
->
pFillInfo
);
pInfo
->
pFillInfo
=
taosDestroyFillInfo
(
pInfo
->
pFillInfo
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
tfree
(
pInfo
->
p
);
tfree
(
pInfo
->
p
);
}
}
...
@@ -6607,12 +6607,12 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -6607,12 +6607,12 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
static
void
destroyTagScanOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyTagScanOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
STagScanInfo
*
pInfo
=
(
STagScanInfo
*
)
param
;
STagScanInfo
*
pInfo
=
(
STagScanInfo
*
)
param
;
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
}
}
static
void
destroyOrderOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyOrderOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SOrderOperatorInfo
*
pInfo
=
(
SOrderOperatorInfo
*
)
param
;
SOrderOperatorInfo
*
pInfo
=
(
SOrderOperatorInfo
*
)
param
;
pInfo
->
pDataBlock
=
destroyOutputBuf
(
pInfo
->
pDataBlock
);
pInfo
->
pDataBlock
=
blockDataDestroy
(
pInfo
->
pDataBlock
);
}
}
static
void
destroyConditionOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyConditionOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
...
@@ -6625,7 +6625,7 @@ static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -6625,7 +6625,7 @@ static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) {
taosHashCleanup
(
pInfo
->
pSet
);
taosHashCleanup
(
pInfo
->
pSet
);
tfree
(
pInfo
->
buf
);
tfree
(
pInfo
->
buf
);
taosArrayDestroy
(
pInfo
->
pDistinctDataInfo
);
taosArrayDestroy
(
pInfo
->
pDistinctDataInfo
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
}
}
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
...
...
2.0/src/query/tests/resultBufferTest.cpp
浏览文件 @
378aaf38
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
namespace
{
namespace
{
// simple test
// simple test
void
simpleTest
()
{
void
simpleTest
()
{
SDiskbased
Result
Buf
*
pResultBuf
=
NULL
;
SDiskbasedBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4096
,
1
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4096
,
1
);
int32_t
pageId
=
0
;
int32_t
pageId
=
0
;
...
@@ -22,40 +22,40 @@ void simpleTest() {
...
@@ -22,40 +22,40 @@ void simpleTest() {
tFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
ASSERT_EQ
(
get
Res
BufSize
(
pResultBuf
),
1024
);
ASSERT_EQ
(
get
Total
BufSize
(
pResultBuf
),
1024
);
SIDList
list
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
SIDList
list
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
list
),
1
);
ASSERT_EQ
(
taosArrayGetSize
(
list
),
1
);
ASSERT_EQ
(
getNumOfResultBufGroupId
(
pResultBuf
),
1
);
ASSERT_EQ
(
getNumOfResultBufGroupId
(
pResultBuf
),
1
);
release
Res
BufPage
(
pResultBuf
,
pBufPage
);
releaseBufPage
(
pResultBuf
,
pBufPage
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t
==
pBufPage1
);
ASSERT_TRUE
(
t
==
pBufPage1
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t1
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t1
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage2
);
ASSERT_TRUE
(
t1
==
pBufPage2
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t2
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t2
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage3
);
ASSERT_TRUE
(
t2
==
pBufPage3
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t3
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t3
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage4
);
ASSERT_TRUE
(
t3
==
pBufPage4
);
tFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t4
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t4
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage5
);
ASSERT_TRUE
(
t4
==
pBufPage5
);
destroyResultBuf
(
pResultBuf
);
destroyResultBuf
(
pResultBuf
);
}
}
void
writeDownTest
()
{
void
writeDownTest
()
{
SDiskbased
Result
Buf
*
pResultBuf
=
NULL
;
SDiskbasedBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
);
int32_t
pageId
=
0
;
int32_t
pageId
=
0
;
...
@@ -68,31 +68,31 @@ void writeDownTest() {
...
@@ -68,31 +68,31 @@ void writeDownTest() {
*
(
int32_t
*
)(
pBufPage
->
data
)
=
nx
;
*
(
int32_t
*
)(
pBufPage
->
data
)
=
nx
;
writePageId
=
pageId
;
writePageId
=
pageId
;
release
Res
BufPage
(
pResultBuf
,
pBufPage
);
releaseBufPage
(
pResultBuf
,
pBufPage
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t1
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t1
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
ASSERT_TRUE
(
pageId
==
1
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t2
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t2
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
ASSERT_TRUE
(
pageId
==
2
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t3
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t3
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
ASSERT_TRUE
(
pageId
==
3
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t4
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t4
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
ASSERT_TRUE
(
pageId
==
4
);
release
Res
BufPage
(
pResultBuf
,
t4
);
releaseBufPage
(
pResultBuf
,
t4
);
// flush the written page to disk, and read it out again
// flush the written page to disk, and read it out again
tFilePage
*
pBufPagex
=
get
Res
BufPage
(
pResultBuf
,
writePageId
);
tFilePage
*
pBufPagex
=
getBufPage
(
pResultBuf
,
writePageId
);
ASSERT_EQ
(
*
(
int32_t
*
)
pBufPagex
->
data
,
nx
);
ASSERT_EQ
(
*
(
int32_t
*
)
pBufPagex
->
data
,
nx
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
...
@@ -102,7 +102,7 @@ void writeDownTest() {
...
@@ -102,7 +102,7 @@ void writeDownTest() {
}
}
void
recyclePageTest
()
{
void
recyclePageTest
()
{
SDiskbased
Result
Buf
*
pResultBuf
=
NULL
;
SDiskbasedBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
);
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
);
int32_t
pageId
=
0
;
int32_t
pageId
=
0
;
...
@@ -112,41 +112,41 @@ void recyclePageTest() {
...
@@ -112,41 +112,41 @@ void recyclePageTest() {
tFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
release
Res
BufPage
(
pResultBuf
,
pBufPage
);
releaseBufPage
(
pResultBuf
,
pBufPage
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t1
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t1
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
ASSERT_TRUE
(
pageId
==
1
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t2
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t2
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
ASSERT_TRUE
(
pageId
==
2
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t3
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t3
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
ASSERT_TRUE
(
pageId
==
3
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t4
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t4
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
ASSERT_TRUE
(
pageId
==
4
);
release
Res
BufPage
(
pResultBuf
,
t4
);
releaseBufPage
(
pResultBuf
,
t4
);
tFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t5
=
get
Res
BufPage
(
pResultBuf
,
pageId
);
tFilePage
*
t5
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t5
==
pBufPage5
);
ASSERT_TRUE
(
t5
==
pBufPage5
);
ASSERT_TRUE
(
pageId
==
5
);
ASSERT_TRUE
(
pageId
==
5
);
// flush the written page to disk, and read it out again
// flush the written page to disk, and read it out again
tFilePage
*
pBufPagex
=
get
Res
BufPage
(
pResultBuf
,
writePageId
);
tFilePage
*
pBufPagex
=
getBufPage
(
pResultBuf
,
writePageId
);
*
(
int32_t
*
)(
pBufPagex
->
data
)
=
nx
;
*
(
int32_t
*
)(
pBufPagex
->
data
)
=
nx
;
writePageId
=
pageId
;
// update the data
writePageId
=
pageId
;
// update the data
release
Res
BufPage
(
pResultBuf
,
pBufPagex
);
releaseBufPage
(
pResultBuf
,
pBufPagex
);
tFilePage
*
pBufPagex1
=
get
Res
BufPage
(
pResultBuf
,
1
);
tFilePage
*
pBufPagex1
=
getBufPage
(
pResultBuf
,
1
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
6
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
6
);
...
...
include/common/common.h
浏览文件 @
378aaf38
...
@@ -16,6 +16,11 @@
...
@@ -16,6 +16,11 @@
#ifndef TDENGINE_COMMON_H
#ifndef TDENGINE_COMMON_H
#define TDENGINE_COMMON_H
#define TDENGINE_COMMON_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "taosdef.h"
#include "taosdef.h"
#include "tarray.h"
#include "tarray.h"
#include "tmsg.h"
#include "tmsg.h"
...
@@ -44,8 +49,8 @@
...
@@ -44,8 +49,8 @@
typedef
struct
{
typedef
struct
{
uint32_t
numOfTables
;
uint32_t
numOfTables
;
SArray
*
pGroupList
;
SArray
*
pGroupList
;
SHashObj
*
map
;
// speedup acquire the tableQueryInfo by table uid
SHashObj
*
map
;
// speedup acquire the tableQueryInfo by table uid
}
STableGroupInfo
;
}
STableGroupInfo
;
typedef
struct
SColumnDataAgg
{
typedef
struct
SColumnDataAgg
{
...
@@ -74,18 +79,28 @@ typedef struct SConstantItem {
...
@@ -74,18 +79,28 @@ typedef struct SConstantItem {
// info.numOfCols = taosArrayGetSize(pDataBlock) + taosArrayGetSize(pConstantList);
// info.numOfCols = taosArrayGetSize(pDataBlock) + taosArrayGetSize(pConstantList);
typedef
struct
SSDataBlock
{
typedef
struct
SSDataBlock
{
SColumnDataAgg
*
pBlockAgg
;
SColumnDataAgg
*
pBlockAgg
;
SArray
*
pDataBlock
;
// SArray<SColumnInfoData>
SArray
*
pDataBlock
;
// SArray<SColumnInfoData>
SArray
*
pConstantList
;
// SArray<SConstantItem>, it is a constant/tags value of the corresponding result value.
SArray
*
pConstantList
;
// SArray<SConstantItem>, it is a constant/tags value of the corresponding result value.
SDataBlockInfo
info
;
SDataBlockInfo
info
;
}
SSDataBlock
;
}
SSDataBlock
;
typedef
struct
SVarColAttr
{
int32_t
*
offset
;
// start position for each entry in the list
uint32_t
length
;
// used buffer size that contain the valid data
uint32_t
allocLen
;
// allocated buffer size
}
SVarColAttr
;
// pBlockAgg->numOfNull == info.rows, all data are null
// pBlockAgg->numOfNull == info.rows, all data are null
// pBlockAgg->numOfNull == 0, no data are null.
// pBlockAgg->numOfNull == 0, no data are null.
typedef
struct
SColumnInfoData
{
typedef
struct
SColumnInfoData
{
SColumnInfo
info
;
// TODO filter info needs to be removed
SColumnInfo
info
;
// TODO filter info needs to be removed
char
*
nullbitmap
;
//
bool
hasNull
;
// if current column data has null value.
char
*
pData
;
// the corresponding block data in memory
char
*
pData
;
// the corresponding block data in memory
union
{
char
*
nullbitmap
;
// bitmap, one bit for each item in the list
SVarColAttr
varmeta
;
};
}
SColumnInfoData
;
}
SColumnInfoData
;
static
FORCE_INLINE
int32_t
tEncodeDataBlock
(
void
**
buf
,
const
SSDataBlock
*
pBlock
)
{
static
FORCE_INLINE
int32_t
tEncodeDataBlock
(
void
**
buf
,
const
SSDataBlock
*
pBlock
)
{
...
@@ -235,11 +250,11 @@ typedef struct SSqlExpr {
...
@@ -235,11 +250,11 @@ typedef struct SSqlExpr {
char
token
[
TSDB_COL_NAME_LEN
];
// original token
char
token
[
TSDB_COL_NAME_LEN
];
// original token
SSchema
resSchema
;
SSchema
resSchema
;
int32_t
numOfCols
;
int32_t
numOfCols
;
SColumn
*
pColumns
;
// data columns that are required by query
SColumn
*
pColumns
;
// data columns that are required by query
int32_t
interBytes
;
// inter result buffer size
int32_t
interBytes
;
// inter result buffer size
int16_t
numOfParams
;
// argument value of each function
int16_t
numOfParams
;
// argument value of each function
SVariant
param
[
3
];
// parameters are not more than 3
SVariant
param
[
3
];
// parameters are not more than 3
}
SSqlExpr
;
}
SSqlExpr
;
typedef
struct
SExprInfo
{
typedef
struct
SExprInfo
{
...
@@ -261,4 +276,8 @@ typedef struct SSessionWindow {
...
@@ -261,4 +276,8 @@ typedef struct SSessionWindow {
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_COMMON_H
#endif // TDENGINE_COMMON_H
include/common/tep.h
浏览文件 @
378aaf38
...
@@ -7,12 +7,22 @@ extern "C" {
...
@@ -7,12 +7,22 @@ extern "C" {
#include "os.h"
#include "os.h"
#include "tmsg.h"
#include "tmsg.h"
#include "common.h"
typedef
struct
SCorEpSet
{
typedef
struct
SCorEpSet
{
int32_t
version
;
int32_t
version
;
SEpSet
epSet
;
SEpSet
epSet
;
}
SCorEpSet
;
}
SCorEpSet
;
typedef
struct
SBlockOrderInfo
{
int32_t
order
;
int32_t
colIndex
;
SColumnInfoData
*
pColData
;
// int32_t type;
// int32_t bytes;
// bool hasNull;
}
SBlockOrderInfo
;
int
taosGetFqdnPortFromEp
(
const
char
*
ep
,
SEp
*
pEp
);
int
taosGetFqdnPortFromEp
(
const
char
*
ep
,
SEp
*
pEp
);
void
addEpIntoEpSet
(
SEpSet
*
pEpSet
,
const
char
*
fqdn
,
uint16_t
port
);
void
addEpIntoEpSet
(
SEpSet
*
pEpSet
,
const
char
*
fqdn
,
uint16_t
port
);
...
@@ -21,6 +31,77 @@ bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2);
...
@@ -21,6 +31,77 @@ bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2);
void
updateEpSet_s
(
SCorEpSet
*
pEpSet
,
SEpSet
*
pNewEpSet
);
void
updateEpSet_s
(
SCorEpSet
*
pEpSet
,
SEpSet
*
pNewEpSet
);
SEpSet
getEpSet_s
(
SCorEpSet
*
pEpSet
);
SEpSet
getEpSet_s
(
SCorEpSet
*
pEpSet
);
#define NBIT (3u)
#define BitPos(_n) ((_n) & ((1 << NBIT) - 1))
#define BMCharPos(bm_, r_) ((bm_)[(r_) >> NBIT])
#define colDataIsNull_f(bm_, r_) ((BMCharPos(bm_, r_) & (1u << (7u - BitPos(r_)))) == (1u << (7u - BitPos(r_))))
#define colDataSetNull_f(bm_, r_) \
do { \
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
} while (0)
static
FORCE_INLINE
bool
colDataIsNull
(
const
SColumnInfoData
*
pColumnInfoData
,
uint32_t
totalRows
,
uint32_t
row
,
SColumnDataAgg
*
pColAgg
)
{
if
(
!
pColumnInfoData
->
hasNull
)
{
return
false
;
}
if
(
pColAgg
!=
NULL
)
{
if
(
pColAgg
->
numOfNull
==
totalRows
)
{
ASSERT
(
pColumnInfoData
->
nullbitmap
==
NULL
);
return
true
;
}
else
if
(
pColAgg
->
numOfNull
==
0
)
{
ASSERT
(
pColumnInfoData
->
nullbitmap
==
NULL
);
return
false
;
}
}
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
return
pColumnInfoData
->
varmeta
.
offset
[
row
]
==
-
1
;
}
else
{
if
(
pColumnInfoData
->
nullbitmap
==
NULL
)
{
return
false
;
}
return
colDataIsNull_f
(
pColumnInfoData
->
nullbitmap
,
row
);
}
}
#define colDataGet(p1_, r_) \
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? (p1_)->pData + (p1_)->varmeta.offset[(r_)] \
: (p1_)->pData + ((r_) * (p1_)->info.bytes));
int32_t
colDataAppend
(
SColumnInfoData
*
pColumnInfoData
,
uint32_t
currentRow
,
const
char
*
pData
,
bool
isNull
);
int32_t
colDataMergeCol
(
SColumnInfoData
*
pColumnInfoData
,
uint32_t
numOfRow1
,
const
SColumnInfoData
*
pSource
,
uint32_t
numOfRow2
);
int32_t
blockDataUpdateTsWindow
(
SSDataBlock
*
pDataBlock
);
int32_t
colDataGetSize
(
const
SColumnInfoData
*
pColumnInfoData
,
int32_t
numOfRows
);
void
colDataTrim
(
SColumnInfoData
*
pColumnInfoData
);
size_t
colDataGetNumOfCols
(
const
SSDataBlock
*
pBlock
);
size_t
colDataGetNumOfRows
(
const
SSDataBlock
*
pBlock
);
int32_t
blockDataMerge
(
SSDataBlock
*
pDest
,
const
SSDataBlock
*
pSrc
);
int32_t
blockDataSplitRows
(
SSDataBlock
*
pBlock
,
bool
hasVarCol
,
int32_t
startIndex
,
int32_t
*
stopIndex
,
int32_t
pageSize
);
SSDataBlock
*
blockDataExtractBlock
(
SSDataBlock
*
pBlock
,
int32_t
startIndex
,
int32_t
rowCount
);
int32_t
blockDataToBuf
(
char
*
buf
,
const
SSDataBlock
*
pBlock
);
int32_t
blockDataFromBuf
(
SSDataBlock
*
pBlock
,
const
char
*
buf
);
size_t
blockDataGetSize
(
const
SSDataBlock
*
pBlock
);
size_t
blockDataGetRowSize
(
const
SSDataBlock
*
pBlock
);
double
blockDataGetSerialRowSize
(
const
SSDataBlock
*
pBlock
);
size_t
blockDataGetSerialMetaSize
(
const
SSDataBlock
*
pBlock
);
size_t
blockDataNumOfRowsForSerialize
(
const
SSDataBlock
*
pBlock
,
int32_t
blockSize
);
int32_t
blockDataSort
(
SSDataBlock
*
pDataBlock
,
SArray
*
pOrderInfo
,
bool
nullFirst
);
int32_t
blockDataSort_rv
(
SSDataBlock
*
pDataBlock
,
SArray
*
pOrderInfo
,
bool
nullFirst
);
int32_t
blockDataEnsureCapacity
(
SSDataBlock
*
pDataBlock
,
uint32_t
numOfRows
);
void
blockDataClearup
(
SSDataBlock
*
pDataBlock
,
bool
hasVarCol
);
void
*
blockDataDestroy
(
SSDataBlock
*
pBlock
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
include/common/trow.h
浏览文件 @
378aaf38
...
@@ -473,7 +473,7 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
...
@@ -473,7 +473,7 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
terrno
=
TSDB_CODE_INVALID_PARA
;
terrno
=
TSDB_CODE_INVALID_PARA
;
return
terrno
;
return
terrno
;
}
}
TD_ROW_SET_TYPE
(
pBuilder
->
pBuf
,
pBuilder
->
rowType
);
TD_ROW_SET_TYPE
(
pBuilder
->
pBuf
,
pBuilder
->
rowType
);
uint32_t
len
=
0
;
uint32_t
len
=
0
;
...
...
include/libs/planner/plannerOp.h
浏览文件 @
378aaf38
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
#endif
#endif
OP_ENUM_MACRO
(
StreamScan
)
OP_ENUM_MACRO
(
StreamScan
)
OP_ENUM_MACRO
(
DataBlocksOpt
Scan
)
OP_ENUM_MACRO
(
Table
Scan
)
OP_ENUM_MACRO
(
TableSeqScan
)
OP_ENUM_MACRO
(
TableSeqScan
)
OP_ENUM_MACRO
(
TagScan
)
OP_ENUM_MACRO
(
TagScan
)
OP_ENUM_MACRO
(
SystemTableScan
)
OP_ENUM_MACRO
(
SystemTableScan
)
...
...
include/util/tlosertree.h
浏览文件 @
378aaf38
...
@@ -22,28 +22,31 @@ extern "C" {
...
@@ -22,28 +22,31 @@ extern "C" {
typedef
int
(
*
__merge_compare_fn_t
)(
const
void
*
,
const
void
*
,
void
*
param
);
typedef
int
(
*
__merge_compare_fn_t
)(
const
void
*
,
const
void
*
,
void
*
param
);
typedef
struct
S
Loser
TreeNode
{
typedef
struct
STreeNode
{
int32_t
index
;
int32_t
index
;
void
*
pData
;
void
*
pData
;
// TODO remove it?
}
S
Loser
TreeNode
;
}
STreeNode
;
typedef
struct
S
Loser
TreeInfo
{
typedef
struct
S
MultiwayMerge
TreeInfo
{
int32_t
numOf
Entri
es
;
int32_t
numOf
Sourc
es
;
int32_t
total
Entri
es
;
int32_t
total
Sourc
es
;
__merge_compare_fn_t
comparFn
;
__merge_compare_fn_t
comparFn
;
void
*
param
;
void
*
param
;
SLoserTreeNode
*
pNode
;
struct
STreeNode
*
pNode
;
}
S
Loser
TreeInfo
;
}
S
MultiwayMerge
TreeInfo
;
uint32_t
tLoserTreeCreate
(
SLoserTreeInfo
**
pTree
,
int32_t
numOfEntries
,
void
*
param
,
__merge_compare_fn_t
compareFn
);
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
void
tLoserTreeInit
(
SLoserTreeInfo
*
pTree
);
int32_t
tMergeTreeCreate
(
SMultiwayMergeTreeInfo
**
pTree
,
uint32_t
numOfEntries
,
void
*
param
,
__merge_compare_fn_t
compareFn
);
void
t
LoserTreeAdjust
(
SLoserTreeInfo
*
pTree
,
int32_t
idx
);
void
t
MergeTreeDestroy
(
SMultiwayMergeTreeInfo
*
pTree
);
void
t
LoserTreeRebuild
(
SLoserTreeInfo
*
pTree
);
void
t
MergeTreeAdjust
(
SMultiwayMergeTreeInfo
*
pTree
,
int32_t
idx
);
void
tLoserTreeDisplay
(
SLoserTreeInfo
*
pTree
);
void
tMergeTreeRebuild
(
SMultiwayMergeTreeInfo
*
pTree
);
void
tMergeTreePrint
(
const
SMultiwayMergeTreeInfo
*
pTree
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
include/util/tpaged
file
.h
→
include/util/tpaged
buf
.h
浏览文件 @
378aaf38
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef TDENGINE_TPAGED
FILE
_H
#ifndef TDENGINE_TPAGED
BUF
_H
#define TDENGINE_TPAGED
FILE
_H
#define TDENGINE_TPAGED
BUF
_H
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -26,57 +26,10 @@ extern "C" {
...
@@ -26,57 +26,10 @@ extern "C" {
#include "tlockfree.h"
#include "tlockfree.h"
typedef
struct
SArray
*
SIDList
;
typedef
struct
SArray
*
SIDList
;
typedef
struct
SPageInfo
SPageInfo
;
typedef
struct
SPageDiskInfo
{
typedef
struct
SDiskbasedBuf
SDiskbasedBuf
;
int32_t
offset
;
int32_t
length
;
}
SPageDiskInfo
;
typedef
struct
SPageInfo
{
SListNode
*
pn
;
// point to list node
int32_t
pageId
;
SPageDiskInfo
info
;
void
*
pData
;
bool
used
;
// set current page is in used
}
SPageInfo
;
typedef
struct
SFreeListItem
{
int32_t
offset
;
int32_t
len
;
}
SFreeListItem
;
typedef
struct
SResultBufStatis
{
int32_t
flushBytes
;
int32_t
loadBytes
;
int32_t
getPages
;
int32_t
releasePages
;
int32_t
flushPages
;
}
SResultBufStatis
;
typedef
struct
SDiskbasedResultBuf
{
int32_t
numOfPages
;
int64_t
totalBufSize
;
int64_t
fileSize
;
// disk file size
FILE
*
file
;
int32_t
allocateId
;
// allocated page id
char
*
path
;
// file path
int32_t
pageSize
;
// current used page size
int32_t
inMemPages
;
// numOfPages that are allocated in memory
SHashObj
*
groupSet
;
// id hash table
SHashObj
*
all
;
SList
*
lruList
;
void
*
emptyDummyIdList
;
// dummy id list
void
*
assistBuf
;
// assistant buffer for compress/decompress data
SArray
*
pFree
;
// free area in file
bool
comp
;
// compressed before flushed to disk
int32_t
nextPos
;
// next page flush position
uint64_t
qId
;
// for debug purpose
SResultBufStatis
statis
;
}
SDiskbasedResultBuf
;
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes
#define PAGE_INFO_INITIALIZER (SPageDiskInfo){-1, -1}
#define DEFAULT_PAGE_SIZE (16384L)
#define DEFAULT_PAGE_SIZE (16384L)
typedef
struct
SFilePage
{
typedef
struct
SFilePage
{
...
@@ -84,76 +37,84 @@ typedef struct SFilePage {
...
@@ -84,76 +37,84 @@ typedef struct SFilePage {
char
data
[];
char
data
[];
}
SFilePage
;
}
SFilePage
;
typedef
struct
SDiskbasedBufStatis
{
int64_t
flushBytes
;
int64_t
loadBytes
;
int32_t
loadPages
;
int32_t
getPages
;
int32_t
releasePages
;
int32_t
flushPages
;
}
SDiskbasedBufStatis
;
/**
/**
* create disk-based result buffer
* create disk-based result buffer
* @param p
Result
Buf
* @param pBuf
* @param rowSize
* @param rowSize
* @param pagesize
* @param pagesize
* @param inMemPages
* @param inMemPages
* @param handle
* @param handle
* @return
* @return
*/
*/
int32_t
createDiskbased
ResultBuffer
(
SDiskbasedResultBuf
**
pResult
Buf
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
uint64_t
qId
,
const
char
*
dir
);
int32_t
createDiskbased
Buffer
(
SDiskbasedBuf
**
p
Buf
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
uint64_t
qId
,
const
char
*
dir
);
/**
/**
*
*
* @param p
Result
Buf
* @param pBuf
* @param groupId
* @param groupId
* @param pageId
* @param pageId
* @return
* @return
*/
*/
SFilePage
*
getNewDataBuf
(
SDiskbased
ResultBuf
*
pResult
Buf
,
int32_t
groupId
,
int32_t
*
pageId
);
SFilePage
*
getNewDataBuf
(
SDiskbased
Buf
*
p
Buf
,
int32_t
groupId
,
int32_t
*
pageId
);
/**
/**
*
*
* @param p
Result
Buf
* @param pBuf
* @param groupId
* @param groupId
* @return
* @return
*/
*/
SIDList
getDataBufPagesIdList
(
SDiskbased
ResultBuf
*
pResult
Buf
,
int32_t
groupId
);
SIDList
getDataBufPagesIdList
(
SDiskbased
Buf
*
p
Buf
,
int32_t
groupId
);
/**
/**
* get the specified buffer page by id
* get the specified buffer page by id
* @param p
Result
Buf
* @param pBuf
* @param id
* @param id
* @return
* @return
*/
*/
SFilePage
*
get
ResBufPage
(
SDiskbasedResultBuf
*
pResult
Buf
,
int32_t
id
);
SFilePage
*
get
BufPage
(
SDiskbasedBuf
*
p
Buf
,
int32_t
id
);
/**
/**
* release the referenced buf pages
* release the referenced buf pages
* @param p
Result
Buf
* @param pBuf
* @param page
* @param page
*/
*/
void
release
ResBufPage
(
SDiskbasedResultBuf
*
pResult
Buf
,
void
*
page
);
void
release
BufPage
(
SDiskbasedBuf
*
p
Buf
,
void
*
page
);
/**
/**
*
*
* @param p
Result
Buf
* @param pBuf
* @param pi
* @param pi
*/
*/
void
releaseResBufPageInfo
(
SDiskbasedResultBuf
*
pResultBuf
,
SPageInfo
*
pi
);
void
releaseBufPageInfo
(
SDiskbasedBuf
*
pBuf
,
struct
SPageInfo
*
pi
);
/**
/**
* get the total buffer size in the format of disk file
* get the total buffer size in the format of disk file
* @param p
Result
Buf
* @param pBuf
* @return
* @return
*/
*/
size_t
get
ResBufSize
(
const
SDiskbasedResultBuf
*
pResult
Buf
);
size_t
get
TotalBufSize
(
const
SDiskbasedBuf
*
p
Buf
);
/**
/**
* get the number of groups in the result buffer
* get the number of groups in the result buffer
* @param p
Result
Buf
* @param pBuf
* @return
* @return
*/
*/
size_t
getNumOfResultBufGroupId
(
const
SDiskbased
ResultBuf
*
pResult
Buf
);
size_t
getNumOfResultBufGroupId
(
const
SDiskbased
Buf
*
p
Buf
);
/**
/**
* destroy result buffer
* destroy result buffer
* @param p
Result
Buf
* @param pBuf
*/
*/
void
destroyResultBuf
(
SDiskbased
ResultBuf
*
pResult
Buf
);
void
destroyResultBuf
(
SDiskbased
Buf
*
p
Buf
);
/**
/**
*
*
...
@@ -162,8 +123,49 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf);
...
@@ -162,8 +123,49 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf);
*/
*/
SPageInfo
*
getLastPageInfo
(
SIDList
pList
);
SPageInfo
*
getLastPageInfo
(
SIDList
pList
);
/**
*
* @param pPgInfo
* @return
*/
int32_t
getPageId
(
const
SPageInfo
*
pPgInfo
);
/**
* Return the buffer page size.
* @param pBuf
* @return
*/
int32_t
getBufPageSize
(
const
SDiskbasedBuf
*
pBuf
);
int32_t
getNumOfInMemBufPages
(
const
SDiskbasedBuf
*
pBuf
);
/**
*
* @param pBuf
* @return
*/
bool
isAllDataInMemBuf
(
const
SDiskbasedBuf
*
pBuf
);
/**
* Set the buffer page is dirty, and needs to be flushed to disk when swap out.
* @param pPageInfo
* @param dirty
*/
void
setBufPageDirty
(
SFilePage
*
pPageInfo
,
bool
dirty
);
/**
* Print the statistics when closing this buffer
* @param pBuf
*/
void
printStatisBeforeClose
(
SDiskbasedBuf
*
pBuf
);
/**
* return buf statistics.
*/
SDiskbasedBufStatis
getDBufStatis
(
const
SDiskbasedBuf
*
pBuf
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
#endif // TDENGINE_TPAGED
FILE
_H
#endif // TDENGINE_TPAGED
BUF
_H
source/client/src/clientImpl.c
浏览文件 @
378aaf38
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#include "tglobal.h"
#include "tglobal.h"
#include "tmsgtype.h"
#include "tmsgtype.h"
#include "tnote.h"
#include "tnote.h"
#include "tpaged
file
.h"
#include "tpaged
buf
.h"
#include "tref.h"
#include "tref.h"
static
int32_t
initEpSetFromCfg
(
const
char
*
firstEp
,
const
char
*
secondEp
,
SCorEpSet
*
pEpSet
);
static
int32_t
initEpSetFromCfg
(
const
char
*
firstEp
,
const
char
*
secondEp
,
SCorEpSet
*
pEpSet
);
...
...
source/client/src/tmq.c
浏览文件 @
378aaf38
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
#include "tglobal.h"
#include "tglobal.h"
#include "tmsgtype.h"
#include "tmsgtype.h"
#include "tnote.h"
#include "tnote.h"
#include "tpaged
file
.h"
#include "tpaged
buf
.h"
#include "tref.h"
#include "tref.h"
struct
tmq_list_t
{
struct
tmq_list_t
{
...
...
source/common/src/tep.c
浏览文件 @
378aaf38
#include "tep.h"
#include "tep.h"
#include <compare.h>
#include "common.h"
#include "common.h"
#include "tglobal.h"
#include "tglobal.h"
#include "tlockfree.h"
#include "tlockfree.h"
...
@@ -60,68 +61,168 @@ SEpSet getEpSet_s(SCorEpSet *pEpSet) {
...
@@ -60,68 +61,168 @@ SEpSet getEpSet_s(SCorEpSet *pEpSet) {
return
ep
;
return
ep
;
}
}
bool
colDataIsNull
(
const
SColumnInfoData
*
pColumnInfoData
,
uint32_t
totalRows
,
uint32_t
row
,
SColumnDataAgg
*
pColAgg
)
{
#define BitmapLen(_n) (((_n) + ((1<<NBIT)-1)) >> NBIT)
if
(
pColAgg
!=
NULL
)
{
if
(
pColAgg
->
numOfNull
==
totalRows
)
{
ASSERT
(
pColumnInfoData
->
nullbitmap
==
NULL
);
return
true
;
}
else
if
(
pColAgg
->
numOfNull
==
0
)
{
ASSERT
(
pColumnInfoData
->
nullbitmap
==
NULL
);
return
false
;
}
}
if
(
pColumnInfoData
->
nullbitmap
==
NULL
)
{
return
false
;
}
uint8_t
v
=
(
pColumnInfoData
->
nullbitmap
[
row
>>
3
]
&
(
1
<<
(
8
-
(
row
&
0x07
))));
return
(
v
==
1
);
}
bool
colDataIsNull_f
(
const
char
*
bitmap
,
uint32_t
row
)
{
return
(
bitmap
[
row
>>
3
]
&
(
1
<<
(
8
-
(
row
&
0x07
))));
}
void
colDataSetNull_f
(
char
*
bitmap
,
uint32_t
row
)
{
// TODO
int32_t
colDataGetSize
(
const
SColumnInfoData
*
pColumnInfoData
,
int32_t
numOfRows
)
{
return
;
ASSERT
(
pColumnInfoData
!=
NULL
);
}
void
*
colDataGet
(
const
SColumnInfoData
*
pColumnInfoData
,
uint32_t
row
)
{
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
uint32_t
offset
=
((
uint32_t
*
)
pColumnInfoData
->
pData
)[
row
];
return
pColumnInfoData
->
varmeta
.
length
;
return
(
char
*
)(
pColumnInfoData
->
pData
)
+
offset
;
// the first part is the pointer to the true binary data
}
else
{
}
else
{
return
(
char
*
)(
pColumnInfoData
->
pData
)
+
(
row
*
pColumnInfoData
->
info
.
bytes
)
;
return
pColumnInfoData
->
info
.
bytes
*
numOfRows
;
}
}
}
}
void
colDataTrim
(
SColumnInfoData
*
pColumnInfoData
)
{
// TODO
}
int32_t
colDataAppend
(
SColumnInfoData
*
pColumnInfoData
,
uint32_t
currentRow
,
const
char
*
pData
,
bool
isNull
)
{
int32_t
colDataAppend
(
SColumnInfoData
*
pColumnInfoData
,
uint32_t
currentRow
,
const
char
*
pData
,
bool
isNull
)
{
ASSERT
(
pColumnInfoData
!=
NULL
);
ASSERT
(
pColumnInfoData
!=
NULL
);
if
(
isNull
)
{
if
(
isNull
)
{
// TODO set null value in the nullbitmap
// There is a placehold for each NULL value of binary or nchar type.
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
pColumnInfoData
->
varmeta
.
offset
[
currentRow
]
=
-
1
;
// it is a null value of VAR type.
}
else
{
colDataSetNull_f
(
pColumnInfoData
->
nullbitmap
,
currentRow
);
}
pColumnInfoData
->
hasNull
=
true
;
return
0
;
return
0
;
}
}
int32_t
type
=
pColumnInfoData
->
info
.
type
;
int32_t
type
=
pColumnInfoData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
if
(
IS_VAR_DATA_TYPE
(
type
))
{
// TODO continue append var_type
SVarColAttr
*
pAttr
=
&
pColumnInfoData
->
varmeta
;
if
(
pAttr
->
allocLen
<
pAttr
->
length
+
varDataTLen
(
pData
))
{
uint32_t
newSize
=
pAttr
->
allocLen
;
if
(
newSize
==
0
)
{
newSize
=
8
;
}
while
(
newSize
<
pAttr
->
length
+
varDataTLen
(
pData
))
{
newSize
=
newSize
*
1
.
5
;
}
char
*
buf
=
realloc
(
pColumnInfoData
->
pData
,
newSize
);
if
(
buf
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pColumnInfoData
->
pData
=
buf
;
pAttr
->
allocLen
=
newSize
;
}
uint32_t
len
=
pColumnInfoData
->
varmeta
.
length
;
pColumnInfoData
->
varmeta
.
offset
[
currentRow
]
=
len
;
memcpy
(
pColumnInfoData
->
pData
+
len
,
pData
,
varDataTLen
(
pData
));
pColumnInfoData
->
varmeta
.
length
+=
varDataTLen
(
pData
);
}
else
{
}
else
{
char
*
p
=
pColumnInfoData
->
pData
+
pColumnInfoData
->
info
.
bytes
*
currentRow
;
char
*
p
=
pColumnInfoData
->
pData
+
pColumnInfoData
->
info
.
bytes
*
currentRow
;
switch
(
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
{
*
(
int8_t
*
)
p
=
*
(
int8_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_UTINYINT
:
{
*
(
int8_t
*
)
p
=
*
(
int8_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
{
*
(
int16_t
*
)
p
=
*
(
int16_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
{
*
(
int32_t
*
)
p
=
*
(
int32_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
{
*
(
int64_t
*
)
p
=
*
(
int64_t
*
)
pData
;
break
;}
default:
default:
assert
(
0
);
assert
(
0
);
}
}
}
}
return
0
;
return
0
;
}
}
size_t
colDataGetCols
(
const
SSDataBlock
*
pBlock
)
{
static
void
doBitmapMerge
(
SColumnInfoData
*
pColumnInfoData
,
int32_t
numOfRow1
,
const
SColumnInfoData
*
pSource
,
int32_t
numOfRow2
)
{
uint32_t
total
=
numOfRow1
+
numOfRow2
;
if
(
BitmapLen
(
numOfRow1
)
<
BitmapLen
(
total
))
{
char
*
tmp
=
realloc
(
pColumnInfoData
->
nullbitmap
,
BitmapLen
(
total
));
uint32_t
extend
=
BitmapLen
(
total
)
-
BitmapLen
(
numOfRow1
);
memset
(
tmp
+
BitmapLen
(
numOfRow1
),
0
,
extend
);
pColumnInfoData
->
nullbitmap
=
tmp
;
}
uint32_t
remindBits
=
BitPos
(
numOfRow1
);
uint32_t
shiftBits
=
8
-
remindBits
;
if
(
remindBits
==
0
)
{
// no need to shift bits of bitmap
memcpy
(
pColumnInfoData
->
nullbitmap
+
BitmapLen
(
numOfRow1
),
pSource
->
nullbitmap
,
BitmapLen
(
numOfRow2
));
}
else
{
int32_t
len
=
BitmapLen
(
numOfRow2
);
int32_t
i
=
0
;
uint8_t
*
p
=
(
uint8_t
*
)
pSource
->
nullbitmap
;
pColumnInfoData
->
nullbitmap
[
BitmapLen
(
numOfRow1
)
-
1
]
|=
(
p
[
0
]
>>
remindBits
);
uint8_t
*
start
=
(
uint8_t
*
)
&
pColumnInfoData
->
nullbitmap
[
BitmapLen
(
numOfRow1
)];
while
(
i
<
len
)
{
start
[
i
]
|=
(
p
[
i
]
<<
shiftBits
);
i
+=
1
;
if
(
i
>
1
)
{
start
[
i
-
1
]
|=
(
p
[
i
]
>>
remindBits
);
}
}
}
}
int32_t
colDataMergeCol
(
SColumnInfoData
*
pColumnInfoData
,
uint32_t
numOfRow1
,
const
SColumnInfoData
*
pSource
,
uint32_t
numOfRow2
)
{
ASSERT
(
pColumnInfoData
!=
NULL
&&
pSource
!=
NULL
&&
pColumnInfoData
->
info
.
type
==
pSource
->
info
.
type
);
if
(
numOfRow2
==
0
)
{
return
numOfRow1
;
}
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
// Handle the bitmap
char
*
p
=
realloc
(
pColumnInfoData
->
varmeta
.
offset
,
sizeof
(
int32_t
)
*
(
numOfRow1
+
numOfRow2
));
if
(
p
==
NULL
)
{
// TODO
}
pColumnInfoData
->
varmeta
.
offset
=
(
int32_t
*
)
p
;
for
(
int32_t
i
=
0
;
i
<
numOfRow2
;
++
i
)
{
pColumnInfoData
->
varmeta
.
offset
[
i
+
numOfRow1
]
=
pSource
->
varmeta
.
offset
[
i
]
+
pColumnInfoData
->
varmeta
.
length
;
}
// copy data
uint32_t
len
=
pSource
->
varmeta
.
length
;
uint32_t
oldLen
=
pColumnInfoData
->
varmeta
.
length
;
if
(
pColumnInfoData
->
varmeta
.
allocLen
<
len
+
oldLen
)
{
char
*
tmp
=
realloc
(
pColumnInfoData
->
pData
,
len
+
oldLen
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_VND_OUT_OF_MEMORY
;
}
pColumnInfoData
->
pData
=
tmp
;
pColumnInfoData
->
varmeta
.
allocLen
=
len
+
oldLen
;
}
memcpy
(
pColumnInfoData
->
pData
+
oldLen
,
pSource
->
pData
,
len
);
pColumnInfoData
->
varmeta
.
length
=
len
+
oldLen
;
}
else
{
doBitmapMerge
(
pColumnInfoData
,
numOfRow1
,
pSource
,
numOfRow2
);
int32_t
newSize
=
(
numOfRow1
+
numOfRow2
)
*
pColumnInfoData
->
info
.
bytes
;
char
*
tmp
=
realloc
(
pColumnInfoData
->
pData
,
newSize
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_VND_OUT_OF_MEMORY
;
}
pColumnInfoData
->
pData
=
tmp
;
int32_t
offset
=
pColumnInfoData
->
info
.
bytes
*
numOfRow1
;
memcpy
(
pColumnInfoData
->
pData
+
offset
,
pSource
->
pData
,
pSource
->
info
.
bytes
*
numOfRow2
);
}
return
numOfRow1
+
numOfRow2
;
}
size_t
colDataGetNumOfCols
(
const
SSDataBlock
*
pBlock
)
{
ASSERT
(
pBlock
);
ASSERT
(
pBlock
);
size_t
constantCols
=
(
pBlock
->
pConstantList
!=
NULL
)
?
taosArrayGetSize
(
pBlock
->
pConstantList
)
:
0
;
size_t
constantCols
=
(
pBlock
->
pConstantList
!=
NULL
)
?
taosArrayGetSize
(
pBlock
->
pConstantList
)
:
0
;
...
@@ -129,11 +230,11 @@ size_t colDataGetCols(const SSDataBlock* pBlock) {
...
@@ -129,11 +230,11 @@ size_t colDataGetCols(const SSDataBlock* pBlock) {
return
pBlock
->
info
.
numOfCols
;
return
pBlock
->
info
.
numOfCols
;
}
}
size_t
colDataGetRows
(
const
SSDataBlock
*
pBlock
)
{
size_t
colDataGet
NumOf
Rows
(
const
SSDataBlock
*
pBlock
)
{
return
pBlock
->
info
.
rows
;
return
pBlock
->
info
.
rows
;
}
}
int32_t
col
DataUpdateTsWindow
(
SSDataBlock
*
pDataBlock
)
{
int32_t
block
DataUpdateTsWindow
(
SSDataBlock
*
pDataBlock
)
{
if
(
pDataBlock
==
NULL
||
pDataBlock
->
info
.
rows
<=
0
)
{
if
(
pDataBlock
==
NULL
||
pDataBlock
->
info
.
rows
<=
0
)
{
return
0
;
return
0
;
}
}
...
@@ -153,6 +254,848 @@ int32_t colDataUpdateTsWindow(SSDataBlock* pDataBlock) {
...
@@ -153,6 +254,848 @@ int32_t colDataUpdateTsWindow(SSDataBlock* pDataBlock) {
return
0
;
return
0
;
}
}
int32_t
blockDataMerge
(
SSDataBlock
*
pDest
,
const
SSDataBlock
*
pSrc
)
{
assert
(
pSrc
!=
NULL
&&
pDest
!=
NULL
&&
pDest
->
info
.
numOfCols
==
pSrc
->
info
.
numOfCols
);
int32_t
numOfCols
=
pSrc
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pCol2
=
taosArrayGet
(
pDest
->
pDataBlock
,
i
);
SColumnInfoData
*
pCol1
=
taosArrayGet
(
pSrc
->
pDataBlock
,
i
);
uint32_t
oldLen
=
colDataGetSize
(
pCol2
,
pDest
->
info
.
rows
);
uint32_t
newLen
=
colDataGetSize
(
pCol1
,
pSrc
->
info
.
rows
);
int32_t
newSize
=
oldLen
+
newLen
;
char
*
tmp
=
realloc
(
pCol2
->
pData
,
newSize
);
if
(
tmp
!=
NULL
)
{
pCol2
->
pData
=
tmp
;
colDataMergeCol
(
pCol2
,
pDest
->
info
.
rows
,
pCol1
,
pSrc
->
info
.
rows
);
}
else
{
return
TSDB_CODE_VND_OUT_OF_MEMORY
;
}
}
pDest
->
info
.
rows
+=
pSrc
->
info
.
rows
;
return
TSDB_CODE_SUCCESS
;
}
size_t
blockDataGetSize
(
const
SSDataBlock
*
pBlock
)
{
assert
(
pBlock
!=
NULL
);
size_t
total
=
0
;
int32_t
numOfCols
=
pBlock
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
total
+=
colDataGetSize
(
pColInfoData
,
pBlock
->
info
.
rows
);
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
total
+=
sizeof
(
int32_t
)
*
pBlock
->
info
.
rows
;
}
else
{
total
+=
BitmapLen
(
pBlock
->
info
.
rows
);
}
}
return
total
;
}
// the number of tuples can be fit in one page.
// Actual data rows pluses the corresponding meta data must fit in one memory buffer of the given page size.
int32_t
blockDataSplitRows
(
SSDataBlock
*
pBlock
,
bool
hasVarCol
,
int32_t
startIndex
,
int32_t
*
stopIndex
,
int32_t
pageSize
)
{
ASSERT
(
pBlock
!=
NULL
&&
stopIndex
!=
NULL
);
int32_t
numOfCols
=
pBlock
->
info
.
numOfCols
;
int32_t
numOfRows
=
pBlock
->
info
.
rows
;
int32_t
bitmapChar
=
1
;
size_t
headerSize
=
sizeof
(
int32_t
);
size_t
colHeaderSize
=
sizeof
(
int32_t
)
*
numOfCols
;
size_t
payloadSize
=
pageSize
-
(
headerSize
+
colHeaderSize
);
// TODO speedup by checking if the whole page can fit in firstly.
if
(
!
hasVarCol
)
{
size_t
rowSize
=
blockDataGetRowSize
(
pBlock
);
int32_t
capacity
=
(
payloadSize
/
(
rowSize
*
8
+
bitmapChar
*
numOfCols
))
*
8
;
*
stopIndex
=
startIndex
+
capacity
;
if
(
*
stopIndex
>=
numOfRows
)
{
*
stopIndex
=
numOfRows
-
1
;
}
return
TSDB_CODE_SUCCESS
;
}
else
{
// iterate the rows that can be fit in this buffer page
int32_t
size
=
(
headerSize
+
colHeaderSize
);
for
(
int32_t
j
=
startIndex
;
j
<
numOfRows
;
++
j
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
TARRAY_GET_ELEM
(
pBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
bool
isNull
=
colDataIsNull
(
pColInfoData
,
numOfRows
,
j
,
NULL
);
if
(
isNull
)
{
// do nothing
}
else
{
char
*
p
=
colDataGet
(
pColInfoData
,
j
);
size
+=
varDataTLen
(
p
);
}
size
+=
sizeof
(
pColInfoData
->
varmeta
.
offset
[
0
]);
}
else
{
size
+=
pColInfoData
->
info
.
bytes
;
if
(((
j
-
startIndex
)
&
0x07
)
==
0
)
{
size
+=
1
;
// the space for null bitmap
}
}
}
if
(
size
>
pageSize
)
{
*
stopIndex
=
j
-
1
;
ASSERT
(
*
stopIndex
>
startIndex
);
return
TSDB_CODE_SUCCESS
;
}
}
// all fit in
*
stopIndex
=
numOfRows
-
1
;
return
TSDB_CODE_SUCCESS
;
}
}
SSDataBlock
*
blockDataExtractBlock
(
SSDataBlock
*
pBlock
,
int32_t
startIndex
,
int32_t
rowCount
)
{
if
(
pBlock
==
NULL
||
startIndex
<
0
||
rowCount
>
pBlock
->
info
.
rows
||
rowCount
+
startIndex
>
pBlock
->
info
.
rows
)
{
return
NULL
;
}
SSDataBlock
*
pDst
=
calloc
(
1
,
sizeof
(
SSDataBlock
));
if
(
pDst
==
NULL
)
{
return
NULL
;
}
pDst
->
info
=
pBlock
->
info
;
pDst
->
info
.
rows
=
0
;
pDst
->
pDataBlock
=
taosArrayInit
(
pBlock
->
info
.
numOfCols
,
sizeof
(
SColumnInfoData
));
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
colInfo
=
{
0
};
SColumnInfoData
*
pSrcCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
colInfo
.
info
=
pSrcCol
->
info
;
if
(
IS_VAR_DATA_TYPE
(
pSrcCol
->
info
.
type
))
{
SVarColAttr
*
pAttr
=
&
colInfo
.
varmeta
;
pAttr
->
offset
=
calloc
(
rowCount
,
sizeof
(
int32_t
));
}
else
{
colInfo
.
nullbitmap
=
calloc
(
1
,
BitmapLen
(
rowCount
));
colInfo
.
pData
=
calloc
(
rowCount
,
colInfo
.
info
.
bytes
);
}
taosArrayPush
(
pDst
->
pDataBlock
,
&
colInfo
);
}
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
SColumnInfoData
*
pDstCol
=
taosArrayGet
(
pDst
->
pDataBlock
,
i
);
for
(
int32_t
j
=
startIndex
;
j
<
(
startIndex
+
rowCount
);
++
j
)
{
bool
isNull
=
colDataIsNull
(
pColData
,
pBlock
->
info
.
rows
,
j
,
pBlock
->
pBlockAgg
);
char
*
p
=
colDataGet
(
pColData
,
j
);
colDataAppend
(
pDstCol
,
j
-
startIndex
,
p
,
isNull
);
}
}
pDst
->
info
.
rows
=
rowCount
;
return
pDst
;
}
/**
*
* +------------------+---------------+--------------------+
* |the number of rows| column length | column #1 |
* | (4 bytes) | (4 bytes) |--------------------+
* | | | null bitmap| values|
* +------------------+---------------+--------------------+
* @param buf
* @param pBlock
* @return
*/
int32_t
blockDataToBuf
(
char
*
buf
,
const
SSDataBlock
*
pBlock
)
{
ASSERT
(
pBlock
!=
NULL
);
// write the number of rows
*
(
uint32_t
*
)
buf
=
pBlock
->
info
.
rows
;
int32_t
numOfCols
=
pBlock
->
info
.
numOfCols
;
int32_t
numOfRows
=
pBlock
->
info
.
rows
;
char
*
pStart
=
buf
+
sizeof
(
uint32_t
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
memcpy
(
pStart
,
pCol
->
varmeta
.
offset
,
numOfRows
*
sizeof
(
int32_t
));
pStart
+=
numOfRows
*
sizeof
(
int32_t
);
}
else
{
memcpy
(
pStart
,
pCol
->
nullbitmap
,
BitmapLen
(
numOfRows
));
pStart
+=
BitmapLen
(
pBlock
->
info
.
rows
);
}
uint32_t
dataSize
=
colDataGetSize
(
pCol
,
numOfRows
);
*
(
int32_t
*
)
pStart
=
dataSize
;
pStart
+=
sizeof
(
int32_t
);
memcpy
(
pStart
,
pCol
->
pData
,
dataSize
);
pStart
+=
dataSize
;
}
return
0
;
}
int32_t
blockDataFromBuf
(
SSDataBlock
*
pBlock
,
const
char
*
buf
)
{
pBlock
->
info
.
rows
=
*
(
int32_t
*
)
buf
;
int32_t
numOfCols
=
pBlock
->
info
.
numOfCols
;
const
char
*
pStart
=
buf
+
sizeof
(
uint32_t
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
size_t
metaSize
=
pBlock
->
info
.
rows
*
sizeof
(
int32_t
);
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
memcpy
(
pCol
->
varmeta
.
offset
,
pStart
,
metaSize
);
pStart
+=
metaSize
;
}
else
{
memcpy
(
pCol
->
nullbitmap
,
pStart
,
BitmapLen
(
pBlock
->
info
.
rows
));
pStart
+=
BitmapLen
(
pBlock
->
info
.
rows
);
}
int32_t
colLength
=
*
(
int32_t
*
)
pStart
;
pStart
+=
sizeof
(
int32_t
);
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
if
(
pCol
->
varmeta
.
allocLen
<
colLength
)
{
char
*
tmp
=
realloc
(
pCol
->
pData
,
colLength
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pCol
->
pData
=
tmp
;
pCol
->
varmeta
.
allocLen
=
colLength
;
}
pCol
->
varmeta
.
length
=
colLength
;
ASSERT
(
pCol
->
varmeta
.
length
<=
pCol
->
varmeta
.
allocLen
);
}
memcpy
(
pCol
->
pData
,
pStart
,
colLength
);
pStart
+=
colLength
;
}
return
TSDB_CODE_SUCCESS
;
}
size_t
blockDataGetRowSize
(
const
SSDataBlock
*
pBlock
)
{
ASSERT
(
pBlock
!=
NULL
);
size_t
rowSize
=
0
;
size_t
numOfCols
=
pBlock
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
rowSize
+=
pColInfo
->
info
.
bytes
;
}
return
rowSize
;
}
/**
* @refitem blockDataToBuf for the meta size
*
* @param pBlock
* @return
*/
size_t
blockDataGetSerialMetaSize
(
const
SSDataBlock
*
pBlock
)
{
return
sizeof
(
int32_t
)
+
pBlock
->
info
.
numOfCols
*
sizeof
(
int32_t
);
}
double
blockDataGetSerialRowSize
(
const
SSDataBlock
*
pBlock
)
{
ASSERT
(
pBlock
!=
NULL
);
double
rowSize
=
0
;
size_t
numOfCols
=
pBlock
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
rowSize
+=
pColInfo
->
info
.
bytes
;
if
(
IS_VAR_DATA_TYPE
(
pColInfo
->
info
.
type
))
{
rowSize
+=
sizeof
(
int32_t
);
}
else
{
rowSize
+=
1
/
8
.
0
;
}
}
return
rowSize
;
}
typedef
struct
SSDataBlockSortHelper
{
SArray
*
orderInfo
;
// SArray<SBlockOrderInfo>
SSDataBlock
*
pDataBlock
;
bool
nullFirst
;
}
SSDataBlockSortHelper
;
int32_t
dataBlockCompar
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
)
{
const
SSDataBlockSortHelper
*
pHelper
=
(
const
SSDataBlockSortHelper
*
)
param
;
SSDataBlock
*
pDataBlock
=
pHelper
->
pDataBlock
;
int32_t
left
=
*
(
int32_t
*
)
p1
;
int32_t
right
=
*
(
int32_t
*
)
p2
;
SArray
*
pInfo
=
pHelper
->
orderInfo
;
for
(
int32_t
i
=
0
;
i
<
pInfo
->
size
;
++
i
)
{
SBlockOrderInfo
*
pOrder
=
TARRAY_GET_ELEM
(
pInfo
,
i
);
SColumnInfoData
*
pColInfoData
=
pOrder
->
pColData
;
//TARRAY_GET_ELEM(pDataBlock->pDataBlock, pOrder->colIndex);
if
(
pColInfoData
->
hasNull
)
{
bool
leftNull
=
colDataIsNull
(
pColInfoData
,
pDataBlock
->
info
.
rows
,
left
,
pDataBlock
->
pBlockAgg
);
bool
rightNull
=
colDataIsNull
(
pColInfoData
,
pDataBlock
->
info
.
rows
,
right
,
pDataBlock
->
pBlockAgg
);
if
(
leftNull
&&
rightNull
)
{
continue
;
// continue to next slot
}
if
(
rightNull
)
{
return
pHelper
->
nullFirst
?
1
:-
1
;
}
if
(
leftNull
)
{
return
pHelper
->
nullFirst
?
-
1
:
1
;
}
}
void
*
left1
=
colDataGet
(
pColInfoData
,
left
);
void
*
right1
=
colDataGet
(
pColInfoData
,
right
);
switch
(
pColInfoData
->
info
.
type
)
{
case
TSDB_DATA_TYPE_INT
:
{
int32_t
leftx
=
*
(
int32_t
*
)
left1
;
int32_t
rightx
=
*
(
int32_t
*
)
right1
;
if
(
leftx
==
rightx
)
{
break
;
}
else
{
if
(
pOrder
->
order
==
TSDB_ORDER_ASC
)
{
return
(
leftx
<
rightx
)
?
-
1
:
1
;
}
else
{
return
(
leftx
<
rightx
)
?
1
:-
1
;
}
}
}
default:
assert
(
0
);
}
}
return
0
;
}
static
int32_t
doAssignOneTuple
(
SColumnInfoData
*
pDstCols
,
int32_t
numOfRows
,
const
SSDataBlock
*
pSrcBlock
,
int32_t
tupleIndex
)
{
int32_t
code
=
0
;
int32_t
numOfCols
=
pSrcBlock
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pDst
=
&
pDstCols
[
i
];
SColumnInfoData
*
pSrc
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
i
);
if
(
pSrc
->
hasNull
&&
colDataIsNull
(
pSrc
,
pSrcBlock
->
info
.
rows
,
tupleIndex
,
pSrcBlock
->
pBlockAgg
))
{
code
=
colDataAppend
(
pDst
,
numOfRows
,
NULL
,
true
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
else
{
char
*
p
=
colDataGet
(
pSrc
,
tupleIndex
);
code
=
colDataAppend
(
pDst
,
numOfRows
,
p
,
false
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
blockDataAssign
(
SColumnInfoData
*
pCols
,
const
SSDataBlock
*
pDataBlock
,
int32_t
*
index
)
{
#if 0
for (int32_t i = 0; i < pDataBlock->info.rows; ++i) {
int32_t code = doAssignOneTuple(pCols, i, pDataBlock, index[i]);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
}
#else
for
(
int32_t
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
pDst
=
&
pCols
[
i
];
SColumnInfoData
*
pSrc
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
pSrc
->
info
.
type
))
{
memcpy
(
pDst
->
pData
,
pSrc
->
pData
,
pSrc
->
varmeta
.
length
);
pDst
->
varmeta
.
length
=
pSrc
->
varmeta
.
length
;
for
(
int32_t
j
=
0
;
j
<
pDataBlock
->
info
.
rows
;
++
j
)
{
pDst
->
varmeta
.
offset
[
j
]
=
pSrc
->
varmeta
.
offset
[
index
[
j
]];
}
}
else
{
switch
(
pSrc
->
info
.
type
)
{
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_INT
:
{
for
(
int32_t
j
=
0
;
j
<
pDataBlock
->
info
.
rows
;
++
j
)
{
int32_t
*
p
=
(
int32_t
*
)
pDst
->
pData
;
int32_t
*
srclist
=
(
int32_t
*
)
pSrc
->
pData
;
p
[
j
]
=
srclist
[
index
[
j
]];
if
(
colDataIsNull_f
(
pSrc
->
nullbitmap
,
index
[
j
]))
{
colDataSetNull_f
(
pDst
->
nullbitmap
,
j
);
}
}
break
;
}
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
{
for
(
int32_t
j
=
0
;
j
<
pDataBlock
->
info
.
rows
;
++
j
)
{
int32_t
*
p
=
(
int32_t
*
)
pDst
->
pData
;
int32_t
*
srclist
=
(
int32_t
*
)
pSrc
->
pData
;
p
[
j
]
=
srclist
[
index
[
j
]];
if
(
colDataIsNull_f
(
pSrc
->
nullbitmap
,
index
[
j
]))
{
colDataSetNull_f
(
pDst
->
nullbitmap
,
j
);
}
}
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
{
for
(
int32_t
j
=
0
;
j
<
pDataBlock
->
info
.
rows
;
++
j
)
{
int32_t
*
p
=
(
int32_t
*
)
pDst
->
pData
;
int32_t
*
srclist
=
(
int32_t
*
)
pSrc
->
pData
;
p
[
j
]
=
srclist
[
index
[
j
]];
if
(
colDataIsNull_f
(
pSrc
->
nullbitmap
,
index
[
j
]))
{
colDataSetNull_f
(
pDst
->
nullbitmap
,
j
);
}
}
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
{
for
(
int32_t
j
=
0
;
j
<
pDataBlock
->
info
.
rows
;
++
j
)
{
int32_t
*
p
=
(
int32_t
*
)
pDst
->
pData
;
int32_t
*
srclist
=
(
int32_t
*
)
pSrc
->
pData
;
p
[
j
]
=
srclist
[
index
[
j
]];
if
(
colDataIsNull_f
(
pSrc
->
nullbitmap
,
index
[
j
]))
{
colDataSetNull_f
(
pDst
->
nullbitmap
,
j
);
}
}
break
;
}
default:
assert
(
0
);
}
}
}
#endif
return
TSDB_CODE_SUCCESS
;
}
static
SColumnInfoData
*
createHelpColInfoData
(
const
SSDataBlock
*
pDataBlock
)
{
int32_t
rows
=
pDataBlock
->
info
.
rows
;
int32_t
numOfCols
=
pDataBlock
->
info
.
numOfCols
;
SColumnInfoData
*
pCols
=
calloc
(
numOfCols
,
sizeof
(
SColumnInfoData
));
if
(
pCols
==
NULL
)
{
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
pCols
[
i
].
info
=
pColInfoData
->
info
;
if
(
IS_VAR_DATA_TYPE
(
pCols
[
i
].
info
.
type
))
{
pCols
[
i
].
varmeta
.
offset
=
calloc
(
rows
,
sizeof
(
int32_t
));
pCols
[
i
].
pData
=
calloc
(
1
,
pColInfoData
->
varmeta
.
length
);
pCols
[
i
].
varmeta
.
length
=
pColInfoData
->
varmeta
.
length
;
pCols
[
i
].
varmeta
.
allocLen
=
pCols
[
i
].
varmeta
.
length
;
}
else
{
pCols
[
i
].
nullbitmap
=
calloc
(
1
,
BitmapLen
(
rows
));
pCols
[
i
].
pData
=
calloc
(
rows
,
pCols
[
i
].
info
.
bytes
);
}
}
return
pCols
;
}
static
void
copyBackToBlock
(
SSDataBlock
*
pDataBlock
,
SColumnInfoData
*
pCols
)
{
int32_t
numOfCols
=
pDataBlock
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
pColInfoData
->
info
=
pCols
[
i
].
info
;
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
tfree
(
pColInfoData
->
varmeta
.
offset
);
pColInfoData
->
varmeta
=
pCols
[
i
].
varmeta
;
}
else
{
tfree
(
pColInfoData
->
nullbitmap
);
pColInfoData
->
nullbitmap
=
pCols
[
i
].
nullbitmap
;
}
tfree
(
pColInfoData
->
pData
);
pColInfoData
->
pData
=
pCols
[
i
].
pData
;
}
tfree
(
pCols
);
}
static
int32_t
*
createTupleIndex
(
size_t
rows
)
{
int32_t
*
index
=
calloc
(
rows
,
sizeof
(
int32_t
));
if
(
index
==
NULL
)
{
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
rows
;
++
i
)
{
index
[
i
]
=
i
;
}
return
index
;
}
static
void
destroyTupleIndex
(
int32_t
*
index
)
{
tfree
(
index
);
}
static
__compar_fn_t
getComparFn
(
int32_t
type
,
int32_t
order
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
return
order
==
TSDB_ORDER_ASC
?
compareInt8Val
:
compareInt8ValDesc
;
case
TSDB_DATA_TYPE_SMALLINT
:
return
order
==
TSDB_ORDER_ASC
?
compareInt16Val
:
compareInt16ValDesc
;
case
TSDB_DATA_TYPE_INT
:
return
order
==
TSDB_ORDER_ASC
?
compareInt32Val
:
compareInt32ValDesc
;
case
TSDB_DATA_TYPE_BIGINT
:
return
order
==
TSDB_ORDER_ASC
?
compareInt64Val
:
compareInt64ValDesc
;
case
TSDB_DATA_TYPE_FLOAT
:
return
order
==
TSDB_ORDER_ASC
?
compareFloatVal
:
compareFloatValDesc
;
case
TSDB_DATA_TYPE_DOUBLE
:
return
order
==
TSDB_ORDER_ASC
?
compareDoubleVal
:
compareDoubleValDesc
;
case
TSDB_DATA_TYPE_UTINYINT
:
return
order
==
TSDB_ORDER_ASC
?
compareUint8Val
:
compareUint8ValDesc
;
case
TSDB_DATA_TYPE_USMALLINT
:
return
order
==
TSDB_ORDER_ASC
?
compareUint16Val
:
compareUint16ValDesc
;
case
TSDB_DATA_TYPE_UINT
:
return
order
==
TSDB_ORDER_ASC
?
compareUint32Val
:
compareUint32ValDesc
;
case
TSDB_DATA_TYPE_UBIGINT
:
return
order
==
TSDB_ORDER_ASC
?
compareUint64Val
:
compareUint64ValDesc
;
default:
return
order
==
TSDB_ORDER_ASC
?
compareInt32Val
:
compareInt32ValDesc
;
}
}
int32_t
blockDataSort
(
SSDataBlock
*
pDataBlock
,
SArray
*
pOrderInfo
,
bool
nullFirst
)
{
ASSERT
(
pDataBlock
!=
NULL
&&
pOrderInfo
!=
NULL
);
if
(
pDataBlock
->
info
.
rows
<=
1
)
{
return
TSDB_CODE_SUCCESS
;
}
// Allocate the additional buffer.
uint32_t
rows
=
pDataBlock
->
info
.
rows
;
bool
sortColumnHasNull
=
false
;
bool
varTypeSort
=
false
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pOrderInfo
);
++
i
)
{
SBlockOrderInfo
*
pInfo
=
taosArrayGet
(
pOrderInfo
,
i
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
pInfo
->
colIndex
);
if
(
pColInfoData
->
hasNull
)
{
sortColumnHasNull
=
true
;
}
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
varTypeSort
=
true
;
}
}
if
(
taosArrayGetSize
(
pOrderInfo
)
==
1
&&
(
!
sortColumnHasNull
))
{
if
(
pDataBlock
->
info
.
numOfCols
==
1
)
{
if
(
!
varTypeSort
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
0
);
SBlockOrderInfo
*
pOrder
=
taosArrayGet
(
pOrderInfo
,
0
);
int64_t
p0
=
taosGetTimestampUs
();
__compar_fn_t
fn
=
getComparFn
(
pColInfoData
->
info
.
type
,
pOrder
->
order
);
qsort
(
pColInfoData
->
pData
,
pDataBlock
->
info
.
rows
,
pColInfoData
->
info
.
bytes
,
fn
);
int64_t
p1
=
taosGetTimestampUs
();
printf
(
"sort:%ld, rows:%d
\n
"
,
p1
-
p0
,
pDataBlock
->
info
.
rows
);
return
TSDB_CODE_SUCCESS
;
}
else
{
// var data type
}
}
else
if
(
pDataBlock
->
info
.
numOfCols
==
2
)
{
}
}
int32_t
*
index
=
createTupleIndex
(
rows
);
if
(
index
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
terrno
;
}
int64_t
p0
=
taosGetTimestampUs
();
SSDataBlockSortHelper
helper
=
{.
nullFirst
=
nullFirst
,
.
pDataBlock
=
pDataBlock
,
.
orderInfo
=
pOrderInfo
};
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
helper
.
orderInfo
);
++
i
)
{
struct
SBlockOrderInfo
*
pInfo
=
taosArrayGet
(
helper
.
orderInfo
,
i
);
pInfo
->
pColData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
pInfo
->
colIndex
);
}
taosqsort
(
index
,
rows
,
sizeof
(
int32_t
),
&
helper
,
dataBlockCompar
);
int64_t
p1
=
taosGetTimestampUs
();
SColumnInfoData
*
pCols
=
createHelpColInfoData
(
pDataBlock
);
if
(
pCols
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
terrno
;
}
int64_t
p2
=
taosGetTimestampUs
();
int32_t
code
=
blockDataAssign
(
pCols
,
pDataBlock
,
index
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
return
code
;
}
int64_t
p3
=
taosGetTimestampUs
();
copyBackToBlock
(
pDataBlock
,
pCols
);
int64_t
p4
=
taosGetTimestampUs
();
printf
(
"sort:%ld, create:%ld, assign:%ld, copyback:%ld, rows:%d
\n
"
,
p1
-
p0
,
p2
-
p1
,
p3
-
p2
,
p4
-
p3
,
rows
);
destroyTupleIndex
(
index
);
return
TSDB_CODE_SUCCESS
;
}
typedef
struct
SHelper
{
int32_t
index
;
union
{
char
*
pData
;
int64_t
i64
;
double
d64
;};
}
SHelper
;
SHelper
*
createTupleIndex_rv
(
int32_t
numOfRows
,
SArray
*
pOrderInfo
,
SSDataBlock
*
pBlock
)
{
int32_t
sortValLengthPerRow
=
0
;
int32_t
numOfCols
=
taosArrayGetSize
(
pOrderInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SBlockOrderInfo
*
pInfo
=
taosArrayGet
(
pOrderInfo
,
i
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
pInfo
->
colIndex
);
pInfo
->
pColData
=
pColInfo
;
sortValLengthPerRow
+=
pColInfo
->
info
.
bytes
;
}
size_t
len
=
sortValLengthPerRow
*
pBlock
->
info
.
rows
;
char
*
buf
=
calloc
(
1
,
len
);
SHelper
*
phelper
=
calloc
(
numOfRows
,
sizeof
(
SHelper
));
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
phelper
[
i
].
index
=
i
;
phelper
[
i
].
pData
=
buf
+
sortValLengthPerRow
*
i
;
}
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SBlockOrderInfo
*
pInfo
=
taosArrayGet
(
pOrderInfo
,
i
);
for
(
int32_t
j
=
0
;
j
<
numOfRows
;
++
j
)
{
phelper
[
j
].
i64
=
*
(
int32_t
*
)
pInfo
->
pColData
->
pData
+
pInfo
->
pColData
->
info
.
bytes
*
j
;
// memcpy(phelper[j].pData + offset, pInfo->pColData->pData + pInfo->pColData->info.bytes * j, pInfo->pColData->info.bytes);
}
offset
+=
pInfo
->
pColData
->
info
.
bytes
;
}
return
phelper
;
}
int32_t
dataBlockCompar_rv
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
)
{
const
SSDataBlockSortHelper
*
pHelper
=
(
const
SSDataBlockSortHelper
*
)
param
;
// SSDataBlock* pDataBlock = pHelper->pDataBlock;
SHelper
*
left
=
(
SHelper
*
)
p1
;
SHelper
*
right
=
(
SHelper
*
)
p2
;
SArray
*
pInfo
=
pHelper
->
orderInfo
;
int32_t
offset
=
0
;
// for(int32_t i = 0; i < pInfo->size; ++i) {
// SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, 0);
// SColumnInfoData* pColInfoData = pOrder->pColData;//TARRAY_GET_ELEM(pDataBlock->pDataBlock, pOrder->colIndex);
// if (pColInfoData->hasNull) {
// bool leftNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, left, pDataBlock->pBlockAgg);
// bool rightNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, right, pDataBlock->pBlockAgg);
// if (leftNull && rightNull) {
// continue; // continue to next slot
// }
//
// if (rightNull) {
// return pHelper->nullFirst? 1:-1;
// }
//
// if (leftNull) {
// return pHelper->nullFirst? -1:1;
// }
// }
// void* left1 = colDataGet(pColInfoData, left);
// void* right1 = colDataGet(pColInfoData, right);
// switch(pColInfoData->info.type) {
// case TSDB_DATA_TYPE_INT: {
int32_t
leftx
=
*
(
int32_t
*
)
left
->
pData
;
//*(int32_t*)(left->pData + offset);
int32_t
rightx
=
*
(
int32_t
*
)
right
->
pData
;
//*(int32_t*)(right->pData + offset);
// offset += pColInfoData->info.bytes;
if
(
leftx
==
rightx
)
{
// break;
return
0
;
}
else
{
// if (pOrder->order == TSDB_ORDER_ASC) {
return
(
leftx
<
rightx
)
?
-
1
:
1
;
// } else {
// return (leftx < rightx)? 1:-1;
// }
}
// }
// default:
// assert(0);
// }
// }
return
0
;
}
int32_t
varColSort
(
SColumnInfoData
*
pColumnInfoData
,
SBlockOrderInfo
*
pOrder
)
{
}
int32_t
blockDataSort_rv
(
SSDataBlock
*
pDataBlock
,
SArray
*
pOrderInfo
,
bool
nullFirst
)
{
// Allocate the additional buffer.
int64_t
p0
=
taosGetTimestampUs
();
SSDataBlockSortHelper
helper
=
{.
nullFirst
=
nullFirst
,
.
pDataBlock
=
pDataBlock
,
.
orderInfo
=
pOrderInfo
};
uint32_t
rows
=
pDataBlock
->
info
.
rows
;
SHelper
*
index
=
createTupleIndex_rv
(
rows
,
helper
.
orderInfo
,
pDataBlock
);
if
(
index
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
terrno
;
}
taosqsort
(
index
,
rows
,
sizeof
(
SHelper
),
&
helper
,
dataBlockCompar_rv
);
int64_t
p1
=
taosGetTimestampUs
();
SColumnInfoData
*
pCols
=
createHelpColInfoData
(
pDataBlock
);
if
(
pCols
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
terrno
;
}
int64_t
p2
=
taosGetTimestampUs
();
// int32_t code = blockDataAssign(pCols, pDataBlock, index);
// if (code != TSDB_CODE_SUCCESS) {
// terrno = code;
// return code;
// }
int64_t
p3
=
taosGetTimestampUs
();
copyBackToBlock
(
pDataBlock
,
pCols
);
int64_t
p4
=
taosGetTimestampUs
();
printf
(
"sort:%ld, create:%ld, assign:%ld, copyback:%ld, rows:%d
\n
"
,
p1
-
p0
,
p2
-
p1
,
p3
-
p2
,
p4
-
p3
,
rows
);
// destroyTupleIndex(index);
}
void
blockDataClearup
(
SSDataBlock
*
pDataBlock
,
bool
hasVarCol
)
{
pDataBlock
->
info
.
rows
=
0
;
if
(
hasVarCol
)
{
for
(
int32_t
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
p
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
p
->
info
.
type
))
{
p
->
varmeta
.
length
=
0
;
}
}
}
}
int32_t
blockDataEnsureCapacity
(
SSDataBlock
*
pDataBlock
,
uint32_t
numOfRows
)
{
for
(
int32_t
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
p
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
p
->
info
.
type
))
{
char
*
tmp
=
realloc
(
p
->
varmeta
.
offset
,
sizeof
(
int32_t
)
*
numOfRows
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
p
->
varmeta
.
offset
=
(
int32_t
*
)
tmp
;
memset
(
p
->
varmeta
.
offset
,
0
,
sizeof
(
int32_t
)
*
numOfRows
);
p
->
varmeta
.
length
=
0
;
p
->
varmeta
.
allocLen
=
0
;
tfree
(
p
->
pData
);
}
else
{
char
*
tmp
=
realloc
(
p
->
nullbitmap
,
BitmapLen
(
numOfRows
));
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
p
->
nullbitmap
=
tmp
;
memset
(
p
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
tmp
=
realloc
(
p
->
pData
,
numOfRows
*
p
->
info
.
bytes
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
p
->
pData
=
tmp
;
}
}
return
TSDB_CODE_SUCCESS
;
}
void
*
blockDataDestroy
(
SSDataBlock
*
pBlock
)
{
if
(
pBlock
==
NULL
)
{
return
NULL
;
}
int32_t
numOfOutput
=
pBlock
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
tfree
(
pColInfoData
->
varmeta
.
offset
);
}
else
{
tfree
(
pColInfoData
->
nullbitmap
);
}
tfree
(
pColInfoData
->
pData
);
}
taosArrayDestroy
(
pBlock
->
pDataBlock
);
tfree
(
pBlock
->
pBlockAgg
);
tfree
(
pBlock
);
return
NULL
;
}
\ No newline at end of file
source/common/src/tname.c
浏览文件 @
378aaf38
#include <common.h>
#include "os.h"
#include "os.h"
#include "tutil.h"
#include "tutil.h"
...
@@ -268,4 +269,5 @@ SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* nam
...
@@ -268,4 +269,5 @@ SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* nam
tstrncpy
(
s
.
name
,
name
,
tListLen
(
s
.
name
));
tstrncpy
(
s
.
name
,
name
,
tListLen
(
s
.
name
));
return
s
;
return
s
;
}
}
\ No newline at end of file
source/common/src/ttszip.c
浏览文件 @
378aaf38
...
@@ -344,8 +344,8 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
...
@@ -344,8 +344,8 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
UNUSED
(
ret
);
UNUSED
(
ret
);
}
}
fread
(
&
pBlock
->
tag
.
nType
,
sizeof
(
pBlock
->
tag
.
nType
),
1
,
pTSBuf
->
f
);
int32_t
ret
=
fread
(
&
pBlock
->
tag
.
nType
,
sizeof
(
pBlock
->
tag
.
nType
),
1
,
pTSBuf
->
f
);
fread
(
&
pBlock
->
tag
.
nLen
,
sizeof
(
pBlock
->
tag
.
nLen
),
1
,
pTSBuf
->
f
);
ret
=
fread
(
&
pBlock
->
tag
.
nLen
,
sizeof
(
pBlock
->
tag
.
nLen
),
1
,
pTSBuf
->
f
);
// NOTE: mix types tags are not supported
// NOTE: mix types tags are not supported
size_t
sz
=
0
;
size_t
sz
=
0
;
...
...
source/common/test/commonTests.cpp
浏览文件 @
378aaf38
#include <common.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <tep.h>
#include <iostream>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h"
#include "os.h"
...
@@ -96,4 +97,199 @@ TEST(testCase, toInteger_test) {
...
@@ -96,4 +97,199 @@ TEST(testCase, toInteger_test) {
ASSERT_EQ
(
ret
,
-
1
);
ASSERT_EQ
(
ret
,
-
1
);
}
}
TEST
(
testCase
,
Datablock_test
)
{
SSDataBlock
*
b
=
static_cast
<
SSDataBlock
*>
(
calloc
(
1
,
sizeof
(
SSDataBlock
)));
b
->
info
.
numOfCols
=
2
;
b
->
pDataBlock
=
taosArrayInit
(
4
,
sizeof
(
SColumnInfoData
));
SColumnInfoData
infoData
=
{
0
};
infoData
.
info
.
bytes
=
4
;
infoData
.
info
.
type
=
TSDB_DATA_TYPE_INT
;
infoData
.
info
.
colId
=
1
;
infoData
.
pData
=
(
char
*
)
calloc
(
40
,
infoData
.
info
.
bytes
);
infoData
.
nullbitmap
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
40
/
8
));
taosArrayPush
(
b
->
pDataBlock
,
&
infoData
);
SColumnInfoData
infoData1
=
{
0
};
infoData1
.
info
.
bytes
=
40
;
infoData1
.
info
.
type
=
TSDB_DATA_TYPE_BINARY
;
infoData1
.
info
.
colId
=
2
;
infoData1
.
varmeta
.
offset
=
(
int32_t
*
)
calloc
(
40
,
sizeof
(
uint32_t
));
taosArrayPush
(
b
->
pDataBlock
,
&
infoData1
);
char
*
str
=
"the value of: %d"
;
char
buf
[
128
]
=
{
0
};
char
varbuf
[
128
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
40
;
++
i
)
{
SColumnInfoData
*
p0
=
(
SColumnInfoData
*
)
taosArrayGet
(
b
->
pDataBlock
,
0
);
SColumnInfoData
*
p1
=
(
SColumnInfoData
*
)
taosArrayGet
(
b
->
pDataBlock
,
1
);
if
(
i
&
0x01
)
{
int32_t
len
=
sprintf
(
buf
,
str
,
i
);
STR_TO_VARSTR
(
varbuf
,
buf
)
colDataAppend
(
p0
,
i
,
(
const
char
*
)
&
i
,
false
);
colDataAppend
(
p1
,
i
,
(
const
char
*
)
varbuf
,
false
);
memset
(
varbuf
,
0
,
sizeof
(
varbuf
));
memset
(
buf
,
0
,
sizeof
(
buf
));
}
else
{
colDataAppend
(
p0
,
i
,
(
const
char
*
)
&
i
,
true
);
colDataAppend
(
p1
,
i
,
(
const
char
*
)
varbuf
,
true
);
}
b
->
info
.
rows
++
;
}
SColumnInfoData
*
p0
=
(
SColumnInfoData
*
)
taosArrayGet
(
b
->
pDataBlock
,
0
);
SColumnInfoData
*
p1
=
(
SColumnInfoData
*
)
taosArrayGet
(
b
->
pDataBlock
,
1
);
for
(
int32_t
i
=
0
;
i
<
40
;
++
i
)
{
if
(
i
&
0x01
)
{
ASSERT_EQ
(
colDataIsNull_f
(
p0
->
nullbitmap
,
i
),
false
);
ASSERT_EQ
(
colDataIsNull
(
p1
,
b
->
info
.
rows
,
i
,
nullptr
),
false
);
}
else
{
ASSERT_EQ
(
colDataIsNull_f
(
p0
->
nullbitmap
,
i
),
true
);
ASSERT_EQ
(
colDataIsNull
(
p0
,
b
->
info
.
rows
,
i
,
nullptr
),
true
);
ASSERT_EQ
(
colDataIsNull
(
p1
,
b
->
info
.
rows
,
i
,
nullptr
),
true
);
}
}
printf
(
"binary column length:%d
\n
"
,
*
(
int32_t
*
)
p1
->
pData
);
ASSERT_EQ
(
colDataGetNumOfCols
(
b
),
2
);
ASSERT_EQ
(
colDataGetNumOfRows
(
b
),
40
);
char
*
pData
=
colDataGet
(
p1
,
3
);
printf
(
"the second row of binary:%s, length:%d
\n
"
,
(
char
*
)
varDataVal
(
pData
),
varDataLen
(
pData
));
SArray
*
pOrderInfo
=
taosArrayInit
(
3
,
sizeof
(
SBlockOrderInfo
));
SBlockOrderInfo
order
=
{.
order
=
TSDB_ORDER_ASC
,
.
colIndex
=
0
};
taosArrayPush
(
pOrderInfo
,
&
order
);
blockDataSort
(
b
,
pOrderInfo
,
true
);
blockDataDestroy
(
b
);
taosArrayDestroy
(
pOrderInfo
);
}
#if 0
TEST(testCase, non_var_dataBlock_split_test) {
SSDataBlock* b = static_cast<SSDataBlock*>(calloc(1, sizeof(SSDataBlock)));
b->info.numOfCols = 2;
b->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData));
SColumnInfoData infoData = {0};
infoData.info.bytes = 4;
infoData.info.type = TSDB_DATA_TYPE_INT;
infoData.info.colId = 1;
int32_t numOfRows = 1000000;
infoData.pData = (char*) calloc(numOfRows, infoData.info.bytes);
infoData.nullbitmap = (char*) calloc(1, sizeof(char) * (numOfRows/8));
taosArrayPush(b->pDataBlock, &infoData);
SColumnInfoData infoData1 = {0};
infoData1.info.bytes = 1;
infoData1.info.type = TSDB_DATA_TYPE_TINYINT;
infoData1.info.colId = 2;
infoData1.pData = (char*) calloc(numOfRows, infoData.info.bytes);
infoData1.nullbitmap = (char*) calloc(1, sizeof(char) * (numOfRows/8));
taosArrayPush(b->pDataBlock, &infoData1);
for(int32_t i = 0; i < numOfRows; ++i) {
SColumnInfoData* p0 = (SColumnInfoData*)taosArrayGet(b->pDataBlock, 0);
SColumnInfoData* p1 = (SColumnInfoData*)taosArrayGet(b->pDataBlock, 1);
int8_t v = i;
colDataAppend(p0, i, (const char*)&i, false);
colDataAppend(p1, i, (const char*)&v, false);
b->info.rows++;
}
int32_t pageSize = 64 * 1024;
int32_t startIndex= 0;
int32_t stopIndex = 0;
int32_t count = 1;
while(1) {
blockDataSplitRows(b, false, startIndex, &stopIndex, pageSize);
printf("the %d split, from: %d to %d\n", count++, startIndex, stopIndex);
if (stopIndex == numOfRows - 1) {
break;
}
startIndex = stopIndex + 1;
}
}
#endif
TEST
(
testCase
,
var_dataBlock_split_test
)
{
SSDataBlock
*
b
=
static_cast
<
SSDataBlock
*>
(
calloc
(
1
,
sizeof
(
SSDataBlock
)));
b
->
info
.
numOfCols
=
2
;
b
->
pDataBlock
=
taosArrayInit
(
4
,
sizeof
(
SColumnInfoData
));
int32_t
numOfRows
=
1000000
;
SColumnInfoData
infoData
=
{
0
};
infoData
.
info
.
bytes
=
4
;
infoData
.
info
.
type
=
TSDB_DATA_TYPE_INT
;
infoData
.
info
.
colId
=
1
;
infoData
.
pData
=
(
char
*
)
calloc
(
numOfRows
,
infoData
.
info
.
bytes
);
infoData
.
nullbitmap
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
numOfRows
/
8
));
taosArrayPush
(
b
->
pDataBlock
,
&
infoData
);
SColumnInfoData
infoData1
=
{
0
};
infoData1
.
info
.
bytes
=
40
;
infoData1
.
info
.
type
=
TSDB_DATA_TYPE_BINARY
;
infoData1
.
info
.
colId
=
2
;
infoData1
.
varmeta
.
offset
=
(
int32_t
*
)
calloc
(
numOfRows
,
sizeof
(
uint32_t
));
taosArrayPush
(
b
->
pDataBlock
,
&
infoData1
);
char
buf
[
41
]
=
{
0
};
char
buf1
[
100
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
SColumnInfoData
*
p0
=
(
SColumnInfoData
*
)
taosArrayGet
(
b
->
pDataBlock
,
0
);
SColumnInfoData
*
p1
=
(
SColumnInfoData
*
)
taosArrayGet
(
b
->
pDataBlock
,
1
);
int8_t
v
=
i
;
colDataAppend
(
p0
,
i
,
(
const
char
*
)
&
i
,
false
);
sprintf
(
buf
,
"the number of row:%d"
,
i
);
int32_t
len
=
sprintf
(
buf1
,
buf
,
i
);
STR_TO_VARSTR
(
buf1
,
buf
)
colDataAppend
(
p1
,
i
,
buf1
,
false
);
b
->
info
.
rows
++
;
memset
(
buf
,
0
,
sizeof
(
buf
));
memset
(
buf1
,
0
,
sizeof
(
buf1
));
}
int32_t
pageSize
=
64
*
1024
;
int32_t
startIndex
=
0
;
int32_t
stopIndex
=
0
;
int32_t
count
=
1
;
while
(
1
)
{
blockDataSplitRows
(
b
,
true
,
startIndex
,
&
stopIndex
,
pageSize
);
printf
(
"the %d split, from: %d to %d
\n
"
,
count
++
,
startIndex
,
stopIndex
);
if
(
stopIndex
==
numOfRows
-
1
)
{
break
;
}
startIndex
=
stopIndex
+
1
;
}
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
378aaf38
...
@@ -2174,8 +2174,8 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
...
@@ -2174,8 +2174,8 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
assert
(
cnt
<=
numOfBlocks
&&
numOfQualTables
<=
numOfTables
);
// the pTableQueryInfo[j]->numOfBlocks may be 0
assert
(
cnt
<=
numOfBlocks
&&
numOfQualTables
<=
numOfTables
);
// the pTableQueryInfo[j]->numOfBlocks may be 0
sup
.
numOfTables
=
numOfQualTables
;
sup
.
numOfTables
=
numOfQualTables
;
S
Loser
TreeInfo
*
pTree
=
NULL
;
S
MultiwayMerge
TreeInfo
*
pTree
=
NULL
;
uint8_t
ret
=
t
Loser
TreeCreate
(
&
pTree
,
sup
.
numOfTables
,
&
sup
,
dataBlockOrderCompar
);
uint8_t
ret
=
t
Merge
TreeCreate
(
&
pTree
,
sup
.
numOfTables
,
&
sup
,
dataBlockOrderCompar
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
cleanBlockOrderSupporter
(
&
sup
,
numOfTables
);
cleanBlockOrderSupporter
(
&
sup
,
numOfTables
);
return
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
TSDB_CODE_TDB_OUT_OF_MEMORY
;
...
@@ -2184,7 +2184,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
...
@@ -2184,7 +2184,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
int32_t
numOfTotal
=
0
;
int32_t
numOfTotal
=
0
;
while
(
numOfTotal
<
cnt
)
{
while
(
numOfTotal
<
cnt
)
{
int32_t
pos
=
pTree
->
pNode
[
0
].
index
;
int32_t
pos
=
tMergeTreeGetChosenIndex
(
pTree
)
;
int32_t
index
=
sup
.
blockIndexArray
[
pos
]
++
;
int32_t
index
=
sup
.
blockIndexArray
[
pos
]
++
;
STableBlockInfo
*
pBlocksInfo
=
sup
.
pDataBlockInfo
[
pos
];
STableBlockInfo
*
pBlocksInfo
=
sup
.
pDataBlockInfo
[
pos
];
...
@@ -2195,7 +2195,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
...
@@ -2195,7 +2195,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
sup
.
blockIndexArray
[
pos
]
=
sup
.
numOfBlocksPerTable
[
pos
]
+
1
;
sup
.
blockIndexArray
[
pos
]
=
sup
.
numOfBlocksPerTable
[
pos
]
+
1
;
}
}
t
LoserTreeAdjust
(
pTree
,
pos
+
sup
.
numOfTables
);
t
MergeTreeAdjust
(
pTree
,
tMergeTreeGetAdjustIndex
(
pTree
)
);
}
}
/*
/*
...
@@ -3643,13 +3643,13 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
...
@@ -3643,13 +3643,13 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
SColIndex
*
pColIndex
,
int32_t
numOfCols
,
uint64_t
reqId
,
uint64_t
taskId
)
{
SColIndex
*
pColIndex
,
int32_t
numOfCols
,
uint64_t
reqId
,
uint64_t
taskId
)
{
STbCfg
*
pTbCfg
=
metaGetTbInfoByUid
(
pMeta
,
uid
);
STbCfg
*
pTbCfg
=
metaGetTbInfoByUid
(
pMeta
,
uid
);
if
(
pTbCfg
==
NULL
)
{
if
(
pTbCfg
==
NULL
)
{
// tsdbError("%p failed to get stable, uid:%"PRIu64", TID:0x%"PRIx64" QID:0x%"PRIx64, tsdb
, uid, taskId, reqId);
tsdbError
(
"%p failed to get stable, uid:%"
PRIu64
", TID:0x%"
PRIx64
" QID:0x%"
PRIx64
,
pMeta
,
uid
,
taskId
,
reqId
);
terrno
=
TSDB_CODE_TDB_INVALID_TABLE_ID
;
terrno
=
TSDB_CODE_TDB_INVALID_TABLE_ID
;
goto
_error
;
goto
_error
;
}
}
if
(
pTbCfg
->
type
!=
META_SUPER_TABLE
)
{
if
(
pTbCfg
->
type
!=
META_SUPER_TABLE
)
{
// tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", TID:0x%"PRIx64" QID:0x%"PRIx64, tsdb
, uid, taskId, reqId);
tsdbError
(
"%p query normal tag not allowed, uid:%"
PRIu64
", TID:0x%"
PRIx64
" QID:0x%"
PRIx64
,
pMeta
,
uid
,
taskId
,
reqId
);
terrno
=
TSDB_CODE_OPS_NOT_SUPPORT
;
//basically, this error is caused by invalid sql issued by client
terrno
=
TSDB_CODE_OPS_NOT_SUPPORT
;
//basically, this error is caused by invalid sql issued by client
goto
_error
;
goto
_error
;
}
}
...
@@ -3668,8 +3668,8 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
...
@@ -3668,8 +3668,8 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
pGroupInfo
->
numOfTables
=
(
uint32_t
)
taosArrayGetSize
(
res
);
pGroupInfo
->
numOfTables
=
(
uint32_t
)
taosArrayGetSize
(
res
);
pGroupInfo
->
pGroupList
=
createTableGroup
(
res
,
pTagSchema
,
pColIndex
,
numOfCols
,
skey
);
pGroupInfo
->
pGroupList
=
createTableGroup
(
res
,
pTagSchema
,
pColIndex
,
numOfCols
,
skey
);
// tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu, TID:0x%"PRIx64" QID:0x%"PRIx64, tsdb
,
tsdbDebug
(
"%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu, TID:0x%"
PRIx64
" QID:0x%"
PRIx64
,
pMeta
,
//
pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList), taskId, reqId);
pGroupInfo
->
numOfTables
,
taosArrayGetSize
(
pGroupInfo
->
pGroupList
),
taskId
,
reqId
);
taosArrayDestroy
(
res
);
taosArrayDestroy
(
res
);
return
ret
;
return
ret
;
...
...
source/libs/executor/inc/executil.h
浏览文件 @
378aaf38
...
@@ -16,8 +16,8 @@
...
@@ -16,8 +16,8 @@
#define TDENGINE_QUERYUTIL_H
#define TDENGINE_QUERYUTIL_H
#include "common.h"
#include "common.h"
#include "tpagedfile.h"
#include "tbuffer.h"
#include "tbuffer.h"
#include "tpagedbuf.h"
#define SET_RES_WINDOW_KEY(_k, _ori, _len, _uid) \
#define SET_RES_WINDOW_KEY(_k, _ori, _len, _uid) \
do { \
do { \
...
@@ -126,6 +126,13 @@ static FORCE_INLINE char* getPosInResultPage(struct STaskAttr* pQueryAttr, SFile
...
@@ -126,6 +126,13 @@ static FORCE_INLINE char* getPosInResultPage(struct STaskAttr* pQueryAttr, SFile
// return ((char *)page->data) + rowOffset + offset * numOfRows;
// return ((char *)page->data) + rowOffset + offset * numOfRows;
}
}
static
FORCE_INLINE
char
*
getPosInResultPage_rv
(
SFilePage
*
page
,
int32_t
rowOffset
,
int32_t
offset
)
{
assert
(
rowOffset
>=
0
);
int32_t
numOfRows
=
1
;
//(int32_t)getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery);
return
((
char
*
)
page
->
data
)
+
rowOffset
+
offset
*
numOfRows
;
}
//bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type);
//bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type);
//bool notNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type);
//bool notNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type);
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
378aaf38
...
@@ -15,35 +15,40 @@
...
@@ -15,35 +15,40 @@
#ifndef TDENGINE_EXECUTORIMPL_H
#ifndef TDENGINE_EXECUTORIMPL_H
#define TDENGINE_EXECUTORIMPL_H
#define TDENGINE_EXECUTORIMPL_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "os.h"
#include "os.h"
#include "common.h"
#include "common.h"
#include "tlosertree.h"
#include "ttszip.h"
#include "ttszip.h"
#include "tvariant.h"
#include "tvariant.h"
#include "dataSinkMgt.h"
#include "dataSinkMgt.h"
#include "executil.h"
#include "executil.h"
#include "executor.h"
#include "planner.h"
#include "planner.h"
#include "taosdef.h"
#include "taosdef.h"
#include "tarray.h"
#include "tarray.h"
#include "tfilter.h"
#include "tfilter.h"
#include "thash.h"
#include "thash.h"
#include "tlockfree.h"
#include "tlockfree.h"
#include "tpagedfile.h"
#include "tpagedbuf.h"
#include "executor.h"
struct
SColumnFilterElem
;
struct
SColumnFilterElem
;
typedef
int32_t
(
*
__block_search_fn_t
)(
char
*
data
,
int32_t
num
,
int64_t
key
,
int32_t
order
);
typedef
int32_t
(
*
__block_search_fn_t
)(
char
*
data
,
int32_t
num
,
int64_t
key
,
int32_t
order
);
#define IS_QUERY_KILLED(_q) ((_q)->code == TSDB_CODE_TSC_QUERY_CANCELLED)
#define IS_QUERY_KILLED(_q) ((_q)->code == TSDB_CODE_TSC_QUERY_CANCELLED)
#define Q_STATUS_EQUAL(p, s)
(((p) & (s)) != 0u)
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
#define GET_TABLEGROUP(q, _index)
((SArray*)
taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index)))
#define GET_TABLEGROUP(q, _index)
((SArray*)
taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index)))
#define GET_NUM_OF_RESULTS(_r) (((_r)->outputBuf) == NULL
? 0:
((_r)->outputBuf)->info.rows)
#define GET_NUM_OF_RESULTS(_r) (((_r)->outputBuf) == NULL
? 0 :
((_r)->outputBuf)->info.rows)
#define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData? 1 : 0)
#define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData
? 1 : 0)
enum
{
enum
{
// when this task starts to execute, this status will set
// when this task starts to execute, this status will set
...
@@ -62,8 +67,8 @@ enum {
...
@@ -62,8 +67,8 @@ enum {
};
};
typedef
struct
SResultRowCell
{
typedef
struct
SResultRowCell
{
uint64_t
groupId
;
uint64_t
groupId
;
SResultRow
*
pRow
;
SResultRow
*
pRow
;
}
SResultRowCell
;
}
SResultRowCell
;
/**
/**
...
@@ -80,25 +85,23 @@ typedef struct SColumnFilterElem {
...
@@ -80,25 +85,23 @@ typedef struct SColumnFilterElem {
int16_t
bytes
;
// column length
int16_t
bytes
;
// column length
__filter_func_t
fp
;
__filter_func_t
fp
;
SColumnFilterInfo
filterInfo
;
SColumnFilterInfo
filterInfo
;
void
*
q
;
void
*
q
;
}
SColumnFilterElem
;
}
SColumnFilterElem
;
typedef
struct
SSingleColumnFilterInfo
{
typedef
struct
SSingleColumnFilterInfo
{
void
*
pData
;
void
*
pData
;
void
*
pData2
;
//used for nchar column
void
*
pData2
;
//
used for nchar column
int32_t
numOfFilters
;
int32_t
numOfFilters
;
SColumnInfo
info
;
SColumnInfo
info
;
SColumnFilterElem
*
pFilters
;
SColumnFilterElem
*
pFilters
;
}
SSingleColumnFilterInfo
;
}
SSingleColumnFilterInfo
;
typedef
struct
STableQueryInfo
{
typedef
struct
STableQueryInfo
{
TSKEY
lastKey
;
TSKEY
lastKey
;
// last check ts
int32_t
groupIndex
;
// group id in table list
uint64_t
uid
;
// table uid
SVariant
tag
;
int32_t
groupIndex
;
// group id in table list
STimeWindow
win
;
// todo remove it later
// SVariant tag;
STSCursor
cur
;
SResultRowInfo
resInfo
;
// result info
void
*
pTable
;
// for retrieve the page id list
SResultRowInfo
resInfo
;
}
STableQueryInfo
;
}
STableQueryInfo
;
typedef
enum
{
typedef
enum
{
...
@@ -109,11 +112,11 @@ typedef enum {
...
@@ -109,11 +112,11 @@ typedef enum {
typedef
struct
{
typedef
struct
{
EQueryProfEventType
eventType
;
EQueryProfEventType
eventType
;
int64_t
eventTime
;
int64_t
eventTime
;
union
{
union
{
uint8_t
operatorType
;
//
for operator event
uint8_t
operatorType
;
//
for operator event
int32_t
abortCode
;
//
for query abort event
int32_t
abortCode
;
//
for query abort event
};
};
}
SQueryProfEvent
;
}
SQueryProfEvent
;
...
@@ -124,33 +127,33 @@ typedef struct {
...
@@ -124,33 +127,33 @@ typedef struct {
}
SOperatorProfResult
;
}
SOperatorProfResult
;
typedef
struct
STaskCostInfo
{
typedef
struct
STaskCostInfo
{
int64_t
created
;
int64_t
created
;
int64_t
start
;
int64_t
start
;
int64_t
end
;
int64_t
end
;
uint64_t
loadStatisTime
;
uint64_t
loadStatisTime
;
uint64_t
loadFileBlockTime
;
uint64_t
loadFileBlockTime
;
uint64_t
loadDataInCacheTime
;
uint64_t
loadDataInCacheTime
;
uint64_t
loadStatisSize
;
uint64_t
loadStatisSize
;
uint64_t
loadFileBlockSize
;
uint64_t
loadFileBlockSize
;
uint64_t
loadDataInCacheSize
;
uint64_t
loadDataInCacheSize
;
uint64_t
loadDataTime
;
uint64_t
loadDataTime
;
uint64_t
totalRows
;
uint64_t
totalRows
;
uint64_t
totalCheckedRows
;
uint64_t
totalCheckedRows
;
uint32_t
totalBlocks
;
uint32_t
totalBlocks
;
uint32_t
loadBlocks
;
uint32_t
loadBlocks
;
uint32_t
loadBlockStatis
;
uint32_t
loadBlockStatis
;
uint32_t
discardBlocks
;
uint32_t
discardBlocks
;
uint64_t
elapsedTime
;
uint64_t
elapsedTime
;
uint64_t
firstStageMergeTime
;
uint64_t
firstStageMergeTime
;
uint64_t
winInfoSize
;
uint64_t
winInfoSize
;
uint64_t
tableInfoSize
;
uint64_t
tableInfoSize
;
uint64_t
hashSize
;
uint64_t
hashSize
;
uint64_t
numOfTimeWindows
;
uint64_t
numOfTimeWindows
;
SArray
*
queryProfEvents
;
//
SArray<SQueryProfEvent>
SArray
*
queryProfEvents
;
//
SArray<SQueryProfEvent>
SHashObj
*
operatorProfResults
;
//
map<operator_type, SQueryProfEvent>
SHashObj
*
operatorProfResults
;
//
map<operator_type, SQueryProfEvent>
}
STaskCostInfo
;
}
STaskCostInfo
;
typedef
struct
{
typedef
struct
{
...
@@ -166,67 +169,67 @@ typedef struct {
...
@@ -166,67 +169,67 @@ typedef struct {
// The basic query information extracted from the SQueryInfo tree to support the
// The basic query information extracted from the SQueryInfo tree to support the
// execution of query in a data node.
// execution of query in a data node.
typedef
struct
STaskAttr
{
typedef
struct
STaskAttr
{
SLimit
limit
;
SLimit
limit
;
SLimit
slimit
;
SLimit
slimit
;
// todo comment it
// todo comment it
bool
stableQuery
;
// super table query or not
bool
stableQuery
;
// super table query or not
bool
topBotQuery
;
// TODO used bitwise flag
bool
topBotQuery
;
// TODO used bitwise flag
bool
groupbyColumn
;
// denote if this is a groupby normal column query
bool
groupbyColumn
;
// denote if this is a groupby normal column query
bool
hasTagResults
;
// if there are tag values in final result or not
bool
hasTagResults
;
// if there are tag values in final result or not
bool
timeWindowInterpo
;
// if the time window start/end required interpolation
bool
timeWindowInterpo
;
// if the time window start/end required interpolation
bool
queryBlockDist
;
// if query data block distribution
bool
queryBlockDist
;
// if query data block distribution
bool
stabledev
;
// super table stddev query
bool
stabledev
;
// super table stddev query
bool
tsCompQuery
;
// is tscomp query
bool
tsCompQuery
;
// is tscomp query
bool
diffQuery
;
// is diff query
bool
diffQuery
;
// is diff query
bool
simpleAgg
;
bool
simpleAgg
;
bool
pointInterpQuery
;
// point interpolation query
bool
pointInterpQuery
;
// point interpolation query
bool
needReverseScan
;
// need reverse scan
bool
needReverseScan
;
// need reverse scan
bool
distinct
;
// distinct query or not
bool
distinct
;
// distinct query or not
bool
stateWindow
;
// window State on sub/normal table
bool
stateWindow
;
// window State on sub/normal table
bool
createFilterOperator
;
// if filter operator is needed
bool
createFilterOperator
;
// if filter operator is needed
bool
multigroupResult
;
// multigroup result can exist in one SSDataBlock
bool
multigroupResult
;
// multigroup result can exist in one SSDataBlock
int32_t
interBufSize
;
// intermediate buffer sizse
int32_t
interBufSize
;
// intermediate buffer sizse
int32_t
havingNum
;
// having expr number
int32_t
havingNum
;
// having expr number
SOrder
order
;
SOrder
order
;
int16_t
numOfCols
;
int16_t
numOfCols
;
int16_t
numOfTags
;
int16_t
numOfTags
;
STimeWindow
window
;
STimeWindow
window
;
SInterval
interval
;
SInterval
interval
;
SSessionWindow
sw
;
SSessionWindow
sw
;
int16_t
precision
;
int16_t
precision
;
int16_t
numOfOutput
;
int16_t
numOfOutput
;
int16_t
fillType
;
int16_t
fillType
;
int32_t
srcRowSize
;
// todo extract struct
int32_t
srcRowSize
;
// todo extract struct
int32_t
resultRowSize
;
int32_t
resultRowSize
;
int32_t
intermediateResultRowSize
;
// intermediate result row size, in case of top-k query.
int32_t
intermediateResultRowSize
;
// intermediate result row size, in case of top-k query.
int32_t
maxTableColumnWidth
;
int32_t
maxTableColumnWidth
;
int32_t
tagLen
;
// tag value length of current query
int32_t
tagLen
;
// tag value length of current query
SGroupbyExpr
*
pGroupbyExpr
;
SGroupbyExpr
*
pGroupbyExpr
;
SExprInfo
*
pExpr1
;
SExprInfo
*
pExpr1
;
SExprInfo
*
pExpr2
;
SExprInfo
*
pExpr2
;
int32_t
numOfExpr2
;
int32_t
numOfExpr2
;
SExprInfo
*
pExpr3
;
SExprInfo
*
pExpr3
;
int32_t
numOfExpr3
;
int32_t
numOfExpr3
;
SColumnInfo
*
tableCols
;
SColumnInfo
*
tableCols
;
SColumnInfo
*
tagColList
;
SColumnInfo
*
tagColList
;
int32_t
numOfFilterCols
;
int32_t
numOfFilterCols
;
int64_t
*
fillVal
;
int64_t
*
fillVal
;
SOrderedPrjQueryInfo
prjInfo
;
// limit value for each vgroup, only available in global order projection query.
SOrderedPrjQueryInfo
prjInfo
;
// limit value for each vgroup, only available in global order projection query.
SSingleColumnFilterInfo
*
pFilterInfo
;
SSingleColumnFilterInfo
*
pFilterInfo
;
// SFilterInfo *pFilters;
// SFilterInfo *pFilters;
void
*
tsdb
;
void
*
tsdb
;
STableGroupInfo
tableGroupInfo
;
// table <tid, last_key> list SArray<STableKeyInfo>
STableGroupInfo
tableGroupInfo
;
// table <tid, last_key> list SArray<STableKeyInfo>
int32_t
vgId
;
int32_t
vgId
;
SArray
*
pUdfInfo
;
// no need to free
SArray
*
pUdfInfo
;
// no need to free
}
STaskAttr
;
}
STaskAttr
;
typedef
int32_t
(
*
__optr_prepare_fn_t
)(
void
*
param
);
typedef
int32_t
(
*
__optr_prepare_fn_t
)(
void
*
param
);
...
@@ -236,176 +239,185 @@ typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num);
...
@@ -236,176 +239,185 @@ typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num);
struct
SOperatorInfo
;
struct
SOperatorInfo
;
typedef
struct
STaskIdInfo
{
typedef
struct
STaskIdInfo
{
uint64_t
queryId
;
// this is also a request id
uint64_t
queryId
;
// this is also a request id
uint64_t
subplanId
;
uint64_t
subplanId
;
uint64_t
templateId
;
uint64_t
templateId
;
char
*
str
;
char
*
str
;
}
STaskIdInfo
;
}
STaskIdInfo
;
typedef
struct
SExecTaskInfo
{
typedef
struct
SExecTaskInfo
{
STaskIdInfo
id
;
STaskIdInfo
id
;
char
*
content
;
char
*
content
;
uint32_t
status
;
uint32_t
status
;
STimeWindow
window
;
STimeWindow
window
;
STaskCostInfo
cost
;
STaskCostInfo
cost
;
int64_t
owner
;
// if it is in execution
int64_t
owner
;
// if it is in execution
int32_t
code
;
int32_t
code
;
uint64_t
totalRows
;
// total number of rows
uint64_t
totalRows
;
// total number of rows
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
char
*
sql
;
// query sql string
char
*
sql
;
// query sql string
jmp_buf
env
;
//
jmp_buf
env
;
//
struct
SOperatorInfo
*
pRoot
;
struct
SOperatorInfo
*
pRoot
;
}
SExecTaskInfo
;
}
SExecTaskInfo
;
typedef
struct
STaskRuntimeEnv
{
typedef
struct
STaskRuntimeEnv
{
jmp_buf
env
;
jmp_buf
env
;
STaskAttr
*
pQueryAttr
;
STaskAttr
*
pQueryAttr
;
uint32_t
status
;
// query status
uint32_t
status
;
// query status
void
*
qinfo
;
void
*
qinfo
;
uint8_t
scanFlag
;
// denotes reversed scan of data or not
uint8_t
scanFlag
;
// denotes reversed scan of data or not
void
*
pTsdbReadHandle
;
void
*
pTsdbReadHandle
;
int32_t
prevGroupId
;
// previous executed group id
int32_t
prevGroupId
;
// previous executed group id
bool
enableGroupData
;
bool
enableGroupData
;
SDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
SDiskbasedBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
SHashObj
*
pResultRowHashTable
;
// quick locate the window object for each result
SHashObj
*
pResultRowHashTable
;
// quick locate the window object for each result
SHashObj
*
pResultRowListSet
;
// used to check if current ResultRowInfo has ResultRow object or not
SHashObj
*
pResultRowListSet
;
// used to check if current ResultRowInfo has ResultRow object or not
SArray
*
pResultRowArrayList
;
// The array list that contains the Result rows
SArray
*
pResultRowArrayList
;
// The array list that contains the Result rows
char
*
keyBuf
;
// window key buffer
char
*
keyBuf
;
// window key buffer
SResultRowPool
*
pool
;
// The window result objects pool, all the resultRow Objects are allocated and managed by this object.
// The window result objects pool, all the resultRow Objects are allocated and managed by this object.
char
**
prevRow
;
char
**
prevRow
;
SResultRowPool
*
pool
;
SArray
*
prevResult
;
// intermediate result, SArray<SInterResult>
STSBuf
*
pTsBuf
;
// timestamp filter list
SArray
*
prevResult
;
// intermediate result, SArray<SInterResult>
STSCursor
cur
;
STSBuf
*
pTsBuf
;
// timestamp filter list
STSCursor
cur
;
char
*
tagVal
;
// tag value of current data block
struct
SScalarFunctionSupport
*
scalarSup
;
char
*
tagVal
;
// tag value of current data block
struct
SScalarFunctionSupport
*
scalarSup
;
SSDataBlock
*
outputBuf
;
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
SSDataBlock
*
outputBuf
;
struct
SOperatorInfo
*
proot
;
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
struct
SOperatorInfo
*
proot
;
SGroupResInfo
groupResInfo
;
SGroupResInfo
groupResInfo
;
int64_t
currentOffset
;
// dynamic offset value
int64_t
currentOffset
;
// dynamic offset value
STableQueryInfo
*
current
;
STableQueryInfo
*
current
;
SRspResultInfo
resultInfo
;
SRspResultInfo
resultInfo
;
SHashObj
*
pTableRetrieveTsMap
;
SHashObj
*
pTableRetrieveTsMap
;
struct
SUdfInfo
*
pUdfInfo
;
struct
SUdfInfo
*
pUdfInfo
;
}
STaskRuntimeEnv
;
}
STaskRuntimeEnv
;
enum
{
enum
{
OP_IN_EXECUTING
=
1
,
OP_IN_EXECUTING
=
1
,
OP_RES_TO_RETURN
=
2
,
OP_RES_TO_RETURN
=
2
,
OP_EXEC_DONE
=
3
,
OP_EXEC_DONE
=
3
,
};
};
typedef
struct
SOperatorInfo
{
typedef
struct
SOperatorInfo
{
uint8_t
operatorType
;
uint8_t
operatorType
;
bool
blockingOptr
;
// block operator or not
bool
blockingOptr
;
// block operator or not
uint8_t
status
;
// denote if current operator is completed
uint8_t
status
;
// denote if current operator is completed
int32_t
numOfOutput
;
// number of columns of the current operator results
int32_t
numOfOutput
;
// number of columns of the current operator results
char
*
name
;
// name, used to show the query execution plan
char
*
name
;
// name, used to show the query execution plan
void
*
info
;
// extension attribution
void
*
info
;
// extension attribution
SExprInfo
*
pExpr
;
SExprInfo
*
pExpr
;
STaskRuntimeEnv
*
pRuntimeEnv
;
// todo remove it
STaskRuntimeEnv
*
pRuntimeEnv
;
// todo remove it
SExecTaskInfo
*
pTaskInfo
;
SExecTaskInfo
*
pTaskInfo
;
struct
SOperatorInfo
**
pDownstream
;
// downstram pointer list
struct
SOperatorInfo
**
pDownstream
;
// downstram pointer list
int32_t
numOfDownstream
;
// number of downstream. The value is always ONE expect for join operator
int32_t
numOfDownstream
;
// number of downstream. The value is always ONE expect for join operator
__optr_prepare_fn_t
prepareFn
;
__optr_prepare_fn_t
prepareFn
;
__operator_fn_t
exec
;
__operator_fn_t
exec
;
__optr_cleanup_fn_t
cleanupFn
;
__optr_cleanup_fn_t
cleanupFn
;
}
SOperatorInfo
;
}
SOperatorInfo
;
enum
{
QUERY_RESULT_NOT_READY
=
1
,
QUERY_RESULT_READY
=
2
,
};
typedef
struct
{
typedef
struct
{
int32_t
numOfTags
;
int32_t
numOfTags
;
int32_t
numOfCols
;
int32_t
numOfCols
;
SColumnInfo
*
colList
;
SColumnInfo
*
colList
;
}
SQueriedTableInfo
;
}
SQueriedTableInfo
;
typedef
struct
SQInfo
{
typedef
struct
SQInfo
{
void
*
signature
;
void
*
signature
;
uint64_t
qId
;
uint64_t
qId
;
int32_t
code
;
// error code to returned to client
int32_t
code
;
// error code to returned to client
int64_t
owner
;
// if it is in execution
int64_t
owner
;
// if it is in execution
STaskRuntimeEnv
runtimeEnv
;
STaskRuntimeEnv
runtimeEnv
;
STaskAttr
query
;
STaskAttr
query
;
void
*
pBuf
;
// allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
void
*
pBuf
;
// allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
pthread_mutex_t
lock
;
// used to synchronize the rsp/query threads
pthread_mutex_t
lock
;
// used to synchronize the rsp/query threads
tsem_t
ready
;
tsem_t
ready
;
int32_t
dataReady
;
// denote if query result is ready or not
int32_t
dataReady
;
// denote if query result is ready or not
void
*
rspContext
;
// response context
void
*
rspContext
;
// response context
int64_t
startExecTs
;
// start to exec timestamp
int64_t
startExecTs
;
// start to exec timestamp
char
*
sql
;
// query sql string
char
*
sql
;
// query sql string
STaskCostInfo
summary
;
STaskCostInfo
summary
;
}
SQInfo
;
}
SQInfo
;
typedef
struct
STaskParam
{
typedef
struct
STaskParam
{
char
*
sql
;
char
*
sql
;
char
*
tagCond
;
char
*
tagCond
;
char
*
colCond
;
char
*
colCond
;
char
*
tbnameCond
;
char
*
tbnameCond
;
char
*
prevResult
;
char
*
prevResult
;
SArray
*
pTableIdList
;
SArray
*
pTableIdList
;
SSqlExpr
**
pExpr
;
SSqlExpr
**
pExpr
;
SSqlExpr
**
pSecExpr
;
SSqlExpr
**
pSecExpr
;
SExprInfo
*
pExprs
;
SExprInfo
*
pExprs
;
SExprInfo
*
pSecExprs
;
SExprInfo
*
pSecExprs
;
SFilterInfo
*
pFilters
;
SFilterInfo
*
pFilters
;
SColIndex
*
pGroupColIndex
;
SColIndex
*
pGroupColIndex
;
SColumnInfo
*
pTagColumnInfo
;
SColumnInfo
*
pTagColumnInfo
;
SGroupbyExpr
*
pGroupbyExpr
;
SGroupbyExpr
*
pGroupbyExpr
;
int32_t
tableScanOperator
;
int32_t
tableScanOperator
;
SArray
*
pOperator
;
SArray
*
pOperator
;
struct
SUdfInfo
*
pUdfInfo
;
struct
SUdfInfo
*
pUdfInfo
;
}
STaskParam
;
}
STaskParam
;
enum
{
DATA_NOT_READY
=
0x1
,
DATA_READY
=
0x2
,
DATA_EXHAUSTED
=
0x3
,
};
typedef
struct
SSourceDataInfo
{
struct
SExchangeInfo
*
pEx
;
int32_t
index
;
SRetrieveTableRsp
*
pRsp
;
uint64_t
totalRows
;
int32_t
status
;
}
SSourceDataInfo
;
typedef
struct
SExchangeInfo
{
typedef
struct
SExchangeInfo
{
SArray
*
pSources
;
SArray
*
pSources
;
SArray
*
pSourceDataInfo
;
tsem_t
ready
;
tsem_t
ready
;
void
*
pTransporter
;
void
*
pTransporter
;
S
RetrieveTableRsp
*
pRsp
;
S
SDataBlock
*
pResult
;
SSDataBlock
*
pResult
;
bool
seqLoadData
;
// sequential load data or not, false by default
int32_t
current
;
int32_t
current
;
uint64_t
rowsOfCurrentSource
;
uint64_t
totalSize
;
// total load bytes from remote
uint64_t
totalRows
;
// total number of rows
uint64_t
totalSize
;
// total load bytes from remote
uint64_t
totalElapsed
;
// total elapsed time
uint64_t
totalRows
;
// total number of rows
uint64_t
totalElapsed
;
// total elapsed time
}
SExchangeInfo
;
}
SExchangeInfo
;
typedef
struct
STableScanInfo
{
typedef
struct
STableScanInfo
{
void
*
pTsdbReadHandle
;
void
*
pTsdbReadHandle
;
int32_t
numOfBlocks
;
// extract basic running information.
int32_t
numOfBlocks
;
// extract basic running information.
int32_t
numOfSkipped
;
int32_t
numOfSkipped
;
int32_t
numOfBlockStatis
;
int32_t
numOfBlockStatis
;
int64_t
numOfRows
;
int64_t
numOfRows
;
int32_t
order
;
// scan order
int32_t
order
;
// scan order
int32_t
times
;
// repeat counts
int32_t
times
;
// repeat counts
int32_t
current
;
int32_t
current
;
int32_t
reverseTimes
;
// 0 by default
int32_t
reverseTimes
;
// 0 by default
SqlFunctionCtx
*
pCtx
;
// next operator query context
SqlFunctionCtx
*
pCtx
;
// next operator query context
SResultRowInfo
*
pResultRowInfo
;
SResultRowInfo
*
pResultRowInfo
;
int32_t
*
rowCellInfoOffset
;
int32_t
*
rowCellInfoOffset
;
SExprInfo
*
pExpr
;
SExprInfo
*
pExpr
;
SSDataBlock
block
;
SSDataBlock
block
;
int32_t
numOfOutput
;
int32_t
numOfOutput
;
int64_t
elapsedTime
;
int64_t
elapsedTime
;
int32_t
prevGroupId
;
// previous table group id
int32_t
prevGroupId
;
// previous table group id
int32_t
scanFlag
;
// table scan flag to denote if it is a repeat/reverse/main scan
int32_t
scanFlag
;
// table scan flag to denote if it is a repeat/reverse/main scan
}
STableScanInfo
;
}
STableScanInfo
;
typedef
struct
STagScanInfo
{
typedef
struct
STagScanInfo
{
...
@@ -416,32 +428,36 @@ typedef struct STagScanInfo {
...
@@ -416,32 +428,36 @@ typedef struct STagScanInfo {
}
STagScanInfo
;
}
STagScanInfo
;
typedef
struct
SStreamBlockScanInfo
{
typedef
struct
SStreamBlockScanInfo
{
SSDataBlock
*
pRes
;
// result SSDataBlock
SSDataBlock
*
pRes
;
// result SSDataBlock
SColumnInfo
*
pCols
;
// the output column info
SColumnInfo
*
pCols
;
// the output column info
uint64_t
numOfRows
;
// total scanned rows
uint64_t
numOfRows
;
// total scanned rows
uint64_t
numOfExec
;
// execution times
uint64_t
numOfExec
;
// execution times
void
*
readerHandle
;
// stream block reader handle
void
*
readerHandle
;
// stream block reader handle
}
SStreamBlockScanInfo
;
}
SStreamBlockScanInfo
;
typedef
struct
SOptrBasicInfo
{
typedef
struct
SOptrBasicInfo
{
SResultRowInfo
resultRowInfo
;
SResultRowInfo
resultRowInfo
;
int32_t
*
rowCellInfoOffset
;
// offset value for each row result cell info
int32_t
*
rowCellInfoOffset
;
// offset value for each row result cell info
SqlFunctionCtx
*
pCtx
;
SqlFunctionCtx
*
pCtx
;
SSDataBlock
*
pRes
;
SSDataBlock
*
pRes
;
uint32_t
resRowSize
;
int32_t
capacity
;
}
SOptrBasicInfo
;
}
SOptrBasicInfo
;
typedef
struct
SOptrBasicInfo
STableIntervalOperatorInfo
;
typedef
struct
SOptrBasicInfo
STableIntervalOperatorInfo
;
typedef
struct
SAggOperatorInfo
{
typedef
struct
SAggOperatorInfo
{
SOptrBasicInfo
binfo
;
SOptrBasicInfo
binfo
;
uint32_t
seed
;
SDiskbasedBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
SDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
SHashObj
*
pResultRowHashTable
;
// quick locate the window object for each result
SHashObj
*
pResultRowHashTable
;
// quick locate the window object for each result
SHashObj
*
pResultRowListSet
;
// used to check if current ResultRowInfo has ResultRow object or not
SHashObj
*
pResultRowListSet
;
// used to check if current ResultRowInfo has ResultRow object or not
SArray
*
pResultRowArrayList
;
// The array list that contains the Result rows
SArray
*
pResultRowArrayList
;
// The array list that contains the Result rows
char
*
keyBuf
;
// window key buffer
char
*
keyBuf
;
// window key buffer
SResultRowPool
*
pool
;
// The window result objects pool, all the resultRow Objects are allocated and managed by this object.
SResultRowPool
*
pool
;
// The window result objects pool, all the resultRow Objects are allocated and managed by this object.
STableQueryInfo
*
current
;
STableQueryInfo
*
current
;
uint32_t
groupId
;
SGroupResInfo
groupResInfo
;
STableQueryInfo
*
pTableQueryInfo
;
}
SAggOperatorInfo
;
}
SAggOperatorInfo
;
typedef
struct
SProjectOperatorInfo
{
typedef
struct
SProjectOperatorInfo
{
...
@@ -449,52 +465,52 @@ typedef struct SProjectOperatorInfo {
...
@@ -449,52 +465,52 @@ typedef struct SProjectOperatorInfo {
int32_t
bufCapacity
;
int32_t
bufCapacity
;
uint32_t
seed
;
uint32_t
seed
;
SSDataBlock
*
existDataBlock
;
SSDataBlock
*
existDataBlock
;
}
SProjectOperatorInfo
;
}
SProjectOperatorInfo
;
typedef
struct
SLimitOperatorInfo
{
typedef
struct
SLimitOperatorInfo
{
int64_t
limit
;
int64_t
limit
;
int64_t
total
;
int64_t
total
;
}
SLimitOperatorInfo
;
}
SLimitOperatorInfo
;
typedef
struct
SSLimitOperatorInfo
{
typedef
struct
SSLimitOperatorInfo
{
int64_t
groupTotal
;
int64_t
groupTotal
;
int64_t
currentGroupOffset
;
int64_t
currentGroupOffset
;
int64_t
rowsTotal
;
int64_t
rowsTotal
;
int64_t
currentOffset
;
int64_t
currentOffset
;
SLimit
limit
;
SLimit
limit
;
SLimit
slimit
;
SLimit
slimit
;
char
**
prevRow
;
char
**
prevRow
;
SArray
*
orderColumnList
;
SArray
*
orderColumnList
;
bool
hasPrev
;
bool
hasPrev
;
bool
ignoreCurrentGroup
;
bool
ignoreCurrentGroup
;
bool
multigroupResult
;
bool
multigroupResult
;
SSDataBlock
*
pRes
;
// result buffer
SSDataBlock
*
pRes
;
// result buffer
SSDataBlock
*
pPrevBlock
;
SSDataBlock
*
pPrevBlock
;
int64_t
capacity
;
int64_t
capacity
;
int64_t
threshold
;
int64_t
threshold
;
}
SSLimitOperatorInfo
;
}
SSLimitOperatorInfo
;
typedef
struct
SFilterOperatorInfo
{
typedef
struct
SFilterOperatorInfo
{
SSingleColumnFilterInfo
*
pFilterInfo
;
SSingleColumnFilterInfo
*
pFilterInfo
;
int32_t
numOfFilterCols
;
int32_t
numOfFilterCols
;
}
SFilterOperatorInfo
;
}
SFilterOperatorInfo
;
typedef
struct
SFillOperatorInfo
{
typedef
struct
SFillOperatorInfo
{
struct
SFillInfo
*
pFillInfo
;
struct
SFillInfo
*
pFillInfo
;
SSDataBlock
*
pRes
;
SSDataBlock
*
pRes
;
int64_t
totalInputRows
;
int64_t
totalInputRows
;
void
**
p
;
void
**
p
;
SSDataBlock
*
existNewGroupBlock
;
SSDataBlock
*
existNewGroupBlock
;
bool
multigroupResult
;
bool
multigroupResult
;
}
SFillOperatorInfo
;
}
SFillOperatorInfo
;
typedef
struct
SGroupbyOperatorInfo
{
typedef
struct
SGroupbyOperatorInfo
{
SOptrBasicInfo
binfo
;
SOptrBasicInfo
binfo
;
int32_t
colIndex
;
int32_t
colIndex
;
char
*
prevData
;
// previous group by value
char
*
prevData
;
// previous group by value
}
SGroupbyOperatorInfo
;
}
SGroupbyOperatorInfo
;
typedef
struct
SSWindowOperatorInfo
{
typedef
struct
SSWindowOperatorInfo
{
...
@@ -503,16 +519,16 @@ typedef struct SSWindowOperatorInfo {
...
@@ -503,16 +519,16 @@ typedef struct SSWindowOperatorInfo {
TSKEY
prevTs
;
// previous timestamp
TSKEY
prevTs
;
// previous timestamp
int32_t
numOfRows
;
// number of rows
int32_t
numOfRows
;
// number of rows
int32_t
start
;
// start row index
int32_t
start
;
// start row index
bool
reptScan
;
// next round scan
bool
reptScan
;
// next round scan
}
SSWindowOperatorInfo
;
}
SSWindowOperatorInfo
;
typedef
struct
SStateWindowOperatorInfo
{
typedef
struct
SStateWindowOperatorInfo
{
SOptrBasicInfo
binfo
;
SOptrBasicInfo
binfo
;
STimeWindow
curWindow
;
// current time window
STimeWindow
curWindow
;
// current time window
int32_t
numOfRows
;
// number of rows
int32_t
numOfRows
;
// number of rows
int32_t
colIndex
;
// start row index
int32_t
colIndex
;
// start row index
int32_t
start
;
int32_t
start
;
char
*
prevData
;
// previous data
char
*
prevData
;
// previous data
bool
reptScan
;
bool
reptScan
;
}
SStateWindowOperatorInfo
;
}
SStateWindowOperatorInfo
;
...
@@ -520,147 +536,186 @@ typedef struct SDistinctDataInfo {
...
@@ -520,147 +536,186 @@ typedef struct SDistinctDataInfo {
int32_t
index
;
int32_t
index
;
int32_t
type
;
int32_t
type
;
int32_t
bytes
;
int32_t
bytes
;
}
SDistinctDataInfo
;
}
SDistinctDataInfo
;
typedef
struct
SDistinctOperatorInfo
{
typedef
struct
SDistinctOperatorInfo
{
SHashObj
*
pSet
;
SHashObj
*
pSet
;
SSDataBlock
*
pRes
;
SSDataBlock
*
pRes
;
bool
recordNullVal
;
//
has already record the null value, no need to try again
bool
recordNullVal
;
//
has already record the null value, no need to try again
int64_t
threshold
;
int64_t
threshold
;
int64_t
outputCapacity
;
int64_t
outputCapacity
;
int32_t
totalBytes
;
int32_t
totalBytes
;
char
*
buf
;
char
*
buf
;
SArray
*
pDistinctDataInfo
;
SArray
*
pDistinctDataInfo
;
}
SDistinctOperatorInfo
;
}
SDistinctOperatorInfo
;
struct
SGlobalMerger
;
struct
SGlobalMerger
;
typedef
struct
SMultiwayMergeInfo
{
typedef
struct
SMultiwayMergeInfo
{
struct
SGlobalMerger
*
pMerge
;
struct
SGlobalMerger
*
pMerge
;
SOptrBasicInfo
binfo
;
SOptrBasicInfo
binfo
;
int32_t
bufCapacity
;
int32_t
bufCapacity
;
int64_t
seed
;
int64_t
seed
;
char
**
prevRow
;
char
**
prevRow
;
SArray
*
orderColumnList
;
SArray
*
orderColumnList
;
int32_t
resultRowFactor
;
int32_t
resultRowFactor
;
bool
hasGroupColData
;
bool
hasGroupColData
;
char
**
currentGroupColData
;
char
**
currentGroupColData
;
SArray
*
groupColumnList
;
SArray
*
groupColumnList
;
bool
hasDataBlockForNewGroup
;
bool
hasDataBlockForNewGroup
;
SSDataBlock
*
pExistBlock
;
SSDataBlock
*
pExistBlock
;
SArray
*
udfInfo
;
SArray
*
udfInfo
;
bool
hasPrev
;
bool
hasPrev
;
bool
multiGroupResults
;
bool
multiGroupResults
;
}
SMultiwayMergeInfo
;
}
SMultiwayMergeInfo
;
// todo support the disk-based sort
typedef
struct
SMsortComparParam
{
struct
SExternalMemSource
**
pSources
;
int32_t
numOfSources
;
SArray
*
orderInfo
;
// SArray<SBlockOrderInfo>
bool
nullFirst
;
}
SMsortComparParam
;
typedef
struct
SOrderOperatorInfo
{
typedef
struct
SOrderOperatorInfo
{
int32_t
colIndex
;
int32_t
sourceId
;
int32_t
order
;
uint32_t
sortBufSize
;
// max buffer size for in-memory sort
SSDataBlock
*
pDataBlock
;
SSDataBlock
*
pDataBlock
;
bool
hasVarCol
;
// has variable length column, such as binary/varchar/nchar
int32_t
numOfCompleted
;
SDiskbasedBuf
*
pSortInternalBuf
;
SMultiwayMergeTreeInfo
*
pMergeTree
;
SArray
*
pSources
;
// SArray<SExternalMemSource*>
int32_t
bufPageSize
;
int32_t
numOfRowsInRes
;
SMsortComparParam
cmpParam
;
int64_t
startTs
;
// sort start time
uint64_t
sortElapsed
;
// sort elapsed time, time to flush to disk not included.
uint64_t
totalSize
;
// total load bytes from remote
uint64_t
totalRows
;
// total number of rows
uint64_t
totalElapsed
;
// total elapsed time
}
SOrderOperatorInfo
;
}
SOrderOperatorInfo
;
SOperatorInfo
*
createExchangeOperatorInfo
(
const
SArray
*
pSources
,
const
SArray
*
pSchema
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createExchangeOperatorInfo
(
const
SArray
*
pSources
,
const
SArray
*
pSchema
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createTableScanOperatorInfo
(
void
*
pTsdbReadHandle
,
int32_t
order
,
int32_t
numOfOutput
,
SOperatorInfo
*
createDataBlocksOptScanInfo
(
void
*
pTsdbReadHandle
,
int32_t
order
,
int32_t
numOfOutput
,
int32_t
repeatTime
,
int32_t
reverseTime
,
SExecTaskInfo
*
pTaskInfo
);
int32_t
repeatTime
,
int32_t
reverseTime
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbReadHandle
,
STaskRuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createTableSeqScanOperator
Info
(
void
*
pTsdbReadHandle
,
STaskRuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
create
SubmitBlockScanOperatorInfo
(
void
*
pSubmitBlockReadHandle
,
int32_t
numOfOutput
,
SExecTaskInfo
*
pTask
Info
);
SOperatorInfo
*
create
AggregateOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
,
const
STableGroupInfo
*
pTableGroup
Info
);
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
,
const
STableGroupInfo
*
pTableGroupInfo
);
SOperatorInfo
*
create
AggregateOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
create
ProjectOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
SOperatorInfo
*
createProjectOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
int32_t
numOfOutput
);
SOperatorInfo
*
createLimitOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
);
SOperatorInfo
*
createLimitOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
);
SOperatorInfo
*
createTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
int32_t
numOfOutput
);
SOperatorInfo
*
createSWindowOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SOperatorInfo
*
createFillOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
bool
multigroupResult
);
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createGroupbyOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createSWindowOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
int32_t
numOfOutput
);
SOperatorInfo
*
createMultiTableTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createFillOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
SOperatorInfo
*
createAllMultiTableTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
int32_t
numOfOutput
,
bool
multigroupResult
);
SOperatorInfo
*
createGroupbyOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createMultiTableTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAllMultiTableTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTagScanOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTagScanOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createDistinctOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createDistinctOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTableBlockInfoScanOperator
(
void
*
pTsdbReadHandle
,
STaskRuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createTableBlockInfoScanOperator
(
void
*
pTsdbReadHandle
,
STaskRuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createMultiwaySortOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOperatorInfo
*
createMultiwaySortOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
,
void
*
merger
);
int32_t
numOfRows
,
void
*
merger
);
SOperatorInfo
*
createGlobalAggregateOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
param
,
SArray
*
pUdfInfo
,
bool
groupResultMixedUp
);
SOperatorInfo
*
createGlobalAggregateOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SOperatorInfo
*
createStatewindowOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
param
,
SArray
*
pUdfInfo
,
SOperatorInfo
*
createSLimitOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
merger
,
bool
multigroupResult
);
bool
groupResultMixedUp
);
SOperatorInfo
*
createStatewindowOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createSLimitOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
merger
,
bool
multigroupResult
);
SOperatorInfo
*
createFilterOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
SOperatorInfo
*
createFilterOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SColumnInfo
*
pCols
,
int32_t
numOfFilter
);
int32_t
numOfOutput
,
SColumnInfo
*
pCols
,
int32_t
numOfFilter
);
SOperatorInfo
*
createJoinOperatorInfo
(
SOperatorInfo
**
pdownstream
,
int32_t
numOfDownstream
,
SSchema
*
pSchema
,
int32_t
numOfOutput
);
SOperatorInfo
*
createJoinOperatorInfo
(
SOperatorInfo
**
pdownstream
,
int32_t
numOfDownstream
,
SSchema
*
pSchema
,
SOperatorInfo
*
createOrderOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOrder
*
pOrderVal
);
int32_t
numOfOutput
);
SOperatorInfo
*
createOrderOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SArray
*
pOrderVal
);
SOperatorInfo
*
createMergeSortOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOrder
*
pOrderVal
);
//SSDataBlock* doGlobalAggregate(void* param, bool* newgroup);
//
SSDataBlock* doGlobalAggregate(void* param, bool* newgroup);
//SSDataBlock* doMultiwayMergeSort(void* param, bool* newgroup);
//
SSDataBlock* doMultiwayMergeSort(void* param, bool* newgroup);
//SSDataBlock* doSLimit(void* param, bool* newgroup);
//
SSDataBlock* doSLimit(void* param, bool* newgroup);
//int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** pFilterInfo, uint64_t qId);
//
int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** pFilterInfo, uint64_t qId);
void
doSetFilterColumnInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
,
SSDataBlock
*
pBlock
);
void
doSetFilterColumnInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
,
SSDataBlock
*
pBlock
);
bool
doFilterDataBlock
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
,
int32_t
numOfRows
,
int8_t
*
p
);
bool
doFilterDataBlock
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
,
int32_t
numOfRows
,
int8_t
*
p
);
void
doCompactSDataBlock
(
SSDataBlock
*
pBlock
,
int32_t
numOfRows
,
int8_t
*
p
);
void
doCompactSDataBlock
(
SSDataBlock
*
pBlock
,
int32_t
numOfRows
,
int8_t
*
p
);
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
);
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
);
void
*
destroyOutputBuf
(
SSDataBlock
*
pBlock
);
void
*
doDestroyFilterInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
);
void
*
doDestroyFilterInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
);
void
setInputDataBlock
(
SOperatorInfo
*
pOperator
,
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
order
);
void
setInputDataBlock
(
SOperatorInfo
*
pOperator
,
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
order
);
void
finalizeQueryResult
(
SOperatorInfo
*
pOperator
,
SqlFunctionCtx
*
pCtx
,
SResultRowInfo
*
pResultRowInfo
,
int32_t
*
rowCellInfoOffset
);
void
finalizeQueryResult
(
SOperatorInfo
*
pOperator
,
SqlFunctionCtx
*
pCtx
,
SResultRowInfo
*
pResultRowInfo
,
void
updateOutputBuf
(
SOptrBasicInfo
*
pBInfo
,
int32_t
*
bufCapacity
,
int32_t
numOfInputRows
);
int32_t
*
rowCellInfoOffset
);
void
clearOutputBuf
(
SOptrBasicInfo
*
pBInfo
,
int32_t
*
bufCapacity
);
void
updateOutputBuf
(
SOptrBasicInfo
*
pBInfo
,
int32_t
*
bufCapacity
,
int32_t
numOfInputRows
);
void
clearOutputBuf
(
SOptrBasicInfo
*
pBInfo
,
int32_t
*
bufCapacity
);
void
copyTsColoum
(
SSDataBlock
*
pRes
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
);
void
copyTsColoum
(
SSDataBlock
*
pRes
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
);
void
freeParam
(
STaskParam
*
param
);
int32_t
createQueryFunc
(
SQueriedTableInfo
*
pTableInfo
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
SSqlExpr
**
pExprMsg
,
int32_t
createQueryFunc
(
SQueriedTableInfo
*
pTableInfo
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
SColumnInfo
*
pTagCols
,
int32_t
queryType
,
void
*
pMsg
,
struct
SUdfInfo
*
pUdfInfo
);
SSqlExpr
**
pExprMsg
,
SColumnInfo
*
pTagCols
,
int32_t
queryType
,
void
*
pMsg
,
struct
SUdfInfo
*
pUdfInfo
);
int32_t
createIndirectQueryFuncExprFromMsg
(
SQueryTableReq
*
pQueryMsg
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
int32_t
createIndirectQueryFuncExprFromMsg
(
SQueryTableReq
*
pQueryMsg
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
SSqlExpr
**
pExpr
,
SExprInfo
*
prevExpr
,
struct
SUdfInfo
*
pUdfInfo
);
SSqlExpr
**
pExpr
,
SExprInfo
*
prevExpr
,
struct
SUdfInfo
*
pUdfInfo
);
int32_t
createQueryFilter
(
char
*
data
,
uint16_t
len
,
SFilterInfo
**
pFilters
);
int32_t
createQueryFilter
(
char
*
data
,
uint16_t
len
,
SFilterInfo
**
pFilters
);
SGroupbyExpr
*
createGroupbyExprFromMsg
(
SQueryTableReq
*
pQueryMsg
,
SColIndex
*
pColIndex
,
int32_t
*
code
);
SGroupbyExpr
*
createGroupbyExprFromMsg
(
SQueryTableReq
*
pQueryMsg
,
SColIndex
*
pColIndex
,
int32_t
*
code
);
int32_t
initQInfo
(
STsBufInfo
*
pTsBufInfo
,
void
*
tsdb
,
void
*
sourceOptr
,
SQInfo
*
pQInfo
,
STaskParam
*
param
,
char
*
start
,
int32_t
initQInfo
(
STsBufInfo
*
pTsBufInfo
,
void
*
tsdb
,
void
*
sourceOptr
,
SQInfo
*
pQInfo
,
STaskParam
*
param
,
char
*
start
,
int32_t
prevResultLen
,
void
*
merger
);
int32_t
prevResultLen
,
void
*
merger
);
int32_t
createFilterInfo
(
STaskAttr
*
pQueryAttr
,
uint64_t
qId
);
int32_t
createFilterInfo
(
STaskAttr
*
pQueryAttr
,
uint64_t
qId
);
void
freeColumnFilterInfo
(
SColumnFilterInfo
*
pFilter
,
int32_t
numOfFilters
);
void
freeColumnFilterInfo
(
SColumnFilterInfo
*
pFilter
,
int32_t
numOfFilters
);
STableQueryInfo
*
createTableQueryInfo
(
STaskAttr
*
pQueryAttr
,
void
*
pTable
,
bool
groupbyColumn
,
STimeWindow
win
,
void
*
buf
);
STableQueryInfo
*
createTableQueryInfo
(
void
*
buf
,
bool
groupbyColumn
,
STimeWindow
win
);
STableQueryInfo
*
createTmpTableQueryInfo
(
STimeWindow
win
);
STableQueryInfo
*
createTmpTableQueryInfo
(
STimeWindow
win
);
int32_t
buildArithmeticExprFromMsg
(
SExprInfo
*
pArithExprInfo
,
void
*
pQueryMsg
);
int32_t
buildArithmeticExprFromMsg
(
SExprInfo
*
pArithExprInfo
,
void
*
pQueryMsg
);
bool
isTaskKilled
(
SExecTaskInfo
*
pTaskInfo
);
bool
isTaskKilled
(
SExecTaskInfo
*
pTaskInfo
);
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
bool
checkNeedToCompressQueryCol
(
SQInfo
*
pQInfo
);
bool
checkNeedToCompressQueryCol
(
SQInfo
*
pQInfo
);
void
setQueryStatus
(
STaskRuntimeEnv
*
pRuntimeEnv
,
int8_t
status
);
void
setQueryStatus
(
STaskRuntimeEnv
*
pRuntimeEnv
,
int8_t
status
);
bool
onlyQueryTags
(
STaskAttr
*
pQueryAttr
);
bool
onlyQueryTags
(
STaskAttr
*
pQueryAttr
);
//void destroyUdfInfo(struct SUdfInfo* pUdfInfo);
//
void destroyUdfInfo(struct SUdfInfo* pUdfInfo);
int32_t
doDumpQueryResult
(
SQInfo
*
pQInfo
,
char
*
data
,
int8_t
compressed
,
int32_t
*
compLen
);
int32_t
doDumpQueryResult
(
SQInfo
*
pQInfo
,
char
*
data
,
int8_t
compressed
,
int32_t
*
compLen
);
size_t
getResultSize
(
SQInfo
*
pQInfo
,
int64_t
*
numOfRows
);
size_t
getResultSize
(
SQInfo
*
pQInfo
,
int64_t
*
numOfRows
);
void
setTaskKilled
(
SExecTaskInfo
*
pTaskInfo
);
void
setTaskKilled
(
SExecTaskInfo
*
pTaskInfo
);
void
publishOperatorProfEvent
(
SOperatorInfo
*
operatorInfo
,
EQueryProfEventType
eventType
);
void
publishOperatorProfEvent
(
SOperatorInfo
*
operatorInfo
,
EQueryProfEventType
eventType
);
void
publishQueryAbortEvent
(
SExecTaskInfo
*
pTaskInfo
,
int32_t
code
);
void
publishQueryAbortEvent
(
SExecTaskInfo
*
pTaskInfo
,
int32_t
code
);
void
calculateOperatorProfResults
(
SQInfo
*
pQInfo
);
void
calculateOperatorProfResults
(
SQInfo
*
pQInfo
);
void
queryCostStatis
(
SExecTaskInfo
*
pTaskInfo
);
void
queryCostStatis
(
SExecTaskInfo
*
pTaskInfo
);
void
doDestroyTask
(
SExecTaskInfo
*
pTaskInfo
);
void
doDestroyTask
(
SExecTaskInfo
*
pTaskInfo
);
void
freeQueryAttr
(
STaskAttr
*
pQuery
);
void
freeQueryAttr
(
STaskAttr
*
pQuery
);
int32_t
getMaximumIdleDurationSec
();
int32_t
getMaximumIdleDurationSec
();
void
doInvokeUdf
(
struct
SUdfInfo
*
pUdfInfo
,
SqlFunctionCtx
*
pCtx
,
int32_t
idx
,
int32_t
type
);
void
doInvokeUdf
(
struct
SUdfInfo
*
pUdfInfo
,
SqlFunctionCtx
*
pCtx
,
int32_t
idx
,
int32_t
type
);
void
setTaskStatus
(
SExecTaskInfo
*
pTaskInfo
,
int8_t
status
);
void
setTaskStatus
(
SExecTaskInfo
*
pTaskInfo
,
int8_t
status
);
int32_t
createExecTaskInfoImpl
(
SSubplan
*
pPlan
,
SExecTaskInfo
**
pTaskInfo
,
SReadHandle
*
pHandle
,
uint64_t
taskId
);
int32_t
createExecTaskInfoImpl
(
SSubplan
*
pPlan
,
SExecTaskInfo
**
pTaskInfo
,
SReadHandle
*
pHandle
,
uint64_t
taskId
);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_EXECUTORIMPL_H
#endif // TDENGINE_EXECUTORIMPL_H
source/libs/executor/src/executil.c
浏览文件 @
378aaf38
...
@@ -141,9 +141,9 @@ void clearResultRow(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16_
...
@@ -141,9 +141,9 @@ void clearResultRow(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16_
return
;
return
;
}
}
// the result does not put into the SDiskbased
Result
Buf, ignore it.
// the result does not put into the SDiskbasedBuf, ignore it.
if
(
pResultRow
->
pageId
>=
0
)
{
if
(
pResultRow
->
pageId
>=
0
)
{
SFilePage
*
page
=
get
Res
BufPage
(
pRuntimeEnv
->
pResultBuf
,
pResultRow
->
pageId
);
SFilePage
*
page
=
getBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResultRow
->
pageId
);
int16_t
offset
=
0
;
int16_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
pRuntimeEnv
->
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pRuntimeEnv
->
pQueryAttr
->
numOfOutput
;
++
i
)
{
...
@@ -358,7 +358,6 @@ void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo)
...
@@ -358,7 +358,6 @@ void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo)
pGroupResInfo
->
pRows
=
taosArrayFromList
(
pResultInfo
->
pResult
,
pResultInfo
->
size
,
POINTER_BYTES
);
pGroupResInfo
->
pRows
=
taosArrayFromList
(
pResultInfo
->
pResult
,
pResultInfo
->
size
,
POINTER_BYTES
);
pGroupResInfo
->
index
=
0
;
pGroupResInfo
->
index
=
0
;
assert
(
pGroupResInfo
->
index
<=
getNumOfTotalRes
(
pGroupResInfo
));
assert
(
pGroupResInfo
->
index
<=
getNumOfTotalRes
(
pGroupResInfo
));
}
}
...
@@ -533,7 +532,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
...
@@ -533,7 +532,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
*
posList
=
NULL
;
int32_t
*
posList
=
NULL
;
S
Loser
TreeInfo
*
pTree
=
NULL
;
S
MultiwayMerge
TreeInfo
*
pTree
=
NULL
;
STableQueryInfo
**
pTableQueryInfoList
=
NULL
;
STableQueryInfo
**
pTableQueryInfoList
=
NULL
;
size_t
size
=
taosArrayGetSize
(
pTableList
);
size_t
size
=
taosArrayGetSize
(
pTableList
);
...
@@ -566,7 +565,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
...
@@ -566,7 +565,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
SCompSupporter
cs
=
{
pTableQueryInfoList
,
posList
,
pRuntimeEnv
->
pQueryAttr
->
order
.
order
};
SCompSupporter
cs
=
{
pTableQueryInfoList
,
posList
,
pRuntimeEnv
->
pQueryAttr
->
order
.
order
};
int32_t
ret
=
t
Loser
TreeCreate
(
&
pTree
,
numOfTables
,
&
cs
,
tableResultComparFn
);
int32_t
ret
=
t
Merge
TreeCreate
(
&
pTree
,
numOfTables
,
&
cs
,
tableResultComparFn
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
goto
_end
;
goto
_end
;
...
@@ -576,7 +575,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
...
@@ -576,7 +575,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
int64_t
startt
=
taosGetTimestampMs
();
int64_t
startt
=
taosGetTimestampMs
();
while
(
1
)
{
while
(
1
)
{
int32_t
tableIndex
=
pTree
->
pNode
[
0
].
index
;
int32_t
tableIndex
=
tMergeTreeGetChosenIndex
(
pTree
)
;
SResultRowInfo
*
pWindowResInfo
=
&
pTableQueryInfoList
[
tableIndex
]
->
resInfo
;
SResultRowInfo
*
pWindowResInfo
=
&
pTableQueryInfoList
[
tableIndex
]
->
resInfo
;
SResultRow
*
pWindowRes
=
getResultRow
(
pWindowResInfo
,
cs
.
rowIndex
[
tableIndex
]);
SResultRow
*
pWindowRes
=
getResultRow
(
pWindowResInfo
,
cs
.
rowIndex
[
tableIndex
]);
...
@@ -612,7 +611,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
...
@@ -612,7 +611,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
}
}
}
}
t
LoserTreeAdjust
(
pTree
,
tableIndex
+
pTree
->
numOfEntries
);
t
MergeTreeAdjust
(
pTree
,
tMergeTreeGetAdjustIndex
(
pTree
)
);
}
}
int64_t
endt
=
taosGetTimestampMs
();
int64_t
endt
=
taosGetTimestampMs
();
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
378aaf38
...
@@ -12,12 +12,13 @@
...
@@ -12,12 +12,13 @@
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "parser.h"
#include <tep.h>
#include "tq.h"
#include "exception.h"
#include "exception.h"
#include "os.h"
#include "os.h"
#include "parser.h"
#include "tglobal.h"
#include "tglobal.h"
#include "tmsg.h"
#include "tmsg.h"
#include "tq.h"
#include "ttime.h"
#include "ttime.h"
#include "executorimpl.h"
#include "executorimpl.h"
...
@@ -214,7 +215,7 @@ static void doSetOperatorCompleted(SOperatorInfo* pOperator) {
...
@@ -214,7 +215,7 @@ static void doSetOperatorCompleted(SOperatorInfo* pOperator) {
}
}
}
}
static
int32_t
doCopyToSDataBlock
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
);
static
int32_t
doCopyToSDataBlock
(
S
DiskbasedBuf
*
pBuf
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
,
int32_t
rowCapacity
);
static
int32_t
getGroupbyColumnIndex
(
SGroupbyExpr
*
pGroupbyExpr
,
SSDataBlock
*
pDataBlock
);
static
int32_t
getGroupbyColumnIndex
(
SGroupbyExpr
*
pGroupbyExpr
,
SSDataBlock
*
pDataBlock
);
static
int32_t
setGroupResultOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binf
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
);
static
int32_t
setGroupResultOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binf
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
);
...
@@ -225,12 +226,10 @@ static void setResultBufSize(STaskAttr* pQueryAttr, SRspResultInfo* pResultInfo)
...
@@ -225,12 +226,10 @@ static void setResultBufSize(STaskAttr* pQueryAttr, SRspResultInfo* pResultInfo)
static
void
setCtxTagForJoin
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SqlFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
void
*
pTable
);
static
void
setCtxTagForJoin
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SqlFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
void
*
pTable
);
static
void
setParamForStableStddev
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
);
static
void
setParamForStableStddev
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
);
static
void
setParamForStableStddevByColData
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
,
char
*
val
,
int16_t
bytes
);
static
void
setParamForStableStddevByColData
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
,
char
*
val
,
int16_t
bytes
);
static
void
doSetTableGroupOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
static
void
doSetTableGroupOutputBuf
(
SAggOperatorInfo
*
pAggInfo
,
int32_t
numOfOutput
,
int32_t
tableGroupId
,
SExecTaskInfo
*
pTaskInfo
);
SqlFunctionCtx
*
pCtx
,
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
tableGroupId
);
SArray
*
getOrderCheckColumns
(
STaskAttr
*
pQuery
);
SArray
*
getOrderCheckColumns
(
STaskAttr
*
pQuery
);
typedef
struct
SRowCompSupporter
{
typedef
struct
SRowCompSupporter
{
STaskRuntimeEnv
*
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
;
int16_t
dataOffset
;
int16_t
dataOffset
;
...
@@ -244,8 +243,8 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
...
@@ -244,8 +243,8 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
SRowCompSupporter
*
supporter
=
(
SRowCompSupporter
*
)
userData
;
SRowCompSupporter
*
supporter
=
(
SRowCompSupporter
*
)
userData
;
STaskRuntimeEnv
*
pRuntimeEnv
=
supporter
->
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
=
supporter
->
pRuntimeEnv
;
SFilePage
*
page1
=
get
Res
BufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow1
->
pageId
);
SFilePage
*
page1
=
getBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow1
->
pageId
);
SFilePage
*
page2
=
get
Res
BufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow2
->
pageId
);
SFilePage
*
page2
=
getBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow2
->
pageId
);
int16_t
offset
=
supporter
->
dataOffset
;
int16_t
offset
=
supporter
->
dataOffset
;
char
*
in1
=
getPosInResultPage
(
pRuntimeEnv
->
pQueryAttr
,
page1
,
pRow1
->
offset
,
offset
);
char
*
in1
=
getPosInResultPage
(
pRuntimeEnv
->
pQueryAttr
,
page1
,
pRow1
->
offset
,
offset
);
...
@@ -337,23 +336,6 @@ SSDataBlock* createOutputBuf_rv(SArray* pExprInfo, int32_t numOfRows) {
...
@@ -337,23 +336,6 @@ SSDataBlock* createOutputBuf_rv(SArray* pExprInfo, int32_t numOfRows) {
return
res
;
return
res
;
}
}
void
*
destroyOutputBuf
(
SSDataBlock
*
pBlock
)
{
if
(
pBlock
==
NULL
)
{
return
NULL
;
}
int32_t
numOfOutput
=
pBlock
->
info
.
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
tfree
(
pColInfoData
->
pData
);
}
taosArrayDestroy
(
pBlock
->
pDataBlock
);
tfree
(
pBlock
->
pBlockAgg
);
tfree
(
pBlock
);
return
NULL
;
}
static
bool
isSelectivityWithTagsQuery
(
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
static
bool
isSelectivityWithTagsQuery
(
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
return
true
;
return
true
;
// bool hasTags = false;
// bool hasTags = false;
...
@@ -709,7 +691,7 @@ static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo * pResultRowInfo, i
...
@@ -709,7 +691,7 @@ static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo * pResultRowInfo, i
}
}
// a new buffer page for each table. Needs to opt this design
// a new buffer page for each table. Needs to opt this design
static
int32_t
addNewWindowResultBuf
(
SResultRow
*
pWindowRes
,
SDiskbased
Result
Buf
*
pResultBuf
,
int32_t
tid
,
uint32_t
size
)
{
static
int32_t
addNewWindowResultBuf
(
SResultRow
*
pWindowRes
,
SDiskbasedBuf
*
pResultBuf
,
int32_t
tid
,
uint32_t
size
)
{
if
(
pWindowRes
->
pageId
!=
-
1
)
{
if
(
pWindowRes
->
pageId
!=
-
1
)
{
return
0
;
return
0
;
}
}
...
@@ -724,12 +706,12 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
...
@@ -724,12 +706,12 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
pData
=
getNewDataBuf
(
pResultBuf
,
tid
,
&
pageId
);
pData
=
getNewDataBuf
(
pResultBuf
,
tid
,
&
pageId
);
}
else
{
}
else
{
SPageInfo
*
pi
=
getLastPageInfo
(
list
);
SPageInfo
*
pi
=
getLastPageInfo
(
list
);
pData
=
get
ResBufPage
(
pResultBuf
,
pi
->
pageId
);
pData
=
get
BufPage
(
pResultBuf
,
getPageId
(
pi
)
);
pageId
=
pi
->
pageId
;
pageId
=
getPageId
(
pi
)
;
if
(
pData
->
num
+
size
>
pResultBuf
->
pageSize
)
{
if
(
pData
->
num
+
size
>
getBufPageSize
(
pResultBuf
)
)
{
// release current page first, and prepare the next one
// release current page first, and prepare the next one
release
Res
BufPageInfo
(
pResultBuf
,
pi
);
releaseBufPageInfo
(
pResultBuf
,
pi
);
pData
=
getNewDataBuf
(
pResultBuf
,
tid
,
&
pageId
);
pData
=
getNewDataBuf
(
pResultBuf
,
tid
,
&
pageId
);
if
(
pData
!=
NULL
)
{
if
(
pData
!=
NULL
)
{
assert
(
pData
->
num
==
0
);
// number of elements must be 0 for new allocated buffer
assert
(
pData
->
num
==
0
);
// number of elements must be 0 for new allocated buffer
...
@@ -764,7 +746,7 @@ static int32_t setResultOutputBufByKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowI
...
@@ -764,7 +746,7 @@ static int32_t setResultOutputBufByKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowI
bool
masterscan
,
SResultRow
**
pResult
,
int64_t
tableGroupId
,
SqlFunctionCtx
*
pCtx
,
bool
masterscan
,
SResultRow
**
pResult
,
int64_t
tableGroupId
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
)
{
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
)
{
assert
(
win
->
skey
<=
win
->
ekey
);
assert
(
win
->
skey
<=
win
->
ekey
);
SDiskbased
Result
Buf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SDiskbasedBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SResultRow
*
pResultRow
=
doSetResultOutBufByKey
(
pRuntimeEnv
,
pResultRowInfo
,
tid
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
tableGroupId
);
SResultRow
*
pResultRow
=
doSetResultOutBufByKey
(
pRuntimeEnv
,
pResultRowInfo
,
tid
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
tableGroupId
);
if
(
pResultRow
==
NULL
)
{
if
(
pResultRow
==
NULL
)
{
...
@@ -1771,7 +1753,7 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) {
...
@@ -1771,7 +1753,7 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) {
}
}
static
int32_t
setGroupResultOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binfo
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
)
{
static
int32_t
setGroupResultOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binfo
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
)
{
SDiskbased
Result
Buf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SDiskbasedBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
int32_t
*
rowCellInfoOffset
=
binfo
->
rowCellInfoOffset
;
int32_t
*
rowCellInfoOffset
=
binfo
->
rowCellInfoOffset
;
SResultRowInfo
*
pResultRowInfo
=
&
binfo
->
resultRowInfo
;
SResultRowInfo
*
pResultRowInfo
=
&
binfo
->
resultRowInfo
;
...
@@ -2024,7 +2006,7 @@ static SqlFunctionCtx* createSqlFunctionCtx(STaskRuntimeEnv* pRuntimeEnv, SExprI
...
@@ -2024,7 +2006,7 @@ static SqlFunctionCtx* createSqlFunctionCtx(STaskRuntimeEnv* pRuntimeEnv, SExprI
return
pFuncCtx
;
return
pFuncCtx
;
}
}
static
SqlFunctionCtx
*
createSqlFunctionCtx_rv
(
SArray
*
pExprInfo
,
int32_t
**
rowCellInfoOffset
)
{
static
SqlFunctionCtx
*
createSqlFunctionCtx_rv
(
SArray
*
pExprInfo
,
int32_t
**
rowCellInfoOffset
,
uint32_t
*
pRowSize
)
{
size_t
numOfOutput
=
taosArrayGetSize
(
pExprInfo
);
size_t
numOfOutput
=
taosArrayGetSize
(
pExprInfo
);
SqlFunctionCtx
*
pFuncCtx
=
(
SqlFunctionCtx
*
)
calloc
(
numOfOutput
,
sizeof
(
SqlFunctionCtx
));
SqlFunctionCtx
*
pFuncCtx
=
(
SqlFunctionCtx
*
)
calloc
(
numOfOutput
,
sizeof
(
SqlFunctionCtx
));
...
@@ -2122,6 +2104,7 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SArray* pExprInfo, int32_t** rowC
...
@@ -2122,6 +2104,7 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SArray* pExprInfo, int32_t** rowC
for
(
int32_t
i
=
1
;
i
<
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
numOfOutput
;
++
i
)
{
SExprInfo
*
pExpr
=
taosArrayGetP
(
pExprInfo
,
i
-
1
);
SExprInfo
*
pExpr
=
taosArrayGetP
(
pExprInfo
,
i
-
1
);
(
*
rowCellInfoOffset
)[
i
]
=
(
int32_t
)((
*
rowCellInfoOffset
)[
i
-
1
]
+
sizeof
(
SResultRowEntryInfo
)
+
pExpr
->
base
.
interBytes
);
(
*
rowCellInfoOffset
)[
i
]
=
(
int32_t
)((
*
rowCellInfoOffset
)[
i
-
1
]
+
sizeof
(
SResultRowEntryInfo
)
+
pExpr
->
base
.
interBytes
);
*
pRowSize
+=
pExpr
->
base
.
resSchema
.
bytes
;
}
}
setCtxTagColumnInfo
(
pFuncCtx
,
numOfOutput
);
setCtxTagColumnInfo
(
pFuncCtx
,
numOfOutput
);
...
@@ -2188,174 +2171,6 @@ static int32_t setupQueryRuntimeEnv(STaskRuntimeEnv *pRuntimeEnv, int32_t numOfT
...
@@ -2188,174 +2171,6 @@ static int32_t setupQueryRuntimeEnv(STaskRuntimeEnv *pRuntimeEnv, int32_t numOfT
// group by normal column, sliding window query, interval query are handled by interval query processor
// group by normal column, sliding window query, interval query are handled by interval query processor
// interval (down sampling operation)
// interval (down sampling operation)
int32_t
numOfOperator
=
(
int32_t
)
taosArrayGetSize
(
pOperator
);
for
(
int32_t
i
=
0
;
i
<
numOfOperator
;
++
i
)
{
int32_t
*
op
=
taosArrayGet
(
pOperator
,
i
);
switch
(
*
op
)
{
// case OP_TagScan: {
// pRuntimeEnv->proot = createTagScanOperatorInfo(pRuntimeEnv, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// break;
// }
// case OP_MultiTableTimeInterval: {
// pRuntimeEnv->proot =
// createMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// break;
// }
// case OP_AllMultiTableTimeInterval: {
// pRuntimeEnv->proot =
// createAllMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// break;
// }
// case OP_TimeWindow: {
// pRuntimeEnv->proot =
// createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->downstream[0]->operatorType;
// if (opType != OP_DummyInput && opType != OP_Join) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// }
// break;
// }
// case OP_AllTimeWindow: {
// pRuntimeEnv->proot =
// createAllTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->downstream[0]->operatorType;
// if (opType != OP_DummyInput && opType != OP_Join) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// }
// break;
// }
// case OP_Groupby: {
// pRuntimeEnv->proot =
// createGroupbyOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
//
// int32_t opType = pRuntimeEnv->proot->downstream[0]->operatorType;
// if (opType != OP_DummyInput) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// }
// break;
// }
// case OP_SessionWindow: {
// pRuntimeEnv->proot =
// createSWindowOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->downstream[0]->operatorType;
// if (opType != OP_DummyInput) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// }
// break;
// }
// case OP_MultiTableAggregate: {
// pRuntimeEnv->proot =
// createMultiTableAggOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// break;
// }
// case OP_Aggregate: {
// pRuntimeEnv->proot =
// createAggregateOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
//
// int32_t opType = pRuntimeEnv->proot->downstream[0]->operatorType;
// if (opType != OP_DummyInput && opType != OP_Join) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// }
// break;
// }
//
// case OP_Project: { // TODO refactor to remove arith operator.
// SOperatorInfo* prev = pRuntimeEnv->proot;
// if (i == 0) {
// pRuntimeEnv->proot = createProjectOperatorInfo(pRuntimeEnv, prev, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// if (pRuntimeEnv->proot != NULL && prev->operatorType != OP_DummyInput && prev->operatorType != OP_Join) { // TODO refactor
// setTableScanFilterOperatorInfo(prev->info, pRuntimeEnv->proot);
// }
// } else {
// prev = pRuntimeEnv->proot;
// assert(pQueryAttr->pExpr2 != NULL);
// pRuntimeEnv->proot = createProjectOperatorInfo(pRuntimeEnv, prev, pQueryAttr->pExpr2, pQueryAttr->numOfExpr2);
// }
// break;
// }
//
// case OP_StateWindow: {
// pRuntimeEnv->proot = createStatewindowOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->downstream[0]->operatorType;
// if (opType != OP_DummyInput) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->downstream[0]->info, pRuntimeEnv->proot);
// }
// break;
// }
//
// case OP_Limit: {
// pRuntimeEnv->proot = createLimitOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot);
// break;
// }
//
// case OP_Filter: { // todo refactor
// int32_t numOfFilterCols = 0;
// if (pQueryAttr->stableQuery) {
// SColumnInfo* pColInfo =
// extractColumnFilterInfo(pQueryAttr->pExpr3, pQueryAttr->numOfExpr3, &numOfFilterCols);
// pRuntimeEnv->proot = createFilterOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr3,
// pQueryAttr->numOfExpr3, pColInfo, numOfFilterCols);
// freeColumnInfo(pColInfo, pQueryAttr->numOfExpr3);
// } else {
// SColumnInfo* pColInfo =
// extractColumnFilterInfo(pQueryAttr->pExpr1, pQueryAttr->numOfOutput, &numOfFilterCols);
// pRuntimeEnv->proot = createFilterOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1,
// pQueryAttr->numOfOutput, pColInfo, numOfFilterCols);
// freeColumnInfo(pColInfo, pQueryAttr->numOfOutput);
// }
//
// break;
// }
//
// case OP_Fill: {
// SOperatorInfo* pInfo = pRuntimeEnv->proot;
// pRuntimeEnv->proot = createFillOperatorInfo(pRuntimeEnv, pInfo, pInfo->pExpr, pInfo->numOfOutput, pQueryAttr->multigroupResult);
// break;
// }
//
// case OP_MultiwayMergeSort: {
// pRuntimeEnv->proot = createMultiwaySortOperatorInfo(pRuntimeEnv, pQueryAttr->pExpr1, pQueryAttr->numOfOutput, 4096, merger);
// break;
// }
//
// case OP_GlobalAggregate: { // If fill operator exists, the result rows of different group can not be in the same SSDataBlock.
// bool multigroupResult = pQueryAttr->multigroupResult;
// if (pQueryAttr->multigroupResult) {
// multigroupResult = (pQueryAttr->fillType == TSDB_FILL_NONE);
// }
//
// pRuntimeEnv->proot = createGlobalAggregateOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr3,
// pQueryAttr->numOfExpr3, merger, pQueryAttr->pUdfInfo, multigroupResult);
// break;
// }
//
// case OP_SLimit: {
// int32_t num = pRuntimeEnv->proot->numOfOutput;
// SExprInfo* pExpr = pRuntimeEnv->proot->pExpr;
// pRuntimeEnv->proot = createSLimitOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pExpr, num, merger, pQueryAttr->multigroupResult);
// break;
// }
//
// case OP_Distinct: {
// pRuntimeEnv->proot = createDistinctOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// break;
// }
//
// case OP_Order: {
// pRuntimeEnv->proot = createOrderOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput, &pQueryAttr->order);
// break;
// }
default:
{
assert
(
0
);
}
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_clean:
_clean:
...
@@ -2964,7 +2779,7 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo
...
@@ -2964,7 +2779,7 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo
int8_t
*
p
=
calloc
(
numOfRows
,
sizeof
(
int8_t
));
int8_t
*
p
=
calloc
(
numOfRows
,
sizeof
(
int8_t
));
bool
all
=
true
;
bool
all
=
true
;
#if 0
if (pRuntimeEnv->pTsBuf != NULL) {
if (pRuntimeEnv->pTsBuf != NULL) {
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0);
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0);
...
@@ -2992,6 +2807,7 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo
...
@@ -2992,6 +2807,7 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo
} else {
} else {
all = doFilterDataBlock(pFilterInfo, numOfFilterCols, numOfRows, p);
all = doFilterDataBlock(pFilterInfo, numOfFilterCols, numOfRows, p);
}
}
#endif
if
(
!
all
)
{
if
(
!
all
)
{
doCompactSDataBlock
(
pBlock
,
numOfRows
,
p
);
doCompactSDataBlock
(
pBlock
,
numOfRows
,
p
);
...
@@ -3030,7 +2846,7 @@ void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock,
...
@@ -3030,7 +2846,7 @@ void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock,
}
}
// save the cursor status
// save the cursor status
pRuntimeEnv
->
current
->
cur
=
tsBufGetCursor
(
pRuntimeEnv
->
pTsBuf
);
//
pRuntimeEnv->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf);
}
else
{
}
else
{
// all = filterExecute(pRuntimeEnv->pQueryAttr->pFilters, numOfRows, &p, pBlock->pBlockAgg, pRuntimeEnv->pQueryAttr->numOfCols);
// all = filterExecute(pRuntimeEnv->pQueryAttr->pFilters, numOfRows, &p, pBlock->pBlockAgg, pRuntimeEnv->pQueryAttr->numOfCols);
}
}
...
@@ -3434,8 +3250,7 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SqlFunctionCtx* pCt
...
@@ -3434,8 +3250,7 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SqlFunctionCtx* pCt
}
}
}
}
void
copyToSDataBlock
(
STaskRuntimeEnv
*
pRuntimeEnv
,
int32_t
threshold
,
SSDataBlock
*
pBlock
,
int32_t
*
offset
)
{
void
copyToSDataBlock
(
SSDataBlock
*
pBlock
,
int32_t
*
offset
,
SGroupResInfo
*
pGroupResInfo
,
SDiskbasedBuf
*
pResBuf
)
{
SGroupResInfo
*
pGroupResInfo
=
&
pRuntimeEnv
->
groupResInfo
;
pBlock
->
info
.
rows
=
0
;
pBlock
->
info
.
rows
=
0
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
@@ -3443,12 +3258,12 @@ void copyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, int32_t threshold, SSDataBlo
...
@@ -3443,12 +3258,12 @@ void copyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, int32_t threshold, SSDataBlo
// all results in current group have been returned to client, try next group
// all results in current group have been returned to client, try next group
if
((
pGroupResInfo
->
pRows
==
NULL
)
||
taosArrayGetSize
(
pGroupResInfo
->
pRows
)
==
0
)
{
if
((
pGroupResInfo
->
pRows
==
NULL
)
||
taosArrayGetSize
(
pGroupResInfo
->
pRows
)
==
0
)
{
assert
(
pGroupResInfo
->
index
==
0
);
assert
(
pGroupResInfo
->
index
==
0
);
if
((
code
=
mergeIntoGroupResult
(
&
pRuntimeEnv
->
g
roupResInfo
,
pRuntimeEnv
,
offset
))
!=
TSDB_CODE_SUCCESS
)
{
// if ((code = mergeIntoGroupResult(&pG
roupResInfo, pRuntimeEnv, offset)) != TSDB_CODE_SUCCESS) {
return
;
return
;
}
//
}
}
}
doCopyToSDataBlock
(
pRuntimeEnv
,
pGroupResInfo
,
TSDB_ORDER_ASC
,
pBlock
);
// doCopyToSDataBlock(pResBuf, pGroupResInfo, TSDB_ORDER_ASC, pBlock,
);
// current data are all dumped to result buffer, clear it
// current data are all dumped to result buffer, clear it
if
(
!
hasRemainDataInCurrentGroup
(
pGroupResInfo
))
{
if
(
!
hasRemainDataInCurrentGroup
(
pGroupResInfo
))
{
...
@@ -3459,9 +3274,9 @@ void copyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, int32_t threshold, SSDataBlo
...
@@ -3459,9 +3274,9 @@ void copyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, int32_t threshold, SSDataBlo
}
}
// enough results in data buffer, return
// enough results in data buffer, return
if
(
pBlock
->
info
.
rows
>=
threshold
)
{
//
if (pBlock->info.rows >= threshold) {
break
;
//
break;
}
//
}
}
}
}
}
...
@@ -3470,11 +3285,11 @@ static void updateTableQueryInfoForReverseScan(STableQueryInfo *pTableQueryInfo)
...
@@ -3470,11 +3285,11 @@ static void updateTableQueryInfoForReverseScan(STableQueryInfo *pTableQueryInfo)
return
;
return
;
}
}
TSWAP
(
pTableQueryInfo
->
win
.
skey
,
pTableQueryInfo
->
win
.
ekey
,
TSKEY
);
//
TSWAP(pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey, TSKEY);
pTableQueryInfo
->
lastKey
=
pTableQueryInfo
->
win
.
skey
;
//
pTableQueryInfo->lastKey = pTableQueryInfo->win.skey;
SWITCH_ORDER
(
pTableQueryInfo
->
cur
.
order
);
//
SWITCH_ORDER(pTableQueryInfo->cur.order);
pTableQueryInfo
->
cur
.
vgroupIndex
=
-
1
;
//
pTableQueryInfo->cur.vgroupIndex = -1;
// set the index to be the end slot of result rows array
// set the index to be the end slot of result rows array
SResultRowInfo
*
pResultRowInfo
=
&
pTableQueryInfo
->
resInfo
;
SResultRowInfo
*
pResultRowInfo
=
&
pTableQueryInfo
->
resInfo
;
...
@@ -3565,7 +3380,7 @@ void setDefaultOutputBuf(STaskRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, in
...
@@ -3565,7 +3380,7 @@ void setDefaultOutputBuf(STaskRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, in
initCtxOutputBuffer
(
pCtx
,
pDataBlock
->
info
.
numOfCols
);
initCtxOutputBuffer
(
pCtx
,
pDataBlock
->
info
.
numOfCols
);
}
}
void
setDefaultOutputBuf_rv
(
SAggOperatorInfo
*
pAggInfo
,
int
64_t
uid
,
int
32_t
stage
,
SExecTaskInfo
*
pTaskInfo
)
{
void
setDefaultOutputBuf_rv
(
SAggOperatorInfo
*
pAggInfo
,
int32_t
stage
,
SExecTaskInfo
*
pTaskInfo
)
{
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
SqlFunctionCtx
*
pCtx
=
pInfo
->
pCtx
;
SqlFunctionCtx
*
pCtx
=
pInfo
->
pCtx
;
...
@@ -3574,8 +3389,10 @@ void setDefaultOutputBuf_rv(SAggOperatorInfo* pAggInfo, int64_t uid, int32_t sta
...
@@ -3574,8 +3389,10 @@ void setDefaultOutputBuf_rv(SAggOperatorInfo* pAggInfo, int64_t uid, int32_t sta
SResultRowInfo
*
pResultRowInfo
=
&
pInfo
->
resultRowInfo
;
SResultRowInfo
*
pResultRowInfo
=
&
pInfo
->
resultRowInfo
;
int64_t
tid
=
0
;
int64_t
tid
=
0
;
int64_t
groupId
=
0
;
pAggInfo
->
keyBuf
=
realloc
(
pAggInfo
->
keyBuf
,
sizeof
(
tid
)
+
sizeof
(
int64_t
)
+
POINTER_BYTES
);
pAggInfo
->
keyBuf
=
realloc
(
pAggInfo
->
keyBuf
,
sizeof
(
tid
)
+
sizeof
(
int64_t
)
+
POINTER_BYTES
);
SResultRow
*
pRow
=
doSetResultOutBufByKey_rv
(
pResultRowInfo
,
tid
,
(
char
*
)
&
tid
,
sizeof
(
tid
),
true
,
ui
d
,
pTaskInfo
,
false
,
pAggInfo
);
SResultRow
*
pRow
=
doSetResultOutBufByKey_rv
(
pResultRowInfo
,
tid
,
(
char
*
)
&
tid
,
sizeof
(
tid
),
true
,
groupI
d
,
pTaskInfo
,
false
,
pAggInfo
);
for
(
int32_t
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
pData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
SColumnInfoData
*
pData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
...
@@ -3781,24 +3598,19 @@ static bool hasMainOutput(STaskAttr *pQueryAttr) {
...
@@ -3781,24 +3598,19 @@ static bool hasMainOutput(STaskAttr *pQueryAttr) {
return
false
;
return
false
;
}
}
STableQueryInfo
*
createTableQueryInfo
(
STaskAttr
*
pQueryAttr
,
void
*
pTable
,
bool
groupbyColumn
,
STimeWindow
win
,
void
*
buf
)
{
STableQueryInfo
*
createTableQueryInfo
(
void
*
buf
,
bool
groupbyColumn
,
STimeWindow
win
)
{
STableQueryInfo
*
pTableQueryInfo
=
buf
;
STableQueryInfo
*
pTableQueryInfo
=
buf
;
pTableQueryInfo
->
win
=
win
;
pTableQueryInfo
->
lastKey
=
win
.
skey
;
pTableQueryInfo
->
lastKey
=
win
.
skey
;
pTableQueryInfo
->
pTable
=
pTable
;
pTableQueryInfo
->
cur
.
vgroupIndex
=
-
1
;
// set more initial size of interval/groupby query
// set more initial size of interval/groupby query
if
(
QUERY_IS_INTERVAL_QUERY
(
pQueryAttr
)
||
groupbyColumn
)
{
// if (/*QUERY_IS_INTERVAL_QUERY(pQueryAttr) || */
groupbyColumn) {
int32_t
initialSize
=
128
;
int32_t
initialSize
=
128
;
int32_t
code
=
initResultRowInfo
(
&
pTableQueryInfo
->
resInfo
,
initialSize
,
TSDB_DATA_TYPE_INT
);
int32_t
code
=
initResultRowInfo
(
&
pTableQueryInfo
->
resInfo
,
initialSize
,
TSDB_DATA_TYPE_INT
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
return
NULL
;
}
}
}
else
{
// in other aggregate query, do not initialize the windowResInfo
//
} else { // in other aggregate query, do not initialize the windowResInfo
}
//
}
return
pTableQueryInfo
;
return
pTableQueryInfo
;
}
}
...
@@ -3806,12 +3618,9 @@ STableQueryInfo *createTableQueryInfo(STaskAttr* pQueryAttr, void* pTable, bool
...
@@ -3806,12 +3618,9 @@ STableQueryInfo *createTableQueryInfo(STaskAttr* pQueryAttr, void* pTable, bool
STableQueryInfo
*
createTmpTableQueryInfo
(
STimeWindow
win
)
{
STableQueryInfo
*
createTmpTableQueryInfo
(
STimeWindow
win
)
{
STableQueryInfo
*
pTableQueryInfo
=
calloc
(
1
,
sizeof
(
STableQueryInfo
));
STableQueryInfo
*
pTableQueryInfo
=
calloc
(
1
,
sizeof
(
STableQueryInfo
));
pTableQueryInfo
->
win
=
win
;
//
pTableQueryInfo->win = win;
pTableQueryInfo
->
lastKey
=
win
.
skey
;
pTableQueryInfo
->
lastKey
=
win
.
skey
;
pTableQueryInfo
->
pTable
=
NULL
;
pTableQueryInfo
->
cur
.
vgroupIndex
=
-
1
;
// set more initial size of interval/groupby query
// set more initial size of interval/groupby query
int32_t
initialSize
=
16
;
int32_t
initialSize
=
16
;
int32_t
code
=
initResultRowInfo
(
&
pTableQueryInfo
->
resInfo
,
initialSize
,
TSDB_DATA_TYPE_INT
);
int32_t
code
=
initResultRowInfo
(
&
pTableQueryInfo
->
resInfo
,
initialSize
,
TSDB_DATA_TYPE_INT
);
...
@@ -3828,14 +3637,14 @@ void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo) {
...
@@ -3828,14 +3637,14 @@ void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo) {
return
;
return
;
}
}
taosVariantDestroy
(
&
pTableQueryInfo
->
tag
);
//
taosVariantDestroy(&pTableQueryInfo->tag);
cleanupResultRowInfo
(
&
pTableQueryInfo
->
resInfo
);
cleanupResultRowInfo
(
&
pTableQueryInfo
->
resInfo
);
}
}
void
setResultRowOutputBufInitCtx
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SqlFunctionCtx
*
pCtx
,
void
setResultRowOutputBufInitCtx
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
)
{
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
)
{
// Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group
// Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group
SFilePage
*
bufPage
=
get
Res
BufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
SFilePage
*
bufPage
=
getBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
int32_t
offset
=
0
;
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
...
@@ -3865,14 +3674,49 @@ void setResultRowOutputBufInitCtx(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pRes
...
@@ -3865,14 +3674,49 @@ void setResultRowOutputBufInitCtx(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pRes
}
}
}
}
void
doSetTableGroupOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SqlFunctionCtx
*
pCtx
,
void
setResultRowOutputBufInitCtx_rv
(
SDiskbasedBuf
*
pBuf
,
SResultRow
*
pResult
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
)
{
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
tableGroupId
)
{
// Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group
SFilePage
*
bufPage
=
getBufPage
(
pBuf
,
pResult
->
pageId
);
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
pCtx
[
i
].
resultInfo
=
getResultCell
(
pResult
,
i
,
rowCellInfoOffset
);
struct
SResultRowEntryInfo
*
pResInfo
=
pCtx
[
i
].
resultInfo
;
if
(
isRowEntryCompleted
(
pResInfo
)
&&
isRowEntryInitialized
(
pResInfo
))
{
offset
+=
pCtx
[
i
].
resDataInfo
.
bytes
;
continue
;
}
pCtx
[
i
].
pOutput
=
getPosInResultPage_rv
(
bufPage
,
pResult
->
offset
,
offset
);
offset
+=
pCtx
[
i
].
resDataInfo
.
bytes
;
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
<
0
)
{
continue
;
}
if
(
functionId
==
FUNCTION_TOP
||
functionId
==
FUNCTION_BOTTOM
||
functionId
==
FUNCTION_DIFF
)
{
if
(
i
>
0
)
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
i
-
1
].
pOutput
;
}
// if (!pResInfo->initialized) {
// aAggs[functionId].init(&pCtx[i], pResInfo);
// }
}
}
void
doSetTableGroupOutputBuf
(
SAggOperatorInfo
*
pAggInfo
,
int32_t
numOfOutput
,
int32_t
tableGroupId
,
SExecTaskInfo
*
pTaskInfo
)
{
// for simple group by query without interval, all the tables belong to one group result.
// for simple group by query without interval, all the tables belong to one group result.
int64_t
uid
=
0
;
int64_t
uid
=
0
;
int64_t
tid
=
0
;
int64_t
tid
=
0
;
SResultRowInfo
*
pResultRowInfo
=
&
pAggInfo
->
binfo
.
resultRowInfo
;
SqlFunctionCtx
*
pCtx
=
pAggInfo
->
binfo
.
pCtx
;
int32_t
*
rowCellInfoOffset
=
pAggInfo
->
binfo
.
rowCellInfoOffset
;
SResultRow
*
pResultRow
=
SResultRow
*
pResultRow
=
doSetResultOutBufByKey
(
pRuntimeEnv
,
pResultRowInfo
,
tid
,
(
char
*
)
&
tableGroupId
,
sizeof
(
tableGroupId
),
true
,
uid
);
doSetResultOutBufByKey
_rv
(
pResultRowInfo
,
tid
,
(
char
*
)
&
tableGroupId
,
sizeof
(
tableGroupId
),
true
,
uid
,
pTaskInfo
,
false
,
pAggInfo
);
assert
(
pResultRow
!=
NULL
);
assert
(
pResultRow
!=
NULL
);
/*
/*
...
@@ -3880,35 +3724,32 @@ void doSetTableGroupOutputBuf(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pRes
...
@@ -3880,35 +3724,32 @@ void doSetTableGroupOutputBuf(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pRes
* all group belong to one result set, and each group result has different group id so set the id to be one
* all group belong to one result set, and each group result has different group id so set the id to be one
*/
*/
if
(
pResultRow
->
pageId
==
-
1
)
{
if
(
pResultRow
->
pageId
==
-
1
)
{
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
p
RuntimeEnv
->
pResultBuf
,
tableGroupId
,
pRuntimeEnv
->
pQueryAttr
->
result
RowSize
);
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
p
AggInfo
->
pResultBuf
,
tableGroupId
,
pAggInfo
->
binfo
.
res
RowSize
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
;
return
;
}
}
}
}
setResultRowOutputBufInitCtx
(
pRuntimeEnv
,
pResultRow
,
pCtx
,
numOfOutput
,
rowCellInfoOffset
);
setResultRowOutputBufInitCtx
_rv
(
pAggInfo
->
pResultBuf
,
pResultRow
,
pCtx
,
numOfOutput
,
rowCellInfoOffset
);
}
}
void
setExecutionContext
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int32_t
numOfOutput
,
int32_t
tableGroupId
,
void
setExecutionContext
(
int32_t
numOfOutput
,
int32_t
tableGroupId
,
TSKEY
nextKey
,
SExecTaskInfo
*
pTaskInfo
,
STableQueryInfo
*
pTableQueryInfo
,
SAggOperatorInfo
*
pAggInfo
)
{
TSKEY
nextKey
)
{
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
// lastKey needs to be updated
// lastKey needs to be updated
pTableQueryInfo
->
lastKey
=
nextKey
;
pTableQueryInfo
->
lastKey
=
nextKey
;
if
(
p
RuntimeEnv
->
prevGroupId
!=
INT32_MIN
&&
pRuntimeEnv
->
prevG
roupId
==
tableGroupId
)
{
if
(
p
AggInfo
->
groupId
!=
INT32_MIN
&&
pAggInfo
->
g
roupId
==
tableGroupId
)
{
return
;
return
;
}
}
doSetTableGroupOutputBuf
(
p
RuntimeEnv
,
&
pInfo
->
resultRowInfo
,
pInfo
->
pCtx
,
pInfo
->
rowCellInfoOffset
,
numOfOutput
,
tableGroupId
);
doSetTableGroupOutputBuf
(
p
AggInfo
,
numOfOutput
,
tableGroupId
,
pTaskInfo
);
// record the current active group id
// record the current active group id
p
RuntimeEnv
->
prevG
roupId
=
tableGroupId
;
p
AggInfo
->
g
roupId
=
tableGroupId
;
}
}
void
setResultOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SqlFunctionCtx
*
pCtx
,
void
setResultOutputBuf
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfCols
,
int32_t
*
rowCellInfoOffset
)
{
int32_t
numOfCols
,
int32_t
*
rowCellInfoOffset
)
{
// Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group
// Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group
SFilePage
*
page
=
get
Res
BufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
SFilePage
*
page
=
getBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
int16_t
offset
=
0
;
int16_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
...
@@ -3957,7 +3798,7 @@ int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, S
...
@@ -3957,7 +3798,7 @@ int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, S
STaskAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
STaskAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
assert
(
pRuntimeEnv
->
pTsBuf
!=
NULL
);
assert
(
pRuntimeEnv
->
pTsBuf
!=
NULL
);
#if 0
// both the master and supplement scan needs to set the correct ts comp start position
// both the master and supplement scan needs to set the correct ts comp start position
if (pTableQueryInfo->cur.vgroupIndex == -1) {
if (pTableQueryInfo->cur.vgroupIndex == -1) {
taosVariantAssign(&pTableQueryInfo->tag, pTag);
taosVariantAssign(&pTableQueryInfo->tag, pTag);
...
@@ -3991,7 +3832,7 @@ int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, S
...
@@ -3991,7 +3832,7 @@ int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, S
//qDebug("QInfo:0x%"PRIx64" find tag:%"PRId64" start pos in ts_comp, blockIndex:%d, tsIndex:%d", GET_TASKID(pRuntimeEnv), pTag->i, pTableQueryInfo->cur.blockIndex, pTableQueryInfo->cur.tsIndex);
//qDebug("QInfo:0x%"PRIx64" find tag:%"PRId64" start pos in ts_comp, blockIndex:%d, tsIndex:%d", GET_TASKID(pRuntimeEnv), pTag->i, pTableQueryInfo->cur.blockIndex, pTableQueryInfo->cur.tsIndex);
}
}
}
}
#endif
return
0
;
return
0
;
}
}
...
@@ -4081,7 +3922,7 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) {
...
@@ -4081,7 +3922,7 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) {
return
;
return
;
}
}
pTableQueryInfo
->
win
.
skey
=
key
;
//
pTableQueryInfo->win.skey = key;
STimeWindow
win
=
{.
skey
=
key
,
.
ekey
=
pQueryAttr
->
window
.
ekey
};
STimeWindow
win
=
{.
skey
=
key
,
.
ekey
=
pQueryAttr
->
window
.
ekey
};
/**
/**
...
@@ -4104,7 +3945,7 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) {
...
@@ -4104,7 +3945,7 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) {
// pResultRowInfo->prevSKey = w.skey;
// pResultRowInfo->prevSKey = w.skey;
// }
// }
pTableQueryInfo
->
lastKey
=
pTableQueryInfo
->
win
.
skey
;
//
pTableQueryInfo->lastKey = pTableQueryInfo->win.skey;
}
}
/**
/**
...
@@ -4117,9 +3958,7 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) {
...
@@ -4117,9 +3958,7 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) {
* @param result
* @param result
*/
*/
static
int32_t
doCopyToSDataBlock
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
)
{
static
int32_t
doCopyToSDataBlock
(
SDiskbasedBuf
*
pBuf
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
,
int32_t
rowCapacity
)
{
STaskAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
numOfRows
=
getNumOfTotalRes
(
pGroupResInfo
);
int32_t
numOfRows
=
getNumOfTotalRes
(
pGroupResInfo
);
int32_t
numOfResult
=
pBlock
->
info
.
rows
;
// there are already exists result rows
int32_t
numOfResult
=
pBlock
->
info
.
rows
;
// there are already exists result rows
...
@@ -4145,13 +3984,13 @@ static int32_t doCopyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, SGroupResInfo* p
...
@@ -4145,13 +3984,13 @@ static int32_t doCopyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, SGroupResInfo* p
}
}
int32_t
numOfRowsToCopy
=
pRow
->
numOfRows
;
int32_t
numOfRowsToCopy
=
pRow
->
numOfRows
;
if
(
numOfResult
+
numOfRowsToCopy
>=
pRuntimeEnv
->
resultInfo
.
c
apacity
)
{
if
(
numOfResult
+
numOfRowsToCopy
>=
rowC
apacity
)
{
break
;
break
;
}
}
pGroupResInfo
->
index
+=
1
;
pGroupResInfo
->
index
+=
1
;
SFilePage
*
page
=
get
ResBufPage
(
pRuntimeEnv
->
pResult
Buf
,
pRow
->
pageId
);
SFilePage
*
page
=
get
BufPage
(
p
Buf
,
pRow
->
pageId
);
int32_t
offset
=
0
;
int32_t
offset
=
0
;
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
numOfCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
numOfCols
;
++
j
)
{
...
@@ -4159,14 +3998,14 @@ static int32_t doCopyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, SGroupResInfo* p
...
@@ -4159,14 +3998,14 @@ static int32_t doCopyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, SGroupResInfo* p
int32_t
bytes
=
pColInfoData
->
info
.
bytes
;
int32_t
bytes
=
pColInfoData
->
info
.
bytes
;
char
*
out
=
pColInfoData
->
pData
+
numOfResult
*
bytes
;
char
*
out
=
pColInfoData
->
pData
+
numOfResult
*
bytes
;
char
*
in
=
getPosInResultPage
(
pQueryAttr
,
page
,
pRow
->
offset
,
offset
);
char
*
in
=
getPosInResultPage
_rv
(
page
,
pRow
->
offset
,
offset
);
memcpy
(
out
,
in
,
bytes
*
numOfRowsToCopy
);
memcpy
(
out
,
in
,
bytes
*
numOfRowsToCopy
);
offset
+=
bytes
;
offset
+=
bytes
;
}
}
numOfResult
+=
numOfRowsToCopy
;
numOfResult
+=
numOfRowsToCopy
;
if
(
numOfResult
==
pRuntimeEnv
->
resultInfo
.
c
apacity
)
{
// output buffer is full
if
(
numOfResult
==
rowC
apacity
)
{
// output buffer is full
break
;
break
;
}
}
}
}
...
@@ -4176,7 +4015,7 @@ static int32_t doCopyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, SGroupResInfo* p
...
@@ -4176,7 +4015,7 @@ static int32_t doCopyToSDataBlock(STaskRuntimeEnv* pRuntimeEnv, SGroupResInfo* p
return
0
;
return
0
;
}
}
static
void
toS
SDataBlock
(
SGroupResInfo
*
pGroupResInfo
,
STaskRuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pBlock
)
{
static
void
toS
Datablock
(
SGroupResInfo
*
pGroupResInfo
,
SDiskbasedBuf
*
pBuf
,
SSDataBlock
*
pBlock
,
int32_t
rowCapacity
)
{
assert
(
pGroupResInfo
->
currentGroup
<=
pGroupResInfo
->
totalGroup
);
assert
(
pGroupResInfo
->
currentGroup
<=
pGroupResInfo
->
totalGroup
);
pBlock
->
info
.
rows
=
0
;
pBlock
->
info
.
rows
=
0
;
...
@@ -4184,29 +4023,19 @@ static void toSSDataBlock(SGroupResInfo *pGroupResInfo, STaskRuntimeEnv* pRuntim
...
@@ -4184,29 +4023,19 @@ static void toSSDataBlock(SGroupResInfo *pGroupResInfo, STaskRuntimeEnv* pRuntim
return
;
return
;
}
}
STaskAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
orderType
=
TSDB_ORDER_ASC
;
//(pQueryAttr->pGroupbyExpr != NULL) ? pQueryAttr->pGroupbyExpr->orderType : TSDB_ORDER_ASC;
int32_t
orderType
=
TSDB_ORDER_ASC
;
//(pQueryAttr->pGroupbyExpr != NULL) ? pQueryAttr->pGroupbyExpr->orderType : TSDB_ORDER_ASC;
doCopyToSDataBlock
(
pRuntimeEnv
,
pGroupResInfo
,
orderType
,
pBlock
);
doCopyToSDataBlock
(
pBuf
,
pGroupResInfo
,
orderType
,
pBlock
,
rowCapacity
);
// refactor : extract method
SColumnInfoData
*
pInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
0
);
//add condition (pBlock->info.rows >= 1) just to runtime happy
// add condition (pBlock->info.rows >= 1) just to runtime happy
if
(
pInfoData
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
&&
pBlock
->
info
.
rows
>=
1
)
{
blockDataUpdateTsWindow
(
pBlock
);
STimeWindow
*
w
=
&
pBlock
->
info
.
window
;
w
->
skey
=
*
(
int64_t
*
)
pInfoData
->
pData
;
w
->
ekey
=
*
(
int64_t
*
)(((
char
*
)
pInfoData
->
pData
)
+
TSDB_KEYSIZE
*
(
pBlock
->
info
.
rows
-
1
));
}
}
}
static
void
updateNumOfRowsInResultRows
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
S
qlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
static
void
updateNumOfRowsInResultRows
(
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SResultRowInfo
*
pResultRowInfo
,
int32_t
*
rowCellInfoOffset
)
{
SResultRowInfo
*
pResultRowInfo
,
int32_t
*
rowCellInfoOffset
)
{
STaskAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
// update the number of result for each, only update the number of rows for the corresponding window result.
// update the number of result for each, only update the number of rows for the corresponding window result.
if
(
QUERY_IS_INTERVAL_QUERY
(
pQueryAttr
))
{
//
if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) {
return
;
//
return;
}
//
}
for
(
int32_t
i
=
0
;
i
<
pResultRowInfo
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pResultRowInfo
->
size
;
++
i
)
{
SResultRow
*
pResult
=
pResultRowInfo
->
pResult
[
i
];
SResultRow
*
pResult
=
pResultRowInfo
->
pResult
[
i
];
...
@@ -4217,8 +4046,8 @@ static void updateNumOfRowsInResultRows(STaskRuntimeEnv* pRuntimeEnv, SqlFunctio
...
@@ -4217,8 +4046,8 @@ static void updateNumOfRowsInResultRows(STaskRuntimeEnv* pRuntimeEnv, SqlFunctio
continue
;
continue
;
}
}
//
SResultRowEntryInfo* pCell = getResultCell(pResult, j, rowCellInfoOffset);
SResultRowEntryInfo
*
pCell
=
getResultCell
(
pResult
,
j
,
rowCellInfoOffset
);
//
pResult->numOfRows = (uint16_t)(TMAX(pResult->numOfRows, pCell->numOfRes));
pResult
->
numOfRows
=
(
uint16_t
)(
TMAX
(
pResult
->
numOfRows
,
pCell
->
numOfRes
));
}
}
}
}
}
}
...
@@ -4799,7 +4628,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
...
@@ -4799,7 +4628,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
getIntermediateBufInfo
(
pRuntimeEnv
,
&
ps
,
&
pQueryAttr
->
intermediateResultRowSize
);
getIntermediateBufInfo
(
pRuntimeEnv
,
&
ps
,
&
pQueryAttr
->
intermediateResultRowSize
);
int32_t
TENMB
=
1024
*
1024
*
10
;
int32_t
TENMB
=
1024
*
1024
*
10
;
int32_t
code
=
createDiskbased
Result
Buffer
(
&
pRuntimeEnv
->
pResultBuf
,
ps
,
TENMB
,
pQInfo
->
qId
,
tsTempDir
);
int32_t
code
=
createDiskbasedBuffer
(
&
pRuntimeEnv
->
pResultBuf
,
ps
,
TENMB
,
pQInfo
->
qId
,
tsTempDir
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
@@ -4829,7 +4658,8 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
...
@@ -4829,7 +4658,8 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
}
}
static
void
doTableQueryInfoTimeWindowCheck
(
SExecTaskInfo
*
pTaskInfo
,
STableQueryInfo
*
pTableQueryInfo
,
int32_t
order
)
{
static
void
doTableQueryInfoTimeWindowCheck
(
SExecTaskInfo
*
pTaskInfo
,
STableQueryInfo
*
pTableQueryInfo
,
int32_t
order
)
{
if
(
order
==
TSDB_ORDER_ASC
)
{
#if 0
if (order == TSDB_ORDER_ASC) {
assert(
assert(
(pTableQueryInfo->win.skey <= pTableQueryInfo->win.ekey) &&
(pTableQueryInfo->win.skey <= pTableQueryInfo->win.ekey) &&
(pTableQueryInfo->lastKey >= pTaskInfo->window.skey) &&
(pTableQueryInfo->lastKey >= pTaskInfo->window.skey) &&
...
@@ -4840,6 +4670,8 @@ static void doTableQueryInfoTimeWindowCheck(SExecTaskInfo* pTaskInfo, STableQuer
...
@@ -4840,6 +4670,8 @@ static void doTableQueryInfoTimeWindowCheck(SExecTaskInfo* pTaskInfo, STableQuer
(pTableQueryInfo->lastKey <= pTaskInfo->window.skey) &&
(pTableQueryInfo->lastKey <= pTaskInfo->window.skey) &&
(pTableQueryInfo->win.skey <= pTaskInfo->window.skey && pTableQueryInfo->win.ekey >= pTaskInfo->window.ekey));
(pTableQueryInfo->win.skey <= pTaskInfo->window.skey && pTableQueryInfo->win.ekey >= pTaskInfo->window.ekey));
}
}
#endif
}
}
//STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win) {
//STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win) {
...
@@ -5102,14 +4934,16 @@ static SSDataBlock* doStreamBlockScan(void* param, bool* newgroup) {
...
@@ -5102,14 +4934,16 @@ static SSDataBlock* doStreamBlockScan(void* param, bool* newgroup) {
}
}
int32_t
loadRemoteDataCallback
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
int32_t
loadRemoteDataCallback
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
S
ExchangeInfo
*
pEx
=
(
SExchange
Info
*
)
param
;
S
SourceDataInfo
*
pSourceDataInfo
=
(
SSourceData
Info
*
)
param
;
p
Ex
->
pRsp
=
pMsg
->
pData
;
p
SourceDataInfo
->
pRsp
=
pMsg
->
pData
;
pEx
->
pRsp
->
numOfRows
=
htonl
(
pEx
->
pRsp
->
numOfRows
);
SRetrieveTableRsp
*
pRsp
=
pSourceDataInfo
->
pRsp
;
pEx
->
pRsp
->
useconds
=
htobe64
(
pEx
->
pRsp
->
useconds
);
pRsp
->
numOfRows
=
htonl
(
pRsp
->
numOfRows
);
pEx
->
pRsp
->
compLen
=
htonl
(
pEx
->
pRsp
->
compLen
);
pRsp
->
useconds
=
htobe64
(
pRsp
->
useconds
);
pRsp
->
compLen
=
htonl
(
pRsp
->
compLen
);
tsem_post
(
&
pEx
->
ready
);
pSourceDataInfo
->
status
=
DATA_READY
;
tsem_post
(
&
pSourceDataInfo
->
pEx
->
ready
);
}
}
static
void
destroySendMsgInfo
(
SMsgSendInfo
*
pMsgBody
)
{
static
void
destroySendMsgInfo
(
SMsgSendInfo
*
pMsgBody
)
{
...
@@ -5139,165 +4973,330 @@ void qProcessFetchRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
...
@@ -5139,165 +4973,330 @@ void qProcessFetchRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
destroySendMsgInfo
(
pSendInfo
);
destroySendMsgInfo
(
pSendInfo
);
}
}
static
SSDataBlock
*
doLoadRemoteData
(
void
*
param
,
bool
*
newgroup
)
{
static
int32_t
doSendFetchDataRequest
(
SExchangeInfo
*
pExchangeInfo
,
SExecTaskInfo
*
pTaskInfo
,
int32_t
sourceIndex
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
size_t
totalSources
=
taosArrayGetSize
(
pExchangeInfo
->
pSources
)
;
SExchangeInfo
*
pExchangeInfo
=
pOperator
->
info
;
SResFetchReq
*
pMsg
=
calloc
(
1
,
sizeof
(
SResFetchReq
));
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
if
(
NULL
==
pMsg
)
{
pTaskInfo
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
pTaskInfo
->
code
;
}
*
newgroup
=
false
;
SDownstreamSource
*
pSource
=
taosArrayGet
(
pExchangeInfo
->
pSources
,
sourceIndex
);
SSourceDataInfo
*
pDataInfo
=
taosArrayGet
(
pExchangeInfo
->
pSourceDataInfo
,
sourceIndex
);
size_t
totalSources
=
taosArrayGetSize
(
pExchangeInfo
->
pSources
);
qDebug
(
"%s build fetch msg and send to vgId:%d, ep:%s, taskId:0x%"
PRIx64
", %d/%"
PRIzu
,
if
(
pExchangeInfo
->
current
>=
totalSources
)
{
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
addr
.
epset
.
eps
[
0
].
fqdn
,
pSource
->
taskId
,
sourceIndex
,
totalSources
);
qDebug
(
"%s all %"
PRIzu
" source(s) are exhausted, total rows:%"
PRIu64
" bytes:%"
PRIu64
", elapsed:%.2f ms"
,
GET_TASKID
(
pTaskInfo
),
totalSources
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
,
pExchangeInfo
->
totalElapsed
/
1000
.
0
);
pMsg
->
header
.
vgId
=
htonl
(
pSource
->
addr
.
nodeId
);
return
NULL
;
pMsg
->
sId
=
htobe64
(
pSource
->
schedId
);
pMsg
->
taskId
=
htobe64
(
pSource
->
taskId
);
pMsg
->
queryId
=
htobe64
(
pTaskInfo
->
id
.
queryId
);
// send the fetch remote task result reques
SMsgSendInfo
*
pMsgSendInfo
=
calloc
(
1
,
sizeof
(
SMsgSendInfo
));
if
(
NULL
==
pMsgSendInfo
)
{
tfree
(
pMsg
);
qError
(
"%s prepare message %d failed"
,
GET_TASKID
(
pTaskInfo
),
(
int32_t
)
sizeof
(
SMsgSendInfo
));
pTaskInfo
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
pTaskInfo
->
code
;
}
}
SResFetchReq
*
pMsg
=
NULL
;
pMsgSendInfo
->
param
=
pDataInfo
;
SMsgSendInfo
*
pMsgSendInfo
=
NULL
;
pMsgSendInfo
->
msgInfo
.
pData
=
pMsg
;
pMsgSendInfo
->
msgInfo
.
len
=
sizeof
(
SResFetchReq
);
pMsgSendInfo
->
msgType
=
TDMT_VND_FETCH
;
pMsgSendInfo
->
fp
=
loadRemoteDataCallback
;
while
(
1
)
{
int64_t
transporterId
=
0
;
pMsg
=
calloc
(
1
,
sizeof
(
SResFetchReq
));
int32_t
code
=
asyncSendMsgToServer
(
pExchangeInfo
->
pTransporter
,
&
pSource
->
addr
.
epset
,
&
transporterId
,
pMsgSendInfo
);
if
(
NULL
==
pMsg
)
{
// todo handle malloc error
return
TSDB_CODE_SUCCESS
;
pTaskInfo
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
goto
_error
;
static
int32_t
setSDataBlockFromFetchRsp
(
SSDataBlock
*
pRes
,
SExchangeInfo
*
pExchangeInfo
,
SSourceDataInfo
*
pDataInfo
,
int32_t
numOfOutput
,
int64_t
startTs
)
{
char
*
pData
=
pDataInfo
->
pRsp
->
data
;
SRetrieveTableRsp
*
pRsp
=
pDataInfo
->
pRsp
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pRes
->
pDataBlock
,
i
);
char
*
tmp
=
realloc
(
pColInfoData
->
pData
,
pColInfoData
->
info
.
bytes
*
pRsp
->
numOfRows
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
}
SDownstreamSource
*
pSource
=
taosArrayGet
(
pExchangeInfo
->
pSources
,
pExchangeInfo
->
current
);
size_t
len
=
pRsp
->
numOfRows
*
pColInfoData
->
info
.
bytes
;
memcpy
(
tmp
,
pData
,
len
);
int64_t
startTs
=
taosGetTimestampUs
()
;
pColInfoData
->
pData
=
tmp
;
qDebug
(
"%s build fetch msg and send to vgId:%d, ep:%s, taskId:0x%"
PRIx64
", %d/%"
PRIzu
,
pData
+=
len
;
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
addr
.
epset
.
eps
[
0
].
fqdn
,
pSource
->
taskId
,
pExchangeInfo
->
current
,
totalSources
);
}
pMsg
->
header
.
vgId
=
htonl
(
pSource
->
addr
.
nodeId
);
pRes
->
info
.
rows
=
pRsp
->
numOfRows
;
pMsg
->
sId
=
htobe64
(
pSource
->
schedId
);
pMsg
->
taskId
=
htobe64
(
pSource
->
taskId
);
pMsg
->
queryId
=
htobe64
(
pTaskInfo
->
id
.
queryId
);
// send the fetch remote task result reques
int64_t
el
=
taosGetTimestampUs
()
-
startTs
;
pMsgSendInfo
=
calloc
(
1
,
sizeof
(
SMsgSendInfo
));
if
(
NULL
==
pMsgSendInfo
)
{
qError
(
"%s prepare message %d failed"
,
GET_TASKID
(
pTaskInfo
),
(
int32_t
)
sizeof
(
SMsgSendInfo
));
pTaskInfo
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
goto
_error
;
}
pMsgSendInfo
->
param
=
pExchangeInfo
;
pExchangeInfo
->
totalRows
+=
pRsp
->
numOfRows
;
pMsgSendInfo
->
msgInfo
.
pData
=
pMsg
;
pExchangeInfo
->
totalSize
+=
pRsp
->
compLen
;
pMsgSendInfo
->
msgInfo
.
len
=
sizeof
(
SResFetchReq
);
pDataInfo
->
totalRows
+=
pRsp
->
numOfRows
;
pMsgSendInfo
->
msgType
=
TDMT_VND_FETCH
;
pMsgSendInfo
->
fp
=
loadRemoteDataCallback
;
int64_t
transporterId
=
0
;
pExchangeInfo
->
totalElapsed
+=
el
;
int32_t
code
=
asyncSendMsgToServer
(
pExchangeInfo
->
pTransporter
,
&
pSource
->
addr
.
epset
,
&
transporterId
,
pMsgSendInfo
);
tsem_wait
(
&
pExchangeInfo
->
ready
);
SRetrieveTableRsp
*
pRsp
=
pExchangeInfo
->
pRsp
;
return
TSDB_CODE_SUCCESS
;
if
(
pRsp
->
numOfRows
==
0
)
{
}
qDebug
(
"%s vgId:%d, taskID:0x%"
PRIx64
" %d of total completed, rowsOfSource:%"
PRIu64
", totalRows:%"
PRIu64
" try next"
,
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pExchangeInfo
->
current
+
1
,
pExchangeInfo
->
rowsOfCurrentSource
,
pExchangeInfo
->
totalRows
);
pExchangeInfo
->
rowsOfCurrentSource
=
0
;
static
void
*
setAllSourcesCompleted
(
SOperatorInfo
*
pOperator
,
int64_t
startTs
)
{
pExchangeInfo
->
current
+=
1
;
SExchangeInfo
*
pExchangeInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
if
(
pExchangeInfo
->
current
>=
totalSources
)
{
int64_t
el
=
taosGetTimestampUs
()
-
startTs
;
int64_t
el
=
taosGetTimestampUs
()
-
startTs
;
pExchangeInfo
->
totalElapsed
+=
el
;
pExchangeInfo
->
totalElapsed
+=
el
;
qDebug
(
"%s all %"
PRIzu
" sources are exhausted, total rows: %"
PRIu64
" bytes:%"
PRIu64
", elapsed:%.2f ms"
,
GET_TASKID
(
pTaskInfo
),
totalSources
,
size_t
totalSources
=
taosArrayGetSize
(
pExchangeInfo
->
pSources
);
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
,
pExchangeInfo
->
totalElapsed
/
1000
.
0
);
qDebug
(
"%s all %"
PRIzu
" sources are exhausted, total rows: %"
PRIu64
" bytes:%"
PRIu64
", elapsed:%.2f ms"
,
GET_TASKID
(
pTaskInfo
),
totalSources
,
return
NULL
;
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
,
pExchangeInfo
->
totalElapsed
/
1000
.
0
);
}
else
{
doSetOperatorCompleted
(
pOperator
);
return
NULL
;
}
static
SSDataBlock
*
concurrentlyLoadRemoteDataImpl
(
SOperatorInfo
*
pOperator
,
SExchangeInfo
*
pExchangeInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
int32_t
code
=
0
;
int64_t
startTs
=
taosGetTimestampUs
();
size_t
totalSources
=
taosArrayGetSize
(
pExchangeInfo
->
pSources
);
while
(
1
)
{
int32_t
completed
=
0
;
for
(
int32_t
i
=
0
;
i
<
totalSources
;
++
i
)
{
SSourceDataInfo
*
pDataInfo
=
taosArrayGet
(
pExchangeInfo
->
pSourceDataInfo
,
i
);
if
(
pDataInfo
->
status
==
DATA_EXHAUSTED
)
{
completed
+=
1
;
continue
;
continue
;
}
}
}
SSDataBlock
*
pRes
=
pExchangeInfo
->
pResult
;
char
*
pData
=
pRsp
->
data
;
for
(
int32_t
i
=
0
;
i
<
pOperator
->
numOfOutput
;
++
i
)
{
if
(
pDataInfo
->
status
!=
DATA_READY
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pRes
->
pDataBlock
,
i
);
continue
;
char
*
tmp
=
realloc
(
pColInfoData
->
pData
,
pColInfoData
->
info
.
bytes
*
pRsp
->
numOfRows
);
if
(
tmp
==
NULL
)
{
goto
_error
;
}
}
size_t
len
=
pRsp
->
numOfRows
*
pColInfoData
->
info
.
bytes
;
SRetrieveTableRsp
*
pRsp
=
pDataInfo
->
pRsp
;
memcpy
(
tmp
,
pData
,
len
);
SDownstreamSource
*
pSource
=
taosArrayGet
(
pExchangeInfo
->
pSources
,
i
);
pColInfoData
->
pData
=
tmp
;
SSDataBlock
*
pRes
=
pExchangeInfo
->
pResult
;
pData
+=
len
;
}
pRes
->
info
.
numOfCols
=
pOperator
->
numOfOutput
;
if
(
pRsp
->
numOfRows
==
0
)
{
pRes
->
info
.
rows
=
pRsp
->
numOfRows
;
qDebug
(
"%s vgId:%d, taskID:0x%"
PRIx64
" index:%d completed, rowsOfSource:%"
PRIu64
", totalRows:%"
PRIu64
" try next"
,
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
i
+
1
,
pDataInfo
->
totalRows
,
pExchangeInfo
->
totalRows
);
pDataInfo
->
status
=
DATA_EXHAUSTED
;
completed
+=
1
;
continue
;
}
int64_t
el
=
taosGetTimestampUs
()
-
startTs
;
code
=
setSDataBlockFromFetchRsp
(
pExchangeInfo
->
pResult
,
pExchangeInfo
,
pDataInfo
,
pOperator
->
numOfOutput
,
startTs
);
if
(
code
!=
0
)
{
goto
_error
;
}
pExchangeInfo
->
totalRows
+=
pRsp
->
numOfRows
;
if
(
pRsp
->
completed
==
1
)
{
pExchangeInfo
->
totalSize
+=
pRsp
->
compLen
;
qDebug
(
"%s fetch msg rsp from vgId:%d, taskId:0x%"
PRIx64
" numOfRows:%d, rowsOfSource:%"
PRIu64
pExchangeInfo
->
rowsOfCurrentSource
+=
pRsp
->
numOfRows
;
", totalRows:%"
PRIu64
", totalBytes:%"
PRIu64
" try next %d/%"
PRIzu
,
pExchangeInfo
->
totalElapsed
+=
el
;
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pRes
->
info
.
rows
,
pDataInfo
->
totalRows
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
,
i
+
1
,
totalSources
);
pDataInfo
->
status
=
DATA_EXHAUSTED
;
}
else
{
qDebug
(
"%s fetch msg rsp from vgId:%d, taskId:0x%"
PRIx64
" numOfRows:%d, totalRows:%"
PRIu64
", totalBytes:%"
PRIu64
,
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pRes
->
info
.
rows
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
);
}
if
(
pRsp
->
completed
==
1
)
{
if
(
pDataInfo
->
status
!=
DATA_EXHAUSTED
)
{
qDebug
(
"%s fetch msg rsp from vgId:%d, taskId:0x%"
PRIx64
" numOfRows:%d, rowsOfSource:%"
PRIu64
pDataInfo
->
status
=
DATA_NOT_READY
;
", totalRows:%"
PRIu64
", totalBytes:%"
PRIu64
" try next %d/%"
PRIzu
,
code
=
doSendFetchDataRequest
(
pExchangeInfo
,
pTaskInfo
,
i
);
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pRes
->
info
.
rows
,
pExchangeInfo
->
rowsOfCurrentSource
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
,
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pExchangeInfo
->
current
+
1
,
totalSources
);
goto
_error
;
}
}
pExchangeInfo
->
rowsOfCurrentSource
=
0
;
return
pExchangeInfo
->
pResult
;
pExchangeInfo
->
current
+=
1
;
}
else
{
qDebug
(
"%s fetch msg rsp from vgId:%d, taskId:0x%"
PRIx64
" numOfRows:%d, totalRows:%"
PRIu64
", totalBytes:%"
PRIu64
,
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pRes
->
info
.
rows
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
);
}
}
return
pExchangeInfo
->
pResult
;
if
(
completed
==
totalSources
)
{
return
setAllSourcesCompleted
(
pOperator
,
startTs
);
}
}
}
_error:
_error:
tfree
(
pMsg
);
pTaskInfo
->
code
=
code
;
tfree
(
pMsgSendInfo
);
terrno
=
pTaskInfo
->
code
;
return
NULL
;
return
NULL
;
}
}
static
SSDataBlock
*
createResultDataBlock
(
const
SArray
*
pExprInfo
);
static
SSDataBlock
*
concurrentlyLoadRemoteData
(
SOperatorInfo
*
pOperator
)
{
SExchangeInfo
*
pExchangeInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
return
concurrentlyLoadRemoteDataImpl
(
pOperator
,
pExchangeInfo
,
pTaskInfo
);
}
SOperatorInfo
*
createExchangeOperatorInfo
(
const
SArray
*
pSources
,
const
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
size_t
totalSources
=
taosArrayGetSize
(
pExchangeInfo
->
pSources
);
SExchangeInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SExchangeInfo
));
int64_t
startTs
=
taosGetTimestampUs
();
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
// Asynchronously send all fetch requests to all sources.
tfree
(
pInfo
);
for
(
int32_t
i
=
0
;
i
<
totalSources
;
++
i
)
{
tfree
(
pOperator
);
int32_t
code
=
doSendFetchDataRequest
(
pExchangeInfo
,
pTaskInfo
,
i
);
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
return
NULL
;
}
}
}
pInfo
->
pSources
=
taosArrayDup
(
pSources
);
int64_t
endTs
=
taosGetTimestampUs
(
);
assert
(
taosArrayGetSize
(
pInfo
->
pSources
)
>
0
);
qDebug
(
"%s send all fetch request to %"
PRIzu
" sources completed, elapsed:%"
PRId64
,
GET_TASKID
(
pTaskInfo
),
totalSources
,
endTs
-
startTs
);
size_t
size
=
taosArrayGetSize
(
pExprInfo
);
tsem_wait
(
&
pExchangeInfo
->
ready
);
pInfo
->
pResult
=
createResultDataBlock
(
pExprInfo
);
pOperator
->
name
=
"ExchangeOperator"
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
operatorType
=
OP_Exchange
;
return
concurrentlyLoadRemoteDataImpl
(
pOperator
,
pExchangeInfo
,
pTaskInfo
);
pOperator
->
blockingOptr
=
false
;
}
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
pOperator
->
numOfOutput
=
size
;
pOperator
->
pRuntimeEnv
=
NULL
;
pOperator
->
exec
=
doLoadRemoteData
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
#if 1
static
SSDataBlock
*
seqLoadRemoteData
(
SOperatorInfo
*
pOperator
)
{
{
// todo refactor
SExchangeInfo
*
pExchangeInfo
=
pOperator
->
info
;
SRpcInit
rpcInit
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
size_t
totalSources
=
taosArrayGetSize
(
pExchangeInfo
->
pSources
);
int64_t
startTs
=
taosGetTimestampUs
();
while
(
1
)
{
if
(
pExchangeInfo
->
current
>=
totalSources
)
{
return
setAllSourcesCompleted
(
pOperator
,
startTs
);
}
doSendFetchDataRequest
(
pExchangeInfo
,
pTaskInfo
,
pExchangeInfo
->
current
);
tsem_wait
(
&
pExchangeInfo
->
ready
);
SSourceDataInfo
*
pDataInfo
=
taosArrayGet
(
pExchangeInfo
->
pSourceDataInfo
,
pExchangeInfo
->
current
);
SDownstreamSource
*
pSource
=
taosArrayGet
(
pExchangeInfo
->
pSources
,
pExchangeInfo
->
current
);
SRetrieveTableRsp
*
pRsp
=
pDataInfo
->
pRsp
;
if
(
pRsp
->
numOfRows
==
0
)
{
qDebug
(
"%s vgId:%d, taskID:0x%"
PRIx64
" %d of total completed, rowsOfSource:%"
PRIu64
", totalRows:%"
PRIu64
" try next"
,
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pExchangeInfo
->
current
+
1
,
pDataInfo
->
totalRows
,
pExchangeInfo
->
totalRows
);
pDataInfo
->
status
=
DATA_EXHAUSTED
;
pExchangeInfo
->
current
+=
1
;
continue
;
}
SSDataBlock
*
pRes
=
pExchangeInfo
->
pResult
;
setSDataBlockFromFetchRsp
(
pExchangeInfo
->
pResult
,
pExchangeInfo
,
pDataInfo
,
pOperator
->
numOfOutput
,
startTs
);
if
(
pRsp
->
completed
==
1
)
{
qDebug
(
"%s fetch msg rsp from vgId:%d, taskId:0x%"
PRIx64
" numOfRows:%d, rowsOfSource:%"
PRIu64
", totalRows:%"
PRIu64
", totalBytes:%"
PRIu64
" try next %d/%"
PRIzu
,
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pRes
->
info
.
rows
,
pDataInfo
->
totalRows
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
,
pExchangeInfo
->
current
+
1
,
totalSources
);
pDataInfo
->
status
=
DATA_EXHAUSTED
;
pExchangeInfo
->
current
+=
1
;
}
else
{
qDebug
(
"%s fetch msg rsp from vgId:%d, taskId:0x%"
PRIx64
" numOfRows:%d, totalRows:%"
PRIu64
", totalBytes:%"
PRIu64
,
GET_TASKID
(
pTaskInfo
),
pSource
->
addr
.
nodeId
,
pSource
->
taskId
,
pRes
->
info
.
rows
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
);
}
return
pExchangeInfo
->
pResult
;
}
}
static
SSDataBlock
*
doLoadRemoteData
(
void
*
param
,
bool
*
newgroup
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SExchangeInfo
*
pExchangeInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
size_t
totalSources
=
taosArrayGetSize
(
pExchangeInfo
->
pSources
);
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
qDebug
(
"%s all %"
PRIzu
" source(s) are exhausted, total rows:%"
PRIu64
" bytes:%"
PRIu64
", elapsed:%.2f ms"
,
GET_TASKID
(
pTaskInfo
),
totalSources
,
pExchangeInfo
->
totalRows
,
pExchangeInfo
->
totalSize
,
pExchangeInfo
->
totalElapsed
/
1000
.
0
);
return
NULL
;
}
*
newgroup
=
false
;
if
(
pExchangeInfo
->
seqLoadData
)
{
return
seqLoadRemoteData
(
pOperator
);
}
else
{
return
concurrentlyLoadRemoteData
(
pOperator
);
}
#if 0
_error:
tfree(pMsg);
tfree(pMsgSendInfo);
terrno = pTaskInfo->code;
return NULL;
#endif
}
static
SSDataBlock
*
createResultDataBlock
(
const
SArray
*
pExprInfo
);
SOperatorInfo
*
createExchangeOperatorInfo
(
const
SArray
*
pSources
,
const
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
SExchangeInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SExchangeInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
tfree
(
pInfo
);
tfree
(
pOperator
);
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
NULL
;
}
size_t
numOfSources
=
taosArrayGetSize
(
pSources
);
pInfo
->
pSources
=
taosArrayDup
(
pSources
);
pInfo
->
pSourceDataInfo
=
taosArrayInit
(
numOfSources
,
sizeof
(
SSourceDataInfo
));
if
(
pInfo
->
pSourceDataInfo
==
NULL
||
pInfo
->
pSources
==
NULL
)
{
tfree
(
pInfo
);
tfree
(
pOperator
);
taosArrayDestroy
(
pInfo
->
pSources
);
taosArrayDestroy
(
pInfo
->
pSourceDataInfo
);
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
numOfSources
;
++
i
)
{
SSourceDataInfo
dataInfo
=
{
0
};
dataInfo
.
status
=
DATA_NOT_READY
;
dataInfo
.
pEx
=
pInfo
;
dataInfo
.
index
=
i
;
taosArrayPush
(
pInfo
->
pSourceDataInfo
,
&
dataInfo
);
}
size_t
size
=
taosArrayGetSize
(
pExprInfo
);
pInfo
->
pResult
=
createResultDataBlock
(
pExprInfo
);
pInfo
->
seqLoadData
=
true
;
tsem_init
(
&
pInfo
->
ready
,
0
,
0
);
pOperator
->
name
=
"ExchangeOperator"
;
pOperator
->
operatorType
=
OP_Exchange
;
pOperator
->
blockingOptr
=
false
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
pOperator
->
numOfOutput
=
size
;
pOperator
->
exec
=
doLoadRemoteData
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
#if 1
{
// todo refactor
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localPort
=
0
;
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"EX"
;
rpcInit
.
label
=
"EX"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
numOfThreads
=
1
;
...
@@ -5316,6 +5315,7 @@ SOperatorInfo* createExchangeOperatorInfo(const SArray* pSources, const SArray*
...
@@ -5316,6 +5315,7 @@ SOperatorInfo* createExchangeOperatorInfo(const SArray* pSources, const SArray*
}
}
}
}
#endif
#endif
return
pOperator
;
return
pOperator
;
}
}
...
@@ -5344,7 +5344,7 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) {
...
@@ -5344,7 +5344,7 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) {
return
pResBlock
;
return
pResBlock
;
}
}
SOperatorInfo
*
create
DataBlocksOptScan
Info
(
void
*
pTsdbReadHandle
,
int32_t
order
,
int32_t
numOfOutput
,
int32_t
repeatTime
,
int32_t
reverseTime
,
SExecTaskInfo
*
pTaskInfo
)
{
SOperatorInfo
*
create
TableScanOperator
Info
(
void
*
pTsdbReadHandle
,
int32_t
order
,
int32_t
numOfOutput
,
int32_t
repeatTime
,
int32_t
reverseTime
,
SExecTaskInfo
*
pTaskInfo
)
{
assert
(
repeatTime
>
0
);
assert
(
repeatTime
>
0
);
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
...
@@ -5364,8 +5364,8 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbReadHandle, int32_t order,
...
@@ -5364,8 +5364,8 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbReadHandle, int32_t order,
pInfo
->
current
=
0
;
pInfo
->
current
=
0
;
pInfo
->
scanFlag
=
MAIN_SCAN
;
pInfo
->
scanFlag
=
MAIN_SCAN
;
pOperator
->
name
=
"
DataBlocksOptimized
ScanOperator"
;
pOperator
->
name
=
"
Table
ScanOperator"
;
pOperator
->
operatorType
=
OP_
DataBlocksOpt
Scan
;
pOperator
->
operatorType
=
OP_
Table
Scan
;
pOperator
->
blockingOptr
=
false
;
pOperator
->
blockingOptr
=
false
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
...
@@ -5376,7 +5376,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbReadHandle, int32_t order,
...
@@ -5376,7 +5376,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbReadHandle, int32_t order,
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbReadHandle
,
STaskRuntimeEnv
*
pRuntimeEnv
)
{
SOperatorInfo
*
createTableSeqScanOperator
Info
(
void
*
pTsdbReadHandle
,
STaskRuntimeEnv
*
pRuntimeEnv
)
{
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
pInfo
->
pTsdbReadHandle
=
pTsdbReadHandle
;
pInfo
->
pTsdbReadHandle
=
pTsdbReadHandle
;
...
@@ -5604,10 +5604,11 @@ static void destroyGlobalAggOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -5604,10 +5604,11 @@ static void destroyGlobalAggOperatorInfo(void* param, int32_t numOfOutput) {
tfree
(
pInfo
->
prevRow
);
tfree
(
pInfo
->
prevRow
);
tfree
(
pInfo
->
currentGroupColData
);
tfree
(
pInfo
->
currentGroupColData
);
}
}
static
void
destroySlimitOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroySlimitOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SSLimitOperatorInfo
*
pInfo
=
(
SSLimitOperatorInfo
*
)
param
;
SSLimitOperatorInfo
*
pInfo
=
(
SSLimitOperatorInfo
*
)
param
;
taosArrayDestroy
(
pInfo
->
orderColumnList
);
taosArrayDestroy
(
pInfo
->
orderColumnList
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
tfree
(
pInfo
->
prevRow
);
tfree
(
pInfo
->
prevRow
);
}
}
...
@@ -5719,39 +5720,397 @@ SOperatorInfo *createMultiwaySortOperatorInfo(STaskRuntimeEnv *pRuntimeEnv, SExp
...
@@ -5719,39 +5720,397 @@ SOperatorInfo *createMultiwaySortOperatorInfo(STaskRuntimeEnv *pRuntimeEnv, SExp
return
pOperator
;
return
pOperator
;
}
}
static
int32_t
doMergeSDatablock
(
SSDataBlock
*
pDest
,
SSDataBlock
*
pSrc
)
{
typedef
struct
SExternalMemSource
{
assert
(
pSrc
!=
NULL
&&
pDest
!=
NULL
&&
pDest
->
info
.
numOfCols
==
pSrc
->
info
.
numOfCols
);
SArray
*
pageIdList
;
int32_t
pageIndex
;
int32_t
sourceId
;
int32_t
rowIndex
;
SSDataBlock
*
pBlock
;
}
SExternalMemSource
;
int32_t
numOfCols
=
pSrc
->
info
.
numOfCols
;
int32_t
msortComparFn
(
const
void
*
pLeft
,
const
void
*
pRight
,
void
*
param
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
int32_t
pLeftIdx
=
*
(
int32_t
*
)
pLeft
;
SColumnInfoData
*
pCol2
=
taosArrayGet
(
pDest
->
pDataBlock
,
i
);
int32_t
pRightIdx
=
*
(
int32_t
*
)
pRight
;
SColumnInfoData
*
pCol1
=
taosArrayGet
(
pSrc
->
pDataBlock
,
i
);
SMsortComparParam
*
pParam
=
(
SMsortComparParam
*
)
param
;
int32_t
newSize
=
(
pDest
->
info
.
rows
+
pSrc
->
info
.
rows
)
*
pCol2
->
info
.
bytes
;
char
*
tmp
=
realloc
(
pCol2
->
pData
,
newSize
);
SArray
*
pInfo
=
pParam
->
orderInfo
;
if
(
tmp
!=
NULL
)
{
pCol2
->
pData
=
tmp
;
SExternalMemSource
*
pLeftSource
=
pParam
->
pSources
[
pLeftIdx
];
int32_t
offset
=
pCol2
->
info
.
bytes
*
pDest
->
info
.
rows
;
SExternalMemSource
*
pRightSource
=
pParam
->
pSources
[
pRightIdx
];
memcpy
(
pCol2
->
pData
+
offset
,
pCol1
->
pData
,
pSrc
->
info
.
rows
*
pCol2
->
info
.
bytes
);
// this input is exhausted, set the special value to denote this
if
(
pLeftSource
->
rowIndex
==
-
1
)
{
return
1
;
}
if
(
pRightSource
->
rowIndex
==
-
1
)
{
return
-
1
;
}
SSDataBlock
*
pLeftBlock
=
pLeftSource
->
pBlock
;
SSDataBlock
*
pRightBlock
=
pRightSource
->
pBlock
;
for
(
int32_t
i
=
0
;
i
<
pInfo
->
size
;
++
i
)
{
SBlockOrderInfo
*
pOrder
=
TARRAY_GET_ELEM
(
pInfo
,
i
);
SColumnInfoData
*
pLeftColInfoData
=
TARRAY_GET_ELEM
(
pLeftBlock
->
pDataBlock
,
pOrder
->
colIndex
);
bool
leftNull
=
false
;
if
(
pLeftColInfoData
->
hasNull
)
{
leftNull
=
colDataIsNull
(
pLeftColInfoData
,
pLeftBlock
->
info
.
rows
,
pLeftSource
->
rowIndex
,
pLeftBlock
->
pBlockAgg
);
}
SColumnInfoData
*
pRightColInfoData
=
TARRAY_GET_ELEM
(
pRightBlock
->
pDataBlock
,
pOrder
->
colIndex
);
bool
rightNull
=
false
;
if
(
pRightColInfoData
->
hasNull
)
{
rightNull
=
colDataIsNull
(
pRightColInfoData
,
pRightBlock
->
info
.
rows
,
pRightSource
->
rowIndex
,
pRightBlock
->
pBlockAgg
);
}
if
(
leftNull
&&
rightNull
)
{
continue
;
// continue to next slot
}
if
(
rightNull
)
{
return
pParam
->
nullFirst
?
1
:-
1
;
}
if
(
leftNull
)
{
return
pParam
->
nullFirst
?
-
1
:
1
;
}
void
*
left1
=
colDataGet
(
pLeftColInfoData
,
pLeftSource
->
rowIndex
);
void
*
right1
=
colDataGet
(
pRightColInfoData
,
pRightSource
->
rowIndex
);
switch
(
pLeftColInfoData
->
info
.
type
)
{
case
TSDB_DATA_TYPE_INT
:
{
int32_t
leftv
=
*
(
int32_t
*
)
left1
;
int32_t
rightv
=
*
(
int32_t
*
)
right1
;
if
(
leftv
==
rightv
)
{
break
;
}
else
{
if
(
pOrder
->
order
==
TSDB_ORDER_ASC
)
{
return
leftv
<
rightv
?
-
1
:
1
;
}
else
{
return
leftv
<
rightv
?
1
:
-
1
;
}
}
}
default:
assert
(
0
);
}
}
}
static
int32_t
adjustMergeTreeForNextTuple
(
SExternalMemSource
*
pSource
,
SMultiwayMergeTreeInfo
*
pTree
,
SOrderOperatorInfo
*
pInfo
)
{
/*
* load a new SDataBlock into memory of a given intermediate data-set source,
* since it's last record in buffer has been chosen to be processed, as the winner of loser-tree
*/
if
(
pSource
->
rowIndex
>=
pSource
->
pBlock
->
info
.
rows
)
{
pSource
->
rowIndex
=
0
;
pSource
->
pageIndex
+=
1
;
if
(
pSource
->
pageIndex
>=
taosArrayGetSize
(
pSource
->
pageIdList
))
{
pInfo
->
numOfCompleted
+=
1
;
pSource
->
rowIndex
=
-
1
;
pSource
->
pageIndex
=
-
1
;
pSource
->
pBlock
=
blockDataDestroy
(
pSource
->
pBlock
);
}
else
{
SPageInfo
*
pPgInfo
=
*
(
SPageInfo
**
)
taosArrayGet
(
pSource
->
pageIdList
,
pSource
->
pageIndex
);
SFilePage
*
pPage
=
getBufPage
(
pInfo
->
pSortInternalBuf
,
getPageId
(
pPgInfo
));
int32_t
code
=
blockDataFromBuf
(
pSource
->
pBlock
,
pPage
->
data
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
releaseBufPage
(
pInfo
->
pSortInternalBuf
,
pPage
);
}
}
/*
* Adjust loser tree otherwise, according to new candidate data
* if the loser tree is rebuild completed, we do not need to adjust
*/
int32_t
leafNodeIndex
=
tMergeTreeGetAdjustIndex
(
pTree
);
#ifdef _DEBUG_VIEW
printf
(
"before adjust:
\t
"
);
tMergeTreePrint
(
pTree
);
#endif
tMergeTreeAdjust
(
pTree
,
leafNodeIndex
);
#ifdef _DEBUG_VIEW
printf
(
"
\n
after adjust:
\t
"
);
tMergeTreePrint
(
pTree
);
#endif
}
static
void
appendOneRowToDataBlock
(
SSDataBlock
*
pBlock
,
const
SSDataBlock
*
pSource
,
int32_t
*
rowIndex
)
{
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
SColumnInfoData
*
pSrcColInfo
=
taosArrayGet
(
pSource
->
pDataBlock
,
i
);
bool
isNull
=
colDataIsNull
(
pSrcColInfo
,
pSource
->
info
.
rows
,
*
rowIndex
,
NULL
);
if
(
isNull
)
{
colDataAppend
(
pColInfo
,
pBlock
->
info
.
rows
,
NULL
,
true
);
}
else
{
}
else
{
return
TSDB_CODE_VND_OUT_OF_MEMORY
;
char
*
pData
=
colDataGet
(
pSrcColInfo
,
*
rowIndex
);
colDataAppend
(
pColInfo
,
pBlock
->
info
.
rows
,
pData
,
false
);
}
}
pBlock
->
info
.
rows
+=
1
;
*
rowIndex
+=
1
;
}
static
int32_t
doAddNewSource
(
SOrderOperatorInfo
*
pInfo
,
SArray
*
pAllSources
,
int32_t
numOfCols
)
{
SExternalMemSource
*
pSource
=
calloc
(
1
,
sizeof
(
SExternalMemSource
));
if
(
pSource
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
pSource
->
pageIdList
=
getDataBufPagesIdList
(
pInfo
->
pSortInternalBuf
,
pInfo
->
sourceId
);
pSource
->
sourceId
=
pInfo
->
sourceId
;
pSource
->
pBlock
=
calloc
(
1
,
sizeof
(
SSDataBlock
));
pSource
->
pBlock
->
pDataBlock
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumnInfoData
));
pSource
->
pBlock
->
info
.
numOfCols
=
numOfCols
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
colInfo
=
{
0
};
SColumnInfoData
*
p
=
taosArrayGet
(
pInfo
->
pDataBlock
->
pDataBlock
,
i
);
colInfo
.
info
=
p
->
info
;
taosArrayPush
(
pSource
->
pBlock
->
pDataBlock
,
&
colInfo
);
}
taosArrayPush
(
pAllSources
,
&
pSource
);
pInfo
->
sourceId
+=
1
;
int32_t
rowSize
=
blockDataGetSerialRowSize
(
pSource
->
pBlock
);
int32_t
numOfRows
=
(
getBufPageSize
(
pInfo
->
pSortInternalBuf
)
-
blockDataGetSerialMetaSize
(
pInfo
->
pDataBlock
))
/
rowSize
;
return
blockDataEnsureCapacity
(
pSource
->
pBlock
,
numOfRows
);
}
void
addToDiskbasedBuf
(
SOrderOperatorInfo
*
pInfo
,
SArray
*
pSources
,
jmp_buf
env
)
{
int32_t
start
=
0
;
while
(
start
<
pInfo
->
pDataBlock
->
info
.
rows
)
{
int32_t
stop
=
0
;
blockDataSplitRows
(
pInfo
->
pDataBlock
,
pInfo
->
hasVarCol
,
start
,
&
stop
,
getBufPageSize
(
pInfo
->
pSortInternalBuf
));
SSDataBlock
*
p
=
blockDataExtractBlock
(
pInfo
->
pDataBlock
,
start
,
stop
-
start
+
1
);
if
(
p
==
NULL
)
{
longjmp
(
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
int32_t
pageId
=
-
1
;
SFilePage
*
pPage
=
getNewDataBuf
(
pInfo
->
pSortInternalBuf
,
pInfo
->
sourceId
,
&
pageId
);
if
(
pPage
==
NULL
)
{
assert
(
0
);
longjmp
(
env
,
terrno
);
}
int32_t
size
=
blockDataGetSize
(
p
)
+
sizeof
(
int32_t
)
+
p
->
info
.
numOfCols
*
sizeof
(
int32_t
);
assert
(
size
<=
getBufPageSize
(
pInfo
->
pSortInternalBuf
));
blockDataToBuf
(
pPage
->
data
,
p
);
setBufPageDirty
(
pPage
,
true
);
releaseBufPage
(
pInfo
->
pSortInternalBuf
,
pPage
);
blockDataDestroy
(
p
);
start
=
stop
+
1
;
}
int32_t
numOfCols
=
pInfo
->
pDataBlock
->
info
.
numOfCols
;
blockDataClearup
(
pInfo
->
pDataBlock
,
pInfo
->
hasVarCol
);
int32_t
code
=
doAddNewSource
(
pInfo
,
pSources
,
numOfCols
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
env
,
code
);
}
}
}
static
int32_t
sortComparInit
(
SMsortComparParam
*
cmpParam
,
SArray
*
pSources
,
int32_t
startIndex
,
int32_t
endIndex
,
SDiskbasedBuf
*
pBuf
)
{
cmpParam
->
pSources
=
taosArrayGet
(
pSources
,
startIndex
);
cmpParam
->
numOfSources
=
(
endIndex
-
startIndex
+
1
);
for
(
int32_t
i
=
0
;
i
<
cmpParam
->
numOfSources
;
++
i
)
{
SExternalMemSource
*
pSource
=
cmpParam
->
pSources
[
i
];
SPageInfo
*
pPgInfo
=
*
(
SPageInfo
**
)
taosArrayGet
(
pSource
->
pageIdList
,
pSource
->
pageIndex
);
SFilePage
*
pPage
=
getBufPage
(
pBuf
,
getPageId
(
pPgInfo
));
int32_t
code
=
blockDataFromBuf
(
cmpParam
->
pSources
[
i
]
->
pBlock
,
pPage
->
data
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
pDest
->
info
.
rows
+=
pSrc
->
info
.
rows
;
releaseBufPage
(
pBuf
,
pPage
);
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
sortComparClearup
(
SMsortComparParam
*
cmpParam
)
{
for
(
int32_t
i
=
0
;
i
<
cmpParam
->
numOfSources
;
++
i
)
{
SExternalMemSource
*
pSource
=
cmpParam
->
pSources
[
i
];
blockDataDestroy
(
pSource
->
pBlock
);
tfree
(
pSource
);
}
cmpParam
->
numOfSources
=
0
;
}
static
SSDataBlock
*
getSortedBlockData
(
SExecTaskInfo
*
pTaskInfo
,
SOrderOperatorInfo
*
pInfo
,
SMsortComparParam
*
cmpParam
,
int32_t
capacity
)
{
blockDataClearup
(
pInfo
->
pDataBlock
,
pInfo
->
hasVarCol
);
while
(
1
)
{
if
(
cmpParam
->
numOfSources
==
pInfo
->
numOfCompleted
)
{
break
;
}
int32_t
index
=
tMergeTreeGetChosenIndex
(
pInfo
->
pMergeTree
);
SExternalMemSource
*
pSource
=
(
*
cmpParam
).
pSources
[
index
];
appendOneRowToDataBlock
(
pInfo
->
pDataBlock
,
pSource
->
pBlock
,
&
pSource
->
rowIndex
);
int32_t
code
=
adjustMergeTreeForNextTuple
(
pSource
,
pInfo
->
pMergeTree
,
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
if
(
pInfo
->
pDataBlock
->
info
.
rows
>=
capacity
)
{
return
pInfo
->
pDataBlock
;
}
}
return
(
pInfo
->
pDataBlock
->
info
.
rows
>
0
)
?
pInfo
->
pDataBlock
:
NULL
;
}
static
int32_t
doInternalSort
(
SExecTaskInfo
*
pTaskInfo
,
SOrderOperatorInfo
*
pInfo
)
{
size_t
numOfSources
=
taosArrayGetSize
(
pInfo
->
pSources
);
// Calculate the I/O counts to complete the data sort.
double
sortCount
=
floorl
(
log2
(
numOfSources
)
/
log2
(
getNumOfInMemBufPages
(
pInfo
->
pSortInternalBuf
)));
pInfo
->
totalElapsed
=
taosGetTimestampUs
()
-
pInfo
->
startTs
;
qDebug
(
"%s %d rounds mergesort required to complete the sort, first-round sorted data size:%"
PRIzu
", sort:%"
PRId64
", total elapsed:%"
PRId64
,
GET_TASKID
(
pTaskInfo
),
(
int32_t
)
(
sortCount
+
1
),
getTotalBufSize
(
pInfo
->
pSortInternalBuf
),
pInfo
->
sortElapsed
,
pInfo
->
totalElapsed
);
size_t
pgSize
=
getBufPageSize
(
pInfo
->
pSortInternalBuf
);
int32_t
numOfRows
=
(
pgSize
-
blockDataGetSerialMetaSize
(
pInfo
->
pDataBlock
))
/
blockDataGetSerialRowSize
(
pInfo
->
pDataBlock
);
blockDataEnsureCapacity
(
pInfo
->
pDataBlock
,
numOfRows
);
size_t
numOfSorted
=
taosArrayGetSize
(
pInfo
->
pSources
);
for
(
int32_t
t
=
0
;
t
<
sortCount
;
++
t
)
{
int64_t
st
=
taosGetTimestampUs
();
SArray
*
pResList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
SMsortComparParam
resultParam
=
{.
orderInfo
=
pInfo
->
cmpParam
.
orderInfo
};
int32_t
numOfInputSources
=
getNumOfInMemBufPages
(
pInfo
->
pSortInternalBuf
);
int32_t
sortGroup
=
(
numOfSorted
+
numOfInputSources
-
1
)
/
numOfInputSources
;
// Only *numOfInputSources* can be loaded into buffer to perform the external sort.
for
(
int32_t
i
=
0
;
i
<
sortGroup
;
++
i
)
{
pInfo
->
sourceId
+=
1
;
int32_t
end
=
(
i
+
1
)
*
numOfInputSources
-
1
;
if
(
end
>
numOfSorted
-
1
)
{
end
=
numOfSorted
-
1
;
}
pInfo
->
cmpParam
.
numOfSources
=
end
-
i
*
numOfInputSources
+
1
;
int32_t
code
=
sortComparInit
(
&
pInfo
->
cmpParam
,
pInfo
->
pSources
,
i
*
numOfInputSources
,
end
,
pInfo
->
pSortInternalBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
code
=
tMergeTreeCreate
(
&
pInfo
->
pMergeTree
,
pInfo
->
cmpParam
.
numOfSources
,
&
pInfo
->
cmpParam
,
msortComparFn
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
while
(
1
)
{
SSDataBlock
*
pDataBlock
=
getSortedBlockData
(
pTaskInfo
,
pInfo
,
&
pInfo
->
cmpParam
,
numOfRows
);
if
(
pDataBlock
==
NULL
)
{
break
;
}
int32_t
pageId
=
-
1
;
SFilePage
*
pPage
=
getNewDataBuf
(
pInfo
->
pSortInternalBuf
,
pInfo
->
sourceId
,
&
pageId
);
if
(
pPage
==
NULL
)
{
assert
(
0
);
longjmp
(
pTaskInfo
->
env
,
terrno
);
}
int32_t
size
=
blockDataGetSize
(
pDataBlock
)
+
sizeof
(
int32_t
)
+
pDataBlock
->
info
.
numOfCols
*
sizeof
(
int32_t
);
assert
(
size
<=
getBufPageSize
(
pInfo
->
pSortInternalBuf
));
blockDataToBuf
(
pPage
->
data
,
pDataBlock
);
setBufPageDirty
(
pPage
,
true
);
releaseBufPage
(
pInfo
->
pSortInternalBuf
,
pPage
);
blockDataClearup
(
pDataBlock
,
pInfo
->
hasVarCol
);
}
tMergeTreeDestroy
(
pInfo
->
pMergeTree
);
pInfo
->
numOfCompleted
=
0
;
code
=
doAddNewSource
(
pInfo
,
pResList
,
pInfo
->
pDataBlock
->
info
.
numOfCols
);
if
(
code
!=
0
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
}
sortComparClearup
(
&
pInfo
->
cmpParam
);
taosArrayClear
(
pInfo
->
pSources
);
taosArrayAddAll
(
pInfo
->
pSources
,
pResList
);
taosArrayDestroy
(
pResList
);
pInfo
->
cmpParam
=
resultParam
;
numOfSorted
=
taosArrayGetSize
(
pInfo
->
pSources
);
int64_t
el
=
taosGetTimestampUs
()
-
st
;
pInfo
->
totalElapsed
+=
el
;
SDiskbasedBufStatis
statis
=
getDBufStatis
(
pInfo
->
pSortInternalBuf
);
qDebug
(
"%s %d round mergesort, elapsed:%"
PRId64
" readDisk:%.2f Kb, flushDisk:%.2f Kb"
,
GET_TASKID
(
pTaskInfo
),
t
+
1
,
el
,
statis
.
loadBytes
/
1024
.
0
,
statis
.
flushBytes
/
1024
.
0
);
}
pInfo
->
cmpParam
.
numOfSources
=
taosArrayGetSize
(
pInfo
->
pSources
);
return
0
;
}
static
SSDataBlock
*
doSort
(
void
*
param
,
bool
*
newgroup
)
{
static
SSDataBlock
*
doSort
(
void
*
param
,
bool
*
newgroup
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
return
NULL
;
}
}
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SOrderOperatorInfo
*
pInfo
=
pOperator
->
info
;
SOrderOperatorInfo
*
pInfo
=
pOperator
->
info
;
SSDataBlock
*
pBlock
=
NULL
;
SSDataBlock
*
pBlock
=
NULL
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
return
getSortedBlockData
(
pTaskInfo
,
pInfo
,
&
pInfo
->
cmpParam
,
pInfo
->
numOfRowsInRes
);
}
int64_t
st
=
taosGetTimestampUs
();
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
pOperator
->
pDownstream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDownstream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDownstream
[
0
],
newgroup
);
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDownstream
[
0
],
newgroup
);
...
@@ -5759,68 +6118,130 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
...
@@ -5759,68 +6118,130 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
// start to flush data into disk and try do multiway merge sort
// start to flush data into disk and try do multiway merge sort
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
doSetOperatorCompleted
(
pOperator
);
break
;
break
;
}
}
int32_t
code
=
doMergeSDatablock
(
pInfo
->
pDataBlock
,
pBlock
);
int32_t
code
=
blockDataMerge
(
pInfo
->
pDataBlock
,
pBlock
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// todo handle error
longjmp
(
pOperator
->
pTaskInfo
->
env
,
code
);
}
size_t
size
=
blockDataGetSize
(
pInfo
->
pDataBlock
);
if
(
size
>
pInfo
->
sortBufSize
)
{
// Perform the in-memory sort and then flush data in the buffer into disk.
int64_t
p
=
taosGetTimestampUs
();
blockDataSort
(
pInfo
->
pDataBlock
,
pInfo
->
cmpParam
.
orderInfo
,
pInfo
->
cmpParam
.
nullFirst
);
int64_t
el
=
taosGetTimestampUs
()
-
p
;
pInfo
->
sortElapsed
+=
el
;
addToDiskbasedBuf
(
pInfo
,
pInfo
->
pSources
,
pTaskInfo
->
env
);
}
}
}
}
i
nt32_t
numOfCols
=
pInfo
->
pDataBlock
->
info
.
numOfCols
;
i
f
(
pInfo
->
pDataBlock
->
info
.
rows
>
0
)
{
void
**
pCols
=
calloc
(
numOfCols
,
POINTER_BYTES
);
// Perform the in-memory sort and then flush data in the buffer into disk.
SSchema
*
pSchema
=
calloc
(
numOfCols
,
sizeof
(
SSchema
)
);
blockDataSort
(
pInfo
->
pDataBlock
,
pInfo
->
cmpParam
.
orderInfo
,
pInfo
->
cmpParam
.
nullFirst
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
// All sorted data are resident in memory, external memory sort is not needed.
SColumnInfoData
*
p1
=
taosArrayGet
(
pInfo
->
pDataBlock
->
pDataBlock
,
i
);
// Return to the upstream operator directly
pCols
[
i
]
=
p1
->
pData
;
if
(
isAllDataInMemBuf
(
pInfo
->
pSortInternalBuf
))
{
pSchema
[
i
].
colId
=
p1
->
info
.
colId
;
pOperator
->
status
=
OP_EXEC_DONE
;
pSchema
[
i
].
bytes
=
p1
->
info
.
bytes
;
return
(
pInfo
->
pDataBlock
->
info
.
rows
==
0
)
?
NULL
:
pInfo
->
pDataBlock
;
pSchema
[
i
].
type
=
(
uint8_t
)
p1
->
info
.
type
;
}
addToDiskbasedBuf
(
pInfo
,
pInfo
->
pSources
,
pTaskInfo
->
env
);
}
}
__compar_fn_t
comp
=
getKeyComparFunc
(
pSchema
[
pInfo
->
colIndex
].
type
,
pInfo
->
order
);
doInternalSort
(
pTaskInfo
,
pInfo
);
// taosqsort(pCols, pSchema, numOfCols, pInfo->pDataBlock->info.rows, pInfo->colIndex, comp);
tfree
(
pCols
);
int32_t
code
=
blockDataEnsureCapacity
(
pInfo
->
pDataBlock
,
pInfo
->
numOfRowsInRes
);
tfree
(
pSchema
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
(
pInfo
->
pDataBlock
->
info
.
rows
>
0
)
?
pInfo
->
pDataBlock
:
NULL
;
longjmp
(
pTaskInfo
->
env
,
code
);
}
int32_t
numOfSources
=
taosArrayGetSize
(
pInfo
->
pSources
);
ASSERT
(
numOfSources
<=
getNumOfInMemBufPages
(
pInfo
->
pSortInternalBuf
));
code
=
sortComparInit
(
&
pInfo
->
cmpParam
,
pInfo
->
pSources
,
0
,
numOfSources
-
1
,
pInfo
->
pSortInternalBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
code
=
tMergeTreeCreate
(
&
pInfo
->
pMergeTree
,
pInfo
->
cmpParam
.
numOfSources
,
&
pInfo
->
cmpParam
,
msortComparFn
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
pOperator
->
status
=
OP_RES_TO_RETURN
;
return
getSortedBlockData
(
pTaskInfo
,
pInfo
,
&
pInfo
->
cmpParam
,
pInfo
->
numOfRowsInRes
);
}
}
SOperatorInfo
*
createOrderOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOrder
*
pOrderVal
)
{
static
SArray
*
createBlockOrder
(
SArray
*
pExprInfo
,
SArray
*
pOrderVal
)
{
S
OrderOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SOrderOperato
rInfo
));
S
Array
*
pOrderInfo
=
taosArrayInit
(
1
,
sizeof
(
SBlockOrde
rInfo
));
{
size_t
numOfOrder
=
taosArrayGetSize
(
pOrderVal
);
SSDataBlock
*
pDataBlock
=
calloc
(
1
,
sizeof
(
SSDataBlock
));
for
(
int32_t
j
=
0
;
j
<
numOfOrder
;
++
j
)
{
pDataBlock
->
pDataBlock
=
taosArrayInit
(
numOfOutput
,
sizeof
(
SColumnInfoData
));
SBlockOrderInfo
orderInfo
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
SOrder
*
pOrder
=
taosArrayGet
(
pOrderVal
,
j
);
SColumnInfoData
col
=
{{
0
}};
orderInfo
.
order
=
pOrder
->
order
;
col
.
info
.
colId
=
pExpr
[
i
].
base
.
pColumns
->
info
.
colId
;
// col.info.bytes = pExpr[i].base.colBytes;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pExprInfo
);
++
i
)
{
// col.info.type = pExpr[i].base.colType;
SExprInfo
*
pExpr
=
taosArrayGet
(
pExprInfo
,
i
);
taosArrayPush
(
pDataBlock
->
pDataBlock
,
&
col
);
if
(
pExpr
->
base
.
resSchema
.
colId
==
pOrder
->
col
.
info
.
colId
)
{
orderInfo
.
colIndex
=
i
;
// if (col.info.colId == pOrderVal->orderColId) {
break
;
// pInfo->colIndex = i;
// }
}
}
}
pDataBlock
->
info
.
numOfCols
=
numOfOutput
;
taosArrayPush
(
pOrderInfo
,
&
orderInfo
);
// pInfo->order = pOrderVal->order;
pInfo
->
pDataBlock
=
pDataBlock
;
}
}
return
pOrderInfo
;
}
SOperatorInfo
*
createOrderOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SArray
*
pOrderVal
)
{
SOrderOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SOrderOperatorInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"InMemoryOrder"
;
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
// pOperator->operatorType = OP_Order;
tfree
(
pInfo
);
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
NULL
;
}
pInfo
->
sortBufSize
=
1024
*
16
;
// 1MB
pInfo
->
bufPageSize
=
1024
;
pInfo
->
numOfRowsInRes
=
1024
;
pInfo
->
pDataBlock
=
createOutputBuf_rv
(
pExprInfo
,
pInfo
->
numOfRowsInRes
);
pInfo
->
pSources
=
taosArrayInit
(
4
,
POINTER_BYTES
);
pInfo
->
cmpParam
.
orderInfo
=
createBlockOrder
(
pExprInfo
,
pOrderVal
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pExprInfo
);
++
i
)
{
SExprInfo
*
pExpr
=
taosArrayGetP
(
pExprInfo
,
i
);
if
(
IS_VAR_DATA_TYPE
(
pExpr
->
base
.
resSchema
.
type
))
{
pInfo
->
hasVarCol
=
true
;
break
;
}
}
int32_t
code
=
createDiskbasedBuffer
(
&
pInfo
->
pSortInternalBuf
,
pInfo
->
bufPageSize
,
pInfo
->
sortBufSize
,
1
,
"/tmp/"
);
if
(
pInfo
->
pSources
==
NULL
||
code
!=
0
||
pInfo
->
cmpParam
.
orderInfo
==
NULL
||
pInfo
->
pDataBlock
==
NULL
)
{
tfree
(
pOperator
);
destroyOrderOperatorInfo
(
pInfo
,
taosArrayGetSize
(
pExprInfo
));
tfree
(
pInfo
);
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
NULL
;
}
pOperator
->
name
=
"Order"
;
pOperator
->
operatorType
=
OP_Order
;
pOperator
->
blockingOptr
=
true
;
pOperator
->
blockingOptr
=
true
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
pOperator
->
exec
=
doSort
;
pOperator
->
exec
=
doSort
;
pOperator
->
cleanupFn
=
destroyOrderOperatorInfo
;
pOperator
->
cleanupFn
=
destroyOrderOperatorInfo
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
appendDownstream
(
pOperator
,
downstream
);
appendDownstream
(
pOperator
,
downstream
);
return
pOperator
;
return
pOperator
;
...
@@ -5869,7 +6290,7 @@ static SSDataBlock* doAggregate(void* param, bool* newgroup) {
...
@@ -5869,7 +6290,7 @@ static SSDataBlock* doAggregate(void* param, bool* newgroup) {
return
(
pInfo
->
pRes
->
info
.
rows
!=
0
)
?
pInfo
->
pRes
:
NULL
;
return
(
pInfo
->
pRes
->
info
.
rows
!=
0
)
?
pInfo
->
pRes
:
NULL
;
}
}
static
SSDataBlock
*
do
S
TableAggregate
(
void
*
param
,
bool
*
newgroup
)
{
static
SSDataBlock
*
do
Multi
TableAggregate
(
void
*
param
,
bool
*
newgroup
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
return
NULL
;
...
@@ -5877,22 +6298,20 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
...
@@ -5877,22 +6298,20 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toS
SDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
pRes
);
toS
Datablock
(
&
pAggInfo
->
groupResInfo
,
pAggInfo
->
pResultBuf
,
pInfo
->
pRes
,
pAggInfo
->
binfo
.
capacity
);
if
(
pInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
p
RuntimeEnv
->
groupResInfo
))
{
if
(
pInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
p
AggInfo
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
}
}
return
pInfo
->
pRes
;
return
pInfo
->
pRes
;
}
}
STaskAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
// table scan order
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
TSDB_ORDER_ASC
;
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
while
(
1
)
{
while
(
1
)
{
...
@@ -5904,9 +6323,8 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
...
@@ -5904,9 +6323,8 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
break
;
break
;
}
}
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfOutput);
// if (downstream->operatorType == OP_TableScan) {
// if (downstream->operatorType == OP_DataBlocksOptScan) {
// STableScanInfo* pScanInfo = downstream->info;
// STableScanInfo* pScanInfo = downstream->info;
// order = getTableScanOrder(pScanInfo);
// order = getTableScanOrder(pScanInfo);
// }
// }
...
@@ -5915,7 +6333,7 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
...
@@ -5915,7 +6333,7 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
);
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
);
TSKEY
key
=
0
;
TSKEY
key
=
0
;
if
(
QUERY_IS_ASC_QUERY
(
pQueryAttr
)
)
{
if
(
order
==
TSDB_ORDER_ASC
)
{
key
=
pBlock
->
info
.
window
.
ekey
;
key
=
pBlock
->
info
.
window
.
ekey
;
TSKEY_MAX_ADD
(
key
,
1
);
TSKEY_MAX_ADD
(
key
,
1
);
}
else
{
}
else
{
...
@@ -5923,20 +6341,18 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
...
@@ -5923,20 +6341,18 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
TSKEY_MIN_SUB
(
key
,
-
1
);
TSKEY_MIN_SUB
(
key
,
-
1
);
}
}
setExecutionContext
(
p
RuntimeEnv
,
pInfo
,
pOperator
->
numOfOutput
,
pRuntimeEnv
->
current
->
groupIndex
,
key
);
setExecutionContext
(
p
Operator
->
numOfOutput
,
pAggInfo
->
current
->
groupIndex
,
key
,
pTaskInfo
,
pAggInfo
->
current
,
pAggInfo
);
doAggregateImpl
(
pOperator
,
pQueryAttr
->
window
.
skey
,
pInfo
->
pCtx
,
pBlock
);
doAggregateImpl
(
pOperator
,
0
,
pInfo
->
pCtx
,
pBlock
);
}
}
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
closeAllResultRows
(
&
pInfo
->
resultRowInfo
);
closeAllResultRows
(
&
pInfo
->
resultRowInfo
);
updateNumOfRowsInResultRows
(
pInfo
->
pCtx
,
pOperator
->
numOfOutput
,
&
pInfo
->
resultRowInfo
,
pInfo
->
rowCellInfoOffset
);
updateNumOfRowsInResultRows
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
,
&
pInfo
->
resultRowInfo
,
initGroupResInfo
(
&
pAggInfo
->
groupResInfo
,
&
pInfo
->
resultRowInfo
);
pInfo
->
rowCellInfoOffset
);
toSDatablock
(
&
pAggInfo
->
groupResInfo
,
pAggInfo
->
pResultBuf
,
pInfo
->
pRes
,
pAggInfo
->
binfo
.
capacity
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pInfo
->
resultRowInfo
);
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
pRes
);
if
(
pInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pAggInfo
->
groupResInfo
))
{
if
(
pInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
doSetOperatorCompleted
(
pOperator
);
doSetOperatorCompleted
(
pOperator
);
}
}
...
@@ -5964,7 +6380,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
...
@@ -5964,7 +6380,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
// todo dynamic set tags
// todo dynamic set tags
if
(
pTableQueryInfo
!=
NULL
)
{
if
(
pTableQueryInfo
!=
NULL
)
{
setTagValue
(
pOperator
,
pTableQueryInfo
->
pTable
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
//
setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput);
}
}
// the pDataBlock are always the same one, no need to call this again
// the pDataBlock are always the same one, no need to call this again
...
@@ -6014,7 +6430,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
...
@@ -6014,7 +6430,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
// todo dynamic set tags
// todo dynamic set tags
if
(
pTableQueryInfo
!=
NULL
)
{
if
(
pTableQueryInfo
!=
NULL
)
{
setTagValue
(
pOperator
,
pTableQueryInfo
->
pTable
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
//
setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput);
}
}
// the pDataBlock are always the same one, no need to call this again
// the pDataBlock are always the same one, no need to call this again
...
@@ -6125,7 +6541,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
...
@@ -6125,7 +6541,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
// toSDatablock(pAggInfo->pGroupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity
);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
doSetOperatorCompleted
(
pOperator
);
doSetOperatorCompleted
(
pOperator
);
}
}
...
@@ -6148,7 +6564,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
...
@@ -6148,7 +6564,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
break
;
break
;
}
}
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pIntervalInfo
->
pCtx
,
pOperator
->
numOfOutput
);
//
setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput);
// the pDataBlock are always the same one, no need to call this again
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
...
@@ -6165,7 +6581,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
...
@@ -6165,7 +6581,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
finalizeQueryResult
(
pOperator
,
pIntervalInfo
->
pCtx
,
&
pIntervalInfo
->
resultRowInfo
,
pIntervalInfo
->
rowCellInfoOffset
);
finalizeQueryResult
(
pOperator
,
pIntervalInfo
->
pCtx
,
&
pIntervalInfo
->
resultRowInfo
,
pIntervalInfo
->
rowCellInfoOffset
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pIntervalInfo
->
resultRowInfo
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pIntervalInfo
->
resultRowInfo
);
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
doSetOperatorCompleted
(
pOperator
);
doSetOperatorCompleted
(
pOperator
);
...
@@ -6184,7 +6600,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
...
@@ -6184,7 +6600,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
doSetOperatorCompleted
(
pOperator
);
doSetOperatorCompleted
(
pOperator
);
...
@@ -6208,7 +6624,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
...
@@ -6208,7 +6624,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
break
;
break
;
}
}
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pIntervalInfo
->
pCtx
,
pOperator
->
numOfOutput
);
//
setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput);
// the pDataBlock are always the same one, no need to call this again
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
...
@@ -6225,7 +6641,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
...
@@ -6225,7 +6641,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
finalizeQueryResult
(
pOperator
,
pIntervalInfo
->
pCtx
,
&
pIntervalInfo
->
resultRowInfo
,
pIntervalInfo
->
rowCellInfoOffset
);
finalizeQueryResult
(
pOperator
,
pIntervalInfo
->
pCtx
,
&
pIntervalInfo
->
resultRowInfo
,
pIntervalInfo
->
rowCellInfoOffset
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pIntervalInfo
->
resultRowInfo
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pIntervalInfo
->
resultRowInfo
);
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
...
@@ -6246,7 +6662,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -6246,7 +6662,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
copyToSDataBlock
(
pRuntimeEnv
,
3000
,
pIntervalInfo
->
pRes
,
pIntervalInfo
->
rowCellInfoOffset
);
// copyToSDataBlock(NULL
, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
doSetOperatorCompleted
(
pOperator
);
doSetOperatorCompleted
(
pOperator
);
}
}
...
@@ -6274,7 +6690,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -6274,7 +6690,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
// the pDataBlock are always the same one, no need to call this again
// the pDataBlock are always the same one, no need to call this again
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
setTagValue
(
pOperator
,
pTableQueryInfo
->
pTable
,
pIntervalInfo
->
pCtx
,
pOperator
->
numOfOutput
);
//
setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput);
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
setIntervalQueryRange
(
pRuntimeEnv
,
pBlock
->
info
.
window
.
skey
);
setIntervalQueryRange
(
pRuntimeEnv
,
pBlock
->
info
.
window
.
skey
);
...
@@ -6286,7 +6702,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -6286,7 +6702,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
doCloseAllTimeWindow
(
pRuntimeEnv
);
doCloseAllTimeWindow
(
pRuntimeEnv
);
setTaskStatus
(
pOperator
->
pTaskInfo
,
TASK_COMPLETED
);
setTaskStatus
(
pOperator
->
pTaskInfo
,
TASK_COMPLETED
);
copyToSDataBlock
(
pRuntimeEnv
,
3000
,
pIntervalInfo
->
pRes
,
pIntervalInfo
->
rowCellInfoOffset
);
//
copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
}
}
...
@@ -6304,7 +6720,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -6304,7 +6720,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
copyToSDataBlock
(
pRuntimeEnv
,
3000
,
pIntervalInfo
->
pRes
,
pIntervalInfo
->
rowCellInfoOffset
);
//
copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
}
}
...
@@ -6329,7 +6745,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -6329,7 +6745,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
// the pDataBlock are always the same one, no need to call this again
// the pDataBlock are always the same one, no need to call this again
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
setTagValue
(
pOperator
,
pTableQueryInfo
->
pTable
,
pIntervalInfo
->
pCtx
,
pOperator
->
numOfOutput
);
//
setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput);
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
setInputDataBlock
(
pOperator
,
pIntervalInfo
->
pCtx
,
pBlock
,
pQueryAttr
->
order
.
order
);
setIntervalQueryRange
(
pRuntimeEnv
,
pBlock
->
info
.
window
.
skey
);
setIntervalQueryRange
(
pRuntimeEnv
,
pBlock
->
info
.
window
.
skey
);
...
@@ -6342,7 +6758,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -6342,7 +6758,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
setTaskStatus
(
pOperator
->
pTaskInfo
,
TASK_COMPLETED
);
setTaskStatus
(
pOperator
->
pTaskInfo
,
TASK_COMPLETED
);
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
copyToSDataBlock
(
pRuntimeEnv
,
3000
,
pIntervalInfo
->
pRes
,
pIntervalInfo
->
rowCellInfoOffset
);
//
copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainData
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
}
}
...
@@ -6439,7 +6855,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
...
@@ -6439,7 +6855,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes);
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
...
@@ -6477,7 +6893,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
...
@@ -6477,7 +6893,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
finalizeQueryResult
(
pOperator
,
pBInfo
->
pCtx
,
&
pBInfo
->
resultRowInfo
,
pBInfo
->
rowCellInfoOffset
);
finalizeQueryResult
(
pOperator
,
pBInfo
->
pCtx
,
&
pBInfo
->
resultRowInfo
,
pBInfo
->
rowCellInfoOffset
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pBInfo
->
resultRowInfo
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pBInfo
->
resultRowInfo
);
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes);
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
...
@@ -6498,7 +6914,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
...
@@ -6498,7 +6914,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes);
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
...
@@ -6537,7 +6953,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
...
@@ -6537,7 +6953,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
finalizeQueryResult
(
pOperator
,
pBInfo
->
pCtx
,
&
pBInfo
->
resultRowInfo
,
pBInfo
->
rowCellInfoOffset
);
finalizeQueryResult
(
pOperator
,
pBInfo
->
pCtx
,
&
pBInfo
->
resultRowInfo
,
pBInfo
->
rowCellInfoOffset
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pBInfo
->
resultRowInfo
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pBInfo
->
resultRowInfo
);
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes);
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pBInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
...
@@ -6556,7 +6972,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6556,7 +6972,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataB
lock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
binfo
.
pRes
);
// toSDatab
lock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes);
if
(
pInfo
->
binfo
.
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pInfo
->
binfo
.
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
...
@@ -6577,7 +6993,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6577,7 +6993,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
// the pDataBlock are always the same one, no need to call this again
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pInfo
->
binfo
.
pCtx
,
pBlock
,
pRuntimeEnv
->
pQueryAttr
->
order
.
order
);
setInputDataBlock
(
pOperator
,
pInfo
->
binfo
.
pCtx
,
pBlock
,
pRuntimeEnv
->
pQueryAttr
->
order
.
order
);
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
);
//
setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput);
if
(
pInfo
->
colIndex
==
-
1
)
{
if
(
pInfo
->
colIndex
==
-
1
)
{
pInfo
->
colIndex
=
getGroupbyColumnIndex
(
pRuntimeEnv
->
pQueryAttr
->
pGroupbyExpr
,
pBlock
);
pInfo
->
colIndex
=
getGroupbyColumnIndex
(
pRuntimeEnv
->
pQueryAttr
->
pGroupbyExpr
,
pBlock
);
}
}
...
@@ -6592,7 +7008,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6592,7 +7008,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
if
(
!
pRuntimeEnv
->
pQueryAttr
->
stableQuery
)
{
// finalize include the update of result rows
if
(
!
pRuntimeEnv
->
pQueryAttr
->
stableQuery
)
{
// finalize include the update of result rows
finalizeQueryResult
(
pOperator
,
pInfo
->
binfo
.
pCtx
,
&
pInfo
->
binfo
.
resultRowInfo
,
pInfo
->
binfo
.
rowCellInfoOffset
);
finalizeQueryResult
(
pOperator
,
pInfo
->
binfo
.
pCtx
,
&
pInfo
->
binfo
.
resultRowInfo
,
pInfo
->
binfo
.
rowCellInfoOffset
);
}
else
{
}
else
{
updateNumOfRowsInResultRows
(
p
RuntimeEnv
,
p
Info
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
&
pInfo
->
binfo
.
resultRowInfo
,
pInfo
->
binfo
.
rowCellInfoOffset
);
updateNumOfRowsInResultRows
(
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
&
pInfo
->
binfo
.
resultRowInfo
,
pInfo
->
binfo
.
rowCellInfoOffset
);
}
}
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pInfo
->
binfo
.
resultRowInfo
);
initGroupResInfo
(
&
pRuntimeEnv
->
groupResInfo
,
&
pInfo
->
binfo
.
resultRowInfo
);
...
@@ -6600,8 +7016,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6600,8 +7016,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
sortGroupResByOrderList
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
binfo
.
pRes
);
sortGroupResByOrderList
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
binfo
.
pRes
);
}
}
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
binfo
.
pRes
);
// toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes);
if
(
pInfo
->
binfo
.
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pInfo
->
binfo
.
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
}
}
...
@@ -6745,41 +7160,67 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
...
@@ -6745,41 +7160,67 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
tfree
(
pOperator
);
tfree
(
pOperator
);
}
}
SOperatorInfo
*
createAggregateOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
static
int32_t
initAggInfo
(
SAggOperatorInfo
*
pInfo
,
SArray
*
pExprInfo
,
int32_t
numOfRows
,
const
STableGroupInfo
*
pTableGroupInfo
)
{
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
int32_t
numOfRows
=
1
;
//(int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery));
size_t
numOfOutput
=
taosArrayGetSize
(
pExprInfo
);
pInfo
->
binfo
.
pRes
=
createOutputBuf_rv
(
pExprInfo
,
numOfRows
);
pInfo
->
binfo
.
pRes
=
createOutputBuf_rv
(
pExprInfo
,
numOfRows
);
pInfo
->
binfo
.
pCtx
=
createSqlFunctionCtx_rv
(
pExprInfo
,
&
pInfo
->
binfo
.
rowCellInfoOffset
);
pInfo
->
binfo
.
pCtx
=
createSqlFunctionCtx_rv
(
pExprInfo
,
&
pInfo
->
binfo
.
rowCellInfoOffset
,
&
pInfo
->
binfo
.
resRowSize
);
pInfo
->
binfo
.
capacity
=
4096
;
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
pInfo
->
pResultRowHashTable
=
taosHashInit
(
10
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
pInfo
->
pResultRowHashTable
=
taosHashInit
(
10
,
hashFn
,
true
,
HASH_NO_LOCK
);
pInfo
->
pResultRowListSet
=
taosHashInit
(
100
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
pInfo
->
pResultRowListSet
=
taosHashInit
(
100
,
hashFn
,
false
,
HASH_NO_LOCK
);
pInfo
->
keyBuf
=
malloc
(
1024
+
sizeof
(
int64_t
)
+
POINTER_BYTES
);
// TODO:
pInfo
->
pool
=
initResultRowPool
(
getResultRowSize
(
pExprInfo
));
pInfo
->
pool
=
initResultRowPool
(
getResultRowSize
(
pExprInfo
));
pInfo
->
pResultRowArrayList
=
taosArrayInit
(
10
,
sizeof
(
SResultRowCell
));
pInfo
->
pResultRowArrayList
=
taosArrayInit
(
10
,
sizeof
(
SResultRowCell
));
initResultRowInfo
(
&
pInfo
->
binfo
.
resultRowInfo
,
8
,
TSDB_DATA_TYPE_INT
);
pInfo
->
pTableQueryInfo
=
calloc
(
pTableGroupInfo
->
numOfTables
,
sizeof
(
STableQueryInfo
)
);
pInfo
->
seed
=
rand
();
int32_t
index
=
0
;
setDefaultOutputBuf_rv
(
pInfo
,
pInfo
->
seed
,
MAIN_SCAN
,
pTaskInfo
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pTableGroupInfo
->
pGroupList
);
++
i
)
{
SArray
*
pa
=
taosArrayGetP
(
pTableGroupInfo
->
pGroupList
,
i
);
for
(
int32_t
j
=
0
;
j
<
taosArrayGetSize
(
pa
);
++
j
)
{
STableKeyInfo
*
pk
=
taosArrayGet
(
pa
,
j
);
STableQueryInfo
*
pTQueryInfo
=
&
pInfo
->
pTableQueryInfo
[
index
++
];
pTQueryInfo
->
uid
=
pk
->
uid
;
pTQueryInfo
->
lastKey
=
pk
->
lastKey
;
pTQueryInfo
->
groupIndex
=
i
;
}
}
STimeWindow
win
=
{
0
,
INT64_MAX
};
createTableQueryInfo
(
pInfo
->
pTableQueryInfo
,
false
,
win
);
return
TSDB_CODE_SUCCESS
;
}
static
SExprInfo
*
exprArrayDup
(
SArray
*
pExprInfo
)
{
size_t
numOfOutput
=
taosArrayGetSize
(
pExprInfo
);
SExprInfo
*
p
=
calloc
(
numOfOutput
,
sizeof
(
SExprInfo
));
SExprInfo
*
p
=
calloc
(
numOfOutput
,
sizeof
(
SExprInfo
));
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pExprInfo
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pExprInfo
);
++
i
)
{
SExprInfo
*
pExpr
=
taosArrayGetP
(
pExprInfo
,
i
);
SExprInfo
*
pExpr
=
taosArrayGetP
(
pExprInfo
,
i
);
assignExprInfo
(
&
p
[
i
],
pExpr
);
assignExprInfo
(
&
p
[
i
],
pExpr
);
}
}
return
p
;
}
SOperatorInfo
*
createAggregateOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
,
const
STableGroupInfo
*
pTableGroupInfo
)
{
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
int32_t
numOfRows
=
1
;
//(int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery));
initAggInfo
(
pInfo
,
pExprInfo
,
numOfRows
,
pTableGroupInfo
);
setDefaultOutputBuf_rv
(
pInfo
,
MAIN_SCAN
,
pTaskInfo
);
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"TableAggregate"
;
pOperator
->
name
=
"TableAggregate"
;
pOperator
->
operatorType
=
OP_Aggregate
;
pOperator
->
operatorType
=
OP_Aggregate
;
pOperator
->
blockingOptr
=
true
;
pOperator
->
blockingOptr
=
true
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
pOperator
->
pExpr
=
p
;
pOperator
->
pExpr
=
exprArrayDup
(
pExprInfo
);
pOperator
->
numOfOutput
=
numOfOutput
;
pOperator
->
numOfOutput
=
taosArrayGetSize
(
pExprInfo
);
pOperator
->
pRuntimeEnv
=
NULL
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
exec
=
doAggregate
;
pOperator
->
exec
=
doAggregate
;
...
@@ -6796,7 +7237,7 @@ static void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput) {
...
@@ -6796,7 +7237,7 @@ static void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput) {
tfree
(
pInfo
->
rowCellInfoOffset
);
tfree
(
pInfo
->
rowCellInfoOffset
);
cleanupResultRowInfo
(
&
pInfo
->
resultRowInfo
);
cleanupResultRowInfo
(
&
pInfo
->
resultRowInfo
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
}
}
static
void
destroyBasicOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyBasicOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
...
@@ -6820,7 +7261,7 @@ static void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -6820,7 +7261,7 @@ static void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) {
static
void
destroySFillOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroySFillOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SFillOperatorInfo
*
pInfo
=
(
SFillOperatorInfo
*
)
param
;
SFillOperatorInfo
*
pInfo
=
(
SFillOperatorInfo
*
)
param
;
pInfo
->
pFillInfo
=
taosDestroyFillInfo
(
pInfo
->
pFillInfo
);
pInfo
->
pFillInfo
=
taosDestroyFillInfo
(
pInfo
->
pFillInfo
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
tfree
(
pInfo
->
p
);
tfree
(
pInfo
->
p
);
}
}
...
@@ -6837,12 +7278,17 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -6837,12 +7278,17 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
static
void
destroyTagScanOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyTagScanOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
STagScanInfo
*
pInfo
=
(
STagScanInfo
*
)
param
;
STagScanInfo
*
pInfo
=
(
STagScanInfo
*
)
param
;
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
}
}
static
void
destroyOrderOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyOrderOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SOrderOperatorInfo
*
pInfo
=
(
SOrderOperatorInfo
*
)
param
;
SOrderOperatorInfo
*
pInfo
=
(
SOrderOperatorInfo
*
)
param
;
pInfo
->
pDataBlock
=
destroyOutputBuf
(
pInfo
->
pDataBlock
);
pInfo
->
pDataBlock
=
blockDataDestroy
(
pInfo
->
pDataBlock
);
taosArrayDestroy
(
pInfo
->
cmpParam
.
orderInfo
);
destroyResultBuf
(
pInfo
->
pSortInternalBuf
);
tMergeTreeDestroy
(
pInfo
->
pMergeTree
);
}
}
static
void
destroyConditionOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
static
void
destroyConditionOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
...
@@ -6855,29 +7301,29 @@ static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -6855,29 +7301,29 @@ static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) {
taosHashCleanup
(
pInfo
->
pSet
);
taosHashCleanup
(
pInfo
->
pSet
);
tfree
(
pInfo
->
buf
);
tfree
(
pInfo
->
buf
);
taosArrayDestroy
(
pInfo
->
pDistinctDataInfo
);
taosArrayDestroy
(
pInfo
->
pDistinctDataInfo
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
blockDataDestroy
(
pInfo
->
pRes
);
}
}
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
S
OperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
,
const
STableGroupInfo
*
pTableGroupInfo
)
{
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
size_t
tableGroup
=
GET_NUM_OF_TABLEGROUP
(
pRuntimeEnv
);
int32_t
numOfRows
=
1
;
size_t
numOfOutput
=
taosArrayGetSize
(
pExprInfo
);
initAggInfo
(
pInfo
,
pExprInfo
,
numOfRows
,
pTableGroupInfo
);
pInfo
->
binfo
.
pRes
=
createOutputBuf
(
pExpr
,
numOfOutput
,
(
int32_t
)
tableGroup
);
size_t
tableGroup
=
taosArrayGetSize
(
pTableGroupInfo
->
pGroupList
);
pInfo
->
binfo
.
pCtx
=
createSqlFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
binfo
.
rowCellInfoOffset
);
initResultRowInfo
(
&
pInfo
->
binfo
.
resultRowInfo
,
(
int32_t
)
tableGroup
,
TSDB_DATA_TYPE_INT
);
initResultRowInfo
(
&
pInfo
->
binfo
.
resultRowInfo
,
(
int32_t
)
tableGroup
,
TSDB_DATA_TYPE_INT
);
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"MultiTableAggregate"
;
pOperator
->
name
=
"MultiTableAggregate"
;
//
pOperator->operatorType = OP_MultiTableAggregate;
pOperator
->
operatorType
=
OP_MultiTableAggregate
;
pOperator
->
blockingOptr
=
true
;
pOperator
->
blockingOptr
=
true
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
pOperator
->
pExpr
=
pExpr
;
pOperator
->
pExpr
=
exprArrayDup
(
pExprInfo
)
;
pOperator
->
numOfOutput
=
numOfOutput
;
pOperator
->
numOfOutput
=
numOfOutput
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
exec
=
do
S
TableAggregate
;
pOperator
->
exec
=
do
Multi
TableAggregate
;
pOperator
->
cleanupFn
=
destroyAggOperatorInfo
;
pOperator
->
cleanupFn
=
destroyAggOperatorInfo
;
appendDownstream
(
pOperator
,
downstream
);
appendDownstream
(
pOperator
,
downstream
);
...
@@ -7719,17 +8165,19 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId) {
...
@@ -7719,17 +8165,19 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId) {
}
}
static
tsdbReaderT
doCreateDataReader
(
STableScanPhyNode
*
pTableScanNode
,
SReadHandle
*
pHandle
,
uint64_t
queryId
,
uint64_t
taskId
);
static
tsdbReaderT
doCreateDataReader
(
STableScanPhyNode
*
pTableScanNode
,
SReadHandle
*
pHandle
,
uint64_t
queryId
,
uint64_t
taskId
);
static
int32_t
doCreateTableGroup
(
void
*
metaHandle
,
int32_t
tableType
,
uint64_t
tableUid
,
STableGroupInfo
*
pGroupInfo
,
uint64_t
queryId
,
uint64_t
taskId
);
static
int32_t
doCreateTableGroup
(
void
*
metaHandle
,
int32_t
tableType
,
uint64_t
tableUid
,
STableGroupInfo
*
pGroupInfo
,
uint64_t
queryId
,
uint64_t
taskId
);
SOperatorInfo
*
doCreateOperatorTreeNode
(
SPhyNode
*
pPhyNode
,
SExecTaskInfo
*
pTaskInfo
,
SReadHandle
*
pHandle
,
uint64_t
queryId
,
uint64_t
taskId
)
{
SOperatorInfo
*
doCreateOperatorTreeNode
(
SPhyNode
*
pPhyNode
,
SExecTaskInfo
*
pTaskInfo
,
SReadHandle
*
pHandle
,
uint64_t
queryId
,
uint64_t
taskId
,
STableGroupInfo
*
pTableGroupInfo
)
{
if
(
pPhyNode
->
pChildren
==
NULL
||
taosArrayGetSize
(
pPhyNode
->
pChildren
)
==
0
)
{
if
(
pPhyNode
->
pChildren
==
NULL
||
taosArrayGetSize
(
pPhyNode
->
pChildren
)
==
0
)
{
if
(
pPhyNode
->
info
.
type
==
OP_
DataBlocksOpt
Scan
)
{
if
(
pPhyNode
->
info
.
type
==
OP_
Table
Scan
)
{
SScanPhyNode
*
pScanPhyNode
=
(
SScanPhyNode
*
)
pPhyNode
;
SScanPhyNode
*
pScanPhyNode
=
(
SScanPhyNode
*
)
pPhyNode
;
size_t
numOfCols
=
taosArrayGetSize
(
pPhyNode
->
pTargets
);
size_t
numOfCols
=
taosArrayGetSize
(
pPhyNode
->
pTargets
);
tsdbReaderT
pDataReader
=
doCreateDataReader
((
STableScanPhyNode
*
)
pPhyNode
,
pHandle
,
(
uint64_t
)
queryId
,
taskId
);
tsdbReaderT
pDataReader
=
doCreateDataReader
((
STableScanPhyNode
*
)
pPhyNode
,
pHandle
,
(
uint64_t
)
queryId
,
taskId
);
return
createDataBlocksOptScanInfo
(
pDataReader
,
pScanPhyNode
->
order
,
numOfCols
,
pScanPhyNode
->
count
,
pScanPhyNode
->
reverse
,
pTaskInfo
);
int32_t
code
=
doCreateTableGroup
(
pHandle
->
meta
,
pScanPhyNode
->
tableType
,
pScanPhyNode
->
uid
,
pTableGroupInfo
,
queryId
,
taskId
);
return
createTableScanOperatorInfo
(
pDataReader
,
pScanPhyNode
->
order
,
numOfCols
,
pScanPhyNode
->
count
,
pScanPhyNode
->
reverse
,
pTaskInfo
);
}
else
if
(
pPhyNode
->
info
.
type
==
OP_Exchange
)
{
}
else
if
(
pPhyNode
->
info
.
type
==
OP_Exchange
)
{
SExchangePhyNode
*
pEx
=
(
SExchangePhyNode
*
)
pPhyNode
;
SExchangePhyNode
*
pEx
=
(
SExchangePhyNode
*
)
pPhyNode
;
return
createExchangeOperatorInfo
(
pEx
->
pSrcEndPoints
,
pEx
->
node
.
pTargets
,
pTaskInfo
);
return
createExchangeOperatorInfo
(
pEx
->
pSrcEndPoints
,
pEx
->
node
.
pTargets
,
pTaskInfo
);
...
@@ -7762,10 +8210,20 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhyNode* pPhyNode, SExecTaskInfo* pTask
...
@@ -7762,10 +8210,20 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhyNode* pPhyNode, SExecTaskInfo* pTask
size_t
size
=
taosArrayGetSize
(
pPhyNode
->
pChildren
);
size_t
size
=
taosArrayGetSize
(
pPhyNode
->
pChildren
);
assert
(
size
==
1
);
assert
(
size
==
1
);
// TODO single table agg
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SPhyNode
*
pChildNode
=
taosArrayGetP
(
pPhyNode
->
pChildren
,
i
);
SPhyNode
*
pChildNode
=
taosArrayGetP
(
pPhyNode
->
pChildren
,
i
);
SOperatorInfo
*
op
=
doCreateOperatorTreeNode
(
pChildNode
,
pTaskInfo
,
pHandle
,
queryId
,
taskId
);
SOperatorInfo
*
op
=
doCreateOperatorTreeNode
(
pChildNode
,
pTaskInfo
,
pHandle
,
queryId
,
taskId
,
pTableGroupInfo
);
return
createAggregateOperatorInfo
(
op
,
pPhyNode
->
pTargets
,
pTaskInfo
);
return
createAggregateOperatorInfo
(
op
,
pPhyNode
->
pTargets
,
pTaskInfo
,
pTableGroupInfo
);
}
}
else
if
(
pPhyNode
->
info
.
type
==
OP_MultiTableAggregate
)
{
size_t
size
=
taosArrayGetSize
(
pPhyNode
->
pChildren
);
assert
(
size
==
1
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SPhyNode
*
pChildNode
=
taosArrayGetP
(
pPhyNode
->
pChildren
,
i
);
SOperatorInfo
*
op
=
doCreateOperatorTreeNode
(
pChildNode
,
pTaskInfo
,
pHandle
,
queryId
,
taskId
,
pTableGroupInfo
);
return
createMultiTableAggOperatorInfo
(
op
,
pPhyNode
->
pTargets
,
pTaskInfo
,
pTableGroupInfo
);
}
}
}
}
}
}
...
@@ -7840,7 +8298,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
...
@@ -7840,7 +8298,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
goto
_complete
;
goto
_complete
;
}
}
(
*
pTaskInfo
)
->
pRoot
=
doCreateOperatorTreeNode
(
pPlan
->
pNode
,
*
pTaskInfo
,
pHandle
,
queryId
,
taskId
);
STableGroupInfo
group
=
{
0
};
(
*
pTaskInfo
)
->
pRoot
=
doCreateOperatorTreeNode
(
pPlan
->
pNode
,
*
pTaskInfo
,
pHandle
,
queryId
,
taskId
,
&
group
);
if
((
*
pTaskInfo
)
->
pRoot
==
NULL
)
{
if
((
*
pTaskInfo
)
->
pRoot
==
NULL
)
{
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
goto
_complete
;
goto
_complete
;
...
@@ -7855,367 +8314,6 @@ _complete:
...
@@ -7855,367 +8314,6 @@ _complete:
return
code
;
return
code
;
}
}
/**
* pQueryMsg->head has been converted before this function is called.
*
* @param pQueryMsg
* @param pTableIdList
* @param pExpr
* @return
*/
//int32_t convertQueryMsg(SQueryTableReq *pQueryMsg, STaskParam* param) {
// int32_t code = TSDB_CODE_SUCCESS;
//
//// if (taosCheckVersion(pQueryMsg->version, version, 3) != 0) {
//// return TSDB_CODE_QRY_INVALID_MSG;
//// }
//
// pQueryMsg->numOfTables = htonl(pQueryMsg->numOfTables);
// pQueryMsg->window.skey = htobe64(pQueryMsg->window.skey);
// pQueryMsg->window.ekey = htobe64(pQueryMsg->window.ekey);
// pQueryMsg->interval.interval = htobe64(pQueryMsg->interval.interval);
// pQueryMsg->interval.sliding = htobe64(pQueryMsg->interval.sliding);
// pQueryMsg->interval.offset = htobe64(pQueryMsg->interval.offset);
// pQueryMsg->limit = htobe64(pQueryMsg->limit);
// pQueryMsg->offset = htobe64(pQueryMsg->offset);
// pQueryMsg->vgroupLimit = htobe64(pQueryMsg->vgroupLimit);
//
// pQueryMsg->order = htons(pQueryMsg->order);
// pQueryMsg->orderColId = htons(pQueryMsg->orderColId);
// pQueryMsg->queryType = htonl(pQueryMsg->queryType);
//// pQueryMsg->tagNameRelType = htons(pQueryMsg->tagNameRelType);
//
// pQueryMsg->numOfCols = htons(pQueryMsg->numOfCols);
// pQueryMsg->numOfOutput = htons(pQueryMsg->numOfOutput);
// pQueryMsg->numOfGroupCols = htons(pQueryMsg->numOfGroupCols);
//
// pQueryMsg->tagCondLen = htons(pQueryMsg->tagCondLen);
// pQueryMsg->colCondLen = htons(pQueryMsg->colCondLen);
//
// pQueryMsg->tsBuf.tsOffset = htonl(pQueryMsg->tsBuf.tsOffset);
// pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen);
// pQueryMsg->tsBuf.tsNumOfBlocks = htonl(pQueryMsg->tsBuf.tsNumOfBlocks);
// pQueryMsg->tsBuf.tsOrder = htonl(pQueryMsg->tsBuf.tsOrder);
//
// pQueryMsg->numOfTags = htonl(pQueryMsg->numOfTags);
//// pQueryMsg->tbnameCondLen = htonl(pQueryMsg->tbnameCondLen);
// pQueryMsg->secondStageOutput = htonl(pQueryMsg->secondStageOutput);
// pQueryMsg->sqlstrLen = htonl(pQueryMsg->sqlstrLen);
// pQueryMsg->prevResultLen = htonl(pQueryMsg->prevResultLen);
//// pQueryMsg->sw.gap = htobe64(pQueryMsg->sw.gap);
//// pQueryMsg->sw.primaryColId = htonl(pQueryMsg->sw.primaryColId);
// pQueryMsg->tableScanOperator = htonl(pQueryMsg->tableScanOperator);
// pQueryMsg->numOfOperator = htonl(pQueryMsg->numOfOperator);
// pQueryMsg->udfContentOffset = htonl(pQueryMsg->udfContentOffset);
// pQueryMsg->udfContentLen = htonl(pQueryMsg->udfContentLen);
// pQueryMsg->udfNum = htonl(pQueryMsg->udfNum);
//
// // query msg safety check
// if (!validateQueryMsg(pQueryMsg)) {
// code = TSDB_CODE_QRY_INVALID_MSG;
// goto _cleanup;
// }
//
// char *pMsg = (char *)(pQueryMsg->tableCols) + sizeof(SColumnInfo) * pQueryMsg->numOfCols;
// for (int32_t col = 0; col < pQueryMsg->numOfCols; ++col) {
// SColumnInfo *pColInfo = &pQueryMsg->tableCols[col];
//
// pColInfo->colId = htons(pColInfo->colId);
// pColInfo->type = htons(pColInfo->type);
// pColInfo->bytes = htons(pColInfo->bytes);
// pColInfo->flist.numOfFilters = 0;
//
// if (!isValidDataType(pColInfo->type)) {
// //qDebug("qmsg:%p, invalid data type in source column, index:%d, type:%d", pQueryMsg, col, pColInfo->type);
// code = TSDB_CODE_QRY_INVALID_MSG;
// goto _cleanup;
// }
//
///*
// int32_t numOfFilters = pColInfo->flist.numOfFilters;
// if (numOfFilters > 0) {
// pColInfo->flist.filterInfo = calloc(numOfFilters, sizeof(SColumnFilterInfo));
// if (pColInfo->flist.filterInfo == NULL) {
// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
// goto _cleanup;
// }
// }
//
// code = deserializeColFilterInfo(pColInfo->flist.filterInfo, numOfFilters, &pMsg);
// if (code != TSDB_CODE_SUCCESS) {
// goto _cleanup;
// }
//*/
// }
//
// if (pQueryMsg->colCondLen > 0) {
// param->colCond = calloc(1, pQueryMsg->colCondLen);
// if (param->colCond == NULL) {
// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
// goto _cleanup;
// }
//
// memcpy(param->colCond, pMsg, pQueryMsg->colCondLen);
// pMsg += pQueryMsg->colCondLen;
// }
//
//
// param->tableScanOperator = pQueryMsg->tableScanOperator;
// param->pExpr = calloc(pQueryMsg->numOfOutput, POINTER_BYTES);
// if (param->pExpr == NULL) {
// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
// goto _cleanup;
// }
//
// SSqlExpr *pExprMsg = (SSqlExpr *)pMsg;
//
// for (int32_t i = 0; i < pQueryMsg->numOfOutput; ++i) {
// param->pExpr[i] = pExprMsg;
//
//// pExprMsg->colInfo.colIndex = htons(pExprMsg->colInfo.colIndex);
//// pExprMsg->colInfo.colId = htons(pExprMsg->colInfo.colId);
//// pExprMsg->colInfo.flag = htons(pExprMsg->colInfo.flag);
//// pExprMsg->colBytes = htons(pExprMsg->colBytes);
//// pExprMsg->colType = htons(pExprMsg->colType);
//
//// pExprMsg->resType = htons(pExprMsg->resType);
//// pExprMsg->resBytes = htons(pExprMsg->resBytes);
// pExprMsg->interBytes = htonl(pExprMsg->interBytes);
//
//// pExprMsg->functionId = htons(pExprMsg->functionId);
// pExprMsg->numOfParams = htons(pExprMsg->numOfParams);
//// pExprMsg->resColId = htons(pExprMsg->resColId);
//// pExprMsg->flist.numOfFilters = htons(pExprMsg->flist.numOfFilters);
// pMsg += sizeof(SSqlExpr);
//
// for (int32_t j = 0; j < pExprMsg->numOfParams; ++j) {
// pExprMsg->param[j].nType = htonl(pExprMsg->param[j].nType);
// pExprMsg->param[j].nLen = htonl(pExprMsg->param[j].nLen);
//
// if (pExprMsg->param[j].nType == TSDB_DATA_TYPE_BINARY) {
// pExprMsg->param[j].pz = pMsg;
// pMsg += pExprMsg->param[j].nLen; // one more for the string terminated char.
// } else {
// pExprMsg->param[j].i = htobe64(pExprMsg->param[j].i);
// }
// }
//
//// int16_t functionId = pExprMsg->functionId;
//// if (functionId == FUNCTION_TAG || functionId == FUNCTION_TAGPRJ || functionId == FUNCTION_TAG_DUMMY) {
//// if (!TSDB_COL_IS_TAG(pExprMsg->colInfo.flag)) { // ignore the column index check for arithmetic expression.
//// code = TSDB_CODE_QRY_INVALID_MSG;
//// goto _cleanup;
//// }
//// }
//
//// if (pExprMsg->flist.numOfFilters > 0) {
//// pExprMsg->flist.filterInfo = calloc(pExprMsg->flist.numOfFilters, sizeof(SColumnFilterInfo));
//// }
////
//// deserializeColFilterInfo(pExprMsg->flist.filterInfo, pExprMsg->flist.numOfFilters, &pMsg);
// pExprMsg = (SSqlExpr *)pMsg;
// }
//
// if (pQueryMsg->secondStageOutput) {
// pExprMsg = (SSqlExpr *)pMsg;
// param->pSecExpr = calloc(pQueryMsg->secondStageOutput, POINTER_BYTES);
//
// for (int32_t i = 0; i < pQueryMsg->secondStageOutput; ++i) {
// param->pSecExpr[i] = pExprMsg;
//
//// pExprMsg->colInfo.colIndex = htons(pExprMsg->colInfo.colIndex);
//// pExprMsg->colInfo.colId = htons(pExprMsg->colInfo.colId);
//// pExprMsg->colInfo.flag = htons(pExprMsg->colInfo.flag);
//// pExprMsg->resType = htons(pExprMsg->resType);
//// pExprMsg->resBytes = htons(pExprMsg->resBytes);
//// pExprMsg->colBytes = htons(pExprMsg->colBytes);
//// pExprMsg->colType = htons(pExprMsg->colType);
//
//// pExprMsg->functionId = htons(pExprMsg->functionId);
// pExprMsg->numOfParams = htons(pExprMsg->numOfParams);
//
// pMsg += sizeof(SSqlExpr);
//
// for (int32_t j = 0; j < pExprMsg->numOfParams; ++j) {
// pExprMsg->param[j].nType = htonl(pExprMsg->param[j].nType);
// pExprMsg->param[j].nLen = htonl(pExprMsg->param[j].nLen);
//
// if (pExprMsg->param[j].nType == TSDB_DATA_TYPE_BINARY) {
// pExprMsg->param[j].pz = pMsg;
// pMsg += pExprMsg->param[j].nLen; // one more for the string terminated char.
// } else {
// pExprMsg->param[j].i = htobe64(pExprMsg->param[j].i);
// }
// }
//
//// int16_t functionId = pExprMsg->functionId;
//// if (functionId == FUNCTION_TAG || functionId == FUNCTION_TAGPRJ || functionId == FUNCTION_TAG_DUMMY) {
//// if (!TSDB_COL_IS_TAG(pExprMsg->colInfo.flag)) { // ignore the column index check for arithmetic expression.
//// code = TSDB_CODE_QRY_INVALID_MSG;
//// goto _cleanup;
//// }
//// }
//
// pExprMsg = (SSqlExpr *)pMsg;
// }
// }
//
// pMsg = createTableIdList(pQueryMsg, pMsg, &(param->pTableIdList));
//
// if (pQueryMsg->numOfGroupCols > 0) { // group by tag columns
// param->pGroupColIndex = malloc(pQueryMsg->numOfGroupCols * sizeof(SColIndex));
// if (param->pGroupColIndex == NULL) {
// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
// goto _cleanup;
// }
//
// for (int32_t i = 0; i < pQueryMsg->numOfGroupCols; ++i) {
// param->pGroupColIndex[i].colId = htons(*(int16_t *)pMsg);
// pMsg += sizeof(param->pGroupColIndex[i].colId);
//
// param->pGroupColIndex[i].colIndex = htons(*(int16_t *)pMsg);
// pMsg += sizeof(param->pGroupColIndex[i].colIndex);
//
// param->pGroupColIndex[i].flag = htons(*(int16_t *)pMsg);
// pMsg += sizeof(param->pGroupColIndex[i].flag);
//
// memcpy(param->pGroupColIndex[i].name, pMsg, tListLen(param->pGroupColIndex[i].name));
// pMsg += tListLen(param->pGroupColIndex[i].name);
// }
//
// pQueryMsg->orderByIdx = htons(pQueryMsg->orderByIdx);
// pQueryMsg->orderType = htons(pQueryMsg->orderType);
// }
//
// pQueryMsg->fillType = htons(pQueryMsg->fillType);
// if (pQueryMsg->fillType != TSDB_FILL_NONE) {
// pQueryMsg->fillVal = (uint64_t)(pMsg);
//
// int64_t *v = (int64_t *)pMsg;
// for (int32_t i = 0; i < pQueryMsg->numOfOutput; ++i) {
// v[i] = htobe64(v[i]);
// }
//
// pMsg += sizeof(int64_t) * pQueryMsg->numOfOutput;
// }
//
// if (pQueryMsg->numOfTags > 0) {
// param->pTagColumnInfo = calloc(1, sizeof(SColumnInfo) * pQueryMsg->numOfTags);
// if (param->pTagColumnInfo == NULL) {
// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
// goto _cleanup;
// }
//
// for (int32_t i = 0; i < pQueryMsg->numOfTags; ++i) {
// SColumnInfo* pTagCol = (SColumnInfo*) pMsg;
//
// pTagCol->colId = htons(pTagCol->colId);
// pTagCol->bytes = htons(pTagCol->bytes);
// pTagCol->type = htons(pTagCol->type);
//// pTagCol->flist.numOfFilters = 0;
//
// param->pTagColumnInfo[i] = *pTagCol;
// pMsg += sizeof(SColumnInfo);
// }
// }
//
// // the tag query condition expression string is located at the end of query msg
// if (pQueryMsg->tagCondLen > 0) {
// param->tagCond = calloc(1, pQueryMsg->tagCondLen);
// if (param->tagCond == NULL) {
// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
// goto _cleanup;
// }
//
// memcpy(param->tagCond, pMsg, pQueryMsg->tagCondLen);
// pMsg += pQueryMsg->tagCondLen;
// }
//
// if (pQueryMsg->prevResultLen > 0) {
// param->prevResult = calloc(1, pQueryMsg->prevResultLen);
// if (param->prevResult == NULL) {
// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
// goto _cleanup;
// }
//
// memcpy(param->prevResult, pMsg, pQueryMsg->prevResultLen);
// pMsg += pQueryMsg->prevResultLen;
// }
//
//// if (pQueryMsg->tbnameCondLen > 0) {
//// param->tbnameCond = calloc(1, pQueryMsg->tbnameCondLen + 1);
//// if (param->tbnameCond == NULL) {
//// code = TSDB_CODE_QRY_OUT_OF_MEMORY;
//// goto _cleanup;
//// }
////
//// strncpy(param->tbnameCond, pMsg, pQueryMsg->tbnameCondLen);
//// pMsg += pQueryMsg->tbnameCondLen;
//// }
//
// //skip ts buf
// if ((pQueryMsg->tsBuf.tsOffset + pQueryMsg->tsBuf.tsLen) > 0) {
// pMsg = (char *)pQueryMsg + pQueryMsg->tsBuf.tsOffset + pQueryMsg->tsBuf.tsLen;
// }
//
// param->pOperator = taosArrayInit(pQueryMsg->numOfOperator, sizeof(int32_t));
// for(int32_t i = 0; i < pQueryMsg->numOfOperator; ++i) {
// int32_t op = htonl(*(int32_t*)pMsg);
// taosArrayPush(param->pOperator, &op);
//
// pMsg += sizeof(int32_t);
// }
//
// if (pQueryMsg->udfContentLen > 0) {
// // todo extract udf function in tudf.c
//// param->pUdfInfo = calloc(1, sizeof(SUdfInfo));
//// param->pUdfInfo->contLen = pQueryMsg->udfContentLen;
////
//// pMsg = (char*)pQueryMsg + pQueryMsg->udfContentOffset;
//// param->pUdfInfo->resType = *(int8_t*) pMsg;
//// pMsg += sizeof(int8_t);
////
//// param->pUdfInfo->resBytes = htons(*(int16_t*)pMsg);
//// pMsg += sizeof(int16_t);
////
//// tstr* name = (tstr*)(pMsg);
//// param->pUdfInfo->name = strndup(name->data, name->len);
////
//// pMsg += varDataTLen(name);
//// param->pUdfInfo->funcType = htonl(*(int32_t*)pMsg);
//// pMsg += sizeof(int32_t);
////
//// param->pUdfInfo->bufSize = htonl(*(int32_t*)pMsg);
//// pMsg += sizeof(int32_t);
////
//// param->pUdfInfo->content = malloc(pQueryMsg->udfContentLen);
//// memcpy(param->pUdfInfo->content, pMsg, pQueryMsg->udfContentLen);
//
// pMsg += pQueryMsg->udfContentLen;
// }
//
// param->sql = strndup(pMsg, pQueryMsg->sqlstrLen);
//
// SQueriedTableInfo info = { .numOfTags = pQueryMsg->numOfTags, .numOfCols = pQueryMsg->numOfCols, .colList = pQueryMsg->tableCols};
// if (!validateQueryTableCols(&info, param->pExpr, pQueryMsg->numOfOutput, param->pTagColumnInfo, pQueryMsg)) {
// code = TSDB_CODE_QRY_INVALID_MSG;
// goto _cleanup;
// }
//
// //qDebug("qmsg:%p query %d tables, type:%d, qrange:%" PRId64 "-%" PRId64 ", numOfGroupbyTagCols:%d, order:%d, "
//// "outputCols:%d, numOfCols:%d, interval:%" PRId64 ", fillType:%d, comptsLen:%d, compNumOfBlocks:%d, limit:%" PRId64 ", offset:%" PRId64,
//// pQueryMsg, pQueryMsg->numOfTables, pQueryMsg->queryType, pQueryMsg->window.skey, pQueryMsg->window.ekey, pQueryMsg->numOfGroupCols,
//// pQueryMsg->order, pQueryMsg->numOfOutput, pQueryMsg->numOfCols, pQueryMsg->interval.interval,
//// pQueryMsg->fillType, pQueryMsg->tsBuf.tsLen, pQueryMsg->tsBuf.tsNumOfBlocks, pQueryMsg->limit, pQueryMsg->offset);
//
// //qDebug("qmsg:%p, sql:%s", pQueryMsg, param->sql);
// return TSDB_CODE_SUCCESS;
//
//_cleanup:
// freeParam(param);
// return code;
//}
int32_t
cloneExprFilterInfo
(
SColumnFilterInfo
**
dst
,
SColumnFilterInfo
*
src
,
int32_t
filterNum
)
{
int32_t
cloneExprFilterInfo
(
SColumnFilterInfo
**
dst
,
SColumnFilterInfo
*
src
,
int32_t
filterNum
)
{
if
(
filterNum
<=
0
)
{
if
(
filterNum
<=
0
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/executor/test/executorTests.cpp
浏览文件 @
378aaf38
...
@@ -33,193 +33,312 @@
...
@@ -33,193 +33,312 @@
#include "stub.h"
#include "stub.h"
#include "executor.h"
#include "executor.h"
/**
namespace
{
{
"Id": {
typedef
struct
SDummyInputInfo
{
"QueryId": 1.3108161807422521e+19,
int32_t
max
;
"TemplateId": 0,
int32_t
current
;
"SubplanId": 0
int32_t
startVal
;
},
SSDataBlock
*
pBlock
;
"Node": {
}
SDummyInputInfo
;
"Name": "TableScan",
"Targets": [{
SSDataBlock
*
getDummyBlock
(
void
*
param
,
bool
*
newgroup
)
{
"Base": {
SOperatorInfo
*
pOperator
=
static_cast
<
SOperatorInfo
*>
(
param
);
"Schema": {
SDummyInputInfo
*
pInfo
=
static_cast
<
SDummyInputInfo
*>
(
pOperator
->
info
);
"Type": 9,
if
(
pInfo
->
current
>=
pInfo
->
max
)
{
"ColId": 5000,
return
NULL
;
"Bytes": 8
}
},
"Columns": [{
int32_t
numOfRows
=
1000
;
"TableId": 1,
"Flag": 0,
if
(
pInfo
->
pBlock
==
NULL
)
{
"Info": {
pInfo
->
pBlock
=
static_cast
<
SSDataBlock
*>
(
calloc
(
1
,
sizeof
(
SSDataBlock
)));
"ColId": 1,
"Type": 9,
pInfo
->
pBlock
->
pDataBlock
=
taosArrayInit
(
4
,
sizeof
(
SColumnInfoData
));
"Bytes": 8
}
SColumnInfoData
colInfo
=
{
0
};
}],
colInfo
.
info
.
type
=
TSDB_DATA_TYPE_INT
;
"InterBytes": 0
colInfo
.
info
.
bytes
=
sizeof
(
int32_t
);
},
colInfo
.
info
.
colId
=
1
;
"Expr": {
colInfo
.
pData
=
static_cast
<
char
*>
(
calloc
(
numOfRows
,
sizeof
(
int32_t
)));
"Type": 4,
colInfo
.
nullbitmap
=
static_cast
<
char
*>
(
calloc
(
1
,
(
numOfRows
+
7
)
/
8
));
"Column": {
"Type": 9,
taosArrayPush
(
pInfo
->
pBlock
->
pDataBlock
,
&
colInfo
);
"ColId": 1,
"Bytes": 8
// SColumnInfoData colInfo1 = {0};
}
// colInfo1.info.type = TSDB_DATA_TYPE_BINARY;
}
// colInfo1.info.bytes = 40;
}, {
// colInfo1.info.colId = 2;
"Base": {
//
"Schema": {
// colInfo1.varmeta.allocLen = 0;//numOfRows * sizeof(int32_t);
"Type": 4,
// colInfo1.varmeta.length = 0;
"ColId": 5001,
// colInfo1.varmeta.offset = static_cast<int32_t*>(calloc(1, numOfRows * sizeof(int32_t)));
"Bytes": 4
//
},
// taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1);
"Columns": [{
}
else
{
"TableId": 1,
blockDataClearup
(
pInfo
->
pBlock
,
true
);
"Flag": 0,
}
"Info": {
"ColId": 2,
SSDataBlock
*
pBlock
=
pInfo
->
pBlock
;
"Type": 4,
"Bytes": 4
char
buf
[
128
]
=
{
0
};
}
char
b1
[
128
]
=
{
0
};
}],
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
"InterBytes": 0
SColumnInfoData
*
pColInfo
=
static_cast
<
SColumnInfoData
*>
(
TARRAY_GET_ELEM
(
pBlock
->
pDataBlock
,
0
));
},
"Expr": {
int32_t
v
=
(
--
pInfo
->
startVal
);
"Type": 4,
colDataAppend
(
pColInfo
,
i
,
reinterpret_cast
<
const
char
*>
(
&
v
),
false
);
"Column": {
"Type": 4,
// sprintf(buf, "this is %d row", i);
"ColId": 2,
// STR_TO_VARSTR(b1, buf);
"Bytes": 4
//
}
// SColumnInfoData* pColInfo2 = static_cast<SColumnInfoData*>(TARRAY_GET_ELEM(pBlock->pDataBlock, 1));
}
// colDataAppend(pColInfo2, i, b1, false);
}],
}
"InputSchema": [{
"Type": 9,
pBlock
->
info
.
rows
=
numOfRows
;
"ColId": 5000,
pBlock
->
info
.
numOfCols
=
1
;
"Bytes": 8
}, {
pInfo
->
current
+=
1
;
"Type": 4,
return
pBlock
;
"ColId": 5001,
"Bytes": 4
}],
"TableScan": {
"TableId": 1,
"TableType": 2,
"Flag": 0,
"Window": {
"StartKey": -9.2233720368547758e+18,
"EndKey": 9.2233720368547758e+18
}
}
},
"DataSink": {
"Name": "Dispatch",
"Dispatch": {
}
}
}
}
*/
SOperatorInfo
*
createDummyOperator
(
int32_t
numOfBlocks
)
{
SOperatorInfo
*
pOperator
=
static_cast
<
SOperatorInfo
*>
(
calloc
(
1
,
sizeof
(
SOperatorInfo
)));
pOperator
->
name
=
"dummyInputOpertor4Test"
;
pOperator
->
exec
=
getDummyBlock
;
SDummyInputInfo
*
pInfo
=
(
SDummyInputInfo
*
)
calloc
(
1
,
sizeof
(
SDummyInputInfo
));
pInfo
->
max
=
numOfBlocks
;
pInfo
->
startVal
=
1500000
;
pOperator
->
info
=
pInfo
;
return
pOperator
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
return
RUN_ALL_TESTS
();
}
}
TEST
(
testCase
,
build_executor_tree_Test
)
{
TEST
(
testCase
,
build_executor_tree_Test
)
{
const
char
*
msg
=
"{
\n
"
const
char
*
msg
=
"{
\n
"
"
\t\"
Id
\"
:
\t
{
\n
"
"
\t\"
Id
\"
:
\t
{
\n
"
"
\t\t\"
QueryId
\"
:
\t
1.3108161807422521e+19,
\n
"
"
\t\t\"
QueryId
\"
:
\t
1.3108161807422521e+19,
\n
"
"
\t\t\"
TemplateId
\"
:
\t
0,
\n
"
"
\t\t\"
TemplateId
\"
:
\t
0,
\n
"
"
\t\t\"
SubplanId
\"
:
\t
0
\n
"
"
\t\t\"
SubplanId
\"
:
\t
0
\n
"
"
\t
},
\n
"
"
\t
},
\n
"
"
\t\"
Node
\"
:
\t
{
\n
"
"
\t\"
Node
\"
:
\t
{
\n
"
"
\t\t\"
Name
\"
:
\t\"
TableScan
\"
,
\n
"
"
\t\t\"
Name
\"
:
\t\"
TableScan
\"
,
\n
"
"
\t\t\"
Targets
\"
:
\t
[{
\n
"
"
\t\t\"
Targets
\"
:
\t
[{
\n
"
"
\t\t\t\t\"
Base
\"
:
\t
{
\n
"
"
\t\t\t\t\"
Base
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Schema
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Schema
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
5000,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
5000,
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t\t\t
},
\n
"
"
\t\t\t\t\t
},
\n
"
"
\t\t\t\t\t\"
Columns
\"
:
\t
[{
\n
"
"
\t\t\t\t\t\"
Columns
\"
:
\t
[{
\n
"
"
\t\t\t\t\t\t\t\"
TableId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\t\"
TableId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\t\"
Flag
\"
:
\t
0,
\n
"
"
\t\t\t\t\t\t\t\"
Flag
\"
:
\t
0,
\n
"
"
\t\t\t\t\t\t\t\"
Info
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\t\"
Info
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\t\t\"
ColId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\t\t\"
ColId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t\t\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t\t\t\t\t
}
\n
"
"
\t\t\t\t\t\t\t
}
\n
"
"
\t\t\t\t\t\t
}],
\n
"
"
\t\t\t\t\t\t
}],
\n
"
"
\t\t\t\t\t\"
InterBytes
\"
:
\t
0
\n
"
"
\t\t\t\t\t\"
InterBytes
\"
:
\t
0
\n
"
"
\t\t\t\t
},
\n
"
"
\t\t\t\t
},
\n
"
"
\t\t\t\t\"
Expr
\"
:
\t
{
\n
"
"
\t\t\t\t\"
Expr
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\"
Column
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Column
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t\t\t
}
\n
"
"
\t\t\t\t\t
}
\n
"
"
\t\t\t\t
}
\n
"
"
\t\t\t\t
}
\n
"
"
\t\t\t
}, {
\n
"
"
\t\t\t
}, {
\n
"
"
\t\t\t\t\"
Base
\"
:
\t
{
\n
"
"
\t\t\t\t\"
Base
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Schema
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Schema
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
5001,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
5001,
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t\t\t
},
\n
"
"
\t\t\t\t\t
},
\n
"
"
\t\t\t\t\t\"
Columns
\"
:
\t
[{
\n
"
"
\t\t\t\t\t\"
Columns
\"
:
\t
[{
\n
"
"
\t\t\t\t\t\t\t\"
TableId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\t\"
TableId
\"
:
\t
1,
\n
"
"
\t\t\t\t\t\t\t\"
Flag
\"
:
\t
0,
\n
"
"
\t\t\t\t\t\t\t\"
Flag
\"
:
\t
0,
\n
"
"
\t\t\t\t\t\t\t\"
Info
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\t\"
Info
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\t\t\"
ColId
\"
:
\t
2,
\n
"
"
\t\t\t\t\t\t\t\t\"
ColId
\"
:
\t
2,
\n
"
"
\t\t\t\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t\t\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t\t\t\t\t
}
\n
"
"
\t\t\t\t\t\t\t
}
\n
"
"
\t\t\t\t\t\t
}],
\n
"
"
\t\t\t\t\t\t
}],
\n
"
"
\t\t\t\t\t\"
InterBytes
\"
:
\t
0
\n
"
"
\t\t\t\t\t\"
InterBytes
\"
:
\t
0
\n
"
"
\t\t\t\t
},
\n
"
"
\t\t\t\t
},
\n
"
"
\t\t\t\t\"
Expr
\"
:
\t
{
\n
"
"
\t\t\t\t\"
Expr
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\"
Column
\"
:
\t
{
\n
"
"
\t\t\t\t\t\"
Column
\"
:
\t
{
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
2,
\n
"
"
\t\t\t\t\t\t\"
ColId
\"
:
\t
2,
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t\t\t
}
\n
"
"
\t\t\t\t\t
}
\n
"
"
\t\t\t\t
}
\n
"
"
\t\t\t\t
}
\n
"
"
\t\t\t
}],
\n
"
"
\t\t\t
}],
\n
"
"
\t\t\"
InputSchema
\"
:
\t
[{
\n
"
"
\t\t\"
InputSchema
\"
:
\t
[{
\n
"
"
\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\"
Type
\"
:
\t
9,
\n
"
"
\t\t\t\t\"
ColId
\"
:
\t
5000,
\n
"
"
\t\t\t\t\"
ColId
\"
:
\t
5000,
\n
"
"
\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t\t\"
Bytes
\"
:
\t
8
\n
"
"
\t\t\t
}, {
\n
"
"
\t\t\t
}, {
\n
"
"
\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\"
Type
\"
:
\t
4,
\n
"
"
\t\t\t\t\"
ColId
\"
:
\t
5001,
\n
"
"
\t\t\t\t\"
ColId
\"
:
\t
5001,
\n
"
"
\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t\t\"
Bytes
\"
:
\t
4
\n
"
"
\t\t\t
}],
\n
"
"
\t\t\t
}],
\n
"
"
\t\t\"
TableScan
\"
:
\t
{
\n
"
"
\t\t\"
TableScan
\"
:
\t
{
\n
"
"
\t\t\t\"
TableId
\"
:
\t
1,
\n
"
"
\t\t\t\"
TableId
\"
:
\t
1,
\n
"
"
\t\t\t\"
TableType
\"
:
\t
2,
\n
"
"
\t\t\t\"
TableType
\"
:
\t
2,
\n
"
"
\t\t\t\"
Flag
\"
:
\t
0,
\n
"
"
\t\t\t\"
Flag
\"
:
\t
0,
\n
"
"
\t\t\t\"
Window
\"
:
\t
{
\n
"
"
\t\t\t\"
Window
\"
:
\t
{
\n
"
"
\t\t\t\t\"
StartKey
\"
:
\t
-9.2233720368547758e+18,
\n
"
"
\t\t\t\t\"
StartKey
\"
:
\t
-9.2233720368547758e+18,
\n
"
"
\t\t\t\t\"
EndKey
\"
:
\t
9.2233720368547758e+18
\n
"
"
\t\t\t\t\"
EndKey
\"
:
\t
9.2233720368547758e+18
\n
"
"
\t\t\t
}
\n
"
"
\t\t\t
}
\n
"
"
\t\t
}
\n
"
"
\t\t
}
\n
"
"
\t
},
\n
"
"
\t
},
\n
"
"
\t\"
DataSink
\"
:
\t
{
\n
"
"
\t\"
DataSink
\"
:
\t
{
\n
"
"
\t\t\"
Name
\"
:
\t\"
Dispatch
\"
,
\n
"
"
\t\t\"
Name
\"
:
\t\"
Dispatch
\"
,
\n
"
"
\t\t\"
Dispatch
\"
:
\t
{
\n
"
"
\t\t\"
Dispatch
\"
:
\t
{
\n
"
"
\t\t
}
\n
"
"
\t\t
}
\n
"
"
\t
}
\n
"
"
\t
}
\n
"
"}"
;
"}"
;
SExecTaskInfo
*
pTaskInfo
=
nullptr
;
SExecTaskInfo
*
pTaskInfo
=
nullptr
;
DataSinkHandle
sinkHandle
=
nullptr
;
DataSinkHandle
sinkHandle
=
nullptr
;
int32_t
code
=
qCreateExecTask
((
SReadHandle
*
)
1
,
2
,
1
,
NULL
,
(
void
**
)
&
pTaskInfo
,
&
sinkHandle
);
SReadHandle
handle
=
{.
reader
=
reinterpret_cast
<
void
*>
(
0x1
),
.
meta
=
reinterpret_cast
<
void
*>
(
0x1
)};
// int32_t code = qCreateExecTask(&handle, 2, 1, NULL, (void**) &pTaskInfo, &sinkHandle);
}
}
//TEST(testCase, inMem_sort_Test) {
// SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
// SOrder o = {.order = TSDB_ORDER_ASC};
// o.col.info.colId = 1;
// o.col.info.type = TSDB_DATA_TYPE_INT;
// taosArrayPush(pOrderVal, &o);
//
// SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo));
// SExprInfo *exp = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
// exp->base.resSchema = createSchema(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1, "res");
// taosArrayPush(pExprInfo, &exp);
//
// SExprInfo *exp1 = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
// exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1");
// taosArrayPush(pExprInfo, &exp1);
//
// SOperatorInfo* pOperator = createOrderOperatorInfo(createDummyOperator(5), pExprInfo, pOrderVal);
//
// bool newgroup = false;
// SSDataBlock* pRes = pOperator->exec(pOperator, &newgroup);
//
// SColumnInfoData* pCol1 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 0));
// SColumnInfoData* pCol2 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 1));
// for(int32_t i = 0; i < pRes->info.rows; ++i) {
// char* p = colDataGet(pCol2, i);
// printf("%d: %d, %s\n", i, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p));
// }
//}
typedef
struct
su
{
int32_t
v
;
char
*
c
;
}
su
;
int32_t
cmp
(
const
void
*
p1
,
const
void
*
p2
)
{
su
*
v1
=
(
su
*
)
p1
;
su
*
v2
=
(
su
*
)
p2
;
int32_t
x1
=
*
(
int32_t
*
)
v1
->
c
;
int32_t
x2
=
*
(
int32_t
*
)
v2
->
c
;
if
(
x1
==
x2
)
{
return
0
;
}
else
{
return
x1
<
x2
?
-
1
:
1
;
}
}
TEST
(
testCase
,
external_sort_Test
)
{
#if 0
su* v = static_cast<su*>(calloc(1000000, sizeof(su)));
for(int32_t i = 0; i < 1000000; ++i) {
v[i].v = rand();
v[i].c = static_cast<char*>(malloc(4));
*(int32_t*) v[i].c = i;
}
qsort(v, 1000000, sizeof(su), cmp);
// for(int32_t i = 0; i < 1000; ++i) {
// printf("%d ", v[i]);
// }
// printf("\n");
return;
#endif
srand
(
time
(
NULL
));
SArray
*
pOrderVal
=
taosArrayInit
(
4
,
sizeof
(
SOrder
));
SOrder
o
=
{
0
};
o
.
order
=
TSDB_ORDER_ASC
;
o
.
col
.
info
.
colId
=
1
;
o
.
col
.
info
.
type
=
TSDB_DATA_TYPE_INT
;
taosArrayPush
(
pOrderVal
,
&
o
);
SArray
*
pExprInfo
=
taosArrayInit
(
4
,
sizeof
(
SExprInfo
));
SExprInfo
*
exp
=
static_cast
<
SExprInfo
*>
(
calloc
(
1
,
sizeof
(
SExprInfo
)));
exp
->
base
.
resSchema
=
createSchema
(
TSDB_DATA_TYPE_INT
,
sizeof
(
int32_t
),
1
,
"res"
);
taosArrayPush
(
pExprInfo
,
&
exp
);
SExprInfo
*
exp1
=
static_cast
<
SExprInfo
*>
(
calloc
(
1
,
sizeof
(
SExprInfo
)));
exp1
->
base
.
resSchema
=
createSchema
(
TSDB_DATA_TYPE_BINARY
,
40
,
2
,
"res1"
);
// taosArrayPush(pExprInfo, &exp1);
SOperatorInfo
*
pOperator
=
createOrderOperatorInfo
(
createDummyOperator
(
1500
),
pExprInfo
,
pOrderVal
);
bool
newgroup
=
false
;
SSDataBlock
*
pRes
=
NULL
;
int32_t
total
=
1
;
int64_t
s1
=
taosGetTimestampUs
();
int32_t
t
=
1
;
while
(
1
)
{
int64_t
s
=
taosGetTimestampUs
();
pRes
=
pOperator
->
exec
(
pOperator
,
&
newgroup
);
int64_t
e
=
taosGetTimestampUs
();
if
(
t
++
==
1
)
{
printf
(
"---------------elapsed:%ld
\n
"
,
e
-
s
);
}
if
(
pRes
==
NULL
)
{
break
;
}
SColumnInfoData
*
pCol1
=
static_cast
<
SColumnInfoData
*>
(
taosArrayGet
(
pRes
->
pDataBlock
,
0
));
// SColumnInfoData* pCol2 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 1));
for
(
int32_t
i
=
0
;
i
<
pRes
->
info
.
rows
;
++
i
)
{
// char* p = colDataGet(pCol2, i);
printf
(
"%d: %d
\n
"
,
total
++
,
((
int32_t
*
)
pCol1
->
pData
)[
i
]);
// printf("%d: %d, %s\n", total++, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p));
}
}
printStatisBeforeClose
(((
SOrderOperatorInfo
*
)
pOperator
->
info
)
->
pSortInternalBuf
);
int64_t
s2
=
taosGetTimestampUs
();
printf
(
"total:%ld
\n
"
,
s2
-
s1
);
pOperator
->
cleanupFn
(
pOperator
->
info
,
2
);
tfree
(
exp
);
tfree
(
exp1
);
taosArrayDestroy
(
pExprInfo
);
taosArrayDestroy
(
pOrderVal
);
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
source/libs/function/inc/thistogram.h
浏览文件 @
378aaf38
...
@@ -49,7 +49,7 @@ typedef struct SHistogramInfo {
...
@@ -49,7 +49,7 @@ typedef struct SHistogramInfo {
SHistBin
*
elems
;
SHistBin
*
elems
;
#else
#else
tSkipList
*
pList
;
tSkipList
*
pList
;
S
Loser
TreeInfo
*
pLoserTree
;
S
MultiwayMerge
TreeInfo
*
pLoserTree
;
int32_t
maxIndex
;
int32_t
maxIndex
;
bool
ordered
;
bool
ordered
;
#endif
#endif
...
...
source/libs/function/inc/tpercentile.h
浏览文件 @
378aaf38
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "tpaged
file
.h"
#include "tpaged
buf
.h"
#include "ttszip.h"
#include "ttszip.h"
typedef
struct
MinMaxEntry
{
typedef
struct
MinMaxEntry
{
...
@@ -63,7 +63,7 @@ typedef struct tMemBucket {
...
@@ -63,7 +63,7 @@ typedef struct tMemBucket {
__compar_fn_t
comparFn
;
__compar_fn_t
comparFn
;
tMemBucketSlot
*
pSlots
;
tMemBucketSlot
*
pSlots
;
SDiskbased
Result
Buf
*
pBuffer
;
SDiskbasedBuf
*
pBuffer
;
__perc_hash_func_t
hashFunc
;
__perc_hash_func_t
hashFunc
;
}
tMemBucket
;
}
tMemBucket
;
...
...
source/libs/function/src/thistogram.c
浏览文件 @
378aaf38
...
@@ -117,14 +117,14 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -117,14 +117,14 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
if
((
*
pHisto
)
->
ordered
)
{
if
((
*
pHisto
)
->
ordered
)
{
int32_t
lastIndex
=
(
*
pHisto
)
->
maxIndex
;
int32_t
lastIndex
=
(
*
pHisto
)
->
maxIndex
;
S
Loser
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
S
MultiwayMerge
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
(
*
pHisto
)
->
pLoserTree
->
pNode
[
lastIndex
+
pTree
->
numOfEntries
].
pData
=
pResNode
;
(
*
pHisto
)
->
pLoserTree
->
pNode
[
lastIndex
+
pTree
->
numOfEntries
].
pData
=
pResNode
;
pEntry1
->
index
=
(
*
pHisto
)
->
pLoserTree
->
pNode
[
lastIndex
+
pTree
->
numOfEntries
].
index
;
pEntry1
->
index
=
(
*
pHisto
)
->
pLoserTree
->
pNode
[
lastIndex
+
pTree
->
numOfEntries
].
index
;
// update the loser tree
// update the loser tree
if
((
*
pHisto
)
->
ordered
)
{
if
((
*
pHisto
)
->
ordered
)
{
t
Loser
TreeAdjust
(
pTree
,
pEntry1
->
index
+
pTree
->
numOfEntries
);
t
Merge
TreeAdjust
(
pTree
,
pEntry1
->
index
+
pTree
->
numOfEntries
);
}
}
tSkipListKey
kx
=
tSkipListKey
kx
=
...
@@ -142,10 +142,10 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -142,10 +142,10 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
SHistBin
*
pPrevEntry
=
(
SHistBin
*
)
pResNode
->
pBackward
[
0
]
->
pData
;
SHistBin
*
pPrevEntry
=
(
SHistBin
*
)
pResNode
->
pBackward
[
0
]
->
pData
;
pPrevEntry
->
delta
=
val
-
pPrevEntry
->
val
;
pPrevEntry
->
delta
=
val
-
pPrevEntry
->
val
;
S
Loser
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
S
MultiwayMerge
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
if
((
*
pHisto
)
->
ordered
)
{
if
((
*
pHisto
)
->
ordered
)
{
t
Loser
TreeAdjust
(
pTree
,
pPrevEntry
->
index
+
pTree
->
numOfEntries
);
t
Merge
TreeAdjust
(
pTree
,
pPrevEntry
->
index
+
pTree
->
numOfEntries
);
t
LoserTreeDisplay
(
pTree
);
t
MergeTreePrint
(
pTree
);
}
}
}
}
...
@@ -155,7 +155,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -155,7 +155,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
if
(
!
(
*
pHisto
)
->
ordered
)
{
if
(
!
(
*
pHisto
)
->
ordered
)
{
SSkipListPrint
((
*
pHisto
)
->
pList
,
1
);
SSkipListPrint
((
*
pHisto
)
->
pList
,
1
);
S
Loser
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
S
MultiwayMerge
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
tSkipListNode
*
pHead
=
(
*
pHisto
)
->
pList
->
pHead
.
pForward
[
0
];
tSkipListNode
*
pHead
=
(
*
pHisto
)
->
pList
->
pHead
.
pForward
[
0
];
tSkipListNode
*
p1
=
pHead
;
tSkipListNode
*
p1
=
pHead
;
...
@@ -183,13 +183,13 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -183,13 +183,13 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
pTree
->
pNode
[
i
].
index
=
-
1
;
pTree
->
pNode
[
i
].
index
=
-
1
;
}
}
t
LoserTreeDisplay
(
pTree
);
t
MergeTreePrint
(
pTree
);
for
(
int32_t
i
=
pTree
->
totalEntries
-
1
;
i
>=
pTree
->
numOfEntries
;
i
--
)
{
for
(
int32_t
i
=
pTree
->
totalEntries
-
1
;
i
>=
pTree
->
numOfEntries
;
i
--
)
{
t
Loser
TreeAdjust
(
pTree
,
i
);
t
Merge
TreeAdjust
(
pTree
,
i
);
}
}
t
LoserTreeDisplay
(
pTree
);
t
MergeTreePrint
(
pTree
);
(
*
pHisto
)
->
ordered
=
true
;
(
*
pHisto
)
->
ordered
=
true
;
}
}
...
@@ -219,7 +219,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -219,7 +219,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
pPrevEntry
->
delta
=
pEntry
->
val
-
pPrevEntry
->
val
;
pPrevEntry
->
delta
=
pEntry
->
val
-
pPrevEntry
->
val
;
}
}
S
Loser
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
S
MultiwayMerge
TreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
if
(
pNextEntry
->
index
!=
-
1
)
{
if
(
pNextEntry
->
index
!=
-
1
)
{
(
*
pHisto
)
->
maxIndex
=
pNextEntry
->
index
;
(
*
pHisto
)
->
maxIndex
=
pNextEntry
->
index
;
...
@@ -230,12 +230,12 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -230,12 +230,12 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
printf
(
"disappear index is:%d
\n
"
,
f
);
printf
(
"disappear index is:%d
\n
"
,
f
);
}
}
t
Loser
TreeAdjust
(
pTree
,
pEntry
->
index
+
pTree
->
numOfEntries
);
t
Merge
TreeAdjust
(
pTree
,
pEntry
->
index
+
pTree
->
numOfEntries
);
// remove the next node in skiplist
// remove the next node in skiplist
tSkipListRemoveNode
((
*
pHisto
)
->
pList
,
pNext
);
tSkipListRemoveNode
((
*
pHisto
)
->
pList
,
pNext
);
SSkipListPrint
((
*
pHisto
)
->
pList
,
1
);
SSkipListPrint
((
*
pHisto
)
->
pList
,
1
);
t
LoserTreeDisplay
((
*
pHisto
)
->
pLoserTree
);
t
MergeTreePrint
((
*
pHisto
)
->
pLoserTree
);
}
else
{
// add to heap
}
else
{
// add to heap
if
(
pResNode
->
pForward
[
0
]
!=
NULL
)
{
if
(
pResNode
->
pForward
[
0
]
!=
NULL
)
{
pEntry1
->
delta
=
((
SHistBin
*
)
pResNode
->
pForward
[
0
]
->
pData
)
->
val
-
val
;
pEntry1
->
delta
=
((
SHistBin
*
)
pResNode
->
pForward
[
0
]
->
pData
)
->
val
-
val
;
...
...
source/libs/function/src/tpercentile.c
浏览文件 @
378aaf38
...
@@ -15,10 +15,10 @@
...
@@ -15,10 +15,10 @@
#include <tglobal.h>
#include <tglobal.h>
#include "os.h"
#include "os.h"
#include "tpercentile.h"
#include "tpagedfile.h"
#include "taosdef.h"
#include "taosdef.h"
#include "tcompare.h"
#include "tcompare.h"
#include "tpagedbuf.h"
#include "tpercentile.h"
#include "ttypes.h"
#include "ttypes.h"
#define DEFAULT_NUM_OF_SLOT 1024
#define DEFAULT_NUM_OF_SLOT 1024
...
@@ -35,9 +35,9 @@ static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx)
...
@@ -35,9 +35,9 @@ static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx)
int32_t
offset
=
0
;
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
list
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
list
->
size
;
++
i
)
{
SPageInfo
*
pgInfo
=
*
(
SPageInfo
**
)
taosArrayGet
(
list
,
i
);
struct
SPageInfo
*
pgInfo
=
*
(
struct
SPageInfo
**
)
taosArrayGet
(
list
,
i
);
SFilePage
*
pg
=
get
ResBufPage
(
pMemBucket
->
pBuffer
,
pgInfo
->
pageId
);
SFilePage
*
pg
=
get
BufPage
(
pMemBucket
->
pBuffer
,
getPageId
(
pgInfo
)
);
memcpy
(
buffer
->
data
+
offset
,
pg
->
data
,
(
size_t
)(
pg
->
num
*
pMemBucket
->
bytes
));
memcpy
(
buffer
->
data
+
offset
,
pg
->
data
,
(
size_t
)(
pg
->
num
*
pMemBucket
->
bytes
));
offset
+=
(
int32_t
)(
pg
->
num
*
pMemBucket
->
bytes
);
offset
+=
(
int32_t
)(
pg
->
num
*
pMemBucket
->
bytes
);
...
@@ -98,8 +98,8 @@ double findOnlyResult(tMemBucket *pMemBucket) {
...
@@ -98,8 +98,8 @@ double findOnlyResult(tMemBucket *pMemBucket) {
SIDList
list
=
getDataBufPagesIdList
(
pMemBucket
->
pBuffer
,
groupId
);
SIDList
list
=
getDataBufPagesIdList
(
pMemBucket
->
pBuffer
,
groupId
);
assert
(
list
->
size
==
1
);
assert
(
list
->
size
==
1
);
SPageInfo
*
pgInfo
=
(
SPageInfo
*
)
taosArrayGetP
(
list
,
0
);
struct
SPageInfo
*
pgInfo
=
(
struct
SPageInfo
*
)
taosArrayGetP
(
list
,
0
);
SFilePage
*
pPage
=
get
ResBufPage
(
pMemBucket
->
pBuffer
,
pgInfo
->
pageId
);
SFilePage
*
pPage
=
get
BufPage
(
pMemBucket
->
pBuffer
,
getPageId
(
pgInfo
)
);
assert
(
pPage
->
num
==
1
);
assert
(
pPage
->
num
==
1
);
double
v
=
0
;
double
v
=
0
;
...
@@ -254,7 +254,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval,
...
@@ -254,7 +254,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval,
resetSlotInfo
(
pBucket
);
resetSlotInfo
(
pBucket
);
int32_t
ret
=
createDiskbased
Result
Buffer
(
&
pBucket
->
pBuffer
,
pBucket
->
bufPageSize
,
pBucket
->
bufPageSize
*
512
,
1
,
tsTempDir
);
int32_t
ret
=
createDiskbasedBuffer
(
&
pBucket
->
pBuffer
,
pBucket
->
bufPageSize
,
pBucket
->
bufPageSize
*
512
,
1
,
tsTempDir
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
tMemBucketDestroy
(
pBucket
);
tMemBucketDestroy
(
pBucket
);
return
NULL
;
return
NULL
;
...
@@ -343,7 +343,7 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
...
@@ -343,7 +343,7 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
assert
(
pSlot
->
info
.
data
->
num
>=
pBucket
->
elemPerPage
&&
pSlot
->
info
.
size
>
0
);
assert
(
pSlot
->
info
.
data
->
num
>=
pBucket
->
elemPerPage
&&
pSlot
->
info
.
size
>
0
);
// keep the pointer in memory
// keep the pointer in memory
release
Res
BufPage
(
pBucket
->
pBuffer
,
pSlot
->
info
.
data
);
releaseBufPage
(
pBucket
->
pBuffer
,
pSlot
->
info
.
data
);
pSlot
->
info
.
data
=
NULL
;
pSlot
->
info
.
data
=
NULL
;
}
}
...
@@ -471,10 +471,10 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction)
...
@@ -471,10 +471,10 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction)
for
(
int32_t
f
=
0
;
f
<
list
->
size
;
++
f
)
{
for
(
int32_t
f
=
0
;
f
<
list
->
size
;
++
f
)
{
SPageInfo
*
pgInfo
=
*
(
SPageInfo
**
)
taosArrayGet
(
list
,
f
);
SPageInfo
*
pgInfo
=
*
(
SPageInfo
**
)
taosArrayGet
(
list
,
f
);
SFilePage
*
pg
=
get
ResBufPage
(
pMemBucket
->
pBuffer
,
pgInfo
->
pageId
);
SFilePage
*
pg
=
get
BufPage
(
pMemBucket
->
pBuffer
,
getPageId
(
pgInfo
)
);
tMemBucketPut
(
pMemBucket
,
pg
->
data
,
(
int32_t
)
pg
->
num
);
tMemBucketPut
(
pMemBucket
,
pg
->
data
,
(
int32_t
)
pg
->
num
);
release
Res
BufPageInfo
(
pMemBucket
->
pBuffer
,
pgInfo
);
releaseBufPageInfo
(
pMemBucket
->
pBuffer
,
pgInfo
);
}
}
return
getPercentileImpl
(
pMemBucket
,
count
-
num
,
fraction
);
return
getPercentileImpl
(
pMemBucket
,
count
-
num
,
fraction
);
...
...
source/libs/planner/src/physicalPlan.c
浏览文件 @
378aaf38
...
@@ -216,7 +216,7 @@ static SPhyNode* createMultiTableScanNode(SQueryPlanNode* pPlanNode, SQueryTable
...
@@ -216,7 +216,7 @@ static SPhyNode* createMultiTableScanNode(SQueryPlanNode* pPlanNode, SQueryTable
}
else
if
(
needSeqScan
(
pPlanNode
))
{
}
else
if
(
needSeqScan
(
pPlanNode
))
{
return
createUserTableScanNode
(
pPlanNode
,
pTable
,
OP_TableSeqScan
);
return
createUserTableScanNode
(
pPlanNode
,
pTable
,
OP_TableSeqScan
);
}
}
int32_t
type
=
(
pPlanNode
->
info
.
type
==
QNODE_TABLESCAN
)
?
OP_
DataBlocksOpt
Scan
:
OP_StreamScan
;
int32_t
type
=
(
pPlanNode
->
info
.
type
==
QNODE_TABLESCAN
)
?
OP_
Table
Scan
:
OP_StreamScan
;
return
createUserTableScanNode
(
pPlanNode
,
pTable
,
type
);
return
createUserTableScanNode
(
pPlanNode
,
pTable
,
type
);
}
}
...
@@ -288,7 +288,7 @@ static bool needMultiNodeScan(SQueryTableInfo* pTable) {
...
@@ -288,7 +288,7 @@ static bool needMultiNodeScan(SQueryTableInfo* pTable) {
static
SPhyNode
*
createSingleTableScanNode
(
SQueryPlanNode
*
pPlanNode
,
SQueryTableInfo
*
pTableInfo
,
SSubplan
*
subplan
)
{
static
SPhyNode
*
createSingleTableScanNode
(
SQueryPlanNode
*
pPlanNode
,
SQueryTableInfo
*
pTableInfo
,
SSubplan
*
subplan
)
{
SVgroupsInfo
*
pVgroupsInfo
=
pTableInfo
->
pMeta
->
vgroupList
;
SVgroupsInfo
*
pVgroupsInfo
=
pTableInfo
->
pMeta
->
vgroupList
;
vgroupInfoToNodeAddr
(
&
(
pVgroupsInfo
->
vgroups
[
0
]),
&
subplan
->
execNode
);
vgroupInfoToNodeAddr
(
&
(
pVgroupsInfo
->
vgroups
[
0
]),
&
subplan
->
execNode
);
int32_t
type
=
(
pPlanNode
->
info
.
type
==
QNODE_TABLESCAN
)
?
OP_
DataBlocksOpt
Scan
:
OP_StreamScan
;
int32_t
type
=
(
pPlanNode
->
info
.
type
==
QNODE_TABLESCAN
)
?
OP_
Table
Scan
:
OP_StreamScan
;
return
createUserTableScanNode
(
pPlanNode
,
pTableInfo
,
type
);
return
createUserTableScanNode
(
pPlanNode
,
pTableInfo
,
type
);
}
}
...
...
source/libs/planner/src/physicalPlanJson.c
浏览文件 @
378aaf38
...
@@ -88,7 +88,7 @@ static const char* jkPnodeType = "Type";
...
@@ -88,7 +88,7 @@ static const char* jkPnodeType = "Type";
static
int32_t
getPnodeTypeSize
(
cJSON
*
json
)
{
static
int32_t
getPnodeTypeSize
(
cJSON
*
json
)
{
switch
(
getNumber
(
json
,
jkPnodeType
))
{
switch
(
getNumber
(
json
,
jkPnodeType
))
{
case
OP_StreamScan
:
case
OP_StreamScan
:
case
OP_
DataBlocksOpt
Scan
:
case
OP_
Table
Scan
:
case
OP_TableSeqScan
:
case
OP_TableSeqScan
:
return
sizeof
(
STableScanPhyNode
);
return
sizeof
(
STableScanPhyNode
);
case
OP_TagScan
:
case
OP_TagScan
:
...
@@ -830,7 +830,7 @@ static bool specificPhyNodeToJson(const void* obj, cJSON* json) {
...
@@ -830,7 +830,7 @@ static bool specificPhyNodeToJson(const void* obj, cJSON* json) {
const
SPhyNode
*
phyNode
=
(
const
SPhyNode
*
)
obj
;
const
SPhyNode
*
phyNode
=
(
const
SPhyNode
*
)
obj
;
switch
(
phyNode
->
info
.
type
)
{
switch
(
phyNode
->
info
.
type
)
{
case
OP_StreamScan
:
case
OP_StreamScan
:
case
OP_
DataBlocksOpt
Scan
:
case
OP_
Table
Scan
:
case
OP_TableSeqScan
:
case
OP_TableSeqScan
:
return
tableScanNodeToJson
(
obj
,
json
);
return
tableScanNodeToJson
(
obj
,
json
);
case
OP_TagScan
:
case
OP_TagScan
:
...
@@ -868,7 +868,7 @@ static bool specificPhyNodeFromJson(const cJSON* json, void* obj) {
...
@@ -868,7 +868,7 @@ static bool specificPhyNodeFromJson(const cJSON* json, void* obj) {
SPhyNode
*
phyNode
=
(
SPhyNode
*
)
obj
;
SPhyNode
*
phyNode
=
(
SPhyNode
*
)
obj
;
switch
(
phyNode
->
info
.
type
)
{
switch
(
phyNode
->
info
.
type
)
{
case
OP_StreamScan
:
case
OP_StreamScan
:
case
OP_
DataBlocksOpt
Scan
:
case
OP_
Table
Scan
:
case
OP_TableSeqScan
:
case
OP_TableSeqScan
:
return
tableScanNodeFromJson
(
json
,
obj
);
return
tableScanNodeFromJson
(
json
,
obj
);
case
OP_TagScan
:
case
OP_TagScan
:
...
...
source/util/src/tlosertree.c
浏览文件 @
378aaf38
...
@@ -14,82 +14,85 @@
...
@@ -14,82 +14,85 @@
*/
*/
#include "os.h"
#include "os.h"
#include "tlosertree.h"
#include "ulog.h"
#include "ulog.h"
#include "tlosertree.h"
#include "taoserror.h"
//
set initial value for loser tree
//
Set the initial value of the multiway merge tree.
void
tLoserTreeInit
(
SLoser
TreeInfo
*
pTree
)
{
static
void
tMergeTreeInit
(
SMultiwayMerge
TreeInfo
*
pTree
)
{
assert
((
pTree
->
total
Entries
&
0x01
)
==
0
&&
(
pTree
->
numOfEntries
<<
1
==
pTree
->
totalEntri
es
));
assert
((
pTree
->
total
Sources
&
0x01
)
==
0
&&
(
pTree
->
numOfSources
<<
1
==
pTree
->
totalSourc
es
));
for
(
int32_t
i
=
0
;
i
<
pTree
->
total
Entri
es
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pTree
->
total
Sourc
es
;
++
i
)
{
if
(
i
<
pTree
->
numOf
Entri
es
)
{
if
(
i
<
pTree
->
numOf
Sourc
es
)
{
pTree
->
pNode
[
i
].
index
=
-
1
;
pTree
->
pNode
[
i
].
index
=
-
1
;
}
else
{
}
else
{
pTree
->
pNode
[
i
].
index
=
i
-
pTree
->
numOf
Entri
es
;
pTree
->
pNode
[
i
].
index
=
i
-
pTree
->
numOf
Sourc
es
;
}
}
}
}
}
}
/*
int32_t
tMergeTreeCreate
(
SMultiwayMergeTreeInfo
**
pTree
,
uint32_t
numOfSources
,
void
*
param
,
__merge_compare_fn_t
compareFn
)
{
* display whole loser tree on screen for debug purpose only.
int32_t
totalEntries
=
numOfSources
<<
1u
;
*/
void
tLoserTreeDisplay
(
SLoserTreeInfo
*
pTree
)
{
printf
(
"the value of loser tree:
\t
"
);
for
(
int32_t
i
=
0
;
i
<
pTree
->
totalEntries
;
++
i
)
printf
(
"%d
\t
"
,
pTree
->
pNode
[
i
].
index
);
printf
(
"
\n
"
);
}
uint32_t
tLoserTreeCreate
(
SLoserTreeInfo
**
pTree
,
int32_t
numOfEntries
,
void
*
param
,
__merge_compare_fn_t
compareFn
)
{
SMultiwayMergeTreeInfo
*
pTreeInfo
=
(
SMultiwayMergeTreeInfo
*
)
calloc
(
1
,
sizeof
(
SMultiwayMergeTreeInfo
)
+
sizeof
(
STreeNode
)
*
totalEntries
);
int32_t
totalEntries
=
numOfEntries
<<
1
;
if
(
pTreeInfo
==
NULL
)
{
*
pTree
=
(
SLoserTreeInfo
*
)
calloc
(
1
,
sizeof
(
SLoserTreeInfo
)
+
sizeof
(
SLoserTreeNode
)
*
totalEntries
);
if
((
*
pTree
)
==
NULL
)
{
uError
(
"allocate memory for loser-tree failed. reason:%s"
,
strerror
(
errno
));
uError
(
"allocate memory for loser-tree failed. reason:%s"
,
strerror
(
errno
));
return
-
1
;
return
TAOS_SYSTEM_ERROR
(
errno
)
;
}
}
(
*
pTree
)
->
pNode
=
(
SLoserTreeNode
*
)(((
char
*
)(
*
pTree
))
+
sizeof
(
SLoser
TreeInfo
));
pTreeInfo
->
pNode
=
(
STreeNode
*
)(((
char
*
)
pTreeInfo
)
+
sizeof
(
SMultiwayMerge
TreeInfo
));
(
*
pTree
)
->
numOfEntries
=
numOfEntri
es
;
pTreeInfo
->
numOfSources
=
numOfSourc
es
;
(
*
pTree
)
->
totalEntri
es
=
totalEntries
;
pTreeInfo
->
totalSourc
es
=
totalEntries
;
(
*
pTree
)
->
param
=
param
;
pTreeInfo
->
param
=
param
;
(
*
pTree
)
->
comparFn
=
compareFn
;
pTreeInfo
->
comparFn
=
compareFn
;
// set initial value for loser tree
// set initial value for loser tree
t
LoserTreeInit
(
*
pTree
);
t
MergeTreeInit
(
pTreeInfo
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"the initial value of loser tree:
\n
"
);
printf
(
"the initial value of loser tree:
\n
"
);
tLoserTreeDisplay
(
*
pTree
)
;
tLoserTreeDisplay
pTreeInfo
;
#endif
#endif
for
(
int32_t
i
=
totalEntries
-
1
;
i
>=
numOf
Entri
es
;
i
--
)
{
for
(
int32_t
i
=
totalEntries
-
1
;
i
>=
numOf
Sourc
es
;
i
--
)
{
t
LoserTreeAdjust
(
*
pTree
,
i
);
t
MergeTreeAdjust
(
pTreeInfo
,
i
);
}
}
#if defined(_DEBUG_VIEW)
#if defined(_DEBUG_VIEW)
printf
(
"after adjust:
\n
"
);
printf
(
"after adjust:
\n
"
);
tLoserTreeDisplay
(
*
pTree
)
;
tLoserTreeDisplay
pTreeInfo
;
printf
(
"initialize local reducer completed!
\n
"
);
printf
(
"initialize local reducer completed!
\n
"
);
#endif
#endif
*
pTree
=
pTreeInfo
;
return
0
;
return
0
;
}
}
void
tLoserTreeAdjust
(
SLoserTreeInfo
*
pTree
,
int32_t
idx
)
{
void
tMergeTreeDestroy
(
SMultiwayMergeTreeInfo
*
pTree
)
{
assert
(
idx
<=
pTree
->
totalEntries
-
1
&&
idx
>=
pTree
->
numOfEntries
&&
pTree
->
totalEntries
>=
2
);
if
(
pTree
==
NULL
)
{
return
;
}
if
(
pTree
->
totalEntries
==
2
)
{
tfree
(
pTree
);
}
void
tMergeTreeAdjust
(
SMultiwayMergeTreeInfo
*
pTree
,
int32_t
idx
)
{
assert
(
idx
<=
pTree
->
totalSources
-
1
&&
idx
>=
pTree
->
numOfSources
&&
pTree
->
totalSources
>=
2
);
if
(
pTree
->
totalSources
==
2
)
{
pTree
->
pNode
[
0
].
index
=
0
;
pTree
->
pNode
[
0
].
index
=
0
;
pTree
->
pNode
[
1
].
index
=
0
;
pTree
->
pNode
[
1
].
index
=
0
;
return
;
return
;
}
}
int32_t
parentId
=
idx
>>
1
;
int32_t
parentId
=
idx
>>
1
;
S
Loser
TreeNode
kLeaf
=
pTree
->
pNode
[
idx
];
STreeNode
kLeaf
=
pTree
->
pNode
[
idx
];
while
(
parentId
>
0
)
{
while
(
parentId
>
0
)
{
S
Loser
TreeNode
*
pCur
=
&
pTree
->
pNode
[
parentId
];
STreeNode
*
pCur
=
&
pTree
->
pNode
[
parentId
];
if
(
pCur
->
index
==
-
1
)
{
if
(
pCur
->
index
==
-
1
)
{
pTree
->
pNode
[
parentId
]
=
kLeaf
;
pTree
->
pNode
[
parentId
]
=
kLeaf
;
return
;
return
;
...
@@ -97,7 +100,7 @@ void tLoserTreeAdjust(SLoserTreeInfo* pTree, int32_t idx) {
...
@@ -97,7 +100,7 @@ void tLoserTreeAdjust(SLoserTreeInfo* pTree, int32_t idx) {
int32_t
ret
=
pTree
->
comparFn
(
pCur
,
&
kLeaf
,
pTree
->
param
);
int32_t
ret
=
pTree
->
comparFn
(
pCur
,
&
kLeaf
,
pTree
->
param
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
S
Loser
TreeNode
t
=
pTree
->
pNode
[
parentId
];
STreeNode
t
=
pTree
->
pNode
[
parentId
];
pTree
->
pNode
[
parentId
]
=
kLeaf
;
pTree
->
pNode
[
parentId
]
=
kLeaf
;
kLeaf
=
t
;
kLeaf
=
t
;
}
}
...
@@ -111,11 +114,23 @@ void tLoserTreeAdjust(SLoserTreeInfo* pTree, int32_t idx) {
...
@@ -111,11 +114,23 @@ void tLoserTreeAdjust(SLoserTreeInfo* pTree, int32_t idx) {
}
}
}
}
void
tLoserTreeRebuild
(
SLoserTreeInfo
*
pTree
)
{
void
tMergeTreeRebuild
(
SMultiwayMergeTreeInfo
*
pTree
)
{
assert
((
pTree
->
totalEntries
&
0x1
)
==
0
);
assert
((
pTree
->
totalSources
&
0x1
)
==
0
);
tMergeTreeInit
(
pTree
);
for
(
int32_t
i
=
pTree
->
totalSources
-
1
;
i
>=
pTree
->
numOfSources
;
i
--
)
{
tMergeTreeAdjust
(
pTree
,
i
);
}
}
tLoserTreeInit
(
pTree
);
/*
for
(
int32_t
i
=
pTree
->
totalEntries
-
1
;
i
>=
pTree
->
numOfEntries
;
i
--
)
{
* display whole loser tree on screen for debug purpose only.
tLoserTreeAdjust
(
pTree
,
i
);
*/
void
tMergeTreePrint
(
const
SMultiwayMergeTreeInfo
*
pTree
)
{
printf
(
"the value of loser tree:
\t
"
);
for
(
int32_t
i
=
0
;
i
<
pTree
->
totalSources
;
++
i
)
{
printf
(
"%d
\t
"
,
pTree
->
pNode
[
i
].
index
);
}
}
printf
(
"
\n
"
);
}
}
source/util/src/tpaged
file
.c
→
source/util/src/tpaged
buf
.c
浏览文件 @
378aaf38
/*
#include "os.h"
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
#include "ulog.h"
*
#include "tpagedbuf.h"
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "tpagedfile.h"
#include "thash.h"
#include "stddef.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tcompression.h"
#include "tcompression.h"
#include "thash.h"
#define GET_DATA_PAYLOAD(_p) ((char *)(_p)->pData + POINTER_BYTES)
#define GET_DATA_PAYLOAD(_p) ((char *)(_p)->pData + POINTER_BYTES)
#define NO_IN_MEM_AVAILABLE_PAGES(_b) (listNEles((_b)->lruList) >= (_b)->inMemPages)
#define NO_IN_MEM_AVAILABLE_PAGES(_b) (listNEles((_b)->lruList) >= (_b)->inMemPages)
int32_t
createDiskbasedResultBuffer
(
SDiskbasedResultBuf
**
pResultBuf
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
uint64_t
qId
,
const
char
*
dir
)
{
typedef
struct
SFreeListItem
{
*
pResultBuf
=
calloc
(
1
,
sizeof
(
SDiskbasedResultBuf
));
int32_t
offset
;
int32_t
len
;
SDiskbasedResultBuf
*
pResBuf
=
*
pResultBuf
;
}
SFreeListItem
;
typedef
struct
SPageDiskInfo
{
int64_t
offset
;
int32_t
length
;
}
SPageDiskInfo
;
typedef
struct
SPageInfo
{
SListNode
*
pn
;
// point to list node
void
*
pData
;
int64_t
offset
;
int32_t
pageId
;
int32_t
length
:
30
;
bool
used
:
1
;
// set current page is in used
bool
dirty
:
1
;
// set current buffer page is dirty or not
}
SPageInfo
;
typedef
struct
SDiskbasedBuf
{
int32_t
numOfPages
;
int64_t
totalBufSize
;
uint64_t
fileSize
;
// disk file size
FILE
*
file
;
int32_t
allocateId
;
// allocated page id
char
*
path
;
// file path
int32_t
pageSize
;
// current used page size
int32_t
inMemPages
;
// numOfPages that are allocated in memory
SHashObj
*
groupSet
;
// id hash table
SHashObj
*
all
;
SList
*
lruList
;
void
*
emptyDummyIdList
;
// dummy id list
void
*
assistBuf
;
// assistant buffer for compress/decompress data
SArray
*
pFree
;
// free area in file
bool
comp
;
// compressed before flushed to disk
uint64_t
nextPos
;
// next page flush position
uint64_t
qId
;
// for debug purpose
bool
printStatis
;
// Print statistics info when closing this buffer.
SDiskbasedBufStatis
statis
;
}
SDiskbasedBuf
;
static
void
printStatisData
(
const
SDiskbasedBuf
*
pBuf
);
int32_t
createDiskbasedBuffer
(
SDiskbasedBuf
**
pBuf
,
int32_t
pagesize
,
int32_t
inMemBufSize
,
uint64_t
qId
,
const
char
*
dir
)
{
*
pBuf
=
calloc
(
1
,
sizeof
(
SDiskbasedBuf
));
SDiskbasedBuf
*
pResBuf
=
*
pBuf
;
if
(
pResBuf
==
NULL
)
{
if
(
pResBuf
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
...
@@ -64,50 +93,50 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t pa
...
@@ -64,50 +93,50 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t pa
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
createDiskFile
(
SDiskbased
ResultBuf
*
pResult
Buf
)
{
static
int32_t
createDiskFile
(
SDiskbased
Buf
*
p
Buf
)
{
p
ResultBuf
->
file
=
fopen
(
pResult
Buf
->
path
,
"wb+"
);
p
Buf
->
file
=
fopen
(
p
Buf
->
path
,
"wb+"
);
if
(
p
Result
Buf
->
file
==
NULL
)
{
if
(
pBuf
->
file
==
NULL
)
{
// qError("failed to create tmp file: %s on disk. %s", p
Result
Buf->path, strerror(errno));
// qError("failed to create tmp file: %s on disk. %s", pBuf->path, strerror(errno));
return
TAOS_SYSTEM_ERROR
(
errno
);
return
TAOS_SYSTEM_ERROR
(
errno
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
char
*
doCompressData
(
void
*
data
,
int32_t
srcSize
,
int32_t
*
dst
,
SDiskbased
ResultBuf
*
pResult
Buf
)
{
// do nothing
static
char
*
doCompressData
(
void
*
data
,
int32_t
srcSize
,
int32_t
*
dst
,
SDiskbased
Buf
*
p
Buf
)
{
// do nothing
if
(
!
p
Result
Buf
->
comp
)
{
if
(
!
pBuf
->
comp
)
{
*
dst
=
srcSize
;
*
dst
=
srcSize
;
return
data
;
return
data
;
}
}
*
dst
=
tsCompressString
(
data
,
srcSize
,
1
,
p
Result
Buf
->
assistBuf
,
srcSize
,
ONE_STAGE_COMP
,
NULL
,
0
);
*
dst
=
tsCompressString
(
data
,
srcSize
,
1
,
pBuf
->
assistBuf
,
srcSize
,
ONE_STAGE_COMP
,
NULL
,
0
);
memcpy
(
data
,
p
Result
Buf
->
assistBuf
,
*
dst
);
memcpy
(
data
,
pBuf
->
assistBuf
,
*
dst
);
return
data
;
return
data
;
}
}
static
char
*
doDecompressData
(
void
*
data
,
int32_t
srcSize
,
int32_t
*
dst
,
SDiskbased
ResultBuf
*
pResult
Buf
)
{
// do nothing
static
char
*
doDecompressData
(
void
*
data
,
int32_t
srcSize
,
int32_t
*
dst
,
SDiskbased
Buf
*
p
Buf
)
{
// do nothing
if
(
!
p
Result
Buf
->
comp
)
{
if
(
!
pBuf
->
comp
)
{
*
dst
=
srcSize
;
*
dst
=
srcSize
;
return
data
;
return
data
;
}
}
*
dst
=
tsDecompressString
(
data
,
srcSize
,
1
,
p
ResultBuf
->
assistBuf
,
pResultBuf
->
pageSize
,
ONE_STAGE_COMP
,
NULL
,
0
);
*
dst
=
tsDecompressString
(
data
,
srcSize
,
1
,
p
Buf
->
assistBuf
,
pBuf
->
pageSize
+
sizeof
(
SFilePage
)
,
ONE_STAGE_COMP
,
NULL
,
0
);
if
(
*
dst
>
0
)
{
if
(
*
dst
>
0
)
{
memcpy
(
data
,
p
Result
Buf
->
assistBuf
,
*
dst
);
memcpy
(
data
,
pBuf
->
assistBuf
,
*
dst
);
}
}
return
data
;
return
data
;
}
}
static
int32_t
allocatePositionInFile
(
SDiskbasedResultBuf
*
pResult
Buf
,
size_t
size
)
{
static
uint64_t
allocatePositionInFile
(
SDiskbasedBuf
*
p
Buf
,
size_t
size
)
{
if
(
p
Result
Buf
->
pFree
==
NULL
)
{
if
(
pBuf
->
pFree
==
NULL
)
{
return
p
Result
Buf
->
nextPos
;
return
pBuf
->
nextPos
;
}
else
{
}
else
{
int32_t
offset
=
-
1
;
int32_t
offset
=
-
1
;
size_t
num
=
taosArrayGetSize
(
p
Result
Buf
->
pFree
);
size_t
num
=
taosArrayGetSize
(
pBuf
->
pFree
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SFreeListItem
*
pi
=
taosArrayGet
(
p
Result
Buf
->
pFree
,
i
);
SFreeListItem
*
pi
=
taosArrayGet
(
pBuf
->
pFree
,
i
);
if
(
pi
->
len
>=
size
)
{
if
(
pi
->
len
>=
size
)
{
offset
=
pi
->
offset
;
offset
=
pi
->
offset
;
pi
->
offset
+=
(
int32_t
)
size
;
pi
->
offset
+=
(
int32_t
)
size
;
...
@@ -118,135 +147,162 @@ static int32_t allocatePositionInFile(SDiskbasedResultBuf* pResultBuf, size_t si
...
@@ -118,135 +147,162 @@ static int32_t allocatePositionInFile(SDiskbasedResultBuf* pResultBuf, size_t si
}
}
// no available recycle space, allocate new area in file
// no available recycle space, allocate new area in file
return
p
Result
Buf
->
nextPos
;
return
pBuf
->
nextPos
;
}
}
}
}
static
char
*
doFlushPageToDisk
(
SDiskbased
ResultBuf
*
pResult
Buf
,
SPageInfo
*
pg
)
{
static
char
*
doFlushPageToDisk
(
SDiskbased
Buf
*
p
Buf
,
SPageInfo
*
pg
)
{
assert
(
!
pg
->
used
&&
pg
->
pData
!=
NULL
);
assert
(
!
pg
->
used
&&
pg
->
pData
!=
NULL
);
int32_t
size
=
-
1
;
int32_t
size
=
-
1
;
char
*
t
=
doCompressData
(
GET_DATA_PAYLOAD
(
pg
),
pResultBuf
->
pageSize
,
&
size
,
pResultBuf
);
char
*
t
=
NULL
;
if
(
pg
->
offset
==
-
1
||
pg
->
dirty
)
{
SFilePage
*
pPage
=
(
SFilePage
*
)
GET_DATA_PAYLOAD
(
pg
);
t
=
doCompressData
(
pPage
->
data
,
pBuf
->
pageSize
,
&
size
,
pBuf
);
}
// this page is flushed to disk for the first time
// this page is flushed to disk for the first time
if
(
pg
->
info
.
offset
==
-
1
)
{
if
(
pg
->
offset
==
-
1
)
{
pg
->
info
.
offset
=
allocatePositionInFile
(
pResultBuf
,
size
);
assert
(
pg
->
dirty
==
true
);
pResultBuf
->
nextPos
+=
size
;
int32_t
ret
=
fseek
(
pResultBuf
->
file
,
pg
->
info
.
offset
,
SEEK_SET
);
pg
->
offset
=
allocatePositionInFile
(
pBuf
,
size
);
assert
(
ret
==
0
);
pBuf
->
nextPos
+=
size
;
int32_t
ret
=
fseek
(
pBuf
->
file
,
pg
->
offset
,
SEEK_SET
);
if
(
ret
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
}
ret
=
(
int32_t
)
fwrite
(
t
,
1
,
size
,
pResultBuf
->
file
);
ret
=
(
int32_t
)
fwrite
(
t
,
1
,
size
,
pBuf
->
file
);
assert
(
ret
==
size
);
if
(
ret
!=
size
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
}
if
(
p
ResultBuf
->
fileSize
<
pg
->
info
.
offset
+
pg
->
info
.
length
)
{
if
(
p
Buf
->
fileSize
<
pg
->
offset
+
size
)
{
p
ResultBuf
->
fileSize
=
pg
->
info
.
offset
+
pg
->
info
.
length
;
p
Buf
->
fileSize
=
pg
->
offset
+
size
;
}
}
}
else
{
pBuf
->
statis
.
flushBytes
+=
size
;
pBuf
->
statis
.
flushPages
+=
1
;
}
else
if
(
pg
->
dirty
)
{
// length becomes greater, current space is not enough, allocate new place, otherwise, do nothing
// length becomes greater, current space is not enough, allocate new place, otherwise, do nothing
if
(
pg
->
info
.
length
<
size
)
{
if
(
pg
->
length
<
size
)
{
// 1. add current space to free list
// 1. add current space to free list
taosArrayPush
(
pResultBuf
->
pFree
,
&
pg
->
info
);
SPageDiskInfo
dinfo
=
{.
length
=
pg
->
length
,
.
offset
=
pg
->
offset
};
taosArrayPush
(
pBuf
->
pFree
,
&
dinfo
);
// 2. allocate new position, and update the info
// 2. allocate new position, and update the info
pg
->
info
.
offset
=
allocatePositionInFile
(
pResult
Buf
,
size
);
pg
->
offset
=
allocatePositionInFile
(
p
Buf
,
size
);
p
Result
Buf
->
nextPos
+=
size
;
pBuf
->
nextPos
+=
size
;
}
}
//3. write to disk.
// 3. write to disk.
int32_t
ret
=
fseek
(
pResultBuf
->
file
,
pg
->
info
.
offset
,
SEEK_SET
);
int32_t
ret
=
fseek
(
pBuf
->
file
,
pg
->
offset
,
SEEK_SET
);
if
(
ret
!=
0
)
{
// todo handle the error case
if
(
ret
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
}
}
ret
=
(
int32_t
)
fwrite
(
t
,
size
,
1
,
pResultBuf
->
file
);
ret
=
(
int32_t
)
fwrite
(
t
,
1
,
size
,
pBuf
->
file
);
if
(
ret
!=
size
)
{
// todo handle the error case
if
(
ret
!=
size
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
}
}
if
(
p
ResultBuf
->
fileSize
<
pg
->
info
.
offset
+
pg
->
info
.
length
)
{
if
(
p
Buf
->
fileSize
<
pg
->
offset
+
size
)
{
p
ResultBuf
->
fileSize
=
pg
->
info
.
offset
+
pg
->
info
.
length
;
p
Buf
->
fileSize
=
pg
->
offset
+
size
;
}
}
}
char
*
ret
=
pg
->
pData
;
pBuf
->
statis
.
flushBytes
+=
size
;
memset
(
ret
,
0
,
pResultBuf
->
pageSize
);
pBuf
->
statis
.
flushPages
+=
1
;
}
pg
->
pData
=
NULL
;
char
*
pDataBuf
=
pg
->
pData
;
pg
->
info
.
length
=
size
;
memset
(
pDataBuf
,
0
,
pBuf
->
pageSize
+
sizeof
(
SFilePage
))
;
pResultBuf
->
statis
.
flushBytes
+=
pg
->
info
.
length
;
pg
->
pData
=
NULL
;
// this means the data is not in buffer
pg
->
length
=
size
;
pg
->
dirty
=
false
;
return
ret
;
return
pDataBuf
;
}
}
static
char
*
flushPageToDisk
(
SDiskbased
ResultBuf
*
pResult
Buf
,
SPageInfo
*
pg
)
{
static
char
*
flushPageToDisk
(
SDiskbased
Buf
*
p
Buf
,
SPageInfo
*
pg
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
assert
(((
int64_t
)
p
ResultBuf
->
numOfPages
*
pResultBuf
->
pageSize
)
==
pResultBuf
->
totalBufSize
&&
pResultBuf
->
numOfPages
>=
pResult
Buf
->
inMemPages
);
assert
(((
int64_t
)
p
Buf
->
numOfPages
*
pBuf
->
pageSize
)
==
pBuf
->
totalBufSize
&&
pBuf
->
numOfPages
>=
p
Buf
->
inMemPages
);
if
(
p
Result
Buf
->
file
==
NULL
)
{
if
(
pBuf
->
file
==
NULL
)
{
if
((
ret
=
createDiskFile
(
p
Result
Buf
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
ret
=
createDiskFile
(
pBuf
))
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
ret
;
terrno
=
ret
;
return
NULL
;
return
NULL
;
}
}
}
}
return
doFlushPageToDisk
(
p
Result
Buf
,
pg
);
return
doFlushPageToDisk
(
pBuf
,
pg
);
}
}
// load file block data in disk
// load file block data in disk
static
char
*
loadPageFromDisk
(
SDiskbasedResultBuf
*
pResultBuf
,
SPageInfo
*
pg
)
{
static
int32_t
loadPageFromDisk
(
SDiskbasedBuf
*
pBuf
,
SPageInfo
*
pg
)
{
int32_t
ret
=
fseek
(
pResultBuf
->
file
,
pg
->
info
.
offset
,
SEEK_SET
);
int32_t
ret
=
fseek
(
pBuf
->
file
,
pg
->
offset
,
SEEK_SET
);
ret
=
(
int32_t
)
fread
(
GET_DATA_PAYLOAD
(
pg
),
1
,
pg
->
info
.
length
,
pResultBuf
->
file
);
if
(
ret
!=
0
)
{
if
(
ret
!=
pg
->
info
.
length
)
{
ret
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
errno
;
return
ret
;
return
NULL
;
}
}
pResultBuf
->
statis
.
loadBytes
+=
pg
->
info
.
length
;
SFilePage
*
pPage
=
(
SFilePage
*
)
GET_DATA_PAYLOAD
(
pg
);
ret
=
(
int32_t
)
fread
(
pPage
->
data
,
1
,
pg
->
length
,
pBuf
->
file
);
if
(
ret
!=
pg
->
length
)
{
ret
=
TAOS_SYSTEM_ERROR
(
errno
);
return
ret
;
}
int32_t
fullSize
=
0
;
pBuf
->
statis
.
loadBytes
+=
pg
->
length
;
doDecompressData
(
GET_DATA_PAYLOAD
(
pg
),
pg
->
info
.
length
,
&
fullSize
,
pResultBuf
)
;
pBuf
->
statis
.
loadPages
+=
1
;
return
(
char
*
)
GET_DATA_PAYLOAD
(
pg
);
int32_t
fullSize
=
0
;
doDecompressData
(
pPage
->
data
,
pg
->
length
,
&
fullSize
,
pBuf
);
return
0
;
}
}
static
SIDList
addNewGroup
(
SDiskbased
ResultBuf
*
pResult
Buf
,
int32_t
groupId
)
{
static
SIDList
addNewGroup
(
SDiskbased
Buf
*
p
Buf
,
int32_t
groupId
)
{
assert
(
taosHashGet
(
p
Result
Buf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
))
==
NULL
);
assert
(
taosHashGet
(
pBuf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
))
==
NULL
);
SArray
*
pa
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
pa
=
taosArrayInit
(
1
,
POINTER_BYTES
);
int32_t
ret
=
taosHashPut
(
p
Result
Buf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
),
&
pa
,
POINTER_BYTES
);
int32_t
ret
=
taosHashPut
(
pBuf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
),
&
pa
,
POINTER_BYTES
);
assert
(
ret
==
0
);
assert
(
ret
==
0
);
return
pa
;
return
pa
;
}
}
static
SPageInfo
*
registerPage
(
SDiskbased
ResultBuf
*
pResult
Buf
,
int32_t
groupId
,
int32_t
pageId
)
{
static
SPageInfo
*
registerPage
(
SDiskbased
Buf
*
p
Buf
,
int32_t
groupId
,
int32_t
pageId
)
{
SIDList
list
=
NULL
;
SIDList
list
=
NULL
;
char
**
p
=
taosHashGet
(
p
Result
Buf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
));
char
**
p
=
taosHashGet
(
pBuf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
));
if
(
p
==
NULL
)
{
// it is a new group id
if
(
p
==
NULL
)
{
// it is a new group id
list
=
addNewGroup
(
p
Result
Buf
,
groupId
);
list
=
addNewGroup
(
pBuf
,
groupId
);
}
else
{
}
else
{
list
=
(
SIDList
)
(
*
p
);
list
=
(
SIDList
)
(
*
p
);
}
}
p
Result
Buf
->
numOfPages
+=
1
;
pBuf
->
numOfPages
+=
1
;
SPageInfo
*
ppi
=
malloc
(
sizeof
(
SPageInfo
));
//{ .info = PAGE_INFO_INITIALIZER, .pageId = pageId, .pn = NULL};
SPageInfo
*
ppi
=
malloc
(
sizeof
(
SPageInfo
));
//{ .info = PAGE_INFO_INITIALIZER, .pageId = pageId, .pn = NULL};
ppi
->
pageId
=
pageId
;
ppi
->
pageId
=
pageId
;
ppi
->
pData
=
NULL
;
ppi
->
pData
=
NULL
;
ppi
->
info
=
PAGE_INFO_INITIALIZER
;
ppi
->
offset
=
-
1
;
ppi
->
length
=
-
1
;
ppi
->
used
=
true
;
ppi
->
used
=
true
;
ppi
->
pn
=
NULL
;
ppi
->
pn
=
NULL
;
return
*
(
SPageInfo
**
)
taosArrayPush
(
list
,
&
ppi
);
return
*
(
SPageInfo
**
)
taosArrayPush
(
list
,
&
ppi
);
}
}
static
SListNode
*
getEldestUnrefedPage
(
SDiskbased
ResultBuf
*
pResult
Buf
)
{
static
SListNode
*
getEldestUnrefedPage
(
SDiskbased
Buf
*
p
Buf
)
{
SListIter
iter
=
{
0
};
SListIter
iter
=
{
0
};
tdListInitIter
(
p
Result
Buf
->
lruList
,
&
iter
,
TD_LIST_BACKWARD
);
tdListInitIter
(
pBuf
->
lruList
,
&
iter
,
TD_LIST_BACKWARD
);
SListNode
*
pn
=
NULL
;
SListNode
*
pn
=
NULL
;
while
((
pn
=
tdListNext
(
&
iter
))
!=
NULL
)
{
while
((
pn
=
tdListNext
(
&
iter
))
!=
NULL
)
{
...
@@ -263,22 +319,22 @@ static SListNode* getEldestUnrefedPage(SDiskbasedResultBuf* pResultBuf) {
...
@@ -263,22 +319,22 @@ static SListNode* getEldestUnrefedPage(SDiskbasedResultBuf* pResultBuf) {
return
pn
;
return
pn
;
}
}
static
char
*
ev
icOneDataPage
(
SDiskbasedResultBuf
*
pResult
Buf
)
{
static
char
*
ev
acOneDataPage
(
SDiskbasedBuf
*
p
Buf
)
{
char
*
bufPage
=
NULL
;
char
*
bufPage
=
NULL
;
SListNode
*
pn
=
getEldestUnrefedPage
(
p
Result
Buf
);
SListNode
*
pn
=
getEldestUnrefedPage
(
pBuf
);
// all pages are referenced by user, try to allocate new space
// all pages are referenced by user, try to allocate new space
if
(
pn
==
NULL
)
{
if
(
pn
==
NULL
)
{
int32_t
prev
=
pResultBuf
->
inMemPages
;
assert
(
0
);
int32_t
prev
=
pBuf
->
inMemPages
;
// increase by 50% of previous mem pages
// increase by 50% of previous mem pages
p
ResultBuf
->
inMemPages
=
(
int32_t
)(
pResult
Buf
->
inMemPages
*
1
.
5
f
);
p
Buf
->
inMemPages
=
(
int32_t
)(
p
Buf
->
inMemPages
*
1
.
5
f
);
// qWarn("%p in memory buf page not sufficient, expand from %d to %d, page size:%d", p
Result
Buf, prev,
// qWarn("%p in memory buf page not sufficient, expand from %d to %d, page size:%d", pBuf, prev,
// p
ResultBuf->inMemPages, pResult
Buf->pageSize);
// p
Buf->inMemPages, p
Buf->pageSize);
}
else
{
}
else
{
pResultBuf
->
statis
.
flushPages
+=
1
;
tdListPopNode
(
pBuf
->
lruList
,
pn
);
tdListPopNode
(
pResultBuf
->
lruList
,
pn
);
SPageInfo
*
d
=
*
(
SPageInfo
**
)
pn
->
data
;
SPageInfo
*
d
=
*
(
SPageInfo
**
)
pn
->
data
;
assert
(
d
->
pn
==
pn
);
assert
(
d
->
pn
==
pn
);
...
@@ -286,7 +342,7 @@ static char* evicOneDataPage(SDiskbasedResultBuf* pResultBuf) {
...
@@ -286,7 +342,7 @@ static char* evicOneDataPage(SDiskbasedResultBuf* pResultBuf) {
d
->
pn
=
NULL
;
d
->
pn
=
NULL
;
tfree
(
pn
);
tfree
(
pn
);
bufPage
=
flushPageToDisk
(
p
Result
Buf
,
d
);
bufPage
=
flushPageToDisk
(
pBuf
,
d
);
}
}
return
bufPage
;
return
bufPage
;
...
@@ -307,36 +363,40 @@ static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) {
...
@@ -307,36 +363,40 @@ static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) {
return
pageSize
+
POINTER_BYTES
+
2
+
sizeof
(
SFilePage
);
return
pageSize
+
POINTER_BYTES
+
2
+
sizeof
(
SFilePage
);
}
}
SFilePage
*
getNewDataBuf
(
SDiskbased
ResultBuf
*
pResult
Buf
,
int32_t
groupId
,
int32_t
*
pageId
)
{
SFilePage
*
getNewDataBuf
(
SDiskbased
Buf
*
p
Buf
,
int32_t
groupId
,
int32_t
*
pageId
)
{
p
Result
Buf
->
statis
.
getPages
+=
1
;
pBuf
->
statis
.
getPages
+=
1
;
char
*
availablePage
=
NULL
;
char
*
availablePage
=
NULL
;
if
(
NO_IN_MEM_AVAILABLE_PAGES
(
pResultBuf
))
{
if
(
NO_IN_MEM_AVAILABLE_PAGES
(
pBuf
))
{
availablePage
=
evicOneDataPage
(
pResultBuf
);
availablePage
=
evacOneDataPage
(
pBuf
);
// Failed to allocate a new buffer page, and there is an error occurs.
if
(
availablePage
==
NULL
)
{
return
NULL
;
}
}
}
// register new id in this group
// register new id in this group
*
pageId
=
(
++
p
Result
Buf
->
allocateId
);
*
pageId
=
(
++
pBuf
->
allocateId
);
// register page id info
// register page id info
SPageInfo
*
pi
=
registerPage
(
p
Result
Buf
,
groupId
,
*
pageId
);
SPageInfo
*
pi
=
registerPage
(
pBuf
,
groupId
,
*
pageId
);
// add to LRU list
// add to LRU list
assert
(
listNEles
(
pResultBuf
->
lruList
)
<
pResultBuf
->
inMemPages
&&
pResultBuf
->
inMemPages
>
0
);
assert
(
listNEles
(
pBuf
->
lruList
)
<
pBuf
->
inMemPages
&&
pBuf
->
inMemPages
>
0
);
lruListPushFront
(
pBuf
->
lruList
,
pi
);
lruListPushFront
(
pResultBuf
->
lruList
,
pi
);
// add to hash map
// add to hash map
taosHashPut
(
p
Result
Buf
->
all
,
pageId
,
sizeof
(
int32_t
),
&
pi
,
POINTER_BYTES
);
taosHashPut
(
pBuf
->
all
,
pageId
,
sizeof
(
int32_t
),
&
pi
,
POINTER_BYTES
);
// allocate buf
// allocate buf
if
(
availablePage
==
NULL
)
{
if
(
availablePage
==
NULL
)
{
pi
->
pData
=
calloc
(
1
,
getAllocPageSize
(
p
Result
Buf
->
pageSize
));
// add extract bytes in case of zipped buffer increased.
pi
->
pData
=
calloc
(
1
,
getAllocPageSize
(
pBuf
->
pageSize
));
// add extract bytes in case of zipped buffer increased.
}
else
{
}
else
{
pi
->
pData
=
availablePage
;
pi
->
pData
=
availablePage
;
}
}
p
ResultBuf
->
totalBufSize
+=
pResult
Buf
->
pageSize
;
p
Buf
->
totalBufSize
+=
p
Buf
->
pageSize
;
((
void
**
)
pi
->
pData
)[
0
]
=
pi
;
((
void
**
)
pi
->
pData
)[
0
]
=
pi
;
pi
->
used
=
true
;
pi
->
used
=
true
;
...
@@ -344,16 +404,16 @@ SFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32
...
@@ -344,16 +404,16 @@ SFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32
return
(
void
*
)(
GET_DATA_PAYLOAD
(
pi
));
return
(
void
*
)(
GET_DATA_PAYLOAD
(
pi
));
}
}
SFilePage
*
get
ResBufPage
(
SDiskbasedResultBuf
*
pResult
Buf
,
int32_t
id
)
{
SFilePage
*
get
BufPage
(
SDiskbasedBuf
*
p
Buf
,
int32_t
id
)
{
assert
(
p
Result
Buf
!=
NULL
&&
id
>=
0
);
assert
(
pBuf
!=
NULL
&&
id
>=
0
);
p
Result
Buf
->
statis
.
getPages
+=
1
;
pBuf
->
statis
.
getPages
+=
1
;
SPageInfo
**
pi
=
taosHashGet
(
p
Result
Buf
->
all
,
&
id
,
sizeof
(
int32_t
));
SPageInfo
**
pi
=
taosHashGet
(
pBuf
->
all
,
&
id
,
sizeof
(
int32_t
));
assert
(
pi
!=
NULL
&&
*
pi
!=
NULL
);
assert
(
pi
!=
NULL
&&
*
pi
!=
NULL
);
if
((
*
pi
)
->
pData
!=
NULL
)
{
// it is in memory
if
((
*
pi
)
->
pData
!=
NULL
)
{
// it is in memory
// no need to update the LRU list if only one page exists
// no need to update the LRU list if only one page exists
if
(
p
Result
Buf
->
numOfPages
==
1
)
{
if
(
pBuf
->
numOfPages
==
1
)
{
(
*
pi
)
->
used
=
true
;
(
*
pi
)
->
used
=
true
;
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
}
}
...
@@ -361,85 +421,102 @@ SFilePage* getResBufPage(SDiskbasedResultBuf* pResultBuf, int32_t id) {
...
@@ -361,85 +421,102 @@ SFilePage* getResBufPage(SDiskbasedResultBuf* pResultBuf, int32_t id) {
SPageInfo
**
pInfo
=
(
SPageInfo
**
)
((
*
pi
)
->
pn
->
data
);
SPageInfo
**
pInfo
=
(
SPageInfo
**
)
((
*
pi
)
->
pn
->
data
);
assert
(
*
pInfo
==
*
pi
);
assert
(
*
pInfo
==
*
pi
);
lruListMoveToFront
(
p
Result
Buf
->
lruList
,
(
*
pi
));
lruListMoveToFront
(
pBuf
->
lruList
,
(
*
pi
));
(
*
pi
)
->
used
=
true
;
(
*
pi
)
->
used
=
true
;
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
}
else
{
// not in memory
}
else
{
// not in memory
assert
((
*
pi
)
->
pData
==
NULL
&&
(
*
pi
)
->
pn
==
NULL
&&
(
*
pi
)
->
info
.
length
>=
0
&&
(
*
pi
)
->
info
.
offset
>=
0
);
assert
((
*
pi
)
->
pData
==
NULL
&&
(
*
pi
)
->
pn
==
NULL
&&
(
*
pi
)
->
length
>=
0
&&
(
*
pi
)
->
offset
>=
0
);
char
*
availablePage
=
NULL
;
char
*
availablePage
=
NULL
;
if
(
NO_IN_MEM_AVAILABLE_PAGES
(
pResultBuf
))
{
if
(
NO_IN_MEM_AVAILABLE_PAGES
(
pBuf
))
{
availablePage
=
evicOneDataPage
(
pResultBuf
);
availablePage
=
evacOneDataPage
(
pBuf
);
if
(
availablePage
==
NULL
)
{
return
NULL
;
}
}
}
if
(
availablePage
==
NULL
)
{
if
(
availablePage
==
NULL
)
{
(
*
pi
)
->
pData
=
calloc
(
1
,
getAllocPageSize
(
p
Result
Buf
->
pageSize
));
(
*
pi
)
->
pData
=
calloc
(
1
,
getAllocPageSize
(
pBuf
->
pageSize
));
}
else
{
}
else
{
(
*
pi
)
->
pData
=
availablePage
;
(
*
pi
)
->
pData
=
availablePage
;
}
}
((
void
**
)((
*
pi
)
->
pData
))[
0
]
=
(
*
pi
);
((
void
**
)((
*
pi
)
->
pData
))[
0
]
=
(
*
pi
);
lruListPushFront
(
p
Result
Buf
->
lruList
,
*
pi
);
lruListPushFront
(
pBuf
->
lruList
,
*
pi
);
(
*
pi
)
->
used
=
true
;
(
*
pi
)
->
used
=
true
;
loadPageFromDisk
(
pResultBuf
,
*
pi
);
int32_t
code
=
loadPageFromDisk
(
pBuf
,
*
pi
);
if
(
code
!=
0
)
{
return
NULL
;
}
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
}
}
}
}
void
releaseResBufPage
(
SDiskbasedResultBuf
*
pResultBuf
,
void
*
page
)
{
void
releaseBufPage
(
SDiskbasedBuf
*
pBuf
,
void
*
page
)
{
assert
(
pResultBuf
!=
NULL
&&
page
!=
NULL
);
assert
(
pBuf
!=
NULL
&&
page
!=
NULL
);
char
*
p
=
(
char
*
)
page
-
POINTER_BYTES
;
int32_t
offset
=
offsetof
(
SPageInfo
,
pData
);
char
*
p
=
page
-
offset
;
SPageInfo
*
ppi
=
((
SPageInfo
**
)
p
)[
0
];
SPageInfo
*
ppi
=
((
SPageInfo
**
)
p
)[
0
];
release
ResBufPageInfo
(
pResult
Buf
,
ppi
);
release
BufPageInfo
(
p
Buf
,
ppi
);
}
}
void
release
ResBufPageInfo
(
SDiskbasedResultBuf
*
pResult
Buf
,
SPageInfo
*
pi
)
{
void
release
BufPageInfo
(
SDiskbasedBuf
*
p
Buf
,
SPageInfo
*
pi
)
{
assert
(
pi
->
pData
!=
NULL
&&
pi
->
used
);
assert
(
pi
->
pData
!=
NULL
&&
pi
->
used
);
pi
->
used
=
false
;
pi
->
used
=
false
;
p
Result
Buf
->
statis
.
releasePages
+=
1
;
pBuf
->
statis
.
releasePages
+=
1
;
}
}
size_t
getNumOfResultBufGroupId
(
const
SDiskbased
ResultBuf
*
pResultBuf
)
{
return
taosHashGetSize
(
pResult
Buf
->
groupSet
);
}
size_t
getNumOfResultBufGroupId
(
const
SDiskbased
Buf
*
pBuf
)
{
return
taosHashGetSize
(
p
Buf
->
groupSet
);
}
size_t
get
ResBufSize
(
const
SDiskbasedResultBuf
*
pResultBuf
)
{
return
(
size_t
)
pResult
Buf
->
totalBufSize
;
}
size_t
get
TotalBufSize
(
const
SDiskbasedBuf
*
pBuf
)
{
return
(
size_t
)
p
Buf
->
totalBufSize
;
}
SIDList
getDataBufPagesIdList
(
SDiskbased
ResultBuf
*
pResult
Buf
,
int32_t
groupId
)
{
SIDList
getDataBufPagesIdList
(
SDiskbased
Buf
*
p
Buf
,
int32_t
groupId
)
{
assert
(
p
Result
Buf
!=
NULL
);
assert
(
pBuf
!=
NULL
);
char
**
p
=
taosHashGet
(
p
Result
Buf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
));
char
**
p
=
taosHashGet
(
pBuf
->
groupSet
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
));
if
(
p
==
NULL
)
{
// it is a new group id
if
(
p
==
NULL
)
{
// it is a new group id
return
p
Result
Buf
->
emptyDummyIdList
;
return
pBuf
->
emptyDummyIdList
;
}
else
{
}
else
{
return
(
SArray
*
)
(
*
p
);
return
(
SArray
*
)
(
*
p
);
}
}
}
}
void
destroyResultBuf
(
SDiskbased
ResultBuf
*
pResult
Buf
)
{
void
destroyResultBuf
(
SDiskbased
Buf
*
p
Buf
)
{
if
(
p
Result
Buf
==
NULL
)
{
if
(
pBuf
==
NULL
)
{
return
;
return
;
}
}
if
(
pResultBuf
->
file
!=
NULL
)
{
printStatisData
(
pBuf
);
// qDebug("QInfo:0x%"PRIx64" res output buffer closed, total:%.2f Kb, inmem size:%.2f Kb, file size:%.2f Kb",
// pResultBuf->qId, pResultBuf->totalBufSize/1024.0, listNEles(pResultBuf->lruList) * pResultBuf->pageSize / 1024.0,
// pResultBuf->fileSize/1024.0);
fclose
(
pResultBuf
->
file
);
if
(
pBuf
->
file
!=
NULL
)
{
uDebug
(
"Paged buffer closed, total:%.2f Kb (%d Pages), inmem size:%.2f Kb (%d Pages), file size:%.2f Kb, page size:%.2f Kb, %"
PRIx64
"
\n
"
,
pBuf
->
totalBufSize
/
1024
.
0
,
pBuf
->
numOfPages
,
listNEles
(
pBuf
->
lruList
)
*
pBuf
->
pageSize
/
1024
.
0
,
listNEles
(
pBuf
->
lruList
),
pBuf
->
fileSize
/
1024
.
0
,
pBuf
->
pageSize
/
1024
.
0
f
,
pBuf
->
qId
);
fclose
(
pBuf
->
file
);
}
else
{
}
else
{
// qDebug("QInfo:0x%"PRIx64" res output buffer closed, total:%.2f Kb, no file created", pResultBuf->qId,
uDebug
(
"Paged buffer closed, total:%.2f Kb, no file created, %"
PRIx64
,
pBuf
->
totalBufSize
/
1024
.
0
,
pBuf
->
qId
);
// pResultBuf->totalBufSize/1024.0);
}
}
remove
(
pResultBuf
->
path
);
// print the statistics information
tfree
(
pResultBuf
->
path
);
{
SDiskbasedBufStatis
*
ps
=
&
pBuf
->
statis
;
uDebug
(
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f Kb
\n
"
,
ps
->
getPages
,
ps
->
releasePages
,
ps
->
flushBytes
/
1024
.
0
f
,
ps
->
flushPages
,
ps
->
loadBytes
/
1024
.
0
f
,
ps
->
loadPages
,
ps
->
loadBytes
/
(
1024
.
0
*
ps
->
loadPages
));
}
SArray
**
p
=
taosHashIterate
(
pResultBuf
->
groupSet
,
NULL
);
remove
(
pBuf
->
path
);
tfree
(
pBuf
->
path
);
SArray
**
p
=
taosHashIterate
(
pBuf
->
groupSet
,
NULL
);
while
(
p
)
{
while
(
p
)
{
size_t
n
=
taosArrayGetSize
(
*
p
);
size_t
n
=
taosArrayGetSize
(
*
p
);
for
(
int32_t
i
=
0
;
i
<
n
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
n
;
++
i
)
{
...
@@ -449,20 +526,72 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) {
...
@@ -449,20 +526,72 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) {
}
}
taosArrayDestroy
(
*
p
);
taosArrayDestroy
(
*
p
);
p
=
taosHashIterate
(
p
Result
Buf
->
groupSet
,
p
);
p
=
taosHashIterate
(
pBuf
->
groupSet
,
p
);
}
}
tdListFree
(
p
Result
Buf
->
lruList
);
tdListFree
(
pBuf
->
lruList
);
taosArrayDestroy
(
p
Result
Buf
->
emptyDummyIdList
);
taosArrayDestroy
(
pBuf
->
emptyDummyIdList
);
taosHashCleanup
(
p
Result
Buf
->
groupSet
);
taosHashCleanup
(
pBuf
->
groupSet
);
taosHashCleanup
(
p
Result
Buf
->
all
);
taosHashCleanup
(
pBuf
->
all
);
tfree
(
p
Result
Buf
->
assistBuf
);
tfree
(
pBuf
->
assistBuf
);
tfree
(
p
Result
Buf
);
tfree
(
pBuf
);
}
}
SPageInfo
*
getLastPageInfo
(
SIDList
pList
)
{
SPageInfo
*
getLastPageInfo
(
SIDList
pList
)
{
size_t
size
=
taosArrayGetSize
(
pList
);
size_t
size
=
taosArrayGetSize
(
pList
);
return
(
SPageInfo
*
)
taosArrayGetP
(
pList
,
size
-
1
);
SPageInfo
*
pPgInfo
=
taosArrayGetP
(
pList
,
size
-
1
);
return
pPgInfo
;
}
int32_t
getPageId
(
const
SPageInfo
*
pPgInfo
)
{
ASSERT
(
pPgInfo
!=
NULL
);
return
pPgInfo
->
pageId
;
}
}
int32_t
getBufPageSize
(
const
SDiskbasedBuf
*
pBuf
)
{
return
pBuf
->
pageSize
;
}
int32_t
getNumOfInMemBufPages
(
const
SDiskbasedBuf
*
pBuf
)
{
return
pBuf
->
inMemPages
;
}
bool
isAllDataInMemBuf
(
const
SDiskbasedBuf
*
pBuf
)
{
return
pBuf
->
fileSize
==
0
;
}
void
setBufPageDirty
(
SFilePage
*
pPage
,
bool
dirty
)
{
int32_t
offset
=
offsetof
(
SPageInfo
,
pData
);
// todo extract method
char
*
p
=
(
char
*
)
pPage
-
offset
;
SPageInfo
*
ppi
=
((
SPageInfo
**
)
p
)[
0
];
ppi
->
dirty
=
dirty
;
}
void
printStatisBeforeClose
(
SDiskbasedBuf
*
pBuf
)
{
pBuf
->
printStatis
=
true
;
}
SDiskbasedBufStatis
getDBufStatis
(
const
SDiskbasedBuf
*
pBuf
)
{
return
pBuf
->
statis
;
}
void
printStatisData
(
const
SDiskbasedBuf
*
pBuf
)
{
if
(
!
pBuf
->
printStatis
)
{
return
;
}
const
SDiskbasedBufStatis
*
ps
=
&
pBuf
->
statis
;
printf
(
"Paged buffer closed, total:%.2f Kb (%d Pages), inmem size:%.2f Kb (%d Pages), file size:%.2f Kb, page size:%.2f "
"Kb, %"
PRIx64
"
\n
"
,
pBuf
->
totalBufSize
/
1024
.
0
,
pBuf
->
numOfPages
,
listNEles
(
pBuf
->
lruList
)
*
pBuf
->
pageSize
/
1024
.
0
,
listNEles
(
pBuf
->
lruList
),
pBuf
->
fileSize
/
1024
.
0
,
pBuf
->
pageSize
/
1024
.
0
f
,
pBuf
->
qId
);
printf
(
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f Kb
\n
"
,
ps
->
getPages
,
ps
->
releasePages
,
ps
->
flushBytes
/
1024
.
0
f
,
ps
->
flushPages
,
ps
->
loadBytes
/
1024
.
0
f
,
ps
->
loadPages
,
ps
->
loadBytes
/
(
1024
.
0
*
ps
->
loadPages
));
}
source/util/test/pageBufferTest.cpp
0 → 100644
浏览文件 @
378aaf38
#include <gtest/gtest.h>
#include <cassert>
#include <iostream>
#include "taos.h"
#include "tpagedbuf.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace
{
// simple test
void
simpleTest
()
{
SDiskbasedBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedBuffer
(
&
pResultBuf
,
1024
,
4096
,
1
,
"/tmp/"
);
int32_t
pageId
=
0
;
int32_t
groupId
=
0
;
SFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
ASSERT_EQ
(
getTotalBufSize
(
pResultBuf
),
1024
);
SIDList
list
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
list
),
1
);
ASSERT_EQ
(
getNumOfResultBufGroupId
(
pResultBuf
),
1
);
releaseBufPage
(
pResultBuf
,
pBufPage
);
SFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t
==
pBufPage1
);
SFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t1
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage2
);
SFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t2
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage3
);
SFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t3
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage4
);
SFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t4
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage5
);
destroyResultBuf
(
pResultBuf
);
}
void
writeDownTest
()
{
SDiskbasedBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
,
"/tmp/"
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
int32_t
groupId
=
0
;
int32_t
nx
=
12345
;
SFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
*
(
int32_t
*
)(
pBufPage
->
data
)
=
nx
;
writePageId
=
pageId
;
releaseBufPage
(
pResultBuf
,
pBufPage
);
SFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t1
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
SFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t2
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
SFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t3
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
SFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t4
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
releaseBufPage
(
pResultBuf
,
t4
);
// flush the written page to disk, and read it out again
SFilePage
*
pBufPagex
=
getBufPage
(
pResultBuf
,
writePageId
);
ASSERT_EQ
(
*
(
int32_t
*
)
pBufPagex
->
data
,
nx
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
5
);
destroyResultBuf
(
pResultBuf
);
}
void
recyclePageTest
()
{
SDiskbasedBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
,
"/tmp/"
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
int32_t
groupId
=
0
;
int32_t
nx
=
12345
;
SFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
releaseBufPage
(
pResultBuf
,
pBufPage
);
SFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t1
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
SFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t2
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
SFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t3
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
SFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t4
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
releaseBufPage
(
pResultBuf
,
t4
);
SFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
SFilePage
*
t5
=
getBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t5
==
pBufPage5
);
ASSERT_TRUE
(
pageId
==
5
);
// flush the written page to disk, and read it out again
SFilePage
*
pBufPagex
=
getBufPage
(
pResultBuf
,
writePageId
);
*
(
int32_t
*
)(
pBufPagex
->
data
)
=
nx
;
writePageId
=
pageId
;
// update the data
releaseBufPage
(
pResultBuf
,
pBufPagex
);
SFilePage
*
pBufPagex1
=
getBufPage
(
pResultBuf
,
1
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
6
);
destroyResultBuf
(
pResultBuf
);
}
}
// namespace
TEST
(
testCase
,
resultBufferTest
)
{
srand
(
time
(
NULL
));
simpleTest
();
writeDownTest
();
recyclePageTest
();
}
#pragma GCC diagnostic pop
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录