Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6402c2b0
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6402c2b0
编写于
1月 17, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-225]refactor codes.
上级
795690cd
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
196 addition
and
202 deletion
+196
-202
src/client/inc/tscLocalMerge.h
src/client/inc/tscLocalMerge.h
+4
-4
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+2
-2
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+2
-2
src/client/src/tscLocalMerge.c
src/client/src/tscLocalMerge.c
+170
-175
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+3
-3
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+10
-11
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+2
-2
src/util/inc/tarray.h
src/util/inc/tarray.h
+1
-1
src/util/src/tarray.c
src/util/src/tarray.c
+1
-1
未找到文件。
src/client/inc/tscLocalMerge.h
浏览文件 @
6402c2b0
...
@@ -38,7 +38,7 @@ typedef struct SLocalDataSource {
...
@@ -38,7 +38,7 @@ typedef struct SLocalDataSource {
tFilePage
filePage
;
tFilePage
filePage
;
}
SLocalDataSource
;
}
SLocalDataSource
;
typedef
struct
SLocal
Reduc
er
{
typedef
struct
SLocal
Merg
er
{
SLocalDataSource
**
pLocalDataSrc
;
SLocalDataSource
**
pLocalDataSrc
;
int32_t
numOfBuffer
;
int32_t
numOfBuffer
;
int32_t
numOfCompleted
;
int32_t
numOfCompleted
;
...
@@ -62,7 +62,7 @@ typedef struct SLocalReducer {
...
@@ -62,7 +62,7 @@ typedef struct SLocalReducer {
bool
discard
;
bool
discard
;
int32_t
offset
;
// limit offset value
int32_t
offset
;
// limit offset value
bool
orderPrjOnSTable
;
// projection query on stable
bool
orderPrjOnSTable
;
// projection query on stable
}
SLocal
Reduc
er
;
}
SLocal
Merg
er
;
typedef
struct
SRetrieveSupport
{
typedef
struct
SRetrieveSupport
{
tExtMemBuffer
**
pExtMemBuffer
;
// for build loser tree
tExtMemBuffer
**
pExtMemBuffer
;
// for build loser tree
...
@@ -89,10 +89,10 @@ int32_t tscFlushTmpBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tF
...
@@ -89,10 +89,10 @@ int32_t tscFlushTmpBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tF
/*
/*
* create local reducer to launch the second-stage reduce process at client site
* create local reducer to launch the second-stage reduce process at client site
*/
*/
void
tscCreateLocal
Reduc
er
(
tExtMemBuffer
**
pMemBuffer
,
int32_t
numOfBuffer
,
tOrderDescriptor
*
pDesc
,
void
tscCreateLocal
Merg
er
(
tExtMemBuffer
**
pMemBuffer
,
int32_t
numOfBuffer
,
tOrderDescriptor
*
pDesc
,
SColumnModel
*
finalModel
,
SColumnModel
*
pFFModel
,
SSqlObj
*
pSql
);
SColumnModel
*
finalModel
,
SColumnModel
*
pFFModel
,
SSqlObj
*
pSql
);
void
tscDestroyLocal
Reduc
er
(
SSqlObj
*
pSql
);
void
tscDestroyLocal
Merg
er
(
SSqlObj
*
pSql
);
int32_t
tscDoLocalMerge
(
SSqlObj
*
pSql
);
int32_t
tscDoLocalMerge
(
SSqlObj
*
pSql
);
...
...
src/client/inc/tscUtil.h
浏览文件 @
6402c2b0
...
@@ -225,7 +225,7 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo);
...
@@ -225,7 +225,7 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo);
void
tscClearSubqueryInfo
(
SSqlCmd
*
pCmd
);
void
tscClearSubqueryInfo
(
SSqlCmd
*
pCmd
);
void
tscFreeVgroupTableInfo
(
SArray
*
pVgroupTables
);
void
tscFreeVgroupTableInfo
(
SArray
*
pVgroupTables
);
SArray
*
tscVgroupTableInfo
Clone
(
SArray
*
pVgroupTables
);
SArray
*
tscVgroupTableInfo
Dup
(
SArray
*
pVgroupTables
);
void
tscRemoveVgroupTableGroup
(
SArray
*
pVgroupTable
,
int32_t
index
);
void
tscRemoveVgroupTableGroup
(
SArray
*
pVgroupTable
,
int32_t
index
);
void
tscVgroupTableCopy
(
SVgroupTableInfo
*
info
,
SVgroupTableInfo
*
pInfo
);
void
tscVgroupTableCopy
(
SVgroupTableInfo
*
info
,
SVgroupTableInfo
*
pInfo
);
...
@@ -292,7 +292,7 @@ uint32_t tscGetTableMetaSize(STableMeta* pTableMeta);
...
@@ -292,7 +292,7 @@ uint32_t tscGetTableMetaSize(STableMeta* pTableMeta);
CChildTableMeta
*
tscCreateChildMeta
(
STableMeta
*
pTableMeta
);
CChildTableMeta
*
tscCreateChildMeta
(
STableMeta
*
pTableMeta
);
uint32_t
tscGetTableMetaMaxSize
();
uint32_t
tscGetTableMetaMaxSize
();
int32_t
tscCreateTableMetaFromCChildMeta
(
STableMeta
*
pChild
,
const
char
*
name
);
int32_t
tscCreateTableMetaFromCChildMeta
(
STableMeta
*
pChild
,
const
char
*
name
);
STableMeta
*
tscTableMeta
Clone
(
STableMeta
*
pTableMeta
);
STableMeta
*
tscTableMeta
Dup
(
STableMeta
*
pTableMeta
);
void
*
malloc_throw
(
size_t
size
);
void
*
malloc_throw
(
size_t
size
);
...
...
src/client/inc/tsclient.h
浏览文件 @
6402c2b0
...
@@ -39,7 +39,7 @@ extern "C" {
...
@@ -39,7 +39,7 @@ extern "C" {
// forward declaration
// forward declaration
struct
SSqlInfo
;
struct
SSqlInfo
;
struct
SLocal
Reduc
er
;
struct
SLocal
Merg
er
;
// data source from sql string or from file
// data source from sql string or from file
enum
{
enum
{
...
@@ -292,7 +292,7 @@ typedef struct {
...
@@ -292,7 +292,7 @@ typedef struct {
SColumnIndex
*
pColumnIndex
;
SColumnIndex
*
pColumnIndex
;
SArithmeticSupport
*
pArithSup
;
// support the arithmetic expression calculation on agg functions
SArithmeticSupport
*
pArithSup
;
// support the arithmetic expression calculation on agg functions
struct
SLocal
Reducer
*
pLocalReduc
er
;
struct
SLocal
Merger
*
pLocalMerg
er
;
}
SSqlRes
;
}
SSqlRes
;
typedef
struct
STscObj
{
typedef
struct
STscObj
{
...
...
src/client/src/tscLocalMerge.c
浏览文件 @
6402c2b0
...
@@ -56,7 +56,7 @@ int32_t treeComparator(const void *pLeft, const void *pRight, void *param) {
...
@@ -56,7 +56,7 @@ int32_t treeComparator(const void *pLeft, const void *pRight, void *param) {
}
}
}
}
static
void
tscInitSqlContext
(
SSqlCmd
*
pCmd
,
SLocal
Reduc
er
*
pReducer
,
tOrderDescriptor
*
pDesc
)
{
static
void
tscInitSqlContext
(
SSqlCmd
*
pCmd
,
SLocal
Merg
er
*
pReducer
,
tOrderDescriptor
*
pDesc
)
{
/*
/*
* the fields and offset attributes in pCmd and pModel may be different due to
* the fields and offset attributes in pCmd and pModel may be different due to
* merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object.
* merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object.
...
@@ -166,7 +166,7 @@ static SFillColInfo* createFillColInfo(SQueryInfo* pQueryInfo) {
...
@@ -166,7 +166,7 @@ static SFillColInfo* createFillColInfo(SQueryInfo* pQueryInfo) {
return
pFillCol
;
return
pFillCol
;
}
}
void
tscCreateLocal
Reduc
er
(
tExtMemBuffer
**
pMemBuffer
,
int32_t
numOfBuffer
,
tOrderDescriptor
*
pDesc
,
void
tscCreateLocal
Merg
er
(
tExtMemBuffer
**
pMemBuffer
,
int32_t
numOfBuffer
,
tOrderDescriptor
*
pDesc
,
SColumnModel
*
finalmodel
,
SColumnModel
*
pFFModel
,
SSqlObj
*
pSql
)
{
SColumnModel
*
finalmodel
,
SColumnModel
*
pFFModel
,
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
...
@@ -212,9 +212,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -212,9 +212,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
return
;
return
;
}
}
size_t
size
=
sizeof
(
SLocal
Reduc
er
)
+
POINTER_BYTES
*
numOfFlush
;
size_t
size
=
sizeof
(
SLocal
Merg
er
)
+
POINTER_BYTES
*
numOfFlush
;
SLocal
Reducer
*
pReducer
=
(
SLocalReduc
er
*
)
calloc
(
1
,
size
);
SLocal
Merger
*
pReducer
=
(
SLocalMerg
er
*
)
calloc
(
1
,
size
);
if
(
pReducer
==
NULL
)
{
if
(
pReducer
==
NULL
)
{
tscError
(
"%p failed to create local merge structure, out of memory"
,
pSql
);
tscError
(
"%p failed to create local merge structure, out of memory"
,
pSql
);
...
@@ -372,7 +372,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -372,7 +372,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
pReducer
->
offset
=
(
int32_t
)
pQueryInfo
->
limit
.
offset
;
pReducer
->
offset
=
(
int32_t
)
pQueryInfo
->
limit
.
offset
;
pRes
->
pLocal
Reduc
er
=
pReducer
;
pRes
->
pLocal
Merg
er
=
pReducer
;
pRes
->
numOfGroups
=
0
;
pRes
->
numOfGroups
=
0
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
...
@@ -477,13 +477,13 @@ int32_t saveToBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tFilePa
...
@@ -477,13 +477,13 @@ int32_t saveToBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tFilePa
return
0
;
return
0
;
}
}
void
tscDestroyLocal
Reduc
er
(
SSqlObj
*
pSql
)
{
void
tscDestroyLocal
Merg
er
(
SSqlObj
*
pSql
)
{
if
(
pSql
==
NULL
)
{
if
(
pSql
==
NULL
)
{
return
;
return
;
}
}
SSqlRes
*
pRes
=
&
(
pSql
->
res
);
SSqlRes
*
pRes
=
&
(
pSql
->
res
);
if
(
pRes
->
pLocal
Reduc
er
==
NULL
)
{
if
(
pRes
->
pLocal
Merg
er
==
NULL
)
{
return
;
return
;
}
}
...
@@ -491,14 +491,14 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
...
@@ -491,14 +491,14 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
// there is no more result, so we release all allocated resource
// there is no more result, so we release all allocated resource
SLocal
Reducer
*
pLocalReducer
=
(
SLocalReducer
*
)
atomic_exchange_ptr
(
&
pRes
->
pLocalReduc
er
,
NULL
);
SLocal
Merger
*
pLocalMerge
=
(
SLocalMerger
*
)
atomic_exchange_ptr
(
&
pRes
->
pLocalMerg
er
,
NULL
);
if
(
pLocal
Reducer
!=
NULL
)
{
if
(
pLocal
Merge
!=
NULL
)
{
pLocal
Reducer
->
pFillInfo
=
taosDestroyFillInfo
(
pLocalReducer
->
pFillInfo
);
pLocal
Merge
->
pFillInfo
=
taosDestroyFillInfo
(
pLocalMerge
->
pFillInfo
);
if
(
pLocal
Reducer
->
pCtx
!=
NULL
)
{
if
(
pLocal
Merge
->
pCtx
!=
NULL
)
{
int32_t
numOfExprs
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
int32_t
numOfExprs
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
SQLFunctionCtx
*
pCtx
=
&
pLocal
Reducer
->
pCtx
[
i
];
SQLFunctionCtx
*
pCtx
=
&
pLocal
Merge
->
pCtx
[
i
];
tVariantDestroy
(
&
pCtx
->
tag
);
tVariantDestroy
(
&
pCtx
->
tag
);
tfree
(
pCtx
->
resultInfo
);
tfree
(
pCtx
->
resultInfo
);
...
@@ -508,31 +508,31 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
...
@@ -508,31 +508,31 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
}
}
}
}
tfree
(
pLocal
Reducer
->
pCtx
);
tfree
(
pLocal
Merge
->
pCtx
);
}
}
tfree
(
pLocal
Reducer
->
prevRowOfInput
);
tfree
(
pLocal
Merge
->
prevRowOfInput
);
tfree
(
pLocal
Reducer
->
pTempBuffer
);
tfree
(
pLocal
Merge
->
pTempBuffer
);
tfree
(
pLocal
Reducer
->
pResultBuf
);
tfree
(
pLocal
Merge
->
pResultBuf
);
if
(
pLocal
Reducer
->
pLoserTree
)
{
if
(
pLocal
Merge
->
pLoserTree
)
{
tfree
(
pLocal
Reducer
->
pLoserTree
->
param
);
tfree
(
pLocal
Merge
->
pLoserTree
->
param
);
tfree
(
pLocal
Reducer
->
pLoserTree
);
tfree
(
pLocal
Merge
->
pLoserTree
);
}
}
tfree
(
pLocal
Reducer
->
pFinalRes
);
tfree
(
pLocal
Merge
->
pFinalRes
);
tfree
(
pLocal
Reducer
->
discardData
);
tfree
(
pLocal
Merge
->
discardData
);
tscLocalReducerEnvDestroy
(
pLocal
Reducer
->
pExtMemBuffer
,
pLocalReducer
->
pDesc
,
pLocalReducer
->
resColModel
,
pLocalReducer
->
finalModel
,
tscLocalReducerEnvDestroy
(
pLocal
Merge
->
pExtMemBuffer
,
pLocalMerge
->
pDesc
,
pLocalMerge
->
resColModel
,
pLocalMerge
->
finalModel
,
pLocal
Reducer
->
numOfVnode
);
pLocal
Merge
->
numOfVnode
);
for
(
int32_t
i
=
0
;
i
<
pLocal
Reducer
->
numOfBuffer
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pLocal
Merge
->
numOfBuffer
;
++
i
)
{
tfree
(
pLocal
Reducer
->
pLocalDataSrc
[
i
]);
tfree
(
pLocal
Merge
->
pLocalDataSrc
[
i
]);
}
}
pLocal
Reducer
->
numOfBuffer
=
0
;
pLocal
Merge
->
numOfBuffer
=
0
;
pLocal
Reducer
->
numOfCompleted
=
0
;
pLocal
Merge
->
numOfCompleted
=
0
;
free
(
pLocal
Reducer
);
free
(
pLocal
Merge
);
}
else
{
}
else
{
tscDebug
(
"%p already freed or another free function is invoked"
,
pSql
);
tscDebug
(
"%p already freed or another free function is invoked"
,
pSql
);
}
}
...
@@ -604,7 +604,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
...
@@ -604,7 +604,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
}
}
}
}
bool
isSameGroup
(
SSqlCmd
*
pCmd
,
SLocal
Reduc
er
*
pReducer
,
char
*
pPrev
,
tFilePage
*
tmpBuffer
)
{
bool
isSameGroup
(
SSqlCmd
*
pCmd
,
SLocal
Merg
er
*
pReducer
,
char
*
pPrev
,
tFilePage
*
tmpBuffer
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
// disable merge procedure for column projection query
// disable merge procedure for column projection query
...
@@ -795,12 +795,12 @@ void tscLocalReducerEnvDestroy(tExtMemBuffer **pMemBuffer, tOrderDescriptor *pDe
...
@@ -795,12 +795,12 @@ void tscLocalReducerEnvDestroy(tExtMemBuffer **pMemBuffer, tOrderDescriptor *pDe
/**
/**
*
*
* @param pLocal
Reducer
* @param pLocal
Merge
* @param pOneInterDataSrc
* @param pOneInterDataSrc
* @param treeList
* @param treeList
* @return the number of remain input source. if ret == 0, all data has been handled
* @return the number of remain input source. if ret == 0, all data has been handled
*/
*/
int32_t
loadNewDataFromDiskFor
(
SLocal
Reducer
*
pLocalReducer
,
SLocalDataSource
*
pOneInterDataSrc
,
int32_t
loadNewDataFromDiskFor
(
SLocal
Merger
*
pLocalMerge
,
SLocalDataSource
*
pOneInterDataSrc
,
bool
*
needAdjustLoserTree
)
{
bool
*
needAdjustLoserTree
)
{
pOneInterDataSrc
->
rowIdx
=
0
;
pOneInterDataSrc
->
rowIdx
=
0
;
pOneInterDataSrc
->
pageId
+=
1
;
pOneInterDataSrc
->
pageId
+=
1
;
...
@@ -817,17 +817,17 @@ int32_t loadNewDataFromDiskFor(SLocalReducer *pLocalReducer, SLocalDataSource *p
...
@@ -817,17 +817,17 @@ int32_t loadNewDataFromDiskFor(SLocalReducer *pLocalReducer, SLocalDataSource *p
#endif
#endif
*
needAdjustLoserTree
=
true
;
*
needAdjustLoserTree
=
true
;
}
else
{
}
else
{
pLocal
Reducer
->
numOfCompleted
+=
1
;
pLocal
Merge
->
numOfCompleted
+=
1
;
pOneInterDataSrc
->
rowIdx
=
-
1
;
pOneInterDataSrc
->
rowIdx
=
-
1
;
pOneInterDataSrc
->
pageId
=
-
1
;
pOneInterDataSrc
->
pageId
=
-
1
;
*
needAdjustLoserTree
=
true
;
*
needAdjustLoserTree
=
true
;
}
}
return
pLocal
Reducer
->
numOfBuffer
;
return
pLocal
Merge
->
numOfBuffer
;
}
}
void
adjustLoserTreeFromNewData
(
SLocal
Reducer
*
pLocalReducer
,
SLocalDataSource
*
pOneInterDataSrc
,
void
adjustLoserTreeFromNewData
(
SLocal
Merger
*
pLocalMerge
,
SLocalDataSource
*
pOneInterDataSrc
,
SLoserTreeInfo
*
pTree
)
{
SLoserTreeInfo
*
pTree
)
{
/*
/*
* load a new data page into memory for intermediate dataset source,
* load a new data page into memory for intermediate dataset source,
...
@@ -835,7 +835,7 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
...
@@ -835,7 +835,7 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
*/
*/
bool
needToAdjust
=
true
;
bool
needToAdjust
=
true
;
if
(
pOneInterDataSrc
->
filePage
.
num
<=
pOneInterDataSrc
->
rowIdx
)
{
if
(
pOneInterDataSrc
->
filePage
.
num
<=
pOneInterDataSrc
->
rowIdx
)
{
loadNewDataFromDiskFor
(
pLocal
Reducer
,
pOneInterDataSrc
,
&
needToAdjust
);
loadNewDataFromDiskFor
(
pLocal
Merge
,
pOneInterDataSrc
,
&
needToAdjust
);
}
}
/*
/*
...
@@ -843,7 +843,7 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
...
@@ -843,7 +843,7 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
* if the loser tree is rebuild completed, we do not need to adjust
* if the loser tree is rebuild completed, we do not need to adjust
*/
*/
if
(
needToAdjust
)
{
if
(
needToAdjust
)
{
int32_t
leafNodeIdx
=
pTree
->
pNode
[
0
].
index
+
pLocal
Reducer
->
numOfBuffer
;
int32_t
leafNodeIdx
=
pTree
->
pNode
[
0
].
index
+
pLocal
Merge
->
numOfBuffer
;
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"before adjust:
\t
"
);
printf
(
"before adjust:
\t
"
);
...
@@ -860,7 +860,7 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
...
@@ -860,7 +860,7 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
}
}
}
}
void
savePrevRecordAndSetupFillInfo
(
SLocal
Reducer
*
pLocalReducer
,
SQueryInfo
*
pQueryInfo
,
SFillInfo
*
pFillInfo
)
{
void
savePrevRecordAndSetupFillInfo
(
SLocal
Merger
*
pLocalMerge
,
SQueryInfo
*
pQueryInfo
,
SFillInfo
*
pFillInfo
)
{
// discard following dataset in the same group and reset the interpolation information
// discard following dataset in the same group and reset the interpolation information
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
...
@@ -873,28 +873,28 @@ void savePrevRecordAndSetupFillInfo(SLocalReducer *pLocalReducer, SQueryInfo *pQ
...
@@ -873,28 +873,28 @@ void savePrevRecordAndSetupFillInfo(SLocalReducer *pLocalReducer, SQueryInfo *pQ
taosResetFillInfo
(
pFillInfo
,
revisedSTime
);
taosResetFillInfo
(
pFillInfo
,
revisedSTime
);
}
}
pLocal
Reducer
->
discard
=
true
;
pLocal
Merge
->
discard
=
true
;
pLocal
Reducer
->
discardData
->
num
=
0
;
pLocal
Merge
->
discardData
->
num
=
0
;
SColumnModel
*
pModel
=
pLocal
Reducer
->
pDesc
->
pColumnModel
;
SColumnModel
*
pModel
=
pLocal
Merge
->
pDesc
->
pColumnModel
;
tColModelAppend
(
pModel
,
pLocal
Reducer
->
discardData
,
pLocalReducer
->
prevRowOfInput
,
0
,
1
,
1
);
tColModelAppend
(
pModel
,
pLocal
Merge
->
discardData
,
pLocalMerge
->
prevRowOfInput
,
0
,
1
,
1
);
}
}
static
void
genFinalResWithoutFill
(
SSqlRes
*
pRes
,
SLocal
Reducer
*
pLocalReducer
,
SQueryInfo
*
pQueryInfo
)
{
static
void
genFinalResWithoutFill
(
SSqlRes
*
pRes
,
SLocal
Merger
*
pLocalMerge
,
SQueryInfo
*
pQueryInfo
)
{
assert
(
pQueryInfo
->
interval
.
interval
==
0
||
pQueryInfo
->
fillType
==
TSDB_FILL_NONE
);
assert
(
pQueryInfo
->
interval
.
interval
==
0
||
pQueryInfo
->
fillType
==
TSDB_FILL_NONE
);
tFilePage
*
pBeforeFillData
=
pLocal
Reducer
->
pResultBuf
;
tFilePage
*
pBeforeFillData
=
pLocal
Merge
->
pResultBuf
;
pRes
->
data
=
pLocal
Reducer
->
pFinalRes
;
pRes
->
data
=
pLocal
Merge
->
pFinalRes
;
pRes
->
numOfRows
=
(
int32_t
)
pBeforeFillData
->
num
;
pRes
->
numOfRows
=
(
int32_t
)
pBeforeFillData
->
num
;
if
(
pQueryInfo
->
limit
.
offset
>
0
)
{
if
(
pQueryInfo
->
limit
.
offset
>
0
)
{
if
(
pQueryInfo
->
limit
.
offset
<
pRes
->
numOfRows
)
{
if
(
pQueryInfo
->
limit
.
offset
<
pRes
->
numOfRows
)
{
int32_t
prevSize
=
(
int32_t
)
pBeforeFillData
->
num
;
int32_t
prevSize
=
(
int32_t
)
pBeforeFillData
->
num
;
tColModelErase
(
pLocal
Reducer
->
finalModel
,
pBeforeFillData
,
prevSize
,
0
,
(
int32_t
)
pQueryInfo
->
limit
.
offset
-
1
);
tColModelErase
(
pLocal
Merge
->
finalModel
,
pBeforeFillData
,
prevSize
,
0
,
(
int32_t
)
pQueryInfo
->
limit
.
offset
-
1
);
/* remove the hole in column model */
/* remove the hole in column model */
tColModelCompact
(
pLocal
Reducer
->
finalModel
,
pBeforeFillData
,
prevSize
);
tColModelCompact
(
pLocal
Merge
->
finalModel
,
pBeforeFillData
,
prevSize
);
pRes
->
numOfRows
-=
(
int32_t
)
pQueryInfo
->
limit
.
offset
;
pRes
->
numOfRows
-=
(
int32_t
)
pQueryInfo
->
limit
.
offset
;
pQueryInfo
->
limit
.
offset
=
0
;
pQueryInfo
->
limit
.
offset
=
0
;
...
@@ -907,7 +907,7 @@ static void genFinalResWithoutFill(SSqlRes* pRes, SLocalReducer *pLocalReducer,
...
@@ -907,7 +907,7 @@ static void genFinalResWithoutFill(SSqlRes* pRes, SLocalReducer *pLocalReducer,
if
(
pRes
->
numOfRowsGroup
>=
pQueryInfo
->
limit
.
limit
&&
pQueryInfo
->
limit
.
limit
>
0
)
{
if
(
pRes
->
numOfRowsGroup
>=
pQueryInfo
->
limit
.
limit
&&
pQueryInfo
->
limit
.
limit
>
0
)
{
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
pBeforeFillData
->
num
=
0
;
pBeforeFillData
->
num
=
0
;
pLocal
Reducer
->
discard
=
true
;
pLocal
Merge
->
discard
=
true
;
return
;
return
;
}
}
...
@@ -923,29 +923,29 @@ static void genFinalResWithoutFill(SSqlRes* pRes, SLocalReducer *pLocalReducer,
...
@@ -923,29 +923,29 @@ static void genFinalResWithoutFill(SSqlRes* pRes, SLocalReducer *pLocalReducer,
pRes
->
numOfRows
-=
overflow
;
pRes
->
numOfRows
-=
overflow
;
pBeforeFillData
->
num
-=
overflow
;
pBeforeFillData
->
num
-=
overflow
;
tColModelCompact
(
pLocal
Reducer
->
finalModel
,
pBeforeFillData
,
prevSize
);
tColModelCompact
(
pLocal
Merge
->
finalModel
,
pBeforeFillData
,
prevSize
);
// set remain data to be discarded, and reset the interpolation information
// set remain data to be discarded, and reset the interpolation information
savePrevRecordAndSetupFillInfo
(
pLocal
Reducer
,
pQueryInfo
,
pLocalReducer
->
pFillInfo
);
savePrevRecordAndSetupFillInfo
(
pLocal
Merge
,
pQueryInfo
,
pLocalMerge
->
pFillInfo
);
}
}
memcpy
(
pRes
->
data
,
pBeforeFillData
->
data
,
(
size_t
)(
pRes
->
numOfRows
*
pLocal
Reducer
->
finalModel
->
rowSize
));
memcpy
(
pRes
->
data
,
pBeforeFillData
->
data
,
(
size_t
)(
pRes
->
numOfRows
*
pLocal
Merge
->
finalModel
->
rowSize
));
pRes
->
numOfClauseTotal
+=
pRes
->
numOfRows
;
pRes
->
numOfClauseTotal
+=
pRes
->
numOfRows
;
pBeforeFillData
->
num
=
0
;
pBeforeFillData
->
num
=
0
;
}
}
/*
/*
* Note: pRes->pLocal
Reducer may be null, due to the fact that "tscDestroyLocalReduc
er" is called
* Note: pRes->pLocal
Merge may be null, due to the fact that "tscDestroyLocalMerg
er" is called
* by "interuptHandler" function in shell
* by "interuptHandler" function in shell
*/
*/
static
void
doFillResult
(
SSqlObj
*
pSql
,
SLocal
Reducer
*
pLocalReducer
,
bool
doneOutput
)
{
static
void
doFillResult
(
SSqlObj
*
pSql
,
SLocal
Merger
*
pLocalMerge
,
bool
doneOutput
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
tFilePage
*
pBeforeFillData
=
pLocal
Reducer
->
pResultBuf
;
tFilePage
*
pBeforeFillData
=
pLocal
Merge
->
pResultBuf
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SFillInfo
*
pFillInfo
=
pLocal
Reducer
->
pFillInfo
;
SFillInfo
*
pFillInfo
=
pLocal
Merge
->
pFillInfo
;
// todo extract function
// todo extract function
int64_t
actualETime
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
ekey
:
pQueryInfo
->
window
.
skey
;
int64_t
actualETime
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
ekey
:
pQueryInfo
->
window
.
skey
;
...
@@ -953,11 +953,11 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
...
@@ -953,11 +953,11 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
tFilePage
**
pResPages
=
malloc
(
POINTER_BYTES
*
pQueryInfo
->
fieldsInfo
.
numOfOutput
);
tFilePage
**
pResPages
=
malloc
(
POINTER_BYTES
*
pQueryInfo
->
fieldsInfo
.
numOfOutput
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutput
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
i
);
pResPages
[
i
]
=
calloc
(
1
,
sizeof
(
tFilePage
)
+
pField
->
bytes
*
pLocal
Reducer
->
resColModel
->
capacity
);
pResPages
[
i
]
=
calloc
(
1
,
sizeof
(
tFilePage
)
+
pField
->
bytes
*
pLocal
Merge
->
resColModel
->
capacity
);
}
}
while
(
1
)
{
while
(
1
)
{
int64_t
newRows
=
taosFillResultDataBlock
(
pFillInfo
,
pResPages
,
pLocal
Reducer
->
resColModel
->
capacity
);
int64_t
newRows
=
taosFillResultDataBlock
(
pFillInfo
,
pResPages
,
pLocal
Merge
->
resColModel
->
capacity
);
if
(
pQueryInfo
->
limit
.
offset
<
newRows
)
{
if
(
pQueryInfo
->
limit
.
offset
<
newRows
)
{
newRows
-=
pQueryInfo
->
limit
.
offset
;
newRows
-=
pQueryInfo
->
limit
.
offset
;
...
@@ -970,7 +970,7 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
...
@@ -970,7 +970,7 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
}
}
}
}
pRes
->
data
=
pLocal
Reducer
->
pFinalRes
;
pRes
->
data
=
pLocal
Merge
->
pFinalRes
;
pRes
->
numOfRows
=
(
int32_t
)
newRows
;
pRes
->
numOfRows
=
(
int32_t
)
newRows
;
pQueryInfo
->
limit
.
offset
=
0
;
pQueryInfo
->
limit
.
offset
=
0
;
...
@@ -985,7 +985,7 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
...
@@ -985,7 +985,7 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
}
}
// all output in current group are completed
// all output in current group are completed
int32_t
totalRemainRows
=
(
int32_t
)
getNumOfResultsAfterFillGap
(
pFillInfo
,
actualETime
,
pLocal
Reducer
->
resColModel
->
capacity
);
int32_t
totalRemainRows
=
(
int32_t
)
getNumOfResultsAfterFillGap
(
pFillInfo
,
actualETime
,
pLocal
Merge
->
resColModel
->
capacity
);
if
(
totalRemainRows
<=
0
)
{
if
(
totalRemainRows
<=
0
)
{
break
;
break
;
}
}
...
@@ -1003,7 +1003,7 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
...
@@ -1003,7 +1003,7 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
assert
(
pRes
->
numOfRows
>=
0
);
assert
(
pRes
->
numOfRows
>=
0
);
/* set remain data to be discarded, and reset the interpolation information */
/* set remain data to be discarded, and reset the interpolation information */
savePrevRecordAndSetupFillInfo
(
pLocal
Reducer
,
pQueryInfo
,
pFillInfo
);
savePrevRecordAndSetupFillInfo
(
pLocal
Merge
,
pQueryInfo
,
pFillInfo
);
}
}
int32_t
offset
=
0
;
int32_t
offset
=
0
;
...
@@ -1025,8 +1025,8 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
...
@@ -1025,8 +1025,8 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
tfree
(
pResPages
);
tfree
(
pResPages
);
}
}
static
void
savePreviousRow
(
SLocal
Reducer
*
pLocalReducer
,
tFilePage
*
tmpBuffer
)
{
static
void
savePreviousRow
(
SLocal
Merger
*
pLocalMerge
,
tFilePage
*
tmpBuffer
)
{
SColumnModel
*
pColumnModel
=
pLocal
Reducer
->
pDesc
->
pColumnModel
;
SColumnModel
*
pColumnModel
=
pLocal
Merge
->
pDesc
->
pColumnModel
;
assert
(
pColumnModel
->
capacity
==
1
&&
tmpBuffer
->
num
==
1
);
assert
(
pColumnModel
->
capacity
==
1
&&
tmpBuffer
->
num
==
1
);
// copy to previous temp buffer
// copy to previous temp buffer
...
@@ -1034,20 +1034,20 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
...
@@ -1034,20 +1034,20 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
SSchema
*
pSchema
=
getColumnModelSchema
(
pColumnModel
,
i
);
SSchema
*
pSchema
=
getColumnModelSchema
(
pColumnModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pColumnModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pColumnModel
,
i
);
memcpy
(
pLocal
Reducer
->
prevRowOfInput
+
offset
,
tmpBuffer
->
data
+
offset
,
pSchema
->
bytes
);
memcpy
(
pLocal
Merge
->
prevRowOfInput
+
offset
,
tmpBuffer
->
data
+
offset
,
pSchema
->
bytes
);
}
}
tmpBuffer
->
num
=
0
;
tmpBuffer
->
num
=
0
;
pLocal
Reducer
->
hasPrevRow
=
true
;
pLocal
Merge
->
hasPrevRow
=
true
;
}
}
static
void
doExecuteSecondaryMerge
(
SSqlCmd
*
pCmd
,
SLocal
Reducer
*
pLocalReducer
,
bool
needInit
)
{
static
void
doExecuteSecondaryMerge
(
SSqlCmd
*
pCmd
,
SLocal
Merger
*
pLocalMerge
,
bool
needInit
)
{
// the tag columns need to be set before all functions execution
// the tag columns need to be set before all functions execution
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
for
(
int32_t
j
=
0
;
j
<
size
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
size
;
++
j
)
{
SQLFunctionCtx
*
pCtx
=
&
pLocal
Reducer
->
pCtx
[
j
];
SQLFunctionCtx
*
pCtx
=
&
pLocal
Merge
->
pCtx
[
j
];
// tags/tags_dummy function, the tag field of SQLFunctionCtx is from the input buffer
// tags/tags_dummy function, the tag field of SQLFunctionCtx is from the input buffer
int32_t
functionId
=
pCtx
->
functionId
;
int32_t
functionId
=
pCtx
->
functionId
;
...
@@ -1074,20 +1074,20 @@ static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer,
...
@@ -1074,20 +1074,20 @@ static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer,
}
}
for
(
int32_t
j
=
0
;
j
<
size
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
size
;
++
j
)
{
int32_t
functionId
=
pLocal
Reducer
->
pCtx
[
j
].
functionId
;
int32_t
functionId
=
pLocal
Merge
->
pCtx
[
j
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TAG_DUMMY
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
if
(
functionId
==
TSDB_FUNC_TAG_DUMMY
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
continue
;
}
}
aAggs
[
functionId
].
mergeFunc
(
&
pLocal
Reducer
->
pCtx
[
j
]);
aAggs
[
functionId
].
mergeFunc
(
&
pLocal
Merge
->
pCtx
[
j
]);
}
}
}
}
static
void
handleUnprocessedRow
(
SSqlCmd
*
pCmd
,
SLocal
Reducer
*
pLocalReducer
,
tFilePage
*
tmpBuffer
)
{
static
void
handleUnprocessedRow
(
SSqlCmd
*
pCmd
,
SLocal
Merger
*
pLocalMerge
,
tFilePage
*
tmpBuffer
)
{
if
(
pLocal
Reducer
->
hasUnprocessedRow
)
{
if
(
pLocal
Merge
->
hasUnprocessedRow
)
{
pLocal
Reducer
->
hasUnprocessedRow
=
false
;
pLocal
Merge
->
hasUnprocessedRow
=
false
;
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Reducer
,
true
);
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Merge
,
true
);
savePreviousRow
(
pLocal
Reducer
,
tmpBuffer
);
savePreviousRow
(
pLocal
Merge
,
tmpBuffer
);
}
}
}
}
...
@@ -1120,7 +1120,7 @@ static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx)
...
@@ -1120,7 +1120,7 @@ static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx)
* filled with the same result, which is the tags, specified in group by clause
* filled with the same result, which is the tags, specified in group by clause
*
*
*/
*/
static
void
fillMultiRowsOfTagsVal
(
SQueryInfo
*
pQueryInfo
,
int32_t
numOfRes
,
SLocal
Reducer
*
pLocalReducer
)
{
static
void
fillMultiRowsOfTagsVal
(
SQueryInfo
*
pQueryInfo
,
int32_t
numOfRes
,
SLocal
Merger
*
pLocalMerge
)
{
int32_t
maxBufSize
=
0
;
// find the max tags column length to prepare the buffer
int32_t
maxBufSize
=
0
;
// find the max tags column length to prepare the buffer
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
...
@@ -1135,7 +1135,7 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
...
@@ -1135,7 +1135,7 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
char
*
buf
=
malloc
((
size_t
)
maxBufSize
);
char
*
buf
=
malloc
((
size_t
)
maxBufSize
);
for
(
int32_t
k
=
0
;
k
<
size
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
size
;
++
k
)
{
SQLFunctionCtx
*
pCtx
=
&
pLocal
Reducer
->
pCtx
[
k
];
SQLFunctionCtx
*
pCtx
=
&
pLocal
Merge
->
pCtx
[
k
];
if
(
pCtx
->
functionId
!=
TSDB_FUNC_TAG
)
{
if
(
pCtx
->
functionId
!=
TSDB_FUNC_TAG
)
{
continue
;
continue
;
}
}
...
@@ -1153,20 +1153,20 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
...
@@ -1153,20 +1153,20 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
free
(
buf
);
free
(
buf
);
}
}
int32_t
finalizeRes
(
SQueryInfo
*
pQueryInfo
,
SLocal
Reducer
*
pLocalReducer
)
{
int32_t
finalizeRes
(
SQueryInfo
*
pQueryInfo
,
SLocal
Merger
*
pLocalMerge
)
{
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
for
(
int32_t
k
=
0
;
k
<
size
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
size
;
++
k
)
{
SQLFunctionCtx
*
pCtx
=
&
pLocal
Reducer
->
pCtx
[
k
];
SQLFunctionCtx
*
pCtx
=
&
pLocal
Merge
->
pCtx
[
k
];
aAggs
[
pCtx
->
functionId
].
xFinalize
(
pCtx
);
aAggs
[
pCtx
->
functionId
].
xFinalize
(
pCtx
);
}
}
pLocal
Reducer
->
hasPrevRow
=
false
;
pLocal
Merge
->
hasPrevRow
=
false
;
int32_t
numOfRes
=
(
int32_t
)
getNumOfResultLocal
(
pQueryInfo
,
pLocal
Reducer
->
pCtx
);
int32_t
numOfRes
=
(
int32_t
)
getNumOfResultLocal
(
pQueryInfo
,
pLocal
Merge
->
pCtx
);
pLocal
Reducer
->
pResultBuf
->
num
+=
numOfRes
;
pLocal
Merge
->
pResultBuf
->
num
+=
numOfRes
;
fillMultiRowsOfTagsVal
(
pQueryInfo
,
numOfRes
,
pLocal
Reducer
);
fillMultiRowsOfTagsVal
(
pQueryInfo
,
numOfRes
,
pLocal
Merge
);
return
numOfRes
;
return
numOfRes
;
}
}
...
@@ -1177,22 +1177,22 @@ int32_t finalizeRes(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) {
...
@@ -1177,22 +1177,22 @@ int32_t finalizeRes(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) {
* results generated by simple aggregation function, we merge them all into one points
* results generated by simple aggregation function, we merge them all into one points
* *Exception*: column projection query, required no merge procedure
* *Exception*: column projection query, required no merge procedure
*/
*/
bool
needToMerge
(
SQueryInfo
*
pQueryInfo
,
SLocal
Reducer
*
pLocalReducer
,
tFilePage
*
tmpBuffer
)
{
bool
needToMerge
(
SQueryInfo
*
pQueryInfo
,
SLocal
Merger
*
pLocalMerge
,
tFilePage
*
tmpBuffer
)
{
int32_t
ret
=
0
;
// merge all result by default
int32_t
ret
=
0
;
// merge all result by default
int16_t
functionId
=
pLocal
Reducer
->
pCtx
[
0
].
functionId
;
int16_t
functionId
=
pLocal
Merge
->
pCtx
[
0
].
functionId
;
// todo opt performance
// todo opt performance
if
((
/*functionId == TSDB_FUNC_PRJ || */
functionId
==
TSDB_FUNC_ARITHM
)
||
(
tscIsProjectionQueryOnSTable
(
pQueryInfo
,
0
)))
{
// column projection query
if
((
/*functionId == TSDB_FUNC_PRJ || */
functionId
==
TSDB_FUNC_ARITHM
)
||
(
tscIsProjectionQueryOnSTable
(
pQueryInfo
,
0
)))
{
// column projection query
ret
=
1
;
// disable merge procedure
ret
=
1
;
// disable merge procedure
}
else
{
}
else
{
tOrderDescriptor
*
pDesc
=
pLocal
Reducer
->
pDesc
;
tOrderDescriptor
*
pDesc
=
pLocal
Merge
->
pDesc
;
if
(
pDesc
->
orderInfo
.
numOfCols
>
0
)
{
if
(
pDesc
->
orderInfo
.
numOfCols
>
0
)
{
if
(
pDesc
->
tsOrder
==
TSDB_ORDER_ASC
)
{
// asc
if
(
pDesc
->
tsOrder
==
TSDB_ORDER_ASC
)
{
// asc
// todo refactor comparator
// todo refactor comparator
ret
=
compare_a
(
pLocal
Reducer
->
pDesc
,
1
,
0
,
pLocalReducer
->
prevRowOfInput
,
1
,
0
,
tmpBuffer
->
data
);
ret
=
compare_a
(
pLocal
Merge
->
pDesc
,
1
,
0
,
pLocalMerge
->
prevRowOfInput
,
1
,
0
,
tmpBuffer
->
data
);
}
else
{
// desc
}
else
{
// desc
ret
=
compare_d
(
pLocal
Reducer
->
pDesc
,
1
,
0
,
pLocalReducer
->
prevRowOfInput
,
1
,
0
,
tmpBuffer
->
data
);
ret
=
compare_d
(
pLocal
Merge
->
pDesc
,
1
,
0
,
pLocalMerge
->
prevRowOfInput
,
1
,
0
,
tmpBuffer
->
data
);
}
}
}
}
}
}
...
@@ -1230,17 +1230,17 @@ static bool saveGroupResultInfo(SSqlObj *pSql) {
...
@@ -1230,17 +1230,17 @@ static bool saveGroupResultInfo(SSqlObj *pSql) {
/**
/**
*
*
* @param pSql
* @param pSql
* @param pLocal
Reducer
* @param pLocal
Merge
* @param noMoreCurrentGroupRes
* @param noMoreCurrentGroupRes
* @return if current group is skipped, return false, and do NOT record it into pRes->numOfGroups
* @return if current group is skipped, return false, and do NOT record it into pRes->numOfGroups
*/
*/
bool
genFinalResults
(
SSqlObj
*
pSql
,
SLocal
Reducer
*
pLocalReducer
,
bool
noMoreCurrentGroupRes
)
{
bool
genFinalResults
(
SSqlObj
*
pSql
,
SLocal
Merger
*
pLocalMerge
,
bool
noMoreCurrentGroupRes
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
tFilePage
*
pResBuf
=
pLocal
Reducer
->
pResultBuf
;
tFilePage
*
pResBuf
=
pLocal
Merge
->
pResultBuf
;
SColumnModel
*
pModel
=
pLocal
Reducer
->
resColModel
;
SColumnModel
*
pModel
=
pLocal
Merge
->
resColModel
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
...
@@ -1251,11 +1251,11 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
...
@@ -1251,11 +1251,11 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
if
(
pQueryInfo
->
slimit
.
offset
>
0
)
{
if
(
pQueryInfo
->
slimit
.
offset
>
0
)
{
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
pQueryInfo
->
slimit
.
offset
-=
1
;
pQueryInfo
->
slimit
.
offset
-=
1
;
pLocal
Reducer
->
discard
=
!
noMoreCurrentGroupRes
;
pLocal
Merge
->
discard
=
!
noMoreCurrentGroupRes
;
if
(
pLocal
Reducer
->
discard
)
{
if
(
pLocal
Merge
->
discard
)
{
SColumnModel
*
pInternModel
=
pLocal
Reducer
->
pDesc
->
pColumnModel
;
SColumnModel
*
pInternModel
=
pLocal
Merge
->
pDesc
->
pColumnModel
;
tColModelAppend
(
pInternModel
,
pLocal
Reducer
->
discardData
,
pLocalReducer
->
pTempBuffer
->
data
,
0
,
1
,
1
);
tColModelAppend
(
pInternModel
,
pLocal
Merge
->
discardData
,
pLocalMerge
->
pTempBuffer
->
data
,
0
,
1
,
1
);
}
}
return
false
;
return
false
;
...
@@ -1264,19 +1264,14 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
...
@@ -1264,19 +1264,14 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
tColModelCompact
(
pModel
,
pResBuf
,
pModel
->
capacity
);
tColModelCompact
(
pModel
,
pResBuf
,
pModel
->
capacity
);
if
(
tscIsSecondStageQuery
(
pQueryInfo
))
{
if
(
tscIsSecondStageQuery
(
pQueryInfo
))
{
doArithmeticCalculate
(
pQueryInfo
,
pResBuf
,
pModel
->
rowSize
,
pLocal
Reducer
->
finalModel
->
rowSize
);
doArithmeticCalculate
(
pQueryInfo
,
pResBuf
,
pModel
->
rowSize
,
pLocal
Merge
->
finalModel
->
rowSize
);
}
}
#ifdef _DEBUG_VIEW
printf
(
"final result before interpo:
\n
"
);
// tColModelDisplay(pLocalReducer->resColModel, pLocalReducer->pBufForInterpo, pResBuf->num, pResBuf->num);
#endif
// no interval query, no fill operation
// no interval query, no fill operation
if
(
pQueryInfo
->
interval
.
interval
==
0
||
pQueryInfo
->
fillType
==
TSDB_FILL_NONE
)
{
if
(
pQueryInfo
->
interval
.
interval
==
0
||
pQueryInfo
->
fillType
==
TSDB_FILL_NONE
)
{
genFinalResWithoutFill
(
pRes
,
pLocal
Reducer
,
pQueryInfo
);
genFinalResWithoutFill
(
pRes
,
pLocal
Merge
,
pQueryInfo
);
}
else
{
}
else
{
SFillInfo
*
pFillInfo
=
pLocal
Reducer
->
pFillInfo
;
SFillInfo
*
pFillInfo
=
pLocal
Merge
->
pFillInfo
;
if
(
pFillInfo
!=
NULL
)
{
if
(
pFillInfo
!=
NULL
)
{
TSKEY
ekey
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
ekey
:
pQueryInfo
->
window
.
skey
;
TSKEY
ekey
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
ekey
:
pQueryInfo
->
window
.
skey
;
...
@@ -1284,34 +1279,34 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
...
@@ -1284,34 +1279,34 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
taosFillCopyInputDataFromOneFilePage
(
pFillInfo
,
pResBuf
);
taosFillCopyInputDataFromOneFilePage
(
pFillInfo
,
pResBuf
);
}
}
doFillResult
(
pSql
,
pLocal
Reducer
,
noMoreCurrentGroupRes
);
doFillResult
(
pSql
,
pLocal
Merge
,
noMoreCurrentGroupRes
);
}
}
return
true
;
return
true
;
}
}
void
resetOutputBuf
(
SQueryInfo
*
pQueryInfo
,
SLocal
Reducer
*
pLocalReducer
)
{
// reset output buffer to the beginning
void
resetOutputBuf
(
SQueryInfo
*
pQueryInfo
,
SLocal
Merger
*
pLocalMerge
)
{
// reset output buffer to the beginning
size_t
t
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
size_t
t
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
for
(
int32_t
i
=
0
;
i
<
t
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
t
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
pLocal
Reducer
->
pCtx
[
i
].
aOutputBuf
=
pLocalReducer
->
pResultBuf
->
data
+
pExpr
->
offset
*
pLocalReducer
->
resColModel
->
capacity
;
pLocal
Merge
->
pCtx
[
i
].
aOutputBuf
=
pLocalMerge
->
pResultBuf
->
data
+
pExpr
->
offset
*
pLocalMerge
->
resColModel
->
capacity
;
if
(
pExpr
->
functionId
==
TSDB_FUNC_TOP
||
pExpr
->
functionId
==
TSDB_FUNC_BOTTOM
||
pExpr
->
functionId
==
TSDB_FUNC_DIFF
)
{
if
(
pExpr
->
functionId
==
TSDB_FUNC_TOP
||
pExpr
->
functionId
==
TSDB_FUNC_BOTTOM
||
pExpr
->
functionId
==
TSDB_FUNC_DIFF
)
{
pLocal
Reducer
->
pCtx
[
i
].
ptsOutputBuf
=
pLocalReducer
->
pCtx
[
0
].
aOutputBuf
;
pLocal
Merge
->
pCtx
[
i
].
ptsOutputBuf
=
pLocalMerge
->
pCtx
[
0
].
aOutputBuf
;
}
}
}
}
memset
(
pLocal
Reducer
->
pResultBuf
,
0
,
pLocalReducer
->
nResultBufSize
+
sizeof
(
tFilePage
));
memset
(
pLocal
Merge
->
pResultBuf
,
0
,
pLocalMerge
->
nResultBufSize
+
sizeof
(
tFilePage
));
}
}
static
void
resetEnvForNewResultset
(
SSqlRes
*
pRes
,
SSqlCmd
*
pCmd
,
SLocal
Reducer
*
pLocalReducer
)
{
static
void
resetEnvForNewResultset
(
SSqlRes
*
pRes
,
SSqlCmd
*
pCmd
,
SLocal
Merger
*
pLocalMerge
)
{
// In handling data in other groups, we need to reset the interpolation information for a new group data
// In handling data in other groups, we need to reset the interpolation information for a new group data
pRes
->
numOfRows
=
0
;
pRes
->
numOfRows
=
0
;
pRes
->
numOfRowsGroup
=
0
;
pRes
->
numOfRowsGroup
=
0
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
pQueryInfo
->
limit
.
offset
=
pLocal
Reducer
->
offset
;
pQueryInfo
->
limit
.
offset
=
pLocal
Merge
->
offset
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
...
@@ -1320,12 +1315,12 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
...
@@ -1320,12 +1315,12 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
if
(
pQueryInfo
->
fillType
!=
TSDB_FILL_NONE
)
{
if
(
pQueryInfo
->
fillType
!=
TSDB_FILL_NONE
)
{
TSKEY
skey
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
skey
:
pQueryInfo
->
window
.
ekey
;
//MIN(pQueryInfo->window.skey, pQueryInfo->window.ekey);
TSKEY
skey
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
skey
:
pQueryInfo
->
window
.
ekey
;
//MIN(pQueryInfo->window.skey, pQueryInfo->window.ekey);
int64_t
newTime
=
taosTimeTruncate
(
skey
,
&
pQueryInfo
->
interval
,
tinfo
.
precision
);
int64_t
newTime
=
taosTimeTruncate
(
skey
,
&
pQueryInfo
->
interval
,
tinfo
.
precision
);
taosResetFillInfo
(
pLocal
Reducer
->
pFillInfo
,
newTime
);
taosResetFillInfo
(
pLocal
Merge
->
pFillInfo
,
newTime
);
}
}
}
}
static
bool
isAllSourcesCompleted
(
SLocal
Reducer
*
pLocalReducer
)
{
static
bool
isAllSourcesCompleted
(
SLocal
Merger
*
pLocalMerge
)
{
return
(
pLocal
Reducer
->
numOfBuffer
==
pLocalReducer
->
numOfCompleted
);
return
(
pLocal
Merge
->
numOfBuffer
==
pLocalMerge
->
numOfCompleted
);
}
}
static
bool
doBuildFilledResultForGroup
(
SSqlObj
*
pSql
)
{
static
bool
doBuildFilledResultForGroup
(
SSqlObj
*
pSql
)
{
...
@@ -1333,19 +1328,19 @@ static bool doBuildFilledResultForGroup(SSqlObj *pSql) {
...
@@ -1333,19 +1328,19 @@ static bool doBuildFilledResultForGroup(SSqlObj *pSql) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SLocal
Reducer
*
pLocalReducer
=
pRes
->
pLocalReduc
er
;
SLocal
Merger
*
pLocalMerge
=
pRes
->
pLocalMerg
er
;
SFillInfo
*
pFillInfo
=
pLocal
Reducer
->
pFillInfo
;
SFillInfo
*
pFillInfo
=
pLocal
Merge
->
pFillInfo
;
if
(
pFillInfo
!=
NULL
&&
taosFillHasMoreResults
(
pFillInfo
))
{
if
(
pFillInfo
!=
NULL
&&
taosFillHasMoreResults
(
pFillInfo
))
{
assert
(
pQueryInfo
->
fillType
!=
TSDB_FILL_NONE
);
assert
(
pQueryInfo
->
fillType
!=
TSDB_FILL_NONE
);
tFilePage
*
pFinalDataBuf
=
pLocal
Reducer
->
pResultBuf
;
tFilePage
*
pFinalDataBuf
=
pLocal
Merge
->
pResultBuf
;
int64_t
etime
=
*
(
int64_t
*
)(
pFinalDataBuf
->
data
+
TSDB_KEYSIZE
*
(
pFillInfo
->
numOfRows
-
1
));
int64_t
etime
=
*
(
int64_t
*
)(
pFinalDataBuf
->
data
+
TSDB_KEYSIZE
*
(
pFillInfo
->
numOfRows
-
1
));
// the first column must be the timestamp column
// the first column must be the timestamp column
int32_t
rows
=
(
int32_t
)
getNumOfResultsAfterFillGap
(
pFillInfo
,
etime
,
pLocal
Reducer
->
resColModel
->
capacity
);
int32_t
rows
=
(
int32_t
)
getNumOfResultsAfterFillGap
(
pFillInfo
,
etime
,
pLocal
Merge
->
resColModel
->
capacity
);
if
(
rows
>
0
)
{
// do fill gap
if
(
rows
>
0
)
{
// do fill gap
doFillResult
(
pSql
,
pLocal
Reducer
,
false
);
doFillResult
(
pSql
,
pLocal
Merge
,
false
);
}
}
return
true
;
return
true
;
...
@@ -1358,23 +1353,23 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
...
@@ -1358,23 +1353,23 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SLocal
Reducer
*
pLocalReducer
=
pRes
->
pLocalReduc
er
;
SLocal
Merger
*
pLocalMerge
=
pRes
->
pLocalMerg
er
;
SFillInfo
*
pFillInfo
=
pLocal
Reducer
->
pFillInfo
;
SFillInfo
*
pFillInfo
=
pLocal
Merge
->
pFillInfo
;
bool
prevGroupCompleted
=
(
!
pLocal
Reducer
->
discard
)
&&
pLocalReducer
->
hasUnprocessedRow
;
bool
prevGroupCompleted
=
(
!
pLocal
Merge
->
discard
)
&&
pLocalMerge
->
hasUnprocessedRow
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
if
((
isAllSourcesCompleted
(
pLocal
Reducer
)
&&
!
pLocalReducer
->
hasPrevRow
)
||
pLocalReducer
->
pLocalDataSrc
[
0
]
==
NULL
||
if
((
isAllSourcesCompleted
(
pLocal
Merge
)
&&
!
pLocalMerge
->
hasPrevRow
)
||
pLocalMerge
->
pLocalDataSrc
[
0
]
==
NULL
||
prevGroupCompleted
)
{
prevGroupCompleted
)
{
// if fillType == TSDB_FILL_NONE, return directly
// if fillType == TSDB_FILL_NONE, return directly
if
(
pQueryInfo
->
fillType
!=
TSDB_FILL_NONE
&&
if
(
pQueryInfo
->
fillType
!=
TSDB_FILL_NONE
&&
((
pRes
->
numOfRowsGroup
<
pQueryInfo
->
limit
.
limit
&&
pQueryInfo
->
limit
.
limit
>
0
)
||
(
pQueryInfo
->
limit
.
limit
<
0
)))
{
((
pRes
->
numOfRowsGroup
<
pQueryInfo
->
limit
.
limit
&&
pQueryInfo
->
limit
.
limit
>
0
)
||
(
pQueryInfo
->
limit
.
limit
<
0
)))
{
int64_t
etime
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
ekey
:
pQueryInfo
->
window
.
skey
;
int64_t
etime
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
ekey
:
pQueryInfo
->
window
.
skey
;
int32_t
rows
=
(
int32_t
)
getNumOfResultsAfterFillGap
(
pFillInfo
,
etime
,
pLocal
Reducer
->
resColModel
->
capacity
);
int32_t
rows
=
(
int32_t
)
getNumOfResultsAfterFillGap
(
pFillInfo
,
etime
,
pLocal
Merge
->
resColModel
->
capacity
);
if
(
rows
>
0
)
{
if
(
rows
>
0
)
{
doFillResult
(
pSql
,
pLocal
Reducer
,
true
);
doFillResult
(
pSql
,
pLocal
Merge
,
true
);
}
}
}
}
...
@@ -1384,7 +1379,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
...
@@ -1384,7 +1379,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
*
*
* No results will be generated and query completed.
* No results will be generated and query completed.
*/
*/
if
(
pRes
->
numOfRows
>
0
||
(
isAllSourcesCompleted
(
pLocal
Reducer
)
&&
(
!
pLocalReducer
->
hasUnprocessedRow
)))
{
if
(
pRes
->
numOfRows
>
0
||
(
isAllSourcesCompleted
(
pLocal
Merge
)
&&
(
!
pLocalMerge
->
hasUnprocessedRow
)))
{
return
true
;
return
true
;
}
}
...
@@ -1393,7 +1388,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
...
@@ -1393,7 +1388,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
return
true
;
return
true
;
}
}
resetEnvForNewResultset
(
pRes
,
pCmd
,
pLocal
Reducer
);
resetEnvForNewResultset
(
pRes
,
pCmd
,
pLocal
Merge
);
}
}
return
false
;
return
false
;
...
@@ -1403,12 +1398,12 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) {
...
@@ -1403,12 +1398,12 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SLocal
Reducer
*
pLocalReducer
=
pRes
->
pLocalReduc
er
;
SLocal
Merger
*
pLocalMerge
=
pRes
->
pLocalMerg
er
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
for
(
int32_t
k
=
0
;
k
<
size
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
size
;
++
k
)
{
SQLFunctionCtx
*
pCtx
=
&
pLocal
Reducer
->
pCtx
[
k
];
SQLFunctionCtx
*
pCtx
=
&
pLocal
Merge
->
pCtx
[
k
];
pCtx
->
aOutputBuf
+=
pCtx
->
outputBytes
*
numOfRes
;
pCtx
->
aOutputBuf
+=
pCtx
->
outputBytes
*
numOfRes
;
// set the correct output timestamp column position
// set the correct output timestamp column position
...
@@ -1417,7 +1412,7 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) {
...
@@ -1417,7 +1412,7 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) {
}
}
}
}
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Reducer
,
true
);
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Merge
,
true
);
}
}
int32_t
tscDoLocalMerge
(
SSqlObj
*
pSql
)
{
int32_t
tscDoLocalMerge
(
SSqlObj
*
pSql
)
{
...
@@ -1426,14 +1421,14 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
...
@@ -1426,14 +1421,14 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
tscResetForNextRetrieve
(
pRes
);
tscResetForNextRetrieve
(
pRes
);
if
(
pSql
->
signature
!=
pSql
||
pRes
==
NULL
||
pRes
->
pLocal
Reduc
er
==
NULL
)
{
// all data has been processed
if
(
pSql
->
signature
!=
pSql
||
pRes
==
NULL
||
pRes
->
pLocal
Merg
er
==
NULL
)
{
// all data has been processed
tscError
(
"%p local merge abort due to error occurs, code:%s"
,
pSql
,
tstrerror
(
pRes
->
code
));
tscError
(
"%p local merge abort due to error occurs, code:%s"
,
pSql
,
tstrerror
(
pRes
->
code
));
return
pRes
->
code
;
return
pRes
->
code
;
}
}
SLocal
Reducer
*
pLocalReducer
=
pRes
->
pLocalReduc
er
;
SLocal
Merger
*
pLocalMerge
=
pRes
->
pLocalMerg
er
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
tFilePage
*
tmpBuffer
=
pLocal
Reducer
->
pTempBuffer
;
tFilePage
*
tmpBuffer
=
pLocal
Merge
->
pTempBuffer
;
if
(
doHandleLastRemainData
(
pSql
))
{
if
(
doHandleLastRemainData
(
pSql
))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1443,24 +1438,24 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
...
@@ -1443,24 +1438,24 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SLoserTreeInfo
*
pTree
=
pLocal
Reducer
->
pLoserTree
;
SLoserTreeInfo
*
pTree
=
pLocal
Merge
->
pLoserTree
;
// clear buffer
// clear buffer
handleUnprocessedRow
(
pCmd
,
pLocal
Reducer
,
tmpBuffer
);
handleUnprocessedRow
(
pCmd
,
pLocal
Merge
,
tmpBuffer
);
SColumnModel
*
pModel
=
pLocal
Reducer
->
pDesc
->
pColumnModel
;
SColumnModel
*
pModel
=
pLocal
Merge
->
pDesc
->
pColumnModel
;
while
(
1
)
{
while
(
1
)
{
if
(
isAllSourcesCompleted
(
pLocal
Reducer
))
{
if
(
isAllSourcesCompleted
(
pLocal
Merge
))
{
break
;
break
;
}
}
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
printf
(
"chosen data in pTree[0] = %d
\n
"
,
pTree
->
pNode
[
0
].
index
);
printf
(
"chosen data in pTree[0] = %d
\n
"
,
pTree
->
pNode
[
0
].
index
);
#endif
#endif
assert
((
pTree
->
pNode
[
0
].
index
<
pLocal
Reducer
->
numOfBuffer
)
&&
(
pTree
->
pNode
[
0
].
index
>=
0
)
&&
tmpBuffer
->
num
==
0
);
assert
((
pTree
->
pNode
[
0
].
index
<
pLocal
Merge
->
numOfBuffer
)
&&
(
pTree
->
pNode
[
0
].
index
>=
0
)
&&
tmpBuffer
->
num
==
0
);
// chosen from loser tree
// chosen from loser tree
SLocalDataSource
*
pOneDataSrc
=
pLocal
Reducer
->
pLocalDataSrc
[
pTree
->
pNode
[
0
].
index
];
SLocalDataSource
*
pOneDataSrc
=
pLocal
Merge
->
pLocalDataSrc
[
pTree
->
pNode
[
0
].
index
];
tColModelAppend
(
pModel
,
tmpBuffer
,
pOneDataSrc
->
filePage
.
data
,
pOneDataSrc
->
rowIdx
,
1
,
tColModelAppend
(
pModel
,
tmpBuffer
,
pOneDataSrc
->
filePage
.
data
,
pOneDataSrc
->
rowIdx
,
1
,
pOneDataSrc
->
pMemBuffer
->
pColumnModel
->
capacity
);
pOneDataSrc
->
pMemBuffer
->
pColumnModel
->
capacity
);
...
@@ -1473,76 +1468,76 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
...
@@ -1473,76 +1468,76 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
tColModelDisplayEx
(
pModel
,
tmpBuffer
->
data
,
tmpBuffer
->
num
,
pModel
->
capacity
,
colInfo
);
tColModelDisplayEx
(
pModel
,
tmpBuffer
->
data
,
tmpBuffer
->
num
,
pModel
->
capacity
,
colInfo
);
#endif
#endif
if
(
pLocal
Reducer
->
discard
)
{
if
(
pLocal
Merge
->
discard
)
{
assert
(
pLocal
Reducer
->
hasUnprocessedRow
==
false
);
assert
(
pLocal
Merge
->
hasUnprocessedRow
==
false
);
/* current record belongs to the same group of previous record, need to discard it */
/* current record belongs to the same group of previous record, need to discard it */
if
(
isSameGroup
(
pCmd
,
pLocal
Reducer
,
pLocalReducer
->
discardData
->
data
,
tmpBuffer
))
{
if
(
isSameGroup
(
pCmd
,
pLocal
Merge
,
pLocalMerge
->
discardData
->
data
,
tmpBuffer
))
{
tmpBuffer
->
num
=
0
;
tmpBuffer
->
num
=
0
;
pOneDataSrc
->
rowIdx
+=
1
;
pOneDataSrc
->
rowIdx
+=
1
;
adjustLoserTreeFromNewData
(
pLocal
Reducer
,
pOneDataSrc
,
pTree
);
adjustLoserTreeFromNewData
(
pLocal
Merge
,
pOneDataSrc
,
pTree
);
// all inputs are exhausted, abort current process
// all inputs are exhausted, abort current process
if
(
isAllSourcesCompleted
(
pLocal
Reducer
))
{
if
(
isAllSourcesCompleted
(
pLocal
Merge
))
{
break
;
break
;
}
}
// data belongs to the same group needs to be discarded
// data belongs to the same group needs to be discarded
continue
;
continue
;
}
else
{
}
else
{
pLocal
Reducer
->
discard
=
false
;
pLocal
Merge
->
discard
=
false
;
pLocal
Reducer
->
discardData
->
num
=
0
;
pLocal
Merge
->
discardData
->
num
=
0
;
if
(
saveGroupResultInfo
(
pSql
))
{
if
(
saveGroupResultInfo
(
pSql
))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
resetEnvForNewResultset
(
pRes
,
pCmd
,
pLocal
Reducer
);
resetEnvForNewResultset
(
pRes
,
pCmd
,
pLocal
Merge
);
}
}
}
}
if
(
pLocal
Reducer
->
hasPrevRow
)
{
if
(
pLocal
Merge
->
hasPrevRow
)
{
if
(
needToMerge
(
pQueryInfo
,
pLocal
Reducer
,
tmpBuffer
))
{
if
(
needToMerge
(
pQueryInfo
,
pLocal
Merge
,
tmpBuffer
))
{
// belong to the group of the previous row, continue process it
// belong to the group of the previous row, continue process it
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Reducer
,
false
);
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Merge
,
false
);
// copy to buffer
// copy to buffer
savePreviousRow
(
pLocal
Reducer
,
tmpBuffer
);
savePreviousRow
(
pLocal
Merge
,
tmpBuffer
);
}
else
{
}
else
{
/*
/*
* current row does not belong to the group of previous row.
* current row does not belong to the group of previous row.
* so the processing of previous group is completed.
* so the processing of previous group is completed.
*/
*/
int32_t
numOfRes
=
finalizeRes
(
pQueryInfo
,
pLocal
Reducer
);
int32_t
numOfRes
=
finalizeRes
(
pQueryInfo
,
pLocal
Merge
);
bool
sameGroup
=
isSameGroup
(
pCmd
,
pLocal
Reducer
,
pLocalReducer
->
prevRowOfInput
,
tmpBuffer
);
bool
sameGroup
=
isSameGroup
(
pCmd
,
pLocal
Merge
,
pLocalMerge
->
prevRowOfInput
,
tmpBuffer
);
tFilePage
*
pResBuf
=
pLocal
Reducer
->
pResultBuf
;
tFilePage
*
pResBuf
=
pLocal
Merge
->
pResultBuf
;
/*
/*
* if the previous group does NOT generate any result (pResBuf->num == 0),
* if the previous group does NOT generate any result (pResBuf->num == 0),
* continue to process results instead of return results.
* continue to process results instead of return results.
*/
*/
if
((
!
sameGroup
&&
pResBuf
->
num
>
0
)
||
(
pResBuf
->
num
==
pLocal
Reducer
->
resColModel
->
capacity
))
{
if
((
!
sameGroup
&&
pResBuf
->
num
>
0
)
||
(
pResBuf
->
num
==
pLocal
Merge
->
resColModel
->
capacity
))
{
// does not belong to the same group
// does not belong to the same group
bool
notSkipped
=
genFinalResults
(
pSql
,
pLocal
Reducer
,
!
sameGroup
);
bool
notSkipped
=
genFinalResults
(
pSql
,
pLocal
Merge
,
!
sameGroup
);
// this row needs to discard, since it belongs to the group of previous
// this row needs to discard, since it belongs to the group of previous
if
(
pLocal
Reducer
->
discard
&&
sameGroup
)
{
if
(
pLocal
Merge
->
discard
&&
sameGroup
)
{
pLocal
Reducer
->
hasUnprocessedRow
=
false
;
pLocal
Merge
->
hasUnprocessedRow
=
false
;
tmpBuffer
->
num
=
0
;
tmpBuffer
->
num
=
0
;
}
else
{
// current row does not belongs to the previous group, so it is not be handled yet.
}
else
{
// current row does not belongs to the previous group, so it is not be handled yet.
pLocal
Reducer
->
hasUnprocessedRow
=
true
;
pLocal
Merge
->
hasUnprocessedRow
=
true
;
}
}
resetOutputBuf
(
pQueryInfo
,
pLocal
Reducer
);
resetOutputBuf
(
pQueryInfo
,
pLocal
Merge
);
pOneDataSrc
->
rowIdx
+=
1
;
pOneDataSrc
->
rowIdx
+=
1
;
// here we do not check the return value
// here we do not check the return value
adjustLoserTreeFromNewData
(
pLocal
Reducer
,
pOneDataSrc
,
pTree
);
adjustLoserTreeFromNewData
(
pLocal
Merge
,
pOneDataSrc
,
pTree
);
if
(
pRes
->
numOfRows
==
0
)
{
if
(
pRes
->
numOfRows
==
0
)
{
handleUnprocessedRow
(
pCmd
,
pLocal
Reducer
,
tmpBuffer
);
handleUnprocessedRow
(
pCmd
,
pLocal
Merge
,
tmpBuffer
);
if
(
!
sameGroup
)
{
if
(
!
sameGroup
)
{
/*
/*
...
@@ -1553,7 +1548,7 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
...
@@ -1553,7 +1548,7 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
resetEnvForNewResultset
(
pRes
,
pCmd
,
pLocal
Reducer
);
resetEnvForNewResultset
(
pRes
,
pCmd
,
pLocal
Merge
);
}
}
}
else
{
}
else
{
/*
/*
...
@@ -1561,7 +1556,7 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
...
@@ -1561,7 +1556,7 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
* We start the process in a new round.
* We start the process in a new round.
*/
*/
if
(
sameGroup
)
{
if
(
sameGroup
)
{
handleUnprocessedRow
(
pCmd
,
pLocal
Reducer
,
tmpBuffer
);
handleUnprocessedRow
(
pCmd
,
pLocal
Merge
,
tmpBuffer
);
}
}
}
}
...
@@ -1573,24 +1568,24 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
...
@@ -1573,24 +1568,24 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
}
}
}
else
{
// result buffer is not full
}
else
{
// result buffer is not full
doProcessResultInNextWindow
(
pSql
,
numOfRes
);
doProcessResultInNextWindow
(
pSql
,
numOfRes
);
savePreviousRow
(
pLocal
Reducer
,
tmpBuffer
);
savePreviousRow
(
pLocal
Merge
,
tmpBuffer
);
}
}
}
}
}
else
{
}
else
{
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Reducer
,
true
);
doExecuteSecondaryMerge
(
pCmd
,
pLocal
Merge
,
true
);
savePreviousRow
(
pLocal
Reducer
,
tmpBuffer
);
// copy the processed row to buffer
savePreviousRow
(
pLocal
Merge
,
tmpBuffer
);
// copy the processed row to buffer
}
}
pOneDataSrc
->
rowIdx
+=
1
;
pOneDataSrc
->
rowIdx
+=
1
;
adjustLoserTreeFromNewData
(
pLocal
Reducer
,
pOneDataSrc
,
pTree
);
adjustLoserTreeFromNewData
(
pLocal
Merge
,
pOneDataSrc
,
pTree
);
}
}
if
(
pLocal
Reducer
->
hasPrevRow
)
{
if
(
pLocal
Merge
->
hasPrevRow
)
{
finalizeRes
(
pQueryInfo
,
pLocal
Reducer
);
finalizeRes
(
pQueryInfo
,
pLocal
Merge
);
}
}
if
(
pLocal
Reducer
->
pResultBuf
->
num
)
{
if
(
pLocal
Merge
->
pResultBuf
->
num
)
{
genFinalResults
(
pSql
,
pLocal
Reducer
,
true
);
genFinalResults
(
pSql
,
pLocal
Merge
,
true
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1598,8 +1593,8 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
...
@@ -1598,8 +1593,8 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
void
tscInitResObjForLocalQuery
(
SSqlObj
*
pObj
,
int32_t
numOfRes
,
int32_t
rowLen
)
{
void
tscInitResObjForLocalQuery
(
SSqlObj
*
pObj
,
int32_t
numOfRes
,
int32_t
rowLen
)
{
SSqlRes
*
pRes
=
&
pObj
->
res
;
SSqlRes
*
pRes
=
&
pObj
->
res
;
if
(
pRes
->
pLocal
Reduc
er
!=
NULL
)
{
if
(
pRes
->
pLocal
Merg
er
!=
NULL
)
{
tscDestroyLocal
Reduc
er
(
pObj
);
tscDestroyLocal
Merg
er
(
pObj
);
}
}
pRes
->
qhandle
=
1
;
// hack to pass the safety check in fetch_row function
pRes
->
qhandle
=
1
;
// hack to pass the safety check in fetch_row function
...
@@ -1607,17 +1602,17 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen)
...
@@ -1607,17 +1602,17 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen)
pRes
->
row
=
0
;
pRes
->
row
=
0
;
pRes
->
rspType
=
0
;
// used as a flag to denote if taos_retrieved() has been called yet
pRes
->
rspType
=
0
;
// used as a flag to denote if taos_retrieved() has been called yet
pRes
->
pLocal
Reducer
=
(
SLocalReducer
*
)
calloc
(
1
,
sizeof
(
SLocalReduc
er
));
pRes
->
pLocal
Merger
=
(
SLocalMerger
*
)
calloc
(
1
,
sizeof
(
SLocalMerg
er
));
/*
/*
* we need one additional byte space
* we need one additional byte space
* the sprintf function needs one additional space to put '\0' at the end of string
* the sprintf function needs one additional space to put '\0' at the end of string
*/
*/
size_t
allocSize
=
numOfRes
*
rowLen
+
sizeof
(
tFilePage
)
+
1
;
size_t
allocSize
=
numOfRes
*
rowLen
+
sizeof
(
tFilePage
)
+
1
;
pRes
->
pLocal
Reduc
er
->
pResultBuf
=
(
tFilePage
*
)
calloc
(
1
,
allocSize
);
pRes
->
pLocal
Merg
er
->
pResultBuf
=
(
tFilePage
*
)
calloc
(
1
,
allocSize
);
pRes
->
pLocal
Reduc
er
->
pResultBuf
->
num
=
numOfRes
;
pRes
->
pLocal
Merg
er
->
pResultBuf
->
num
=
numOfRes
;
pRes
->
data
=
pRes
->
pLocal
Reduc
er
->
pResultBuf
->
data
;
pRes
->
data
=
pRes
->
pLocal
Merg
er
->
pResultBuf
->
data
;
}
}
int32_t
doArithmeticCalculate
(
SQueryInfo
*
pQueryInfo
,
tFilePage
*
pOutput
,
int32_t
rowSize
,
int32_t
finalRowSize
)
{
int32_t
doArithmeticCalculate
(
SQueryInfo
*
pQueryInfo
,
tFilePage
*
pOutput
,
int32_t
rowSize
,
int32_t
finalRowSize
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
6402c2b0
...
@@ -2444,7 +2444,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
...
@@ -2444,7 +2444,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
clauseIndex
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
STableMetaInfo
*
pMInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
STableMetaInfo
*
pMInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
STableMeta
*
pTableMeta
=
tscTableMeta
Clone
(
pMInfo
->
pTableMeta
);
STableMeta
*
pTableMeta
=
tscTableMeta
Dup
(
pMInfo
->
pTableMeta
);
tscAddTableMetaInfo
(
pNewQueryInfo
,
pMInfo
->
name
,
pTableMeta
,
NULL
,
pMInfo
->
tagColList
,
pMInfo
->
pVgroupTables
);
tscAddTableMetaInfo
(
pNewQueryInfo
,
pMInfo
->
name
,
pTableMeta
,
NULL
,
pMInfo
->
tagColList
,
pMInfo
->
pVgroupTables
);
}
}
...
...
src/client/src/tscSubquery.c
浏览文件 @
6402c2b0
...
@@ -885,10 +885,10 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
...
@@ -885,10 +885,10 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
tscBuildVgroupTableInfo
(
pParentSql
,
pTableMetaInfo2
,
s2
);
tscBuildVgroupTableInfo
(
pParentSql
,
pTableMetaInfo2
,
s2
);
SSqlObj
*
psub1
=
pParentSql
->
pSubs
[
0
];
SSqlObj
*
psub1
=
pParentSql
->
pSubs
[
0
];
((
SJoinSupporter
*
)
psub1
->
param
)
->
pVgroupTables
=
tscVgroupTableInfo
Clone
(
pTableMetaInfo1
->
pVgroupTables
);
((
SJoinSupporter
*
)
psub1
->
param
)
->
pVgroupTables
=
tscVgroupTableInfo
Dup
(
pTableMetaInfo1
->
pVgroupTables
);
SSqlObj
*
psub2
=
pParentSql
->
pSubs
[
1
];
SSqlObj
*
psub2
=
pParentSql
->
pSubs
[
1
];
((
SJoinSupporter
*
)
psub2
->
param
)
->
pVgroupTables
=
tscVgroupTableInfo
Clone
(
pTableMetaInfo2
->
pVgroupTables
);
((
SJoinSupporter
*
)
psub2
->
param
)
->
pVgroupTables
=
tscVgroupTableInfo
Dup
(
pTableMetaInfo2
->
pVgroupTables
);
pParentSql
->
subState
.
numOfSub
=
2
;
pParentSql
->
subState
.
numOfSub
=
2
;
pParentSql
->
subState
.
numOfRemain
=
pParentSql
->
subState
.
numOfSub
;
pParentSql
->
subState
.
numOfRemain
=
pParentSql
->
subState
.
numOfSub
;
...
@@ -1998,7 +1998,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
...
@@ -1998,7 +1998,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
0
);
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
0
);
tscClearInterpInfo
(
pPQueryInfo
);
tscClearInterpInfo
(
pPQueryInfo
);
tscCreateLocal
Reduc
er
(
trsupport
->
pExtMemBuffer
,
pState
->
numOfSub
,
pDesc
,
trsupport
->
pFinalColModel
,
trsupport
->
pFFColModel
,
pParentSql
);
tscCreateLocal
Merg
er
(
trsupport
->
pExtMemBuffer
,
pState
->
numOfSub
,
pDesc
,
trsupport
->
pFinalColModel
,
trsupport
->
pFFColModel
,
pParentSql
);
tscDebug
(
"%p build loser tree completed"
,
pParentSql
);
tscDebug
(
"%p build loser tree completed"
,
pParentSql
);
pParentSql
->
res
.
precision
=
pSql
->
res
.
precision
;
pParentSql
->
res
.
precision
=
pSql
->
res
.
precision
;
...
...
src/client/src/tscUtil.c
浏览文件 @
6402c2b0
...
@@ -420,7 +420,7 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd) {
...
@@ -420,7 +420,7 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd) {
}
}
void
tscFreeSqlResult
(
SSqlObj
*
pSql
)
{
void
tscFreeSqlResult
(
SSqlObj
*
pSql
)
{
tscDestroyLocal
Reduc
er
(
pSql
);
tscDestroyLocal
Merg
er
(
pSql
);
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
tscDestroyResPointerInfo
(
pRes
);
tscDestroyResPointerInfo
(
pRes
);
...
@@ -612,7 +612,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
...
@@ -612,7 +612,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
tfree
(
pTableMetaInfo
->
pTableMeta
);
tfree
(
pTableMetaInfo
->
pTableMeta
);
}
}
pTableMetaInfo
->
pTableMeta
=
tscTableMeta
Clone
(
pDataBlock
->
pTableMeta
);
pTableMetaInfo
->
pTableMeta
=
tscTableMeta
Dup
(
pDataBlock
->
pTableMeta
);
}
else
{
}
else
{
assert
(
strncmp
(
pTableMetaInfo
->
name
,
pDataBlock
->
tableName
,
tListLen
(
pDataBlock
->
tableName
))
==
0
);
assert
(
strncmp
(
pTableMetaInfo
->
name
,
pDataBlock
->
tableName
,
tListLen
(
pDataBlock
->
tableName
))
==
0
);
}
}
...
@@ -680,7 +680,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
...
@@ -680,7 +680,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
tstrncpy
(
dataBuf
->
tableName
,
name
,
sizeof
(
dataBuf
->
tableName
));
tstrncpy
(
dataBuf
->
tableName
,
name
,
sizeof
(
dataBuf
->
tableName
));
//Here we keep the tableMeta to avoid it to be remove by other threads.
//Here we keep the tableMeta to avoid it to be remove by other threads.
dataBuf
->
pTableMeta
=
tscTableMeta
Clone
(
pTableMeta
);
dataBuf
->
pTableMeta
=
tscTableMeta
Dup
(
pTableMeta
);
assert
(
initialSize
>
0
&&
pTableMeta
!=
NULL
&&
dataBuf
->
pTableMeta
!=
NULL
);
assert
(
initialSize
>
0
&&
pTableMeta
!=
NULL
&&
dataBuf
->
pTableMeta
!=
NULL
);
*
dataBlocks
=
dataBuf
;
*
dataBlocks
=
dataBuf
;
...
@@ -1810,10 +1810,10 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo) {
...
@@ -1810,10 +1810,10 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo) {
info
->
vgInfo
.
epAddr
[
j
].
fqdn
=
strdup
(
pInfo
->
vgInfo
.
epAddr
[
j
].
fqdn
);
info
->
vgInfo
.
epAddr
[
j
].
fqdn
=
strdup
(
pInfo
->
vgInfo
.
epAddr
[
j
].
fqdn
);
}
}
info
->
itemList
=
taosArray
Clone
(
pInfo
->
itemList
);
info
->
itemList
=
taosArray
Dup
(
pInfo
->
itemList
);
}
}
SArray
*
tscVgroupTableInfo
Clone
(
SArray
*
pVgroupTables
)
{
SArray
*
tscVgroupTableInfo
Dup
(
SArray
*
pVgroupTables
)
{
if
(
pVgroupTables
==
NULL
)
{
if
(
pVgroupTables
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -1881,7 +1881,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
...
@@ -1881,7 +1881,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
tscColumnListCopy
(
pTableMetaInfo
->
tagColList
,
pTagCols
,
-
1
);
tscColumnListCopy
(
pTableMetaInfo
->
tagColList
,
pTagCols
,
-
1
);
}
}
pTableMetaInfo
->
pVgroupTables
=
tscVgroupTableInfo
Clone
(
pVgroupTables
);
pTableMetaInfo
->
pVgroupTables
=
tscVgroupTableInfo
Dup
(
pVgroupTables
);
pQueryInfo
->
numOfTables
+=
1
;
pQueryInfo
->
numOfTables
+=
1
;
return
pTableMetaInfo
;
return
pTableMetaInfo
;
...
@@ -2064,7 +2064,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
...
@@ -2064,7 +2064,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
pNewQueryInfo
->
groupbyExpr
=
pQueryInfo
->
groupbyExpr
;
pNewQueryInfo
->
groupbyExpr
=
pQueryInfo
->
groupbyExpr
;
if
(
pQueryInfo
->
groupbyExpr
.
columnInfo
!=
NULL
)
{
if
(
pQueryInfo
->
groupbyExpr
.
columnInfo
!=
NULL
)
{
pNewQueryInfo
->
groupbyExpr
.
columnInfo
=
taosArray
Clone
(
pQueryInfo
->
groupbyExpr
.
columnInfo
);
pNewQueryInfo
->
groupbyExpr
.
columnInfo
=
taosArray
Dup
(
pQueryInfo
->
groupbyExpr
.
columnInfo
);
if
(
pNewQueryInfo
->
groupbyExpr
.
columnInfo
==
NULL
)
{
if
(
pNewQueryInfo
->
groupbyExpr
.
columnInfo
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
_error
;
goto
_error
;
...
@@ -2119,7 +2119,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
...
@@ -2119,7 +2119,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
STableMetaInfo
*
pFinalInfo
=
NULL
;
STableMetaInfo
*
pFinalInfo
=
NULL
;
if
(
pPrevSql
==
NULL
)
{
if
(
pPrevSql
==
NULL
)
{
STableMeta
*
pTableMeta
=
tscTableMeta
Clone
(
pTableMetaInfo
->
pTableMeta
);
STableMeta
*
pTableMeta
=
tscTableMeta
Dup
(
pTableMetaInfo
->
pTableMeta
);
assert
(
pTableMeta
!=
NULL
);
assert
(
pTableMeta
!=
NULL
);
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
name
,
pTableMeta
,
pTableMetaInfo
->
vgroupList
,
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
name
,
pTableMeta
,
pTableMetaInfo
->
vgroupList
,
...
@@ -2127,7 +2127,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
...
@@ -2127,7 +2127,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
}
else
{
// transfer the ownership of pTableMeta to the newly create sql object.
}
else
{
// transfer the ownership of pTableMeta to the newly create sql object.
STableMetaInfo
*
pPrevInfo
=
tscGetTableMetaInfoFromCmd
(
&
pPrevSql
->
cmd
,
pPrevSql
->
cmd
.
clauseIndex
,
0
);
STableMetaInfo
*
pPrevInfo
=
tscGetTableMetaInfoFromCmd
(
&
pPrevSql
->
cmd
,
pPrevSql
->
cmd
.
clauseIndex
,
0
);
STableMeta
*
pPrevTableMeta
=
tscTableMeta
Clone
(
pPrevInfo
->
pTableMeta
);
STableMeta
*
pPrevTableMeta
=
tscTableMeta
Dup
(
pPrevInfo
->
pTableMeta
);
SVgroupsInfo
*
pVgroupsInfo
=
pPrevInfo
->
vgroupList
;
SVgroupsInfo
*
pVgroupsInfo
=
pPrevInfo
->
vgroupList
;
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
name
,
pPrevTableMeta
,
pVgroupsInfo
,
pTableMetaInfo
->
tagColList
,
pFinalInfo
=
tscAddTableMetaInfo
(
pNewQueryInfo
,
name
,
pPrevTableMeta
,
pVgroupsInfo
,
pTableMetaInfo
->
tagColList
,
pTableMetaInfo
->
pVgroupTables
);
pTableMetaInfo
->
pVgroupTables
);
...
@@ -2297,7 +2297,6 @@ int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo, const char* s
...
@@ -2297,7 +2297,6 @@ int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo, const char* s
}
}
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
}
int32_t
tscInvalidSQLErrMsg
(
char
*
msg
,
const
char
*
additionalInfo
,
const
char
*
sql
)
{
int32_t
tscInvalidSQLErrMsg
(
char
*
msg
,
const
char
*
additionalInfo
,
const
char
*
sql
)
{
...
@@ -2695,7 +2694,7 @@ uint32_t tscGetTableMetaMaxSize() {
...
@@ -2695,7 +2694,7 @@ uint32_t tscGetTableMetaMaxSize() {
return
sizeof
(
STableMeta
)
+
TSDB_MAX_COLUMNS
*
sizeof
(
SSchema
);
return
sizeof
(
STableMeta
)
+
TSDB_MAX_COLUMNS
*
sizeof
(
SSchema
);
}
}
STableMeta
*
tscTableMeta
Clone
(
STableMeta
*
pTableMeta
)
{
STableMeta
*
tscTableMeta
Dup
(
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
);
assert
(
pTableMeta
!=
NULL
);
uint32_t
size
=
tscGetTableMetaSize
(
pTableMeta
);
uint32_t
size
=
tscGetTableMetaSize
(
pTableMeta
);
STableMeta
*
p
=
calloc
(
1
,
size
);
STableMeta
*
p
=
calloc
(
1
,
size
);
...
...
src/query/src/qExecutor.c
浏览文件 @
6402c2b0
...
@@ -5043,7 +5043,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -5043,7 +5043,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
STsdbQueryCond
cond
=
createTsdbQueryCond
(
pQuery
,
&
pQuery
->
window
);
STsdbQueryCond
cond
=
createTsdbQueryCond
(
pQuery
,
&
pQuery
->
window
);
SArray
*
g1
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
g1
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
tx
=
taosArray
Clone
(
group
);
SArray
*
tx
=
taosArray
Dup
(
group
);
taosArrayPush
(
g1
,
&
tx
);
taosArrayPush
(
g1
,
&
tx
);
STableGroupInfo
gp
=
{.
numOfTables
=
taosArrayGetSize
(
tx
),
.
pGroupList
=
g1
};
STableGroupInfo
gp
=
{.
numOfTables
=
taosArrayGetSize
(
tx
),
.
pGroupList
=
g1
};
...
@@ -5103,7 +5103,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -5103,7 +5103,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
STsdbQueryCond
cond
=
createTsdbQueryCond
(
pQuery
,
&
pQuery
->
window
);
STsdbQueryCond
cond
=
createTsdbQueryCond
(
pQuery
,
&
pQuery
->
window
);
SArray
*
g1
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
g1
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
tx
=
taosArray
Clone
(
group
);
SArray
*
tx
=
taosArray
Dup
(
group
);
taosArrayPush
(
g1
,
&
tx
);
taosArrayPush
(
g1
,
&
tx
);
STableGroupInfo
gp
=
{.
numOfTables
=
taosArrayGetSize
(
tx
),
.
pGroupList
=
g1
};
STableGroupInfo
gp
=
{.
numOfTables
=
taosArrayGetSize
(
tx
),
.
pGroupList
=
g1
};
...
...
src/util/inc/tarray.h
浏览文件 @
6402c2b0
...
@@ -110,7 +110,7 @@ void taosArrayCopy(SArray* pDst, const SArray* pSrc);
...
@@ -110,7 +110,7 @@ void taosArrayCopy(SArray* pDst, const SArray* pSrc);
* clone a new array
* clone a new array
* @param pSrc
* @param pSrc
*/
*/
SArray
*
taosArray
Clone
(
const
SArray
*
pSrc
);
SArray
*
taosArray
Dup
(
const
SArray
*
pSrc
);
/**
/**
* clear the array (remove all element)
* clear the array (remove all element)
...
...
src/util/src/tarray.c
浏览文件 @
6402c2b0
...
@@ -165,7 +165,7 @@ void taosArrayCopy(SArray* pDst, const SArray* pSrc) {
...
@@ -165,7 +165,7 @@ void taosArrayCopy(SArray* pDst, const SArray* pSrc) {
pDst
->
size
=
pSrc
->
size
;
pDst
->
size
=
pSrc
->
size
;
}
}
SArray
*
taosArray
Clone
(
const
SArray
*
pSrc
)
{
SArray
*
taosArray
Dup
(
const
SArray
*
pSrc
)
{
assert
(
pSrc
!=
NULL
);
assert
(
pSrc
!=
NULL
);
if
(
pSrc
->
size
==
0
)
{
// empty array list
if
(
pSrc
->
size
==
0
)
{
// empty array list
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录