Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
buyaopa
TDengine
提交
1a802566
T
TDengine
项目概览
buyaopa
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1a802566
编写于
2月 27, 2020
作者:
S
slguan
提交者:
GitHub
2月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1266 from taosdata/feature/liaohj
Feature/liaohj
上级
e42d6fa1
3932d0ac
变更
31
展开全部
隐藏空白更改
内联
并排
Showing
31 changed file
with
3072 addition
and
3121 deletion
+3072
-3121
src/client/inc/tscSQLParser.h
src/client/inc/tscSQLParser.h
+5
-4
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+4
-1
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+44
-45
src/client/src/tscAst.c
src/client/src/tscAst.c
+2
-1
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+15
-3
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+26
-15
src/client/src/tscJoinProcess.c
src/client/src/tscJoinProcess.c
+10
-7
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+9
-0
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+421
-227
src/client/src/tscSecondaryMerge.c
src/client/src/tscSecondaryMerge.c
+220
-188
src/client/src/tscServer.c
src/client/src/tscServer.c
+40
-32
src/client/src/tscSql.c
src/client/src/tscSql.c
+117
-62
src/client/src/tscStream.c
src/client/src/tscStream.c
+17
-19
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+144
-76
src/inc/hash.h
src/inc/hash.h
+7
-2
src/inc/taosmsg.h
src/inc/taosmsg.h
+2
-1
src/inc/tast.h
src/inc/tast.h
+2
-0
src/inc/tresultBuf.h
src/inc/tresultBuf.h
+10
-10
src/inc/tsqlfunction.h
src/inc/tsqlfunction.h
+9
-5
src/system/detail/inc/vnode.h
src/system/detail/inc/vnode.h
+1
-1
src/system/detail/inc/vnodeQueryImpl.h
src/system/detail/inc/vnodeQueryImpl.h
+58
-58
src/system/detail/inc/vnodeRead.h
src/system/detail/inc/vnodeRead.h
+33
-41
src/system/detail/src/vnodeQueryImpl.c
src/system/detail/src/vnodeQueryImpl.c
+1538
-1947
src/system/detail/src/vnodeQueryProcess.c
src/system/detail/src/vnodeQueryProcess.c
+223
-225
src/system/detail/src/vnodeRead.c
src/system/detail/src/vnodeRead.c
+13
-13
src/system/detail/src/vnodeShell.c
src/system/detail/src/vnodeShell.c
+7
-7
src/system/detail/src/vnodeUtil.c
src/system/detail/src/vnodeUtil.c
+16
-12
src/util/src/hash.c
src/util/src/hash.c
+0
-30
src/util/src/textbuffer.c
src/util/src/textbuffer.c
+4
-4
src/util/src/tinterpolation.c
src/util/src/tinterpolation.c
+61
-71
src/util/src/tresultBuf.c
src/util/src/tresultBuf.c
+14
-14
未找到文件。
src/client/inc/tscSQLParser.h
浏览文件 @
1a802566
...
...
@@ -86,15 +86,16 @@ enum _sql_cmd {
TSDB_SQL_MAX
//48
};
#define MAX_TOKEN_LEN 30
// token type
enum
{
TSQL_NODE_TYPE_EXPR
=
0x1
,
TSQL_NODE_TYPE_ID
=
0x2
,
TSQL_NODE_TYPE_VALUE
=
0x4
,
};
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
extern
char
tTokenTypeSwitcher
[
13
];
#define toTSDBType(x) \
...
...
@@ -112,7 +113,7 @@ typedef struct SLimitVal {
}
SLimitVal
;
typedef
struct
SOrderVal
{
int32_t
order
;
u
int32_t
order
;
int32_t
orderColId
;
}
SOrderVal
;
...
...
src/client/inc/tscUtil.h
浏览文件 @
1a802566
...
...
@@ -128,6 +128,8 @@ void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema
void
tscFieldInfoSetValFromField
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
TAOS_FIELD
*
pField
);
void
tscFieldInfoSetValue
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
int8_t
type
,
const
char
*
name
,
int16_t
bytes
);
void
tscFieldInfoUpdateVisible
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
bool
visible
);
void
tscFieldInfoSetExpr
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
SSqlExpr
*
pExpr
);
void
tscFieldInfoSetBinExpr
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
SSqlFunctionExpr
*
pExpr
);
void
tscFieldInfoCalOffset
(
SQueryInfo
*
pQueryInfo
);
void
tscFieldInfoUpdateOffsetForInterResult
(
SQueryInfo
*
pQueryInfo
);
...
...
@@ -149,9 +151,10 @@ SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t f
SSqlExpr
*
tscSqlExprUpdate
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
,
int16_t
srcColumnIndex
,
int16_t
type
,
int16_t
size
);
int32_t
tscSqlExprNumOfExprs
(
SQueryInfo
*
pQueryInfo
);
SSqlExpr
*
tscSqlExprGet
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
);
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
uid
);
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
uid
,
bool
deepcopy
);
void
*
tscSqlExprDestroy
(
SSqlExpr
*
pExpr
);
void
tscSqlExprInfoDestroy
(
SSqlExprInfo
*
pExprInfo
);
...
...
src/client/inc/tsclient.h
浏览文件 @
1a802566
...
...
@@ -31,9 +31,8 @@ extern "C" {
#include "tsqlfunction.h"
#include "tutil.h"
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col, ord) \
(res->data + tscFieldInfoGetOffset(_queryinfo, col) * res->numOfRows)
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows)
// forward declaration
struct
SSqlInfo
;
...
...
@@ -70,13 +69,19 @@ typedef struct SSqlExpr {
int16_t
interResBytes
;
// inter result buffer size
int16_t
numOfParams
;
// argument value of each function
tVariant
param
[
3
];
// parameters are not more than 3
int32_t
offset
;
// sub result column value of arithmetic expression.
}
SSqlExpr
;
typedef
struct
SColumnIndex
{
int16_t
tableIndex
;
int16_t
columnIndex
;
}
SColumnIndex
;
typedef
struct
SFieldInfo
{
int16_t
numOfOutputCols
;
// number of column in result
int16_t
numOfAlloc
;
// allocated size
TAOS_FIELD
*
pFields
;
short
*
pOffset
;
//
short * pOffset;
/*
* define if this column is belong to the queried result, it may be add by parser to faciliate
...
...
@@ -85,20 +90,17 @@ typedef struct SFieldInfo {
* NOTE: these hidden columns always locate at the end of the output columns
*/
bool
*
pVisibleCols
;
int32_t
numOfHiddenCols
;
// the number of column not belongs to the queried result columns
int32_t
numOfHiddenCols
;
// the number of column not belongs to the queried result columns
SSqlFunctionExpr
**
pExpr
;
// used for aggregation arithmetic express,such as count(*)+count(*)
SSqlExpr
**
pSqlExpr
;
}
SFieldInfo
;
typedef
struct
SSqlExprInfo
{
int16_t
numOfAlloc
;
int16_t
numOfExprs
;
SSqlExpr
*
pExprs
;
int16_t
numOfAlloc
;
int16_t
numOfExprs
;
SSqlExpr
**
pExprs
;
}
SSqlExprInfo
;
typedef
struct
SColumnIndex
{
int16_t
tableIndex
;
int16_t
columnIndex
;
}
SColumnIndex
;
typedef
struct
SColumnBase
{
SColumnIndex
colIndex
;
int32_t
numOfFilters
;
...
...
@@ -163,7 +165,7 @@ typedef struct STableDataBlocks {
int32_t
rowSize
;
// row size for current table
uint32_t
nAllocSize
;
uint32_t
headerSize
;
// header for metadata (submit metadata)
uint32_t
headerSize
;
// header for metadata (submit metadata)
uint32_t
size
;
/*
...
...
@@ -198,9 +200,9 @@ typedef struct SQueryInfo {
char
intervalTimeUnit
;
int64_t
etime
,
stime
;
int64_t
nAggTimeInterval
;
// aggregation time interval
int64_t
nSlidingTime
;
// sliding window in mseconds
SSqlGroupbyExpr
groupbyExpr
;
// group by tags info
int64_t
intervalTime
;
// aggregation time interval
int64_t
slidingTime
;
// sliding window in mseconds
SSqlGroupbyExpr
groupbyExpr
;
// group by tags info
SColumnBaseInfo
colList
;
SFieldInfo
fieldsInfo
;
...
...
@@ -216,9 +218,9 @@ typedef struct SQueryInfo {
int64_t
*
defaultVal
;
// default value for interpolation
char
*
msg
;
// pointer to the pCmd->payload to keep error message temporarily
int64_t
clauseLimit
;
// limit for current sub clause
// offset value in the original sql expression, NOT sent to virtual node, only applied at client side
int64_t
prjOffset
;
int64_t
prjOffset
;
}
SQueryInfo
;
// data source from sql string or from file
...
...
@@ -269,29 +271,28 @@ typedef struct SResRec {
struct
STSBuf
;
typedef
struct
{
uint8_t
code
;
int64_t
numOfRows
;
// num of results in current retrieved
int64_t
numOfTotal
;
// num of total results
int64_t
numOfTotalInCurrentClause
;
// num of total result in current subclause
char
*
pRsp
;
int
rspType
;
int
rspLen
;
uint64_t
qhandle
;
int64_t
uid
;
int64_t
useconds
;
int
64_t
offset
;
// offset value from vnode during projection query of stable
int
row
;
int16_t
numOfnchar
;
int
16_t
precision
;
int32_t
numOfGroups
;
SResRec
*
pGroupRec
;
char
*
data
;
short
*
bytes
;
void
**
tsrow
;
char
**
buffer
;
// Buffer used to put multibytes encoded using unicode (wchar_t)
uint8_t
code
;
int64_t
numOfRows
;
// num of results in current retrieved
int64_t
numOfTotal
;
// num of total results
int64_t
numOfTotalInCurrentClause
;
// num of total result in current subclause
char
*
pRsp
;
int
rspType
;
int
rspLen
;
uint64_t
qhandle
;
int64_t
uid
;
int64_t
useconds
;
int64_t
offset
;
// offset value from vnode during projection query of stable
int
row
;
int
16_t
numOfCols
;
int16_t
precision
;
int
32_t
numOfGroups
;
SResRec
*
pGroupRec
;
char
*
data
;
void
**
tsrow
;
char
**
buffer
;
// Buffer used to put multibytes encoded using unicode (wchar_t)
SColumnIndex
*
pColumnIndex
;
struct
SLocalReducer
*
pLocalReducer
;
SColumnIndex
*
pColumnIndex
;
}
SSqlRes
;
typedef
struct
_tsc_obj
{
...
...
@@ -404,19 +405,17 @@ int taos_retrieve(TAOS_RES *res);
int32_t
tscTansformSQLFunctionForSTableQuery
(
SQueryInfo
*
pQueryInfo
);
void
tscRestoreSQLFunctionForMetricQuery
(
SQueryInfo
*
pQueryInfo
);
void
tscClearSqlMetaInfoForce
(
SSqlCmd
*
pCmd
);
int32_t
tscCreateResPointerInfo
(
SSqlRes
*
pRes
,
SQueryInfo
*
pQueryInfo
);
void
tscDestroyResPointerInfo
(
SSqlRes
*
pRes
);
void
tscFreeSqlCmdData
(
SSqlCmd
*
pCmd
);
void
tscFreeResData
(
SSqlObj
*
pSql
);
void
tscFreeResData
(
SSqlObj
*
pSql
);
/**
* free query result of the sql object
* @param pObj
*/
void
tscFreeSqlResult
(
SSqlObj
*
pSql
);
void
tscFreeSqlResult
(
SSqlObj
*
pSql
);
/**
* only free part of resources allocated during query.
...
...
src/client/src/tscAst.c
浏览文件 @
1a802566
...
...
@@ -158,7 +158,7 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
return
pNode
;
}
static
uint8_t
getBinaryExprOptr
(
SSQLToken
*
pToken
)
{
uint8_t
getBinaryExprOptr
(
SSQLToken
*
pToken
)
{
switch
(
pToken
->
type
)
{
case
TK_LT
:
return
TSDB_RELATION_LESS
;
...
...
@@ -183,6 +183,7 @@ static uint8_t getBinaryExprOptr(SSQLToken *pToken) {
case
TK_STAR
:
return
TSDB_BINARY_OP_MULTIPLY
;
case
TK_SLASH
:
case
TK_DIVIDE
:
return
TSDB_BINARY_OP_DIVIDE
;
case
TK_REM
:
return
TSDB_BINARY_OP_REMAINDER
;
...
...
src/client/src/tscAsync.c
浏览文件 @
1a802566
...
...
@@ -283,8 +283,15 @@ void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows) {
return
;
}
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
)
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
,
pQueryInfo
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
){
SSqlExpr
*
pExpr
=
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
i
];
if
(
pExpr
!=
NULL
)
{
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
)
+
pExpr
->
resBytes
*
pRes
->
row
;
}
else
{
//todo add
}
}
pRes
->
row
++
;
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
pSql
->
res
.
tsrow
);
...
...
@@ -298,7 +305,12 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
)
{
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
,
pQueryInfo
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
SSqlExpr
*
pExpr
=
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
i
];
if
(
pExpr
!=
NULL
)
{
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
)
+
pExpr
->
resBytes
*
pRes
->
row
;
}
else
{
//todo add
}
}
pRes
->
row
++
;
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
1a802566
...
...
@@ -322,6 +322,10 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return
TSDB_CODE_SUCCESS
;
}
bool
stableQueryFunctChanged
(
int32_t
funcId
)
{
return
(
aAggs
[
funcId
].
stableFuncId
!=
funcId
);
}
/**
* the numOfRes should be kept, since it may be used later
* and allow the ResultInfo to be re initialized
...
...
@@ -719,12 +723,15 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
return
BLK_DATA_NO_NEEDED
;
}
SFirstLastInfo
*
pInfo
=
(
SFirstLastInfo
*
)
(
pCtx
->
aOutputBuf
+
pCtx
->
inputBytes
);
if
(
pInfo
->
hasResult
!=
DATA_SET_FLAG
)
{
return
BLK_DATA_ALL_NEEDED
;
}
else
{
// data in current block is not earlier than current result
return
(
pInfo
->
ts
<=
start
)
?
BLK_DATA_NO_NEEDED
:
BLK_DATA_ALL_NEEDED
;
}
// result buffer has not been set yet.
return
BLK_DATA_ALL_NEEDED
;
//todo optimize the filter info
// SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
// if (pInfo->hasResult != DATA_SET_FLAG) {
// return BLK_DATA_ALL_NEEDED;
// } else { // data in current block is not earlier than current result
// return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
// }
}
static
int32_t
last_dist_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
,
...
...
@@ -733,12 +740,13 @@ static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
return
BLK_DATA_NO_NEEDED
;
}
SFirstLastInfo
*
pInfo
=
(
SFirstLastInfo
*
)
(
pCtx
->
aOutputBuf
+
pCtx
->
inputBytes
);
if
(
pInfo
->
hasResult
!=
DATA_SET_FLAG
)
{
return
BLK_DATA_ALL_NEEDED
;
}
else
{
return
(
pInfo
->
ts
>
end
)
?
BLK_DATA_NO_NEEDED
:
BLK_DATA_ALL_NEEDED
;
}
return
BLK_DATA_ALL_NEEDED
;
// SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
// if (pInfo->hasResult != DATA_SET_FLAG) {
// return BLK_DATA_ALL_NEEDED;
// } else {
// return (pInfo->ts > end) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
// }
}
//////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -1437,7 +1445,9 @@ static void stddev_next_step(SQLFunctionCtx *pCtx) {
*/
pStd
->
stage
++
;
avg_finalizer
(
pCtx
);
pResInfo
->
initialized
=
true
;
// set it initialized to avoid re-initialization
// save average value into tmpBuf, for second stage scan
SAvgInfo
*
pAvg
=
pResInfo
->
interResultBuf
;
...
...
@@ -2184,7 +2194,7 @@ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) {
// only the first_stage_merge is directly written data into final output buffer
if
(
pResInfo
->
superTableQ
&&
pCtx
->
currentStage
!=
SECONDARY_STAGE_MERGE
)
{
return
(
STopBotInfo
*
)
pCtx
->
aOutputBuf
;
}
else
{
//
for
normal table query and super table at the secondary_stage, result is written to intermediate buffer
}
else
{
//
during
normal table query and super table at the secondary_stage, result is written to intermediate buffer
return
pResInfo
->
interResultBuf
;
}
}
...
...
@@ -3312,7 +3322,7 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
tSQLBinaryExprCalcTraverse
(
sas
->
pExpr
->
pBinExprInfo
.
pBinExpr
,
pCtx
->
size
,
pCtx
->
aOutputBuf
,
sas
,
pCtx
->
order
,
arithmetic_callback_function
);
pCtx
->
aOutputBuf
+=
pCtx
->
outputBytes
*
pCtx
->
size
/* * GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/
;
pCtx
->
aOutputBuf
+=
pCtx
->
outputBytes
*
pCtx
->
size
;
pCtx
->
param
[
1
].
pz
=
NULL
;
}
...
...
@@ -3573,6 +3583,7 @@ void spread_function_finalizer(SQLFunctionCtx *pCtx) {
}
GET_RES_INFO
(
pCtx
)
->
numOfRes
=
1
;
// todo add test case
doFinalizer
(
pCtx
);
}
/*
...
...
src/client/src/tscJoinProcess.c
浏览文件 @
1a802566
...
...
@@ -100,7 +100,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
* in case of stable query, limit/offset is not applied here. the limit/offset is applied to the
* final results which is acquired after the secondry merge of in the client.
*/
if
(
pLimit
->
offset
==
0
||
pQueryInfo
->
nAggTimeInterval
>
0
||
QUERY_IS_STABLE_QUERY
(
pQueryInfo
->
type
))
{
if
(
pLimit
->
offset
==
0
||
pQueryInfo
->
intervalTime
>
0
||
QUERY_IS_STABLE_QUERY
(
pQueryInfo
->
type
))
{
if
(
*
st
>
elem1
.
ts
)
{
*
st
=
elem1
.
ts
;
}
...
...
@@ -165,7 +165,7 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
pSupporter
->
subqueryIndex
=
index
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
);
pSupporter
->
interval
=
pQueryInfo
->
nAggTimeInterval
;
pSupporter
->
interval
=
pQueryInfo
->
intervalTime
;
pSupporter
->
limit
=
pQueryInfo
->
limit
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
index
);
...
...
@@ -275,6 +275,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
pSubQueryInfo
->
tsBuf
=
NULL
;
// free result for async object will also free sqlObj
assert
(
pSubQueryInfo
->
exprsInfo
.
numOfExprs
==
1
);
// ts_comp query only requires one resutl columns
taos_free_result
(
pPrevSub
);
SSqlObj
*
pNew
=
createSubqueryObj
(
pSql
,
(
int16_t
)
i
,
tscJoinQueryCallback
,
pSupporter
,
NULL
);
...
...
@@ -293,24 +294,26 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
// set the second stage sub query for join process
pQueryInfo
->
type
|=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
;
pQueryInfo
->
nAggTimeInterval
=
pSupporter
->
interval
;
pQueryInfo
->
intervalTime
=
pSupporter
->
interval
;
pQueryInfo
->
groupbyExpr
=
pSupporter
->
groupbyExpr
;
tscColumnBaseInfoCopy
(
&
pQueryInfo
->
colList
,
&
pSupporter
->
colList
,
0
);
tscTagCondCopy
(
&
pQueryInfo
->
tagCond
,
&
pSupporter
->
tagCond
);
tscSqlExprCopy
(
&
pQueryInfo
->
exprsInfo
,
&
pSupporter
->
exprsInfo
,
pSupporter
->
uid
);
tscSqlExprCopy
(
&
pQueryInfo
->
exprsInfo
,
&
pSupporter
->
exprsInfo
,
pSupporter
->
uid
,
false
);
tscFieldInfoCopyAll
(
&
pQueryInfo
->
fieldsInfo
,
&
pSupporter
->
fieldsInfo
);
pSupporter
->
exprsInfo
.
numOfExprs
=
0
;
pSupporter
->
fieldsInfo
.
numOfOutputCols
=
0
;
/*
* if the first column of the secondary query is not ts function, add this function.
* Because this column is required to filter with timestamp after intersecting.
*/
if
(
pSupporter
->
exprsInfo
.
pExprs
[
0
]
.
functionId
!=
TSDB_FUNC_TS
)
{
if
(
pSupporter
->
exprsInfo
.
pExprs
[
0
]
->
functionId
!=
TSDB_FUNC_TS
)
{
tscAddTimestampColumn
(
pQueryInfo
,
TSDB_FUNC_TS
,
0
);
}
// todo refactor function name
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
assert
(
pNew
->
numOfSubs
==
0
&&
pNew
->
cmd
.
numOfClause
==
1
&&
pNewQueryInfo
->
numOfTables
==
1
);
...
...
src/client/src/tscLocal.c
浏览文件 @
1a802566
...
...
@@ -251,6 +251,13 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
tscFieldInfoSetValue
(
&
pQueryInfo
->
fieldsInfo
,
3
,
TSDB_DATA_TYPE_BINARY
,
"Note"
,
noteColLength
);
rowLen
+=
noteColLength
;
//set the sqlexpr part
SColumnIndex
index
=
{
0
};
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
0
]
=
tscSqlExprInsert
(
pQueryInfo
,
0
,
TSDB_FUNC_TS_DUMMY
,
&
index
,
TSDB_DATA_TYPE_BINARY
,
TSDB_COL_NAME_LEN
,
TSDB_COL_NAME_LEN
);
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
1
]
=
tscSqlExprInsert
(
pQueryInfo
,
1
,
TSDB_FUNC_TS_DUMMY
,
&
index
,
TSDB_DATA_TYPE_BINARY
,
typeColLength
,
typeColLength
);
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
2
]
=
tscSqlExprInsert
(
pQueryInfo
,
2
,
TSDB_FUNC_TS_DUMMY
,
&
index
,
TSDB_DATA_TYPE_INT
,
sizeof
(
int32_t
),
sizeof
(
int32_t
));
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
3
]
=
tscSqlExprInsert
(
pQueryInfo
,
3
,
TSDB_FUNC_TS_DUMMY
,
&
index
,
TSDB_DATA_TYPE_BINARY
,
noteColLength
,
noteColLength
);
return
rowLen
;
}
...
...
@@ -455,6 +462,8 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
tscInitResObjForLocalQuery
(
pSql
,
1
,
valueLength
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
0
);
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
0
]
=
pQueryInfo
->
exprsInfo
.
pExprs
[
0
];
strncpy
(
pRes
->
data
,
val
,
pField
->
bytes
);
}
...
...
src/client/src/tscSQLParser.c
浏览文件 @
1a802566
此差异已折叠。
点击以展开。
src/client/src/tscSecondaryMerge.c
浏览文件 @
1a802566
此差异已折叠。
点击以展开。
src/client/src/tscServer.c
浏览文件 @
1a802566
...
...
@@ -231,7 +231,7 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
if
(
UTIL_METER_IS_SUPERTABLE
(
pMeterMetaInfo
))
{
// multiple vnode query
SVnodeSidList
*
vnodeList
=
tscGetVnodeSidList
(
pMeterMetaInfo
->
pMetricMeta
,
pMeterMetaInfo
->
vnodeIndex
);
if
(
vnodeList
!=
NULL
)
{
...
...
@@ -254,6 +254,8 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
while
(
pSql
->
retry
<
pSql
->
maxRetry
)
{
(
pSql
->
retry
)
++
;
pSql
->
index
=
pSql
->
index
%
TSDB_VNODES_SUPPORT
;
char
ipstr
[
40
]
=
{
0
};
if
(
pVPeersDesc
[
pSql
->
index
].
ip
==
0
)
{
/*
...
...
@@ -643,19 +645,23 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
tscColumnBaseInfoUpdateTableIndex
(
&
pNewQueryInfo
->
colList
,
0
);
tscColumnBaseInfoCopy
(
&
pSupporter
->
colList
,
&
pNewQueryInfo
->
colList
,
0
);
tscSqlExprCopy
(
&
pSupporter
->
exprsInfo
,
&
pNewQueryInfo
->
exprsInfo
,
pSupporter
->
uid
);
tscSqlExprCopy
(
&
pSupporter
->
exprsInfo
,
&
pNewQueryInfo
->
exprsInfo
,
pSupporter
->
uid
,
false
);
tscFieldInfoCopyAll
(
&
pSupporter
->
fieldsInfo
,
&
pNewQueryInfo
->
fieldsInfo
);
tscTagCondCopy
(
&
pSupporter
->
tagCond
,
&
pNewQueryInfo
->
tagCond
);
pNew
->
cmd
.
numOfCols
=
0
;
pNewQueryInfo
->
nAggTimeInterval
=
0
;
pNewQueryInfo
->
intervalTime
=
0
;
memset
(
&
pNewQueryInfo
->
limit
,
0
,
sizeof
(
SLimitVal
));
// backup the data and clear it in the sqlcmd object
pSupporter
->
groupbyExpr
=
pNewQueryInfo
->
groupbyExpr
;
memset
(
&
pNewQueryInfo
->
groupbyExpr
,
0
,
sizeof
(
SSqlGroupbyExpr
));
// this data needs to be transfer to support struct
pNewQueryInfo
->
fieldsInfo
.
numOfOutputCols
=
0
;
pNewQueryInfo
->
exprsInfo
.
numOfExprs
=
0
;
// set the ts,tags that involved in join, as the output column of intermediate result
tscClearSubqueryInfo
(
&
pNew
->
cmd
);
...
...
@@ -901,7 +907,7 @@ int tscLaunchSTableSubqueries(SSqlObj *pSql) {
tExtMemBuffer
**
pMemoryBuf
=
NULL
;
tOrderDescriptor
*
pDesc
=
NULL
;
SColumnModel
*
pModel
=
NULL
;
SColumnModel
*
pModel
=
NULL
;
pRes
->
qhandle
=
1
;
// hack the qhandle check
...
...
@@ -1318,8 +1324,6 @@ void tscKillMetricQuery(SSqlObj *pSql) {
taosStopRpcConn
(
pSql
->
pSubs
[
i
]
->
thandle
);
}
pSql
->
numOfSubs
=
0
;
/*
* 1. if the subqueries are not launched or partially launched, we need to waiting the launched
* query return to successfully free allocated resources.
...
...
@@ -1537,7 +1541,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
int32_t
srcColListSize
=
pQueryInfo
->
colList
.
numOfCols
*
sizeof
(
SColumnInfo
);
int32_t
exprSize
=
sizeof
(
SSqlFuncExprMsg
)
*
pQueryInfo
->
fieldsInfo
.
numOfOutputCol
s
;
int32_t
exprSize
=
sizeof
(
SSqlFuncExprMsg
)
*
pQueryInfo
->
exprsInfo
.
numOfExpr
s
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
// meter query without tags values
...
...
@@ -1546,11 +1550,10 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
}
SMetricMeta
*
pMetricMeta
=
pMeterMetaInfo
->
pMetricMeta
;
SVnodeSidList
*
pVnodeSidList
=
tscGetVnodeSidList
(
pMetricMeta
,
pMeterMetaInfo
->
vnodeIndex
);
int32_t
meterInfoSize
=
(
pMetricMeta
->
tagLen
+
sizeof
(
SMeterSidExtInfo
))
*
pVnodeSidList
->
numOfSids
;
int32_t
outputColumnSize
=
pQueryInfo
->
fieldsInfo
.
numOfOutputCol
s
*
sizeof
(
SSqlFuncExprMsg
);
int32_t
outputColumnSize
=
pQueryInfo
->
exprsInfo
.
numOfExpr
s
*
sizeof
(
SSqlFuncExprMsg
);
int32_t
size
=
meterInfoSize
+
outputColumnSize
+
srcColListSize
+
exprSize
+
MIN_QUERY_MSG_PKT_SIZE
;
if
(
pQueryInfo
->
tsBuf
!=
NULL
)
{
...
...
@@ -1566,7 +1569,7 @@ static char *doSerializeTableInfo(SSqlObj *pSql, int32_t numOfMeters, int32_t vn
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
SMetricMeta
*
pMetricMeta
=
pMeterMetaInfo
->
pMetricMeta
;
tscTrace
(
"%p vid:%d, query on %d meters"
,
pSql
,
htons
(
vnodeId
)
,
numOfMeters
);
tscTrace
(
"%p vid:%d, query on %d meters"
,
pSql
,
vnodeId
,
numOfMeters
);
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
#ifdef _DEBUG_VIEW
tscTrace
(
"%p sid:%d, uid:%"
PRIu64
,
pSql
,
pMeterMetaInfo
->
pMeterMeta
->
sid
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
...
...
@@ -1683,12 +1686,12 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
-
1
;
}
pQueryMsg
->
nAggTimeInterval
=
htobe64
(
pQueryInfo
->
nAggTimeInterval
);
pQueryMsg
->
intervalTime
=
htobe64
(
pQueryInfo
->
intervalTime
);
pQueryMsg
->
intervalTimeUnit
=
pQueryInfo
->
intervalTimeUnit
;
pQueryMsg
->
slidingTime
=
htobe64
(
pQueryInfo
->
nS
lidingTime
);
pQueryMsg
->
slidingTime
=
htobe64
(
pQueryInfo
->
s
lidingTime
);
if
(
pQueryInfo
->
nAggTimeInterval
<
0
)
{
tscError
(
"%p illegal value of aggregation time interval in query msg: %ld"
,
pSql
,
pQueryInfo
->
nAggTimeInterval
);
if
(
pQueryInfo
->
intervalTime
<
0
)
{
tscError
(
"%p illegal value of aggregation time interval in query msg: %ld"
,
pSql
,
pQueryInfo
->
intervalTime
);
return
-
1
;
}
...
...
@@ -1768,7 +1771,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlFuncExprMsg
*
pSqlFuncExpr
=
(
SSqlFuncExprMsg
*
)
pMsg
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tscSqlExprNumOfExprs
(
pQueryInfo
)
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
->
functionId
==
TSDB_FUNC_ARITHM
)
{
...
...
@@ -1862,6 +1865,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
flag
;
pMsg
+=
sizeof
(
pCol
->
flag
);
memcpy
(
pMsg
,
pCol
->
name
,
tListLen
(
pCol
->
name
));
pMsg
+=
tListLen
(
pCol
->
name
);
}
}
...
...
@@ -2491,16 +2497,8 @@ static int tscSetResultPointer(SQueryInfo *pQueryInfo, SSqlRes *pRes) {
}
for
(
int
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
int16_t
offset
=
tscFieldInfoGetOffset
(
pQueryInfo
,
i
);
pRes
->
bytes
[
i
]
=
pField
->
bytes
;
// if (pQueryInfo->order.order == TSQL_SO_DESC) {
// pRes->bytes[i] = -pRes->bytes[i];
// pRes->tsrow[i] = ((pRes->data + offset * pRes->numOfRows) + (pRes->numOfRows - 1) * pField->bytes);
// } else {
pRes
->
tsrow
[
i
]
=
(
pRes
->
data
+
offset
*
pRes
->
numOfRows
);
// }
int16_t
offset
=
tscFieldInfoGetOffset
(
pQueryInfo
,
i
);
pRes
->
tsrow
[
i
]
=
(
pRes
->
data
+
offset
*
pRes
->
numOfRows
);
}
return
0
;
...
...
@@ -2725,8 +2723,10 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
int32_t
joinCondLen
=
(
TSDB_METER_ID_LEN
+
sizeof
(
int16_t
))
*
2
;
int32_t
elemSize
=
sizeof
(
SMetricMetaElemMsg
)
*
pQueryInfo
->
numOfTables
;
int32_t
colSize
=
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
*
sizeof
(
SColIndexEx
);
int32_t
len
=
tagLen
+
joinCondLen
+
elemSize
+
defaultSize
;
int32_t
len
=
tagLen
+
joinCondLen
+
elemSize
+
colSize
+
defaultSize
;
return
MAX
(
len
,
TSDB_DEFAULT_PAYLOAD_SIZE
);
}
...
...
@@ -2795,7 +2795,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int32_t
condLen
=
0
;
if
(
pTagCond
->
numOfTagCond
>
0
)
{
SCond
*
pCond
=
tsGetMetricQueryCondPos
(
pTagCond
,
uid
);
if
(
pCond
!=
NULL
)
{
if
(
pCond
!=
NULL
&&
pCond
->
cond
!=
NULL
)
{
condLen
=
strlen
(
pCond
->
cond
)
+
1
;
bool
ret
=
taosMbsToUcs4
(
pCond
->
cond
,
condLen
,
pMsg
,
condLen
*
TSDB_NCHAR_SIZE
);
...
...
@@ -2817,11 +2817,14 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
offset
=
pMsg
-
(
char
*
)
pMetaMsg
;
pElem
->
tableCond
=
htonl
(
offset
);
uint32_t
len
=
strlen
(
pTagCond
->
tbnameCond
.
cond
);
uint32_t
len
=
0
;
if
(
pTagCond
->
tbnameCond
.
cond
!=
NULL
)
{
len
=
strlen
(
pTagCond
->
tbnameCond
.
cond
);
memcpy
(
pMsg
,
pTagCond
->
tbnameCond
.
cond
,
len
);
}
pElem
->
tableCondLen
=
htonl
(
len
);
memcpy
(
pMsg
,
pTagCond
->
tbnameCond
.
cond
,
len
);
pMsg
+=
len
;
}
...
...
@@ -2851,6 +2854,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pDestCol
->
colIdx
=
htons
(
pCol
->
colIdx
);
pDestCol
->
colId
=
htons
(
pDestCol
->
colId
);
pDestCol
->
flag
=
htons
(
pDestCol
->
flag
);
strncpy
(
pDestCol
->
name
,
pCol
->
name
,
tListLen
(
pCol
->
name
));
pMsg
+=
sizeof
(
SColIndexEx
);
}
...
...
@@ -3288,6 +3292,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
int32_t
size
=
pMeta
->
numOfColumns
*
sizeof
(
SSchema
)
+
sizeof
(
SMeterMeta
);
pMeterMetaInfo
->
pMeterMeta
=
(
SMeterMeta
*
)
taosAddDataIntoCache
(
tscCacheHandle
,
key
,
(
char
*
)
pMeta
,
size
,
tsMeterMetaKeepTimer
);
pCmd
->
numOfCols
=
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
SSchema
*
pMeterSchema
=
tsGetSchema
(
pMeterMetaInfo
->
pMeterMeta
);
...
...
@@ -3298,6 +3303,9 @@ int tscProcessShowRsp(SSqlObj *pSql) {
index
.
columnIndex
=
i
;
tscColumnBaseInfoInsert
(
pQueryInfo
,
&
index
);
tscFieldInfoSetValFromSchema
(
&
pQueryInfo
->
fieldsInfo
,
i
,
&
pMeterSchema
[
i
]);
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
i
]
=
tscSqlExprInsert
(
pQueryInfo
,
i
,
TSDB_FUNC_TS_DUMMY
,
&
index
,
pMeterSchema
[
i
].
type
,
pMeterSchema
[
i
].
bytes
,
pMeterSchema
[
i
].
bytes
);
}
tscFieldInfoCalOffset
(
pQueryInfo
);
...
...
src/client/src/tscSql.c
浏览文件 @
1a802566
...
...
@@ -13,8 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"os.h"
#include
<tast.h>
#include "hash.h"
#include "os.h"
#include "tcache.h"
#include "tlog.h"
#include "tnote.h"
...
...
@@ -200,7 +201,7 @@ int taos_query_imp(STscObj *pObj, SSqlObj *pSql) {
taosCleanUpHashTable
(
pSql
->
pTableHashList
);
pSql
->
pTableHashList
=
NULL
;
}
tscDump
(
"%p pObj:%p, SQL: %s"
,
pSql
,
pObj
,
pSql
->
sqlstr
);
pRes
->
code
=
(
uint8_t
)
tsParseSql
(
pSql
,
false
);
...
...
@@ -367,9 +368,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
for
(
int
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
// pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i, pQueryInfo->order) +
// pRes->bytes[i] * (1 - pQueryInfo->order.order) * (pRes->numOfRows - 1);
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
,
pQueryInfo
->
order
);
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
);
}
*
rows
=
pRes
->
tsrow
;
...
...
@@ -377,54 +376,115 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
return
(
pQueryInfo
->
order
.
order
==
TSQL_SO_DESC
)
?
pRes
->
numOfRows
:
-
pRes
->
numOfRows
;
}
static
void
transferNcharData
(
SSqlObj
*
pSql
,
int32_t
columnIndex
,
TAOS_FIELD
*
pField
)
{
SSqlRes
*
pRes
=
&
pSql
->
res
;
if
(
isNull
(
pRes
->
tsrow
[
columnIndex
],
pField
->
type
))
{
pRes
->
tsrow
[
columnIndex
]
=
NULL
;
}
else
if
(
pField
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
if
(
pRes
->
buffer
[
columnIndex
]
==
NULL
)
{
pRes
->
buffer
[
columnIndex
]
=
malloc
(
pField
->
bytes
+
TSDB_NCHAR_SIZE
);
}
/* string terminated char for binary data*/
memset
(
pRes
->
buffer
[
columnIndex
],
0
,
pField
->
bytes
+
TSDB_NCHAR_SIZE
);
if
(
taosUcs4ToMbs
(
pRes
->
tsrow
[
columnIndex
],
pField
->
bytes
,
pRes
->
buffer
[
columnIndex
]))
{
pRes
->
tsrow
[
columnIndex
]
=
pRes
->
buffer
[
columnIndex
];
}
else
{
tscError
(
"%p charset:%s to %s. val:%ls convert failed."
,
pSql
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
pRes
->
tsrow
);
pRes
->
tsrow
[
columnIndex
]
=
NULL
;
}
}
}
static
char
*
getArithemicInputSrc
(
void
*
param
,
char
*
name
,
int32_t
colId
)
{
SArithmeticSupport
*
pSupport
=
(
SArithmeticSupport
*
)
param
;
SSqlFunctionExpr
*
pExpr
=
pSupport
->
pExpr
;
int32_t
index
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pExpr
->
pBinExprInfo
.
numOfCols
;
++
i
)
{
if
(
strcmp
(
name
,
pExpr
->
pBinExprInfo
.
pReqColumns
[
i
].
name
)
==
0
)
{
index
=
i
;
break
;
}
}
assert
(
index
>=
0
&&
index
<
pExpr
->
pBinExprInfo
.
numOfCols
);
return
pSupport
->
data
[
index
]
+
pSupport
->
offset
*
pSupport
->
elemSize
[
index
];
}
static
void
**
doSetResultRowData
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
assert
(
pRes
->
row
>=
0
&&
pRes
->
row
<=
pRes
->
numOfRows
);
if
(
pRes
->
row
>=
pRes
->
numOfRows
)
{
// all the results has returned to invoker
tfree
(
pRes
->
tsrow
);
return
pRes
->
tsrow
;
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
//todo refactor move away
for
(
int32_t
k
=
0
;
k
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
k
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
k
);
if
(
k
>
0
)
{
SSqlExpr
*
pPrev
=
tscSqlExprGet
(
pQueryInfo
,
k
-
1
);
pExpr
->
offset
=
pPrev
->
offset
+
pPrev
->
resBytes
;
}
}
int32_t
num
=
0
;
for
(
int
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
,
pQueryInfo
->
order
)
+
pRes
->
bytes
[
i
]
*
pRes
->
row
;
for
(
int
i
=
0
;
i
<
tscNumOfFields
(
pQueryInfo
);
++
i
)
{
if
(
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
i
]
!=
NULL
)
{
SSqlExpr
*
pExpr
=
pQueryInfo
->
fieldsInfo
.
pSqlExpr
[
i
];
pRes
->
tsrow
[
i
]
=
TSC_GET_RESPTR_BASE
(
pRes
,
pQueryInfo
,
i
)
+
pExpr
->
resBytes
*
pRes
->
row
;
}
else
{
assert
(
0
);
}
// primary key column cannot be null in interval query, no need to check
if
(
i
==
0
&&
pQueryInfo
->
nAggTimeInterval
>
0
)
{
if
(
i
==
0
&&
pQueryInfo
->
intervalTime
>
0
)
{
continue
;
}
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
if
(
isNull
(
pRes
->
tsrow
[
i
],
pField
->
type
))
{
pRes
->
tsrow
[
i
]
=
NULL
;
}
else
if
(
pField
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
if
(
pRes
->
buffer
[
num
]
==
NULL
)
{
pRes
->
buffer
[
num
]
=
malloc
(
pField
->
bytes
+
TSDB_NCHAR_SIZE
);
}
/* string terminated char for binary data*/
memset
(
pRes
->
buffer
[
num
],
0
,
pField
->
bytes
+
TSDB_NCHAR_SIZE
);
transferNcharData
(
pSql
,
i
,
pField
);
if
(
taosUcs4ToMbs
(
pRes
->
tsrow
[
i
],
pField
->
bytes
,
pRes
->
buffer
[
num
]))
{
pRes
->
tsrow
[
i
]
=
pRes
->
buffer
[
num
];
}
else
{
tscError
(
"%p charset:%s to %s. val:%ls convert failed."
,
pSql
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
pRes
->
tsrow
);
pRes
->
tsrow
[
i
]
=
NULL
;
// calculate the result from serveral other columns
if
(
pQueryInfo
->
fieldsInfo
.
pExpr
!=
NULL
&&
pQueryInfo
->
fieldsInfo
.
pExpr
[
i
]
!=
NULL
)
{
SArithmeticSupport
*
sas
=
(
SArithmeticSupport
*
)
calloc
(
1
,
sizeof
(
SArithmeticSupport
));
sas
->
offset
=
0
;
sas
->
pExpr
=
pQueryInfo
->
fieldsInfo
.
pExpr
[
i
];
sas
->
numOfCols
=
sas
->
pExpr
->
pBinExprInfo
.
numOfCols
;
if
(
pRes
->
buffer
[
i
]
==
NULL
)
{
pRes
->
buffer
[
i
]
=
malloc
(
tscFieldInfoGetField
(
pQueryInfo
,
i
)
->
bytes
);
}
for
(
int32_t
k
=
0
;
k
<
sas
->
numOfCols
;
++
k
)
{
int32_t
columnIndex
=
sas
->
pExpr
->
pBinExprInfo
.
pReqColumns
[
k
].
colIdxInBuf
;
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
columnIndex
);
sas
->
elemSize
[
k
]
=
pExpr
->
resBytes
;
sas
->
data
[
k
]
=
(
pRes
->
data
+
pRes
->
numOfRows
*
pExpr
->
offset
)
+
pRes
->
row
*
pExpr
->
resBytes
;
}
tSQLBinaryExprCalcTraverse
(
sas
->
pExpr
->
pBinExprInfo
.
pBinExpr
,
1
,
pRes
->
buffer
[
i
],
sas
,
TSQL_SO_ASC
,
getArithemicInputSrc
);
pRes
->
tsrow
[
i
]
=
pRes
->
buffer
[
i
];
num
++
;
free
(
sas
);
//todo optimization
}
}
assert
(
num
<=
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
);
pRes
->
row
++
;
// index increase one-step
pRes
->
row
++
;
// index increase one-step
return
pRes
->
tsrow
;
}
...
...
@@ -466,7 +526,7 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
if
(
pSql
->
pSubs
[
i
]
==
0
)
{
continue
;
}
SSqlRes
*
pRes1
=
&
pSql
->
pSubs
[
i
]
->
res
;
SQueryInfo
*
pQueryInfo1
=
tscGetQueryInfoDetail
(
&
pSql
->
pSubs
[
i
]
->
cmd
,
0
);
...
...
@@ -502,11 +562,10 @@ static void **tscBuildResFromSubqueries(SSqlObj *pSql) {
if
(
numOfTableHasRes
>=
2
)
{
// do merge result
success
=
(
doSetResultRowData
(
pSql
->
pSubs
[
0
])
!=
NULL
)
&&
(
doSetResultRowData
(
pSql
->
pSubs
[
1
])
!=
NULL
);
// TSKEY key1 = *(TSKEY *)pRes1->tsrow[0];
// TSKEY key2 = *(TSKEY *)pRes2->tsrow[0];
// printf("first:%" PRId64 ", second:%" PRId64 "\n", key1, key2);
success
=
(
doSetResultRowData
(
pSql
->
pSubs
[
0
])
!=
NULL
)
&&
(
doSetResultRowData
(
pSql
->
pSubs
[
1
])
!=
NULL
);
// TSKEY key1 = *(TSKEY *)pRes1->tsrow[0];
// TSKEY key2 = *(TSKEY *)pRes2->tsrow[0];
// printf("first:%" PRId64 ", second:%" PRId64 "\n", key1, key2);
}
else
{
// only one subquery
SSqlObj
*
pSub
=
pSql
->
pSubs
[
0
];
if
(
pSub
==
NULL
)
{
...
...
@@ -596,7 +655,7 @@ TAOS_ROW taos_fetch_row_impl(TAOS_RES *res) {
tscProcessSql
(
pSql
);
// retrieve data from virtual node
//if failed to retrieve data from current virtual node, try next one if exists
//
if failed to retrieve data from current virtual node, try next one if exists
if
(
hasMoreVnodesToTry
(
pSql
))
{
tscTryQueryNextVnode
(
pSql
,
NULL
);
}
...
...
@@ -638,7 +697,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
// current subclause is completed, try the next subclause
while
(
rows
==
NULL
&&
pCmd
->
clauseIndex
<
pCmd
->
numOfClause
-
1
)
{
tscTryQueryNextClause
(
pSql
,
NULL
);
// if the rows is not NULL, return immediately
rows
=
taos_fetch_row_impl
(
res
);
}
...
...
@@ -701,7 +760,7 @@ int taos_select_db(TAOS *taos, const char *db) {
return
taos_query
(
taos
,
sql
);
}
void
taos_free_result_imp
(
TAOS_RES
*
res
,
int
keepCmd
)
{
void
taos_free_result_imp
(
TAOS_RES
*
res
,
int
keepCmd
)
{
if
(
res
==
NULL
)
return
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
...
...
@@ -755,7 +814,7 @@ void taos_free_result_imp(TAOS_RES* res, int keepCmd) {
pCmd
->
command
=
(
pCmd
->
command
>
TSDB_SQL_MGMT
)
?
TSDB_SQL_RETRIEVE
:
TSDB_SQL_FETCH
;
tscTrace
(
"%p code:%d, numOfRows:%d, command:%d"
,
pSql
,
pRes
->
code
,
pRes
->
numOfRows
,
pCmd
->
command
);
void
*
fp
=
pSql
->
fp
;
if
(
fp
!=
NULL
)
{
pSql
->
freed
=
1
;
...
...
@@ -804,9 +863,7 @@ void taos_free_result_imp(TAOS_RES* res, int keepCmd) {
}
}
void
taos_free_result
(
TAOS_RES
*
res
)
{
taos_free_result_imp
(
res
,
0
);
}
void
taos_free_result
(
TAOS_RES
*
res
)
{
taos_free_result_imp
(
res
,
0
);
}
int
taos_errno
(
TAOS
*
taos
)
{
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
...
...
@@ -822,26 +879,24 @@ int taos_errno(TAOS *taos) {
return
code
;
}
static
bool
validErrorCode
(
int32_t
code
)
{
return
code
>=
TSDB_CODE_SUCCESS
&&
code
<
TSDB_CODE_MAX_ERROR_CODE
;
}
static
bool
validErrorCode
(
int32_t
code
)
{
return
code
>=
TSDB_CODE_SUCCESS
&&
code
<
TSDB_CODE_MAX_ERROR_CODE
;
}
/*
* In case of invalid sql error, additional information is attached to explain
* why the sql is invalid
*/
static
bool
hasAdditionalErrorInfo
(
int32_t
code
,
SSqlCmd
*
pCmd
)
{
static
bool
hasAdditionalErrorInfo
(
int32_t
code
,
SSqlCmd
*
pCmd
)
{
if
(
code
!=
TSDB_CODE_INVALID_SQL
)
{
return
false
;
}
size_t
len
=
strlen
(
pCmd
->
payload
);
char
*
z
=
NULL
;
char
*
z
=
NULL
;
if
(
len
>
0
)
{
z
=
strstr
(
pCmd
->
payload
,
"invalid SQL"
);
z
=
strstr
(
pCmd
->
payload
,
"invalid SQL"
);
}
return
z
!=
NULL
;
}
...
...
@@ -851,12 +906,12 @@ char *taos_errstr(TAOS *taos) {
if
(
pObj
==
NULL
||
pObj
->
signature
!=
pObj
)
return
tsError
[
globalCode
];
SSqlObj
*
pSql
=
pObj
->
pSql
;
SSqlObj
*
pSql
=
pObj
->
pSql
;
if
(
validErrorCode
(
pSql
->
res
.
code
))
{
code
=
pSql
->
res
.
code
;
}
else
{
code
=
TSDB_CODE_OTHERS
;
//unknown error
code
=
TSDB_CODE_OTHERS
;
//
unknown error
}
if
(
hasAdditionalErrorInfo
(
code
,
&
pSql
->
cmd
))
{
...
...
@@ -954,14 +1009,14 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
{
size_t
xlen
=
0
;
for
(
xlen
=
0
;
xlen
<=
fields
[
i
].
bytes
;
xlen
++
)
{
char
c
=
((
char
*
)
row
[
i
])[
xlen
];
if
(
c
==
0
)
break
;
str
[
len
++
]
=
c
;
}
str
[
len
]
=
0
;
}
break
;
size_t
xlen
=
0
;
for
(
xlen
=
0
;
xlen
<=
fields
[
i
].
bytes
;
xlen
++
)
{
char
c
=
((
char
*
)
row
[
i
])[
xlen
];
if
(
c
==
0
)
break
;
str
[
len
++
]
=
c
;
}
str
[
len
]
=
0
;
}
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
len
+=
sprintf
(
str
+
len
,
"%"
PRId64
,
*
((
int64_t
*
)
row
[
i
]));
...
...
src/client/src/tscStream.c
浏览文件 @
1a802566
...
...
@@ -246,8 +246,6 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
int32_t
retry
=
tsProjectExecInterval
;
tscError
(
"%p stream:%p, retrieve no data, code:%d, retry in %"
PRId64
"ms"
,
pSql
,
pStream
,
numOfRows
,
retry
);
tscClearSqlMetaInfoForce
(
&
(
pStream
->
pSql
->
cmd
));
tscSetRetryTimer
(
pStream
,
pStream
->
pSql
,
retry
);
return
;
}
...
...
@@ -381,41 +379,41 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
pQueryInfo
->
nAggTimeInterval
<
minIntervalTime
)
{
if
(
pQueryInfo
->
intervalTime
<
minIntervalTime
)
{
tscWarn
(
"%p stream:%p, original sample interval:%ld too small, reset to:%"
PRId64
""
,
pSql
,
pStream
,
pQueryInfo
->
nAggTimeInterval
,
minIntervalTime
);
pQueryInfo
->
nAggTimeInterval
=
minIntervalTime
;
pQueryInfo
->
intervalTime
,
minIntervalTime
);
pQueryInfo
->
intervalTime
=
minIntervalTime
;
}
pStream
->
interval
=
pQueryInfo
->
nAggTimeInterval
;
// it shall be derived from sql string
pStream
->
interval
=
pQueryInfo
->
intervalTime
;
// it shall be derived from sql string
if
(
pQueryInfo
->
nS
lidingTime
==
0
)
{
pQueryInfo
->
nSlidingTime
=
pQueryInfo
->
nAggTimeInterval
;
if
(
pQueryInfo
->
s
lidingTime
==
0
)
{
pQueryInfo
->
slidingTime
=
pQueryInfo
->
intervalTime
;
}
int64_t
minSlidingTime
=
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
tsMinSlidingTime
*
1000L
:
tsMinSlidingTime
;
if
(
pQueryInfo
->
nS
lidingTime
==
-
1
)
{
pQueryInfo
->
nSlidingTime
=
pQueryInfo
->
nAggTimeInterval
;
}
else
if
(
pQueryInfo
->
nS
lidingTime
<
minSlidingTime
)
{
if
(
pQueryInfo
->
s
lidingTime
==
-
1
)
{
pQueryInfo
->
slidingTime
=
pQueryInfo
->
intervalTime
;
}
else
if
(
pQueryInfo
->
s
lidingTime
<
minSlidingTime
)
{
tscWarn
(
"%p stream:%p, original sliding value:%"
PRId64
" too small, reset to:%"
PRId64
""
,
pSql
,
pStream
,
pQueryInfo
->
nS
lidingTime
,
minSlidingTime
);
pQueryInfo
->
s
lidingTime
,
minSlidingTime
);
pQueryInfo
->
nS
lidingTime
=
minSlidingTime
;
pQueryInfo
->
s
lidingTime
=
minSlidingTime
;
}
if
(
pQueryInfo
->
nSlidingTime
>
pQueryInfo
->
nAggTimeInterval
)
{
if
(
pQueryInfo
->
slidingTime
>
pQueryInfo
->
intervalTime
)
{
tscWarn
(
"%p stream:%p, sliding value:%"
PRId64
" can not be larger than interval range, reset to:%"
PRId64
""
,
pSql
,
pStream
,
pQueryInfo
->
nSlidingTime
,
pQueryInfo
->
nAggTimeInterval
);
pQueryInfo
->
slidingTime
,
pQueryInfo
->
intervalTime
);
pQueryInfo
->
nSlidingTime
=
pQueryInfo
->
nAggTimeInterval
;
pQueryInfo
->
slidingTime
=
pQueryInfo
->
intervalTime
;
}
pStream
->
slidingTime
=
pQueryInfo
->
nS
lidingTime
;
pStream
->
slidingTime
=
pQueryInfo
->
s
lidingTime
;
pQueryInfo
->
nAggTimeInterval
=
0
;
// clear the interval value to avoid the force time window split by query processor
pQueryInfo
->
nS
lidingTime
=
0
;
pQueryInfo
->
intervalTime
=
0
;
// clear the interval value to avoid the force time window split by query processor
pQueryInfo
->
s
lidingTime
=
0
;
}
static
int64_t
tscGetStreamStartTimestamp
(
SSqlObj
*
pSql
,
SSqlStream
*
pStream
,
int64_t
stime
)
{
...
...
src/client/src/tscUtil.c
浏览文件 @
1a802566
...
...
@@ -27,6 +27,7 @@
#include "tsclient.h"
#include "tsqldef.h"
#include "ttimer.h"
#include "tast.h"
/*
* the detailed information regarding metric meta key is:
...
...
@@ -64,7 +65,7 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
size_t
redundantLen
=
20
;
size_t
bufSize
=
strlen
(
pMeterMetaInfo
->
name
)
+
tbnameCondLen
+
strlen
(
join
)
+
strlen
(
tagIdBuf
);
if
(
cond
!=
NULL
)
{
if
(
cond
!=
NULL
&&
cond
->
cond
!=
NULL
)
{
bufSize
+=
strlen
(
cond
->
cond
);
}
...
...
@@ -72,7 +73,7 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
char
*
tmp
=
calloc
(
1
,
bufSize
);
int32_t
keyLen
=
snprintf
(
tmp
,
bufSize
,
"%s,%s,%s,%d,%s,[%s],%d"
,
pMeterMetaInfo
->
name
,
(
cond
!=
NULL
?
cond
->
cond
:
NULL
),
(
tbnameCondLen
>
0
?
pTagCond
->
tbnameCond
.
cond
:
NULL
),
(
(
cond
!=
NULL
&&
cond
->
cond
!=
NULL
)
?
cond
->
cond
:
NULL
),
(
tbnameCondLen
>
0
?
pTagCond
->
tbnameCond
.
cond
:
NULL
),
pTagCond
->
relType
,
join
,
tagIdBuf
,
pQueryInfo
->
groupbyExpr
.
orderType
);
assert
(
keyLen
<=
bufSize
);
...
...
@@ -202,6 +203,9 @@ SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx) {
tscError
(
"illegal sidIdx:%d, reset to 0, sidIdx range:%d-%d"
,
idx
,
0
,
sidRange
);
idx
=
0
;
}
assert
(
pSidList
->
pSidExtInfoList
[
idx
]
>=
0
);
return
(
SMeterSidExtInfo
*
)(
pSidList
->
pSidExtInfoList
[
idx
]
+
(
char
*
)
pSidList
);
}
...
...
@@ -335,35 +339,17 @@ void tscClearInterpInfo(SQueryInfo* pQueryInfo) {
tfree
(
pQueryInfo
->
defaultVal
);
}
void
tscClearSqlMetaInfoForce
(
SSqlCmd
*
pCmd
)
{
/* remove the metermeta/metricmeta in cache */
// taosRemoveDataFromCache(tscCacheHandle, (void**)&(pCmd->pMeterMeta), true);
// taosRemoveDataFromCache(tscCacheHandle, (void**)&(pCmd->pMetricMeta), true);
}
int32_t
tscCreateResPointerInfo
(
SSqlRes
*
pRes
,
SQueryInfo
*
pQueryInfo
)
{
if
(
pRes
->
tsrow
==
NULL
)
{
pRes
->
numOfnchar
=
0
;
int32_t
numOfOutputCols
=
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
for
(
int32_t
i
=
0
;
i
<
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
if
(
pField
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
pRes
->
numOfnchar
++
;
}
}
pRes
->
numOfCols
=
numOfOutputCols
;
pRes
->
tsrow
=
calloc
(
1
,
(
POINTER_BYTES
+
sizeof
(
short
))
*
numOfOutputCols
+
POINTER_BYTES
*
pRes
->
numOfnchar
);
pRes
->
bytes
=
calloc
(
numOfOutputCols
,
sizeof
(
short
));
if
(
pRes
->
numOfnchar
>
0
)
{
pRes
->
buffer
=
calloc
(
POINTER_BYTES
,
pRes
->
numOfnchar
);
}
pRes
->
tsrow
=
calloc
(
POINTER_BYTES
,
numOfOutputCols
);
pRes
->
buffer
=
calloc
(
POINTER_BYTES
,
numOfOutputCols
);
// not enough memory
if
(
pRes
->
tsrow
==
NULL
||
pRes
->
bytes
==
NULL
||
(
pRes
->
buffer
==
NULL
&&
pRes
->
numOfnchar
>
0
))
{
if
(
pRes
->
tsrow
==
NULL
||
(
pRes
->
buffer
==
NULL
&&
pRes
->
numOfCols
>
0
))
{
tfree
(
pRes
->
tsrow
);
tfree
(
pRes
->
bytes
);
tfree
(
pRes
->
buffer
);
pRes
->
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
...
...
@@ -376,13 +362,12 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
void
tscDestroyResPointerInfo
(
SSqlRes
*
pRes
)
{
if
(
pRes
->
buffer
!=
NULL
)
{
assert
(
pRes
->
numOfnchar
>
0
);
// free all buffers containing the multibyte string
for
(
int
i
=
0
;
i
<
pRes
->
numOf
nchar
;
i
++
)
{
for
(
int
i
=
0
;
i
<
pRes
->
numOf
Cols
;
i
++
)
{
tfree
(
pRes
->
buffer
[
i
]);
}
pRes
->
numOf
nchar
=
0
;
pRes
->
numOf
Cols
=
0
;
}
tfree
(
pRes
->
pRsp
);
...
...
@@ -391,7 +376,6 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) {
tfree
(
pRes
->
pGroupRec
);
tfree
(
pRes
->
pColumnIndex
);
tfree
(
pRes
->
buffer
);
tfree
(
pRes
->
bytes
);
pRes
->
data
=
NULL
;
// pRes->data points to the buffer of pRsp, no need to free
}
...
...
@@ -831,11 +815,18 @@ static void ensureSpace(SFieldInfo* pFieldInfo, int32_t size) {
pFieldInfo
->
pFields
=
realloc
(
pFieldInfo
->
pFields
,
newSize
*
sizeof
(
TAOS_FIELD
));
memset
(
&
pFieldInfo
->
pFields
[
oldSize
],
0
,
inc
*
sizeof
(
TAOS_FIELD
));
pFieldInfo
->
pOffset
=
realloc
(
pFieldInfo
->
pOffset
,
newSize
*
sizeof
(
int16_t
));
memset
(
&
pFieldInfo
->
pOffset
[
oldSize
],
0
,
inc
*
sizeof
(
int16_t
));
//
pFieldInfo->pOffset = realloc(pFieldInfo->pOffset, newSize * sizeof(int16_t));
//
memset(&pFieldInfo->pOffset[oldSize], 0, inc * sizeof(int16_t));
pFieldInfo
->
pVisibleCols
=
realloc
(
pFieldInfo
->
pVisibleCols
,
newSize
*
sizeof
(
bool
));
memset
(
&
pFieldInfo
->
pVisibleCols
[
oldSize
],
0
,
inc
*
sizeof
(
bool
));
pFieldInfo
->
pSqlExpr
=
realloc
(
pFieldInfo
->
pSqlExpr
,
POINTER_BYTES
*
newSize
);
pFieldInfo
->
pExpr
=
realloc
(
pFieldInfo
->
pExpr
,
POINTER_BYTES
*
newSize
);
memset
(
&
pFieldInfo
->
pSqlExpr
[
oldSize
],
0
,
inc
*
POINTER_BYTES
);
memset
(
&
pFieldInfo
->
pExpr
[
oldSize
],
0
,
inc
*
POINTER_BYTES
);
pFieldInfo
->
numOfAlloc
=
newSize
;
}
}
...
...
@@ -844,6 +835,15 @@ static void evic(SFieldInfo* pFieldInfo, int32_t index) {
if
(
index
<
pFieldInfo
->
numOfOutputCols
)
{
memmove
(
&
pFieldInfo
->
pFields
[
index
+
1
],
&
pFieldInfo
->
pFields
[
index
],
sizeof
(
pFieldInfo
->
pFields
[
0
])
*
(
pFieldInfo
->
numOfOutputCols
-
index
));
memmove
(
&
pFieldInfo
->
pVisibleCols
[
index
+
1
],
&
pFieldInfo
->
pVisibleCols
[
index
],
sizeof
(
pFieldInfo
->
pVisibleCols
[
0
])
*
(
pFieldInfo
->
numOfOutputCols
-
index
));
memmove
(
&
pFieldInfo
->
pSqlExpr
[
index
+
1
],
&
pFieldInfo
->
pSqlExpr
[
index
],
sizeof
(
pFieldInfo
->
pSqlExpr
[
0
])
*
(
pFieldInfo
->
numOfOutputCols
-
index
));
memmove
(
&
pFieldInfo
->
pExpr
[
index
+
1
],
&
pFieldInfo
->
pExpr
[
index
],
sizeof
(
pFieldInfo
->
pExpr
[
0
])
*
(
pFieldInfo
->
numOfOutputCols
-
index
));
}
}
...
...
@@ -868,7 +868,6 @@ void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIE
memcpy
(
&
pFieldInfo
->
pFields
[
index
],
pField
,
sizeof
(
TAOS_FIELD
));
pFieldInfo
->
pVisibleCols
[
index
]
=
true
;
pFieldInfo
->
numOfOutputCols
++
;
}
...
...
@@ -902,29 +901,49 @@ void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, co
pFieldInfo
->
numOfOutputCols
++
;
}
void
tscFieldInfoCalOffset
(
SQueryInfo
*
pQueryInfo
)
{
SFieldInfo
*
pFieldInfo
=
&
pQueryInfo
->
fieldsInfo
;
pFieldInfo
->
pOffset
[
0
]
=
0
;
void
tscFieldInfoSetExpr
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
SSqlExpr
*
pExpr
)
{
assert
(
index
>=
0
&&
index
<
pFieldInfo
->
numOfOutputCols
);
pFieldInfo
->
pSqlExpr
[
index
]
=
pExpr
;
}
void
tscFieldInfoSetBinExpr
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
SSqlFunctionExpr
*
pExpr
)
{
assert
(
index
>=
0
&&
index
<
pFieldInfo
->
numOfOutputCols
);
pFieldInfo
->
pExpr
[
index
]
=
pExpr
;
}
for
(
int32_t
i
=
1
;
i
<
pFieldInfo
->
numOfOutputCols
;
++
i
)
{
pFieldInfo
->
pOffset
[
i
]
=
pFieldInfo
->
pOffset
[
i
-
1
]
+
pFieldInfo
->
pFields
[
i
-
1
].
bytes
;
void
tscFieldInfoCalOffset
(
SQueryInfo
*
pQueryInfo
)
{
SSqlExprInfo
*
pExprInfo
=
&
pQueryInfo
->
exprsInfo
;
pExprInfo
->
pExprs
[
0
]
->
offset
=
0
;
for
(
int32_t
i
=
1
;
i
<
pExprInfo
->
numOfExprs
;
++
i
)
{
pExprInfo
->
pExprs
[
i
]
->
offset
=
pExprInfo
->
pExprs
[
i
-
1
]
->
offset
+
pExprInfo
->
pExprs
[
i
-
1
]
->
resBytes
;
}
}
void
tscFieldInfoUpdateOffsetForInterResult
(
SQueryInfo
*
pQueryInfo
)
{
SFieldInfo
*
pFieldInfo
=
&
pQueryInfo
->
fieldsInfo
;
if
(
pFieldInfo
->
numOfOutputCols
==
0
)
{
// SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo;
// if (pFieldInfo->numOfOutputCols == 0) {
// return;
// }
//
// pFieldInfo->pOffset[0] = 0;
//
// /*
// * the retTypeLen is used to store the intermediate result length
// * for potential secondary merge exists
// */
// for (int32_t i = 1; i < pFieldInfo->numOfOutputCols; ++i) {
// pFieldInfo->pOffset[i] = pFieldInfo->pOffset[i - 1] + tscSqlExprGet(pQueryInfo, i - 1)->resBytes;
// }
SSqlExprInfo
*
pExprInfo
=
&
pQueryInfo
->
exprsInfo
;
if
(
pExprInfo
->
numOfExprs
==
0
)
{
return
;
}
pFieldInfo
->
pOffset
[
0
]
=
0
;
/*
* the retTypeLen is used to store the intermediate result length
* for potential secondary merge exists
*/
for
(
int32_t
i
=
1
;
i
<
pFieldInfo
->
numOfOutputCols
;
++
i
)
{
pFieldInfo
->
pOffset
[
i
]
=
pFieldInfo
->
pOffset
[
i
-
1
]
+
tscSqlExprGet
(
pQueryInfo
,
i
-
1
)
->
resBytes
;
pExprInfo
->
pExprs
[
0
]
->
offset
=
0
;
for
(
int32_t
i
=
1
;
i
<
pExprInfo
->
numOfExprs
;
++
i
)
{
pExprInfo
->
pExprs
[
i
]
->
offset
=
pExprInfo
->
pExprs
[
i
-
1
]
->
offset
+
pExprInfo
->
pExprs
[
i
-
1
]
->
resBytes
;
}
}
...
...
@@ -940,6 +959,8 @@ void tscFieldInfoCopy(SFieldInfo* src, SFieldInfo* dst, const int32_t* indexList
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
assert
(
indexList
[
i
]
>=
0
&&
indexList
[
i
]
<=
src
->
numOfOutputCols
);
tscFieldInfoSetValFromField
(
dst
,
i
,
&
src
->
pFields
[
indexList
[
i
]]);
dst
->
pVisibleCols
[
i
]
=
src
->
pVisibleCols
[
indexList
[
i
]];
dst
->
pSqlExpr
[
i
]
=
src
->
pSqlExpr
[
indexList
[
i
]];
}
}
}
...
...
@@ -948,12 +969,14 @@ void tscFieldInfoCopyAll(SFieldInfo* dst, SFieldInfo* src) {
*
dst
=
*
src
;
dst
->
pFields
=
malloc
(
sizeof
(
TAOS_FIELD
)
*
dst
->
numOfAlloc
);
dst
->
pOffset
=
malloc
(
sizeof
(
short
)
*
dst
->
numOfAlloc
);
dst
->
pVisibleCols
=
malloc
(
sizeof
(
bool
)
*
dst
->
numOfAlloc
);
dst
->
pSqlExpr
=
malloc
(
POINTER_BYTES
*
dst
->
numOfAlloc
);
dst
->
pExpr
=
malloc
(
POINTER_BYTES
*
dst
->
numOfAlloc
);
memcpy
(
dst
->
pFields
,
src
->
pFields
,
sizeof
(
TAOS_FIELD
)
*
dst
->
numOfOutputCols
);
memcpy
(
dst
->
pOffset
,
src
->
pOffset
,
sizeof
(
short
)
*
dst
->
numOfOutputCols
);
memcpy
(
dst
->
pVisibleCols
,
src
->
pVisibleCols
,
sizeof
(
bool
)
*
dst
->
numOfOutputCols
);
memcpy
(
dst
->
pSqlExpr
,
src
->
pSqlExpr
,
POINTER_BYTES
*
dst
->
numOfOutputCols
);
memcpy
(
dst
->
pExpr
,
src
->
pExpr
,
POINTER_BYTES
*
dst
->
numOfOutputCols
);
}
TAOS_FIELD
*
tscFieldInfoGetField
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
)
{
...
...
@@ -967,11 +990,11 @@ TAOS_FIELD* tscFieldInfoGetField(SQueryInfo* pQueryInfo, int32_t index) {
int32_t
tscNumOfFields
(
SQueryInfo
*
pQueryInfo
)
{
return
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
}
int16_t
tscFieldInfoGetOffset
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
)
{
if
(
index
>=
pQueryInfo
->
fieldsInfo
.
numOfOutputCol
s
)
{
if
(
index
>=
pQueryInfo
->
exprsInfo
.
numOfExpr
s
)
{
return
0
;
}
return
pQueryInfo
->
fieldsInfo
.
pOffset
[
index
]
;
return
pQueryInfo
->
exprsInfo
.
pExprs
[
index
]
->
offset
;
}
int32_t
tscFieldInfoCompare
(
SFieldInfo
*
pFieldInfo1
,
SFieldInfo
*
pFieldInfo2
)
{
...
...
@@ -995,13 +1018,16 @@ int32_t tscFieldInfoCompare(SFieldInfo* pFieldInfo1, SFieldInfo* pFieldInfo2) {
}
int32_t
tscGetResRowLength
(
SQueryInfo
*
pQueryInfo
)
{
SFieldInfo
*
pFieldInfo
=
&
pQueryInfo
->
fieldsInfo
;
if
(
pFieldInfo
->
numOfOutputCols
<=
0
)
{
if
(
pQueryInfo
->
exprsInfo
.
numOfExprs
<=
0
)
{
return
0
;
}
return
pFieldInfo
->
pOffset
[
pFieldInfo
->
numOfOutputCols
-
1
]
+
pFieldInfo
->
pFields
[
pFieldInfo
->
numOfOutputCols
-
1
].
bytes
;
int32_t
size
=
0
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
size
+=
pQueryInfo
->
exprsInfo
.
pExprs
[
i
]
->
resBytes
;
}
return
size
;
}
void
tscClearFieldInfo
(
SFieldInfo
*
pFieldInfo
)
{
...
...
@@ -1009,10 +1035,19 @@ void tscClearFieldInfo(SFieldInfo* pFieldInfo) {
return
;
}
tfree
(
pFieldInfo
->
pOffset
);
tfree
(
pFieldInfo
->
pFields
);
tfree
(
pFieldInfo
->
pVisibleCols
);
tfree
(
pFieldInfo
->
pSqlExpr
);
for
(
int32_t
i
=
0
;
i
<
pFieldInfo
->
numOfOutputCols
;
++
i
)
{
if
(
pFieldInfo
->
pExpr
[
i
]
!=
NULL
)
{
tSQLBinaryExprDestroy
(
&
pFieldInfo
->
pExpr
[
i
]
->
pBinExprInfo
.
pBinExpr
,
NULL
);
tfree
(
pFieldInfo
->
pExpr
[
i
]
->
pBinExprInfo
.
pReqColumns
);
tfree
(
pFieldInfo
->
pExpr
[
i
]);
}
}
tfree
(
pFieldInfo
->
pExpr
);
memset
(
pFieldInfo
,
0
,
sizeof
(
SFieldInfo
));
}
...
...
@@ -1050,11 +1085,12 @@ SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t f
_exprCheckSpace
(
pExprInfo
,
pExprInfo
->
numOfExprs
+
1
);
_exprEvic
(
pExprInfo
,
index
);
SSqlExpr
*
pExpr
=
&
pExprInfo
->
pExprs
[
index
]
;
SSqlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
SSqlExpr
))
;
pExpr
->
functionId
=
functionId
;
pExprInfo
->
numOfExprs
++
;
pExprInfo
->
pExprs
[
index
]
=
pExpr
;
return
pExpr
;
}
...
...
@@ -1067,8 +1103,9 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
_exprCheckSpace
(
pExprInfo
,
pExprInfo
->
numOfExprs
+
1
);
_exprEvic
(
pExprInfo
,
index
);
SSqlExpr
*
pExpr
=
&
pExprInfo
->
pExprs
[
index
];
SSqlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
SSqlExpr
));
pExprInfo
->
pExprs
[
index
]
=
pExpr
;
pExpr
->
functionId
=
functionId
;
int16_t
numOfCols
=
pMeterMetaInfo
->
pMeterMeta
->
numOfColumns
;
...
...
@@ -1110,7 +1147,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
return
NULL
;
}
SSqlExpr
*
pExpr
=
&
pExprInfo
->
pExprs
[
index
];
SSqlExpr
*
pExpr
=
pExprInfo
->
pExprs
[
index
];
pExpr
->
functionId
=
functionId
;
...
...
@@ -1123,6 +1160,10 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
return
pExpr
;
}
int32_t
tscSqlExprNumOfExprs
(
SQueryInfo
*
pQueryInfo
)
{
return
pQueryInfo
->
exprsInfo
.
numOfExprs
;
}
void
addExprParams
(
SSqlExpr
*
pExpr
,
char
*
argument
,
int32_t
type
,
int32_t
bytes
,
int16_t
tableIndex
)
{
if
(
pExpr
==
NULL
||
argument
==
NULL
||
bytes
==
0
)
{
return
;
...
...
@@ -1141,7 +1182,7 @@ SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index) {
return
NULL
;
}
return
&
pQueryInfo
->
exprsInfo
.
pExprs
[
index
];
return
pQueryInfo
->
exprsInfo
.
pExprs
[
index
];
}
void
*
tscSqlExprDestroy
(
SSqlExpr
*
pExpr
)
{
...
...
@@ -1153,6 +1194,8 @@ void* tscSqlExprDestroy(SSqlExpr* pExpr) {
tVariantDestroy
(
&
pExpr
->
param
[
i
]);
}
tfree
(
pExpr
);
return
NULL
;
}
...
...
@@ -1164,8 +1207,8 @@ void tscSqlExprInfoDestroy(SSqlExprInfo* pExprInfo) {
return
;
}
for
(
int32_t
i
=
0
;
i
<
pExprInfo
->
numOf
Alloc
;
++
i
)
{
tscSqlExprDestroy
(
&
pExprInfo
->
pExprs
[
i
]);
for
(
int32_t
i
=
0
;
i
<
pExprInfo
->
numOf
Exprs
;
++
i
)
{
tscSqlExprDestroy
(
pExprInfo
->
pExprs
[
i
]);
}
tfree
(
pExprInfo
->
pExprs
);
...
...
@@ -1175,27 +1218,40 @@ void tscSqlExprInfoDestroy(SSqlExprInfo* pExprInfo) {
}
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
tableuid
)
{
void
tscSqlExprCopy
(
SSqlExprInfo
*
dst
,
const
SSqlExprInfo
*
src
,
uint64_t
tableuid
,
bool
deepcopy
)
{
if
(
src
==
NULL
)
{
return
;
}
*
dst
=
*
src
;
dst
->
pExprs
=
calloc
(
dst
->
numOfAlloc
,
sizeof
(
SSqlExpr
));
dst
->
pExprs
=
calloc
(
dst
->
numOfAlloc
,
POINTER_BYTES
);
int16_t
num
=
0
;
for
(
int32_t
i
=
0
;
i
<
src
->
numOfExprs
;
++
i
)
{
if
(
src
->
pExprs
[
i
].
uid
==
tableuid
)
{
dst
->
pExprs
[
num
++
]
=
src
->
pExprs
[
i
];
if
(
src
->
pExprs
[
i
]
->
uid
==
tableuid
)
{
if
(
deepcopy
)
{
dst
->
pExprs
[
num
]
=
calloc
(
1
,
sizeof
(
SSqlExpr
));
*
dst
->
pExprs
[
num
]
=
*
src
->
pExprs
[
i
];
}
else
{
dst
->
pExprs
[
num
]
=
src
->
pExprs
[
i
];
}
num
++
;
}
}
dst
->
numOfExprs
=
num
;
for
(
int32_t
i
=
0
;
i
<
dst
->
numOfExprs
;
++
i
)
{
for
(
int32_t
j
=
0
;
j
<
src
->
pExprs
[
i
].
numOfParams
;
++
j
)
{
tVariantAssign
(
&
dst
->
pExprs
[
i
].
param
[
j
],
&
src
->
pExprs
[
i
].
param
[
j
]);
if
(
deepcopy
)
{
for
(
int32_t
i
=
0
;
i
<
dst
->
numOfExprs
;
++
i
)
{
for
(
int32_t
j
=
0
;
j
<
src
->
pExprs
[
i
]
->
numOfParams
;
++
j
)
{
tVariantAssign
(
&
dst
->
pExprs
[
i
]
->
param
[
j
],
&
src
->
pExprs
[
i
]
->
param
[
j
]);
}
}
}
}
static
void
clearVal
(
SColumnBase
*
pBase
)
{
...
...
@@ -1950,7 +2006,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
}
uint64_t
uid
=
pMeterMetaInfo
->
pMeterMeta
->
uid
;
tscSqlExprCopy
(
&
pNewQueryInfo
->
exprsInfo
,
&
pQueryInfo
->
exprsInfo
,
uid
);
tscSqlExprCopy
(
&
pNewQueryInfo
->
exprsInfo
,
&
pQueryInfo
->
exprsInfo
,
uid
,
true
);
int32_t
numOfOutputCols
=
pNewQueryInfo
->
exprsInfo
.
numOfExprs
;
...
...
@@ -1965,7 +2021,19 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
tscFieldInfoCopy
(
&
pQueryInfo
->
fieldsInfo
,
&
pNewQueryInfo
->
fieldsInfo
,
indexList
,
numOfOutputCols
);
free
(
indexList
);
// make sure the the sqlExpr for each fields is correct
// todo handle the agg arithmetic expression
for
(
int32_t
f
=
0
;
f
<
pNewQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
f
)
{
char
*
name
=
pNewQueryInfo
->
fieldsInfo
.
pFields
[
f
].
name
;
for
(
int32_t
k1
=
0
;
k1
<
pNewQueryInfo
->
exprsInfo
.
numOfExprs
;
++
k1
)
{
SSqlExpr
*
pExpr1
=
tscSqlExprGet
(
pNewQueryInfo
,
k1
);
if
(
strcmp
(
name
,
pExpr1
->
aliasName
)
==
0
)
{
pNewQueryInfo
->
fieldsInfo
.
pSqlExpr
[
f
]
=
pExpr1
;
}
}
}
tscFieldInfoUpdateOffsetForInterResult
(
pNewQueryInfo
);
}
...
...
src/inc/hash.h
浏览文件 @
1a802566
...
...
@@ -16,6 +16,10 @@
#ifndef TDENGINE_HASH_H
#define TDENGINE_HASH_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "hashutil.h"
#define HASH_MAX_CAPACITY (1024 * 1024 * 16)
...
...
@@ -64,11 +68,12 @@ int32_t taosNumElemsInHashTable(HashObj *pObj);
char
*
taosGetDataFromHashTable
(
HashObj
*
pObj
,
const
char
*
key
,
uint32_t
keyLen
);
void
taosCleanUpHashTable
(
void
*
handle
);
int32_t
taosGetHashMaxOverflowLength
(
HashObj
*
pObj
);
int32_t
taosCheckHashTable
(
HashObj
*
pObj
);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_HASH_H
src/inc/taosmsg.h
浏览文件 @
1a802566
...
...
@@ -417,6 +417,7 @@ typedef struct SColIndexEx {
int16_t
colIdx
;
int16_t
colIdxInBuf
;
uint16_t
flag
;
// denote if it is a tag or not
char
name
[
TSDB_COL_NAME_LEN
];
}
SColIndexEx
;
/* sql function msg, to describe the message to vnode about sql function
...
...
@@ -514,7 +515,7 @@ typedef struct {
int16_t
numOfCols
;
// the number of columns will be load from vnode
char
intervalTimeUnit
;
// time interval type, for revisement of interval(1d)
int64_t
nAggTimeInterval
;
// time interval for aggregation, in million second
int64_t
intervalTime
;
// time interval for aggregation, in million second
int64_t
slidingTime
;
// value for sliding window
// tag schema, used to parse tag information in pSidExtInfo
...
...
src/inc/tast.h
浏览文件 @
1a802566
...
...
@@ -103,6 +103,8 @@ void tSQLBinaryExprCalcTraverse(tSQLBinaryExpr *pExprs, int32_t numOfRows, char
void
tSQLBinaryExprTrv
(
tSQLBinaryExpr
*
pExprs
,
int32_t
*
val
,
int16_t
*
ids
);
void
tQueryResultClean
(
tQueryResultset
*
pRes
);
uint8_t
getBinaryExprOptr
(
SSQLToken
*
pToken
);
#ifdef __cplusplus
}
#endif
...
...
src/inc/tresultBuf.h
浏览文件 @
1a802566
...
...
@@ -14,7 +14,7 @@ typedef struct SIDList {
int32_t
*
pData
;
}
SIDList
;
typedef
struct
SQueryResultBuf
{
typedef
struct
SQuery
Diskbased
ResultBuf
{
int32_t
numOfRowsPerPage
;
int32_t
numOfPages
;
int64_t
totalBufSize
;
...
...
@@ -27,7 +27,7 @@ typedef struct SQueryResultBuf {
uint32_t
numOfAllocGroupIds
;
// number of allocated id list
void
*
idsTable
;
// id hash table
SIDList
*
list
;
// for each id, there is a page id list
}
SQueryResultBuf
;
}
SQuery
Diskbased
ResultBuf
;
/**
* create disk-based result buffer
...
...
@@ -36,7 +36,7 @@ typedef struct SQueryResultBuf {
* @param rowSize
* @return
*/
int32_t
create
ResultBuf
(
SQuery
ResultBuf
**
pResultBuf
,
int32_t
size
,
int32_t
rowSize
);
int32_t
create
DiskbasedResultBuffer
(
SQueryDiskbased
ResultBuf
**
pResultBuf
,
int32_t
size
,
int32_t
rowSize
);
/**
*
...
...
@@ -45,14 +45,14 @@ int32_t createResultBuf(SQueryResultBuf** pResultBuf, int32_t size, int32_t rowS
* @param pageId
* @return
*/
tFilePage
*
getNewDataBuf
(
SQueryResultBuf
*
pResultBuf
,
int32_t
groupId
,
int32_t
*
pageId
);
tFilePage
*
getNewDataBuf
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
groupId
,
int32_t
*
pageId
);
/**
*
* @param pResultBuf
* @return
*/
int32_t
getNumOfRowsPerPage
(
SQueryResultBuf
*
pResultBuf
);
int32_t
getNumOfRowsPerPage
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
);
/**
*
...
...
@@ -60,7 +60,7 @@ int32_t getNumOfRowsPerPage(SQueryResultBuf* pResultBuf);
* @param groupId
* @return
*/
SIDList
getDataBufPagesIdList
(
SQueryResultBuf
*
pResultBuf
,
int32_t
groupId
);
SIDList
getDataBufPagesIdList
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
groupId
);
/**
* get the specified buffer page by id
...
...
@@ -68,27 +68,27 @@ SIDList getDataBufPagesIdList(SQueryResultBuf* pResultBuf, int32_t groupId);
* @param id
* @return
*/
tFilePage
*
getResultBufferPageById
(
SQueryResultBuf
*
pResultBuf
,
int32_t
id
);
tFilePage
*
getResultBufferPageById
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
id
);
/**
* get the total buffer size in the format of disk file
* @param pResultBuf
* @return
*/
int32_t
getResBufSize
(
SQueryResultBuf
*
pResultBuf
);
int32_t
getResBufSize
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
);
/**
* get the number of groups in the result buffer
* @param pResultBuf
* @return
*/
int32_t
getNumOfResultBufGroupId
(
SQueryResultBuf
*
pResultBuf
);
int32_t
getNumOfResultBufGroupId
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
);
/**
* destroy result buffer
* @param pResultBuf
*/
void
destroyResultBuf
(
SQueryResultBuf
*
pResultBuf
);
void
destroyResultBuf
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
);
/**
*
...
...
src/inc/tsqlfunction.h
浏览文件 @
1a802566
...
...
@@ -107,10 +107,11 @@ extern "C" {
#define TOP_BOTTOM_QUERY_LIMIT 100
enum
{
MASTER_SCAN
=
0x0
,
SUPPLEMENTARY_SCAN
=
0x1
,
FIRST_STAGE_MERGE
=
0x10
,
SECONDARY_STAGE_MERGE
=
0x20
,
MASTER_SCAN
=
0x0u
,
SUPPLEMENTARY_SCAN
=
0x1u
,
REPEAT_SCAN
=
0x2u
,
//repeat scan belongs to the master scan
FIRST_STAGE_MERGE
=
0x10u
,
SECONDARY_STAGE_MERGE
=
0x20u
,
};
#define QUERY_IS_STABLE_QUERY(type) (((type)&TSDB_QUERY_TYPE_STABLE_QUERY) != 0)
...
...
@@ -171,7 +172,7 @@ typedef struct SQLFunctionCtx {
int32_t
startOffset
;
int32_t
size
;
// number of rows
int32_t
order
;
// asc|desc
int32_t
scanFlag
;
// TODO merge with currentStage
u
int32_t
scanFlag
;
// TODO merge with currentStage
int16_t
inputType
;
int16_t
inputBytes
;
...
...
@@ -304,6 +305,9 @@ void getStatistics(char *priData, char *data, int32_t size, int32_t numOfRow, in
bool
top_bot_datablock_filter
(
SQLFunctionCtx
*
pCtx
,
int32_t
functionId
,
char
*
minval
,
char
*
maxval
);
bool
stableQueryFunctChanged
(
int32_t
funcId
);
void
resetResultInfo
(
SResultInfo
*
pResInfo
);
void
initResultInfo
(
SResultInfo
*
pResInfo
);
void
setResultInfoBuf
(
SResultInfo
*
pResInfo
,
int32_t
size
,
bool
superTable
);
...
...
src/system/detail/inc/vnode.h
浏览文件 @
1a802566
...
...
@@ -259,7 +259,7 @@ typedef struct SQuery {
int64_t
blockId
;
TSKEY
skey
;
TSKEY
ekey
;
int64_t
nAggTimeInterval
;
int64_t
intervalTime
;
int64_t
slidingTime
;
// sliding time for sliding window query
char
intervalTimeUnit
;
// interval data type, used for daytime revise
int8_t
precision
;
...
...
src/system/detail/inc/vnodeQueryImpl.h
浏览文件 @
1a802566
...
...
@@ -25,7 +25,7 @@ extern "C" {
#include "hash.h"
#include "hashutil.h"
#define GET_QINFO_ADDR(x)
((char*)(x)-offsetof(SQInfo, query))
#define GET_QINFO_ADDR(x) ((char*)(x)-offsetof(SQInfo, query))
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0)
/*
...
...
@@ -33,10 +33,10 @@ extern "C" {
* The page size should be sufficient for at least one output result or intermediate result.
* Some intermediate results may be extremely large, such as top/bottom(100) query.
*/
#define DEFAULT_INTERN_BUF_SIZE
16384L
#define DEFAULT_INTERN_BUF_SIZE 16384L
#define INIT_ALLOCATE_DISK_PAGES
60L
#define DEFAULT_DATA_FILE_MAPPING_PAGES
2L
#define INIT_ALLOCATE_DISK_PAGES 60L
#define DEFAULT_DATA_FILE_MAPPING_PAGES 2L
#define DEFAULT_DATA_FILE_MMAP_WINDOW_SIZE (DEFAULT_DATA_FILE_MAPPING_PAGES * DEFAULT_INTERN_BUF_SIZE)
#define IO_ENGINE_MMAP 0
...
...
@@ -56,7 +56,7 @@ typedef enum {
* the program will call this function again, if this status is set.
* used to transfer from QUERY_RESBUF_FULL
*/
QUERY_NOT_COMPLETED
=
0x1
,
QUERY_NOT_COMPLETED
=
0x1
u
,
/*
* output buffer is full, so, the next query will be employed,
...
...
@@ -66,7 +66,7 @@ typedef enum {
* this status is only exist in group-by clause and
* diff/add/division/multiply/ query.
*/
QUERY_RESBUF_FULL
=
0x2
,
QUERY_RESBUF_FULL
=
0x2
u
,
/*
* query is over
...
...
@@ -76,14 +76,13 @@ typedef enum {
* 2. when the query range on timestamp is satisfied, it is also denoted as
* query_compeleted
*/
QUERY_COMPLETED
=
0x4
,
QUERY_COMPLETED
=
0x4
u
,
/*
* all data has been scanned, so current search is stopped,
* At last, the function will transfer this status to QUERY_COMPLETED
*/
QUERY_NO_DATA_TO_CHECK
=
0x8
,
QUERY_NO_DATA_TO_CHECK
=
0x8u
,
}
vnodeQueryStatus
;
typedef
struct
SPointInterpoSupporter
{
...
...
@@ -112,15 +111,15 @@ typedef enum {
DISK_DATA_DISCARDED
=
0x01
,
}
vnodeDiskLoadStatus
;
#define IS_MASTER_SCAN(runtime) ((
runtime)->scanFlag
== MASTER_SCAN)
#define IS_SUPPLEMENT_SCAN(runtime) (
!IS_MASTER_SCAN(runtime)
)
#define IS_MASTER_SCAN(runtime) ((
(runtime)->scanFlag & 1u)
== MASTER_SCAN)
#define IS_SUPPLEMENT_SCAN(runtime) (
(runtime)->scanFlag == SUPPLEMENTARY_SCAN
)
#define SET_SUPPLEMENT_SCAN_FLAG(runtime) ((runtime)->scanFlag = SUPPLEMENTARY_SCAN)
#define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN)
typedef
int
(
*
__block_search_fn_t
)(
char
*
data
,
int
num
,
int64_t
key
,
int
order
);
static
FORCE_INLINE
SMeterObj
*
getMeterObj
(
void
*
hashHandle
,
int32_t
sid
)
{
return
*
(
SMeterObj
**
)
taosGetDataFromHashTable
(
hashHandle
,
(
const
char
*
)
&
sid
,
sizeof
(
sid
));
return
*
(
SMeterObj
**
)
taosGetDataFromHashTable
(
hashHandle
,
(
const
char
*
)
&
sid
,
sizeof
(
sid
));
}
bool
isQueryKilled
(
SQuery
*
pQuery
);
...
...
@@ -130,7 +129,7 @@ bool isSumAvgRateQuery(SQuery *pQuery);
bool
isTopBottomQuery
(
SQuery
*
pQuery
);
bool
isFirstLastRowQuery
(
SQuery
*
pQuery
);
bool
isTSCompQuery
(
SQuery
*
pQuery
);
bool
notHasQueryTimeRange
(
SQuery
*
pQuery
);
bool
notHasQueryTimeRange
(
SQuery
*
pQuery
);
bool
needSupplementaryScan
(
SQuery
*
pQuery
);
bool
onDemandLoadDatablock
(
SQuery
*
pQuery
,
int16_t
queryRangeSet
);
...
...
@@ -149,16 +148,15 @@ void vnodeScanAllData(SQueryRuntimeEnv* pRuntimeEnv);
int32_t
vnodeQueryResultInterpolate
(
SQInfo
*
pQInfo
,
tFilePage
**
pDst
,
tFilePage
**
pDataSrc
,
int32_t
numOfRows
,
int32_t
*
numOfInterpo
);
void
copyResToQueryResultBuf
(
SMeter
QuerySupportObj
*
pSupporter
,
SQuery
*
pQuery
);
void
copyResToQueryResultBuf
(
STable
QuerySupportObj
*
pSupporter
,
SQuery
*
pQuery
);
void
doSkipResults
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
void
doFinalizeResult
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
void
doSkipResults
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
void
doFinalizeResult
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
int64_t
getNumOfResult
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
void
forwardIntervalQueryRange
(
SMeterQuerySupportObj
*
pSupporter
,
SQueryRuntimeEnv
*
pRuntimeEnv
);
void
forwardQueryStartPosition
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
bool
normalizedFirstQueryRange
(
bool
dataInDisk
,
bool
dataInCache
,
S
Meter
QuerySupportObj
*
pSupporter
,
bool
normalizedFirstQueryRange
(
bool
dataInDisk
,
bool
dataInCache
,
S
Table
QuerySupportObj
*
pSupporter
,
SPointInterpoSupporter
*
pPointInterpSupporter
,
int64_t
*
key
);
void
pointInterpSupporterInit
(
SQuery
*
pQuery
,
SPointInterpoSupporter
*
pInterpoSupport
);
...
...
@@ -166,41 +164,42 @@ void pointInterpSupporterDestroy(SPointInterpoSupporter* pPointInterpSupport);
void
pointInterpSupporterSetData
(
SQInfo
*
pQInfo
,
SPointInterpoSupporter
*
pPointInterpSupport
);
int64_t
loadRequiredBlockIntoMem
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SPositionInfo
*
position
);
int32_t
doCloseAllOpenedResults
(
SMeterQuerySupportObj
*
pSupporter
);
void
disableFunctForSuppleScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
order
);
void
enableFunctForMasterScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
order
);
void
disableFunctForSuppleScan
(
STableQuerySupportObj
*
pSupporter
,
int32_t
order
);
void
enableFunctForMasterScan
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
order
);
int32_t
mergeMetersResultToOneGroups
(
STableQuerySupportObj
*
pSupporter
);
void
copyFromWindowResToSData
(
SQInfo
*
pQInfo
,
SWindowResult
*
result
);
int32_t
mergeMetersResultToOneGroups
(
SMeterQuerySupportObj
*
pSupporter
);
void
copyFromGroupBuf
(
SQInfo
*
pQInfo
,
SOutputRes
*
result
);
SBlockInfo
getBlockInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
SBlockInfo
getBlockBasicInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
void
*
pBlock
,
int32_t
type
);
SBlockInfo
getBlockBasicInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
void
*
pBlock
,
int32_t
blockType
);
SCacheBlock
*
getCacheDataBlock
(
SMeterObj
*
pMeterObj
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
slot
);
void
queryOnBlock
(
SMeterQuerySupportObj
*
pSupporter
,
int64_t
*
primaryKeys
,
int32_t
blockStatus
,
SBlockInfo
*
pBlockBasicInfo
,
SMeterDataInfo
*
pDataHeadInfoEx
,
SField
*
pFields
,
__block_search_fn_t
searchFn
);
void
stableApplyFunctionsOnBlock
(
STableQuerySupportObj
*
pSupporter
,
SMeterDataInfo
*
pMeterDataInfo
,
SBlockInfo
*
pBlockInfo
,
SField
*
pFields
,
__block_search_fn_t
searchFn
);
int32_t
vnodeFilterQualifiedMeters
(
SQInfo
*
pQInfo
,
int32_t
vid
,
tSidSet
*
pSidSet
,
SMeterDataInfo
*
pMeterDataInfo
,
int32_t
*
numOfMeters
,
SMeterDataInfo
***
pReqMeterDataInfo
);
int32_t
vnodeGetVnodeHeaderFileI
d
x
(
int32_t
*
fid
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
order
);
int32_t
vnodeFilterQualifiedMeters
(
SQInfo
*
pQInfo
,
int32_t
vid
,
tSidSet
*
pSidSet
,
SMeterDataInfo
*
pMeterDataInfo
,
int32_t
*
numOfMeters
,
SMeterDataInfo
***
pReqMeterDataInfo
);
int32_t
vnodeGetVnodeHeaderFileI
nde
x
(
int32_t
*
fid
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
order
);
int32_t
createDataBlocksInfoEx
(
SMeterDataInfo
**
pMeterDataInfo
,
int32_t
numOfMeters
,
SMeterDataBlockInfoEx
**
pDataBlockInfoEx
,
int32_t
numOfCompBlocks
,
int32_t
*
nAllocBlocksInfoSize
,
int64_t
addr
);
void
freeMeterBlockInfoEx
(
SMeterDataBlockInfoEx
*
pDataBlockInfoEx
,
int32_t
len
);
void
freeMeterBlockInfoEx
(
SMeterDataBlockInfoEx
*
pDataBlockInfoEx
,
int32_t
len
);
void
setExecutionContext
(
SMeterQuerySupportObj
*
pSupporter
,
SOutputRes
*
outputRes
,
int32_t
meterIdx
,
int32_t
groupIdx
,
SMeterQueryInfo
*
sqinfo
);
int32_t
setIntervalQueryExecutionContext
(
SMeterQuerySupportObj
*
pSupporter
,
int32_t
meterIdx
,
SMeterQueryInfo
*
sqinfo
);
void
setExecutionContext
(
STableQuerySupportObj
*
pSupporter
,
SMeterQueryInfo
*
pMeterQueryInfo
,
int32_t
meterIdx
,
int32_t
groupIdx
,
TSKEY
nextKey
);
int32_t
setAdditionalInfo
(
STableQuerySupportObj
*
pSupporter
,
int32_t
meterIdx
,
SMeterQueryInfo
*
pMeterQueryInfo
);
void
doGetAlignedIntervalQueryRangeImpl
(
SQuery
*
pQuery
,
int64_t
pKey
,
int64_t
keyFirst
,
int64_t
keyLast
,
int64_t
*
actualSkey
,
int64_t
*
actualEkey
,
int64_t
*
skey
,
int64_t
*
ekey
);
int64_t
getQueryStartPositionInCache
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
*
slot
,
int32_t
*
pos
,
bool
ignoreQueryRange
);
int64_t
getNextAccessedKeyInData
(
SQuery
*
pQuery
,
int64_t
*
pPrimaryCol
,
SBlockInfo
*
pBlockInfo
,
int32_t
blockStatus
);
int32_t
getDataBlocksForMeters
(
S
Meter
QuerySupportObj
*
pSupporter
,
SQuery
*
pQuery
,
int32_t
numOfMeters
,
const
char
*
filePath
,
SMeterDataInfo
**
pMeterDataInfo
,
uint32_t
*
numOfBlocks
);
int32_t
getDataBlocksForMeters
(
S
Table
QuerySupportObj
*
pSupporter
,
SQuery
*
pQuery
,
int32_t
numOfMeters
,
const
char
*
filePath
,
SMeterDataInfo
**
pMeterDataInfo
,
uint32_t
*
numOfBlocks
);
int32_t
LoadDatablockOnDemand
(
SCompBlock
*
pBlock
,
SField
**
pFields
,
uint8_t
*
blkStatus
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
fileIdx
,
int32_t
slotIdx
,
__block_search_fn_t
searchFn
,
bool
onDemand
);
int32_t
vnodeGetHeaderFile
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
fileIndex
);
int32_t
vnodeGetHeaderFile
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
fileIndex
);
/**
* Create SMeterQueryInfo.
...
...
@@ -210,14 +209,14 @@ int32_t vnodeGetHeaderFile(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex);
* @param ekey
* @return
*/
SMeterQueryInfo
*
createMeterQueryInfo
(
S
Query
*
pQuery
,
int32_t
sid
,
TSKEY
skey
,
TSKEY
ekey
);
SMeterQueryInfo
*
createMeterQueryInfo
(
S
TableQuerySupportObj
*
pSupporter
,
int32_t
sid
,
TSKEY
skey
,
TSKEY
ekey
);
/**
* Destroy meter query info
* @param pMeterQInfo
* @param numOfCols
*/
void
destroyMeterQueryInfo
(
SMeterQueryInfo
*
pMeterQueryInfo
,
int32_t
numOfCols
);
void
destroyMeterQueryInfo
(
SMeterQueryInfo
*
pMeterQueryInfo
,
int32_t
numOfCols
);
/**
* change the meter query info for supplement scan
...
...
@@ -225,7 +224,8 @@ void destroyMeterQueryInfo(SMeterQueryInfo *pMeterQueryInfo, int32_t numOfCols);
* @param skey
* @param ekey
*/
void
changeMeterQueryInfoForSuppleQuery
(
SQueryResultBuf
*
pResultBuf
,
SMeterQueryInfo
*
pMeterQueryInfo
,
TSKEY
skey
,
TSKEY
ekey
);
void
changeMeterQueryInfoForSuppleQuery
(
SQuery
*
pQuery
,
SMeterQueryInfo
*
pMeterQueryInfo
,
TSKEY
skey
,
TSKEY
ekey
);
/**
* add the new allocated disk page to meter query info
...
...
@@ -234,14 +234,8 @@ void changeMeterQueryInfoForSuppleQuery(SQueryResultBuf* pResultBuf, SMeterQuery
* @param pMeterQueryInfo
* @param pSupporter
*/
tFilePage
*
addDataPageForMeterQueryInfo
(
SQuery
*
pQuery
,
SMeterQueryInfo
*
pMeterQueryInfo
,
SMeterQuerySupportObj
*
pSupporter
);
/**
* save the query range data into SMeterQueryInfo
* @param pRuntimeEnv
* @param pMeterQueryInfo
*/
void
saveIntervalQueryRange
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SMeterQueryInfo
*
pMeterQueryInfo
);
tFilePage
*
addDataPageForMeterQueryInfo
(
SQuery
*
pQuery
,
SMeterQueryInfo
*
pMeterQueryInfo
,
STableQuerySupportObj
*
pSupporter
);
/**
* restore the query range data from SMeterQueryInfo to runtime environment
...
...
@@ -258,7 +252,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv* pRuntimeEnv, SMeterQueryInfo* p
* @param pSupporter
* @param key
*/
void
setIntervalQueryRange
(
SMeterQueryInfo
*
pMeterQueryInfo
,
SMeter
QuerySupportObj
*
pSupporter
,
int64_t
key
);
void
setIntervalQueryRange
(
SMeterQueryInfo
*
pMeterQueryInfo
,
STable
QuerySupportObj
*
pSupporter
,
int64_t
key
);
/**
* set the meter data information
...
...
@@ -275,16 +269,22 @@ void vnodeCheckIfDataExists(SQueryRuntimeEnv* pRuntimeEnv, SMeterObj* pMeterObj,
void
displayInterResult
(
SData
**
pdata
,
SQuery
*
pQuery
,
int32_t
numOfRows
);
void
vnodePrintQueryStatistics
(
SMeterQuerySupportObj
*
pSupporter
);
void
vnodePrintQueryStatistics
(
STableQuerySupportObj
*
pSupporter
);
void
clearTimeWindowResBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
pOneOutputRes
);
void
copyTimeWindowResBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
dst
,
const
SWindowResult
*
src
);
int32_t
initWindowResInfo
(
SWindowResInfo
*
pWindowResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
size
,
int32_t
threshold
,
int16_t
type
);
void
clearGroupResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOutputRes
*
pOneOutputRes
);
void
copyGroupResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOutputRes
*
dst
,
const
SOutputRes
*
src
);
void
cleanupTimeWindowInfo
(
SWindowResInfo
*
pWindowResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
);
void
resetTimeWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResInfo
*
pWindowResInfo
);
void
clearFirstNTimeWindow
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
num
);
void
resetSlidingWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SSlidingWindowInfo
*
pSlidingWindowInfo
);
void
clearCompletedSlidingWindows
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
int32_t
numOfClosedSlidingWindow
(
SSlidingWindowInfo
*
pSlidingWindowInfo
);
void
closeSlidingWindow
(
SSlidingWindowInfo
*
pSlidingWindowInfo
,
int32_t
slot
);
void
closeAllSlidingWindow
(
SSlidingWindowInfo
*
pSlidingWindowInfo
);
void
clearClosedTimeWindow
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
int32_t
numOfClosedTimeWindow
(
SWindowResInfo
*
pWindowResInfo
);
void
closeTimeWindow
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
);
void
closeAllTimeWindow
(
SWindowResInfo
*
pWindowResInfo
);
#ifdef __cplusplus
}
...
...
src/system/detail/inc/vnodeRead.h
浏览文件 @
1a802566
...
...
@@ -86,16 +86,26 @@ typedef struct SQueryCostSummary {
}
SQueryCostSummary
;
typedef
struct
SPosInfo
{
int
64
_t
pageId
;
int
32
_t
rowId
;
int
16
_t
pageId
;
int
16
_t
rowId
;
}
SPosInfo
;
typedef
struct
SOutputRes
{
typedef
struct
STimeWindow
{
TSKEY
skey
;
TSKEY
ekey
;
}
STimeWindow
;
typedef
struct
SWindowStatus
{
bool
closed
;
}
SWindowStatus
;
typedef
struct
SWindowResult
{
uint16_t
numOfRows
;
int32_t
nAlloc
;
SPosInfo
pos
;
SResultInfo
*
resultInfo
;
}
SOutputRes
;
SPosInfo
pos
;
// Position of current result in disk-based output buffer
SResultInfo
*
resultInfo
;
// For each result column, there is a resultInfo
STimeWindow
window
;
// The time window that current result covers.
SWindowStatus
status
;
}
SWindowResult
;
/*
* header files info, avoid to iterate the directory, the data is acquired
...
...
@@ -118,19 +128,8 @@ typedef struct SQueryFilesInfo {
char
dbFilePathPrefix
[
PATH_MAX
];
}
SQueryFilesInfo
;
typedef
struct
STimeWindow
{
TSKEY
skey
;
TSKEY
ekey
;
}
STimeWindow
;
typedef
struct
SWindowStatus
{
STimeWindow
window
;
bool
closed
;
}
SWindowStatus
;
typedef
struct
SSlidingWindowInfo
{
SOutputRes
*
pResult
;
// reference to SQuerySupporter->pResult
SWindowStatus
*
pStatus
;
// current query window closed or not?
typedef
struct
SWindowResInfo
{
SWindowResult
*
pResult
;
// reference to SQuerySupporter->pResult
void
*
hashList
;
// hash list for quick access
int16_t
type
;
// data type for hash key
int32_t
capacity
;
// max capacity
...
...
@@ -140,7 +139,7 @@ typedef struct SSlidingWindowInfo {
int64_t
startTime
;
// start time of the first time window for sliding query
int64_t
prevSKey
;
// previous (not completed) sliding window start key
int64_t
threshold
;
// threshold for return completed results.
}
S
SlidingWindow
Info
;
}
S
WindowRes
Info
;
typedef
struct
SQueryRuntimeEnv
{
SPositionInfo
startPos
;
/* the start position, used for secondary/third iteration */
...
...
@@ -161,28 +160,25 @@ typedef struct SQueryRuntimeEnv {
SQueryFilesInfo
vnodeFileInfo
;
int16_t
numOfRowsPerPage
;
int16_t
offset
[
TSDB_MAX_COLUMNS
];
int16_t
scanFlag
;
// denotes reversed scan of data or not
uint16_t
scanFlag
;
// denotes reversed scan of data or not
SInterpolationInfo
interpoInfo
;
SData
**
pInterpoBuf
;
S
SlidingWindowInfo
s
windowResInfo
;
S
WindowResInfo
windowResInfo
;
STSBuf
*
pTSBuf
;
STSCursor
cur
;
SQueryCostSummary
summary
;
S
TimeWindow
intervalWindow
;
// the complete time window, not affected by the actual data distribution
bool
stableQuery
;
// is super table query or not
S
QueryDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
/*
* Temporarily hold the in-memory cache block info during scan cache blocks
* Here we do not use the cacheblock info from pMeterObj, simple because it may change anytime
* during the query by the sub
u
mit/insert handling threads.
* Here we do not use the cache
block info from pMeterObj, simple because it may change anytime
* during the query by the submit/insert handling threads.
* So we keep a copy of the support structure as well as the cache block data itself.
*/
SCacheBlock
cacheBlock
;
SQueryResultBuf
*
pResultBuf
;
bool
stableQuery
;
// is super table query or not
}
SQueryRuntimeEnv
;
/* intermediate pos during multimeter query involves interval */
...
...
@@ -191,14 +187,12 @@ typedef struct SMeterQueryInfo {
int64_t
skey
;
int64_t
ekey
;
int32_t
numOfRes
;
int32_t
reverseIndex
;
// reversed output indicator, start from (numOfRes-1)
int16_t
reverseFillRes
;
// denote if reverse fill the results in supplementary scan required or not
int16_t
queryRangeSet
;
// denote if the query range is set, only available for interval query
int16_t
lastResRows
;
int64_t
tag
;
STSCursor
cur
;
SResultInfo
*
resultInfo
;
int32_t
sid
;
// for retrieve the page id list
SWindowResInfo
windowResInfo
;
}
SMeterQueryInfo
;
typedef
struct
SMeterDataInfo
{
...
...
@@ -212,7 +206,7 @@ typedef struct SMeterDataInfo {
SMeterQueryInfo
*
pMeterQInfo
;
}
SMeterDataInfo
;
typedef
struct
S
Meter
QuerySupportObj
{
typedef
struct
S
Table
QuerySupportObj
{
void
*
pMetersHashTable
;
// meter table hash list
SMeterSidExtInfo
**
pMeterSidExtInfo
;
...
...
@@ -225,13 +219,11 @@ typedef struct SMeterQuerySupportObj {
* rows may be generated by a specific subgroup. When query on all subgroups is executed,
* the result is copy to output buffer. This attribution is not used during single meter query processing.
*/
SOutputRes
*
pResult
;
SQueryRuntimeEnv
runtimeEnv
;
int64_t
rawSKey
;
int64_t
rawEKey
;
int32_t
subgroupIdx
;
int32_t
offset
;
/* offset in group result set of subgroup */
tSidSet
*
pSidSet
;
/*
...
...
@@ -247,7 +239,7 @@ typedef struct SMeterQuerySupportObj {
SMeterDataInfo
*
pMeterDataInfo
;
TSKEY
*
tsList
;
}
S
Meter
QuerySupportObj
;
}
S
Table
QuerySupportObj
;
typedef
struct
_qinfo
{
uint64_t
signature
;
...
...
@@ -273,18 +265,18 @@ typedef struct _qinfo {
SMeterObj
*
pObj
;
sem_t
dataReady
;
S
MeterQuerySupportObj
*
pMeter
QuerySupporter
;
S
TableQuerySupportObj
*
pTable
QuerySupporter
;
int
(
*
fp
)(
SMeterObj
*
,
SQuery
*
);
}
SQInfo
;
int32_t
vnodeQuery
SingleMeterPrepare
(
SQInfo
*
pQInfo
,
SMeterObj
*
pMeterObj
,
SMeter
QuerySupportObj
*
pSMultiMeterObj
,
int32_t
vnodeQuery
TablePrepare
(
SQInfo
*
pQInfo
,
SMeterObj
*
pMeterObj
,
STable
QuerySupportObj
*
pSMultiMeterObj
,
void
*
param
);
void
vnodeQueryFreeQInfoEx
(
SQInfo
*
pQInfo
);
bool
vnodeParametersSafetyCheck
(
SQuery
*
pQuery
);
int32_t
vnode
MultiMeter
QueryPrepare
(
SQInfo
*
pQInfo
,
SQuery
*
pQuery
,
void
*
param
);
int32_t
vnode
STable
QueryPrepare
(
SQInfo
*
pQInfo
,
SQuery
*
pQuery
,
void
*
param
);
/**
* decrease the numofQuery of each table that is queried, enable the
...
...
src/system/detail/src/vnodeQueryImpl.c
浏览文件 @
1a802566
此差异已折叠。
点击以展开。
src/system/detail/src/vnodeQueryProcess.c
浏览文件 @
1a802566
此差异已折叠。
点击以展开。
src/system/detail/src/vnodeRead.c
浏览文件 @
1a802566
...
...
@@ -266,7 +266,7 @@ static SQInfo *vnodeAllocateQInfoEx(SQueryMeterMsg *pQueryMsg, SSqlGroupbyExpr *
}
pQuery
->
pGroupbyExpr
=
pGroupbyExpr
;
pQuery
->
nAggTimeInterval
=
pQueryMsg
->
nAggTimeInterval
;
pQuery
->
intervalTime
=
pQueryMsg
->
intervalTime
;
pQuery
->
slidingTime
=
pQueryMsg
->
slidingTime
;
pQuery
->
interpoType
=
pQueryMsg
->
interpoType
;
pQuery
->
intervalTimeUnit
=
pQueryMsg
->
intervalTimeUnit
;
...
...
@@ -648,7 +648,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
goto
_error
;
}
S
MeterQuerySupportObj
*
pSupporter
=
(
SMeterQuerySupportObj
*
)
calloc
(
1
,
sizeof
(
SMeter
QuerySupportObj
));
S
TableQuerySupportObj
*
pSupporter
=
(
STableQuerySupportObj
*
)
calloc
(
1
,
sizeof
(
STable
QuerySupportObj
));
pSupporter
->
numOfMeters
=
1
;
pSupporter
->
pMetersHashTable
=
taosInitHashTable
(
pSupporter
->
numOfMeters
,
taosIntHash_32
,
false
);
...
...
@@ -659,7 +659,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
pSupporter
->
subgroupIdx
=
-
1
;
pSupporter
->
pMeterSidExtInfo
=
NULL
;
pQInfo
->
p
Meter
QuerySupporter
=
pSupporter
;
pQInfo
->
p
Table
QuerySupporter
=
pSupporter
;
STSBuf
*
pTSBuf
=
NULL
;
if
(
pQueryMsg
->
tsLen
>
0
)
{
...
...
@@ -670,7 +670,7 @@ void *vnodeQueryOnSingleTable(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
tsBufNextPos
(
pTSBuf
);
}
if
(((
*
code
)
=
vnodeQuery
SingleMeter
Prepare
(
pQInfo
,
pQInfo
->
pObj
,
pSupporter
,
pTSBuf
))
!=
TSDB_CODE_SUCCESS
)
{
if
(((
*
code
)
=
vnodeQuery
Table
Prepare
(
pQInfo
,
pQInfo
->
pObj
,
pSupporter
,
pTSBuf
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
...
...
@@ -739,7 +739,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
SSchedMsg
schedMsg
=
{
0
};
S
MeterQuerySupportObj
*
pSupporter
=
(
SMeterQuerySupportObj
*
)
calloc
(
1
,
sizeof
(
SMeter
QuerySupportObj
));
S
TableQuerySupportObj
*
pSupporter
=
(
STableQuerySupportObj
*
)
calloc
(
1
,
sizeof
(
STable
QuerySupportObj
));
pSupporter
->
numOfMeters
=
pQueryMsg
->
numOfSids
;
pSupporter
->
pMetersHashTable
=
taosInitHashTable
(
pSupporter
->
numOfMeters
,
taosIntHash_32
,
false
);
...
...
@@ -784,7 +784,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
(
SSchema
*
)
pQueryMsg
->
pTagSchema
,
pQueryMsg
->
numOfTagsCols
,
NULL
,
0
);
}
pQInfo
->
p
Meter
QuerySupporter
=
pSupporter
;
pQInfo
->
p
Table
QuerySupporter
=
pSupporter
;
STSBuf
*
pTSBuf
=
NULL
;
if
(
pQueryMsg
->
tsLen
>
0
)
{
...
...
@@ -794,7 +794,7 @@ void *vnodeQueryOnMultiMeters(SMeterObj **pMetersObj, SSqlGroupbyExpr *pGroupbyE
tsBufResetPos
(
pTSBuf
);
}
if
(((
*
code
)
=
vnode
MultiMeter
QueryPrepare
(
pQInfo
,
pQuery
,
pTSBuf
))
!=
TSDB_CODE_SUCCESS
)
{
if
(((
*
code
)
=
vnode
STable
QueryPrepare
(
pQInfo
,
pQuery
,
pTSBuf
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
...
...
@@ -898,8 +898,8 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
SSchedMsg
schedMsg
=
{
0
};
if
(
pQInfo
->
p
Meter
QuerySupporter
!=
NULL
)
{
if
(
pQInfo
->
p
Meter
QuerySupporter
->
pSidSet
==
NULL
)
{
if
(
pQInfo
->
p
Table
QuerySupporter
!=
NULL
)
{
if
(
pQInfo
->
p
Table
QuerySupporter
->
pSidSet
==
NULL
)
{
schedMsg
.
fp
=
vnodeSingleTableQuery
;
}
else
{
// group by tag
schedMsg
.
fp
=
vnodeMultiMeterQuery
;
...
...
@@ -920,8 +920,8 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
}
static
int32_t
validateQueryMeterMsg
(
SQueryMeterMsg
*
pQueryMsg
)
{
if
(
pQueryMsg
->
nAggTimeInterval
<
0
)
{
dError
(
"qmsg:%p illegal value of aggTimeInterval %"
PRId64
""
,
pQueryMsg
,
pQueryMsg
->
nAggTimeInterval
);
if
(
pQueryMsg
->
intervalTime
<
0
)
{
dError
(
"qmsg:%p illegal value of aggTimeInterval %"
PRId64
""
,
pQueryMsg
,
pQueryMsg
->
intervalTime
);
return
-
1
;
}
...
...
@@ -975,7 +975,7 @@ int32_t vnodeConvertQueryMeterMsg(SQueryMeterMsg *pQueryMsg) {
pQueryMsg
->
queryType
=
htons
(
pQueryMsg
->
queryType
);
pQueryMsg
->
nAggTimeInterval
=
htobe64
(
pQueryMsg
->
nAggTimeInterval
);
pQueryMsg
->
intervalTime
=
htobe64
(
pQueryMsg
->
intervalTime
);
pQueryMsg
->
slidingTime
=
htobe64
(
pQueryMsg
->
slidingTime
);
pQueryMsg
->
numOfTagsCols
=
htons
(
pQueryMsg
->
numOfTagsCols
);
...
...
@@ -1146,7 +1146,7 @@ int32_t vnodeConvertQueryMeterMsg(SQueryMeterMsg *pQueryMsg) {
"offset:%"
PRId64
,
pQueryMsg
,
pQueryMsg
->
numOfSids
,
pQueryMsg
->
skey
,
pQueryMsg
->
ekey
,
pQueryMsg
->
numOfGroupCols
,
pQueryMsg
->
numOfTagsCols
,
pQueryMsg
->
order
,
pQueryMsg
->
orderType
,
pQueryMsg
->
orderByIdx
,
pQueryMsg
->
numOfOutputCols
,
pQueryMsg
->
numOfCols
,
pQueryMsg
->
nAggTimeInterval
,
pQueryMsg
->
interpoType
,
pQueryMsg
->
numOfOutputCols
,
pQueryMsg
->
numOfCols
,
pQueryMsg
->
intervalTime
,
pQueryMsg
->
interpoType
,
pQueryMsg
->
tsLen
,
pQueryMsg
->
limit
,
pQueryMsg
->
offset
);
return
0
;
...
...
src/system/detail/src/vnodeShell.c
浏览文件 @
1a802566
...
...
@@ -446,8 +446,8 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
// buffer size for progress information, including meter count,
// and for each meter, including 'uid' and 'TSKEY'.
int
progressSize
=
0
;
if
(
pQInfo
->
p
Meter
QuerySupporter
!=
NULL
)
progressSize
=
pQInfo
->
p
Meter
QuerySupporter
->
numOfMeters
*
(
sizeof
(
int64_t
)
+
sizeof
(
TSKEY
))
+
sizeof
(
int32_t
);
if
(
pQInfo
->
p
Table
QuerySupporter
!=
NULL
)
progressSize
=
pQInfo
->
p
Table
QuerySupporter
->
numOfMeters
*
(
sizeof
(
int64_t
)
+
sizeof
(
TSKEY
))
+
sizeof
(
int32_t
);
else
if
(
pQInfo
->
pObj
!=
NULL
)
progressSize
=
sizeof
(
int64_t
)
+
sizeof
(
TSKEY
)
+
sizeof
(
int32_t
);
...
...
@@ -486,13 +486,13 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
// write the progress information of each meter to response
// this is required by subscriptions
if
(
pQInfo
!=
NULL
)
{
if
(
pQInfo
->
p
MeterQuerySupporter
!=
NULL
&&
pQInfo
->
pMeter
QuerySupporter
->
pMeterSidExtInfo
!=
NULL
)
{
*
((
int32_t
*
)
pMsg
)
=
htonl
(
pQInfo
->
p
Meter
QuerySupporter
->
numOfMeters
);
if
(
pQInfo
->
p
TableQuerySupporter
!=
NULL
&&
pQInfo
->
pTable
QuerySupporter
->
pMeterSidExtInfo
!=
NULL
)
{
*
((
int32_t
*
)
pMsg
)
=
htonl
(
pQInfo
->
p
Table
QuerySupporter
->
numOfMeters
);
pMsg
+=
sizeof
(
int32_t
);
for
(
int32_t
i
=
0
;
i
<
pQInfo
->
p
Meter
QuerySupporter
->
numOfMeters
;
i
++
)
{
*
((
int64_t
*
)
pMsg
)
=
htobe64
(
pQInfo
->
p
Meter
QuerySupporter
->
pMeterSidExtInfo
[
i
]
->
uid
);
for
(
int32_t
i
=
0
;
i
<
pQInfo
->
p
Table
QuerySupporter
->
numOfMeters
;
i
++
)
{
*
((
int64_t
*
)
pMsg
)
=
htobe64
(
pQInfo
->
p
Table
QuerySupporter
->
pMeterSidExtInfo
[
i
]
->
uid
);
pMsg
+=
sizeof
(
int64_t
);
*
((
TSKEY
*
)
pMsg
)
=
htobe64
(
pQInfo
->
p
Meter
QuerySupporter
->
pMeterSidExtInfo
[
i
]
->
key
);
*
((
TSKEY
*
)
pMsg
)
=
htobe64
(
pQInfo
->
p
Table
QuerySupporter
->
pMeterSidExtInfo
[
i
]
->
key
);
pMsg
+=
sizeof
(
TSKEY
);
}
}
else
if
(
pQInfo
->
pObj
!=
NULL
)
{
...
...
src/system/detail/src/vnodeUtil.c
浏览文件 @
1a802566
...
...
@@ -372,18 +372,22 @@ void vnodeUpdateFilterColumnIndex(SQuery* pQuery) {
}
// set the column index in buffer for arithmetic operation
if
(
pQuery
->
pSelectExpr
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
SSqlBinaryExprInfo
*
pBinExprInfo
=
&
pQuery
->
pSelectExpr
[
i
].
pBinExprInfo
;
if
(
pBinExprInfo
->
pBinExpr
!=
NULL
)
{
for
(
int16_t
j
=
0
;
j
<
pBinExprInfo
->
numOfCols
;
++
j
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfCols
;
++
k
)
{
if
(
pBinExprInfo
->
pReqColumns
[
j
].
colId
==
pQuery
->
colList
[
k
].
data
.
colId
)
{
pBinExprInfo
->
pReqColumns
[
j
].
colIdxInBuf
=
pQuery
->
colList
[
k
].
colIdxInBuf
;
assert
(
pQuery
->
colList
[
k
].
colIdxInBuf
==
k
);
break
;
}
}
if
(
pQuery
->
pSelectExpr
==
NULL
)
{
return
;
}
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
SSqlBinaryExprInfo
*
pBinExprInfo
=
&
pQuery
->
pSelectExpr
[
i
].
pBinExprInfo
;
if
(
pBinExprInfo
->
pBinExpr
==
NULL
)
{
continue
;
}
for
(
int16_t
j
=
0
;
j
<
pBinExprInfo
->
numOfCols
;
++
j
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfCols
;
++
k
)
{
if
(
pBinExprInfo
->
pReqColumns
[
j
].
colId
==
pQuery
->
colList
[
k
].
data
.
colId
)
{
pBinExprInfo
->
pReqColumns
[
j
].
colIdxInBuf
=
pQuery
->
colList
[
k
].
colIdxInBuf
;
assert
(
pQuery
->
colList
[
k
].
colIdxInBuf
==
k
);
break
;
}
}
}
...
...
src/util/src/hash.c
浏览文件 @
1a802566
...
...
@@ -340,10 +340,6 @@ static void doAddToHashTable(HashObj *pObj, SHashNode *pNode) {
pEntry
->
num
++
;
pObj
->
size
++
;
// char key[512] = {0};
// memcpy(key, pNode->key, MIN(512, pNode->keyLen));
// pTrace("key:%s %p add to hash table", key, pNode);
}
int32_t
taosNumElemsInHashTable
(
HashObj
*
pObj
)
{
...
...
@@ -525,29 +521,3 @@ int32_t taosGetHashMaxOverflowLength(HashObj* pObj) {
return
num
;
}
int32_t
taosCheckHashTable
(
HashObj
*
pObj
)
{
for
(
int32_t
i
=
0
;
i
<
pObj
->
capacity
;
++
i
)
{
SHashEntry
*
pEntry
=
pObj
->
hashList
[
i
];
SHashNode
*
pNode
=
pEntry
->
next
;
if
(
pNode
!=
NULL
)
{
assert
(
pEntry
==
pNode
->
prev1
);
int32_t
num
=
1
;
SHashNode
*
pNext
=
pNode
->
next
;
while
(
pNext
)
{
assert
(
pNext
->
prev
==
pNode
);
pNode
=
pNext
;
pNext
=
pNext
->
next
;
num
++
;
}
assert
(
num
==
pEntry
->
num
);
}
}
return
0
;
}
src/util/src/textbuffer.c
浏览文件 @
1a802566
...
...
@@ -468,8 +468,8 @@ int32_t compare_a(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1,
return
ret
;
}
}
else
{
SSchema
*
pSchema
=
&
pDescriptor
->
pColumnModel
->
pFields
[
colIdx
];
int32_t
ret
=
columnValueAscendingComparator
(
f1
,
f2
,
pSchema
->
type
,
pSchema
->
bytes
);
SSchema
Ex
*
pSchema
=
&
pDescriptor
->
pColumnModel
->
pFields
[
colIdx
];
int32_t
ret
=
columnValueAscendingComparator
(
f1
,
f2
,
pSchema
->
field
.
type
,
pSchema
->
field
.
bytes
);
if
(
ret
==
0
)
{
continue
;
}
else
{
...
...
@@ -500,8 +500,8 @@ int32_t compare_d(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1,
return
ret
;
}
}
else
{
SSchema
*
pSchema
=
&
pDescriptor
->
pColumnModel
->
pFields
[
colIdx
];
int32_t
ret
=
columnValueAscendingComparator
(
f1
,
f2
,
pSchema
->
type
,
pSchema
->
bytes
);
SSchema
Ex
*
pSchema
=
&
pDescriptor
->
pColumnModel
->
pFields
[
colIdx
];
int32_t
ret
=
columnValueAscendingComparator
(
f1
,
f2
,
pSchema
->
field
.
type
,
pSchema
->
field
.
bytes
);
if
(
ret
==
0
)
{
continue
;
}
else
{
...
...
src/util/src/tinterpolation.c
浏览文件 @
1a802566
...
...
@@ -13,9 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <stdint.h>
#include "os.h"
#include "taosmsg.h"
#include "textbuffer.h"
...
...
@@ -47,7 +44,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t timeRange, char
char
**
tzname
=
_tzname
;
#endif
int64_t
t
=
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
?
MILLISECOND_PER_SECOND
:
MILLISECOND_PER_SECOND
*
1000L
;
int64_t
t
=
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
?
MILLISECOND_PER_SECOND
:
MILLISECOND_PER_SECOND
*
1000L
;
int64_t
revStartime
=
(
startTime
/
timeRange
)
*
timeRange
+
timezone
*
t
;
int64_t
revEndtime
=
revStartime
+
timeRange
-
1
;
...
...
@@ -78,14 +75,14 @@ void taosInitInterpoInfo(SInterpolationInfo* pInterpoInfo, int32_t order, int64_
}
// the SInterpolationInfo itself will not be released
void
taosDestoryInterpoInfo
(
SInterpolationInfo
*
pInterpoInfo
)
{
void
taosDestoryInterpoInfo
(
SInterpolationInfo
*
pInterpoInfo
)
{
if
(
pInterpoInfo
==
NULL
)
{
return
;
}
tfree
(
pInterpoInfo
->
prevValues
);
tfree
(
pInterpoInfo
->
nextValues
);
tfree
(
pInterpoInfo
->
pTags
);
}
...
...
@@ -94,7 +91,7 @@ void taosInterpoSetStartInfo(SInterpolationInfo* pInterpoInfo, int32_t numOfRawD
return
;
}
pInterpoInfo
->
rowIdx
=
0
;
//
INTERPOL_IS_ASC_INTERPOL(pInterpoInfo) ? 0 : numOfRawDataInRows - 1;
pInterpoInfo
->
rowIdx
=
0
;
//
INTERPOL_IS_ASC_INTERPOL(pInterpoInfo) ? 0 : numOfRawDataInRows - 1;
pInterpoInfo
->
numOfRawDataInRows
=
numOfRawDataInRows
;
}
...
...
@@ -118,14 +115,9 @@ int32_t taosGetNumOfResWithoutLimit(SInterpolationInfo* pInterpoInfo, int64_t* p
if
(
numOfAvailRawData
>
0
)
{
int32_t
finalNumOfResult
=
0
;
// if (pInterpoInfo->order == TSQL_SO_ASC) {
// get last timestamp, calculate the result size
int64_t
lastKey
=
pPrimaryKeyArray
[
pInterpoInfo
->
numOfRawDataInRows
-
1
];
finalNumOfResult
=
(
int32_t
)(
labs
(
lastKey
-
pInterpoInfo
->
startTimestamp
)
/
nInterval
)
+
1
;
// } else { // todo error less than one!!!
// TSKEY lastKey = pPrimaryKeyArray[0];
// finalNumOfResult = (int32_t)((pInterpoInfo->startTimestamp - lastKey) / nInterval) + 1;
// }
// get last timestamp, calculate the result size
int64_t
lastKey
=
pPrimaryKeyArray
[
pInterpoInfo
->
numOfRawDataInRows
-
1
];
finalNumOfResult
=
(
int32_t
)(
labs
(
lastKey
-
pInterpoInfo
->
startTimestamp
)
/
nInterval
)
+
1
;
assert
(
finalNumOfResult
>=
numOfAvailRawData
);
return
finalNumOfResult
;
...
...
@@ -140,7 +132,9 @@ int32_t taosGetNumOfResWithoutLimit(SInterpolationInfo* pInterpoInfo, int64_t* p
}
}
bool
taosHasRemainsDataForInterpolation
(
SInterpolationInfo
*
pInterpoInfo
)
{
return
taosNumOfRemainPoints
(
pInterpoInfo
)
>
0
;
}
bool
taosHasRemainsDataForInterpolation
(
SInterpolationInfo
*
pInterpoInfo
)
{
return
taosNumOfRemainPoints
(
pInterpoInfo
)
>
0
;
}
int32_t
taosNumOfRemainPoints
(
SInterpolationInfo
*
pInterpoInfo
)
{
if
(
pInterpoInfo
->
rowIdx
==
-
1
||
pInterpoInfo
->
numOfRawDataInRows
==
0
)
{
...
...
@@ -197,28 +191,22 @@ int taosDoLinearInterpolation(int32_t type, SPoint* point1, SPoint* point2, SPoi
return
0
;
}
static
char
*
getPos
(
char
*
data
,
int32_t
bytes
,
int32_t
order
,
int32_t
capacity
,
int32_t
index
)
{
// if (order == TSQL_SO_ASC) {
return
data
+
index
*
bytes
;
// } else {
// return data + (capacity - index - 1) * bytes;
// }
}
static
char
*
getPos
(
char
*
data
,
int32_t
bytes
,
int32_t
index
)
{
return
data
+
index
*
bytes
;
}
static
void
setTagsValueInInterpolation
(
tFilePage
**
data
,
char
**
pTags
,
SColumnModel
*
pModel
,
int32_t
order
,
int32_t
start
,
int32_t
capacity
,
int32_t
num
)
{
static
void
setTagsValueInInterpolation
(
tFilePage
**
data
,
char
**
pTags
,
SColumnModel
*
pModel
,
int32_t
order
,
int32_t
start
,
int32_t
capacity
,
int32_t
num
)
{
for
(
int32_t
j
=
0
,
i
=
start
;
i
<
pModel
->
numOfCols
;
++
i
,
++
j
)
{
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
order
,
capacity
,
num
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
num
);
assignVal
(
val1
,
pTags
[
j
],
pSchema
->
bytes
,
pSchema
->
type
);
}
}
static
void
doInterpoResultImpl
(
SInterpolationInfo
*
pInterpoInfo
,
int16_t
interpoType
,
tFilePage
**
data
,
SColumnModel
*
pModel
,
int32_t
*
num
,
char
**
srcData
,
int64_t
nInterval
,
int64_t
*
defaultVal
,
int64_t
currentTimestamp
,
int32_t
capacity
,
int32_t
numOfTags
,
char
**
p
Tags
,
bool
outOfBound
)
{
SColumnModel
*
pModel
,
int32_t
*
num
,
char
**
srcData
,
int64_t
nInterval
,
int64_t
*
defaultVal
,
int64_t
currentTimestamp
,
int32_t
capacity
,
int32_t
numOf
Tags
,
char
**
pTags
,
bool
outOfBound
)
{
char
**
prevValues
=
&
pInterpoInfo
->
prevValues
;
char
**
nextValues
=
&
pInterpoInfo
->
nextValues
;
...
...
@@ -226,7 +214,7 @@ static void doInterpoResultImpl(SInterpolationInfo* pInterpoInfo, int16_t interp
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pInterpoInfo
->
order
);
char
*
val
=
getPos
(
data
[
0
]
->
data
,
TSDB_KEYSIZE
,
pInterpoInfo
->
order
,
capacity
,
*
num
);
char
*
val
=
getPos
(
data
[
0
]
->
data
,
TSDB_KEYSIZE
,
*
num
);
*
(
TSKEY
*
)
val
=
pInterpoInfo
->
startTimestamp
;
int32_t
numOfValCols
=
pModel
->
numOfCols
-
numOfTags
;
...
...
@@ -237,9 +225,9 @@ static void doInterpoResultImpl(SInterpolationInfo* pInterpoInfo, int16_t interp
if
(
pInterpolationData
!=
NULL
)
{
for
(
int32_t
i
=
1
;
i
<
numOfValCols
;
++
i
)
{
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
pInterpoInfo
->
order
,
capacity
,
*
num
);
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
*
num
);
if
(
isNull
(
pInterpolationData
+
offset
,
pSchema
->
type
))
{
setNull
(
val1
,
pSchema
->
type
,
pSchema
->
bytes
);
...
...
@@ -250,8 +238,8 @@ static void doInterpoResultImpl(SInterpolationInfo* pInterpoInfo, int16_t interp
}
else
{
/* no prev value yet, set the value for null */
for
(
int32_t
i
=
1
;
i
<
numOfValCols
;
++
i
)
{
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
pInterpoInfo
->
order
,
capacity
,
*
num
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
*
num
);
setNull
(
val1
,
pSchema
->
type
,
pSchema
->
bytes
);
}
}
...
...
@@ -262,10 +250,10 @@ static void doInterpoResultImpl(SInterpolationInfo* pInterpoInfo, int16_t interp
if
(
*
prevValues
!=
NULL
&&
!
outOfBound
)
{
for
(
int32_t
i
=
1
;
i
<
numOfValCols
;
++
i
)
{
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
int16_t
type
=
pSchema
->
type
;
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
pInterpoInfo
->
order
,
capacity
,
*
num
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
*
num
);
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
||
type
==
TSDB_DATA_TYPE_BOOL
)
{
setNull
(
val1
,
type
,
pSchema
->
bytes
);
...
...
@@ -283,8 +271,8 @@ static void doInterpoResultImpl(SInterpolationInfo* pInterpoInfo, int16_t interp
}
else
{
for
(
int32_t
i
=
1
;
i
<
numOfValCols
;
++
i
)
{
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
pInterpoInfo
->
order
,
capacity
,
*
num
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
*
num
);
setNull
(
val1
,
pSchema
->
type
,
pSchema
->
bytes
);
}
...
...
@@ -293,8 +281,8 @@ static void doInterpoResultImpl(SInterpolationInfo* pInterpoInfo, int16_t interp
}
else
{
/* default value interpolation */
for
(
int32_t
i
=
1
;
i
<
numOfValCols
;
++
i
)
{
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
pInterpoInfo
->
order
,
capacity
,
*
num
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
*
num
);
assignVal
(
val1
,
(
char
*
)
&
defaultVal
[
i
],
pSchema
->
bytes
,
pSchema
->
type
);
}
...
...
@@ -344,9 +332,9 @@ int32_t taosDoInterpoResult(SInterpolationInfo* pInterpoInfo, int16_t interpoTyp
if
(
*
nextValues
==
NULL
)
{
*
nextValues
=
calloc
(
1
,
pModel
->
rowSize
);
for
(
int
i
=
1
;
i
<
pModel
->
numOfCols
;
i
++
)
{
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
setNull
(
*
nextValues
+
offset
,
pSchema
->
type
,
pSchema
->
bytes
);
}
}
...
...
@@ -354,33 +342,36 @@ int32_t taosDoInterpoResult(SInterpolationInfo* pInterpoInfo, int16_t interpoTyp
int32_t
offset
=
pInterpoInfo
->
rowIdx
;
for
(
int32_t
tlen
=
0
,
i
=
0
;
i
<
pModel
->
numOfCols
-
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
memcpy
(
*
nextValues
+
tlen
,
srcData
[
i
]
+
offset
*
pSchema
->
bytes
,
pSchema
->
bytes
);
tlen
+=
pSchema
->
bytes
;
}
}
while
(((
pInterpoInfo
->
startTimestamp
<
currentTimestamp
&&
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
))
||
(
pInterpoInfo
->
startTimestamp
>
currentTimestamp
&&
!
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
)))
&&
num
<
outputRows
)
{
doInterpoResultImpl
(
pInterpoInfo
,
interpoType
,
data
,
pModel
,
&
num
,
srcData
,
nInterval
,
defaultVal
,
currentTimestamp
,
bufSize
,
numOfTags
,
pTags
,
false
);
}
/* output buffer is full, abort */
if
((
num
==
outputRows
&&
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
))
||
(
num
<
0
&&
!
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
)))
{
pInterpoInfo
->
numOfTotalInterpo
+=
pInterpoInfo
->
numOfCurrentInterpo
;
return
outputRows
;
}
if
(((
pInterpoInfo
->
startTimestamp
<
currentTimestamp
&&
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
))
||
(
pInterpoInfo
->
startTimestamp
>
currentTimestamp
&&
!
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
)))
&&
num
<
outputRows
)
{
while
(((
pInterpoInfo
->
startTimestamp
<
currentTimestamp
&&
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
))
||
(
pInterpoInfo
->
startTimestamp
>
currentTimestamp
&&
!
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
)))
&&
num
<
outputRows
)
{
doInterpoResultImpl
(
pInterpoInfo
,
interpoType
,
data
,
pModel
,
&
num
,
srcData
,
nInterval
,
defaultVal
,
currentTimestamp
,
bufSize
,
numOfTags
,
pTags
,
false
);
}
if
(
pInterpoInfo
->
startTimestamp
==
currentTimestamp
)
{
/* output buffer is full, abort */
if
((
num
==
outputRows
&&
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
))
||
(
num
<
0
&&
!
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
)))
{
pInterpoInfo
->
numOfTotalInterpo
+=
pInterpoInfo
->
numOfCurrentInterpo
;
return
outputRows
;
}
}
else
{
// if (pInterpoInfo->startTimestamp == currentTimestamp) {
if
(
*
prevValues
==
NULL
)
{
*
prevValues
=
calloc
(
1
,
pModel
->
rowSize
);
for
(
int
i
=
1
;
i
<
pModel
->
numOfCols
;
i
++
)
{
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
setNull
(
*
prevValues
+
offset
,
pSchema
->
type
,
pSchema
->
bytes
);
}
}
...
...
@@ -388,17 +379,16 @@ int32_t taosDoInterpoResult(SInterpolationInfo* pInterpoInfo, int16_t interpoTyp
// assign rows to dst buffer
int32_t
i
=
0
;
for
(
int32_t
tlen
=
0
;
i
<
pModel
->
numOfCols
-
numOfTags
;
++
i
)
{
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pModel
,
i
);
SSchema
*
pSchema
=
getColumnModelSchema
(
pModel
,
i
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
pInterpoInfo
->
order
,
bufSize
,
num
);
char
*
val1
=
getPos
(
data
[
i
]
->
data
,
pSchema
->
bytes
,
num
);
if
(
i
==
0
||
(
functionIDs
[
i
]
!=
TSDB_FUNC_COUNT
&&
!
isNull
(
srcData
[
i
]
+
pInterpoInfo
->
rowIdx
*
pSchema
->
bytes
,
pSchema
->
type
))
||
(
functionIDs
[
i
]
==
TSDB_FUNC_COUNT
&&
*
(
int64_t
*
)(
srcData
[
i
]
+
pInterpoInfo
->
rowIdx
*
pSchema
->
bytes
)
!=
0
))
{
assignVal
(
val1
,
srcData
[
i
]
+
pInterpoInfo
->
rowIdx
*
pSchema
->
bytes
,
pSchema
->
bytes
,
pSchema
->
type
);
memcpy
(
*
prevValues
+
tlen
,
srcData
[
i
]
+
pInterpoInfo
->
rowIdx
*
pSchema
->
bytes
,
pSchema
->
bytes
);
}
else
{
// i > 0 and isNULL, do interpolation
...
...
@@ -416,11 +406,11 @@ int32_t taosDoInterpoResult(SInterpolationInfo* pInterpoInfo, int16_t interpoTyp
/* set the tag value for final result */
setTagsValueInInterpolation
(
data
,
pTags
,
pModel
,
pInterpoInfo
->
order
,
pModel
->
numOfCols
-
numOfTags
,
bufSize
,
num
);
}
pInterpoInfo
->
startTimestamp
+=
(
nInterval
*
step
);
pInterpoInfo
->
rowIdx
+=
1
;
num
+=
1
;
pInterpoInfo
->
startTimestamp
+=
(
nInterval
*
step
);
pInterpoInfo
->
rowIdx
+=
1
;
num
+=
1
;
}
if
((
pInterpoInfo
->
rowIdx
>=
pInterpoInfo
->
numOfRawDataInRows
&&
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
))
||
(
pInterpoInfo
->
rowIdx
<
0
&&
!
INTERPOL_IS_ASC_INTERPOL
(
pInterpoInfo
))
||
num
>=
outputRows
)
{
...
...
src/util/src/tresultBuf.c
浏览文件 @
1a802566
...
...
@@ -7,8 +7,8 @@
#define DEFAULT_INTERN_BUF_SIZE 16384L
int32_t
create
ResultBuf
(
SQuery
ResultBuf
**
pResultBuf
,
int32_t
size
,
int32_t
rowSize
)
{
SQuery
ResultBuf
*
pResBuf
=
calloc
(
1
,
sizeof
(
SQuery
ResultBuf
));
int32_t
create
DiskbasedResultBuffer
(
SQueryDiskbased
ResultBuf
**
pResultBuf
,
int32_t
size
,
int32_t
rowSize
)
{
SQuery
DiskbasedResultBuf
*
pResBuf
=
calloc
(
1
,
sizeof
(
SQueryDiskbased
ResultBuf
));
pResBuf
->
numOfRowsPerPage
=
(
DEFAULT_INTERN_BUF_SIZE
-
sizeof
(
tFilePage
))
/
rowSize
;
pResBuf
->
numOfPages
=
size
;
...
...
@@ -50,17 +50,17 @@ int32_t createResultBuf(SQueryResultBuf** pResultBuf, int32_t size, int32_t rowS
return
TSDB_CODE_SUCCESS
;
}
tFilePage
*
getResultBufferPageById
(
SQueryResultBuf
*
pResultBuf
,
int32_t
id
)
{
tFilePage
*
getResultBufferPageById
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
id
)
{
assert
(
id
<
pResultBuf
->
numOfPages
&&
id
>=
0
);
return
(
tFilePage
*
)(
pResultBuf
->
pBuf
+
DEFAULT_INTERN_BUF_SIZE
*
id
);
}
int32_t
getNumOfResultBufGroupId
(
SQueryResultBuf
*
pResultBuf
)
{
return
taosNumElemsInHashTable
(
pResultBuf
->
idsTable
);
}
int32_t
getNumOfResultBufGroupId
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
)
{
return
taosNumElemsInHashTable
(
pResultBuf
->
idsTable
);
}
int32_t
getResBufSize
(
SQueryResultBuf
*
pResultBuf
)
{
return
pResultBuf
->
totalBufSize
;
}
int32_t
getResBufSize
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
)
{
return
pResultBuf
->
totalBufSize
;
}
static
int32_t
extendDiskFileSize
(
SQueryResultBuf
*
pResultBuf
,
int32_t
numOfPages
)
{
static
int32_t
extendDiskFileSize
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
numOfPages
)
{
assert
(
pResultBuf
->
numOfPages
*
DEFAULT_INTERN_BUF_SIZE
==
pResultBuf
->
totalBufSize
);
int32_t
ret
=
munmap
(
pResultBuf
->
pBuf
,
pResultBuf
->
totalBufSize
);
...
...
@@ -88,11 +88,11 @@ static int32_t extendDiskFileSize(SQueryResultBuf* pResultBuf, int32_t numOfPage
return
TSDB_CODE_SUCCESS
;
}
static
bool
noMoreAvailablePages
(
SQueryResultBuf
*
pResultBuf
)
{
static
bool
noMoreAvailablePages
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
)
{
return
(
pResultBuf
->
allocateId
==
pResultBuf
->
numOfPages
-
1
);
}
static
int32_t
getGroupIndex
(
SQueryResultBuf
*
pResultBuf
,
int32_t
groupId
)
{
static
int32_t
getGroupIndex
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
groupId
)
{
assert
(
pResultBuf
!=
NULL
);
char
*
p
=
taosGetDataFromHashTable
(
pResultBuf
->
idsTable
,
(
const
char
*
)
&
groupId
,
sizeof
(
int32_t
));
...
...
@@ -106,7 +106,7 @@ static int32_t getGroupIndex(SQueryResultBuf* pResultBuf, int32_t groupId) {
return
slot
;
}
static
int32_t
addNewGroupId
(
SQueryResultBuf
*
pResultBuf
,
int32_t
groupId
)
{
static
int32_t
addNewGroupId
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
groupId
)
{
int32_t
num
=
getNumOfResultBufGroupId
(
pResultBuf
);
// the num is the newest allocated group id slot
if
(
pResultBuf
->
numOfAllocGroupIds
<=
num
)
{
...
...
@@ -148,7 +148,7 @@ static int32_t doRegisterId(SIDList* pList, int32_t id) {
return
0
;
}
static
void
registerPageId
(
SQueryResultBuf
*
pResultBuf
,
int32_t
groupId
,
int32_t
pageId
)
{
static
void
registerPageId
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
groupId
,
int32_t
pageId
)
{
int32_t
slot
=
getGroupIndex
(
pResultBuf
,
groupId
);
if
(
slot
<
0
)
{
slot
=
addNewGroupId
(
pResultBuf
,
groupId
);
...
...
@@ -158,7 +158,7 @@ static void registerPageId(SQueryResultBuf* pResultBuf, int32_t groupId, int32_t
doRegisterId
(
pList
,
pageId
);
}
tFilePage
*
getNewDataBuf
(
SQueryResultBuf
*
pResultBuf
,
int32_t
groupId
,
int32_t
*
pageId
)
{
tFilePage
*
getNewDataBuf
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
groupId
,
int32_t
*
pageId
)
{
if
(
noMoreAvailablePages
(
pResultBuf
))
{
if
(
extendDiskFileSize
(
pResultBuf
,
pResultBuf
->
incStep
)
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
...
...
@@ -177,9 +177,9 @@ tFilePage* getNewDataBuf(SQueryResultBuf* pResultBuf, int32_t groupId, int32_t*
return
page
;
}
int32_t
getNumOfRowsPerPage
(
SQueryResultBuf
*
pResultBuf
)
{
return
pResultBuf
->
numOfRowsPerPage
;
}
int32_t
getNumOfRowsPerPage
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
)
{
return
pResultBuf
->
numOfRowsPerPage
;
}
SIDList
getDataBufPagesIdList
(
SQueryResultBuf
*
pResultBuf
,
int32_t
groupId
)
{
SIDList
getDataBufPagesIdList
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
,
int32_t
groupId
)
{
SIDList
list
=
{
0
};
int32_t
slot
=
getGroupIndex
(
pResultBuf
,
groupId
);
if
(
slot
<
0
)
{
...
...
@@ -189,7 +189,7 @@ SIDList getDataBufPagesIdList(SQueryResultBuf* pResultBuf, int32_t groupId) {
}
}
void
destroyResultBuf
(
SQueryResultBuf
*
pResultBuf
)
{
void
destroyResultBuf
(
SQuery
Diskbased
ResultBuf
*
pResultBuf
)
{
if
(
pResultBuf
==
NULL
)
{
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录