Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
95347ff6
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
“f2af0afecf86e19963b53b438bacc1ad00afc58d”上不存在“packaging/git@gitcode.net:taosdata/tdengine.git”
提交
95347ff6
编写于
1月 09, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/dnode3
上级
371432c1
5b591713
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
1554 addition
and
669 deletion
+1554
-669
include/libs/executor/executor.h
include/libs/executor/executor.h
+18
-18
include/libs/function/function.h
include/libs/function/function.h
+1
-2
include/libs/planner/planner.h
include/libs/planner/planner.h
+1
-1
source/libs/executor/inc/executil.h
source/libs/executor/inc/executil.h
+9
-9
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+107
-76
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+12
-12
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+579
-0
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+520
-459
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+1
-0
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+1
-0
source/libs/index/src/index.c
source/libs/index/src/index.c
+4
-1
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+1
-1
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+4
-1
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+14
-1
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+50
-4
source/libs/index/test/fstTest.cc
source/libs/index/test/fstTest.cc
+31
-3
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+13
-7
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+2
-1
source/libs/planner/inc/plannerInt.h
source/libs/planner/inc/plannerInt.h
+1
-1
source/libs/planner/src/physicalPlan.c
source/libs/planner/src/physicalPlan.c
+65
-25
source/libs/planner/src/planner.c
source/libs/planner/src/planner.c
+2
-2
source/libs/scheduler/inc/schedulerInt.h
source/libs/scheduler/inc/schedulerInt.h
+3
-3
source/libs/scheduler/src/scheduler.c
source/libs/scheduler/src/scheduler.c
+115
-42
未找到文件。
include/libs/executor/executor.h
浏览文件 @
95347ff6
...
@@ -20,16 +20,16 @@
...
@@ -20,16 +20,16 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
typedef
void
*
q
i
nfo_t
;
typedef
void
*
q
TaskI
nfo_t
;
/**
/**
* create the qinfo object according to QueryTableMsg
* create the qinfo object according to QueryTableMsg
* @param tsdb
* @param tsdb
* @param pQueryTableMsg
* @param pQueryTableMsg
* @param
qi
nfo
* @param
pTaskI
nfo
* @return
* @return
*/
*/
int32_t
qCreate
QueryInfo
(
void
*
tsdb
,
int32_t
vgId
,
SQueryTableInfo
*
pQueryTableMsg
,
qinfo_t
*
qi
nfo
,
uint64_t
qId
);
int32_t
qCreate
Task
(
void
*
tsdb
,
int32_t
vgId
,
void
*
pQueryTableMsg
,
qTaskInfo_t
*
pTaskI
nfo
,
uint64_t
qId
);
/**
/**
* the main query execution function, including query on both table and multiple tables,
* the main query execution function, including query on both table and multiple tables,
...
@@ -38,7 +38,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableInfo* pQueryTableM
...
@@ -38,7 +38,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableInfo* pQueryTableM
* @param qinfo
* @param qinfo
* @return
* @return
*/
*/
bool
q
TableQuery
(
qi
nfo_t
qinfo
,
uint64_t
*
qId
);
bool
q
ExecTask
(
qTaskI
nfo_t
qinfo
,
uint64_t
*
qId
);
/**
/**
* Retrieve the produced results information, if current query is not paused or completed,
* Retrieve the produced results information, if current query is not paused or completed,
...
@@ -48,7 +48,7 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId);
...
@@ -48,7 +48,7 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId);
* @param qinfo
* @param qinfo
* @return
* @return
*/
*/
int32_t
qRetrieveQueryResultInfo
(
q
i
nfo_t
qinfo
,
bool
*
buildRes
,
void
*
pRspContext
);
int32_t
qRetrieveQueryResultInfo
(
q
TaskI
nfo_t
qinfo
,
bool
*
buildRes
,
void
*
pRspContext
);
/**
/**
*
*
...
@@ -60,41 +60,41 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex
...
@@ -60,41 +60,41 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex
* @param contLen payload length
* @param contLen payload length
* @return
* @return
*/
*/
int32_t
qDumpRetrieveResult
(
q
i
nfo_t
qinfo
,
SRetrieveTableRsp
**
pRsp
,
int32_t
*
contLen
,
bool
*
continueExec
);
int32_t
qDumpRetrieveResult
(
q
TaskI
nfo_t
qinfo
,
SRetrieveTableRsp
**
pRsp
,
int32_t
*
contLen
,
bool
*
continueExec
);
/**
/**
* return the transporter context (RPC)
* return the transporter context (RPC)
* @param qinfo
* @param qinfo
* @return
* @return
*/
*/
void
*
qGetResultRetrieveMsg
(
q
i
nfo_t
qinfo
);
void
*
qGetResultRetrieveMsg
(
q
TaskI
nfo_t
qinfo
);
/**
/**
* kill the ongoing query and free the query handle and corresponding resources automatically
* kill the ongoing query and free the query handle and corresponding resources automatically
* @param qinfo qhandle
* @param qinfo qhandle
* @return
* @return
*/
*/
int32_t
qKill
Query
(
qi
nfo_t
qinfo
);
int32_t
qKill
Task
(
qTaskI
nfo_t
qinfo
);
/**
/**
* return whether query is completed or not
* return whether query is completed or not
* @param qinfo
* @param qinfo
* @return
* @return
*/
*/
int32_t
qIsQueryCompleted
(
q
i
nfo_t
qinfo
);
int32_t
qIsQueryCompleted
(
q
TaskI
nfo_t
qinfo
);
/**
/**
* destroy query info structure
* destroy query info structure
* @param qHandle
* @param qHandle
*/
*/
void
qDestroy
QueryInfo
(
qi
nfo_t
qHandle
);
void
qDestroy
Task
(
qTaskI
nfo_t
qHandle
);
/**
/**
* Get the queried table uid
* Get the queried table uid
* @param qHandle
* @param qHandle
* @return
* @return
*/
*/
int64_t
qGetQueriedTableUid
(
q
i
nfo_t
qHandle
);
int64_t
qGetQueriedTableUid
(
q
TaskI
nfo_t
qHandle
);
/**
/**
* Extract the qualified table id list, and than pass them to the TSDB driver to load the required table data blocks.
* Extract the qualified table id list, and than pass them to the TSDB driver to load the required table data blocks.
...
@@ -121,7 +121,7 @@ int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGro
...
@@ -121,7 +121,7 @@ int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGro
* @param type operation type: ADD|DROP
* @param type operation type: ADD|DROP
* @return
* @return
*/
*/
int32_t
qUpdateQueriedTableIdList
(
q
i
nfo_t
qinfo
,
int64_t
uid
,
int32_t
type
);
int32_t
qUpdateQueriedTableIdList
(
q
TaskI
nfo_t
qinfo
,
int64_t
uid
,
int32_t
type
);
//================================================================================================
//================================================================================================
// query handle management
// query handle management
...
@@ -130,13 +130,13 @@ int32_t qUpdateQueriedTableIdList(qinfo_t qinfo, int64_t uid, int32_t type);
...
@@ -130,13 +130,13 @@ int32_t qUpdateQueriedTableIdList(qinfo_t qinfo, int64_t uid, int32_t type);
* @param vgId
* @param vgId
* @return
* @return
*/
*/
void
*
qOpen
Query
Mgmt
(
int32_t
vgId
);
void
*
qOpen
Task
Mgmt
(
int32_t
vgId
);
/**
/**
* broadcast the close information and wait for all query stop.
* broadcast the close information and wait for all query stop.
* @param pExecutor
* @param pExecutor
*/
*/
void
q
QueryMgmtNotifyClosed
(
void
*
pExecutor
);
void
q
TaskMgmtNotifyClosing
(
void
*
pExecutor
);
/**
/**
* Re-open the query handle management module when opening the vnode again.
* Re-open the query handle management module when opening the vnode again.
...
@@ -148,7 +148,7 @@ void qQueryMgmtReOpen(void *pExecutor);
...
@@ -148,7 +148,7 @@ void qQueryMgmtReOpen(void *pExecutor);
* Close query mgmt and clean up resources.
* Close query mgmt and clean up resources.
* @param pExecutor
* @param pExecutor
*/
*/
void
qCleanup
Query
Mgmt
(
void
*
pExecutor
);
void
qCleanup
Task
Mgmt
(
void
*
pExecutor
);
/**
/**
* Add the query into the query mgmt object
* Add the query into the query mgmt object
...
@@ -157,7 +157,7 @@ void qCleanupQueryMgmt(void* pExecutor);
...
@@ -157,7 +157,7 @@ void qCleanupQueryMgmt(void* pExecutor);
* @param qInfo
* @param qInfo
* @return
* @return
*/
*/
void
**
qRegister
QInfo
(
void
*
pMgmt
,
uint64_t
qId
,
void
*
qInfo
);
void
**
qRegister
Task
(
void
*
pMgmt
,
uint64_t
qId
,
void
*
qInfo
);
/**
/**
* acquire the query handle according to the key from query mgmt object.
* acquire the query handle according to the key from query mgmt object.
...
@@ -165,7 +165,7 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qId, void *qInfo);
...
@@ -165,7 +165,7 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qId, void *qInfo);
* @param key
* @param key
* @return
* @return
*/
*/
void
**
qAcquire
QInfo
(
void
*
pMgmt
,
uint64_t
key
);
void
**
qAcquire
Task
(
void
*
pMgmt
,
uint64_t
key
);
/**
/**
* release the query handle and decrease the reference count in cache
* release the query handle and decrease the reference count in cache
...
@@ -174,7 +174,7 @@ void** qAcquireQInfo(void* pMgmt, uint64_t key);
...
@@ -174,7 +174,7 @@ void** qAcquireQInfo(void* pMgmt, uint64_t key);
* @param freeHandle
* @param freeHandle
* @return
* @return
*/
*/
void
**
qRelease
QInfo
(
void
*
pMgmt
,
void
*
pQInfo
);
void
**
qRelease
Task
(
void
*
pMgmt
,
void
*
pQInfo
,
bool
freeHandle
);
/**
/**
* De-register the query handle from the management module and free it immediately.
* De-register the query handle from the management module and free it immediately.
...
...
include/libs/function/function.h
浏览文件 @
95347ff6
...
@@ -89,7 +89,7 @@ enum {
...
@@ -89,7 +89,7 @@ enum {
};
};
enum
{
enum
{
MA
STER_SCAN
=
0x0u
,
MA
IN_SCAN
=
0x0u
,
REVERSE_SCAN
=
0x1u
,
REVERSE_SCAN
=
0x1u
,
REPEAT_SCAN
=
0x2u
,
//repeat scan belongs to the master scan
REPEAT_SCAN
=
0x2u
,
//repeat scan belongs to the master scan
MERGE_STAGE
=
0x20u
,
MERGE_STAGE
=
0x20u
,
...
@@ -183,7 +183,6 @@ typedef struct tExprNode {
...
@@ -183,7 +183,6 @@ typedef struct tExprNode {
struct
{
// function node
struct
{
// function node
char
functionName
[
FUNCTIONS_NAME_MAX_LENGTH
];
char
functionName
[
FUNCTIONS_NAME_MAX_LENGTH
];
// int32_t functionId;
int32_t
num
;
int32_t
num
;
// Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the
// Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the
...
...
include/libs/planner/planner.h
浏览文件 @
95347ff6
...
@@ -155,7 +155,7 @@ int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag**
...
@@ -155,7 +155,7 @@ int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag**
// @subplan subplan to be schedule
// @subplan subplan to be schedule
// @templateId templateId of a group of datasource subplans of this @subplan
// @templateId templateId of a group of datasource subplans of this @subplan
// @ep one execution location of this group of datasource subplans
// @ep one execution location of this group of datasource subplans
int32_t
qSetSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
ep
);
void
qSetSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
ep
);
int32_t
qExplainQuery
(
const
struct
SQueryNode
*
pQueryInfo
,
struct
SEpSet
*
pQnode
,
char
**
str
);
int32_t
qExplainQuery
(
const
struct
SQueryNode
*
pQueryInfo
,
struct
SEpSet
*
pQnode
,
char
**
str
);
...
...
source/libs/executor/inc/executil.h
浏览文件 @
95347ff6
...
@@ -88,37 +88,37 @@ typedef struct SResultRowPool {
...
@@ -88,37 +88,37 @@ typedef struct SResultRowPool {
SArray
*
pData
;
// SArray<void*>
SArray
*
pData
;
// SArray<void*>
}
SResultRowPool
;
}
SResultRowPool
;
struct
S
Query
Attr
;
struct
S
Task
Attr
;
struct
S
Query
RuntimeEnv
;
struct
S
Task
RuntimeEnv
;
struct
SUdfInfo
;
struct
SUdfInfo
;
int32_t
getOutputInterResultBufSize
(
struct
S
Query
Attr
*
pQueryAttr
);
int32_t
getOutputInterResultBufSize
(
struct
S
Task
Attr
*
pQueryAttr
);
size_t
getResultRowSize
(
struct
S
Query
RuntimeEnv
*
pRuntimeEnv
);
size_t
getResultRowSize
(
struct
S
Task
RuntimeEnv
*
pRuntimeEnv
);
int32_t
initResultRowInfo
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
size
,
int16_t
type
);
int32_t
initResultRowInfo
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
size
,
int16_t
type
);
void
cleanupResultRowInfo
(
SResultRowInfo
*
pResultRowInfo
);
void
cleanupResultRowInfo
(
SResultRowInfo
*
pResultRowInfo
);
void
resetResultRowInfo
(
struct
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
);
void
resetResultRowInfo
(
struct
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
);
int32_t
numOfClosedResultRows
(
SResultRowInfo
*
pResultRowInfo
);
int32_t
numOfClosedResultRows
(
SResultRowInfo
*
pResultRowInfo
);
void
closeAllResultRows
(
SResultRowInfo
*
pResultRowInfo
);
void
closeAllResultRows
(
SResultRowInfo
*
pResultRowInfo
);
int32_t
initResultRow
(
SResultRow
*
pResultRow
);
int32_t
initResultRow
(
SResultRow
*
pResultRow
);
void
closeResultRow
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
);
void
closeResultRow
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
);
bool
isResultRowClosed
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
);
bool
isResultRowClosed
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
);
void
clearResultRow
(
struct
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int16_t
type
);
void
clearResultRow
(
struct
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int16_t
type
);
struct
SResultRowEntryInfo
*
getResultCell
(
const
SResultRow
*
pRow
,
int32_t
index
,
int32_t
*
offset
);
struct
SResultRowEntryInfo
*
getResultCell
(
const
SResultRow
*
pRow
,
int32_t
index
,
int32_t
*
offset
);
void
*
destroyQueryFuncExpr
(
SExprInfo
*
pExprInfo
,
int32_t
numOfExpr
);
void
*
destroyQueryFuncExpr
(
SExprInfo
*
pExprInfo
,
int32_t
numOfExpr
);
void
*
freeColumnInfo
(
SColumnInfo
*
pColumnInfo
,
int32_t
numOfCols
);
void
*
freeColumnInfo
(
SColumnInfo
*
pColumnInfo
,
int32_t
numOfCols
);
int32_t
getRowNumForMultioutput
(
struct
S
Query
Attr
*
pQueryAttr
,
bool
topBottomQuery
,
bool
stable
);
int32_t
getRowNumForMultioutput
(
struct
S
Task
Attr
*
pQueryAttr
,
bool
topBottomQuery
,
bool
stable
);
static
FORCE_INLINE
SResultRow
*
getResultRow
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
)
{
static
FORCE_INLINE
SResultRow
*
getResultRow
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
slot
)
{
assert
(
pResultRowInfo
!=
NULL
&&
slot
>=
0
&&
slot
<
pResultRowInfo
->
size
);
assert
(
pResultRowInfo
!=
NULL
&&
slot
>=
0
&&
slot
<
pResultRowInfo
->
size
);
return
pResultRowInfo
->
pResult
[
slot
];
return
pResultRowInfo
->
pResult
[
slot
];
}
}
static
FORCE_INLINE
char
*
getPosInResultPage
(
struct
S
Query
Attr
*
pQueryAttr
,
SFilePage
*
page
,
int32_t
rowOffset
,
static
FORCE_INLINE
char
*
getPosInResultPage
(
struct
S
Task
Attr
*
pQueryAttr
,
SFilePage
*
page
,
int32_t
rowOffset
,
int32_t
offset
)
{
int32_t
offset
)
{
assert
(
rowOffset
>=
0
&&
pQueryAttr
!=
NULL
);
assert
(
rowOffset
>=
0
&&
pQueryAttr
!=
NULL
);
...
@@ -155,7 +155,7 @@ bool hasRemainData(SGroupResInfo* pGroupResInfo);
...
@@ -155,7 +155,7 @@ bool hasRemainData(SGroupResInfo* pGroupResInfo);
bool
incNextGroup
(
SGroupResInfo
*
pGroupResInfo
);
bool
incNextGroup
(
SGroupResInfo
*
pGroupResInfo
);
int32_t
getNumOfTotalRes
(
SGroupResInfo
*
pGroupResInfo
);
int32_t
getNumOfTotalRes
(
SGroupResInfo
*
pGroupResInfo
);
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
struct
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int32_t
*
offset
);
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
struct
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int32_t
*
offset
);
int32_t
initUdfInfo
(
struct
SUdfInfo
*
pUdfInfo
);
int32_t
initUdfInfo
(
struct
SUdfInfo
*
pUdfInfo
);
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
95347ff6
...
@@ -21,13 +21,14 @@
...
@@ -21,13 +21,14 @@
#include "tvariant.h"
#include "tvariant.h"
#include "thash.h"
#include "thash.h"
//#include "parser.h"
#include "executil.h"
#include "executil.h"
#include "taosdef.h"
#include "taosdef.h"
#include "tarray.h"
#include "tarray.h"
#include "tfilter.h"
#include "tfilter.h"
#include "tlockfree.h"
#include "tlockfree.h"
#include "tpagedfile.h"
#include "tpagedfile.h"
#include "planner.h"
struct
SColumnFilterElem
;
struct
SColumnFilterElem
;
...
@@ -65,7 +66,6 @@ enum {
...
@@ -65,7 +66,6 @@ enum {
QUERY_OVER
=
0x4u
,
QUERY_OVER
=
0x4u
,
};
};
typedef
struct
SResultRowCell
{
typedef
struct
SResultRowCell
{
uint64_t
groupId
;
uint64_t
groupId
;
SResultRow
*
pRow
;
SResultRow
*
pRow
;
...
@@ -100,7 +100,7 @@ typedef struct STableQueryInfo {
...
@@ -100,7 +100,7 @@ typedef struct STableQueryInfo {
TSKEY
lastKey
;
TSKEY
lastKey
;
int32_t
groupIndex
;
// group id in table list
int32_t
groupIndex
;
// group id in table list
SVariant
tag
;
SVariant
tag
;
STimeWindow
win
;
STimeWindow
win
;
// todo remove it later
STSCursor
cur
;
STSCursor
cur
;
void
*
pTable
;
// for retrieve the page id list
void
*
pTable
;
// for retrieve the page id list
SResultRowInfo
resInfo
;
SResultRowInfo
resInfo
;
...
@@ -128,31 +128,34 @@ typedef struct {
...
@@ -128,31 +128,34 @@ typedef struct {
int64_t
sumRunTimes
;
int64_t
sumRunTimes
;
}
SOperatorProfResult
;
}
SOperatorProfResult
;
typedef
struct
SQueryCostInfo
{
typedef
struct
STaskCostInfo
{
uint64_t
loadStatisTime
;
int64_t
start
;
uint64_t
loadFileBlockTime
;
int64_t
end
;
uint64_t
loadDataInCacheTime
;
uint64_t
loadStatisSize
;
uint64_t
loadStatisTime
;
uint64_t
loadFileBlockSize
;
uint64_t
loadFileBlockTime
;
uint64_t
loadDataInCacheSize
;
uint64_t
loadDataInCacheTime
;
uint64_t
loadStatisSize
;
uint64_t
loadDataTime
;
uint64_t
loadFileBlockSize
;
uint64_t
totalRows
;
uint64_t
loadDataInCacheSize
;
uint64_t
totalCheckedRows
;
uint32_t
totalBlocks
;
uint64_t
loadDataTime
;
uint32_t
loadBlocks
;
uint64_t
totalRows
;
uint32_t
loadBlockStatis
;
uint64_t
totalCheckedRows
;
uint32_t
discardBlocks
;
uint32_t
totalBlocks
;
uint64_t
elapsedTime
;
uint32_t
loadBlocks
;
uint64_t
firstStageMergeTime
;
uint32_t
loadBlockStatis
;
uint64_t
winInfoSize
;
uint32_t
discardBlocks
;
uint64_t
tableInfoSize
;
uint64_t
elapsedTime
;
uint64_t
hashSize
;
uint64_t
firstStageMergeTime
;
uint64_t
numOfTimeWindows
;
uint64_t
winInfoSize
;
uint64_t
tableInfoSize
;
SArray
*
queryProfEvents
;
//SArray<SQueryProfEvent>
uint64_t
hashSize
;
SHashObj
*
operatorProfResults
;
//map<operator_type, SQueryProfEvent>
uint64_t
numOfTimeWindows
;
}
SQueryCostInfo
;
SArray
*
queryProfEvents
;
//SArray<SQueryProfEvent>
SHashObj
*
operatorProfResults
;
//map<operator_type, SQueryProfEvent>
}
STaskCostInfo
;
typedef
struct
{
typedef
struct
{
int64_t
vgroupLimit
;
int64_t
vgroupLimit
;
...
@@ -166,7 +169,7 @@ typedef struct {
...
@@ -166,7 +169,7 @@ 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
S
Query
Attr
{
typedef
struct
S
Task
Attr
{
SLimit
limit
;
SLimit
limit
;
SLimit
slimit
;
SLimit
slimit
;
...
@@ -229,16 +232,40 @@ typedef struct SQueryAttr {
...
@@ -229,16 +232,40 @@ typedef struct SQueryAttr {
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
}
S
Query
Attr
;
}
S
Task
Attr
;
typedef
SSDataBlock
*
(
*
__operator_fn_t
)(
void
*
param
,
bool
*
newgroup
);
typedef
SSDataBlock
*
(
*
__operator_fn_t
)(
void
*
param
,
bool
*
newgroup
);
typedef
void
(
*
__optr_cleanup_fn_t
)(
void
*
param
,
int32_t
num
);
typedef
void
(
*
__optr_cleanup_fn_t
)(
void
*
param
,
int32_t
num
);
struct
SOperatorInfo
;
struct
SOperatorInfo
;
typedef
struct
SQueryRuntimeEnv
{
typedef
struct
STaskIdInfo
{
uint64_t
queryId
;
// this is also a request id
uint64_t
subplanId
;
uint64_t
templateId
;
uint64_t
taskId
;
// this is a subplan id
}
STaskIdInfo
;
typedef
struct
STaskInfo
{
STaskIdInfo
id
;
char
*
content
;
uint32_t
status
;
STimeWindow
window
;
STaskCostInfo
cost
;
int64_t
owner
;
// if it is in execution
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
pthread_mutex_t
lock
;
// used to synchronize the rsp/query threads
// tsem_t ready;
// int32_t dataReady; // denote if query result is ready or not
// void* rspContext; // response context
char
*
sql
;
// query sql string
jmp_buf
env
;
}
STaskInfo
;
typedef
struct
STaskRuntimeEnv
{
jmp_buf
env
;
jmp_buf
env
;
S
QueryAttr
*
pQueryAttr
;
S
TaskAttr
*
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
...
@@ -271,7 +298,7 @@ typedef struct SQueryRuntimeEnv {
...
@@ -271,7 +298,7 @@ typedef struct SQueryRuntimeEnv {
SRspResultInfo
resultInfo
;
SRspResultInfo
resultInfo
;
SHashObj
*
pTableRetrieveTsMap
;
SHashObj
*
pTableRetrieveTsMap
;
struct
SUdfInfo
*
pUdfInfo
;
struct
SUdfInfo
*
pUdfInfo
;
}
S
Query
RuntimeEnv
;
}
S
Task
RuntimeEnv
;
enum
{
enum
{
OP_IN_EXECUTING
=
1
,
OP_IN_EXECUTING
=
1
,
...
@@ -287,10 +314,11 @@ typedef struct SOperatorInfo {
...
@@ -287,10 +314,11 @@ typedef struct SOperatorInfo {
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
;
SQueryRuntimeEnv
*
pRuntimeEnv
;
STaskRuntimeEnv
*
pRuntimeEnv
;
STaskInfo
*
pTaskInfo
;
struct
SOperatorInfo
**
upstream
;
// upstre
am pointer list
struct
SOperatorInfo
**
pDownstream
;
// downstr
am pointer list
int32_t
numOf
Upstream
;
// number of up
stream. The value is always ONE expect for join operator
int32_t
numOf
Downstream
;
// number of down
stream. The value is always ONE expect for join operator
__operator_fn_t
exec
;
__operator_fn_t
exec
;
__optr_cleanup_fn_t
cleanup
;
__optr_cleanup_fn_t
cleanup
;
}
SOperatorInfo
;
}
SOperatorInfo
;
...
@@ -312,8 +340,8 @@ typedef struct SQInfo {
...
@@ -312,8 +340,8 @@ typedef struct SQInfo {
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
S
Query
RuntimeEnv
runtimeEnv
;
S
Task
RuntimeEnv
runtimeEnv
;
S
Query
Attr
query
;
S
Task
Attr
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
...
@@ -322,10 +350,10 @@ typedef struct SQInfo {
...
@@ -322,10 +350,10 @@ typedef struct SQInfo {
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
S
QueryCostInfo
summary
;
S
TaskCostInfo
summary
;
}
SQInfo
;
}
SQInfo
;
typedef
struct
S
Query
Param
{
typedef
struct
S
Task
Param
{
char
*
sql
;
char
*
sql
;
char
*
tagCond
;
char
*
tagCond
;
char
*
colCond
;
char
*
colCond
;
...
@@ -345,7 +373,7 @@ typedef struct SQueryParam {
...
@@ -345,7 +373,7 @@ typedef struct SQueryParam {
int32_t
tableScanOperator
;
int32_t
tableScanOperator
;
SArray
*
pOperator
;
SArray
*
pOperator
;
struct
SUdfInfo
*
pUdfInfo
;
struct
SUdfInfo
*
pUdfInfo
;
}
S
Query
Param
;
}
S
Task
Param
;
typedef
struct
STableScanInfo
{
typedef
struct
STableScanInfo
{
void
*
pQueryHandle
;
void
*
pQueryHandle
;
...
@@ -366,9 +394,12 @@ typedef struct STableScanInfo {
...
@@ -366,9 +394,12 @@ typedef struct STableScanInfo {
SSDataBlock
block
;
SSDataBlock
block
;
int32_t
numOfOutput
;
int32_t
numOfOutput
;
int64_t
elapsedTime
;
int64_t
elapsedTime
;
int32_t
tableIndex
;
int32_t
tableIndex
;
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
STimeWindow
window
;
}
STableScanInfo
;
}
STableScanInfo
;
typedef
struct
STagScanInfo
{
typedef
struct
STagScanInfo
{
...
@@ -512,34 +543,34 @@ typedef struct SOrderOperatorInfo {
...
@@ -512,34 +543,34 @@ typedef struct SOrderOperatorInfo {
void
appendUpstream
(
SOperatorInfo
*
p
,
SOperatorInfo
*
pUpstream
);
void
appendUpstream
(
SOperatorInfo
*
p
,
SOperatorInfo
*
pUpstream
);
SOperatorInfo
*
createDataBlocksOptScanInfo
(
void
*
pTsdbQueryHandle
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
);
SOperatorInfo
*
createDataBlocksOptScanInfo
(
void
*
pTsdbQueryHandle
,
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
);
SOperatorInfo
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
);
SOperatorInfo
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
int32_t
order
,
int32_t
numOfOutput
,
int32_t
repeatTime
);
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbQueryHandle
,
S
Query
RuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbQueryHandle
,
S
Task
RuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createAggregateOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAggregateOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createProjectOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createProjectOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createLimitOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
);
SOperatorInfo
*
createLimitOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
);
SOperatorInfo
*
createTimeIntervalOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTimeIntervalOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createSWindowOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createSWindowOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createFillOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
bool
multigroupResult
);
SOperatorInfo
*
createFillOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
bool
multigroupResult
);
SOperatorInfo
*
createGroupbyOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createGroupbyOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createMultiTableTimeIntervalOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createMultiTableTimeIntervalOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAllMultiTableTimeIntervalOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createAllMultiTableTimeIntervalOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTagScanOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTagScanOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createDistinctOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createDistinctOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createTableBlockInfoScanOperator
(
void
*
pTsdbQueryHandle
,
S
Query
RuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createTableBlockInfoScanOperator
(
void
*
pTsdbQueryHandle
,
S
Task
RuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createMultiwaySortOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOperatorInfo
*
createMultiwaySortOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
,
void
*
merger
);
int32_t
numOfRows
,
void
*
merger
);
SOperatorInfo
*
createGlobalAggregateOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
param
,
SArray
*
pUdfInfo
,
bool
groupResultMixedUp
);
SOperatorInfo
*
createGlobalAggregateOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
param
,
SArray
*
pUdfInfo
,
bool
groupResultMixedUp
);
SOperatorInfo
*
createStatewindowOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createStatewindowOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createSLimitOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
merger
,
bool
multigroupResult
);
SOperatorInfo
*
createSLimitOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
merger
,
bool
multigroupResult
);
SOperatorInfo
*
createFilterOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
SOperatorInfo
*
createFilterOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SColumnInfo
*
pCols
,
int32_t
numOfFilter
);
int32_t
numOfOutput
,
SColumnInfo
*
pCols
,
int32_t
numOfFilter
);
SOperatorInfo
*
createJoinOperatorInfo
(
SOperatorInfo
**
pUpstream
,
int32_t
numOfUpstream
,
SSchema
*
pSchema
,
int32_t
numOfOutput
);
SOperatorInfo
*
createJoinOperatorInfo
(
SOperatorInfo
**
pUpstream
,
int32_t
numOfUpstream
,
SSchema
*
pSchema
,
int32_t
numOfOutput
);
SOperatorInfo
*
createOrderOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOrder
*
pOrderVal
);
SOperatorInfo
*
createOrderOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
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
);
...
@@ -561,8 +592,8 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf
...
@@ -561,8 +592,8 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf
void
clearOutputBuf
(
SOptrBasicInfo
*
pBInfo
,
int32_t
*
bufCapacity
);
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
(
S
Query
Param
*
param
);
void
freeParam
(
S
Task
Param
*
param
);
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
S
Query
Param
*
param
);
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
S
Task
Param
*
param
);
int32_t
createQueryFunc
(
SQueriedTableInfo
*
pTableInfo
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
int32_t
createQueryFunc
(
SQueriedTableInfo
*
pTableInfo
,
int32_t
numOfOutput
,
SExprInfo
**
pExprInfo
,
SSqlExpr
**
pExprMsg
,
SColumnInfo
*
pTagCols
,
int32_t
queryType
,
void
*
pMsg
,
struct
SUdfInfo
*
pUdfInfo
);
SSqlExpr
**
pExprMsg
,
SColumnInfo
*
pTagCols
,
int32_t
queryType
,
void
*
pMsg
,
struct
SUdfInfo
*
pUdfInfo
);
...
@@ -575,13 +606,13 @@ SGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pCo
...
@@ -575,13 +606,13 @@ SGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pCo
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
SGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
SGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
SExprInfo
*
pSecExprs
,
STableGroupInfo
*
pTableGroupInfo
,
SColumnInfo
*
pTagCols
,
SFilterInfo
*
pFilters
,
int32_t
vgId
,
char
*
sql
,
uint64_t
qId
,
struct
SUdfInfo
*
pUdfInfo
);
SExprInfo
*
pSecExprs
,
STableGroupInfo
*
pTableGroupInfo
,
SColumnInfo
*
pTagCols
,
SFilterInfo
*
pFilters
,
int32_t
vgId
,
char
*
sql
,
uint64_t
qId
,
struct
SUdfInfo
*
pUdfInfo
);
int32_t
initQInfo
(
STsBufInfo
*
pTsBufInfo
,
void
*
tsdb
,
void
*
sourceOptr
,
SQInfo
*
pQInfo
,
S
Query
Param
*
param
,
char
*
start
,
int32_t
initQInfo
(
STsBufInfo
*
pTsBufInfo
,
void
*
tsdb
,
void
*
sourceOptr
,
SQInfo
*
pQInfo
,
S
Task
Param
*
param
,
char
*
start
,
int32_t
prevResultLen
,
void
*
merger
);
int32_t
prevResultLen
,
void
*
merger
);
int32_t
createFilterInfo
(
S
Query
Attr
*
pQueryAttr
,
uint64_t
qId
);
int32_t
createFilterInfo
(
S
Task
Attr
*
pQueryAttr
,
uint64_t
qId
);
void
freeColumnFilterInfo
(
SColumnFilterInfo
*
pFilter
,
int32_t
numOfFilters
);
void
freeColumnFilterInfo
(
SColumnFilterInfo
*
pFilter
,
int32_t
numOfFilters
);
STableQueryInfo
*
createTableQueryInfo
(
S
Query
Attr
*
pQueryAttr
,
void
*
pTable
,
bool
groupbyColumn
,
STimeWindow
win
,
void
*
buf
);
STableQueryInfo
*
createTableQueryInfo
(
S
Task
Attr
*
pQueryAttr
,
void
*
pTable
,
bool
groupbyColumn
,
STimeWindow
win
,
void
*
buf
);
STableQueryInfo
*
createTmpTableQueryInfo
(
STimeWindow
win
);
STableQueryInfo
*
createTmpTableQueryInfo
(
STimeWindow
win
);
int32_t
buildArithmeticExprFromMsg
(
SExprInfo
*
pArithExprInfo
,
void
*
pQueryMsg
);
int32_t
buildArithmeticExprFromMsg
(
SExprInfo
*
pArithExprInfo
,
void
*
pQueryMsg
);
...
@@ -590,9 +621,9 @@ bool isQueryKilled(SQInfo *pQInfo);
...
@@ -590,9 +621,9 @@ bool isQueryKilled(SQInfo *pQInfo);
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
bool
checkNeedToCompressQueryCol
(
SQInfo
*
pQInfo
);
bool
checkNeedToCompressQueryCol
(
SQInfo
*
pQInfo
);
bool
doBuildResCheck
(
SQInfo
*
pQInfo
);
bool
doBuildResCheck
(
SQInfo
*
pQInfo
);
void
setQueryStatus
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int8_t
status
);
void
setQueryStatus
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int8_t
status
);
bool
onlyQueryTags
(
S
Query
Attr
*
pQueryAttr
);
bool
onlyQueryTags
(
S
Task
Attr
*
pQueryAttr
);
void
destroyUdfInfo
(
struct
SUdfInfo
*
pUdfInfo
);
void
destroyUdfInfo
(
struct
SUdfInfo
*
pUdfInfo
);
bool
isValidQInfo
(
void
*
param
);
bool
isValidQInfo
(
void
*
param
);
...
@@ -607,8 +638,8 @@ void publishQueryAbortEvent(SQInfo* pQInfo, int32_t code);
...
@@ -607,8 +638,8 @@ void publishQueryAbortEvent(SQInfo* pQInfo, int32_t code);
void
calculateOperatorProfResults
(
SQInfo
*
pQInfo
);
void
calculateOperatorProfResults
(
SQInfo
*
pQInfo
);
void
queryCostStatis
(
SQInfo
*
pQInfo
);
void
queryCostStatis
(
SQInfo
*
pQInfo
);
void
freeQInfo
(
SQInfo
*
pQInfo
);
void
doDestroyTask
(
SQInfo
*
pQInfo
);
void
freeQueryAttr
(
S
Query
Attr
*
pQuery
);
void
freeQueryAttr
(
S
Task
Attr
*
pQuery
);
int32_t
getMaximumIdleDurationSec
();
int32_t
getMaximumIdleDurationSec
();
...
...
source/libs/executor/src/executil.c
浏览文件 @
95347ff6
...
@@ -30,7 +30,7 @@ typedef struct SCompSupporter {
...
@@ -30,7 +30,7 @@ typedef struct SCompSupporter {
int32_t
order
;
int32_t
order
;
}
SCompSupporter
;
}
SCompSupporter
;
int32_t
getRowNumForMultioutput
(
S
Query
Attr
*
pQueryAttr
,
bool
topBottomQuery
,
bool
stable
)
{
int32_t
getRowNumForMultioutput
(
S
Task
Attr
*
pQueryAttr
,
bool
topBottomQuery
,
bool
stable
)
{
if
(
pQueryAttr
&&
(
!
stable
))
{
if
(
pQueryAttr
&&
(
!
stable
))
{
for
(
int16_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int16_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
// if (pQueryAttr->pExpr1[i].base. == FUNCTION_TOP || pQueryAttr->pExpr1[i].base.functionId == FUNCTION_BOTTOM) {
// if (pQueryAttr->pExpr1[i].base. == FUNCTION_TOP || pQueryAttr->pExpr1[i].base.functionId == FUNCTION_BOTTOM) {
...
@@ -42,7 +42,7 @@ int32_t getRowNumForMultioutput(SQueryAttr* pQueryAttr, bool topBottomQuery, boo
...
@@ -42,7 +42,7 @@ int32_t getRowNumForMultioutput(SQueryAttr* pQueryAttr, bool topBottomQuery, boo
return
1
;
return
1
;
}
}
int32_t
getOutputInterResultBufSize
(
S
Query
Attr
*
pQueryAttr
)
{
int32_t
getOutputInterResultBufSize
(
S
Task
Attr
*
pQueryAttr
)
{
int32_t
size
=
0
;
int32_t
size
=
0
;
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
...
@@ -86,7 +86,7 @@ void cleanupResultRowInfo(SResultRowInfo *pResultRowInfo) {
...
@@ -86,7 +86,7 @@ void cleanupResultRowInfo(SResultRowInfo *pResultRowInfo) {
tfree
(
pResultRowInfo
->
pResult
);
tfree
(
pResultRowInfo
->
pResult
);
}
}
void
resetResultRowInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
)
{
void
resetResultRowInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
)
{
if
(
pResultRowInfo
==
NULL
||
pResultRowInfo
->
capacity
==
0
)
{
if
(
pResultRowInfo
==
NULL
||
pResultRowInfo
->
capacity
==
0
)
{
return
;
return
;
}
}
...
@@ -136,7 +136,7 @@ void closeResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {
...
@@ -136,7 +136,7 @@ void closeResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {
getResultRow
(
pResultRowInfo
,
slot
)
->
closed
=
true
;
getResultRow
(
pResultRowInfo
,
slot
)
->
closed
=
true
;
}
}
void
clearResultRow
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int16_t
type
)
{
void
clearResultRow
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int16_t
type
)
{
if
(
pResultRow
==
NULL
)
{
if
(
pResultRow
==
NULL
)
{
return
;
return
;
}
}
...
@@ -174,8 +174,8 @@ struct SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index,
...
@@ -174,8 +174,8 @@ struct SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index,
return
NULL
;
return
NULL
;
}
}
size_t
getResultRowSize
(
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
size_t
getResultRowSize
(
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
return
0
;
return
0
;
// return (pQueryAttr->numOfOutput * sizeof(SResultRowEntryInfo)) + pQueryAttr->interBufSize + sizeof(SResultRow);
// return (pQueryAttr->numOfOutput * sizeof(SResultRowEntryInfo)) + pQueryAttr->interBufSize + sizeof(SResultRow);
}
}
...
@@ -393,8 +393,8 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) {
...
@@ -393,8 +393,8 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) {
return
(
int32_t
)
taosArrayGetSize
(
pGroupResInfo
->
pRows
);
return
(
int32_t
)
taosArrayGetSize
(
pGroupResInfo
->
pRows
);
}
}
static
int64_t
getNumOfResultWindowRes
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int32_t
*
rowCellInfoOffset
)
{
static
int64_t
getNumOfResultWindowRes
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
,
int32_t
*
rowCellInfoOffset
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
for
(
int32_t
j
=
0
;
j
<
pQueryAttr
->
numOfOutput
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQueryAttr
->
numOfOutput
;
++
j
)
{
int32_t
functionId
=
0
;
//pQueryAttr->pExpr1[j].base.functionId;
int32_t
functionId
=
0
;
//pQueryAttr->pExpr1[j].base.functionId;
...
@@ -488,7 +488,7 @@ int32_t tsDescOrder(const void* p1, const void* p2) {
...
@@ -488,7 +488,7 @@ int32_t tsDescOrder(const void* p1, const void* p2) {
}
}
}
}
void
orderTheResultRows
(
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
void
orderTheResultRows
(
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
__compar_fn_t
fn
=
NULL
;
__compar_fn_t
fn
=
NULL
;
if
(
pRuntimeEnv
->
pQueryAttr
->
order
.
order
==
TSDB_ORDER_ASC
)
{
if
(
pRuntimeEnv
->
pQueryAttr
->
order
.
order
==
TSDB_ORDER_ASC
)
{
fn
=
tsAscOrder
;
fn
=
tsAscOrder
;
...
@@ -499,7 +499,7 @@ void orderTheResultRows(SQueryRuntimeEnv* pRuntimeEnv) {
...
@@ -499,7 +499,7 @@ void orderTheResultRows(SQueryRuntimeEnv* pRuntimeEnv) {
taosArraySort
(
pRuntimeEnv
->
pResultRowArrayList
,
fn
);
taosArraySort
(
pRuntimeEnv
->
pResultRowArrayList
,
fn
);
}
}
static
int32_t
mergeIntoGroupResultImplRv
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
uint64_t
groupId
,
int32_t
*
rowCellInfoOffset
)
{
static
int32_t
mergeIntoGroupResultImplRv
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
uint64_t
groupId
,
int32_t
*
rowCellInfoOffset
)
{
if
(
!
pGroupResInfo
->
ordered
)
{
if
(
!
pGroupResInfo
->
ordered
)
{
orderTheResultRows
(
pRuntimeEnv
);
orderTheResultRows
(
pRuntimeEnv
);
pGroupResInfo
->
ordered
=
true
;
pGroupResInfo
->
ordered
=
true
;
...
@@ -528,7 +528,7 @@ static int32_t mergeIntoGroupResultImplRv(SQueryRuntimeEnv *pRuntimeEnv, SGroupR
...
@@ -528,7 +528,7 @@ static int32_t mergeIntoGroupResultImplRv(SQueryRuntimeEnv *pRuntimeEnv, SGroupR
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
UNUSED_FUNC
int32_t
mergeIntoGroupResultImpl
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
SArray
*
pTableList
,
static
UNUSED_FUNC
int32_t
mergeIntoGroupResultImpl
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
SArray
*
pTableList
,
int32_t
*
rowCellInfoOffset
)
{
int32_t
*
rowCellInfoOffset
)
{
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pRuntimeEnv
->
pQueryAttr
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pRuntimeEnv
->
pQueryAttr
);
...
@@ -630,7 +630,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEn
...
@@ -630,7 +630,7 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEn
return
code
;
return
code
;
}
}
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int32_t
*
offset
)
{
int32_t
mergeIntoGroupResult
(
SGroupResInfo
*
pGroupResInfo
,
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int32_t
*
offset
)
{
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
while
(
pGroupResInfo
->
currentGroup
<
pGroupResInfo
->
totalGroup
)
{
while
(
pGroupResInfo
->
currentGroup
<
pGroupResInfo
->
totalGroup
)
{
...
...
source/libs/executor/src/executorMain.c
0 → 100644
浏览文件 @
95347ff6
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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/>.
*/
#include "os.h"
#include "tcache.h"
#include "tglobal.h"
#include "tmsg.h"
#include "exception.h"
#include "thash.h"
#include "executorimpl.h"
#include "executor.h"
#include "tlosertree.h"
#include "ttypes.h"
#include "query.h"
typedef
struct
STaskMgmt
{
pthread_mutex_t
lock
;
SCacheObj
*
qinfoPool
;
// query handle pool
int32_t
vgId
;
bool
closed
;
}
STaskMgmt
;
static
void
taskMgmtKillTaskFn
(
void
*
handle
,
void
*
param1
)
{
void
**
fp
=
(
void
**
)
handle
;
qKillTask
(
*
fp
);
}
static
void
freeqinfoFn
(
void
*
qhandle
)
{
void
**
handle
=
qhandle
;
if
(
handle
==
NULL
||
*
handle
==
NULL
)
{
return
;
}
qKillTask
(
*
handle
);
qDestroyTask
(
*
handle
);
}
void
freeParam
(
STaskParam
*
param
)
{
tfree
(
param
->
sql
);
tfree
(
param
->
tagCond
);
tfree
(
param
->
tbnameCond
);
tfree
(
param
->
pTableIdList
);
taosArrayDestroy
(
param
->
pOperator
);
tfree
(
param
->
pExprs
);
tfree
(
param
->
pSecExprs
);
tfree
(
param
->
pExpr
);
tfree
(
param
->
pSecExpr
);
tfree
(
param
->
pGroupColIndex
);
tfree
(
param
->
pTagColumnInfo
);
tfree
(
param
->
pGroupbyExpr
);
tfree
(
param
->
prevResult
);
}
// todo parse json to get the operator tree.
int32_t
qCreateTask
(
void
*
tsdb
,
int32_t
vgId
,
void
*
pQueryMsg
,
qTaskInfo_t
*
pTaskInfo
,
uint64_t
taskId
)
{
assert
(
pQueryMsg
!=
NULL
&&
tsdb
!=
NULL
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
#if 0
STaskParam param = {0};
code = convertQueryMsg(pQueryMsg, ¶m);
if (code != TSDB_CODE_SUCCESS) {
goto _over;
}
if (pQueryMsg->numOfTables <= 0) {
qError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables);
code = TSDB_CODE_QRY_INVALID_MSG;
goto _over;
}
if (param.pTableIdList == NULL || taosArrayGetSize(param.pTableIdList) == 0) {
qError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg);
code = TSDB_CODE_QRY_INVALID_MSG;
goto _over;
}
SQueriedTableInfo info = { .numOfTags = pQueryMsg->numOfTags, .numOfCols = pQueryMsg->numOfCols, .colList = pQueryMsg->tableCols};
if ((code = createQueryFunc(&info, pQueryMsg->numOfOutput, ¶m.pExprs, param.pExpr, param.pTagColumnInfo,
pQueryMsg->queryType, pQueryMsg, param.pUdfInfo)) != TSDB_CODE_SUCCESS) {
goto _over;
}
if (param.pSecExpr != NULL) {
if ((code = createIndirectQueryFuncExprFromMsg(pQueryMsg, pQueryMsg->secondStageOutput, ¶m.pSecExprs, param.pSecExpr, param.pExprs, param.pUdfInfo)) != TSDB_CODE_SUCCESS) {
goto _over;
}
}
if (param.colCond != NULL) {
if ((code = createQueryFilter(param.colCond, pQueryMsg->colCondLen, ¶m.pFilters)) != TSDB_CODE_SUCCESS) {
goto _over;
}
}
param.pGroupbyExpr = createGroupbyExprFromMsg(pQueryMsg, param.pGroupColIndex, &code);
if ((param.pGroupbyExpr == NULL && pQueryMsg->numOfGroupCols != 0) || code != TSDB_CODE_SUCCESS) {
goto _over;
}
bool isSTableQuery = false;
STableGroupInfo tableGroupInfo = {0};
int64_t st = taosGetTimestampUs();
if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_TABLE_QUERY)) {
STableIdInfo *id = taosArrayGet(param.pTableIdList, 0);
qDebug("qmsg:%p query normal table, uid:%"PRId64", tid:%d", pQueryMsg, id->uid, id->tid);
if ((code = tsdbGetOneTableGroup(tsdb, id->uid, pQueryMsg->window.skey, &tableGroupInfo)) != TSDB_CODE_SUCCESS) {
goto _over;
}
} else if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_MULTITABLE_QUERY|TSDB_QUERY_TYPE_STABLE_QUERY)) {
isSTableQuery = true;
// also note there's possibility that only one table in the super table
if (!TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_MULTITABLE_QUERY)) {
STableIdInfo *id = taosArrayGet(param.pTableIdList, 0);
// group by normal column, do not pass the group by condition to tsdb to group table into different group
int32_t numOfGroupByCols = pQueryMsg->numOfGroupCols;
if (pQueryMsg->numOfGroupCols == 1 && !TSDB_COL_IS_TAG(param.pGroupColIndex->flag)) {
numOfGroupByCols = 0;
}
qDebug("qmsg:%p query stable, uid:%"PRIu64", tid:%d", pQueryMsg, id->uid, id->tid);
code = tsdbQuerySTableByTagCond(tsdb, id->uid, pQueryMsg->window.skey, param.tagCond, pQueryMsg->tagCondLen,
pQueryMsg->tagNameRelType, param.tbnameCond, &tableGroupInfo, param.pGroupColIndex, numOfGroupByCols);
if (code != TSDB_CODE_SUCCESS) {
qError("qmsg:%p failed to query stable, reason: %s", pQueryMsg, tstrerror(code));
goto _over;
}
} else {
code = tsdbGetTableGroupFromIdList(tsdb, param.pTableIdList, &tableGroupInfo);
if (code != TSDB_CODE_SUCCESS) {
goto _over;
}
qDebug("qmsg:%p query on %u tables in one group from client", pQueryMsg, tableGroupInfo.numOfTables);
}
int64_t el = taosGetTimestampUs() - st;
qDebug("qmsg:%p tag filter completed, numOfTables:%u, elapsed time:%"PRId64"us", pQueryMsg, tableGroupInfo.numOfTables, el);
} else {
assert(0);
}
code = checkForQueryBuf(tableGroupInfo.numOfTables);
if (code != TSDB_CODE_SUCCESS) { // not enough query buffer, abort
goto _over;
}
assert(pQueryMsg->stableQuery == isSTableQuery);
(*pTaskInfo) = createQInfoImpl(pQueryMsg, param.pGroupbyExpr, param.pExprs, param.pSecExprs, &tableGroupInfo,
param.pTagColumnInfo, param.pFilters, vgId, param.sql, qId, param.pUdfInfo);
param.sql = NULL;
param.pExprs = NULL;
param.pSecExprs = NULL;
param.pGroupbyExpr = NULL;
param.pTagColumnInfo = NULL;
param.pFilters = NULL;
if ((*pTaskInfo) == NULL) {
code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _over;
}
param.pUdfInfo = NULL;
code = initQInfo(&pQueryMsg->tsBuf, tsdb, NULL, *pTaskInfo, ¶m, (char*)pQueryMsg, pQueryMsg->prevResultLen, NULL);
_over:
if (param.pGroupbyExpr != NULL) {
taosArrayDestroy(param.pGroupbyExpr->columnInfo);
}
tfree(param.colCond);
destroyUdfInfo(param.pUdfInfo);
taosArrayDestroy(param.pTableIdList);
param.pTableIdList = NULL;
freeParam(¶m);
for (int32_t i = 0; i < pQueryMsg->numOfCols; i++) {
SColumnInfo* column = pQueryMsg->tableCols + i;
freeColumnFilterInfo(column->flist.filterInfo, column->flist.numOfFilters);
}
filterFreeInfo(param.pFilters);
//pTaskInfo already freed in initQInfo, but *pTaskInfo may not pointer to null;
if (code != TSDB_CODE_SUCCESS) {
*pTaskInfo = NULL;
}
#endif
// if failed to add ref for all tables in this query, abort current query
return
code
;
}
#ifdef TEST_IMPL
// wait moment
int
waitMoment
(
SQInfo
*
pQInfo
){
if
(
pQInfo
->
sql
)
{
int
ms
=
0
;
char
*
pcnt
=
strstr
(
pQInfo
->
sql
,
" count(*)"
);
if
(
pcnt
)
return
0
;
char
*
pos
=
strstr
(
pQInfo
->
sql
,
" t_"
);
if
(
pos
){
pos
+=
3
;
ms
=
atoi
(
pos
);
while
(
*
pos
>=
'0'
&&
*
pos
<=
'9'
){
pos
++
;
}
char
unit_char
=
*
pos
;
if
(
unit_char
==
'h'
){
ms
*=
3600
*
1000
;
}
else
if
(
unit_char
==
'm'
){
ms
*=
60
*
1000
;
}
else
if
(
unit_char
==
's'
){
ms
*=
1000
;
}
}
if
(
ms
==
0
)
return
0
;
printf
(
"test wait sleep %dms. sql=%s ...
\n
"
,
ms
,
pQInfo
->
sql
);
if
(
ms
<
1000
)
{
taosMsleep
(
ms
);
}
else
{
int
used_ms
=
0
;
while
(
used_ms
<
ms
)
{
taosMsleep
(
1000
);
used_ms
+=
1000
;
if
(
isQueryKilled
(
pQInfo
)){
printf
(
"test check query is canceled, sleep break.%s
\n
"
,
pQInfo
->
sql
);
break
;
}
}
}
}
return
1
;
}
#endif
bool
qExecTask
(
qTaskInfo_t
qinfo
,
uint64_t
*
qId
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
qinfo
;
assert
(
pQInfo
&&
pQInfo
->
signature
==
pQInfo
);
int64_t
threadId
=
taosGetSelfPthreadId
();
int64_t
curOwner
=
0
;
if
((
curOwner
=
atomic_val_compare_exchange_64
(
&
pQInfo
->
owner
,
0
,
threadId
))
!=
0
)
{
qError
(
"QInfo:0x%"
PRIx64
"-%p qhandle is now executed by thread:%p"
,
pQInfo
->
qId
,
pQInfo
,
(
void
*
)
curOwner
);
pQInfo
->
code
=
TSDB_CODE_QRY_IN_EXEC
;
return
false
;
}
*
qId
=
pQInfo
->
qId
;
if
(
pQInfo
->
startExecTs
==
0
)
pQInfo
->
startExecTs
=
taosGetTimestampMs
();
if
(
isQueryKilled
(
pQInfo
))
{
qDebug
(
"QInfo:0x%"
PRIx64
" it is already killed, abort"
,
pQInfo
->
qId
);
return
doBuildResCheck
(
pQInfo
);
}
STaskRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
if
(
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
==
0
)
{
qDebug
(
"QInfo:0x%"
PRIx64
" no table exists for query, abort"
,
pQInfo
->
qId
);
// setTaskStatus(pRuntimeEnv, QUERY_COMPLETED);
return
doBuildResCheck
(
pQInfo
);
}
// error occurs, record the error code and return to client
int32_t
ret
=
setjmp
(
pQInfo
->
runtimeEnv
.
env
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
publishQueryAbortEvent
(
pQInfo
,
ret
);
pQInfo
->
code
=
ret
;
qDebug
(
"QInfo:0x%"
PRIx64
" query abort due to error/cancel occurs, code:%s"
,
pQInfo
->
qId
,
tstrerror
(
pQInfo
->
code
));
return
doBuildResCheck
(
pQInfo
);
}
qDebug
(
"QInfo:0x%"
PRIx64
" query task is launched"
,
pQInfo
->
qId
);
bool
newgroup
=
false
;
publishOperatorProfEvent
(
pRuntimeEnv
->
proot
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
int64_t
st
=
taosGetTimestampUs
();
pRuntimeEnv
->
outputBuf
=
pRuntimeEnv
->
proot
->
exec
(
pRuntimeEnv
->
proot
,
&
newgroup
);
pQInfo
->
summary
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
#ifdef TEST_IMPL
waitMoment
(
pQInfo
);
#endif
publishOperatorProfEvent
(
pRuntimeEnv
->
proot
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
pRuntimeEnv
->
resultInfo
.
total
+=
GET_NUM_OF_RESULTS
(
pRuntimeEnv
);
if
(
isQueryKilled
(
pQInfo
))
{
qDebug
(
"QInfo:0x%"
PRIx64
" query is killed"
,
pQInfo
->
qId
);
}
else
if
(
GET_NUM_OF_RESULTS
(
pRuntimeEnv
)
==
0
)
{
qDebug
(
"QInfo:0x%"
PRIx64
" over, %u tables queried, total %"
PRId64
" rows returned"
,
pQInfo
->
qId
,
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
,
pRuntimeEnv
->
resultInfo
.
total
);
}
else
{
qDebug
(
"QInfo:0x%"
PRIx64
" query paused, %d rows returned, total:%"
PRId64
" rows"
,
pQInfo
->
qId
,
GET_NUM_OF_RESULTS
(
pRuntimeEnv
),
pRuntimeEnv
->
resultInfo
.
total
);
}
return
doBuildResCheck
(
pQInfo
);
}
int32_t
qRetrieveQueryResultInfo
(
qTaskInfo_t
qinfo
,
bool
*
buildRes
,
void
*
pRspContext
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
qinfo
;
if
(
pQInfo
==
NULL
||
!
isValidQInfo
(
pQInfo
))
{
qError
(
"QInfo invalid qhandle"
);
return
TSDB_CODE_QRY_INVALID_QHANDLE
;
}
*
buildRes
=
false
;
if
(
IS_QUERY_KILLED
(
pQInfo
))
{
qDebug
(
"QInfo:0x%"
PRIx64
" query is killed, code:0x%08x"
,
pQInfo
->
qId
,
pQInfo
->
code
);
return
pQInfo
->
code
;
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
tsRetrieveBlockingModel
)
{
pQInfo
->
rspContext
=
pRspContext
;
tsem_wait
(
&
pQInfo
->
ready
);
*
buildRes
=
true
;
code
=
pQInfo
->
code
;
}
else
{
STaskRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
STaskAttr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
pthread_mutex_lock
(
&
pQInfo
->
lock
);
assert
(
pQInfo
->
rspContext
==
NULL
);
if
(
pQInfo
->
dataReady
==
QUERY_RESULT_READY
)
{
*
buildRes
=
true
;
qDebug
(
"QInfo:0x%"
PRIx64
" retrieve result info, rowsize:%d, rows:%d, code:%s"
,
pQInfo
->
qId
,
pQueryAttr
->
resultRowSize
,
GET_NUM_OF_RESULTS
(
pRuntimeEnv
),
tstrerror
(
pQInfo
->
code
));
}
else
{
*
buildRes
=
false
;
qDebug
(
"QInfo:0x%"
PRIx64
" retrieve req set query return result after paused"
,
pQInfo
->
qId
);
pQInfo
->
rspContext
=
pRspContext
;
assert
(
pQInfo
->
rspContext
!=
NULL
);
}
code
=
pQInfo
->
code
;
pthread_mutex_unlock
(
&
pQInfo
->
lock
);
}
return
code
;
}
void
*
qGetResultRetrieveMsg
(
qTaskInfo_t
qinfo
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
qinfo
;
assert
(
pQInfo
!=
NULL
);
return
pQInfo
->
rspContext
;
}
int32_t
qKillTask
(
qTaskInfo_t
qinfo
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
qinfo
;
if
(
pQInfo
==
NULL
||
!
isValidQInfo
(
pQInfo
))
{
return
TSDB_CODE_QRY_INVALID_QHANDLE
;
}
qDebug
(
"QInfo:0x%"
PRIx64
" query killed"
,
pQInfo
->
qId
);
setQueryKilled
(
pQInfo
);
// Wait for the query executing thread being stopped/
// Once the query is stopped, the owner of qHandle will be cleared immediately.
while
(
pQInfo
->
owner
!=
0
)
{
taosMsleep
(
100
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
qIsTaskCompleted
(
qTaskInfo_t
qinfo
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
qinfo
;
if
(
pQInfo
==
NULL
||
!
isValidQInfo
(
pQInfo
))
{
return
TSDB_CODE_QRY_INVALID_QHANDLE
;
}
return
isQueryKilled
(
pQInfo
)
||
Q_STATUS_EQUAL
(
pQInfo
->
runtimeEnv
.
status
,
QUERY_OVER
);
}
void
qDestroyTask
(
qTaskInfo_t
qHandle
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
qHandle
;
if
(
!
isValidQInfo
(
pQInfo
))
{
return
;
}
qDebug
(
"QInfo:0x%"
PRIx64
" query completed"
,
pQInfo
->
qId
);
queryCostStatis
(
pQInfo
);
// print the query cost summary
doDestroyTask
(
pQInfo
);
}
void
*
qOpenTaskMgmt
(
int32_t
vgId
)
{
const
int32_t
refreshHandleInterval
=
30
;
// every 30 seconds, refresh handle pool
char
cacheName
[
128
]
=
{
0
};
sprintf
(
cacheName
,
"qhandle_%d"
,
vgId
);
STaskMgmt
*
pTaskMgmt
=
calloc
(
1
,
sizeof
(
STaskMgmt
));
if
(
pTaskMgmt
==
NULL
)
{
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
NULL
;
}
pTaskMgmt
->
qinfoPool
=
taosCacheInit
(
TSDB_CACHE_PTR_KEY
,
refreshHandleInterval
,
true
,
freeqinfoFn
,
cacheName
);
pTaskMgmt
->
closed
=
false
;
pTaskMgmt
->
vgId
=
vgId
;
pthread_mutex_init
(
&
pTaskMgmt
->
lock
,
NULL
);
qDebug
(
"vgId:%d, open queryTaskMgmt success"
,
vgId
);
return
pTaskMgmt
;
}
void
qTaskMgmtNotifyClosing
(
void
*
pQMgmt
)
{
if
(
pQMgmt
==
NULL
)
{
return
;
}
STaskMgmt
*
pQueryMgmt
=
pQMgmt
;
qInfo
(
"vgId:%d, set querymgmt closed, wait for all queries cancelled"
,
pQueryMgmt
->
vgId
);
pthread_mutex_lock
(
&
pQueryMgmt
->
lock
);
pQueryMgmt
->
closed
=
true
;
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
taosCacheRefresh
(
pQueryMgmt
->
qinfoPool
,
taskMgmtKillTaskFn
,
NULL
);
}
void
qQueryMgmtReOpen
(
void
*
pQMgmt
)
{
if
(
pQMgmt
==
NULL
)
{
return
;
}
STaskMgmt
*
pQueryMgmt
=
pQMgmt
;
qInfo
(
"vgId:%d, set querymgmt reopen"
,
pQueryMgmt
->
vgId
);
pthread_mutex_lock
(
&
pQueryMgmt
->
lock
);
pQueryMgmt
->
closed
=
false
;
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
}
void
qCleanupTaskMgmt
(
void
*
pQMgmt
)
{
if
(
pQMgmt
==
NULL
)
{
return
;
}
STaskMgmt
*
pQueryMgmt
=
pQMgmt
;
int32_t
vgId
=
pQueryMgmt
->
vgId
;
assert
(
pQueryMgmt
->
closed
);
SCacheObj
*
pqinfoPool
=
pQueryMgmt
->
qinfoPool
;
pQueryMgmt
->
qinfoPool
=
NULL
;
taosCacheCleanup
(
pqinfoPool
);
pthread_mutex_destroy
(
&
pQueryMgmt
->
lock
);
tfree
(
pQueryMgmt
);
qDebug
(
"vgId:%d, queryMgmt cleanup completed"
,
vgId
);
}
void
**
qRegisterTask
(
void
*
pMgmt
,
uint64_t
qId
,
void
*
qInfo
)
{
if
(
pMgmt
==
NULL
)
{
terrno
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
return
NULL
;
}
STaskMgmt
*
pQueryMgmt
=
pMgmt
;
if
(
pQueryMgmt
->
qinfoPool
==
NULL
)
{
qError
(
"QInfo:0x%"
PRIx64
"-%p failed to add qhandle into qMgmt, since qMgmt is closed"
,
qId
,
(
void
*
)
qInfo
);
terrno
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
return
NULL
;
}
pthread_mutex_lock
(
&
pQueryMgmt
->
lock
);
if
(
pQueryMgmt
->
closed
)
{
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
qError
(
"QInfo:0x%"
PRIx64
"-%p failed to add qhandle into cache, since qMgmt is colsing"
,
qId
,
(
void
*
)
qInfo
);
terrno
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
return
NULL
;
}
else
{
void
**
handle
=
taosCachePut
(
pQueryMgmt
->
qinfoPool
,
&
qId
,
sizeof
(
qId
),
&
qInfo
,
sizeof
(
TSDB_CACHE_PTR_TYPE
),
(
getMaximumIdleDurationSec
()
*
1000
));
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
return
handle
;
}
}
void
**
qAcquireTask
(
void
*
pMgmt
,
uint64_t
_key
)
{
STaskMgmt
*
pQueryMgmt
=
pMgmt
;
if
(
pQueryMgmt
->
closed
)
{
terrno
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
return
NULL
;
}
if
(
pQueryMgmt
->
qinfoPool
==
NULL
)
{
terrno
=
TSDB_CODE_QRY_INVALID_QHANDLE
;
return
NULL
;
}
void
**
handle
=
taosCacheAcquireByKey
(
pQueryMgmt
->
qinfoPool
,
&
_key
,
sizeof
(
_key
));
if
(
handle
==
NULL
||
*
handle
==
NULL
)
{
terrno
=
TSDB_CODE_QRY_INVALID_QHANDLE
;
return
NULL
;
}
else
{
return
handle
;
}
}
void
**
qReleaseTask
(
void
*
pMgmt
,
void
*
pQInfo
,
bool
freeHandle
)
{
STaskMgmt
*
pQueryMgmt
=
pMgmt
;
if
(
pQueryMgmt
->
qinfoPool
==
NULL
)
{
return
NULL
;
}
taosCacheRelease
(
pQueryMgmt
->
qinfoPool
,
pQInfo
,
freeHandle
);
return
0
;
}
#if 0
//kill by qid
int32_t qKillQueryByQId(void* pMgmt, int64_t qId, int32_t waitMs, int32_t waitCount) {
int32_t error = TSDB_CODE_SUCCESS;
void** handle = qAcquireTask(pMgmt, qId);
if(handle == NULL) return terrno;
SQInfo* pQInfo = (SQInfo*)(*handle);
if (pQInfo == NULL || !isValidQInfo(pQInfo)) {
return TSDB_CODE_QRY_INVALID_QHANDLE;
}
qWarn("QId:0x%"PRIx64" be killed(no memory commit).", pQInfo->qId);
setQueryKilled(pQInfo);
// wait query stop
int32_t loop = 0;
while (pQInfo->owner != 0) {
taosMsleep(waitMs);
if(loop++ > waitCount){
error = TSDB_CODE_FAILED;
break;
}
}
qReleaseTask(pMgmt, (void **)&handle, true);
return error;
}
#endif
\ No newline at end of file
source/libs/executor/src/executorimpl.c
浏览文件 @
95347ff6
...
@@ -12,24 +12,25 @@
...
@@ -12,24 +12,25 @@
* 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 <function.h>
#include "os.h"
#include "os.h"
#include "tmsg.h"
#include "tmsg.h"
#include "tglobal.h"
#include "tglobal.h"
#include "ttime.h"
#include "ttime.h"
#include "exception.h"
#include "exception.h"
#include "../../../../contrib/cJson/cJSON.h"
#include "executorimpl.h"
#include "executorimpl.h"
#include "thash.h"
#include "function.h"
#include "function.h"
#include "tcompare.h"
#include "tcompare.h"
#include "tcompression.h"
#include "tcompression.h"
#include "thash.h"
#include "ttypes.h"
#include "ttypes.h"
#include "query.h"
#define IS_MA
STER_SCAN(runtime) ((runtime)->scanFlag == MASTER
_SCAN)
#define IS_MA
IN_SCAN(runtime) ((runtime)->scanFlag == MAIN
_SCAN)
#define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN)
#define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN)
#define IS_REPEAT_SCAN(runtime) ((runtime)->scanFlag == REPEAT_SCAN)
#define IS_REPEAT_SCAN(runtime) ((runtime)->scanFlag == REPEAT_SCAN)
#define SET_MA
STER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER
_SCAN)
#define SET_MA
IN_SCAN_FLAG(runtime) ((runtime)->scanFlag = MAIN
_SCAN)
#define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = REVERSE_SCAN)
#define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = REVERSE_SCAN)
#define TSWINDOW_IS_EQUAL(t1, t2) (((t1).skey == (t2).skey) && ((t1).ekey == (t2).ekey))
#define TSWINDOW_IS_EQUAL(t1, t2) (((t1).skey == (t2).skey) && ((t1).ekey == (t2).ekey))
...
@@ -41,11 +42,6 @@
...
@@ -41,11 +42,6 @@
#define MULTI_KEY_DELIM "-"
#define MULTI_KEY_DELIM "-"
#define TIME_WINDOW_COPY(_dst, _src) do {\
(_dst).skey = (_src).skey;\
(_dst).ekey = (_src).ekey;\
} while (0)
enum
{
enum
{
TS_JOIN_TS_EQUAL
=
0
,
TS_JOIN_TS_EQUAL
=
0
,
TS_JOIN_TS_NOT_EQUALS
=
1
,
TS_JOIN_TS_NOT_EQUALS
=
1
,
...
@@ -131,40 +127,16 @@ do { \
...
@@ -131,40 +127,16 @@ do { \
} \
} \
} while (0)
} while (0)
uint64_t
queryHandleId
=
0
;
int32_t
getMaximumIdleDurationSec
()
{
int32_t
getMaximumIdleDurationSec
()
{
return
tsShellActivityTimer
*
2
;
return
tsShellActivityTimer
*
2
;
}
}
int64_t
genQueryId
(
void
)
{
int64_t
uid
=
0
;
int64_t
did
=
0
;
//tsDnodeId;
uid
=
did
<<
54
;
int64_t
pid
=
((
int64_t
)
taosGetPId
())
&
0x3FF
;
uid
|=
pid
<<
44
;
int64_t
ts
=
taosGetTimestampMs
()
&
0x1FFFFFFFF
;
uid
|=
ts
<<
11
;
int64_t
sid
=
atomic_add_fetch_64
(
&
queryHandleId
,
1
)
&
0x7FF
;
uid
|=
sid
;
// //qDebug("gen qid:0x%"PRIx64, uid);
return
uid
;
}
static
int32_t
getExprFunctionId
(
SExprInfo
*
pExprInfo
)
{
static
int32_t
getExprFunctionId
(
SExprInfo
*
pExprInfo
)
{
assert
(
pExprInfo
!=
NULL
&&
pExprInfo
->
pExpr
!=
NULL
&&
pExprInfo
->
pExpr
->
nodeType
==
TEXPR_UNARYEXPR_NODE
);
assert
(
pExprInfo
!=
NULL
&&
pExprInfo
->
pExpr
!=
NULL
&&
pExprInfo
->
pExpr
->
nodeType
==
TEXPR_UNARYEXPR_NODE
);
return
0
;
return
0
;
}
}
static
void
getNextTimeWindow
(
S
Query
Attr
*
pQueryAttr
,
STimeWindow
*
tw
)
{
static
void
getNextTimeWindow
(
S
Task
Attr
*
pQueryAttr
,
STimeWindow
*
tw
)
{
int32_t
factor
=
GET_FORWARD_DIRECTION_FACTOR
(
pQueryAttr
->
order
.
order
);
int32_t
factor
=
GET_FORWARD_DIRECTION_FACTOR
(
pQueryAttr
->
order
.
order
);
if
(
pQueryAttr
->
interval
.
intervalUnit
!=
'n'
&&
pQueryAttr
->
interval
.
intervalUnit
!=
'y'
)
{
if
(
pQueryAttr
->
interval
.
intervalUnit
!=
'n'
&&
pQueryAttr
->
interval
.
intervalUnit
!=
'y'
)
{
tw
->
skey
+=
pQueryAttr
->
interval
.
sliding
*
factor
;
tw
->
skey
+=
pQueryAttr
->
interval
.
sliding
*
factor
;
...
@@ -198,28 +170,28 @@ static void getNextTimeWindow(SQueryAttr* pQueryAttr, STimeWindow* tw) {
...
@@ -198,28 +170,28 @@ static void getNextTimeWindow(SQueryAttr* pQueryAttr, STimeWindow* tw) {
}
}
static
void
doSetTagValueToResultBuf
(
char
*
output
,
const
char
*
val
,
int16_t
type
,
int16_t
bytes
);
static
void
doSetTagValueToResultBuf
(
char
*
output
,
const
char
*
val
,
int16_t
type
,
int16_t
bytes
);
static
void
setResultOutputBuf
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SQLFunctionCtx
*
pCtx
,
static
void
setResultOutputBuf
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfCols
,
int32_t
*
rowCellInfoOffset
);
int32_t
numOfCols
,
int32_t
*
rowCellInfoOffset
);
void
setResultRowOutputBufInitCtx
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
);
void
setResultRowOutputBufInitCtx
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
);
static
bool
functionNeedToExecute
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
);
static
bool
functionNeedToExecute
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
);
static
void
setBlockStatisInfo
(
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pSDataBlock
,
SColIndex
*
pColIndex
);
static
void
setBlockStatisInfo
(
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pSDataBlock
,
SColIndex
*
pColIndex
);
static
void
destroyTableQueryInfoImpl
(
STableQueryInfo
*
pTableQueryInfo
);
static
void
destroyTableQueryInfoImpl
(
STableQueryInfo
*
pTableQueryInfo
);
static
bool
hasMainOutput
(
S
Query
Attr
*
pQueryAttr
);
static
bool
hasMainOutput
(
S
Task
Attr
*
pQueryAttr
);
static
SColumnInfo
*
extractColumnFilterInfo
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
*
numOfFilterCols
);
static
SColumnInfo
*
extractColumnFilterInfo
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
*
numOfFilterCols
);
static
int32_t
setTimestampListJoinInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SVariant
*
pTag
,
STableQueryInfo
*
pTableQueryInfo
);
static
int32_t
setTimestampListJoinInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SVariant
*
pTag
,
STableQueryInfo
*
pTableQueryInfo
);
static
void
releaseQueryBuf
(
size_t
numOfTables
);
static
void
releaseQueryBuf
(
size_t
numOfTables
);
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
//static STsdbQueryCond createTsdbQueryCond(S
Query
Attr* pQueryAttr, STimeWindow* win);
//static STsdbQueryCond createTsdbQueryCond(S
Task
Attr* pQueryAttr, STimeWindow* win);
static
STableIdInfo
createTableIdInfo
(
STableQueryInfo
*
pTableQueryInfo
);
static
STableIdInfo
createTableIdInfo
(
STableQueryInfo
*
pTableQueryInfo
);
static
void
setTableScanFilterOperatorInfo
(
STableScanInfo
*
pTableScanInfo
,
SOperatorInfo
*
pDownstream
);
static
void
setTableScanFilterOperatorInfo
(
STableScanInfo
*
pTableScanInfo
,
SOperatorInfo
*
pDownstream
);
static
int32_t
getNumOfScanTimes
(
S
Query
Attr
*
pQueryAttr
);
static
int32_t
getNumOfScanTimes
(
S
Task
Attr
*
pQueryAttr
);
static
void
destroyBasicOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroyBasicOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroySFillOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroySFillOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
...
@@ -232,32 +204,34 @@ static void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput);
...
@@ -232,32 +204,34 @@ static void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput);
static
void
destroyAggOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroyAggOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroyOperatorInfo
(
SOperatorInfo
*
pOperator
);
static
void
destroyOperatorInfo
(
SOperatorInfo
*
pOperator
);
void
setTaskStatus
(
STaskInfo
*
pTaskInfo
,
int8_t
status
);
static
void
doSetOperatorCompleted
(
SOperatorInfo
*
pOperator
)
{
static
void
doSetOperatorCompleted
(
SOperatorInfo
*
pOperator
)
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
if
(
pOperator
->
p
RuntimeEnv
!=
NULL
)
{
if
(
pOperator
->
p
TaskInfo
!=
NULL
)
{
set
QueryStatus
(
pOperator
->
pRuntimeEnv
,
QUERY_COMPLETED
);
set
TaskStatus
(
pOperator
->
pTaskInfo
,
QUERY_COMPLETED
);
}
}
}
}
static
int32_t
doCopyToSDataBlock
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
);
static
int32_t
doCopyToSDataBlock
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
);
static
int32_t
getGroupbyColumnIndex
(
SGroupbyExpr
*
pGroupbyExpr
,
SSDataBlock
*
pDataBlock
);
static
int32_t
getGroupbyColumnIndex
(
SGroupbyExpr
*
pGroupbyExpr
,
SSDataBlock
*
pDataBlock
);
static
int32_t
setGroupResultOutputBuf
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binf
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
);
static
int32_t
setGroupResultOutputBuf
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binf
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
);
static
void
initCtxOutputBuffer
(
SQLFunctionCtx
*
pCtx
,
int32_t
size
);
static
void
initCtxOutputBuffer
(
SQLFunctionCtx
*
pCtx
,
int32_t
size
);
static
void
getAlignQueryTimeWindow
(
S
Query
Attr
*
pQueryAttr
,
int64_t
key
,
int64_t
keyFirst
,
int64_t
keyLast
,
STimeWindow
*
win
);
static
void
getAlignQueryTimeWindow
(
S
Task
Attr
*
pQueryAttr
,
int64_t
key
,
int64_t
keyFirst
,
int64_t
keyLast
,
STimeWindow
*
win
);
static
void
setResultBufSize
(
S
Query
Attr
*
pQueryAttr
,
SRspResultInfo
*
pResultInfo
);
static
void
setResultBufSize
(
S
Task
Attr
*
pQueryAttr
,
SRspResultInfo
*
pResultInfo
);
static
void
setCtxTagForJoin
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
void
*
pTable
);
static
void
setCtxTagForJoin
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
void
*
pTable
);
static
void
setParamForStableStddev
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
);
static
void
setParamForStableStddev
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
);
static
void
setParamForStableStddevByColData
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
,
char
*
val
,
int16_t
bytes
);
static
void
setParamForStableStddevByColData
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
,
char
*
val
,
int16_t
bytes
);
static
void
doSetTableGroupOutputBuf
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
static
void
doSetTableGroupOutputBuf
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
tableGroupId
);
SQLFunctionCtx
*
pCtx
,
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
tableGroupId
);
SArray
*
getOrderCheckColumns
(
S
Query
Attr
*
pQuery
);
SArray
*
getOrderCheckColumns
(
S
Task
Attr
*
pQuery
);
typedef
struct
SRowCompSupporter
{
typedef
struct
SRowCompSupporter
{
S
Query
RuntimeEnv
*
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
;
int16_t
dataOffset
;
int16_t
dataOffset
;
__compar_fn_t
comFunc
;
__compar_fn_t
comFunc
;
}
SRowCompSupporter
;
}
SRowCompSupporter
;
...
@@ -267,7 +241,7 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
...
@@ -267,7 +241,7 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
const
SResultRow
*
pRow2
=
(
const
SResultRow
*
)
b
;
const
SResultRow
*
pRow2
=
(
const
SResultRow
*
)
b
;
SRowCompSupporter
*
supporter
=
(
SRowCompSupporter
*
)
userData
;
SRowCompSupporter
*
supporter
=
(
SRowCompSupporter
*
)
userData
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
supporter
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
supporter
->
pRuntimeEnv
;
SFilePage
*
page1
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow1
->
pageId
);
SFilePage
*
page1
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow1
->
pageId
);
SFilePage
*
page2
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow2
->
pageId
);
SFilePage
*
page2
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow2
->
pageId
);
...
@@ -279,7 +253,7 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
...
@@ -279,7 +253,7 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
return
(
in1
!=
NULL
&&
in2
!=
NULL
)
?
supporter
->
comFunc
(
in1
,
in2
)
:
0
;
return
(
in1
!=
NULL
&&
in2
!=
NULL
)
?
supporter
->
comFunc
(
in1
,
in2
)
:
0
;
}
}
static
void
sortGroupResByOrderList
(
SGroupResInfo
*
pGroupResInfo
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pDataBlock
)
{
static
void
sortGroupResByOrderList
(
SGroupResInfo
*
pGroupResInfo
,
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pDataBlock
)
{
SArray
*
columnOrderList
=
getOrderCheckColumns
(
pRuntimeEnv
->
pQueryAttr
);
SArray
*
columnOrderList
=
getOrderCheckColumns
(
pRuntimeEnv
->
pQueryAttr
);
size_t
size
=
taosArrayGetSize
(
columnOrderList
);
size_t
size
=
taosArrayGetSize
(
columnOrderList
);
taosArrayDestroy
(
columnOrderList
);
taosArrayDestroy
(
columnOrderList
);
...
@@ -375,7 +349,7 @@ static bool isSelectivityWithTagsQuery(SQLFunctionCtx *pCtx, int32_t numOfOutput
...
@@ -375,7 +349,7 @@ static bool isSelectivityWithTagsQuery(SQLFunctionCtx *pCtx, int32_t numOfOutput
// return (numOfSelectivity > 0 && hasTags);
// return (numOfSelectivity > 0 && hasTags);
}
}
static
bool
isProjQuery
(
S
Query
Attr
*
pQueryAttr
)
{
static
bool
isProjQuery
(
S
Task
Attr
*
pQueryAttr
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
int32_t
functId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
int32_t
functId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
if
(
functId
!=
FUNCTION_PRJ
&&
functId
!=
FUNCTION_TAGPRJ
)
{
if
(
functId
!=
FUNCTION_PRJ
&&
functId
!=
FUNCTION_TAGPRJ
)
{
...
@@ -398,7 +372,7 @@ static bool hasNull(SColIndex* pColIndex, SColumnDataAgg *pStatis) {
...
@@ -398,7 +372,7 @@ static bool hasNull(SColIndex* pColIndex, SColumnDataAgg *pStatis) {
return
true
;
return
true
;
}
}
static
void
prepareResultListBuffer
(
SResultRowInfo
*
pResultRowInfo
,
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
static
void
prepareResultListBuffer
(
SResultRowInfo
*
pResultRowInfo
,
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
// more than the capacity, reallocate the resources
// more than the capacity, reallocate the resources
if
(
pResultRowInfo
->
size
<
pResultRowInfo
->
capacity
)
{
if
(
pResultRowInfo
->
size
<
pResultRowInfo
->
capacity
)
{
return
;
return
;
...
@@ -424,7 +398,7 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, SQueryRuntim
...
@@ -424,7 +398,7 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, SQueryRuntim
pResultRowInfo
->
capacity
=
(
int32_t
)
newCapacity
;
pResultRowInfo
->
capacity
=
(
int32_t
)
newCapacity
;
}
}
static
bool
chkResultRowFromKey
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
char
*
pData
,
static
bool
chkResultRowFromKey
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
char
*
pData
,
int16_t
bytes
,
bool
masterscan
,
uint64_t
uid
)
{
int16_t
bytes
,
bool
masterscan
,
uint64_t
uid
)
{
bool
existed
=
false
;
bool
existed
=
false
;
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
pData
,
bytes
,
uid
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
pData
,
bytes
,
uid
);
...
@@ -462,7 +436,7 @@ static bool chkResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *p
...
@@ -462,7 +436,7 @@ static bool chkResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *p
}
}
static
SResultRow
*
doSetResultOutBufByKey
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
int64_t
tid
,
static
SResultRow
*
doSetResultOutBufByKey
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
int64_t
tid
,
char
*
pData
,
int16_t
bytes
,
bool
masterscan
,
uint64_t
tableGroupId
)
{
char
*
pData
,
int16_t
bytes
,
bool
masterscan
,
uint64_t
tableGroupId
)
{
bool
existed
=
false
;
bool
existed
=
false
;
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
pData
,
bytes
,
tableGroupId
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
pData
,
bytes
,
tableGroupId
);
...
@@ -536,7 +510,7 @@ static SResultRow* doSetResultOutBufByKey(SQueryRuntimeEnv* pRuntimeEnv, SResult
...
@@ -536,7 +510,7 @@ static SResultRow* doSetResultOutBufByKey(SQueryRuntimeEnv* pRuntimeEnv, SResult
return
pResultRowInfo
->
pResult
[
pResultRowInfo
->
curPos
];
return
pResultRowInfo
->
pResult
[
pResultRowInfo
->
curPos
];
}
}
static
void
getInitialStartTimeWindow
(
S
Query
Attr
*
pQueryAttr
,
TSKEY
ts
,
STimeWindow
*
w
)
{
static
void
getInitialStartTimeWindow
(
S
Task
Attr
*
pQueryAttr
,
TSKEY
ts
,
STimeWindow
*
w
)
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryAttr
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryAttr
))
{
getAlignQueryTimeWindow
(
pQueryAttr
,
ts
,
ts
,
pQueryAttr
->
window
.
ekey
,
w
);
getAlignQueryTimeWindow
(
pQueryAttr
,
ts
,
ts
,
pQueryAttr
->
window
.
ekey
,
w
);
}
else
{
}
else
{
...
@@ -561,7 +535,7 @@ static void getInitialStartTimeWindow(SQueryAttr* pQueryAttr, TSKEY ts, STimeWin
...
@@ -561,7 +535,7 @@ static void getInitialStartTimeWindow(SQueryAttr* pQueryAttr, TSKEY ts, STimeWin
}
}
// get the correct time window according to the handled timestamp
// get the correct time window according to the handled timestamp
static
STimeWindow
getActiveTimeWindow
(
SResultRowInfo
*
pResultRowInfo
,
int64_t
ts
,
S
Query
Attr
*
pQueryAttr
)
{
static
STimeWindow
getActiveTimeWindow
(
SResultRowInfo
*
pResultRowInfo
,
int64_t
ts
,
S
Task
Attr
*
pQueryAttr
)
{
STimeWindow
w
=
{
0
};
STimeWindow
w
=
{
0
};
if
(
pResultRowInfo
->
curPos
==
-
1
)
{
// the first window, from the previous stored value
if
(
pResultRowInfo
->
curPos
==
-
1
)
{
// the first window, from the previous stored value
...
@@ -609,7 +583,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t
...
@@ -609,7 +583,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t
}
}
// get the correct time window according to the handled timestamp
// get the correct time window according to the handled timestamp
static
STimeWindow
getCurrentActiveTimeWindow
(
SResultRowInfo
*
pResultRowInfo
,
int64_t
ts
,
S
Query
Attr
*
pQueryAttr
)
{
static
STimeWindow
getCurrentActiveTimeWindow
(
SResultRowInfo
*
pResultRowInfo
,
int64_t
ts
,
S
Task
Attr
*
pQueryAttr
)
{
STimeWindow
w
=
{
0
};
STimeWindow
w
=
{
0
};
if
(
pResultRowInfo
->
curPos
==
-
1
)
{
// the first window, from the previous stored value
if
(
pResultRowInfo
->
curPos
==
-
1
)
{
// the first window, from the previous stored value
...
@@ -680,14 +654,14 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
...
@@ -680,14 +654,14 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
return
0
;
return
0
;
}
}
static
bool
chkWindowOutputBufByKey
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
STimeWindow
*
win
,
static
bool
chkWindowOutputBufByKey
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
STimeWindow
*
win
,
bool
masterscan
,
SResultRow
**
pResult
,
int64_t
groupId
,
SQLFunctionCtx
*
pCtx
,
bool
masterscan
,
SResultRow
**
pResult
,
int64_t
groupId
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
)
{
int32_t
numOfOutput
,
int32_t
*
rowCellInfoOffset
)
{
assert
(
win
->
skey
<=
win
->
ekey
);
assert
(
win
->
skey
<=
win
->
ekey
);
return
chkResultRowFromKey
(
pRuntimeEnv
,
pResultRowInfo
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
groupId
);
return
chkResultRowFromKey
(
pRuntimeEnv
,
pResultRowInfo
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
groupId
);
}
}
static
int32_t
setResultOutputBufByKey
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
int64_t
tid
,
STimeWindow
*
win
,
static
int32_t
setResultOutputBufByKey
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
int64_t
tid
,
STimeWindow
*
win
,
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
);
...
@@ -816,7 +790,7 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey,
...
@@ -816,7 +790,7 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey,
}
}
}
}
static
void
updateResultRowInfoActiveIndex
(
SResultRowInfo
*
pResultRowInfo
,
S
Query
Attr
*
pQueryAttr
,
TSKEY
lastKey
)
{
static
void
updateResultRowInfoActiveIndex
(
SResultRowInfo
*
pResultRowInfo
,
S
Task
Attr
*
pQueryAttr
,
TSKEY
lastKey
)
{
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
if
((
lastKey
>
pQueryAttr
->
window
.
ekey
&&
ascQuery
)
||
(
lastKey
<
pQueryAttr
->
window
.
ekey
&&
(
!
ascQuery
)))
{
if
((
lastKey
>
pQueryAttr
->
window
.
ekey
&&
ascQuery
)
||
(
lastKey
<
pQueryAttr
->
window
.
ekey
&&
(
!
ascQuery
)))
{
closeAllResultRows
(
pResultRowInfo
);
closeAllResultRows
(
pResultRowInfo
);
...
@@ -827,10 +801,10 @@ static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, SQuer
...
@@ -827,10 +801,10 @@ static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, SQuer
}
}
}
}
static
int32_t
getNumOfRowsInTimeWindow
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
pPrimaryColumn
,
static
int32_t
getNumOfRowsInTimeWindow
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
pPrimaryColumn
,
int32_t
startPos
,
TSKEY
ekey
,
__block_search_fn_t
searchFn
,
bool
updateLastKey
)
{
int32_t
startPos
,
TSKEY
ekey
,
__block_search_fn_t
searchFn
,
bool
updateLastKey
)
{
assert
(
startPos
>=
0
&&
startPos
<
pDataBlockInfo
->
rows
);
assert
(
startPos
>=
0
&&
startPos
<
pDataBlockInfo
->
rows
);
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
int32_t
num
=
-
1
;
int32_t
num
=
-
1
;
...
@@ -867,9 +841,9 @@ static int32_t getNumOfRowsInTimeWindow(SQueryRuntimeEnv* pRuntimeEnv, SDataBloc
...
@@ -867,9 +841,9 @@ static int32_t getNumOfRowsInTimeWindow(SQueryRuntimeEnv* pRuntimeEnv, SDataBloc
return
num
;
return
num
;
}
}
static
void
doApplyFunctions
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
STimeWindow
*
pWin
,
int32_t
offset
,
static
void
doApplyFunctions
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
STimeWindow
*
pWin
,
int32_t
offset
,
int32_t
forwardStep
,
TSKEY
*
tsCol
,
int32_t
numOfTotal
,
int32_t
numOfOutput
)
{
int32_t
forwardStep
,
TSKEY
*
tsCol
,
int32_t
numOfTotal
,
int32_t
numOfOutput
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
bool
hasAggregates
=
pCtx
[
0
].
isAggSet
;
bool
hasAggregates
=
pCtx
[
0
].
isAggSet
;
for
(
int32_t
k
=
0
;
k
<
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
numOfOutput
;
++
k
)
{
...
@@ -904,7 +878,7 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
...
@@ -904,7 +878,7 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
}
}
}
}
static
int32_t
getNextQualifiedWindow
(
S
Query
Attr
*
pQueryAttr
,
STimeWindow
*
pNext
,
SDataBlockInfo
*
pDataBlockInfo
,
static
int32_t
getNextQualifiedWindow
(
S
Task
Attr
*
pQueryAttr
,
STimeWindow
*
pNext
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
primaryKeys
,
__block_search_fn_t
searchFn
,
int32_t
prevPosition
)
{
TSKEY
*
primaryKeys
,
__block_search_fn_t
searchFn
,
int32_t
prevPosition
)
{
getNextTimeWindow
(
pQueryAttr
,
pNext
);
getNextTimeWindow
(
pQueryAttr
,
pNext
);
...
@@ -983,7 +957,7 @@ static int32_t getNextQualifiedWindow(SQueryAttr* pQueryAttr, STimeWindow* pNext
...
@@ -983,7 +957,7 @@ static int32_t getNextQualifiedWindow(SQueryAttr* pQueryAttr, STimeWindow* pNext
return
startPos
;
return
startPos
;
}
}
static
FORCE_INLINE
TSKEY
reviseWindowEkey
(
S
Query
Attr
*
pQueryAttr
,
STimeWindow
*
pWindow
)
{
static
FORCE_INLINE
TSKEY
reviseWindowEkey
(
S
Task
Attr
*
pQueryAttr
,
STimeWindow
*
pWindow
)
{
TSKEY
ekey
=
-
1
;
TSKEY
ekey
=
-
1
;
if
(
QUERY_IS_ASC_QUERY
(
pQueryAttr
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryAttr
))
{
ekey
=
pWindow
->
ekey
;
ekey
=
pWindow
->
ekey
;
...
@@ -1012,20 +986,20 @@ static void setNotInterpoWindowKey(SQLFunctionCtx* pCtx, int32_t numOfOutput, in
...
@@ -1012,20 +986,20 @@ static void setNotInterpoWindowKey(SQLFunctionCtx* pCtx, int32_t numOfOutput, in
}
}
}
}
static
void
saveDataBlockLastRow
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
SArray
*
pDataBlock
,
static
void
saveDataBlockLastRow
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
SArray
*
pDataBlock
,
int32_t
rowIndex
)
{
int32_t
rowIndex
)
{
if
(
pDataBlock
==
NULL
)
{
if
(
pDataBlock
==
NULL
)
{
return
;
return
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
for
(
int32_t
k
=
0
;
k
<
pQueryAttr
->
numOfCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQueryAttr
->
numOfCols
;
++
k
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
k
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
k
);
memcpy
(
pRuntimeEnv
->
prevRow
[
k
],
((
char
*
)
pColInfo
->
pData
)
+
(
pColInfo
->
info
.
bytes
*
rowIndex
),
pColInfo
->
info
.
bytes
);
memcpy
(
pRuntimeEnv
->
prevRow
[
k
],
((
char
*
)
pColInfo
->
pData
)
+
(
pColInfo
->
info
.
bytes
*
rowIndex
),
pColInfo
->
info
.
bytes
);
}
}
}
}
static
TSKEY
getStartTsKey
(
S
Query
Attr
*
pQueryAttr
,
STimeWindow
*
win
,
const
TSKEY
*
tsCols
,
int32_t
rows
)
{
static
TSKEY
getStartTsKey
(
S
Task
Attr
*
pQueryAttr
,
STimeWindow
*
win
,
const
TSKEY
*
tsCols
,
int32_t
rows
)
{
TSKEY
ts
=
TSKEY_INITIAL_VAL
;
TSKEY
ts
=
TSKEY_INITIAL_VAL
;
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
...
@@ -1126,7 +1100,7 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx,
...
@@ -1126,7 +1100,7 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx,
}
}
static
void
doAggregateImpl
(
SOperatorInfo
*
pOperator
,
TSKEY
startTs
,
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pSDataBlock
)
{
static
void
doAggregateImpl
(
SOperatorInfo
*
pOperator
,
TSKEY
startTs
,
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pSDataBlock
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
for
(
int32_t
k
=
0
;
k
<
pOperator
->
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pOperator
->
numOfOutput
;
++
k
)
{
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
]))
{
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
]))
{
...
@@ -1136,8 +1110,8 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SQLFunction
...
@@ -1136,8 +1110,8 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SQLFunction
}
}
}
}
static
void
projectApplyFunctions
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
static
void
projectApplyFunctions
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
for
(
int32_t
k
=
0
;
k
<
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
numOfOutput
;
++
k
)
{
pCtx
[
k
].
startTs
=
pQueryAttr
->
window
.
skey
;
pCtx
[
k
].
startTs
=
pQueryAttr
->
window
.
skey
;
...
@@ -1161,7 +1135,7 @@ static void projectApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx
...
@@ -1161,7 +1135,7 @@ static void projectApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx
void
doTimeWindowInterpolation
(
SOperatorInfo
*
pOperator
,
SOptrBasicInfo
*
pInfo
,
SArray
*
pDataBlock
,
TSKEY
prevTs
,
void
doTimeWindowInterpolation
(
SOperatorInfo
*
pOperator
,
SOptrBasicInfo
*
pInfo
,
SArray
*
pDataBlock
,
TSKEY
prevTs
,
int32_t
prevRowIndex
,
TSKEY
curTs
,
int32_t
curRowIndex
,
TSKEY
windowKey
,
int32_t
type
)
{
int32_t
prevRowIndex
,
TSKEY
curTs
,
int32_t
curRowIndex
,
TSKEY
windowKey
,
int32_t
type
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
SExprInfo
*
pExpr
=
pOperator
->
pExpr
;
SExprInfo
*
pExpr
=
pOperator
->
pExpr
;
SQLFunctionCtx
*
pCtx
=
pInfo
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pInfo
->
pCtx
;
...
@@ -1226,8 +1200,8 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
...
@@ -1226,8 +1200,8 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
static
bool
setTimeWindowInterpolationStartTs
(
SOperatorInfo
*
pOperatorInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
pos
,
static
bool
setTimeWindowInterpolationStartTs
(
SOperatorInfo
*
pOperatorInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
pos
,
int32_t
numOfRows
,
SArray
*
pDataBlock
,
const
TSKEY
*
tsCols
,
STimeWindow
*
win
)
{
int32_t
numOfRows
,
SArray
*
pDataBlock
,
const
TSKEY
*
tsCols
,
STimeWindow
*
win
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
...
@@ -1257,8 +1231,8 @@ static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SQLF
...
@@ -1257,8 +1231,8 @@ static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SQLF
static
bool
setTimeWindowInterpolationEndTs
(
SOperatorInfo
*
pOperatorInfo
,
SQLFunctionCtx
*
pCtx
,
static
bool
setTimeWindowInterpolationEndTs
(
SOperatorInfo
*
pOperatorInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
endRowIndex
,
SArray
*
pDataBlock
,
const
TSKEY
*
tsCols
,
TSKEY
blockEkey
,
STimeWindow
*
win
)
{
int32_t
endRowIndex
,
SArray
*
pDataBlock
,
const
TSKEY
*
tsCols
,
TSKEY
blockEkey
,
STimeWindow
*
win
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfOutput
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfOutput
;
TSKEY
actualEndKey
=
tsCols
[
endRowIndex
];
TSKEY
actualEndKey
=
tsCols
[
endRowIndex
];
...
@@ -1289,8 +1263,8 @@ static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SQLFun
...
@@ -1289,8 +1263,8 @@ static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SQLFun
static
void
doWindowBorderInterpolation
(
SOperatorInfo
*
pOperatorInfo
,
SSDataBlock
*
pBlock
,
SQLFunctionCtx
*
pCtx
,
static
void
doWindowBorderInterpolation
(
SOperatorInfo
*
pOperatorInfo
,
SSDataBlock
*
pBlock
,
SQLFunctionCtx
*
pCtx
,
SResultRow
*
pResult
,
STimeWindow
*
win
,
int32_t
startPos
,
int32_t
forwardStep
)
{
SResultRow
*
pResult
,
STimeWindow
*
win
,
int32_t
startPos
,
int32_t
forwardStep
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
if
(
!
pQueryAttr
->
timeWindowInterpo
)
{
if
(
!
pQueryAttr
->
timeWindowInterpo
)
{
return
;
return
;
}
}
...
@@ -1340,9 +1314,9 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc
...
@@ -1340,9 +1314,9 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc
static
void
hashIntervalAgg
(
SOperatorInfo
*
pOperatorInfo
,
SResultRowInfo
*
pResultRowInfo
,
SSDataBlock
*
pSDataBlock
,
int32_t
tableGroupId
)
{
static
void
hashIntervalAgg
(
SOperatorInfo
*
pOperatorInfo
,
SResultRowInfo
*
pResultRowInfo
,
SSDataBlock
*
pSDataBlock
,
int32_t
tableGroupId
)
{
STableIntervalOperatorInfo
*
pInfo
=
(
STableIntervalOperatorInfo
*
)
pOperatorInfo
->
info
;
STableIntervalOperatorInfo
*
pInfo
=
(
STableIntervalOperatorInfo
*
)
pOperatorInfo
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfOutput
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfOutput
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQueryAttr
->
order
.
order
);
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQueryAttr
->
order
.
order
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
...
@@ -1361,7 +1335,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
...
@@ -1361,7 +1335,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
TSKEY
ts
=
getStartTsKey
(
pQueryAttr
,
&
pSDataBlock
->
info
.
window
,
tsCols
,
pSDataBlock
->
info
.
rows
);
TSKEY
ts
=
getStartTsKey
(
pQueryAttr
,
&
pSDataBlock
->
info
.
window
,
tsCols
,
pSDataBlock
->
info
.
rows
);
STimeWindow
win
=
getActiveTimeWindow
(
pResultRowInfo
,
ts
,
pQueryAttr
);
STimeWindow
win
=
getActiveTimeWindow
(
pResultRowInfo
,
ts
,
pQueryAttr
);
bool
masterScan
=
IS_MA
STER
_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MA
IN
_SCAN
(
pRuntimeEnv
);
SResultRow
*
pResult
=
NULL
;
SResultRow
*
pResult
=
NULL
;
int32_t
ret
=
setResultOutputBufByKey
(
pRuntimeEnv
,
pResultRowInfo
,
pSDataBlock
->
info
.
uid
,
&
win
,
masterScan
,
&
pResult
,
tableGroupId
,
pInfo
->
pCtx
,
int32_t
ret
=
setResultOutputBufByKey
(
pRuntimeEnv
,
pResultRowInfo
,
pSDataBlock
->
info
.
uid
,
&
win
,
masterScan
,
&
pResult
,
tableGroupId
,
pInfo
->
pCtx
,
...
@@ -1450,9 +1424,9 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
...
@@ -1450,9 +1424,9 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
static
void
hashAllIntervalAgg
(
SOperatorInfo
*
pOperatorInfo
,
SResultRowInfo
*
pResultRowInfo
,
SSDataBlock
*
pSDataBlock
,
int32_t
tableGroupId
)
{
static
void
hashAllIntervalAgg
(
SOperatorInfo
*
pOperatorInfo
,
SResultRowInfo
*
pResultRowInfo
,
SSDataBlock
*
pSDataBlock
,
int32_t
tableGroupId
)
{
STableIntervalOperatorInfo
*
pInfo
=
(
STableIntervalOperatorInfo
*
)
pOperatorInfo
->
info
;
STableIntervalOperatorInfo
*
pInfo
=
(
STableIntervalOperatorInfo
*
)
pOperatorInfo
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfOutput
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfOutput
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQueryAttr
->
order
.
order
);
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQueryAttr
->
order
.
order
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
...
@@ -1469,7 +1443,7 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe
...
@@ -1469,7 +1443,7 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe
TSKEY
ts
=
getStartTsKey
(
pQueryAttr
,
&
pSDataBlock
->
info
.
window
,
tsCols
,
pSDataBlock
->
info
.
rows
);
TSKEY
ts
=
getStartTsKey
(
pQueryAttr
,
&
pSDataBlock
->
info
.
window
,
tsCols
,
pSDataBlock
->
info
.
rows
);
STimeWindow
win
=
getCurrentActiveTimeWindow
(
pResultRowInfo
,
ts
,
pQueryAttr
);
STimeWindow
win
=
getCurrentActiveTimeWindow
(
pResultRowInfo
,
ts
,
pQueryAttr
);
bool
masterScan
=
IS_MA
STER
_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MA
IN
_SCAN
(
pRuntimeEnv
);
SResultRow
*
pResult
=
NULL
;
SResultRow
*
pResult
=
NULL
;
int32_t
forwardStep
=
0
;
int32_t
forwardStep
=
0
;
...
@@ -1525,12 +1499,12 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe
...
@@ -1525,12 +1499,12 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe
static
void
doHashGroupbyAgg
(
SOperatorInfo
*
pOperator
,
SGroupbyOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
static
void
doHashGroupbyAgg
(
SOperatorInfo
*
pOperator
,
SGroupbyOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
pInfo
->
colIndex
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
pInfo
->
colIndex
);
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int16_t
bytes
=
pColInfoData
->
info
.
bytes
;
int16_t
bytes
=
pColInfoData
->
info
.
bytes
;
int16_t
type
=
pColInfoData
->
info
.
type
;
int16_t
type
=
pColInfoData
->
info
.
type
;
...
@@ -1607,13 +1581,13 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
...
@@ -1607,13 +1581,13 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
}
}
static
void
doSessionWindowAggImpl
(
SOperatorInfo
*
pOperator
,
SSWindowOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
static
void
doSessionWindowAggImpl
(
SOperatorInfo
*
pOperator
,
SSWindowOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
// primary timestamp column
// primary timestamp column
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
0
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
0
);
bool
masterScan
=
IS_MA
STER
_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MA
IN
_SCAN
(
pRuntimeEnv
);
SOptrBasicInfo
*
pBInfo
=
&
pInfo
->
binfo
;
SOptrBasicInfo
*
pBInfo
=
&
pInfo
->
binfo
;
int64_t
gap
=
pOperator
->
pRuntimeEnv
->
pQueryAttr
->
sw
.
gap
;
int64_t
gap
=
pOperator
->
pRuntimeEnv
->
pQueryAttr
->
sw
.
gap
;
...
@@ -1692,7 +1666,7 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) {
...
@@ -1692,7 +1666,7 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) {
}
}
}
}
static
int32_t
setGroupResultOutputBuf
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binfo
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
)
{
static
int32_t
setGroupResultOutputBuf
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
binfo
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
)
{
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
int32_t
*
rowCellInfoOffset
=
binfo
->
rowCellInfoOffset
;
int32_t
*
rowCellInfoOffset
=
binfo
->
rowCellInfoOffset
;
...
@@ -1746,9 +1720,9 @@ static int32_t getGroupbyColumnIndex(SGroupbyExpr *pGroupbyExpr, SSDataBlock* pD
...
@@ -1746,9 +1720,9 @@ static int32_t getGroupbyColumnIndex(SGroupbyExpr *pGroupbyExpr, SSDataBlock* pD
return
-
1
;
return
-
1
;
}
}
static
bool
functionNeedToExecute
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
)
{
static
bool
functionNeedToExecute
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
)
{
struct
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
struct
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
// in case of timestamp column, always generated results.
// in case of timestamp column, always generated results.
int32_t
functionId
=
pCtx
->
functionId
;
int32_t
functionId
=
pCtx
->
functionId
;
...
@@ -1843,9 +1817,9 @@ static int32_t setCtxTagColumnInfo(SQLFunctionCtx *pCtx, int32_t numOfOutput) {
...
@@ -1843,9 +1817,9 @@ static int32_t setCtxTagColumnInfo(SQLFunctionCtx *pCtx, int32_t numOfOutput) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
SQLFunctionCtx
*
createSQLFunctionCtx
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
static
SQLFunctionCtx
*
createSQLFunctionCtx
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
**
rowCellInfoOffset
)
{
int32_t
**
rowCellInfoOffset
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SQLFunctionCtx
*
pFuncCtx
=
(
SQLFunctionCtx
*
)
calloc
(
numOfOutput
,
sizeof
(
SQLFunctionCtx
));
SQLFunctionCtx
*
pFuncCtx
=
(
SQLFunctionCtx
*
)
calloc
(
numOfOutput
,
sizeof
(
SQLFunctionCtx
));
if
(
pFuncCtx
==
NULL
)
{
if
(
pFuncCtx
==
NULL
)
{
...
@@ -1965,9 +1939,9 @@ static void* destroySQLFunctionCtx(SQLFunctionCtx* pCtx, int32_t numOfOutput) {
...
@@ -1965,9 +1939,9 @@ static void* destroySQLFunctionCtx(SQLFunctionCtx* pCtx, int32_t numOfOutput) {
return
NULL
;
return
NULL
;
}
}
static
int32_t
setupQueryRuntimeEnv
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int32_t
numOfTables
,
SArray
*
pOperator
,
void
*
merger
)
{
static
int32_t
setupQueryRuntimeEnv
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int32_t
numOfTables
,
SArray
*
pOperator
,
void
*
merger
)
{
//qDebug("QInfo:0x%"PRIx64" setup runtime env", GET_QID(pRuntimeEnv));
//qDebug("QInfo:0x%"PRIx64" setup runtime env", GET_QID(pRuntimeEnv));
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
pRuntimeEnv
->
prevGroupId
=
INT32_MIN
;
pRuntimeEnv
->
prevGroupId
=
INT32_MIN
;
pRuntimeEnv
->
pQueryAttr
=
pQueryAttr
;
pRuntimeEnv
->
pQueryAttr
=
pQueryAttr
;
...
@@ -2019,30 +1993,30 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
...
@@ -2019,30 +1993,30 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
// case OP_MultiTableTimeInterval: {
// case OP_MultiTableTimeInterval: {
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// break;
// break;
// }
// }
// case OP_AllMultiTableTimeInterval: {
// case OP_AllMultiTableTimeInterval: {
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createAllMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createAllMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// break;
// break;
// }
// }
// case OP_TimeWindow: {
// case OP_TimeWindow: {
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->
up
stream[0]->operatorType;
// int32_t opType = pRuntimeEnv->proot->
down
stream[0]->operatorType;
// if (opType != OP_DummyInput && opType != OP_Join) {
// if (opType != OP_DummyInput && opType != OP_Join) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// }
// }
// break;
// break;
// }
// }
// case OP_AllTimeWindow: {
// case OP_AllTimeWindow: {
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createAllTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createAllTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->
up
stream[0]->operatorType;
// int32_t opType = pRuntimeEnv->proot->
down
stream[0]->operatorType;
// if (opType != OP_DummyInput && opType != OP_Join) {
// if (opType != OP_DummyInput && opType != OP_Join) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// }
// }
// break;
// break;
// }
// }
...
@@ -2050,34 +2024,34 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
...
@@ -2050,34 +2024,34 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createGroupbyOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createGroupbyOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
//
//
// int32_t opType = pRuntimeEnv->proot->
up
stream[0]->operatorType;
// int32_t opType = pRuntimeEnv->proot->
down
stream[0]->operatorType;
// if (opType != OP_DummyInput) {
// if (opType != OP_DummyInput) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// }
// }
// break;
// break;
// }
// }
// case OP_SessionWindow: {
// case OP_SessionWindow: {
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createSWindowOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createSWindowOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->
up
stream[0]->operatorType;
// int32_t opType = pRuntimeEnv->proot->
down
stream[0]->operatorType;
// if (opType != OP_DummyInput) {
// if (opType != OP_DummyInput) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// }
// }
// break;
// break;
// }
// }
// case OP_MultiTableAggregate: {
// case OP_MultiTableAggregate: {
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createMultiTableAggOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createMultiTableAggOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// break;
// break;
// }
// }
// case OP_Aggregate: {
// case OP_Aggregate: {
// pRuntimeEnv->proot =
// pRuntimeEnv->proot =
// createAggregateOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// createAggregateOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
//
//
// int32_t opType = pRuntimeEnv->proot->
up
stream[0]->operatorType;
// int32_t opType = pRuntimeEnv->proot->
down
stream[0]->operatorType;
// if (opType != OP_DummyInput && opType != OP_Join) {
// if (opType != OP_DummyInput && opType != OP_Join) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// }
// }
// break;
// break;
// }
// }
...
@@ -2099,9 +2073,9 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
...
@@ -2099,9 +2073,9 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
//
//
// case OP_StateWindow: {
// case OP_StateWindow: {
// pRuntimeEnv->proot = createStatewindowOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// pRuntimeEnv->proot = createStatewindowOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
// int32_t opType = pRuntimeEnv->proot->
up
stream[0]->operatorType;
// int32_t opType = pRuntimeEnv->proot->
down
stream[0]->operatorType;
// if (opType != OP_DummyInput) {
// if (opType != OP_DummyInput) {
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
up
stream[0]->info, pRuntimeEnv->proot);
// setTableScanFilterOperatorInfo(pRuntimeEnv->proot->
down
stream[0]->info, pRuntimeEnv->proot);
// }
// }
// break;
// break;
// }
// }
...
@@ -2187,8 +2161,8 @@ _clean:
...
@@ -2187,8 +2161,8 @@ _clean:
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
}
static
void
doFreeQueryHandle
(
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
static
void
doFreeQueryHandle
(
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
// tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle);
// tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle);
pRuntimeEnv
->
pQueryHandle
=
NULL
;
pRuntimeEnv
->
pQueryHandle
=
NULL
;
...
@@ -2197,7 +2171,7 @@ static void doFreeQueryHandle(SQueryRuntimeEnv* pRuntimeEnv) {
...
@@ -2197,7 +2171,7 @@ static void doFreeQueryHandle(SQueryRuntimeEnv* pRuntimeEnv) {
// assert(pMemRef->ref == 0 && pMemRef->snapshot.imem == NULL && pMemRef->snapshot.mem == NULL);
// assert(pMemRef->ref == 0 && pMemRef->snapshot.imem == NULL && pMemRef->snapshot.mem == NULL);
}
}
static
void
destroyTsComp
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SQuery
Attr
*
pQueryAttr
)
{
static
void
destroyTsComp
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
STask
Attr
*
pQueryAttr
)
{
if
(
pQueryAttr
->
tsCompQuery
&&
pRuntimeEnv
->
outputBuf
&&
pRuntimeEnv
->
outputBuf
->
pDataBlock
&&
taosArrayGetSize
(
pRuntimeEnv
->
outputBuf
->
pDataBlock
)
>
0
)
{
if
(
pQueryAttr
->
tsCompQuery
&&
pRuntimeEnv
->
outputBuf
&&
pRuntimeEnv
->
outputBuf
->
pDataBlock
&&
taosArrayGetSize
(
pRuntimeEnv
->
outputBuf
->
pDataBlock
)
>
0
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pRuntimeEnv
->
outputBuf
->
pDataBlock
,
0
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pRuntimeEnv
->
outputBuf
->
pDataBlock
,
0
);
if
(
pColInfoData
)
{
if
(
pColInfoData
)
{
...
@@ -2210,8 +2184,8 @@ static void destroyTsComp(SQueryRuntimeEnv *pRuntimeEnv, SQueryAttr *pQueryAttr)
...
@@ -2210,8 +2184,8 @@ static void destroyTsComp(SQueryRuntimeEnv *pRuntimeEnv, SQueryAttr *pQueryAttr)
}
}
}
}
static
void
teardownQueryRuntimeEnv
(
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
static
void
teardownQueryRuntimeEnv
(
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SQInfo
*
pQInfo
=
(
SQInfo
*
)
pRuntimeEnv
->
qinfo
;
SQInfo
*
pQInfo
=
(
SQInfo
*
)
pRuntimeEnv
->
qinfo
;
//qDebug("QInfo:0x%"PRIx64" teardown runtime env", pQInfo->qId);
//qDebug("QInfo:0x%"PRIx64" teardown runtime env", pQInfo->qId);
...
@@ -2271,7 +2245,7 @@ bool isQueryKilled(SQInfo *pQInfo) {
...
@@ -2271,7 +2245,7 @@ bool isQueryKilled(SQInfo *pQInfo) {
void
setQueryKilled
(
SQInfo
*
pQInfo
)
{
pQInfo
->
code
=
TSDB_CODE_TSC_QUERY_CANCELLED
;}
void
setQueryKilled
(
SQInfo
*
pQInfo
)
{
pQInfo
->
code
=
TSDB_CODE_TSC_QUERY_CANCELLED
;}
//static bool isFixedOutputQuery(S
Query
Attr* pQueryAttr) {
//static bool isFixedOutputQuery(S
Task
Attr* pQueryAttr) {
// if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) {
// if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) {
// return false;
// return false;
// }
// }
...
@@ -2297,7 +2271,7 @@ void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELL
...
@@ -2297,7 +2271,7 @@ void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELL
//}
//}
// todo refactor with isLastRowQuery
// todo refactor with isLastRowQuery
//bool isPointInterpoQuery(S
Query
Attr *pQueryAttr) {
//bool isPointInterpoQuery(S
Task
Attr *pQueryAttr) {
// for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
// for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
// int32_t functionId = pQueryAttr->pExpr1[i].base.functionId;
// int32_t functionId = pQueryAttr->pExpr1[i].base.functionId;
// if (functionId == FUNCTION_INTERP) {
// if (functionId == FUNCTION_INTERP) {
...
@@ -2308,7 +2282,7 @@ void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELL
...
@@ -2308,7 +2282,7 @@ void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELL
// return false;
// return false;
//}
//}
static
bool
isFirstLastRowQuery
(
S
Query
Attr
*
pQueryAttr
)
{
static
bool
isFirstLastRowQuery
(
S
Task
Attr
*
pQueryAttr
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
int32_t
functionID
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
int32_t
functionID
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
if
(
functionID
==
FUNCTION_LAST_ROW
)
{
if
(
functionID
==
FUNCTION_LAST_ROW
)
{
...
@@ -2319,7 +2293,7 @@ static bool isFirstLastRowQuery(SQueryAttr *pQueryAttr) {
...
@@ -2319,7 +2293,7 @@ static bool isFirstLastRowQuery(SQueryAttr *pQueryAttr) {
return
false
;
return
false
;
}
}
static
bool
isCachedLastQuery
(
S
Query
Attr
*
pQueryAttr
)
{
static
bool
isCachedLastQuery
(
S
Task
Attr
*
pQueryAttr
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
if
(
functionId
==
FUNCTION_LAST
||
functionId
==
FUNCTION_LAST_DST
)
{
if
(
functionId
==
FUNCTION_LAST
||
functionId
==
FUNCTION_LAST_DST
)
{
...
@@ -2354,7 +2328,7 @@ static bool isCachedLastQuery(SQueryAttr *pQueryAttr) {
...
@@ -2354,7 +2328,7 @@ static bool isCachedLastQuery(SQueryAttr *pQueryAttr) {
* The following 4 kinds of query are treated as the tags query
* The following 4 kinds of query are treated as the tags query
* tagprj, tid_tag query, count(tbname), 'abc' (user defined constant value column) query
* tagprj, tid_tag query, count(tbname), 'abc' (user defined constant value column) query
*/
*/
bool
onlyQueryTags
(
S
Query
Attr
*
pQueryAttr
)
{
bool
onlyQueryTags
(
S
Task
Attr
*
pQueryAttr
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
SExprInfo
*
pExprInfo
=
&
pQueryAttr
->
pExpr1
[
i
];
SExprInfo
*
pExprInfo
=
&
pQueryAttr
->
pExpr1
[
i
];
...
@@ -2373,7 +2347,7 @@ bool onlyQueryTags(SQueryAttr* pQueryAttr) {
...
@@ -2373,7 +2347,7 @@ bool onlyQueryTags(SQueryAttr* pQueryAttr) {
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
void
getAlignQueryTimeWindow
(
S
Query
Attr
*
pQueryAttr
,
int64_t
key
,
int64_t
keyFirst
,
int64_t
keyLast
,
STimeWindow
*
win
)
{
void
getAlignQueryTimeWindow
(
S
Task
Attr
*
pQueryAttr
,
int64_t
key
,
int64_t
keyFirst
,
int64_t
keyLast
,
STimeWindow
*
win
)
{
assert
(
key
>=
keyFirst
&&
key
<=
keyLast
&&
pQueryAttr
->
interval
.
sliding
<=
pQueryAttr
->
interval
.
interval
);
assert
(
key
>=
keyFirst
&&
key
<=
keyLast
&&
pQueryAttr
->
interval
.
sliding
<=
pQueryAttr
->
interval
.
interval
);
win
->
skey
=
taosTimeTruncate
(
key
,
&
pQueryAttr
->
interval
,
pQueryAttr
->
precision
);
win
->
skey
=
taosTimeTruncate
(
key
,
&
pQueryAttr
->
interval
,
pQueryAttr
->
precision
);
...
@@ -2394,7 +2368,7 @@ void getAlignQueryTimeWindow(SQueryAttr *pQueryAttr, int64_t key, int64_t keyFir
...
@@ -2394,7 +2368,7 @@ void getAlignQueryTimeWindow(SQueryAttr *pQueryAttr, int64_t key, int64_t keyFir
/*
/*
* todo add more parameters to check soon..
* todo add more parameters to check soon..
*/
*/
bool
colIdCheck
(
S
Query
Attr
*
pQueryAttr
,
uint64_t
qId
)
{
bool
colIdCheck
(
S
Task
Attr
*
pQueryAttr
,
uint64_t
qId
)
{
// load data column information is incorrect
// load data column information is incorrect
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfCols
-
1
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfCols
-
1
;
++
i
)
{
if
(
pQueryAttr
->
tableCols
[
i
].
colId
==
pQueryAttr
->
tableCols
[
i
+
1
].
colId
)
{
if
(
pQueryAttr
->
tableCols
[
i
].
colId
==
pQueryAttr
->
tableCols
[
i
+
1
].
colId
)
{
...
@@ -2408,7 +2382,7 @@ bool colIdCheck(SQueryAttr *pQueryAttr, uint64_t qId) {
...
@@ -2408,7 +2382,7 @@ bool colIdCheck(SQueryAttr *pQueryAttr, uint64_t qId) {
// todo ignore the avg/sum/min/max/count/stddev/top/bottom functions, of which
// todo ignore the avg/sum/min/max/count/stddev/top/bottom functions, of which
// the scan order is not matter
// the scan order is not matter
static
bool
onlyOneQueryType
(
S
Query
Attr
*
pQueryAttr
,
int32_t
functId
,
int32_t
functIdDst
)
{
static
bool
onlyOneQueryType
(
S
Task
Attr
*
pQueryAttr
,
int32_t
functId
,
int32_t
functIdDst
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
...
@@ -2425,13 +2399,13 @@ static bool onlyOneQueryType(SQueryAttr *pQueryAttr, int32_t functId, int32_t fu
...
@@ -2425,13 +2399,13 @@ static bool onlyOneQueryType(SQueryAttr *pQueryAttr, int32_t functId, int32_t fu
return
true
;
return
true
;
}
}
static
bool
onlyFirstQuery
(
S
Query
Attr
*
pQueryAttr
)
{
return
onlyOneQueryType
(
pQueryAttr
,
FUNCTION_FIRST
,
FUNCTION_FIRST_DST
);
}
static
bool
onlyFirstQuery
(
S
Task
Attr
*
pQueryAttr
)
{
return
onlyOneQueryType
(
pQueryAttr
,
FUNCTION_FIRST
,
FUNCTION_FIRST_DST
);
}
static
bool
onlyLastQuery
(
S
Query
Attr
*
pQueryAttr
)
{
return
onlyOneQueryType
(
pQueryAttr
,
FUNCTION_LAST
,
FUNCTION_LAST_DST
);
}
static
bool
onlyLastQuery
(
S
Task
Attr
*
pQueryAttr
)
{
return
onlyOneQueryType
(
pQueryAttr
,
FUNCTION_LAST
,
FUNCTION_LAST_DST
);
}
static
bool
notContainSessionOrStateWindow
(
S
Query
Attr
*
pQueryAttr
)
{
return
!
(
pQueryAttr
->
sw
.
gap
>
0
||
pQueryAttr
->
stateWindow
);
}
static
bool
notContainSessionOrStateWindow
(
S
Task
Attr
*
pQueryAttr
)
{
return
!
(
pQueryAttr
->
sw
.
gap
>
0
||
pQueryAttr
->
stateWindow
);
}
static
int32_t
updateBlockLoadStatus
(
S
Query
Attr
*
pQuery
,
int32_t
status
)
{
static
int32_t
updateBlockLoadStatus
(
S
Task
Attr
*
pQuery
,
int32_t
status
)
{
bool
hasFirstLastFunc
=
false
;
bool
hasFirstLastFunc
=
false
;
bool
hasOtherFunc
=
false
;
bool
hasOtherFunc
=
false
;
...
@@ -2465,7 +2439,7 @@ static int32_t updateBlockLoadStatus(SQueryAttr *pQuery, int32_t status) {
...
@@ -2465,7 +2439,7 @@ static int32_t updateBlockLoadStatus(SQueryAttr *pQuery, int32_t status) {
return
status
;
return
status
;
}
}
static
void
doUpdateLastKey
(
S
Query
Attr
*
pQueryAttr
)
{
static
void
doUpdateLastKey
(
S
Task
Attr
*
pQueryAttr
)
{
STimeWindow
*
win
=
&
pQueryAttr
->
window
;
STimeWindow
*
win
=
&
pQueryAttr
->
window
;
size_t
num
=
taosArrayGetSize
(
pQueryAttr
->
tableGroupInfo
.
pGroupList
);
size_t
num
=
taosArrayGetSize
(
pQueryAttr
->
tableGroupInfo
.
pGroupList
);
...
@@ -2485,7 +2459,7 @@ static void doUpdateLastKey(SQueryAttr* pQueryAttr) {
...
@@ -2485,7 +2459,7 @@ static void doUpdateLastKey(SQueryAttr* pQueryAttr) {
}
}
static
void
updateDataCheckOrder
(
SQInfo
*
pQInfo
,
SQueryTableMsg
*
pQueryMsg
,
bool
stableQuery
)
{
static
void
updateDataCheckOrder
(
SQInfo
*
pQInfo
,
SQueryTableMsg
*
pQueryMsg
,
bool
stableQuery
)
{
S
Query
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
// in case of point-interpolation query, use asc order scan
// in case of point-interpolation query, use asc order scan
char
msg
[]
=
"QInfo:0x%"
PRIx64
" scan order changed for %s query, old:%d, new:%d, qrange exchanged, old qrange:%"
PRId64
char
msg
[]
=
"QInfo:0x%"
PRIx64
" scan order changed for %s query, old:%d, new:%d, qrange exchanged, old qrange:%"
PRId64
...
@@ -2580,8 +2554,8 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
...
@@ -2580,8 +2554,8 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
}
}
}
}
static
void
getIntermediateBufInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int32_t
*
ps
,
int32_t
*
rowsize
)
{
static
void
getIntermediateBufInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int32_t
*
ps
,
int32_t
*
rowsize
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
MIN_ROWS_PER_PAGE
=
4
;
int32_t
MIN_ROWS_PER_PAGE
=
4
;
*
rowsize
=
(
int32_t
)(
pQueryAttr
->
resultRowSize
*
getRowNumForMultioutput
(
pQueryAttr
,
pQueryAttr
->
topBotQuery
,
pQueryAttr
->
stableQuery
));
*
rowsize
=
(
int32_t
)(
pQueryAttr
->
resultRowSize
*
getRowNumForMultioutput
(
pQueryAttr
,
pQueryAttr
->
topBotQuery
,
pQueryAttr
->
stableQuery
));
...
@@ -2596,8 +2570,8 @@ static void getIntermediateBufInfo(SQueryRuntimeEnv* pRuntimeEnv, int32_t* ps, i
...
@@ -2596,8 +2570,8 @@ static void getIntermediateBufInfo(SQueryRuntimeEnv* pRuntimeEnv, int32_t* ps, i
#define IS_PREFILTER_TYPE(_t) ((_t) != TSDB_DATA_TYPE_BINARY && (_t) != TSDB_DATA_TYPE_NCHAR)
#define IS_PREFILTER_TYPE(_t) ((_t) != TSDB_DATA_TYPE_BINARY && (_t) != TSDB_DATA_TYPE_NCHAR)
//static FORCE_INLINE bool doFilterByBlockStatistics(S
Query
RuntimeEnv* pRuntimeEnv, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx, int32_t numOfRows) {
//static FORCE_INLINE bool doFilterByBlockStatistics(S
Task
RuntimeEnv* pRuntimeEnv, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx, int32_t numOfRows) {
// S
Query
Attr* pQueryAttr = pRuntimeEnv->pQueryAttr;
// S
Task
Attr* pQueryAttr = pRuntimeEnv->pQueryAttr;
//
//
// if (pDataStatis == NULL || pQueryAttr->pFilters == NULL) {
// if (pDataStatis == NULL || pQueryAttr->pFilters == NULL) {
// return true;
// return true;
...
@@ -2606,7 +2580,7 @@ static void getIntermediateBufInfo(SQueryRuntimeEnv* pRuntimeEnv, int32_t* ps, i
...
@@ -2606,7 +2580,7 @@ static void getIntermediateBufInfo(SQueryRuntimeEnv* pRuntimeEnv, int32_t* ps, i
// return filterRangeExecute(pQueryAttr->pFilters, pDataStatis, pQueryAttr->numOfCols, numOfRows);
// return filterRangeExecute(pQueryAttr->pFilters, pDataStatis, pQueryAttr->numOfCols, numOfRows);
//}
//}
static
bool
overlapWithTimeWindow
(
S
Query
Attr
*
pQueryAttr
,
SDataBlockInfo
*
pBlockInfo
)
{
static
bool
overlapWithTimeWindow
(
S
Task
Attr
*
pQueryAttr
,
SDataBlockInfo
*
pBlockInfo
)
{
STimeWindow
w
=
{
0
};
STimeWindow
w
=
{
0
};
TSKEY
sk
=
MIN
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
);
TSKEY
sk
=
MIN
(
pQueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
);
...
@@ -2655,7 +2629,7 @@ static bool overlapWithTimeWindow(SQueryAttr* pQueryAttr, SDataBlockInfo* pBlock
...
@@ -2655,7 +2629,7 @@ static bool overlapWithTimeWindow(SQueryAttr* pQueryAttr, SDataBlockInfo* pBlock
return
false
;
return
false
;
}
}
static
int32_t
doTSJoinFilter
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
TSKEY
key
,
bool
ascQuery
)
{
static
int32_t
doTSJoinFilter
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
TSKEY
key
,
bool
ascQuery
)
{
STSElem
elem
=
tsBufGetElem
(
pRuntimeEnv
->
pTsBuf
);
STSElem
elem
=
tsBufGetElem
(
pRuntimeEnv
->
pTsBuf
);
#if defined(_DEBUG_VIEW)
#if defined(_DEBUG_VIEW)
...
@@ -2781,7 +2755,7 @@ void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p) {
...
@@ -2781,7 +2755,7 @@ void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p) {
}
}
}
}
void
filterRowsInDataBlock
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
,
void
filterRowsInDataBlock
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
,
SSDataBlock
*
pBlock
,
bool
ascQuery
)
{
SSDataBlock
*
pBlock
,
bool
ascQuery
)
{
int32_t
numOfRows
=
pBlock
->
info
.
rows
;
int32_t
numOfRows
=
pBlock
->
info
.
rows
;
...
@@ -2823,7 +2797,7 @@ void filterRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInf
...
@@ -2823,7 +2797,7 @@ void filterRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInf
tfree
(
p
);
tfree
(
p
);
}
}
void
filterColRowsInDataBlock
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pBlock
,
bool
ascQuery
)
{
void
filterColRowsInDataBlock
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pBlock
,
bool
ascQuery
)
{
int32_t
numOfRows
=
pBlock
->
info
.
rows
;
int32_t
numOfRows
=
pBlock
->
info
.
rows
;
int8_t
*
p
=
NULL
;
int8_t
*
p
=
NULL
;
...
@@ -2913,22 +2887,35 @@ void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFi
...
@@ -2913,22 +2887,35 @@ void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFi
}
}
}
}
int32_t
loadDataBlockOnDemand
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
,
int32_t
loadDataBlock
(
STaskInfo
*
pTaskInfo
,
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
,
uint32_t
*
status
)
{
uint32_t
*
status
)
{
STaskCostInfo
*
pCost
=
&
pTaskInfo
->
cost
;
pCost
->
totalBlocks
+=
1
;
pCost
->
totalRows
+=
pBlock
->
info
.
rows
;
pCost
->
totalCheckedRows
+=
pBlock
->
info
.
rows
;
pCost
->
loadBlocks
+=
1
;
// pBlock->pDataBlock = tsdbRetrieveDataBlock(pTableScanInfo->pQueryHandle, NULL);
if
(
pBlock
->
pDataBlock
==
NULL
)
{
return
terrno
;
}
}
int32_t
loadDataBlockOnDemand
(
STaskInfo
*
pTaskInfo
,
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
,
uint32_t
*
status
)
{
*
status
=
BLK_DATA_NO_NEEDED
;
*
status
=
BLK_DATA_NO_NEEDED
;
pBlock
->
pDataBlock
=
NULL
;
pBlock
->
pBlockAgg
=
NULL
;
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
pBlock
->
pDataBlock
=
NULL
;
int64_t
groupId
=
pRuntimeEnv
->
current
->
groupIndex
;
pBlock
->
pBlockAgg
=
NULL
;
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
// int64_t groupId = pRuntimeEnv->current->groupIndex;
// bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr);
SQInfo
*
pQInfo
=
pRuntimeEnv
->
qinfo
;
STaskCostInfo
*
pCost
=
&
pTaskInfo
->
cost
;
SQueryCostInfo
*
pCost
=
&
pQInfo
->
summary
;
pCost
->
totalBlocks
+=
1
;
pCost
->
totalBlocks
+=
1
;
pCost
->
totalRows
+=
pBlock
->
info
.
rows
;
pCost
->
totalRows
+=
pBlock
->
info
.
rows
;
#if 0
if (pRuntimeEnv->pTsBuf != NULL) {
if (pRuntimeEnv->pTsBuf != NULL) {
(*status) = BLK_DATA_ALL_NEEDED;
(*status) = BLK_DATA_ALL_NEEDED;
...
@@ -2953,7 +2940,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
...
@@ -2953,7 +2940,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
// Calculate all time windows that are overlapping or contain current data block.
// Calculate all time windows that are overlapping or contain current data block.
// If current data block is contained by all possible time window, do not load current data block.
// If current data block is contained by all possible time window, do not load current data block.
if (/*pQueryAttr->pFilters || */pQueryAttr->groupbyColumn || pQueryAttr->sw.gap > 0 ||
if (/*pQueryAttr->pFilters || */pQueryAttr->groupbyColumn || pQueryAttr->sw.gap > 0 ||
(
QUERY_IS_INTERVAL_QUERY
(
pQueryAttr
)
&&
overlapWithTimeWindow
(
p
QueryAttr
,
&
pBlock
->
info
)))
{
(QUERY_IS_INTERVAL_QUERY(pQueryAttr) && overlapWithTimeWindow(p
TaskInfo
, &pBlock->info))) {
(*status) = BLK_DATA_ALL_NEEDED;
(*status) = BLK_DATA_ALL_NEEDED;
}
}
...
@@ -2966,7 +2953,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
...
@@ -2966,7 +2953,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) {
if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) {
SResultRow* pResult = NULL;
SResultRow* pResult = NULL;
bool
masterScan
=
IS_MA
STER
_SCAN
(
pRuntimeEnv
);
bool masterScan = IS_MA
IN
_SCAN(pRuntimeEnv);
TSKEY k = ascQuery? pBlock->info.window.skey : pBlock->info.window.ekey;
TSKEY k = ascQuery? pBlock->info.window.skey : pBlock->info.window.ekey;
STimeWindow win = getActiveTimeWindow(pTableScanInfo->pResultRowInfo, k, pQueryAttr);
STimeWindow win = getActiveTimeWindow(pTableScanInfo->pResultRowInfo, k, pQueryAttr);
...
@@ -2995,7 +2982,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
...
@@ -2995,7 +2982,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
}
}
SDataBlockInfo* pBlockInfo = &pBlock->info;
SDataBlockInfo* pBlockInfo = &pBlock->info;
*
status
=
updateBlockLoadStatus
(
pRuntimeEnv
->
pQueryAttr
,
*
status
);
//
*status = updateBlockLoadStatus(pRuntimeEnv->pQueryAttr, *status);
if ((*status) == BLK_DATA_NO_NEEDED || (*status) == BLK_DATA_DISCARD) {
if ((*status) == BLK_DATA_NO_NEEDED || (*status) == BLK_DATA_DISCARD) {
//qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId, pBlockInfo->window.skey,
//qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId, pBlockInfo->window.skey,
...
@@ -3022,7 +3009,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
...
@@ -3022,7 +3009,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) {
if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) {
SResultRow* pResult = NULL;
SResultRow* pResult = NULL;
bool
masterScan
=
IS_MA
STER
_SCAN
(
pRuntimeEnv
);
bool masterScan = IS_MA
IN
_SCAN(pRuntimeEnv);
TSKEY k = ascQuery? pBlock->info.window.skey : pBlock->info.window.ekey;
TSKEY k = ascQuery? pBlock->info.window.skey : pBlock->info.window.ekey;
STimeWindow win = getActiveTimeWindow(pTableScanInfo->pResultRowInfo, k, pQueryAttr);
STimeWindow win = getActiveTimeWindow(pTableScanInfo->pResultRowInfo, k, pQueryAttr);
...
@@ -3074,7 +3061,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
...
@@ -3074,7 +3061,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
// filterColRowsInDataBlock(pRuntimeEnv, pBlock, ascQuery);
// filterColRowsInDataBlock(pRuntimeEnv, pBlock, ascQuery);
// }
// }
}
}
#endif
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -3184,10 +3171,10 @@ static SColumnInfo* doGetTagColumnInfoById(SColumnInfo* pTagColList, int32_t num
...
@@ -3184,10 +3171,10 @@ static SColumnInfo* doGetTagColumnInfoById(SColumnInfo* pTagColList, int32_t num
}
}
void
setTagValue
(
SOperatorInfo
*
pOperatorInfo
,
void
*
pTable
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
void
setTagValue
(
SOperatorInfo
*
pOperatorInfo
,
void
*
pTable
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
SExprInfo
*
pExpr
=
pOperatorInfo
->
pExpr
;
SExprInfo
*
pExpr
=
pOperatorInfo
->
pExpr
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SExprInfo
*
pExprInfo
=
&
pExpr
[
0
];
SExprInfo
*
pExprInfo
=
&
pExpr
[
0
];
int32_t
functionId
=
getExprFunctionId
(
pExprInfo
);
int32_t
functionId
=
getExprFunctionId
(
pExprInfo
);
...
@@ -3242,7 +3229,7 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt
...
@@ -3242,7 +3229,7 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt
}
}
}
}
void
copyToSDataBlock
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int32_t
threshold
,
SSDataBlock
*
pBlock
,
int32_t
*
offset
)
{
void
copyToSDataBlock
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int32_t
threshold
,
SSDataBlock
*
pBlock
,
int32_t
*
offset
)
{
SGroupResInfo
*
pGroupResInfo
=
&
pRuntimeEnv
->
groupResInfo
;
SGroupResInfo
*
pGroupResInfo
=
&
pRuntimeEnv
->
groupResInfo
;
pBlock
->
info
.
rows
=
0
;
pBlock
->
info
.
rows
=
0
;
...
@@ -3293,9 +3280,8 @@ static void updateTableQueryInfoForReverseScan(STableQueryInfo *pTableQueryInfo)
...
@@ -3293,9 +3280,8 @@ static void updateTableQueryInfoForReverseScan(STableQueryInfo *pTableQueryInfo)
}
}
}
}
static
void
setupQueryRangeForReverseScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
static
void
setupQueryRangeForReverseScan
(
STableScanInfo
*
pTableScanInfo
)
{
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
#if 0
int32_t numOfGroups = (int32_t)(GET_NUM_OF_TABLEGROUP(pRuntimeEnv));
int32_t numOfGroups = (int32_t)(GET_NUM_OF_TABLEGROUP(pRuntimeEnv));
for(int32_t i = 0; i < numOfGroups; ++i) {
for(int32_t i = 0; i < numOfGroups; ++i) {
SArray *group = GET_TABLEGROUP(pRuntimeEnv, i);
SArray *group = GET_TABLEGROUP(pRuntimeEnv, i);
...
@@ -3314,6 +3300,8 @@ static void setupQueryRangeForReverseScan(SQueryRuntimeEnv* pRuntimeEnv) {
...
@@ -3314,6 +3300,8 @@ static void setupQueryRangeForReverseScan(SQueryRuntimeEnv* pRuntimeEnv) {
// assert(pCheckInfo->pTable == pTableKeyInfo->pTable);
// assert(pCheckInfo->pTable == pTableKeyInfo->pTable);
}
}
}
}
#endif
}
}
void
switchCtxOrder
(
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
void
switchCtxOrder
(
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
...
@@ -3337,7 +3325,7 @@ int32_t initResultRow(SResultRow *pResultRow) {
...
@@ -3337,7 +3325,7 @@ int32_t initResultRow(SResultRow *pResultRow) {
* +------------+-------------------------------------------+-------------------------------------------+
* +------------+-------------------------------------------+-------------------------------------------+
* offset[0] offset[1] offset[2]
* offset[0] offset[1] offset[2]
*/
*/
void
setDefaultOutputBuf
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int64_t
uid
,
int32_t
stage
)
{
void
setDefaultOutputBuf
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int64_t
uid
,
int32_t
stage
)
{
SQLFunctionCtx
*
pCtx
=
pInfo
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pInfo
->
pCtx
;
SSDataBlock
*
pDataBlock
=
pInfo
->
pRes
;
SSDataBlock
*
pDataBlock
=
pInfo
->
pRes
;
int32_t
*
rowCellInfoOffset
=
pInfo
->
rowCellInfoOffset
;
int32_t
*
rowCellInfoOffset
=
pInfo
->
rowCellInfoOffset
;
...
@@ -3461,40 +3449,38 @@ void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size) {
...
@@ -3461,40 +3449,38 @@ void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size) {
}
}
}
}
void
set
QueryStatus
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int8_t
status
)
{
void
set
TaskStatus
(
STaskInfo
*
pTaskInfo
,
int8_t
status
)
{
if
(
status
==
QUERY_NOT_COMPLETED
)
{
if
(
status
==
QUERY_NOT_COMPLETED
)
{
p
RuntimeEnv
->
status
=
status
;
p
TaskInfo
->
status
=
status
;
}
else
{
}
else
{
// QUERY_NOT_COMPLETED is not compatible with any other status, so clear its position first
// QUERY_NOT_COMPLETED is not compatible with any other status, so clear its position first
CLEAR_QUERY_STATUS
(
p
RuntimeEnv
,
QUERY_NOT_COMPLETED
);
CLEAR_QUERY_STATUS
(
p
TaskInfo
,
QUERY_NOT_COMPLETED
);
p
RuntimeEnv
->
status
|=
status
;
p
TaskInfo
->
status
|=
status
;
}
}
}
}
static
void
setupEnvForReverseScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
static
void
setupEnvForReverseScan
(
STableScanInfo
*
pTableScanInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
// if (pRuntimeEnv->pTsBuf) {
// SWITCH_ORDER(pRuntimeEnv->pTsBuf->cur.order);
if
(
pRuntimeEnv
->
pTsBuf
)
{
// bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf);
SWITCH_ORDER
(
pRuntimeEnv
->
pTsBuf
->
cur
.
order
);
// assert(ret);
bool
ret
=
tsBufNextPos
(
pRuntimeEnv
->
pTsBuf
);
// }
assert
(
ret
);
}
// reverse order time range
// reverse order time range
SWAP
(
p
QueryAttr
->
window
.
skey
,
pQueryAttr
->
window
.
ekey
,
TSKEY
);
SWAP
(
p
TableScanInfo
->
window
.
skey
,
pTableScanInfo
->
window
.
ekey
,
TSKEY
);
SET_REVERSE_SCAN_FLAG
(
p
RuntimeEnv
);
SET_REVERSE_SCAN_FLAG
(
p
TableScanInfo
);
setQueryStatus
(
pRuntimeEnv
,
QUERY_NOT_COMPLETED
);
// setTaskStatus(pTableScanInfo
, QUERY_NOT_COMPLETED);
switchCtxOrder
(
pCtx
,
numOfOutput
);
switchCtxOrder
(
pCtx
,
numOfOutput
);
SWITCH_ORDER
(
pQueryAttr
->
order
.
order
);
setupQueryRangeForReverseScan
(
pRuntimeEnv
);
SWITCH_ORDER
(
pTableScanInfo
->
order
);
setupQueryRangeForReverseScan
(
pTableScanInfo
);
}
}
void
finalizeQueryResult
(
SOperatorInfo
*
pOperator
,
SQLFunctionCtx
*
pCtx
,
SResultRowInfo
*
pResultRowInfo
,
int32_t
*
rowCellInfoOffset
)
{
void
finalizeQueryResult
(
SOperatorInfo
*
pOperator
,
SQLFunctionCtx
*
pCtx
,
SResultRowInfo
*
pResultRowInfo
,
int32_t
*
rowCellInfoOffset
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
numOfOutput
=
pOperator
->
numOfOutput
;
int32_t
numOfOutput
=
pOperator
->
numOfOutput
;
if
(
pQueryAttr
->
groupbyColumn
||
QUERY_IS_INTERVAL_QUERY
(
pQueryAttr
)
||
pQueryAttr
->
sw
.
gap
>
0
||
pQueryAttr
->
stateWindow
)
{
if
(
pQueryAttr
->
groupbyColumn
||
QUERY_IS_INTERVAL_QUERY
(
pQueryAttr
)
||
pQueryAttr
->
sw
.
gap
>
0
||
pQueryAttr
->
stateWindow
)
{
...
@@ -3539,7 +3525,7 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResult
...
@@ -3539,7 +3525,7 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResult
}
}
}
}
static
bool
hasMainOutput
(
S
Query
Attr
*
pQueryAttr
)
{
static
bool
hasMainOutput
(
S
Task
Attr
*
pQueryAttr
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
...
@@ -3551,7 +3537,7 @@ static bool hasMainOutput(SQueryAttr *pQueryAttr) {
...
@@ -3551,7 +3537,7 @@ static bool hasMainOutput(SQueryAttr *pQueryAttr) {
return
false
;
return
false
;
}
}
STableQueryInfo
*
createTableQueryInfo
(
S
Query
Attr
*
pQueryAttr
,
void
*
pTable
,
bool
groupbyColumn
,
STimeWindow
win
,
void
*
buf
)
{
STableQueryInfo
*
createTableQueryInfo
(
S
Task
Attr
*
pQueryAttr
,
void
*
pTable
,
bool
groupbyColumn
,
STimeWindow
win
,
void
*
buf
)
{
STableQueryInfo
*
pTableQueryInfo
=
buf
;
STableQueryInfo
*
pTableQueryInfo
=
buf
;
pTableQueryInfo
->
win
=
win
;
pTableQueryInfo
->
win
=
win
;
...
@@ -3602,7 +3588,7 @@ void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo) {
...
@@ -3602,7 +3588,7 @@ void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo) {
cleanupResultRowInfo
(
&
pTableQueryInfo
->
resInfo
);
cleanupResultRowInfo
(
&
pTableQueryInfo
->
resInfo
);
}
}
void
setResultRowOutputBufInitCtx
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SQLFunctionCtx
*
pCtx
,
void
setResultRowOutputBufInitCtx
(
S
Task
RuntimeEnv
*
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
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
SFilePage
*
bufPage
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
...
@@ -3635,7 +3621,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
...
@@ -3635,7 +3621,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
}
}
}
}
void
doSetTableGroupOutputBuf
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
void
doSetTableGroupOutputBuf
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
tableGroupId
)
{
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
tableGroupId
)
{
// 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
;
...
@@ -3659,7 +3645,7 @@ void doSetTableGroupOutputBuf(SQueryRuntimeEnv* pRuntimeEnv, SResultRowInfo* pRe
...
@@ -3659,7 +3645,7 @@ void doSetTableGroupOutputBuf(SQueryRuntimeEnv* pRuntimeEnv, SResultRowInfo* pRe
setResultRowOutputBufInitCtx
(
pRuntimeEnv
,
pResultRow
,
pCtx
,
numOfOutput
,
rowCellInfoOffset
);
setResultRowOutputBufInitCtx
(
pRuntimeEnv
,
pResultRow
,
pCtx
,
numOfOutput
,
rowCellInfoOffset
);
}
}
void
setExecutionContext
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int32_t
numOfOutput
,
int32_t
tableGroupId
,
void
setExecutionContext
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int32_t
numOfOutput
,
int32_t
tableGroupId
,
TSKEY
nextKey
)
{
TSKEY
nextKey
)
{
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
...
@@ -3675,7 +3661,7 @@ void setExecutionContext(SQueryRuntimeEnv* pRuntimeEnv, SOptrBasicInfo* pInfo, i
...
@@ -3675,7 +3661,7 @@ void setExecutionContext(SQueryRuntimeEnv* pRuntimeEnv, SOptrBasicInfo* pInfo, i
pRuntimeEnv
->
prevGroupId
=
tableGroupId
;
pRuntimeEnv
->
prevGroupId
=
tableGroupId
;
}
}
void
setResultOutputBuf
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SQLFunctionCtx
*
pCtx
,
void
setResultOutputBuf
(
S
Task
RuntimeEnv
*
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
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
SFilePage
*
page
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
...
@@ -3698,8 +3684,8 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF
...
@@ -3698,8 +3684,8 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF
}
}
}
}
void
setCtxTagForJoin
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
void
*
pTable
)
{
void
setCtxTagForJoin
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
void
*
pTable
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SSqlExpr
*
pExpr
=
&
pExprInfo
->
base
;
SSqlExpr
*
pExpr
=
&
pExprInfo
->
base
;
// if (pQueryAttr->stableQuery && (pRuntimeEnv->pTsBuf != NULL) &&
// if (pQueryAttr->stableQuery && (pRuntimeEnv->pTsBuf != NULL) &&
...
@@ -3723,8 +3709,8 @@ void setCtxTagForJoin(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx, SExpr
...
@@ -3723,8 +3709,8 @@ void setCtxTagForJoin(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx, SExpr
// }
// }
}
}
int32_t
setTimestampListJoinInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SVariant
*
pTag
,
STableQueryInfo
*
pTableQueryInfo
)
{
int32_t
setTimestampListJoinInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SVariant
*
pTag
,
STableQueryInfo
*
pTableQueryInfo
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
assert
(
pRuntimeEnv
->
pTsBuf
!=
NULL
);
assert
(
pRuntimeEnv
->
pTsBuf
!=
NULL
);
...
@@ -3766,9 +3752,9 @@ int32_t setTimestampListJoinInfo(SQueryRuntimeEnv* pRuntimeEnv, SVariant* pTag,
...
@@ -3766,9 +3752,9 @@ int32_t setTimestampListJoinInfo(SQueryRuntimeEnv* pRuntimeEnv, SVariant* pTag,
}
}
// TODO refactor: this funciton should be merged with setparamForStableStddevColumnData function.
// TODO refactor: this funciton should be merged with setparamForStableStddevColumnData function.
void
setParamForStableStddev
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExprInfo
)
{
void
setParamForStableStddev
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExprInfo
)
{
#if 0
#if 0
S
Query
Attr* pQueryAttr = pRuntimeEnv->pQueryAttr;
S
Task
Attr* pQueryAttr = pRuntimeEnv->pQueryAttr;
int32_t numOfExprs = pQueryAttr->numOfOutput;
int32_t numOfExprs = pQueryAttr->numOfOutput;
for(int32_t i = 0; i < numOfExprs; ++i) {
for(int32_t i = 0; i < numOfExprs; ++i) {
...
@@ -3801,8 +3787,8 @@ void setParamForStableStddev(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
...
@@ -3801,8 +3787,8 @@ void setParamForStableStddev(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
#endif
#endif
}
}
void
setParamForStableStddevByColData
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
,
char
*
val
,
int16_t
bytes
)
{
void
setParamForStableStddevByColData
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
,
char
*
val
,
int16_t
bytes
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
#if 0
#if 0
int32_t numOfExprs = pQueryAttr->numOfOutput;
int32_t numOfExprs = pQueryAttr->numOfOutput;
for(int32_t i = 0; i < numOfExprs; ++i) {
for(int32_t i = 0; i < numOfExprs; ++i) {
...
@@ -3842,8 +3828,8 @@ void setParamForStableStddevByColData(SQueryRuntimeEnv* pRuntimeEnv, SQLFunction
...
@@ -3842,8 +3828,8 @@ void setParamForStableStddevByColData(SQueryRuntimeEnv* pRuntimeEnv, SQLFunction
* merged during merge stage. In this case, we need the pTableQueryInfo->lastResRows to decide if there
* merged during merge stage. In this case, we need the pTableQueryInfo->lastResRows to decide if there
* is a previous result generated or not.
* is a previous result generated or not.
*/
*/
void
setIntervalQueryRange
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
TSKEY
key
)
{
void
setIntervalQueryRange
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
TSKEY
key
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
SResultRowInfo
*
pResultRowInfo
=
&
pTableQueryInfo
->
resInfo
;
SResultRowInfo
*
pResultRowInfo
=
&
pTableQueryInfo
->
resInfo
;
...
@@ -3887,8 +3873,8 @@ void setIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key) {
...
@@ -3887,8 +3873,8 @@ void setIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key) {
* @param result
* @param result
*/
*/
static
int32_t
doCopyToSDataBlock
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
)
{
static
int32_t
doCopyToSDataBlock
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
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
...
@@ -3946,7 +3932,7 @@ static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo*
...
@@ -3946,7 +3932,7 @@ static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo*
return
0
;
return
0
;
}
}
static
void
toSSDataBlock
(
SGroupResInfo
*
pGroupResInfo
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pBlock
)
{
static
void
toSSDataBlock
(
SGroupResInfo
*
pGroupResInfo
,
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pBlock
)
{
assert
(
pGroupResInfo
->
currentGroup
<=
pGroupResInfo
->
totalGroup
);
assert
(
pGroupResInfo
->
currentGroup
<=
pGroupResInfo
->
totalGroup
);
pBlock
->
info
.
rows
=
0
;
pBlock
->
info
.
rows
=
0
;
...
@@ -3954,7 +3940,7 @@ static void toSSDataBlock(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv* pRunti
...
@@ -3954,7 +3940,7 @@ static void toSSDataBlock(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv* pRunti
return
;
return
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
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
(
pRuntimeEnv
,
pGroupResInfo
,
orderType
,
pBlock
);
...
@@ -3969,9 +3955,9 @@ static void toSSDataBlock(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv* pRunti
...
@@ -3969,9 +3955,9 @@ static void toSSDataBlock(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv* pRunti
}
}
}
}
static
void
updateNumOfRowsInResultRows
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
static
void
updateNumOfRowsInResultRows
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SResultRowInfo
*
pResultRowInfo
,
int32_t
*
rowCellInfoOffset
)
{
SResultRowInfo
*
pResultRowInfo
,
int32_t
*
rowCellInfoOffset
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
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
))
{
...
@@ -4000,8 +3986,8 @@ static int32_t compressQueryColData(SColumnInfoData *pColRes, int32_t numOfRows,
...
@@ -4000,8 +3986,8 @@ static int32_t compressQueryColData(SColumnInfoData *pColRes, int32_t numOfRows,
}
}
static
void
doCopyQueryResultToMsg
(
SQInfo
*
pQInfo
,
int32_t
numOfRows
,
char
*
data
,
int8_t
compressed
,
int32_t
*
compLen
)
{
static
void
doCopyQueryResultToMsg
(
SQInfo
*
pQInfo
,
int32_t
numOfRows
,
char
*
data
,
int8_t
compressed
,
int32_t
*
compLen
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SSDataBlock
*
pRes
=
pRuntimeEnv
->
outputBuf
;
SSDataBlock
*
pRes
=
pRuntimeEnv
->
outputBuf
;
...
@@ -4070,7 +4056,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
...
@@ -4070,7 +4056,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
// Check if query is completed or not for stable query or normal table query respectively.
// Check if query is completed or not for stable query or normal table query respectively.
if
(
Q_STATUS_EQUAL
(
pRuntimeEnv
->
status
,
QUERY_COMPLETED
)
&&
pRuntimeEnv
->
proot
->
status
==
OP_EXEC_DONE
)
{
if
(
Q_STATUS_EQUAL
(
pRuntimeEnv
->
status
,
QUERY_COMPLETED
)
&&
pRuntimeEnv
->
proot
->
status
==
OP_EXEC_DONE
)
{
setQueryStatus
(
pRuntimeEnv
,
QUERY_OVER
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_OVER);
}
}
}
}
...
@@ -4187,8 +4173,8 @@ void calculateOperatorProfResults(SQInfo* pQInfo) {
...
@@ -4187,8 +4173,8 @@ void calculateOperatorProfResults(SQInfo* pQInfo) {
}
}
void
queryCostStatis
(
SQInfo
*
pQInfo
)
{
void
queryCostStatis
(
SQInfo
*
pQInfo
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Query
CostInfo
*
pSummary
=
&
pQInfo
->
summary
;
S
Task
CostInfo
*
pSummary
=
&
pQInfo
->
summary
;
uint64_t
hashSize
=
taosHashGetMemSize
(
pQInfo
->
runtimeEnv
.
pResultRowHashTable
);
uint64_t
hashSize
=
taosHashGetMemSize
(
pQInfo
->
runtimeEnv
.
pResultRowHashTable
);
hashSize
+=
taosHashGetMemSize
(
pRuntimeEnv
->
tableqinfoGroupInfo
.
map
);
hashSize
+=
taosHashGetMemSize
(
pRuntimeEnv
->
tableqinfoGroupInfo
.
map
);
...
@@ -4226,8 +4212,8 @@ void queryCostStatis(SQInfo *pQInfo) {
...
@@ -4226,8 +4212,8 @@ void queryCostStatis(SQInfo *pQInfo) {
}
}
}
}
//static void updateOffsetVal(S
Query
RuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) {
//static void updateOffsetVal(S
Task
RuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) {
// S
Query
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// S
Task
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current;
// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current;
//
//
// int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order);
// int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order);
...
@@ -4262,8 +4248,8 @@ void queryCostStatis(SQInfo *pQInfo) {
...
@@ -4262,8 +4248,8 @@ void queryCostStatis(SQInfo *pQInfo) {
// pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows, numOfRes, pQuery->current->lastKey);
// pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows, numOfRes, pQuery->current->lastKey);
//}
//}
//void skipBlocks(S
Query
RuntimeEnv *pRuntimeEnv) {
//void skipBlocks(S
Task
RuntimeEnv *pRuntimeEnv) {
// S
Query
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// S
Task
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
//
//
// if (pQueryAttr->limit.offset <= 0 || pQueryAttr->numOfFilterCols > 0) {
// if (pQueryAttr->limit.offset <= 0 || pQueryAttr->numOfFilterCols > 0) {
// return;
// return;
...
@@ -4301,8 +4287,8 @@ void queryCostStatis(SQInfo *pQInfo) {
...
@@ -4301,8 +4287,8 @@ void queryCostStatis(SQInfo *pQInfo) {
// }
// }
//}
//}
//static TSKEY doSkipIntervalProcess(S
Query
RuntimeEnv* pRuntimeEnv, STimeWindow* win, SDataBlockInfo* pBlockInfo, STableQueryInfo* pTableQueryInfo) {
//static TSKEY doSkipIntervalProcess(S
Task
RuntimeEnv* pRuntimeEnv, STimeWindow* win, SDataBlockInfo* pBlockInfo, STableQueryInfo* pTableQueryInfo) {
// S
Query
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// S
Task
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// SResultRowInfo *pWindowResInfo = &pRuntimeEnv->resultRowInfo;
// SResultRowInfo *pWindowResInfo = &pRuntimeEnv->resultRowInfo;
//
//
// assert(pQueryAttr->limit.offset == 0);
// assert(pQueryAttr->limit.offset == 0);
...
@@ -4352,8 +4338,8 @@ void queryCostStatis(SQInfo *pQInfo) {
...
@@ -4352,8 +4338,8 @@ void queryCostStatis(SQInfo *pQInfo) {
// return true;
// return true;
//}
//}
//static bool skipTimeInterval(S
Query
RuntimeEnv *pRuntimeEnv, TSKEY* start) {
//static bool skipTimeInterval(S
Task
RuntimeEnv *pRuntimeEnv, TSKEY* start) {
// S
Query
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// S
Task
Attr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// if (QUERY_IS_ASC_QUERY(pQueryAttr)) {
// if (QUERY_IS_ASC_QUERY(pQueryAttr)) {
// assert(*start <= pRuntimeEnv->current->lastKey);
// assert(*start <= pRuntimeEnv->current->lastKey);
// } else {
// } else {
...
@@ -4463,18 +4449,18 @@ void queryCostStatis(SQInfo *pQInfo) {
...
@@ -4463,18 +4449,18 @@ void queryCostStatis(SQInfo *pQInfo) {
//}
//}
void
appendUpstream
(
SOperatorInfo
*
p
,
SOperatorInfo
*
pUpstream
)
{
void
appendUpstream
(
SOperatorInfo
*
p
,
SOperatorInfo
*
pUpstream
)
{
if
(
p
->
up
stream
==
NULL
)
{
if
(
p
->
pDown
stream
==
NULL
)
{
assert
(
p
->
numOf
Up
stream
==
0
);
assert
(
p
->
numOf
Down
stream
==
0
);
}
}
p
->
upstream
=
realloc
(
p
->
upstream
,
POINTER_BYTES
*
(
p
->
numOfUp
stream
+
1
));
p
->
pDownstream
=
realloc
(
p
->
pDownstream
,
POINTER_BYTES
*
(
p
->
numOfDown
stream
+
1
));
p
->
upstream
[
p
->
numOfUp
stream
++
]
=
pUpstream
;
p
->
pDownstream
[
p
->
numOfDown
stream
++
]
=
pUpstream
;
}
}
static
void
doDestroyTableQueryInfo
(
STableGroupInfo
*
pTableqinfoGroupInfo
);
static
void
doDestroyTableQueryInfo
(
STableGroupInfo
*
pTableqinfoGroupInfo
);
static
int32_t
setupQueryHandle
(
void
*
tsdb
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int64_t
qId
,
bool
isSTableQuery
)
{
static
int32_t
setupQueryHandle
(
void
*
tsdb
,
S
Task
RuntimeEnv
*
pRuntimeEnv
,
int64_t
qId
,
bool
isSTableQuery
)
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
#if 0
#if 0
// TODO set the tags scan handle
// TODO set the tags scan handle
if (onlyQueryTags(pQueryAttr)) {
if (onlyQueryTags(pQueryAttr)) {
...
@@ -4533,9 +4519,9 @@ static int32_t setupQueryHandle(void* tsdb, SQueryRuntimeEnv* pRuntimeEnv, int64
...
@@ -4533,9 +4519,9 @@ static int32_t setupQueryHandle(void* tsdb, SQueryRuntimeEnv* pRuntimeEnv, int64
int32_t
doInitQInfo
(
SQInfo
*
pQInfo
,
STSBuf
*
pTsBuf
,
void
*
tsdb
,
void
*
sourceOptr
,
int32_t
tbScanner
,
SArray
*
pOperator
,
int32_t
doInitQInfo
(
SQInfo
*
pQInfo
,
STSBuf
*
pTsBuf
,
void
*
tsdb
,
void
*
sourceOptr
,
int32_t
tbScanner
,
SArray
*
pOperator
,
void
*
param
)
{
void
*
param
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
pQueryAttr
->
tsdb
=
tsdb
;
pQueryAttr
->
tsdb
=
tsdb
;
if
(
tsdb
!=
NULL
)
{
if
(
tsdb
!=
NULL
)
{
...
@@ -4616,25 +4602,25 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
...
@@ -4616,25 +4602,25 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
return
code
;
return
code
;
}
}
setQueryStatus
(
pRuntimeEnv
,
QUERY_NOT_COMPLETED
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_NOT_COMPLETED);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
doTableQueryInfoTimeWindowCheck
(
S
QueryAttr
*
pQueryAttr
,
STableQueryInfo
*
pTableQueryInfo
)
{
static
void
doTableQueryInfoTimeWindowCheck
(
S
TaskInfo
*
pTaskInfo
,
STableQueryInfo
*
pTableQueryInfo
,
int32_t
order
)
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryAttr
)
)
{
if
(
order
==
TSDB_ORDER_ASC
)
{
assert
(
assert
(
(
pTableQueryInfo
->
win
.
skey
<=
pTableQueryInfo
->
win
.
ekey
)
&&
(
pTableQueryInfo
->
win
.
skey
<=
pTableQueryInfo
->
win
.
ekey
)
&&
(
pTableQueryInfo
->
lastKey
>=
pTa
bleQueryInfo
->
win
.
skey
)
&&
(
pTableQueryInfo
->
lastKey
>=
pTa
skInfo
->
window
.
skey
)
&&
(
pTableQueryInfo
->
win
.
skey
>=
p
QueryAttr
->
window
.
skey
&&
pTableQueryInfo
->
win
.
ekey
<=
pQueryAttr
->
window
.
ekey
));
(
pTableQueryInfo
->
win
.
skey
>=
p
TaskInfo
->
window
.
skey
&&
pTableQueryInfo
->
win
.
ekey
<=
pTaskInfo
->
window
.
ekey
));
}
else
{
}
else
{
assert
(
assert
(
(
pTableQueryInfo
->
win
.
skey
>=
pTableQueryInfo
->
win
.
ekey
)
&&
(
pTableQueryInfo
->
win
.
skey
>=
pTableQueryInfo
->
win
.
ekey
)
&&
(
pTableQueryInfo
->
lastKey
<=
pTa
bleQueryInfo
->
win
.
skey
)
&&
(
pTableQueryInfo
->
lastKey
<=
pTa
skInfo
->
window
.
skey
)
&&
(
pTableQueryInfo
->
win
.
skey
<=
p
QueryAttr
->
window
.
skey
&&
pTableQueryInfo
->
win
.
ekey
>=
pQueryAttr
->
window
.
ekey
));
(
pTableQueryInfo
->
win
.
skey
<=
p
TaskInfo
->
window
.
skey
&&
pTableQueryInfo
->
win
.
ekey
>=
pTaskInfo
->
window
.
ekey
));
}
}
}
}
//STsdbQueryCond createTsdbQueryCond(S
Query
Attr* pQueryAttr, STimeWindow* win) {
//STsdbQueryCond createTsdbQueryCond(S
Task
Attr* pQueryAttr, STimeWindow* win) {
// STsdbQueryCond cond = {
// STsdbQueryCond cond = {
// .colList = pQueryAttr->tableCols,
// .colList = pQueryAttr->tableCols,
// .order = pQueryAttr->order.order,
// .order = pQueryAttr->order.order,
...
@@ -4676,7 +4662,7 @@ static STableIdInfo createTableIdInfo(STableQueryInfo* pTableQueryInfo) {
...
@@ -4676,7 +4662,7 @@ static STableIdInfo createTableIdInfo(STableQueryInfo* pTableQueryInfo) {
// }
// }
//}
//}
static
void
doCloseAllTimeWindow
(
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
static
void
doCloseAllTimeWindow
(
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
size_t
numOfGroup
=
GET_NUM_OF_TABLEGROUP
(
pRuntimeEnv
);
size_t
numOfGroup
=
GET_NUM_OF_TABLEGROUP
(
pRuntimeEnv
);
for
(
int32_t
i
=
0
;
i
<
numOfGroup
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfGroup
;
++
i
)
{
SArray
*
group
=
GET_TABLEGROUP
(
pRuntimeEnv
,
i
);
SArray
*
group
=
GET_TABLEGROUP
(
pRuntimeEnv
,
i
);
...
@@ -4693,44 +4679,37 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) {
...
@@ -4693,44 +4679,37 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) {
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
STableScanInfo
*
pTableScanInfo
=
pOperator
->
info
;
STableScanInfo
*
pTableScanInfo
=
pOperator
->
info
;
STaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SSDataBlock
*
pBlock
=
&
pTableScanInfo
->
block
;
SSDataBlock
*
pBlock
=
&
pTableScanInfo
->
block
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STableGroupInfo
*
pTableGroupInfo
=
&
pOperator
->
pTaskInfo
->
tableqinfoGroupInfo
;
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
STableGroupInfo
*
pTableGroupInfo
=
&
pOperator
->
pRuntimeEnv
->
tableqinfoGroupInfo
;
*
newgroup
=
false
;
*
newgroup
=
false
;
#if 0
while (
tsdbNextDataBlock(pTableScanInfo->pQueryHandle)
) {
while
(
/*tsdbNextDataBlock(pTableScanInfo->pQueryHandle)*/
1
)
{
if
(
isQueryKilled
(
pOperator
->
pRuntimeEnv
->
qinfo
))
{
if
(
isQueryKilled
(
pOperator
->
pRuntimeEnv
->
qinfo
))
{
longjmp
(
pOperator
->
pRuntimeEnv
->
env
,
TSDB_CODE_TSC_QUERY_CANCELLED
);
longjmp
(
pOperator
->
pRuntimeEnv
->
env
,
TSDB_CODE_TSC_QUERY_CANCELLED
);
}
}
pTableScanInfo
->
numOfBlocks
+=
1
;
pTableScanInfo
->
numOfBlocks
+=
1
;
tsdbRetrieveDataBlockInfo(pTableScanInfo->pQueryHandle, &pBlock->info);
//
tsdbRetrieveDataBlockInfo(pTableScanInfo->pQueryHandle, &pBlock->info);
// todo opt
// todo opt
if (pTableGroupInfo->numOfTables > 1 || (pRuntimeEnv->current == NULL && pTableGroupInfo->numOfTables == 1)) {
// if (pTableGroupInfo->numOfTables > 1 || (pRuntimeEnv->current == NULL && pTableGroupInfo->numOfTables == 1)) {
STableQueryInfo** pTableQueryInfo =
// STableQueryInfo** pTableQueryInfo =
(STableQueryInfo**)taosHashGet(pTableGroupInfo->map, &pBlock->info.uid, sizeof(pBlock->info.uid));
// (STableQueryInfo**)taosHashGet(pTableGroupInfo->map, &pBlock->info.uid, sizeof(pBlock->info.uid));
if (pTableQueryInfo == NULL) {
// if (pTableQueryInfo == NULL) {
break;
// break;
}
// }
//
pRuntimeEnv->current = *pTableQueryInfo;
// pRuntimeEnv->current = *pTableQueryInfo;
doTableQueryInfoTimeWindowCheck(pQueryAttr, *pTableQueryInfo);
// doTableQueryInfoTimeWindowCheck(pTaskInfo, *pTableQueryInfo, pTableScanInfo->order);
// }
if (pRuntimeEnv->enableGroupData) {
if(pTableScanInfo->prevGroupId != -1 && pTableScanInfo->prevGroupId != (*pTableQueryInfo)->groupIndex) {
*newgroup = true;
}
}
pTableScanInfo->prevGroupId = (*pTableQueryInfo)->groupIndex;
}
// this function never returns error?
// this function never returns error?
uint32_t
status
;
uint32_t
status
;
int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status);
int32_t
code
=
loadDataBlock
(
pTaskInfo
,
pTableScanInfo
,
pBlock
,
&
status
);
// int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pOperator
->
pRuntimeEnv
->
env
,
code
);
longjmp
(
pOperator
->
pRuntimeEnv
->
env
,
code
);
}
}
...
@@ -4742,7 +4721,6 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) {
...
@@ -4742,7 +4721,6 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) {
return
pBlock
;
return
pBlock
;
}
}
#endif
return
NULL
;
return
NULL
;
}
}
...
@@ -4750,9 +4728,8 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) {
...
@@ -4750,9 +4728,8 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) {
static
SSDataBlock
*
doTableScan
(
void
*
param
,
bool
*
newgroup
)
{
static
SSDataBlock
*
doTableScan
(
void
*
param
,
bool
*
newgroup
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
STableScanInfo
*
pTableScanInfo
=
pOperator
->
info
;
STableScanInfo
*
pTableScanInfo
=
pOperator
->
info
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SResultRowInfo
*
pResultRowInfo
=
pTableScanInfo
->
pResultRowInfo
;
SResultRowInfo
*
pResultRowInfo
=
pTableScanInfo
->
pResultRowInfo
;
*
newgroup
=
false
;
*
newgroup
=
false
;
...
@@ -4775,14 +4752,14 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) {
...
@@ -4775,14 +4752,14 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) {
// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window);
// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window);
// tsdbResetQueryHandle(pTableScanInfo->pQueryHandle, &cond);
// tsdbResetQueryHandle(pTableScanInfo->pQueryHandle, &cond);
setQueryStatus
(
pRuntimeEnv
,
QUERY_NOT_COMPLETED
);
setTaskStatus
(
pTaskInfo
,
QUERY_NOT_COMPLETED
);
pRuntimeEnv
->
scanFlag
=
REPEAT_SCAN
;
pTableScanInfo
->
scanFlag
=
REPEAT_SCAN
;
if
(
pRuntimeEnv
->
pTsBuf
)
{
bool
ret
=
tsBufNextPos
(
pRuntimeEnv
->
pTsBuf
);
assert
(
ret
);
}
// if (pTaskInfo->pTsBuf) {
// bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf);
// assert(ret);
// }
//
if
(
pResultRowInfo
->
size
>
0
)
{
if
(
pResultRowInfo
->
size
>
0
)
{
pResultRowInfo
->
curPos
=
0
;
pResultRowInfo
->
curPos
=
0
;
}
}
...
@@ -4792,17 +4769,15 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) {
...
@@ -4792,17 +4769,15 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) {
}
}
SSDataBlock
*
p
=
NULL
;
SSDataBlock
*
p
=
NULL
;
// todo refactor
if
(
pTableScanInfo
->
reverseTimes
>
0
)
{
if
(
pTableScanInfo
->
reverseTimes
>
0
)
{
setupEnvForReverseScan
(
pRuntimeEnv
,
pTableScanInfo
->
pResultRowInfo
,
pTableScanInfo
->
pCtx
,
pTableScanInfo
->
numOfOutput
);
setupEnvForReverseScan
(
pTableScanInfo
,
pTableScanInfo
->
pCtx
,
pTableScanInfo
->
numOfOutput
);
// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window);
// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window);
// tsdbResetQueryHandle(pTableScanInfo->pQueryHandle, &cond);
// tsdbResetQueryHandle(pTableScanInfo->pQueryHandle, &cond);
//qDebug("QInfo:0x%"PRIx64" start to reverse scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
//qDebug("QInfo:0x%"PRIx64" start to reverse scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
// GET_QID(pRuntimeEnv), cond.twindow.skey, cond.twindow.ekey);
// GET_QID(pRuntimeEnv), cond.twindow.skey, cond.twindow.ekey);
pRuntimeEnv
->
scanFlag
=
REVERSE_SCAN
;
pTableScanInfo
->
times
=
1
;
pTableScanInfo
->
times
=
1
;
pTableScanInfo
->
current
=
0
;
pTableScanInfo
->
current
=
0
;
pTableScanInfo
->
reverseTimes
=
0
;
pTableScanInfo
->
reverseTimes
=
0
;
...
@@ -4867,31 +4842,31 @@ static SSDataBlock* doBlockInfoScan(void* param, bool* newgroup) {
...
@@ -4867,31 +4842,31 @@ static SSDataBlock* doBlockInfoScan(void* param, bool* newgroup) {
}
}
SOperatorInfo
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
)
{
SOperatorInfo
*
createTableScanOperator
(
void
*
pTsdbQueryHandle
,
int32_t
order
,
int32_t
numOfOutput
,
int32_t
repeatTime
)
{
assert
(
repeatTime
>
0
);
assert
(
repeatTime
>
0
&&
numOfOutput
>
0
);
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
pInfo
->
times
=
repeatTime
;
pInfo
->
times
=
repeatTime
;
pInfo
->
reverseTimes
=
0
;
pInfo
->
reverseTimes
=
0
;
pInfo
->
order
=
pRuntimeEnv
->
pQueryAttr
->
order
.
order
;
pInfo
->
order
=
order
;
pInfo
->
current
=
0
;
pInfo
->
current
=
0
;
// pInfo->prevGroupId = -1
;
pInfo
->
scanFlag
=
MAIN_SCAN
;
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"TableScanOperator"
;
pOperator
->
name
=
"TableScanOperator"
;
//
pOperator->operatorType = OP_TableScan;
pOperator
->
operatorType
=
OP_TableScan
;
pOperator
->
blockingOptr
=
false
;
pOperator
->
blockingOptr
=
false
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
pOperator
->
numOfOutput
=
pRuntimeEnv
->
pQueryAttr
->
numOfCols
;
pOperator
->
numOfOutput
=
numOfOutput
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
pRuntimeEnv
=
NULL
;
pOperator
->
exec
=
doTableScan
;
pOperator
->
exec
=
doTableScan
;
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbQueryHandle
,
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbQueryHandle
,
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
...
@@ -4915,7 +4890,7 @@ SOperatorInfo* createTableSeqScanOperator(void* pTsdbQueryHandle, SQueryRuntimeE
...
@@ -4915,7 +4890,7 @@ SOperatorInfo* createTableSeqScanOperator(void* pTsdbQueryHandle, SQueryRuntimeE
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createTableBlockInfoScanOperator
(
void
*
pTsdbQueryHandle
,
S
Query
RuntimeEnv
*
pRuntimeEnv
)
{
SOperatorInfo
*
createTableBlockInfoScanOperator
(
void
*
pTsdbQueryHandle
,
S
Task
RuntimeEnv
*
pRuntimeEnv
)
{
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
STableScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableScanInfo
));
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
pInfo
->
pQueryHandle
=
pTsdbQueryHandle
;
...
@@ -4998,7 +4973,7 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf
...
@@ -4998,7 +4973,7 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf
}
}
SOperatorInfo
*
createDataBlocksOptScanInfo
(
void
*
pTsdbQueryHandle
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
int32_t
repeatTime
,
int32_t
reverseTime
)
{
SOperatorInfo
*
createDataBlocksOptScanInfo
(
void
*
pTsdbQueryHandle
,
S
Task
RuntimeEnv
*
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
));
...
@@ -5019,7 +4994,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime
...
@@ -5019,7 +4994,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime
return
pOptr
;
return
pOptr
;
}
}
SArray
*
getOrderCheckColumns
(
S
Query
Attr
*
pQuery
)
{
SArray
*
getOrderCheckColumns
(
S
Task
Attr
*
pQuery
)
{
int32_t
numOfCols
=
(
pQuery
->
pGroupbyExpr
==
NULL
)
?
0
:
taosArrayGetSize
(
pQuery
->
pGroupbyExpr
->
columnInfo
);
int32_t
numOfCols
=
(
pQuery
->
pGroupbyExpr
==
NULL
)
?
0
:
taosArrayGetSize
(
pQuery
->
pGroupbyExpr
->
columnInfo
);
SArray
*
pOrderColumns
=
NULL
;
SArray
*
pOrderColumns
=
NULL
;
...
@@ -5058,7 +5033,7 @@ SArray* getOrderCheckColumns(SQueryAttr* pQuery) {
...
@@ -5058,7 +5033,7 @@ SArray* getOrderCheckColumns(SQueryAttr* pQuery) {
return
pOrderColumns
;
return
pOrderColumns
;
}
}
SArray
*
getResultGroupCheckColumns
(
S
Query
Attr
*
pQuery
)
{
SArray
*
getResultGroupCheckColumns
(
S
Task
Attr
*
pQuery
)
{
int32_t
numOfCols
=
(
pQuery
->
pGroupbyExpr
==
NULL
)
?
0
:
taosArrayGetSize
(
pQuery
->
pGroupbyExpr
->
columnInfo
);
int32_t
numOfCols
=
(
pQuery
->
pGroupbyExpr
==
NULL
)
?
0
:
taosArrayGetSize
(
pQuery
->
pGroupbyExpr
->
columnInfo
);
SArray
*
pOrderColumns
=
NULL
;
SArray
*
pOrderColumns
=
NULL
;
...
@@ -5109,7 +5084,7 @@ static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -5109,7 +5084,7 @@ static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) {
tfree
(
pInfo
->
prevRow
);
tfree
(
pInfo
->
prevRow
);
}
}
SOperatorInfo
*
createGlobalAggregateOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SOperatorInfo
*
createGlobalAggregateOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
param
,
SArray
*
pUdfInfo
,
bool
groupResultMixedUp
)
{
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
param
,
SArray
*
pUdfInfo
,
bool
groupResultMixedUp
)
{
SMultiwayMergeInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SMultiwayMergeInfo
));
SMultiwayMergeInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SMultiwayMergeInfo
));
...
@@ -5172,12 +5147,12 @@ SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv,
...
@@ -5172,12 +5147,12 @@ SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv,
pOperator
->
exec
=
doGlobalAggregate
;
pOperator
->
exec
=
doGlobalAggregate
;
pOperator
->
cleanup
=
destroyGlobalAggOperatorInfo
;
pOperator
->
cleanup
=
destroyGlobalAggOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createMultiwaySortOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOperatorInfo
*
createMultiwaySortOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
,
void
*
merger
)
{
int32_t
numOfRows
,
void
*
merger
)
{
SMultiwayMergeInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SMultiwayMergeInfo
));
SMultiwayMergeInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SMultiwayMergeInfo
));
...
@@ -5252,9 +5227,9 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
...
@@ -5252,9 +5227,9 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
SSDataBlock
*
pBlock
=
NULL
;
SSDataBlock
*
pBlock
=
NULL
;
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
pBlock
=
pOperator
->
upstream
[
0
]
->
exec
(
pOperator
->
up
stream
[
0
],
newgroup
);
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDown
stream
[
0
],
newgroup
);
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
// 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
)
{
...
@@ -5288,7 +5263,7 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
...
@@ -5288,7 +5263,7 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
return
(
pInfo
->
pDataBlock
->
info
.
rows
>
0
)
?
pInfo
->
pDataBlock
:
NULL
;
return
(
pInfo
->
pDataBlock
->
info
.
rows
>
0
)
?
pInfo
->
pDataBlock
:
NULL
;
}
}
SOperatorInfo
*
createOrderOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOrder
*
pOrderVal
)
{
SOperatorInfo
*
createOrderOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SOrder
*
pOrderVal
)
{
SOrderOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SOrderOperatorInfo
));
SOrderOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SOrderOperatorInfo
));
{
{
...
@@ -5321,7 +5296,7 @@ SOperatorInfo *createOrderOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
...
@@ -5321,7 +5296,7 @@ SOperatorInfo *createOrderOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
pOperator
->
cleanup
=
destroyOrderOperatorInfo
;
pOperator
->
cleanup
=
destroyOrderOperatorInfo
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
...
@@ -5339,17 +5314,17 @@ static SSDataBlock* doAggregate(void* param, bool* newgroup) {
...
@@ -5339,17 +5314,17 @@ static SSDataBlock* doAggregate(void* param, bool* newgroup) {
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5359,8 +5334,8 @@ static SSDataBlock* doAggregate(void* param, bool* newgroup) {
...
@@ -5359,8 +5334,8 @@ static SSDataBlock* doAggregate(void* param, bool* newgroup) {
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
}
}
// if (
up
stream->operatorType == OP_DataBlocksOptScan) {
// if (
down
stream->operatorType == OP_DataBlocksOptScan) {
// STableScanInfo* pScanInfo =
up
stream->info;
// STableScanInfo* pScanInfo =
down
stream->info;
// order = getTableScanOrder(pScanInfo);
// order = getTableScanOrder(pScanInfo);
// }
// }
...
@@ -5386,7 +5361,7 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
...
@@ -5386,7 +5361,7 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
pRes
);
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
pRes
);
...
@@ -5398,15 +5373,15 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
...
@@ -5398,15 +5373,15 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
return
pInfo
->
pRes
;
return
pInfo
->
pRes
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5414,8 +5389,8 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
...
@@ -5414,8 +5389,8 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
setTagValue
(
pOperator
,
pRuntimeEnv
->
current
->
pTable
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
// if (
up
stream->operatorType == OP_DataBlocksOptScan) {
// if (
down
stream->operatorType == OP_DataBlocksOptScan) {
// STableScanInfo* pScanInfo =
up
stream->info;
// STableScanInfo* pScanInfo =
down
stream->info;
// order = getTableScanOrder(pScanInfo);
// order = getTableScanOrder(pScanInfo);
// }
// }
...
@@ -5455,7 +5430,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
...
@@ -5455,7 +5430,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
SProjectOperatorInfo
*
pProjectInfo
=
pOperator
->
info
;
SProjectOperatorInfo
*
pProjectInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
SOptrBasicInfo
*
pInfo
=
&
pProjectInfo
->
binfo
;
SOptrBasicInfo
*
pInfo
=
&
pProjectInfo
->
binfo
;
SSDataBlock
*
pRes
=
pInfo
->
pRes
;
SSDataBlock
*
pRes
=
pInfo
->
pRes
;
...
@@ -5492,16 +5467,16 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
...
@@ -5492,16 +5467,16 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
while
(
1
)
{
while
(
1
)
{
bool
prevVal
=
*
newgroup
;
bool
prevVal
=
*
newgroup
;
// The
up
stream exec may change the value of the newgroup, so use a local variable instead.
// The
down
stream exec may change the value of the newgroup, so use a local variable instead.
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
pOperator
->
upstream
[
0
]
->
exec
(
pOperator
->
up
stream
[
0
],
newgroup
);
SSDataBlock
*
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDown
stream
[
0
],
newgroup
);
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
assert
(
*
newgroup
==
false
);
assert
(
*
newgroup
==
false
);
*
newgroup
=
prevVal
;
*
newgroup
=
prevVal
;
set
QueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
set
TaskStatus
(
pOperator
->
pTaskInfo
,
QUERY_COMPLETED
);
break
;
break
;
}
}
...
@@ -5547,13 +5522,13 @@ static SSDataBlock* doLimit(void* param, bool* newgroup) {
...
@@ -5547,13 +5522,13 @@ static SSDataBlock* doLimit(void* param, bool* newgroup) {
}
}
SLimitOperatorInfo
*
pInfo
=
pOperator
->
info
;
SLimitOperatorInfo
*
pInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
SSDataBlock
*
pBlock
=
NULL
;
SSDataBlock
*
pBlock
=
NULL
;
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
pBlock
=
pOperator
->
upstream
[
0
]
->
exec
(
pOperator
->
up
stream
[
0
],
newgroup
);
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDown
stream
[
0
],
newgroup
);
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
doSetOperatorCompleted
(
pOperator
);
doSetOperatorCompleted
(
pOperator
);
...
@@ -5599,12 +5574,12 @@ static SSDataBlock* doFilter(void* param, bool* newgroup) {
...
@@ -5599,12 +5574,12 @@ static SSDataBlock* doFilter(void* param, bool* newgroup) {
}
}
SFilterOperatorInfo
*
pCondInfo
=
pOperator
->
info
;
SFilterOperatorInfo
*
pCondInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
pOperator
->
upstream
[
0
]
->
exec
(
pOperator
->
up
stream
[
0
],
newgroup
);
SSDataBlock
*
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDown
stream
[
0
],
newgroup
);
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5631,7 +5606,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
...
@@ -5631,7 +5606,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
if
(
pIntervalInfo
->
pRes
->
info
.
rows
==
0
||
!
hasRemainDataInCurrentGroup
(
&
pRuntimeEnv
->
groupResInfo
))
{
...
@@ -5641,16 +5616,16 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
...
@@ -5641,16 +5616,16 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
return
pIntervalInfo
->
pRes
;
return
pIntervalInfo
->
pRes
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
STimeWindow
win
=
pQueryAttr
->
window
;
STimeWindow
win
=
pQueryAttr
->
window
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5669,7 +5644,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
...
@@ -5669,7 +5644,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
closeAllResultRows
(
&
pIntervalInfo
->
resultRowInfo
);
closeAllResultRows
(
&
pIntervalInfo
->
resultRowInfo
);
set
QueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
set
TaskStatus
(
pOperator
->
pTaskInfo
,
QUERY_COMPLETED
);
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
);
...
@@ -5690,7 +5665,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
...
@@ -5690,7 +5665,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pIntervalInfo
->
pRes
);
...
@@ -5701,16 +5676,16 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
...
@@ -5701,16 +5676,16 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
return
pIntervalInfo
->
pRes
;
return
pIntervalInfo
->
pRes
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
STimeWindow
win
=
pQueryAttr
->
window
;
STimeWindow
win
=
pQueryAttr
->
window
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5729,7 +5704,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
...
@@ -5729,7 +5704,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
closeAllResultRows
(
&
pIntervalInfo
->
resultRowInfo
);
closeAllResultRows
(
&
pIntervalInfo
->
resultRowInfo
);
set
QueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
set
TaskStatus
(
pOperator
->
pTaskInfo
,
QUERY_COMPLETED
);
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
);
...
@@ -5749,7 +5724,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -5749,7 +5724,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
}
}
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
...
@@ -5765,15 +5740,15 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -5765,15 +5740,15 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
return
pIntervalInfo
->
pRes
;
return
pIntervalInfo
->
pRes
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5792,7 +5767,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -5792,7 +5767,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
pQueryAttr
->
order
.
order
=
order
;
// TODO : restore the order
pQueryAttr
->
order
.
order
=
order
;
// TODO : restore the order
doCloseAllTimeWindow
(
pRuntimeEnv
);
doCloseAllTimeWindow
(
pRuntimeEnv
);
set
QueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
set
TaskStatus
(
pOperator
->
pTaskInfo
,
QUERY_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
))
{
...
@@ -5809,7 +5784,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -5809,7 +5784,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
}
}
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
STableIntervalOperatorInfo
*
pIntervalInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
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
);
...
@@ -5820,15 +5795,15 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -5820,15 +5795,15 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
return
pIntervalInfo
->
pRes
;
return
pIntervalInfo
->
pRes
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5847,7 +5822,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -5847,7 +5822,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
pQueryAttr
->
order
.
order
=
order
;
// TODO : restore the order
pQueryAttr
->
order
.
order
=
order
;
// TODO : restore the order
doCloseAllTimeWindow
(
pRuntimeEnv
);
doCloseAllTimeWindow
(
pRuntimeEnv
);
set
QueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
set
TaskStatus
(
pOperator
->
pTaskInfo
,
QUERY_COMPLETED
);
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
copyToSDataBlock
(
pRuntimeEnv
,
3000
,
pIntervalInfo
->
pRes
,
pIntervalInfo
->
rowCellInfoOffset
);
copyToSDataBlock
(
pRuntimeEnv
,
3000
,
pIntervalInfo
->
pRes
,
pIntervalInfo
->
rowCellInfoOffset
);
...
@@ -5862,13 +5837,13 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
...
@@ -5862,13 +5837,13 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
}
}
static
void
doStateWindowAggImpl
(
SOperatorInfo
*
pOperator
,
SStateWindowOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
static
void
doStateWindowAggImpl
(
SOperatorInfo
*
pOperator
,
SStateWindowOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
current
;
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
pInfo
->
colIndex
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
pInfo
->
colIndex
);
SOptrBasicInfo
*
pBInfo
=
&
pInfo
->
binfo
;
SOptrBasicInfo
*
pBInfo
=
&
pInfo
->
binfo
;
bool
masterScan
=
IS_MA
STER
_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MA
IN
_SCAN
(
pRuntimeEnv
);
int16_t
bytes
=
pColInfoData
->
info
.
bytes
;
int16_t
bytes
=
pColInfoData
->
info
.
bytes
;
int16_t
type
=
pColInfoData
->
info
.
type
;
int16_t
type
=
pColInfoData
->
info
.
type
;
...
@@ -5945,7 +5920,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
...
@@ -5945,7 +5920,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
SStateWindowOperatorInfo
*
pWindowInfo
=
pOperator
->
info
;
SStateWindowOperatorInfo
*
pWindowInfo
=
pOperator
->
info
;
SOptrBasicInfo
*
pBInfo
=
&
pWindowInfo
->
binfo
;
SOptrBasicInfo
*
pBInfo
=
&
pWindowInfo
->
binfo
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
...
@@ -5956,14 +5931,14 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
...
@@ -5956,14 +5931,14 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
return
pBInfo
->
pRes
;
return
pBInfo
->
pRes
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
STimeWindow
win
=
pQueryAttr
->
window
;
STimeWindow
win
=
pQueryAttr
->
window
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
...
@@ -5981,7 +5956,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
...
@@ -5981,7 +5956,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
closeAllResultRows
(
&
pBInfo
->
resultRowInfo
);
closeAllResultRows
(
&
pBInfo
->
resultRowInfo
);
set
QueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
set
TaskStatus
(
pOperator
->
pTaskInfo
,
QUERY_COMPLETED
);
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
);
...
@@ -6004,7 +5979,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
...
@@ -6004,7 +5979,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
SOptrBasicInfo
*
pBInfo
=
&
pWindowInfo
->
binfo
;
SOptrBasicInfo
*
pBInfo
=
&
pWindowInfo
->
binfo
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pBInfo
->
pRes
);
...
@@ -6015,17 +5990,17 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
...
@@ -6015,17 +5990,17 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
return
pBInfo
->
pRes
;
return
pBInfo
->
pRes
;
}
}
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
//pQueryAttr->order.order = TSDB_ORDER_ASC;
//pQueryAttr->order.order = TSDB_ORDER_ASC;
int32_t
order
=
pQueryAttr
->
order
.
order
;
int32_t
order
=
pQueryAttr
->
order
.
order
;
STimeWindow
win
=
pQueryAttr
->
window
;
STimeWindow
win
=
pQueryAttr
->
window
;
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
}
}
...
@@ -6041,7 +6016,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
...
@@ -6041,7 +6016,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
closeAllResultRows
(
&
pBInfo
->
resultRowInfo
);
closeAllResultRows
(
&
pBInfo
->
resultRowInfo
);
setQueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_COMPLETED);
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
);
...
@@ -6062,7 +6037,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6062,7 +6037,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
SGroupbyOperatorInfo
*
pInfo
=
pOperator
->
info
;
SGroupbyOperatorInfo
*
pInfo
=
pOperator
->
info
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
binfo
.
pRes
);
toSSDataBlock
(
&
pRuntimeEnv
->
groupResInfo
,
pRuntimeEnv
,
pInfo
->
binfo
.
pRes
);
...
@@ -6073,12 +6048,12 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6073,12 +6048,12 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
return
pInfo
->
binfo
.
pRes
;
return
pInfo
->
binfo
.
pRes
;
}
}
SOperatorInfo
*
upstream
=
pOperator
->
up
stream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDown
stream
[
0
];
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
upstream
->
exec
(
up
stream
,
newgroup
);
SSDataBlock
*
pBlock
=
downstream
->
exec
(
down
stream
,
newgroup
);
publishOperatorProfEvent
(
up
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
down
stream
,
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
break
;
break
;
}
}
...
@@ -6095,7 +6070,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6095,7 +6070,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
closeAllResultRows
(
&
pInfo
->
binfo
.
resultRowInfo
);
closeAllResultRows
(
&
pInfo
->
binfo
.
resultRowInfo
);
setQueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_COMPLETED);
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
);
...
@@ -6117,7 +6092,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
...
@@ -6117,7 +6092,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
return
pInfo
->
binfo
.
pRes
;
return
pInfo
->
binfo
.
pRes
;
}
}
static
void
doHandleRemainBlockForNewGroupImpl
(
SFillOperatorInfo
*
pInfo
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
bool
*
newgroup
)
{
static
void
doHandleRemainBlockForNewGroupImpl
(
SFillOperatorInfo
*
pInfo
,
S
Task
RuntimeEnv
*
pRuntimeEnv
,
bool
*
newgroup
)
{
pInfo
->
totalInputRows
=
pInfo
->
existNewGroupBlock
->
info
.
rows
;
pInfo
->
totalInputRows
=
pInfo
->
existNewGroupBlock
->
info
.
rows
;
int64_t
ekey
=
Q_STATUS_EQUAL
(
pRuntimeEnv
->
status
,
QUERY_COMPLETED
)
?
pRuntimeEnv
->
pQueryAttr
->
window
.
ekey
:
pInfo
->
existNewGroupBlock
->
info
.
window
.
ekey
;
int64_t
ekey
=
Q_STATUS_EQUAL
(
pRuntimeEnv
->
status
,
QUERY_COMPLETED
)
?
pRuntimeEnv
->
pQueryAttr
->
window
.
ekey
:
pInfo
->
existNewGroupBlock
->
info
.
window
.
ekey
;
taosResetFillInfo
(
pInfo
->
pFillInfo
,
getFillInfoStart
(
pInfo
->
pFillInfo
));
taosResetFillInfo
(
pInfo
->
pFillInfo
,
getFillInfoStart
(
pInfo
->
pFillInfo
));
...
@@ -6130,7 +6105,7 @@ static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo *pInfo, SQueryR
...
@@ -6130,7 +6105,7 @@ static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo *pInfo, SQueryR
*
newgroup
=
true
;
*
newgroup
=
true
;
}
}
static
void
doHandleRemainBlockFromNewGroup
(
SFillOperatorInfo
*
pInfo
,
S
Query
RuntimeEnv
*
pRuntimeEnv
,
bool
*
newgroup
)
{
static
void
doHandleRemainBlockFromNewGroup
(
SFillOperatorInfo
*
pInfo
,
S
Task
RuntimeEnv
*
pRuntimeEnv
,
bool
*
newgroup
)
{
if
(
taosFillHasMoreResults
(
pInfo
->
pFillInfo
))
{
if
(
taosFillHasMoreResults
(
pInfo
->
pFillInfo
))
{
*
newgroup
=
false
;
*
newgroup
=
false
;
doFillTimeIntervalGapsInResults
(
pInfo
->
pFillInfo
,
pInfo
->
pRes
,
(
int32_t
)
pRuntimeEnv
->
resultInfo
.
capacity
,
pInfo
->
p
);
doFillTimeIntervalGapsInResults
(
pInfo
->
pFillInfo
,
pInfo
->
pRes
,
(
int32_t
)
pRuntimeEnv
->
resultInfo
.
capacity
,
pInfo
->
p
);
...
@@ -6155,16 +6130,16 @@ static SSDataBlock* doFill(void* param, bool* newgroup) {
...
@@ -6155,16 +6130,16 @@ static SSDataBlock* doFill(void* param, bool* newgroup) {
return
NULL
;
return
NULL
;
}
}
S
Query
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
doHandleRemainBlockFromNewGroup
(
pInfo
,
pRuntimeEnv
,
newgroup
);
doHandleRemainBlockFromNewGroup
(
pInfo
,
pRuntimeEnv
,
newgroup
);
if
(
pInfo
->
pRes
->
info
.
rows
>
pRuntimeEnv
->
resultInfo
.
threshold
||
(
!
pInfo
->
multigroupResult
&&
pInfo
->
pRes
->
info
.
rows
>
0
))
{
if
(
pInfo
->
pRes
->
info
.
rows
>
pRuntimeEnv
->
resultInfo
.
threshold
||
(
!
pInfo
->
multigroupResult
&&
pInfo
->
pRes
->
info
.
rows
>
0
))
{
return
pInfo
->
pRes
;
return
pInfo
->
pRes
;
}
}
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
SSDataBlock
*
pBlock
=
pOperator
->
upstream
[
0
]
->
exec
(
pOperator
->
up
stream
[
0
],
newgroup
);
SSDataBlock
*
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDown
stream
[
0
],
newgroup
);
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
*
newgroup
)
{
if
(
*
newgroup
)
{
assert
(
pBlock
!=
NULL
);
assert
(
pBlock
!=
NULL
);
...
@@ -6220,7 +6195,7 @@ static SSDataBlock* doFill(void* param, bool* newgroup) {
...
@@ -6220,7 +6195,7 @@ static SSDataBlock* doFill(void* param, bool* newgroup) {
}
}
// todo set the attribute of query scan count
// todo set the attribute of query scan count
static
int32_t
getNumOfScanTimes
(
S
Query
Attr
*
pQueryAttr
)
{
static
int32_t
getNumOfScanTimes
(
S
Task
Attr
*
pQueryAttr
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfOutput
;
++
i
)
{
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
int32_t
functionId
=
getExprFunctionId
(
&
pQueryAttr
->
pExpr1
[
i
]);
if
(
functionId
==
FUNCTION_STDDEV
||
functionId
==
FUNCTION_PERCT
)
{
if
(
functionId
==
FUNCTION_STDDEV
||
functionId
==
FUNCTION_PERCT
)
{
...
@@ -6240,23 +6215,23 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
...
@@ -6240,23 +6215,23 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
pOperator
->
cleanup
(
pOperator
->
info
,
pOperator
->
numOfOutput
);
pOperator
->
cleanup
(
pOperator
->
info
,
pOperator
->
numOfOutput
);
}
}
if
(
pOperator
->
up
stream
!=
NULL
)
{
if
(
pOperator
->
pDown
stream
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
pOperator
->
numOf
Up
stream
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pOperator
->
numOf
Down
stream
;
++
i
)
{
destroyOperatorInfo
(
pOperator
->
up
stream
[
i
]);
destroyOperatorInfo
(
pOperator
->
pDown
stream
[
i
]);
}
}
tfree
(
pOperator
->
up
stream
);
tfree
(
pOperator
->
pDown
stream
);
pOperator
->
numOf
Up
stream
=
0
;
pOperator
->
numOf
Down
stream
=
0
;
}
}
tfree
(
pOperator
->
info
);
tfree
(
pOperator
->
info
);
tfree
(
pOperator
);
tfree
(
pOperator
);
}
}
SOperatorInfo
*
createAggregateOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createAggregateOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
numOfRows
=
(
int32_t
)(
getRowNumForMultioutput
(
pQueryAttr
,
pQueryAttr
->
topBotQuery
,
pQueryAttr
->
stableQuery
));
int32_t
numOfRows
=
(
int32_t
)(
getRowNumForMultioutput
(
pQueryAttr
,
pQueryAttr
->
topBotQuery
,
pQueryAttr
->
stableQuery
));
pInfo
->
binfo
.
pRes
=
createOutputBuf
(
pExpr
,
numOfOutput
,
numOfRows
);
pInfo
->
binfo
.
pRes
=
createOutputBuf
(
pExpr
,
numOfOutput
,
numOfRows
);
...
@@ -6265,7 +6240,7 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera
...
@@ -6265,7 +6240,7 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera
initResultRowInfo
(
&
pInfo
->
binfo
.
resultRowInfo
,
8
,
TSDB_DATA_TYPE_INT
);
initResultRowInfo
(
&
pInfo
->
binfo
.
resultRowInfo
,
8
,
TSDB_DATA_TYPE_INT
);
pInfo
->
seed
=
rand
();
pInfo
->
seed
=
rand
();
setDefaultOutputBuf
(
pRuntimeEnv
,
&
pInfo
->
binfo
,
pInfo
->
seed
,
MA
STER
_SCAN
);
setDefaultOutputBuf
(
pRuntimeEnv
,
&
pInfo
->
binfo
,
pInfo
->
seed
,
MA
IN
_SCAN
);
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"TableAggregate"
;
pOperator
->
name
=
"TableAggregate"
;
...
@@ -6279,7 +6254,7 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera
...
@@ -6279,7 +6254,7 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera
pOperator
->
exec
=
doAggregate
;
pOperator
->
exec
=
doAggregate
;
pOperator
->
cleanup
=
destroyAggOperatorInfo
;
pOperator
->
cleanup
=
destroyAggOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
...
@@ -6353,7 +6328,7 @@ static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -6353,7 +6328,7 @@ static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) {
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
pInfo
->
pRes
=
destroyOutputBuf
(
pInfo
->
pRes
);
}
}
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createMultiTableAggOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
SAggOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SAggOperatorInfo
));
size_t
tableGroup
=
GET_NUM_OF_TABLEGROUP
(
pRuntimeEnv
);
size_t
tableGroup
=
GET_NUM_OF_TABLEGROUP
(
pRuntimeEnv
);
...
@@ -6374,12 +6349,12 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SO
...
@@ -6374,12 +6349,12 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SO
pOperator
->
exec
=
doSTableAggregate
;
pOperator
->
exec
=
doSTableAggregate
;
pOperator
->
cleanup
=
destroyAggOperatorInfo
;
pOperator
->
cleanup
=
destroyAggOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createProjectOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createProjectOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SProjectOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SProjectOperatorInfo
));
SProjectOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SProjectOperatorInfo
));
pInfo
->
seed
=
rand
();
pInfo
->
seed
=
rand
();
...
@@ -6390,7 +6365,7 @@ SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
...
@@ -6390,7 +6365,7 @@ SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
pBInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pBInfo
->
rowCellInfoOffset
);
pBInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pBInfo
->
rowCellInfoOffset
);
initResultRowInfo
(
&
pBInfo
->
resultRowInfo
,
8
,
TSDB_DATA_TYPE_INT
);
initResultRowInfo
(
&
pBInfo
->
resultRowInfo
,
8
,
TSDB_DATA_TYPE_INT
);
setDefaultOutputBuf
(
pRuntimeEnv
,
pBInfo
,
pInfo
->
seed
,
MA
STER
_SCAN
);
setDefaultOutputBuf
(
pRuntimeEnv
,
pBInfo
,
pInfo
->
seed
,
MA
IN
_SCAN
);
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"ProjectOperator"
;
pOperator
->
name
=
"ProjectOperator"
;
...
@@ -6404,7 +6379,7 @@ SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
...
@@ -6404,7 +6379,7 @@ SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
pOperator
->
exec
=
doProjectOperation
;
pOperator
->
exec
=
doProjectOperation
;
pOperator
->
cleanup
=
destroyProjectOperatorInfo
;
pOperator
->
cleanup
=
destroyProjectOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
...
@@ -6442,7 +6417,7 @@ SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int3
...
@@ -6442,7 +6417,7 @@ SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int3
return
0
;
return
0
;
}
}
SOperatorInfo
*
createFilterOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
SOperatorInfo
*
createFilterOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
SColumnInfo
*
pCols
,
int32_t
numOfFilter
)
{
int32_t
numOfOutput
,
SColumnInfo
*
pCols
,
int32_t
numOfFilter
)
{
SFilterOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SFilterOperatorInfo
));
SFilterOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SFilterOperatorInfo
));
...
@@ -6462,12 +6437,12 @@ SOperatorInfo* createFilterOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
...
@@ -6462,12 +6437,12 @@ SOperatorInfo* createFilterOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
cleanup
=
destroyConditionOperatorInfo
;
pOperator
->
cleanup
=
destroyConditionOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createLimitOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
)
{
SOperatorInfo
*
createLimitOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
)
{
SLimitOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SLimitOperatorInfo
));
SLimitOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SLimitOperatorInfo
));
pInfo
->
limit
=
pRuntimeEnv
->
pQueryAttr
->
limit
.
limit
;
pInfo
->
limit
=
pRuntimeEnv
->
pQueryAttr
->
limit
.
limit
;
...
@@ -6480,12 +6455,12 @@ SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
...
@@ -6480,12 +6455,12 @@ SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
pOperator
->
exec
=
doLimit
;
pOperator
->
exec
=
doLimit
;
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createTimeIntervalOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createTimeIntervalOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
...
@@ -6505,12 +6480,12 @@ SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOp
...
@@ -6505,12 +6480,12 @@ SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOp
pOperator
->
exec
=
doIntervalAgg
;
pOperator
->
exec
=
doIntervalAgg
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
...
@@ -6530,11 +6505,11 @@ SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv,
...
@@ -6530,11 +6505,11 @@ SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv,
pOperator
->
exec
=
doAllIntervalAgg
;
pOperator
->
exec
=
doAllIntervalAgg
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createStatewindowOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createStatewindowOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SStateWindowOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SStateWindowOperatorInfo
));
SStateWindowOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SStateWindowOperatorInfo
));
pInfo
->
colIndex
=
-
1
;
pInfo
->
colIndex
=
-
1
;
pInfo
->
reptScan
=
false
;
pInfo
->
reptScan
=
false
;
...
@@ -6554,10 +6529,10 @@ SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpe
...
@@ -6554,10 +6529,10 @@ SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpe
pOperator
->
exec
=
doStateWindowAgg
;
pOperator
->
exec
=
doStateWindowAgg
;
pOperator
->
cleanup
=
destroyStateWindowOperatorInfo
;
pOperator
->
cleanup
=
destroyStateWindowOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createSWindowOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createSWindowOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SSWindowOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SSWindowOperatorInfo
));
SSWindowOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SSWindowOperatorInfo
));
pInfo
->
binfo
.
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
binfo
.
rowCellInfoOffset
);
pInfo
->
binfo
.
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
binfo
.
rowCellInfoOffset
);
...
@@ -6579,11 +6554,11 @@ SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
...
@@ -6579,11 +6554,11 @@ SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
pOperator
->
exec
=
doSessionWindowAgg
;
pOperator
->
exec
=
doSessionWindowAgg
;
pOperator
->
cleanup
=
destroySWindowOperatorInfo
;
pOperator
->
cleanup
=
destroySWindowOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createMultiTableTimeIntervalOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createMultiTableTimeIntervalOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
...
@@ -6603,11 +6578,11 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRunti
...
@@ -6603,11 +6578,11 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRunti
pOperator
->
exec
=
doSTableIntervalAgg
;
pOperator
->
exec
=
doSTableIntervalAgg
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createAllMultiTableTimeIntervalOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createAllMultiTableTimeIntervalOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
pInfo
->
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
rowCellInfoOffset
);
...
@@ -6627,20 +6602,20 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRu
...
@@ -6627,20 +6602,20 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRu
pOperator
->
exec
=
doAllSTableIntervalAgg
;
pOperator
->
exec
=
doAllSTableIntervalAgg
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
pOperator
->
cleanup
=
destroyBasicOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createGroupbyOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createGroupbyOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SGroupbyOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SGroupbyOperatorInfo
));
SGroupbyOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SGroupbyOperatorInfo
));
pInfo
->
colIndex
=
-
1
;
// group by column index
pInfo
->
colIndex
=
-
1
;
// group by column index
pInfo
->
binfo
.
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
binfo
.
rowCellInfoOffset
);
pInfo
->
binfo
.
pCtx
=
createSQLFunctionCtx
(
pRuntimeEnv
,
pExpr
,
numOfOutput
,
&
pInfo
->
binfo
.
rowCellInfoOffset
);
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
pQueryAttr
->
resultRowSize
=
(
pQueryAttr
->
resultRowSize
*
pQueryAttr
->
resultRowSize
=
(
pQueryAttr
->
resultRowSize
*
(
int32_t
)(
getRowNumForMultioutput
(
pQueryAttr
,
pQueryAttr
->
topBotQuery
,
pQueryAttr
->
stableQuery
)));
(
int32_t
)(
getRowNumForMultioutput
(
pQueryAttr
,
pQueryAttr
->
topBotQuery
,
pQueryAttr
->
stableQuery
)));
...
@@ -6660,17 +6635,17 @@ SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
...
@@ -6660,17 +6635,17 @@ SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
pOperator
->
exec
=
hashGroupbyAggregate
;
pOperator
->
exec
=
hashGroupbyAggregate
;
pOperator
->
cleanup
=
destroyGroupbyOperatorInfo
;
pOperator
->
cleanup
=
destroyGroupbyOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createFillOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
bool
multigroupResult
)
{
SOperatorInfo
*
createFillOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
bool
multigroupResult
)
{
SFillOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SFillOperatorInfo
));
SFillOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SFillOperatorInfo
));
pInfo
->
pRes
=
createOutputBuf
(
pExpr
,
numOfOutput
,
pRuntimeEnv
->
resultInfo
.
capacity
);
pInfo
->
pRes
=
createOutputBuf
(
pExpr
,
numOfOutput
,
pRuntimeEnv
->
resultInfo
.
capacity
);
pInfo
->
multigroupResult
=
multigroupResult
;
pInfo
->
multigroupResult
=
multigroupResult
;
{
{
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
struct
SFillColInfo
*
pColInfo
=
createFillColInfo
(
pExpr
,
numOfOutput
,
pQueryAttr
->
fillVal
);
struct
SFillColInfo
*
pColInfo
=
createFillColInfo
(
pExpr
,
numOfOutput
,
pQueryAttr
->
fillVal
);
STimeWindow
w
=
TSWINDOW_INITIALIZER
;
STimeWindow
w
=
TSWINDOW_INITIALIZER
;
...
@@ -6699,14 +6674,14 @@ SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorIn
...
@@ -6699,14 +6674,14 @@ SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorIn
pOperator
->
exec
=
doFill
;
pOperator
->
exec
=
doFill
;
pOperator
->
cleanup
=
destroySFillOperatorInfo
;
pOperator
->
cleanup
=
destroySFillOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
SOperatorInfo
*
createSLimitOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
pMerger
,
bool
multigroupResult
)
{
SOperatorInfo
*
createSLimitOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
void
*
pMerger
,
bool
multigroupResult
)
{
SSLimitOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SSLimitOperatorInfo
));
SSLimitOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SSLimitOperatorInfo
));
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
pInfo
->
orderColumnList
=
getResultGroupCheckColumns
(
pQueryAttr
);
pInfo
->
orderColumnList
=
getResultGroupCheckColumns
(
pQueryAttr
);
pInfo
->
slimit
=
pQueryAttr
->
slimit
;
pInfo
->
slimit
=
pQueryAttr
->
slimit
;
...
@@ -6747,7 +6722,7 @@ SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
...
@@ -6747,7 +6722,7 @@ SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
cleanup
=
destroySlimitOperatorInfo
;
pOperator
->
cleanup
=
destroySlimitOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
...
@@ -6758,7 +6733,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
...
@@ -6758,7 +6733,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
return NULL;
return NULL;
}
}
S
Query
RuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv;
S
Task
RuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv;
int32_t maxNumOfTables = (int32_t)pRuntimeEnv->resultInfo.capacity;
int32_t maxNumOfTables = (int32_t)pRuntimeEnv->resultInfo.capacity;
STagScanInfo *pInfo = pOperator->info;
STagScanInfo *pInfo = pOperator->info;
...
@@ -6770,7 +6745,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
...
@@ -6770,7 +6745,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
int32_t functionId = getExprFunctionId(&pOperator->pExpr[0]);
int32_t functionId = getExprFunctionId(&pOperator->pExpr[0]);
if (functionId == FUNCTION_TID_TAG) { // return the tags & table Id
if (functionId == FUNCTION_TID_TAG) { // return the tags & table Id
S
Query
Attr* pQueryAttr = pRuntimeEnv->pQueryAttr;
S
Task
Attr* pQueryAttr = pRuntimeEnv->pQueryAttr;
assert(pQueryAttr->numOfOutput == 1);
assert(pQueryAttr->numOfOutput == 1);
SExprInfo* pExprInfo = &pOperator->pExpr[0];
SExprInfo* pExprInfo = &pOperator->pExpr[0];
...
@@ -6874,7 +6849,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
...
@@ -6874,7 +6849,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
}
}
if (pOperator->status == OP_EXEC_DONE) {
if (pOperator->status == OP_EXEC_DONE) {
set
Query
Status(pOperator->pRuntimeEnv, QUERY_COMPLETED);
set
Task
Status(pOperator->pRuntimeEnv, QUERY_COMPLETED);
}
}
pRes->info.rows = count;
pRes->info.rows = count;
...
@@ -6883,7 +6858,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
...
@@ -6883,7 +6858,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
#endif
#endif
}
}
SOperatorInfo
*
createTagScanOperatorInfo
(
S
Query
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createTagScanOperatorInfo
(
S
Task
RuntimeEnv
*
pRuntimeEnv
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
STagScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STagScanInfo
));
STagScanInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STagScanInfo
));
pInfo
->
pRes
=
createOutputBuf
(
pExpr
,
numOfOutput
,
pRuntimeEnv
->
resultInfo
.
capacity
);
pInfo
->
pRes
=
createOutputBuf
(
pExpr
,
numOfOutput
,
pRuntimeEnv
->
resultInfo
.
capacity
);
...
@@ -6968,9 +6943,9 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) {
...
@@ -6968,9 +6943,9 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) {
SSDataBlock
*
pBlock
=
NULL
;
SSDataBlock
*
pBlock
=
NULL
;
while
(
1
)
{
while
(
1
)
{
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
pBlock
=
pOperator
->
upstream
[
0
]
->
exec
(
pOperator
->
up
stream
[
0
],
newgroup
);
pBlock
=
pOperator
->
pDownstream
[
0
]
->
exec
(
pOperator
->
pDown
stream
[
0
],
newgroup
);
publishOperatorProfEvent
(
pOperator
->
up
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pOperator
->
pDown
stream
[
0
],
QUERY_PROF_AFTER_OPERATOR_EXEC
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
doSetOperatorCompleted
(
pOperator
);
doSetOperatorCompleted
(
pOperator
);
...
@@ -7021,7 +6996,7 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) {
...
@@ -7021,7 +6996,7 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) {
return
(
pInfo
->
pRes
->
info
.
rows
>
0
)
?
pInfo
->
pRes
:
NULL
;
return
(
pInfo
->
pRes
->
info
.
rows
>
0
)
?
pInfo
->
pRes
:
NULL
;
}
}
SOperatorInfo
*
createDistinctOperatorInfo
(
S
QueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
up
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SOperatorInfo
*
createDistinctOperatorInfo
(
S
TaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
down
stream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
SDistinctOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SDistinctOperatorInfo
));
SDistinctOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SDistinctOperatorInfo
));
pInfo
->
totalBytes
=
0
;
pInfo
->
totalBytes
=
0
;
pInfo
->
buf
=
NULL
;
pInfo
->
buf
=
NULL
;
...
@@ -7045,7 +7020,7 @@ SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperat
...
@@ -7045,7 +7020,7 @@ SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperat
pOperator
->
pExpr
=
pExpr
;
pOperator
->
pExpr
=
pExpr
;
pOperator
->
cleanup
=
destroyDistinctOperatorInfo
;
pOperator
->
cleanup
=
destroyDistinctOperatorInfo
;
appendUpstream
(
pOperator
,
up
stream
);
appendUpstream
(
pOperator
,
down
stream
);
return
pOperator
;
return
pOperator
;
}
}
...
@@ -7199,6 +7174,92 @@ static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t
...
@@ -7199,6 +7174,92 @@ static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
/**
* {
"Id": {
"QueryId": 20,
"TemplateId": 0,
"SubplanId": 0
},
"Node": {
"Name": "TableScan",
"InputSchema": [{
"Type": 9,
"ColId": 1,
"Bytes": 8
}, {
"Type": 4,
"ColId": 2,
"Bytes": 4
}, {
"Type": 8,
"ColId": 3,
"Bytes": 20
}],
"TableScan": {
"TableId": 1,
"TableType": 3,
"Flag": 0,
"Window": {
"StartKey": 0,
"EndKey": 0
}
}
},
"DataSink": {
"Name": "Dispatch",
"Dispatch": {
}
}
}
*/
int32_t
parseTaskInfo
(
const
char
*
msg
,
int32_t
len
)
{
cJSON
*
pJson
=
cJSON_Parse
(
msg
);
if
(
NULL
==
pJson
)
{
return
TSDB_CODE_INVALID_MSG
;
}
cJSON
*
pSub
=
cJSON_GetObjectItem
(
pJson
,
"ID"
);
if
(
NULL
!=
pSub
)
{
printf
(
"Id : %s
\n
"
,
pSub
->
valuestring
);
}
cJSON
*
pNode
=
cJSON_GetObjectItem
(
pJson
,
"Node"
);
if
(
pNode
==
NULL
)
{
return
TSDB_CODE_INVALID_MSG
;
}
cJSON
*
pNodeName
=
cJSON_GetObjectItem
(
pNode
,
"name"
);
if
(
pNodeName
==
NULL
)
{
return
TSDB_CODE_INVALID_MSG
;
}
printf
(
"node name is: %s
\n
"
,
pNodeName
->
valuestring
);
cJSON
*
pNodeSchema
=
cJSON_GetObjectItem
(
pNode
,
"InputSchema"
);
if
(
pNodeSchema
==
NULL
)
{
return
TSDB_CODE_INVALID_MSG
;
}
cJSON
*
pOperator
=
cJSON_GetObjectItem
(
pNode
,
pNodeName
->
valuestring
);
if
(
pOperator
==
NULL
)
{
return
TSDB_CODE_INVALID_MSG
;
}
cJSON
*
pTableId
=
cJSON_GetObjectItem
(
pOperator
,
"tableId"
);
if
(
pTableId
==
NULL
)
{
return
TSDB_CODE_INVALID_MSG
;
}
cJSON
*
pTimeWindow
=
cJSON_GetObjectItem
(
pOperator
,
"window"
);
if
(
pTimeWindow
==
NULL
)
{
return
TSDB_CODE_INVALID_MSG
;
}
}
/**
/**
* pQueryMsg->head has been converted before this function is called.
* pQueryMsg->head has been converted before this function is called.
*
*
...
@@ -7207,7 +7268,7 @@ static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t
...
@@ -7207,7 +7268,7 @@ static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t
* @param pExpr
* @param pExpr
* @return
* @return
*/
*/
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
S
Query
Param
*
param
)
{
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
S
Task
Param
*
param
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
// if (taosCheckVersion(pQueryMsg->version, version, 3) != 0) {
// if (taosCheckVersion(pQueryMsg->version, version, 3) != 0) {
...
@@ -7924,7 +7985,7 @@ void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFil
...
@@ -7924,7 +7985,7 @@ void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFil
return
NULL
;
return
NULL
;
}
}
int32_t
createFilterInfo
(
S
Query
Attr
*
pQueryAttr
,
uint64_t
qId
)
{
int32_t
createFilterInfo
(
S
Task
Attr
*
pQueryAttr
,
uint64_t
qId
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryAttr
->
numOfCols
;
++
i
)
{
// if (pQueryAttr->tableCols[i].flist.numOfFilters > 0 && pQueryAttr->tableCols[i].flist.filterInfo != NULL) {
// if (pQueryAttr->tableCols[i].flist.numOfFilters > 0 && pQueryAttr->tableCols[i].flist.filterInfo != NULL) {
// pQueryAttr->numOfFilterCols++;
// pQueryAttr->numOfFilterCols++;
...
@@ -7943,7 +8004,7 @@ int32_t createFilterInfo(SQueryAttr* pQueryAttr, uint64_t qId) {
...
@@ -7943,7 +8004,7 @@ int32_t createFilterInfo(SQueryAttr* pQueryAttr, uint64_t qId) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
doUpdateExprColumnIndex
(
S
Query
Attr
*
pQueryAttr
)
{
static
void
doUpdateExprColumnIndex
(
S
Task
Attr
*
pQueryAttr
)
{
assert
(
pQueryAttr
->
pExpr1
!=
NULL
&&
pQueryAttr
!=
NULL
);
assert
(
pQueryAttr
->
pExpr1
!=
NULL
&&
pQueryAttr
!=
NULL
);
for
(
int32_t
k
=
0
;
k
<
pQueryAttr
->
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQueryAttr
->
numOfOutput
;
++
k
)
{
...
@@ -7980,7 +8041,7 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) {
...
@@ -7980,7 +8041,7 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) {
}
}
}
}
void
setResultBufSize
(
S
Query
Attr
*
pQueryAttr
,
SRspResultInfo
*
pResultInfo
)
{
void
setResultBufSize
(
S
Task
Attr
*
pQueryAttr
,
SRspResultInfo
*
pResultInfo
)
{
const
int32_t
DEFAULT_RESULT_MSG_SIZE
=
1024
*
(
1024
+
512
);
const
int32_t
DEFAULT_RESULT_MSG_SIZE
=
1024
*
(
1024
+
512
);
// the minimum number of rows for projection query
// the minimum number of rows for projection query
...
@@ -8026,7 +8087,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
...
@@ -8026,7 +8087,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
// to make sure third party won't overwrite this structure
// to make sure third party won't overwrite this structure
pQInfo
->
signature
=
pQInfo
;
pQInfo
->
signature
=
pQInfo
;
S
Query
Attr
*
pQueryAttr
=
&
pQInfo
->
query
;
S
Task
Attr
*
pQueryAttr
=
&
pQInfo
->
query
;
pQInfo
->
runtimeEnv
.
pQueryAttr
=
pQueryAttr
;
pQInfo
->
runtimeEnv
.
pQueryAttr
=
pQueryAttr
;
pQueryAttr
->
tableGroupInfo
=
*
pTableGroupInfo
;
pQueryAttr
->
tableGroupInfo
=
*
pTableGroupInfo
;
...
@@ -8145,7 +8206,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
...
@@ -8145,7 +8206,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
pQueryAttr
->
window
=
pQueryMsg
->
window
;
pQueryAttr
->
window
=
pQueryMsg
->
window
;
updateDataCheckOrder
(
pQInfo
,
pQueryMsg
,
pQueryAttr
->
stableQuery
);
updateDataCheckOrder
(
pQInfo
,
pQueryMsg
,
pQueryAttr
->
stableQuery
);
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
STimeWindow
window
=
pQueryAttr
->
window
;
STimeWindow
window
=
pQueryAttr
->
window
;
int32_t
index
=
0
;
int32_t
index
=
0
;
...
@@ -8213,7 +8274,7 @@ _cleanup_qinfo:
...
@@ -8213,7 +8274,7 @@ _cleanup_qinfo:
// filterFreeInfo(pFilters);
// filterFreeInfo(pFilters);
_cleanup:
_cleanup:
freeQInfo
(
pQInfo
);
doDestroyTask
(
pQInfo
);
return
NULL
;
return
NULL
;
}
}
...
@@ -8231,14 +8292,14 @@ bool isValidQInfo(void *param) {
...
@@ -8231,14 +8292,14 @@ bool isValidQInfo(void *param) {
return
(
sig
==
(
uint64_t
)
pQInfo
);
return
(
sig
==
(
uint64_t
)
pQInfo
);
}
}
int32_t
initQInfo
(
STsBufInfo
*
pTsBufInfo
,
void
*
tsdb
,
void
*
sourceOptr
,
SQInfo
*
pQInfo
,
S
Query
Param
*
param
,
char
*
start
,
int32_t
initQInfo
(
STsBufInfo
*
pTsBufInfo
,
void
*
tsdb
,
void
*
sourceOptr
,
SQInfo
*
pQInfo
,
S
Task
Param
*
param
,
char
*
start
,
int32_t
prevResultLen
,
void
*
merger
)
{
int32_t
prevResultLen
,
void
*
merger
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
pRuntimeEnv
->
qinfo
=
pQInfo
;
pRuntimeEnv
->
qinfo
=
pQInfo
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
STSBuf
*
pTsBuf
=
NULL
;
STSBuf
*
pTsBuf
=
NULL
;
...
@@ -8271,7 +8332,7 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo*
...
@@ -8271,7 +8332,7 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo*
(
!
QUERY_IS_ASC_QUERY
(
pQueryAttr
)
&&
(
pQueryAttr
->
window
.
ekey
>
pQueryAttr
->
window
.
skey
)))
{
(
!
QUERY_IS_ASC_QUERY
(
pQueryAttr
)
&&
(
pQueryAttr
->
window
.
ekey
>
pQueryAttr
->
window
.
skey
)))
{
//qDebug("QInfo:0x%"PRIx64" no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo->qId, pQueryAttr->window.skey,
//qDebug("QInfo:0x%"PRIx64" no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo->qId, pQueryAttr->window.skey,
// pQueryAttr->window.ekey, pQueryAttr->order.order);
// pQueryAttr->window.ekey, pQueryAttr->order.order);
setQueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_COMPLETED);
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
=
0
;
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
=
0
;
// todo free memory
// todo free memory
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -8279,7 +8340,7 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo*
...
@@ -8279,7 +8340,7 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo*
if
(
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
==
0
)
{
if
(
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
==
0
)
{
//qDebug("QInfo:0x%"PRIx64" no table qualified for tag filter, abort query", pQInfo->qId);
//qDebug("QInfo:0x%"PRIx64" no table qualified for tag filter, abort query", pQInfo->qId);
setQueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_COMPLETED);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -8292,7 +8353,7 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo*
...
@@ -8292,7 +8353,7 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo*
_error:
_error:
// table query ref will be decrease during error handling
// table query ref will be decrease during error handling
freeQInfo
(
pQInfo
);
doDestroyTask
(
pQInfo
);
return
code
;
return
code
;
}
}
...
@@ -8373,20 +8434,20 @@ void* freeColumnInfo(SColumnInfo* pColumnInfo, int32_t numOfCols) {
...
@@ -8373,20 +8434,20 @@ void* freeColumnInfo(SColumnInfo* pColumnInfo, int32_t numOfCols) {
return
NULL
;
return
NULL
;
}
}
void
freeQInfo
(
SQInfo
*
pQInfo
)
{
void
doDestroyTask
(
SQInfo
*
pQInfo
)
{
if
(
!
isValidQInfo
(
pQInfo
))
{
if
(
!
isValidQInfo
(
pQInfo
))
{
return
;
return
;
}
}
//qDebug("QInfo:0x%"PRIx64" start to free QInfo", pQInfo->qId);
//qDebug("QInfo:0x%"PRIx64" start to free QInfo", pQInfo->qId);
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
releaseQueryBuf
(
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
);
releaseQueryBuf
(
pRuntimeEnv
->
tableqinfoGroupInfo
.
numOfTables
);
doDestroyTableQueryInfo
(
&
pRuntimeEnv
->
tableqinfoGroupInfo
);
doDestroyTableQueryInfo
(
&
pRuntimeEnv
->
tableqinfoGroupInfo
);
teardownQueryRuntimeEnv
(
&
pQInfo
->
runtimeEnv
);
teardownQueryRuntimeEnv
(
&
pQInfo
->
runtimeEnv
);
S
Query
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
freeQueryAttr
(
pQueryAttr
);
freeQueryAttr
(
pQueryAttr
);
// tsdbDestroyTableGroup(&pQueryAttr->tableGroupInfo);
// tsdbDestroyTableGroup(&pQueryAttr->tableGroupInfo);
...
@@ -8407,8 +8468,8 @@ void freeQInfo(SQInfo *pQInfo) {
...
@@ -8407,8 +8468,8 @@ void freeQInfo(SQInfo *pQInfo) {
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
)
{
// the remained number of retrieved rows, not the interpolated result
// the remained number of retrieved rows, not the interpolated result
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pQInfo
->
runtimeEnv
.
pQueryAttr
;
// load data from file to msg buffer
// load data from file to msg buffer
if
(
pQueryAttr
->
tsCompQuery
)
{
if
(
pQueryAttr
->
tsCompQuery
)
{
...
@@ -8445,7 +8506,7 @@ int32_t doDumpQueryResult(SQInfo *pQInfo, char *data, int8_t compressed, int32_t
...
@@ -8445,7 +8506,7 @@ int32_t doDumpQueryResult(SQInfo *pQInfo, char *data, int8_t compressed, int32_t
// all data returned, set query over
// all data returned, set query over
if
(
Q_STATUS_EQUAL
(
pRuntimeEnv
->
status
,
QUERY_COMPLETED
))
{
if
(
Q_STATUS_EQUAL
(
pRuntimeEnv
->
status
,
QUERY_COMPLETED
))
{
setQueryStatus
(
pRuntimeEnv
,
QUERY_OVER
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_OVER);
}
}
}
else
{
}
else
{
doCopyQueryResultToMsg
(
pQInfo
,
(
int32_t
)
pRuntimeEnv
->
outputBuf
->
info
.
rows
,
data
,
compressed
,
compLen
);
doCopyQueryResultToMsg
(
pQInfo
,
(
int32_t
)
pRuntimeEnv
->
outputBuf
->
info
.
rows
,
data
,
compressed
,
compLen
);
...
@@ -8456,7 +8517,7 @@ int32_t doDumpQueryResult(SQInfo *pQInfo, char *data, int8_t compressed, int32_t
...
@@ -8456,7 +8517,7 @@ int32_t doDumpQueryResult(SQInfo *pQInfo, char *data, int8_t compressed, int32_t
if
(
pQueryAttr
->
limit
.
limit
>
0
&&
pQueryAttr
->
limit
.
limit
==
pRuntimeEnv
->
resultInfo
.
total
)
{
if
(
pQueryAttr
->
limit
.
limit
>
0
&&
pQueryAttr
->
limit
.
limit
==
pRuntimeEnv
->
resultInfo
.
total
)
{
//qDebug("QInfo:0x%"PRIx64" results limitation reached, limitation:%"PRId64, pQInfo->qId, pQueryAttr->limit.limit);
//qDebug("QInfo:0x%"PRIx64" results limitation reached, limitation:%"PRId64, pQInfo->qId, pQueryAttr->limit.limit);
setQueryStatus
(
pRuntimeEnv
,
QUERY_OVER
);
// setTaskStatus(pOperator->pTaskInfo
, QUERY_OVER);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -8535,8 +8596,8 @@ int32_t checkForQueryBuf(size_t numOfTables) {
...
@@ -8535,8 +8596,8 @@ int32_t checkForQueryBuf(size_t numOfTables) {
}
}
bool
checkNeedToCompressQueryCol
(
SQInfo
*
pQInfo
)
{
bool
checkNeedToCompressQueryCol
(
SQInfo
*
pQInfo
)
{
S
Query
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Task
RuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
S
Query
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
S
Task
Attr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SSDataBlock
*
pRes
=
pRuntimeEnv
->
outputBuf
;
SSDataBlock
*
pRes
=
pRuntimeEnv
->
outputBuf
;
...
@@ -8569,7 +8630,7 @@ void releaseQueryBuf(size_t numOfTables) {
...
@@ -8569,7 +8630,7 @@ void releaseQueryBuf(size_t numOfTables) {
atomic_add_fetch_64
(
&
tsQueryBufferSizeBytes
,
t
);
atomic_add_fetch_64
(
&
tsQueryBufferSizeBytes
,
t
);
}
}
void
freeQueryAttr
(
S
Query
Attr
*
pQueryAttr
)
{
void
freeQueryAttr
(
S
Task
Attr
*
pQueryAttr
)
{
if
(
pQueryAttr
!=
NULL
)
{
if
(
pQueryAttr
!=
NULL
)
{
if
(
pQueryAttr
->
fillVal
!=
NULL
)
{
if
(
pQueryAttr
->
fillVal
!=
NULL
)
{
tfree
(
pQueryAttr
->
fillVal
);
tfree
(
pQueryAttr
->
fillVal
);
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
95347ff6
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "index.h"
#include "index.h"
#include "index_fst.h"
#include "index_fst.h"
#include "taos.h"
#include "taos.h"
#include "tchecksum.h"
#include "thash.h"
#include "thash.h"
#include "tlog.h"
#include "tlog.h"
...
...
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
95347ff6
...
@@ -34,6 +34,7 @@ typedef struct WriterCtx {
...
@@ -34,6 +34,7 @@ typedef struct WriterCtx {
int
(
*
read
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
read
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
flush
)(
struct
WriterCtx
*
ctx
);
int
(
*
flush
)(
struct
WriterCtx
*
ctx
);
int
(
*
readFrom
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
);
int
(
*
readFrom
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
);
int
(
*
size
)(
struct
WriterCtx
*
ctx
);
WriterType
type
;
WriterType
type
;
union
{
union
{
struct
{
struct
{
...
...
source/libs/index/src/index.c
浏览文件 @
95347ff6
...
@@ -34,7 +34,10 @@ void indexInit() {
...
@@ -34,7 +34,10 @@ void indexInit() {
// refactor later
// refactor later
indexQhandle
=
taosInitScheduler
(
INDEX_QUEUE_SIZE
,
INDEX_NUM_OF_THREADS
,
"index"
);
indexQhandle
=
taosInitScheduler
(
INDEX_QUEUE_SIZE
,
INDEX_NUM_OF_THREADS
,
"index"
);
}
}
void
indexCleanUp
()
{
taosCleanUpScheduler
(
indexQhandle
);
}
void
indexCleanUp
()
{
// refacto later
taosCleanUpScheduler
(
indexQhandle
);
}
static
int
uidCompare
(
const
void
*
a
,
const
void
*
b
)
{
static
int
uidCompare
(
const
void
*
a
,
const
void
*
b
)
{
// add more version compare
// add more version compare
...
...
source/libs/index/src/index_cache.c
浏览文件 @
95347ff6
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MEM_TERM_LIMIT 10 * 10000
#define MEM_TERM_LIMIT 10 * 10000
#define MEM_THRESHOLD 1024 * 1024
* 2
#define MEM_THRESHOLD 1024 * 1024
#define MEM_ESTIMATE_RADIO 1.5
#define MEM_ESTIMATE_RADIO 1.5
static
void
indexMemRef
(
MemTable
*
tbl
);
static
void
indexMemRef
(
MemTable
*
tbl
);
...
...
source/libs/index/src/index_fst.c
浏览文件 @
95347ff6
...
@@ -935,7 +935,10 @@ Fst* fstCreate(FstSlice* slice) {
...
@@ -935,7 +935,10 @@ Fst* fstCreate(FstSlice* slice) {
uint32_t
checkSum
=
0
;
uint32_t
checkSum
=
0
;
len
-=
sizeof
(
checkSum
);
len
-=
sizeof
(
checkSum
);
taosDecodeFixedU32
(
buf
+
len
,
&
checkSum
);
taosDecodeFixedU32
(
buf
+
len
,
&
checkSum
);
if
(
taosCheckChecksum
(
buf
,
len
,
checkSum
))
{
// verify fst
return
NULL
;
}
CompiledAddr
rootAddr
;
CompiledAddr
rootAddr
;
len
-=
sizeof
(
rootAddr
);
len
-=
sizeof
(
rootAddr
);
taosDecodeFixedU64
(
buf
+
len
,
&
rootAddr
);
taosDecodeFixedU64
(
buf
+
len
,
&
rootAddr
);
...
...
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
95347ff6
...
@@ -59,6 +59,13 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
...
@@ -59,6 +59,13 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
}
}
return
nRead
;
return
nRead
;
}
}
static
int
writeCtxGetSize
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
&&
ctx
->
file
.
readOnly
)
{
// refactor later
return
ctx
->
file
.
size
;
}
return
0
;
}
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
// taosFsyncFile(ctx->file.fd);
// taosFsyncFile(ctx->file.fd);
...
@@ -109,6 +116,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
...
@@ -109,6 +116,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
ctx
->
read
=
writeCtxDoRead
;
ctx
->
read
=
writeCtxDoRead
;
ctx
->
flush
=
writeCtxDoFlush
;
ctx
->
flush
=
writeCtxDoFlush
;
ctx
->
readFrom
=
writeCtxDoReadFrom
;
ctx
->
readFrom
=
writeCtxDoReadFrom
;
ctx
->
size
=
writeCtxGetSize
;
ctx
->
offset
=
0
;
ctx
->
offset
=
0
;
ctx
->
limit
=
capacity
;
ctx
->
limit
=
capacity
;
...
@@ -159,6 +167,8 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len)
...
@@ -159,6 +167,8 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len)
int
nWrite
=
ctx
->
write
(
ctx
,
buf
,
len
);
int
nWrite
=
ctx
->
write
(
ctx
,
buf
,
len
);
assert
(
nWrite
==
len
);
assert
(
nWrite
==
len
);
write
->
count
+=
len
;
write
->
count
+=
len
;
write
->
summer
=
taosCalcChecksum
(
write
->
summer
,
buf
,
len
);
return
len
;
return
len
;
}
}
int
fstCountingWriterRead
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
int
fstCountingWriterRead
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
...
@@ -169,7 +179,10 @@ int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len)
...
@@ -169,7 +179,10 @@ int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len)
return
nRead
;
return
nRead
;
}
}
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
return
0
;
}
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
// opt
return
write
->
summer
;
}
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
WriterCtx
*
ctx
=
write
->
wrt
;
WriterCtx
*
ctx
=
write
->
wrt
;
...
...
source/libs/index/src/index_tfile.c
浏览文件 @
95347ff6
...
@@ -21,8 +21,11 @@ p *
...
@@ -21,8 +21,11 @@ p *
#include "index_fst_counting_writer.h"
#include "index_fst_counting_writer.h"
#include "index_util.h"
#include "index_util.h"
#include "taosdef.h"
#include "taosdef.h"
#include "tcoding.h"
#include "tcompare.h"
#include "tcompare.h"
const
static
uint64_t
tfileMagicNumber
=
0xdb4775248b80fb57ull
;
typedef
struct
TFileFstIter
{
typedef
struct
TFileFstIter
{
FstStreamBuilder
*
fb
;
FstStreamBuilder
*
fb
;
StreamWithState
*
st
;
StreamWithState
*
st
;
...
@@ -40,9 +43,12 @@ static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds);
...
@@ -40,9 +43,12 @@ static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds);
static
int
tfileWriteHeader
(
TFileWriter
*
writer
);
static
int
tfileWriteHeader
(
TFileWriter
*
writer
);
static
int
tfileWriteFstOffset
(
TFileWriter
*
tw
,
int32_t
offset
);
static
int
tfileWriteFstOffset
(
TFileWriter
*
tw
,
int32_t
offset
);
static
int
tfileWriteData
(
TFileWriter
*
write
,
TFileValue
*
tval
);
static
int
tfileWriteData
(
TFileWriter
*
write
,
TFileValue
*
tval
);
static
int
tfileWriteFooter
(
TFileWriter
*
write
);
// handle file corrupt later
static
int
tfileReaderLoadHeader
(
TFileReader
*
reader
);
static
int
tfileReaderLoadHeader
(
TFileReader
*
reader
);
static
int
tfileReaderLoadFst
(
TFileReader
*
reader
);
static
int
tfileReaderLoadFst
(
TFileReader
*
reader
);
static
int
tfileReaderVerify
(
TFileReader
*
reader
);
static
int
tfileReaderLoadTableIds
(
TFileReader
*
reader
,
int32_t
offset
,
SArray
*
result
);
static
int
tfileReaderLoadTableIds
(
TFileReader
*
reader
,
int32_t
offset
,
SArray
*
result
);
static
SArray
*
tfileGetFileList
(
const
char
*
path
);
static
SArray
*
tfileGetFileList
(
const
char
*
path
);
...
@@ -138,8 +144,14 @@ TFileReader* tfileReaderCreate(WriterCtx* ctx) {
...
@@ -138,8 +144,14 @@ TFileReader* tfileReaderCreate(WriterCtx* ctx) {
TFileReader
*
reader
=
calloc
(
1
,
sizeof
(
TFileReader
));
TFileReader
*
reader
=
calloc
(
1
,
sizeof
(
TFileReader
));
if
(
reader
==
NULL
)
{
return
NULL
;
}
if
(
reader
==
NULL
)
{
return
NULL
;
}
// T_REF_INC(reader);
reader
->
ctx
=
ctx
;
reader
->
ctx
=
ctx
;
if
(
0
!=
tfileReaderVerify
(
reader
))
{
tfileReaderDestroy
(
reader
);
indexError
(
"invalid tfile, suid: %"
PRIu64
", colName: %s"
,
reader
->
header
.
suid
,
reader
->
header
.
colName
);
return
NULL
;
}
// T_REF_INC(reader);
if
(
0
!=
tfileReaderLoadHeader
(
reader
))
{
if
(
0
!=
tfileReaderLoadHeader
(
reader
))
{
tfileReaderDestroy
(
reader
);
tfileReaderDestroy
(
reader
);
indexError
(
"failed to load index header, suid: %"
PRIu64
", colName: %s"
,
reader
->
header
.
suid
,
indexError
(
"failed to load index header, suid: %"
PRIu64
", colName: %s"
,
reader
->
header
.
suid
,
...
@@ -296,6 +308,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) {
...
@@ -296,6 +308,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) {
fstBuilderFinish
(
tw
->
fb
);
fstBuilderFinish
(
tw
->
fb
);
fstBuilderDestroy
(
tw
->
fb
);
fstBuilderDestroy
(
tw
->
fb
);
tw
->
fb
=
NULL
;
tw
->
fb
=
NULL
;
tfileWriteFooter
(
tw
);
return
0
;
return
0
;
}
}
void
tfileWriterClose
(
TFileWriter
*
tw
)
{
void
tfileWriterClose
(
TFileWriter
*
tw
)
{
...
@@ -502,6 +516,14 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) {
...
@@ -502,6 +516,14 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) {
}
}
return
0
;
return
0
;
}
}
static
int
tfileWriteFooter
(
TFileWriter
*
write
)
{
char
buf
[
sizeof
(
tfileMagicNumber
)
+
1
]
=
{
0
};
void
*
pBuf
=
(
void
*
)
buf
;
taosEncodeFixedU64
((
void
**
)(
void
*
)
&
pBuf
,
tfileMagicNumber
);
int
nwrite
=
write
->
ctx
->
write
(
write
->
ctx
,
buf
,
strlen
(
buf
));
assert
(
nwrite
==
sizeof
(
tfileMagicNumber
));
return
nwrite
;
}
static
int
tfileReaderLoadHeader
(
TFileReader
*
reader
)
{
static
int
tfileReaderLoadHeader
(
TFileReader
*
reader
)
{
// TODO simple tfile header later
// TODO simple tfile header later
char
buf
[
TFILE_HEADER_SIZE
]
=
{
0
};
char
buf
[
TFILE_HEADER_SIZE
]
=
{
0
};
...
@@ -527,9 +549,14 @@ static int tfileReaderLoadFst(TFileReader* reader) {
...
@@ -527,9 +549,14 @@ static int tfileReaderLoadFst(TFileReader* reader) {
if
(
buf
==
NULL
)
{
return
-
1
;
}
if
(
buf
==
NULL
)
{
return
-
1
;
}
WriterCtx
*
ctx
=
reader
->
ctx
;
WriterCtx
*
ctx
=
reader
->
ctx
;
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
buf
,
FST_MAX_SIZE
,
reader
->
header
.
fstOffset
);
int
size
=
ctx
->
size
(
ctx
);
indexInfo
(
"nread = %d, and fst offset=%d, filename: %s, size: %d "
,
nread
,
reader
->
header
.
fstOffset
,
ctx
->
file
.
buf
,
ctx
->
file
.
size
);
int64_t
ts
=
taosGetTimestampUs
();
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
buf
,
size
-
reader
->
header
.
fstOffset
-
sizeof
(
tfileMagicNumber
),
reader
->
header
.
fstOffset
);
int64_t
cost
=
taosGetTimestampUs
()
-
ts
;
indexInfo
(
"nread = %d, and fst offset=%d, filename: %s, size: %d, time cost: %"
PRId64
"us"
,
nread
,
reader
->
header
.
fstOffset
,
ctx
->
file
.
buf
,
ctx
->
file
.
size
,
cost
);
// we assuse fst size less than FST_MAX_SIZE
// we assuse fst size less than FST_MAX_SIZE
assert
(
nread
>
0
&&
nread
<
FST_MAX_SIZE
);
assert
(
nread
>
0
&&
nread
<
FST_MAX_SIZE
);
...
@@ -558,6 +585,25 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
...
@@ -558,6 +585,25 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
free
(
buf
);
free
(
buf
);
return
0
;
return
0
;
}
}
static
int
tfileReaderVerify
(
TFileReader
*
reader
)
{
// just validate header and Footer, file corrupted also shuild be verified later
WriterCtx
*
ctx
=
reader
->
ctx
;
uint64_t
tMagicNumber
=
0
;
char
buf
[
sizeof
(
tMagicNumber
)
+
1
]
=
{
0
};
int
size
=
ctx
->
size
(
ctx
);
if
(
size
<
sizeof
(
tMagicNumber
)
||
size
<=
sizeof
(
reader
->
header
))
{
return
-
1
;
}
else
if
(
ctx
->
readFrom
(
ctx
,
buf
,
sizeof
(
tMagicNumber
),
size
-
sizeof
(
tMagicNumber
))
!=
sizeof
(
tMagicNumber
))
{
return
-
1
;
}
taosDecodeFixedU64
(
buf
,
&
tMagicNumber
);
return
tMagicNumber
==
tfileMagicNumber
?
0
:
-
1
;
}
void
tfileReaderRef
(
TFileReader
*
reader
)
{
void
tfileReaderRef
(
TFileReader
*
reader
)
{
if
(
reader
==
NULL
)
{
return
;
}
if
(
reader
==
NULL
)
{
return
;
}
int
ref
=
T_REF_INC
(
reader
);
int
ref
=
T_REF_INC
(
reader
);
...
...
source/libs/index/test/fstTest.cc
浏览文件 @
95347ff6
#include <algorithm>
#include <iostream>
#include <iostream>
#include <string>
#include <string>
#include <thread>
#include <thread>
...
@@ -12,7 +13,6 @@
...
@@ -12,7 +13,6 @@
#include "index_tfile.h"
#include "index_tfile.h"
#include "tskiplist.h"
#include "tskiplist.h"
#include "tutil.h"
#include "tutil.h"
void
*
callback
(
void
*
s
)
{
return
s
;
}
void
*
callback
(
void
*
s
)
{
return
s
;
}
static
std
::
string
fileName
=
"/tmp/tindex.tindex"
;
static
std
::
string
fileName
=
"/tmp/tindex.tindex"
;
...
@@ -293,7 +293,7 @@ void validateTFile(char* arg) {
...
@@ -293,7 +293,7 @@ void validateTFile(char* arg) {
std
::
thread
threads
[
NUM_OF_THREAD
];
std
::
thread
threads
[
NUM_OF_THREAD
];
// std::vector<std::thread> threads;
// std::vector<std::thread> threads;
TFileReader
*
reader
=
tfileReaderOpen
(
arg
,
0
,
999992
,
"tag1"
);
TFileReader
*
reader
=
tfileReaderOpen
(
arg
,
0
,
20000000
,
"tag1"
);
for
(
int
i
=
0
;
i
<
NUM_OF_THREAD
;
i
++
)
{
for
(
int
i
=
0
;
i
<
NUM_OF_THREAD
;
i
++
)
{
threads
[
i
]
=
std
::
thread
(
fst_get
,
reader
->
fst
);
threads
[
i
]
=
std
::
thread
(
fst_get
,
reader
->
fst
);
...
@@ -306,13 +306,41 @@ void validateTFile(char* arg) {
...
@@ -306,13 +306,41 @@ void validateTFile(char* arg) {
}
}
tfCleanup
();
tfCleanup
();
}
}
void
iterTFileReader
(
char
*
path
,
char
*
ver
)
{
tfInit
();
int
version
=
atoi
(
ver
);
TFileReader
*
reader
=
tfileReaderOpen
(
path
,
0
,
version
,
"tag1"
);
Iterate
*
iter
=
tfileIteratorCreate
(
reader
);
bool
tn
=
iter
?
iter
->
next
(
iter
)
:
false
;
int
count
=
0
;
int
termCount
=
0
;
while
(
tn
==
true
)
{
count
++
;
IterateValue
*
cv
=
iter
->
getValue
(
iter
);
termCount
+=
(
int
)
taosArrayGetSize
(
cv
->
val
);
printf
(
"col val: %s, size: %d
\n
"
,
cv
->
colVal
,
(
int
)
taosArrayGetSize
(
cv
->
val
));
tn
=
iter
->
next
(
iter
);
}
printf
(
"total size: %d
\n
term count: %d
\n
"
,
count
,
termCount
);
tfileIteratorDestroy
(
iter
);
tfCleanup
();
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
// tool to check all kind of fst test
// tool to check all kind of fst test
// if (argc > 1) { validateTFile(argv[1]); }
// if (argc > 1) { validateTFile(argv[1]); }
if
(
argc
>
2
)
{
// opt
iterTFileReader
(
argv
[
1
],
argv
[
2
]);
}
// checkFstCheckIterator();
// checkFstCheckIterator();
// checkFstLongTerm();
// checkFstLongTerm();
// checkFstPrefixSearch();
// checkFstPrefixSearch();
checkMillonWriteAndReadOfFst
();
// checkMillonWriteAndReadOfFst();
return
1
;
return
1
;
}
}
source/libs/index/test/indexTests.cc
浏览文件 @
95347ff6
...
@@ -665,14 +665,19 @@ class IndexObj {
...
@@ -665,14 +665,19 @@ class IndexObj {
size_t
numOfTable
=
100
*
10000
)
{
size_t
numOfTable
=
100
*
10000
)
{
std
::
string
tColVal
=
colVal
;
std
::
string
tColVal
=
colVal
;
size_t
colValSize
=
tColVal
.
size
();
size_t
colValSize
=
tColVal
.
size
();
int
skip
=
100
;
numOfTable
/=
skip
;
for
(
int
i
=
0
;
i
<
numOfTable
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfTable
;
i
++
)
{
tColVal
[
i
%
colValSize
]
=
'a'
+
i
%
26
;
for
(
int
k
=
0
;
k
<
10
&&
k
<
colVal
.
size
();
k
++
)
{
// opt
tColVal
[
rand
()
%
colValSize
]
=
'a'
+
k
%
26
;
}
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
tColVal
.
c_str
(),
tColVal
.
size
());
tColVal
.
c_str
(),
tColVal
.
size
());
SIndexMultiTerm
*
terms
=
indexMultiTermCreate
();
SIndexMultiTerm
*
terms
=
indexMultiTermCreate
();
indexMultiTermAdd
(
terms
,
term
);
indexMultiTermAdd
(
terms
,
term
);
for
(
size_t
i
=
0
;
i
<
10
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
skip
;
j
++
)
{
int
ret
=
Put
(
terms
,
i
);
int
ret
=
Put
(
terms
,
j
);
assert
(
ret
==
0
);
assert
(
ret
==
0
);
}
}
indexMultiTermDestroy
(
terms
);
indexMultiTermDestroy
(
terms
);
...
@@ -939,10 +944,11 @@ TEST_F(IndexEnv2, testIndex_read_performance) {
...
@@ -939,10 +944,11 @@ TEST_F(IndexEnv2, testIndex_read_performance) {
TEST_F
(
IndexEnv2
,
testIndexMultiTag
)
{
TEST_F
(
IndexEnv2
,
testIndexMultiTag
)
{
std
::
string
path
=
"/tmp/multi_tag"
;
std
::
string
path
=
"/tmp/multi_tag"
;
if
(
index
->
Init
(
path
)
!=
0
)
{}
if
(
index
->
Init
(
path
)
!=
0
)
{}
index
->
WriteMultiMillonData
(
"tag1"
,
"Hello"
,
100
*
10000
);
int64_t
st
=
taosGetTimestampUs
();
index
->
WriteMultiMillonData
(
"tag2"
,
"Test"
,
100
*
10000
);
int32_t
num
=
1000
*
10000
;
index
->
WriteMultiMillonData
(
"tag3"
,
"Test"
,
100
*
10000
);
index
->
WriteMultiMillonData
(
"tag1"
,
"xxxxxxxxxxxxxxx"
,
num
);
index
->
WriteMultiMillonData
(
"tag4"
,
"Test"
,
100
*
10000
);
std
::
cout
<<
"numOfRow: "
<<
num
<<
"
\t
time cost:"
<<
taosGetTimestampUs
()
-
st
<<
std
::
endl
;
// index->WriteMultiMillonData("tag2", "xxxxxxxxxxxxxxxxxxxxxxxxx", 100 * 10000);
}
}
TEST_F
(
IndexEnv2
,
testLongComVal
)
{
TEST_F
(
IndexEnv2
,
testLongComVal
)
{
std
::
string
path
=
"/tmp/long_colVal"
;
std
::
string
path
=
"/tmp/long_colVal"
;
...
...
source/libs/parser/src/astValidate.c
浏览文件 @
95347ff6
...
@@ -3952,7 +3952,8 @@ int32_t qParserValidateSqlNode(SParseBasicCtx *pCtx, SSqlInfo* pInfo, SQueryStmt
...
@@ -3952,7 +3952,8 @@ int32_t qParserValidateSqlNode(SParseBasicCtx *pCtx, SSqlInfo* pInfo, SQueryStmt
pQueryInfo
->
pTableMetaInfo
[
0
]
->
pTableMeta
=
pmt
;
pQueryInfo
->
pTableMetaInfo
[
0
]
->
pTableMeta
=
pmt
;
pQueryInfo
->
pTableMetaInfo
[
0
]
->
name
=
*
name
;
pQueryInfo
->
pTableMetaInfo
[
0
]
->
name
=
*
name
;
pQueryInfo
->
numOfTables
=
1
;
pQueryInfo
->
numOfTables
=
1
;
pQueryInfo
->
pTableMetaInfo
[
0
]
->
tagColList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
code
=
setTableVgroupList
(
pCtx
,
name
,
&
pQueryInfo
->
pTableMetaInfo
[
0
]
->
vgroupList
);
code
=
setTableVgroupList
(
pCtx
,
name
,
&
pQueryInfo
->
pTableMetaInfo
[
0
]
->
vgroupList
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosArrayDestroy
(
data
.
pTableMeta
);
taosArrayDestroy
(
data
.
pTableMeta
);
...
...
source/libs/planner/inc/plannerInt.h
浏览文件 @
95347ff6
...
@@ -106,7 +106,7 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str);
...
@@ -106,7 +106,7 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str);
int32_t
queryPlanToSql
(
struct
SQueryPlanNode
*
pQueryNode
,
char
**
sql
);
int32_t
queryPlanToSql
(
struct
SQueryPlanNode
*
pQueryNode
,
char
**
sql
);
int32_t
createDag
(
SQueryPlanNode
*
pQueryNode
,
struct
SCatalog
*
pCatalog
,
SQueryDag
**
pDag
,
uint64_t
requestId
);
int32_t
createDag
(
SQueryPlanNode
*
pQueryNode
,
struct
SCatalog
*
pCatalog
,
SQueryDag
**
pDag
,
uint64_t
requestId
);
int32_t
setSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
ep
);
void
setSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
ep
);
int32_t
subPlanToString
(
const
SSubplan
*
pPhyNode
,
char
**
str
,
int32_t
*
len
);
int32_t
subPlanToString
(
const
SSubplan
*
pPhyNode
,
char
**
str
,
int32_t
*
len
);
int32_t
stringToSubplan
(
const
char
*
str
,
SSubplan
**
subplan
);
int32_t
stringToSubplan
(
const
char
*
str
,
SSubplan
**
subplan
);
...
...
source/libs/planner/src/physicalPlan.c
浏览文件 @
95347ff6
...
@@ -75,24 +75,16 @@ int32_t dsinkNameToDsinkType(const char* name) {
...
@@ -75,24 +75,16 @@ int32_t dsinkNameToDsinkType(const char* name) {
return
DSINK_Unknown
;
return
DSINK_Unknown
;
}
}
static
SDataSink
*
initDataSink
(
int32_t
type
,
int32_t
size
)
{
static
bool
copySchema
(
SDataBlockSchema
*
dst
,
const
SDataBlockSchema
*
src
)
{
SDataSink
*
sink
=
(
SDataSink
*
)
validPointer
(
calloc
(
1
,
size
));
dst
->
pSchema
=
malloc
(
sizeof
(
SSlotSchema
)
*
src
->
numOfCols
);
sink
->
info
.
type
=
type
;
if
(
NULL
==
dst
->
pSchema
)
{
sink
->
info
.
name
=
dsinkTypeToDsinkName
(
type
);
return
false
;
return
sink
;
}
}
memcpy
(
dst
->
pSchema
,
src
->
pSchema
,
sizeof
(
SSlotSchema
)
*
src
->
numOfCols
);
dst
->
numOfCols
=
src
->
numOfCols
;
static
SDataSink
*
createDataDispatcher
(
SPlanContext
*
pCxt
,
SQueryPlanNode
*
pPlanNode
)
{
dst
->
resultRowSize
=
src
->
resultRowSize
;
SDataDispatcher
*
dispatcher
=
(
SDataDispatcher
*
)
initDataSink
(
DSINK_Dispatch
,
sizeof
(
SDataDispatcher
));
dst
->
precision
=
src
->
precision
;
return
(
SDataSink
*
)
dispatcher
;
return
true
;
}
static
SDataSink
*
createDataInserter
(
SPlanContext
*
pCxt
,
SVgDataBlocks
*
pBlocks
)
{
SDataInserter
*
inserter
=
(
SDataInserter
*
)
initDataSink
(
DSINK_Insert
,
sizeof
(
SDataInserter
));
inserter
->
numOfTables
=
pBlocks
->
numOfTables
;
inserter
->
size
=
pBlocks
->
size
;
SWAP
(
inserter
->
pData
,
pBlocks
->
pData
,
char
*
);
return
(
SDataSink
*
)
inserter
;
}
}
static
bool
toDataBlockSchema
(
SQueryPlanNode
*
pPlanNode
,
SDataBlockSchema
*
dataBlockSchema
)
{
static
bool
toDataBlockSchema
(
SQueryPlanNode
*
pPlanNode
,
SDataBlockSchema
*
dataBlockSchema
)
{
...
@@ -102,6 +94,10 @@ static bool toDataBlockSchema(SQueryPlanNode* pPlanNode, SDataBlockSchema* dataB
...
@@ -102,6 +94,10 @@ static bool toDataBlockSchema(SQueryPlanNode* pPlanNode, SDataBlockSchema* dataB
return
false
;
return
false
;
}
}
memcpy
(
dataBlockSchema
->
pSchema
,
pPlanNode
->
pSchema
,
sizeof
(
SSlotSchema
)
*
pPlanNode
->
numOfCols
);
memcpy
(
dataBlockSchema
->
pSchema
,
pPlanNode
->
pSchema
,
sizeof
(
SSlotSchema
)
*
pPlanNode
->
numOfCols
);
dataBlockSchema
->
resultRowSize
=
0
;
for
(
int32_t
i
=
0
;
i
<
dataBlockSchema
->
numOfCols
;
++
i
)
{
dataBlockSchema
->
resultRowSize
+=
dataBlockSchema
->
pSchema
[
i
].
bytes
;
}
return
true
;
return
true
;
}
}
...
@@ -120,13 +116,37 @@ static bool cloneExprArray(SArray** dst, SArray* src) {
...
@@ -120,13 +116,37 @@ static bool cloneExprArray(SArray** dst, SArray* src) {
return
(
TSDB_CODE_SUCCESS
==
copyAllExprInfo
(
*
dst
,
src
,
true
)
?
true
:
false
);
return
(
TSDB_CODE_SUCCESS
==
copyAllExprInfo
(
*
dst
,
src
,
true
)
?
true
:
false
);
}
}
static
SDataSink
*
initDataSink
(
int32_t
type
,
int32_t
size
,
const
SPhyNode
*
pRoot
)
{
SDataSink
*
sink
=
(
SDataSink
*
)
validPointer
(
calloc
(
1
,
size
));
sink
->
info
.
type
=
type
;
sink
->
info
.
name
=
dsinkTypeToDsinkName
(
type
);
if
(
NULL
!=
pRoot
&&
!
copySchema
(
&
sink
->
schema
,
&
pRoot
->
targetSchema
))
{
tfree
(
sink
);
THROW
(
TSDB_CODE_TSC_OUT_OF_MEMORY
);
}
return
sink
;
}
static
SDataSink
*
createDataInserter
(
SPlanContext
*
pCxt
,
SVgDataBlocks
*
pBlocks
,
const
SPhyNode
*
pRoot
)
{
SDataInserter
*
inserter
=
(
SDataInserter
*
)
initDataSink
(
DSINK_Insert
,
sizeof
(
SDataInserter
),
pRoot
);
inserter
->
numOfTables
=
pBlocks
->
numOfTables
;
inserter
->
size
=
pBlocks
->
size
;
SWAP
(
inserter
->
pData
,
pBlocks
->
pData
,
char
*
);
return
(
SDataSink
*
)
inserter
;
}
static
SDataSink
*
createDataDispatcher
(
SPlanContext
*
pCxt
,
SQueryPlanNode
*
pPlanNode
,
const
SPhyNode
*
pRoot
)
{
SDataDispatcher
*
dispatcher
=
(
SDataDispatcher
*
)
initDataSink
(
DSINK_Dispatch
,
sizeof
(
SDataDispatcher
),
pRoot
);
return
(
SDataSink
*
)
dispatcher
;
}
static
SPhyNode
*
initPhyNode
(
SQueryPlanNode
*
pPlanNode
,
int32_t
type
,
int32_t
size
)
{
static
SPhyNode
*
initPhyNode
(
SQueryPlanNode
*
pPlanNode
,
int32_t
type
,
int32_t
size
)
{
SPhyNode
*
node
=
(
SPhyNode
*
)
validPointer
(
calloc
(
1
,
size
));
SPhyNode
*
node
=
(
SPhyNode
*
)
validPointer
(
calloc
(
1
,
size
));
node
->
info
.
type
=
type
;
node
->
info
.
type
=
type
;
node
->
info
.
name
=
opTypeToOpName
(
type
);
node
->
info
.
name
=
opTypeToOpName
(
type
);
if
(
!
cloneExprArray
(
&
node
->
pTargets
,
pPlanNode
->
pExpr
)
||
!
toDataBlockSchema
(
pPlanNode
,
&
(
node
->
targetSchema
)))
{
if
(
!
cloneExprArray
(
&
node
->
pTargets
,
pPlanNode
->
pExpr
)
||
!
toDataBlockSchema
(
pPlanNode
,
&
(
node
->
targetSchema
)))
{
free
(
node
);
free
(
node
);
return
NULL
;
THROW
(
TSDB_CODE_TSC_OUT_OF_MEMORY
)
;
}
}
return
node
;
return
node
;
}
}
...
@@ -149,7 +169,7 @@ static SPhyNode* createTagScanNode(SQueryPlanNode* pPlanNode) {
...
@@ -149,7 +169,7 @@ static SPhyNode* createTagScanNode(SQueryPlanNode* pPlanNode) {
static
uint8_t
getScanFlag
(
SQueryPlanNode
*
pPlanNode
,
SQueryTableInfo
*
pTable
)
{
static
uint8_t
getScanFlag
(
SQueryPlanNode
*
pPlanNode
,
SQueryTableInfo
*
pTable
)
{
// todo
// todo
return
MA
STER
_SCAN
;
return
MA
IN
_SCAN
;
}
}
static
SPhyNode
*
createUserTableScanNode
(
SQueryPlanNode
*
pPlanNode
,
SQueryTableInfo
*
pTable
,
int32_t
op
)
{
static
SPhyNode
*
createUserTableScanNode
(
SQueryPlanNode
*
pPlanNode
,
SQueryTableInfo
*
pTable
,
int32_t
op
)
{
...
@@ -237,9 +257,10 @@ static uint64_t splitSubplanByTable(SPlanContext* pCxt, SQueryPlanNode* pPlanNod
...
@@ -237,9 +257,10 @@ static uint64_t splitSubplanByTable(SPlanContext* pCxt, SQueryPlanNode* pPlanNod
for
(
int32_t
i
=
0
;
i
<
pTable
->
pMeta
->
vgroupList
->
numOfVgroups
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pTable
->
pMeta
->
vgroupList
->
numOfVgroups
;
++
i
)
{
STORE_CURRENT_SUBPLAN
(
pCxt
);
STORE_CURRENT_SUBPLAN
(
pCxt
);
SSubplan
*
subplan
=
initSubplan
(
pCxt
,
QUERY_TYPE_SCAN
);
SSubplan
*
subplan
=
initSubplan
(
pCxt
,
QUERY_TYPE_SCAN
);
subplan
->
msgType
=
TDMT_VND_QUERY
;
vgroupMsgToEpSet
(
&
(
pTable
->
pMeta
->
vgroupList
->
vgroups
[
i
]),
&
subplan
->
execNode
);
vgroupMsgToEpSet
(
&
(
pTable
->
pMeta
->
vgroupList
->
vgroups
[
i
]),
&
subplan
->
execNode
);
subplan
->
pNode
=
createMultiTableScanNode
(
pPlanNode
,
pTable
);
subplan
->
pNode
=
createMultiTableScanNode
(
pPlanNode
,
pTable
);
subplan
->
pDataSink
=
createDataDispatcher
(
pCxt
,
pPlanNode
);
subplan
->
pDataSink
=
createDataDispatcher
(
pCxt
,
pPlanNode
,
subplan
->
pNode
);
RECOVERY_CURRENT_SUBPLAN
(
pCxt
);
RECOVERY_CURRENT_SUBPLAN
(
pCxt
);
}
}
return
pCxt
->
nextId
.
templateId
++
;
return
pCxt
->
nextId
.
templateId
++
;
...
@@ -248,6 +269,7 @@ static uint64_t splitSubplanByTable(SPlanContext* pCxt, SQueryPlanNode* pPlanNod
...
@@ -248,6 +269,7 @@ static uint64_t splitSubplanByTable(SPlanContext* pCxt, SQueryPlanNode* pPlanNod
static
SPhyNode
*
createExchangeNode
(
SPlanContext
*
pCxt
,
SQueryPlanNode
*
pPlanNode
,
uint64_t
srcTemplateId
)
{
static
SPhyNode
*
createExchangeNode
(
SPlanContext
*
pCxt
,
SQueryPlanNode
*
pPlanNode
,
uint64_t
srcTemplateId
)
{
SExchangePhyNode
*
node
=
(
SExchangePhyNode
*
)
initPhyNode
(
pPlanNode
,
OP_Exchange
,
sizeof
(
SExchangePhyNode
));
SExchangePhyNode
*
node
=
(
SExchangePhyNode
*
)
initPhyNode
(
pPlanNode
,
OP_Exchange
,
sizeof
(
SExchangePhyNode
));
node
->
srcTemplateId
=
srcTemplateId
;
node
->
srcTemplateId
=
srcTemplateId
;
node
->
pSrcEndPoints
=
validPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
sizeof
(
SQueryNodeAddr
)));
return
(
SPhyNode
*
)
node
;
return
(
SPhyNode
*
)
node
;
}
}
...
@@ -313,7 +335,7 @@ static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlan
...
@@ -313,7 +335,7 @@ static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlan
SVgDataBlocks
*
blocks
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pPayload
->
payload
,
i
);
SVgDataBlocks
*
blocks
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pPayload
->
payload
,
i
);
vgroupInfoToEpSet
(
&
blocks
->
vg
,
&
subplan
->
execNode
);
vgroupInfoToEpSet
(
&
blocks
->
vg
,
&
subplan
->
execNode
);
subplan
->
pDataSink
=
createDataInserter
(
pCxt
,
blocks
);
subplan
->
pDataSink
=
createDataInserter
(
pCxt
,
blocks
,
NULL
);
subplan
->
pNode
=
NULL
;
subplan
->
pNode
=
NULL
;
subplan
->
type
=
QUERY_TYPE_MODIFY
;
subplan
->
type
=
QUERY_TYPE_MODIFY
;
subplan
->
msgType
=
pPayload
->
msgType
;
subplan
->
msgType
=
pPayload
->
msgType
;
...
@@ -332,7 +354,7 @@ static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) {
...
@@ -332,7 +354,7 @@ static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) {
subplan
->
msgType
=
TDMT_VND_QUERY
;
subplan
->
msgType
=
TDMT_VND_QUERY
;
subplan
->
pNode
=
createPhyNode
(
pCxt
,
pRoot
);
subplan
->
pNode
=
createPhyNode
(
pCxt
,
pRoot
);
subplan
->
pDataSink
=
createDataDispatcher
(
pCxt
,
pRoot
);
subplan
->
pDataSink
=
createDataDispatcher
(
pCxt
,
pRoot
,
subplan
->
pNode
);
}
}
// todo deal subquery
// todo deal subquery
}
}
...
@@ -359,6 +381,24 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD
...
@@ -359,6 +381,24 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
setSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
ep
)
{
void
setExchangSourceNode
(
uint64_t
templateId
,
SQueryNodeAddr
*
pEp
,
SPhyNode
*
pNode
)
{
//todo
if
(
NULL
==
pNode
)
{
return
;
}
if
(
OP_Exchange
==
pNode
->
info
.
type
)
{
SExchangePhyNode
*
pExchange
=
(
SExchangePhyNode
*
)
pNode
;
if
(
templateId
==
pExchange
->
srcTemplateId
)
{
taosArrayPush
(
pExchange
->
pSrcEndPoints
,
pEp
);
}
}
if
(
pNode
->
pChildren
!=
NULL
)
{
size_t
size
=
taosArrayGetSize
(
pNode
->
pChildren
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
setExchangSourceNode
(
templateId
,
pEp
,
taosArrayGetP
(
pNode
->
pChildren
,
i
));
}
}
}
void
setSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
pEp
)
{
setExchangSourceNode
(
templateId
,
pEp
,
subplan
->
pNode
);
}
}
source/libs/planner/src/planner.c
浏览文件 @
95347ff6
...
@@ -88,8 +88,8 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag,
...
@@ -88,8 +88,8 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag,
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
qSetSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
ep
)
{
void
qSetSubplanExecutionNode
(
SSubplan
*
subplan
,
uint64_t
templateId
,
SQueryNodeAddr
*
ep
)
{
return
setSubplanExecutionNode
(
subplan
,
templateId
,
ep
);
setSubplanExecutionNode
(
subplan
,
templateId
,
ep
);
}
}
int32_t
qSubPlanToString
(
const
SSubplan
*
subplan
,
char
**
str
,
int32_t
*
len
)
{
int32_t
qSubPlanToString
(
const
SSubplan
*
subplan
,
char
**
str
,
int32_t
*
len
)
{
...
...
source/libs/scheduler/inc/schedulerInt.h
浏览文件 @
95347ff6
...
@@ -96,7 +96,7 @@ typedef struct SSchJob {
...
@@ -96,7 +96,7 @@ typedef struct SSchJob {
SHashObj
*
succTasks
;
// succeed tasks, key:taskid, value:SQueryTask*
SHashObj
*
succTasks
;
// succeed tasks, key:taskid, value:SQueryTask*
SHashObj
*
failTasks
;
// failed tasks, key:taskid, value:SQueryTask*
SHashObj
*
failTasks
;
// failed tasks, key:taskid, value:SQueryTask*
int8_t
status
;
int8_t
status
;
SQueryNodeAddr
resNode
;
SQueryNodeAddr
resNode
;
tsem_t
rspSem
;
tsem_t
rspSem
;
int32_t
userFetch
;
int32_t
userFetch
;
...
@@ -113,10 +113,10 @@ typedef struct SSchJob {
...
@@ -113,10 +113,10 @@ typedef struct SSchJob {
#define SCH_IS_DATA_SRC_TASK(task) ((task)->plan->type == QUERY_TYPE_SCAN)
#define SCH_IS_DATA_SRC_TASK(task) ((task)->plan->type == QUERY_TYPE_SCAN)
#define SCH_TASK_NEED_WAIT_ALL(task) ((task)->plan->type == QUERY_TYPE_MODIFY)
#define SCH_TASK_NEED_WAIT_ALL(task) ((task)->plan->type == QUERY_TYPE_MODIFY)
#define SCH_SET_TASK_STATUS(task, st) atomic_store_8(&(task)->status, st)
#define SCH_SET_TASK_STATUS(task, st) atomic_store_8(&(task)->status, st)
#define SCH_GET_TASK_STATUS(task) atomic_load_8(&(task)->status)
#define SCH_GET_TASK_STATUS(task) atomic_load_8(&(task)->status)
#define SCH_SET_JOB_STATUS(job, st) atomic_store_8(&(job)->status, st)
#define SCH_SET_JOB_STATUS(job, st) atomic_store_8(&(job)->status, st)
#define SCH_GET_JOB_STATUS(job) atomic_load_8(&(job)->status)
#define SCH_GET_JOB_STATUS(job) atomic_load_8(&(job)->status)
#define SCH_SET_JOB_TYPE(pAttr, type) (pAttr)->queryJob = ((type) != QUERY_TYPE_MODIFY)
#define SCH_SET_JOB_TYPE(pAttr, type) (pAttr)->queryJob = ((type) != QUERY_TYPE_MODIFY)
...
...
source/libs/scheduler/src/scheduler.c
浏览文件 @
95347ff6
...
@@ -20,6 +20,75 @@
...
@@ -20,6 +20,75 @@
static
SSchedulerMgmt
schMgmt
=
{
0
};
static
SSchedulerMgmt
schMgmt
=
{
0
};
int32_t
schValidateStatus
(
SSchJob
*
pJob
,
int8_t
oriStatus
,
int8_t
newStatus
)
{
int32_t
code
=
0
;
/*
if (oriStatus == newStatus) {
SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
}
switch (oriStatus) {
case JOB_TASK_STATUS_NULL:
if (newStatus != JOB_TASK_STATUS_EXECUTING
&& newStatus != JOB_TASK_STATUS_FAILED
&& newStatus != JOB_TASK_STATUS_NOT_START) {
SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
}
break;
case JOB_TASK_STATUS_NOT_START:
if (newStatus != JOB_TASK_STATUS_CANCELLED) {
SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
}
break;
case JOB_TASK_STATUS_EXECUTING:
if (newStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED
&& newStatus != JOB_TASK_STATUS_FAILED
&& newStatus != JOB_TASK_STATUS_CANCELLING
&& newStatus != JOB_TASK_STATUS_CANCELLED
&& newStatus != JOB_TASK_STATUS_DROPPING) {
SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
}
break;
case JOB_TASK_STATUS_PARTIAL_SUCCEED:
if (newStatus != JOB_TASK_STATUS_EXECUTING
&& newStatus != JOB_TASK_STATUS_SUCCEED
&& newStatus != JOB_TASK_STATUS_CANCELLED) {
SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
}
break;
case JOB_TASK_STATUS_SUCCEED:
case JOB_TASK_STATUS_FAILED:
case JOB_TASK_STATUS_CANCELLING:
if (newStatus != JOB_TASK_STATUS_CANCELLED) {
SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
}
break;
case JOB_TASK_STATUS_CANCELLED:
case JOB_TASK_STATUS_DROPPING:
SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
break;
default:
qError("invalid task status:%d", oriStatus);
return TSDB_CODE_QRY_APP_ERROR;
}
*/
return
TSDB_CODE_SUCCESS
;
_return:
SCH_JOB_ELOG
(
"invalid job status update, from %d to %d"
,
oriStatus
,
newStatus
);
SCH_ERR_RET
(
code
);
}
int32_t
schBuildTaskRalation
(
SSchJob
*
pJob
,
SHashObj
*
planToTask
)
{
int32_t
schBuildTaskRalation
(
SSchJob
*
pJob
,
SHashObj
*
planToTask
)
{
for
(
int32_t
i
=
0
;
i
<
pJob
->
levelNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pJob
->
levelNum
;
++
i
)
{
SSchLevel
*
pLevel
=
taosArrayGet
(
pJob
->
levels
,
i
);
SSchLevel
*
pLevel
=
taosArrayGet
(
pJob
->
levels
,
i
);
...
@@ -365,14 +434,21 @@ int32_t schProcessOnJobPartialSuccess(SSchJob *job) {
...
@@ -365,14 +434,21 @@ int32_t schProcessOnJobPartialSuccess(SSchJob *job) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
schProcessOnJobFailure
(
SSchJob
*
job
,
int32_t
errCode
)
{
int32_t
schProcessOnJobFailure
(
SSchJob
*
pJob
,
int32_t
errCode
)
{
job
->
status
=
JOB_TASK_STATUS_FAILED
;
int8_t
status
=
SCH_GET_JOB_STATUS
(
pJob
);
job
->
errCode
=
errCode
;
atomic_val_compare_exchange_32
(
&
job
->
remoteFetch
,
1
,
0
);
if
(
schValidateStatus
(
pJob
,
status
,
JOB_TASK_STATUS_FAILED
))
{
SCH_ERR_RET
(
atomic_load_32
(
&
pJob
->
errCode
));
}
SCH_SET_JOB_STATUS
(
pJob
,
JOB_TASK_STATUS_FAILED
);
atomic_store_32
(
&
pJob
->
errCode
,
errCode
);
if
(
job
->
userFetch
||
((
!
SCH_JOB_NEED_FETCH
(
&
job
->
attr
))
&&
job
->
attr
.
syncSchedule
))
{
atomic_val_compare_exchange_32
(
&
pJob
->
remoteFetch
,
1
,
0
);
tsem_post
(
&
job
->
rspSem
);
if
(
pJob
->
userFetch
||
((
!
SCH_JOB_NEED_FETCH
(
&
pJob
->
attr
))
&&
pJob
->
attr
.
syncSchedule
))
{
tsem_post
(
&
pJob
->
rspSem
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -387,6 +463,7 @@ int32_t schProcessOnDataFetched(SSchJob *job) {
...
@@ -387,6 +463,7 @@ int32_t schProcessOnDataFetched(SSchJob *job) {
int32_t
schProcessOnTaskSuccess
(
SSchJob
*
pJob
,
SSchTask
*
pTask
)
{
int32_t
schProcessOnTaskSuccess
(
SSchJob
*
pJob
,
SSchTask
*
pTask
)
{
bool
moved
=
false
;
bool
moved
=
false
;
int32_t
code
=
0
;
SCH_ERR_RET
(
schMoveTaskToSuccList
(
pJob
,
pTask
,
&
moved
));
SCH_ERR_RET
(
schMoveTaskToSuccList
(
pJob
,
pTask
,
&
moved
));
if
(
!
moved
)
{
if
(
!
moved
)
{
...
@@ -448,7 +525,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
...
@@ -448,7 +525,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
atomic_add_fetch_32
(
&
par
->
childReady
,
1
);
atomic_add_fetch_32
(
&
par
->
childReady
,
1
);
SCH_ERR_RET
(
qSetSubplanExecutionNode
(
par
->
plan
,
pTask
->
plan
->
id
.
templateId
,
&
pTask
->
execAddr
)
);
qSetSubplanExecutionNode
(
par
->
plan
,
pTask
->
plan
->
id
.
templateId
,
&
pTask
->
execAddr
);
if
(
SCH_TASK_READY_TO_LUNCH
(
par
))
{
if
(
SCH_TASK_READY_TO_LUNCH
(
par
))
{
SCH_ERR_RET
(
schLaunchTask
(
pJob
,
par
));
SCH_ERR_RET
(
schLaunchTask
(
pJob
,
par
));
...
@@ -465,7 +542,7 @@ int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode)
...
@@ -465,7 +542,7 @@ int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode)
SCH_ERR_RET
(
schTaskCheckAndSetRetry
(
pJob
,
pTask
,
errCode
,
&
needRetry
));
SCH_ERR_RET
(
schTaskCheckAndSetRetry
(
pJob
,
pTask
,
errCode
,
&
needRetry
));
if
(
!
needRetry
)
{
if
(
!
needRetry
)
{
SCH_TASK_ELOG
(
"task failed
[%x], no more retry
"
,
errCode
);
SCH_TASK_ELOG
(
"task failed
and no more retry, code:%x
"
,
errCode
);
if
(
SCH_GET_TASK_STATUS
(
pTask
)
==
JOB_TASK_STATUS_EXECUTING
)
{
if
(
SCH_GET_TASK_STATUS
(
pTask
)
==
JOB_TASK_STATUS_EXECUTING
)
{
SCH_ERR_RET
(
schMoveTaskToFailList
(
pJob
,
pTask
,
&
moved
));
SCH_ERR_RET
(
schMoveTaskToFailList
(
pJob
,
pTask
,
&
moved
));
...
@@ -670,13 +747,13 @@ int32_t schAsyncSendMsg(void *transport, SEpSet* epSet, uint64_t qId, uint64_t t
...
@@ -670,13 +747,13 @@ int32_t schAsyncSendMsg(void *transport, SEpSet* epSet, uint64_t qId, uint64_t t
int32_t
code
=
0
;
int32_t
code
=
0
;
SMsgSendInfo
*
pMsgSendInfo
=
calloc
(
1
,
sizeof
(
SMsgSendInfo
));
SMsgSendInfo
*
pMsgSendInfo
=
calloc
(
1
,
sizeof
(
SMsgSendInfo
));
if
(
NULL
==
pMsgSendInfo
)
{
if
(
NULL
==
pMsgSendInfo
)
{
qError
(
"
calloc %d failed"
,
(
int32_t
)
sizeof
(
SMsgSendInfo
));
qError
(
"
QID:%"
PRIx64
",TID:%"
PRIx64
" calloc %d failed"
,
qId
,
tId
,
(
int32_t
)
sizeof
(
SMsgSendInfo
));
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
SSchCallbackParam
*
param
=
calloc
(
1
,
sizeof
(
SSchCallbackParam
));
SSchCallbackParam
*
param
=
calloc
(
1
,
sizeof
(
SSchCallbackParam
));
if
(
NULL
==
param
)
{
if
(
NULL
==
param
)
{
qError
(
"
calloc %d failed"
,
(
int32_t
)
sizeof
(
SSchCallbackParam
));
qError
(
"
QID:%"
PRIx64
",TID:%"
PRIx64
" calloc %d failed"
,
qId
,
tId
,
(
int32_t
)
sizeof
(
SSchCallbackParam
));
SCH_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCH_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
...
@@ -694,11 +771,13 @@ int32_t schAsyncSendMsg(void *transport, SEpSet* epSet, uint64_t qId, uint64_t t
...
@@ -694,11 +771,13 @@ int32_t schAsyncSendMsg(void *transport, SEpSet* epSet, uint64_t qId, uint64_t t
pMsgSendInfo
->
fp
=
fp
;
pMsgSendInfo
->
fp
=
fp
;
int64_t
transporterId
=
0
;
int64_t
transporterId
=
0
;
SCH_ERR_JRET
(
asyncSendMsgToServer
(
transport
,
epSet
,
&
transporterId
,
pMsgSendInfo
));
SCH_ERR_JRET
(
asyncSendMsgToServer
(
transport
,
epSet
,
&
transporterId
,
pMsgSendInfo
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_return:
_return:
tfree
(
param
);
tfree
(
param
);
tfree
(
pMsgSendInfo
);
tfree
(
pMsgSendInfo
);
...
@@ -720,35 +799,31 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType) {
...
@@ -720,35 +799,31 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType) {
uint32_t
msgSize
=
0
;
uint32_t
msgSize
=
0
;
void
*
msg
=
NULL
;
void
*
msg
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
SEpSet
epSet
;
SQueryNodeAddr
*
addr
=
taosArrayGet
(
pTask
->
candidateAddrs
,
pTask
->
candidateIdx
);
schConvertAddrToEpSet
(
addr
,
&
epSet
);
switch
(
msgType
)
{
switch
(
msgType
)
{
case
TDMT_VND_CREATE_TABLE
:
case
TDMT_VND_CREATE_TABLE
:
case
TDMT_VND_SUBMIT
:
{
case
TDMT_VND_SUBMIT
:
{
if
(
NULL
==
pTask
->
msg
||
pTask
->
msgLen
<=
0
)
{
qError
(
"submit msg is NULL"
);
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
}
msgSize
=
pTask
->
msgLen
;
msgSize
=
pTask
->
msgLen
;
msg
=
pTask
->
msg
;
msg
=
pTask
->
msg
;
break
;
break
;
}
}
case
TDMT_VND_QUERY
:
{
case
TDMT_VND_QUERY
:
{
if
(
NULL
==
pTask
->
msg
)
{
qError
(
"query msg is NULL"
);
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
}
msgSize
=
sizeof
(
SSubQueryMsg
)
+
pTask
->
msgLen
;
msgSize
=
sizeof
(
SSubQueryMsg
)
+
pTask
->
msgLen
;
msg
=
calloc
(
1
,
msgSize
);
msg
=
calloc
(
1
,
msgSize
);
if
(
NULL
==
msg
)
{
if
(
NULL
==
msg
)
{
qError
(
"calloc %d failed"
,
msgSize
);
SCH_TASK_ELOG
(
"calloc %d failed"
,
msgSize
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
SSubQueryMsg
*
pMsg
=
msg
;
SSubQueryMsg
*
pMsg
=
msg
;
pMsg
->
header
.
vgId
=
htonl
(
pTask
->
plan
->
execNode
.
nodeId
);
pMsg
->
header
.
vgId
=
htonl
(
addr
->
nodeId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
...
@@ -760,32 +835,31 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType) {
...
@@ -760,32 +835,31 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType) {
msgSize
=
sizeof
(
SResReadyMsg
);
msgSize
=
sizeof
(
SResReadyMsg
);
msg
=
calloc
(
1
,
msgSize
);
msg
=
calloc
(
1
,
msgSize
);
if
(
NULL
==
msg
)
{
if
(
NULL
==
msg
)
{
qError
(
"calloc %d failed"
,
msgSize
);
SCH_TASK_ELOG
(
"calloc %d failed"
,
msgSize
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
SResReadyMsg
*
pMsg
=
msg
;
SResReadyMsg
*
pMsg
=
msg
;
pMsg
->
header
.
vgId
=
htonl
(
pTask
->
plan
->
execNode
.
nodeId
);
pMsg
->
header
.
vgId
=
htonl
(
addr
->
nodeId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
break
;
break
;
}
}
case
TDMT_VND_FETCH
:
{
case
TDMT_VND_FETCH
:
{
if
(
NULL
==
pTask
)
{
SCH_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
msgSize
=
sizeof
(
SResFetchMsg
);
msgSize
=
sizeof
(
SResFetchMsg
);
msg
=
calloc
(
1
,
msgSize
);
msg
=
calloc
(
1
,
msgSize
);
if
(
NULL
==
msg
)
{
if
(
NULL
==
msg
)
{
qError
(
"calloc %d failed"
,
msgSize
);
SCH_TASK_ELOG
(
"calloc %d failed"
,
msgSize
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
SResFetchMsg
*
pMsg
=
msg
;
SResFetchMsg
*
pMsg
=
msg
;
pMsg
->
header
.
vgId
=
htonl
(
pTask
->
plan
->
execNode
.
nodeId
);
pMsg
->
header
.
vgId
=
htonl
(
addr
->
nodeId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
...
@@ -795,28 +869,25 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType) {
...
@@ -795,28 +869,25 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType) {
msgSize
=
sizeof
(
STaskDropMsg
);
msgSize
=
sizeof
(
STaskDropMsg
);
msg
=
calloc
(
1
,
msgSize
);
msg
=
calloc
(
1
,
msgSize
);
if
(
NULL
==
msg
)
{
if
(
NULL
==
msg
)
{
qError
(
"calloc %d failed"
,
msgSize
);
SCH_TASK_ELOG
(
"calloc %d failed"
,
msgSize
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
STaskDropMsg
*
pMsg
=
msg
;
STaskDropMsg
*
pMsg
=
msg
;
pMsg
->
header
.
vgId
=
htonl
(
pTask
->
plan
->
execNode
.
nodeId
);
pMsg
->
header
.
vgId
=
htonl
(
addr
->
nodeId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
sId
=
htobe64
(
schMgmt
.
sId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
queryId
=
htobe64
(
pJob
->
queryId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
pMsg
->
taskId
=
htobe64
(
pTask
->
taskId
);
break
;
break
;
}
}
default:
default:
qError
(
"unknown msg type:%d"
,
msgType
);
SCH_TASK_ELOG
(
"unknown msg type:%d"
,
msgType
);
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
break
;
break
;
}
}
SEpSet
epSet
;
SQueryNodeAddr
*
addr
=
taosArrayGet
(
pTask
->
candidateAddrs
,
pTask
->
candidateIdx
);
schConvertAddrToEpSet
(
addr
,
&
epSet
);
SCH_ERR_JRET
(
schAsyncSendMsg
(
pJob
->
transport
,
&
epSet
,
pJob
->
queryId
,
pTask
->
taskId
,
msgType
,
msg
,
msgSize
));
SCH_ERR_JRET
(
schAsyncSendMsg
(
pJob
->
transport
,
&
epSet
,
pJob
->
queryId
,
pTask
->
taskId
,
msgType
,
msg
,
msgSize
));
...
@@ -844,7 +915,7 @@ int32_t schLaunchTask(SSchJob *pJob, SSchTask *pTask) {
...
@@ -844,7 +915,7 @@ int32_t schLaunchTask(SSchJob *pJob, SSchTask *pTask) {
if
(
schJobNeedToStop
(
pJob
,
&
status
))
{
if
(
schJobNeedToStop
(
pJob
,
&
status
))
{
SCH_TASK_ELOG
(
"no need to launch task cause of job status, job status:%d"
,
status
);
SCH_TASK_ELOG
(
"no need to launch task cause of job status, job status:%d"
,
status
);
SCH_ERR_RET
(
pJob
->
errCode
);
SCH_ERR_RET
(
atomic_load_32
(
&
pJob
->
errCode
)
);
}
}
SSubplan
*
plan
=
pTask
->
plan
;
SSubplan
*
plan
=
pTask
->
plan
;
...
@@ -860,9 +931,11 @@ int32_t schLaunchTask(SSchJob *pJob, SSchTask *pTask) {
...
@@ -860,9 +931,11 @@ int32_t schLaunchTask(SSchJob *pJob, SSchTask *pTask) {
SCH_ERR_JRET
(
schSetTaskCandidateAddrs
(
pJob
,
pTask
));
SCH_ERR_JRET
(
schSetTaskCandidateAddrs
(
pJob
,
pTask
));
// NOTE: race condition: the task should be put into the hash table before send msg to server
// NOTE: race condition: the task should be put into the hash table before send msg to server
SCH_ERR_JRET
(
schPushTaskToExecList
(
pJob
,
pTask
));
if
(
SCH_GET_TASK_STATUS
(
pTask
)
!=
JOB_TASK_STATUS_EXECUTING
)
{
SCH_ERR_JRET
(
schPushTaskToExecList
(
pJob
,
pTask
));
SCH_SET_TASK_STATUS
(
pTask
,
JOB_TASK_STATUS_EXECUTING
);
SCH_SET_TASK_STATUS
(
pTask
,
JOB_TASK_STATUS_EXECUTING
);
}
SCH_ERR_JRET
(
schBuildAndSendMsg
(
pJob
,
pTask
,
plan
->
msgType
));
SCH_ERR_JRET
(
schBuildAndSendMsg
(
pJob
,
pTask
,
plan
->
msgType
));
...
@@ -1031,7 +1104,7 @@ int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void
...
@@ -1031,7 +1104,7 @@ int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void
SSchJob
*
job
=
*
(
SSchJob
**
)
pJob
;
SSchJob
*
job
=
*
(
SSchJob
**
)
pJob
;
pRes
->
code
=
job
->
errCode
;
pRes
->
code
=
atomic_load_32
(
&
job
->
errCode
)
;
pRes
->
numOfRows
=
job
->
resNumOfRows
;
pRes
->
numOfRows
=
job
->
resNumOfRows
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1061,7 +1134,7 @@ int32_t scheduleFetchRows(void *pJob, void **data) {
...
@@ -1061,7 +1134,7 @@ int32_t scheduleFetchRows(void *pJob, void **data) {
if
(
job
->
status
==
JOB_TASK_STATUS_FAILED
)
{
if
(
job
->
status
==
JOB_TASK_STATUS_FAILED
)
{
job
->
res
=
NULL
;
job
->
res
=
NULL
;
SCH_RET
(
job
->
errCode
);
SCH_RET
(
atomic_load_32
(
&
job
->
errCode
)
);
}
}
if
(
job
->
status
==
JOB_TASK_STATUS_SUCCEED
)
{
if
(
job
->
status
==
JOB_TASK_STATUS_SUCCEED
)
{
...
@@ -1081,7 +1154,7 @@ int32_t scheduleFetchRows(void *pJob, void **data) {
...
@@ -1081,7 +1154,7 @@ int32_t scheduleFetchRows(void *pJob, void **data) {
tsem_wait
(
&
job
->
rspSem
);
tsem_wait
(
&
job
->
rspSem
);
if
(
job
->
status
==
JOB_TASK_STATUS_FAILED
)
{
if
(
job
->
status
==
JOB_TASK_STATUS_FAILED
)
{
code
=
job
->
errCode
;
code
=
atomic_load_32
(
&
job
->
errCode
)
;
}
}
if
(
job
->
res
&&
((
SRetrieveTableRsp
*
)
job
->
res
)
->
completed
)
{
if
(
job
->
res
&&
((
SRetrieveTableRsp
*
)
job
->
res
)
->
completed
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录