Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dgr6878
TDengine
提交
ce88438b
T
TDengine
项目概览
dgr6878
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
8
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,发现更多精彩内容 >>
提交
ce88438b
编写于
4月 02, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-32] refactor codes.
上级
6e907a23
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
166 addition
and
165 deletion
+166
-165
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+10
-10
src/dnode/src/dnodeRead.c
src/dnode/src/dnodeRead.c
+1
-0
src/query/inc/qast.h
src/query/inc/qast.h
+13
-20
src/query/inc/qsqlparser.h
src/query/inc/qsqlparser.h
+3
-3
src/query/src/qast.c
src/query/src/qast.c
+95
-101
src/query/src/qtokenizer.c
src/query/src/qtokenizer.c
+2
-2
src/query/src/queryExecutor.c
src/query/src/queryExecutor.c
+1
-2
src/query/src/queryUtil.c
src/query/src/queryUtil.c
+1
-0
src/vnode/tsdb/src/tsdbRead.c
src/vnode/tsdb/src/tsdbRead.c
+40
-27
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
ce88438b
...
...
@@ -117,7 +117,7 @@ static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo);
static
int32_t
doCheckForStream
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForQuery
(
SSqlObj
*
pSql
,
SQuerySQL
*
pQuerySql
,
int32_t
index
);
static
int32_t
tSQLBinaryExprCreateFromSqlExpr
(
t
SQLSyntax
Node
**
pExpr
,
tSQLExpr
*
pAst
,
int32_t
*
num
,
static
int32_t
tSQLBinaryExprCreateFromSqlExpr
(
t
Expr
Node
**
pExpr
,
tSQLExpr
*
pAst
,
int32_t
*
num
,
SColIndexEx
**
pColIndex
,
SSqlExprInfo
*
pExprInfo
);
/*
...
...
@@ -1208,7 +1208,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
SSqlBinaryExprInfo
*
pBinExprInfo
=
&
pFuncExpr
->
binExprInfo
;
t
SQLSyntax
Node
*
pNode
=
NULL
;
t
Expr
Node
*
pNode
=
NULL
;
SColIndexEx
*
pColIndex
=
NULL
;
int32_t
ret
=
tSQLBinaryExprCreateFromSqlExpr
(
&
pNode
,
pItem
->
pNode
,
&
pBinExprInfo
->
numOfCols
,
&
pColIndex
,
&
pQueryInfo
->
exprsInfo
);
...
...
@@ -5807,10 +5807,10 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return
TSDB_CODE_SUCCESS
;
// Does not build query message here
}
static
int32_t
tSQLBinaryExprCreateFromSqlExpr
(
t
SQLSyntax
Node
**
pExpr
,
tSQLExpr
*
pAst
,
int32_t
*
num
,
static
int32_t
tSQLBinaryExprCreateFromSqlExpr
(
t
Expr
Node
**
pExpr
,
tSQLExpr
*
pAst
,
int32_t
*
num
,
SColIndexEx
**
pColIndex
,
SSqlExprInfo
*
pExprInfo
)
{
t
SQLSyntax
Node
*
pLeft
=
NULL
;
t
SQLSyntax
Node
*
pRight
=
NULL
;
t
Expr
Node
*
pLeft
=
NULL
;
t
Expr
Node
*
pRight
=
NULL
;
if
(
pAst
->
pLeft
!=
NULL
)
{
int32_t
ret
=
tSQLBinaryExprCreateFromSqlExpr
(
&
pLeft
,
pAst
->
pLeft
,
num
,
pColIndex
,
pExprInfo
);
...
...
@@ -5828,14 +5828,14 @@ static int32_t tSQLBinaryExprCreateFromSqlExpr(tSQLSyntaxNode **pExpr, tSQLExpr*
if
(
pAst
->
pLeft
==
NULL
)
{
if
(
pAst
->
nSQLOptr
>=
TK_TINYINT
&&
pAst
->
nSQLOptr
<=
TK_DOUBLE
)
{
*
pExpr
=
calloc
(
1
,
sizeof
(
t
SQLSyntax
Node
)
+
sizeof
(
tVariant
));
*
pExpr
=
calloc
(
1
,
sizeof
(
t
Expr
Node
)
+
sizeof
(
tVariant
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_VALUE
;
(
*
pExpr
)
->
pVal
=
(
tVariant
*
)
((
char
*
)(
*
pExpr
)
+
sizeof
(
t
SQLSyntax
Node
));
(
*
pExpr
)
->
pVal
=
(
tVariant
*
)
((
char
*
)(
*
pExpr
)
+
sizeof
(
t
Expr
Node
));
tVariantAssign
((
*
pExpr
)
->
pVal
,
&
pAst
->
val
);
}
else
if
(
pAst
->
nSQLOptr
>=
TK_COUNT
&&
pAst
->
nSQLOptr
<=
TK_AVG_IRATE
)
{
*
pExpr
=
calloc
(
1
,
sizeof
(
t
SQLSyntax
Node
)
+
sizeof
(
SSchemaEx
));
*
pExpr
=
calloc
(
1
,
sizeof
(
t
Expr
Node
)
+
sizeof
(
SSchemaEx
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_COL
;
(
*
pExpr
)
->
pSchema
=
(
SSchema
*
)((
char
*
)(
*
pExpr
)
+
sizeof
(
t
SQLSyntax
Node
));
(
*
pExpr
)
->
pSchema
=
(
SSchema
*
)((
char
*
)(
*
pExpr
)
+
sizeof
(
t
Expr
Node
));
strncpy
((
*
pExpr
)
->
pSchema
->
name
,
pAst
->
operand
.
z
,
pAst
->
operand
.
n
);
// set the input column data byte and type.
...
...
@@ -5855,7 +5855,7 @@ static int32_t tSQLBinaryExprCreateFromSqlExpr(tSQLSyntaxNode **pExpr, tSQLExpr*
strncpy
((
*
pColIndex
)[(
*
num
)
-
1
].
name
,
pAst
->
operand
.
z
,
pAst
->
operand
.
n
);
}
else
{
*
pExpr
=
(
t
SQLSyntaxNode
*
)
calloc
(
1
,
sizeof
(
tSQLSyntax
Node
));
*
pExpr
=
(
t
ExprNode
*
)
calloc
(
1
,
sizeof
(
tExpr
Node
));
(
*
pExpr
)
->
_node
.
hasPK
=
false
;
(
*
pExpr
)
->
_node
.
pLeft
=
pLeft
;
(
*
pExpr
)
->
_node
.
pRight
=
pRight
;
...
...
src/dnode/src/dnodeRead.c
浏览文件 @
ce88438b
...
...
@@ -286,6 +286,7 @@ static void dnodeProcessRetrieveMsg(void *pVnode, SReadMsg *pMsg) {
dnodeContinueExecuteQuery
(
pVnode
,
pQInfo
,
pMsg
);
}
else
{
// no further execution invoked, release the ref to vnode
dnodeProcessReadResult
(
pVnode
,
pMsg
);
dnodeReleaseVnode
(
pVnode
);
}
}
...
...
src/query/inc/qast.h
浏览文件 @
ce88438b
...
...
@@ -27,14 +27,14 @@ extern "C" {
#include "taosdef.h"
#include "tvariant.h"
struct
t
SQLSyntax
Node
;
struct
t
Expr
Node
;
struct
SSchema
;
struct
tSkipList
;
struct
tSkipListNode
;
enum
{
TSQL_NODE_EXPR
=
0x1
,
TSQL_NODE_COL
=
0x2
,
TSQL_NODE_EXPR
=
0x1
,
TSQL_NODE_COL
=
0x2
,
TSQL_NODE_VALUE
=
0x4
,
};
...
...
@@ -60,7 +60,7 @@ typedef struct SBinaryFilterSupp {
void
*
pExtInfo
;
}
SBinaryFilterSupp
;
typedef
struct
t
SQLSyntax
Node
{
typedef
struct
t
Expr
Node
{
uint8_t
nodeType
;
union
{
struct
{
...
...
@@ -68,33 +68,26 @@ typedef struct tSQLSyntaxNode {
uint8_t
hasPK
;
// 0: do not contain primary filter, 1: contain
void
*
info
;
// support filter operation on this expression only available for leaf node
struct
t
SQLSyntax
Node
*
pLeft
;
// left child pointer
struct
t
SQLSyntax
Node
*
pRight
;
// right child pointer
struct
t
Expr
Node
*
pLeft
;
// left child pointer
struct
t
Expr
Node
*
pRight
;
// right child pointer
}
_node
;
struct
SSchema
*
pSchema
;
tVariant
*
pVal
;
};
}
t
SQLSyntax
Node
;
}
t
Expr
Node
;
void
tSQLBinaryExprFromString
(
tExprNode
**
pExpr
,
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
src
,
int32_t
len
);
typedef
struct
tQueryResultset
{
void
**
pRes
;
int64_t
num
;
}
tQueryResultset
;
void
tSQLBinaryExprToString
(
tExprNode
*
pExpr
,
char
*
dst
,
int32_t
*
len
);
void
tSQLBinaryExpr
FromString
(
tSQLSyntaxNode
**
pExpr
,
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
src
,
int32_t
len
);
void
tSQLBinaryExpr
Destroy
(
tExprNode
**
pExprs
,
void
(
*
fp
)(
void
*
)
);
void
tSQLBinaryExprT
oString
(
tSQLSyntaxNode
*
pExpr
,
char
*
dst
,
int32_t
*
len
);
void
tSQLBinaryExprT
raverse
(
tExprNode
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
);
void
tSQLBinaryExprDestroy
(
tSQLSyntaxNode
**
pExprs
,
void
(
*
fp
)(
void
*
));
void
tSQLBinaryExprTraverse
(
tSQLSyntaxNode
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
);
void
tSQLBinaryExprCalcTraverse
(
tSQLSyntaxNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
void
tSQLBinaryExprCalcTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
char
*
(
*
cb
)(
void
*
,
char
*
,
int32_t
));
void
tSQLBinaryExprTrv
(
tSQLSyntaxNode
*
pExprs
,
int32_t
*
val
,
int16_t
*
ids
);
void
tQueryResultClean
(
tQueryResultset
*
pRes
);
void
tSQLBinaryExprTrv
(
tExprNode
*
pExprs
,
int32_t
*
val
,
int16_t
*
ids
);
uint8_t
getBinaryExprOptr
(
SSQLToken
*
pToken
);
...
...
src/query/inc/qsqlparser.h
浏览文件 @
ce88438b
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_Q
ASTDEF
_H
#define TDENGINE_Q
ASTDEF
_H
#ifndef TDENGINE_Q
SQLPARSER
_H
#define TDENGINE_Q
SQLPARSER
_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -329,4 +329,4 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pSql);
}
#endif
#endif // TDENGINE_Q
ASTDEF
_H
#endif // TDENGINE_Q
SQLPARSER
_H
src/query/src/qast.c
浏览文件 @
ce88438b
...
...
@@ -13,11 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qast.h"
#include <tarray.h>
#include <tskiplist.h>
#include "../../client/inc/tschemautil.h"
#include "os.h"
#include "tutil.h"
#include "qsqlparser.h"
#include "qsyntaxtreefunction.h"
#include "taosdef.h"
...
...
@@ -26,7 +25,12 @@
#include "tsqlfunction.h"
#include "tstoken.h"
#include "ttokendef.h"
#include "tutil.h"
#include "../../client/inc/tschemautil.h"
#include "qast.h"
#include "tarray.h"
#include "tskiplist.h"
/*
*
...
...
@@ -39,22 +43,20 @@
* ver 0.3, pipeline filter in the form of: (a+2)/9 > 14
*
*/
static
tExprNode
*
tExprNodeCreate
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
SSQLToken
*
pToken
);
static
void
tExprNodeDestroy
(
tExprNode
*
pNode
,
void
(
*
fp
)(
void
*
));
static
t
SQLSyntaxNode
*
tSQLSyntaxNodeCreate
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
SSQLToken
*
pToken
);
static
void
tSQLSyntaxNodeDestroy
(
tSQLSyntaxNode
*
pNode
,
void
(
*
fp
)(
void
*
)
);
static
t
ExprNode
*
createSyntaxTree
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
str
,
int32_t
*
i
);
static
void
destroySyntaxTree
(
tExprNode
*
);
static
tSQLSyntaxNode
*
createSyntaxTree
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
str
,
int32_t
*
i
);
static
void
destroySyntaxTree
(
tSQLSyntaxNode
*
);
static
uint8_t
isQueryOnPrimaryKey
(
const
char
*
primaryColumnName
,
const
tSQLSyntaxNode
*
pLeft
,
const
tSQLSyntaxNode
*
pRight
);
static
uint8_t
isQueryOnPrimaryKey
(
const
char
*
primaryColumnName
,
const
tExprNode
*
pLeft
,
const
tExprNode
*
pRight
);
/*
* Check the filter value type on the right hand side based on the column id on the left hand side,
* the filter value type must be identical to field type for relational operation
* As for binary arithmetic operation, it is not necessary to do so.
*/
static
void
reviseBinaryExprIfNecessary
(
t
SQLSyntaxNode
**
pLeft
,
tSQLSyntax
Node
**
pRight
,
uint8_t
*
optr
)
{
static
void
reviseBinaryExprIfNecessary
(
t
ExprNode
**
pLeft
,
tExpr
Node
**
pRight
,
uint8_t
*
optr
)
{
if
(
*
optr
>=
TSDB_RELATION_LESS
&&
*
optr
<=
TSDB_RELATION_LIKE
)
{
// make sure that the type of data on both sides of relational comparision are identical
if
((
*
pLeft
)
->
nodeType
==
TSQL_NODE_VALUE
)
{
...
...
@@ -79,7 +81,7 @@ static void reviseBinaryExprIfNecessary(tSQLSyntaxNode **pLeft, tSQLSyntaxNode *
*/
if
((
*
pLeft
)
->
nodeType
==
TSQL_NODE_VALUE
&&
(
*
pRight
)
->
nodeType
==
TSQL_NODE_COL
)
{
if
(
*
optr
>=
TSDB_RELATION_LARGE
&&
*
optr
<=
TSDB_RELATION_LARGE_EQUAL
&&
*
optr
!=
TSDB_RELATION_EQUAL
)
{
SWAP
(
*
pLeft
,
*
pRight
,
t
SQLSyntax
Node
*
);
SWAP
(
*
pLeft
,
*
pRight
,
t
Expr
Node
*
);
}
switch
(
*
optr
)
{
...
...
@@ -101,15 +103,15 @@ static void reviseBinaryExprIfNecessary(tSQLSyntaxNode **pLeft, tSQLSyntaxNode *
}
}
static
t
SQLSyntaxNode
*
tSQLSyntax
NodeCreate
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
SSQLToken
*
pToken
)
{
static
t
ExprNode
*
tExpr
NodeCreate
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
SSQLToken
*
pToken
)
{
/* if the token is not a value, return false */
if
(
pToken
->
type
==
TK_RP
||
(
pToken
->
type
!=
TK_INTEGER
&&
pToken
->
type
!=
TK_FLOAT
&&
pToken
->
type
!=
TK_ID
&&
pToken
->
type
!=
TK_TBNAME
&&
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_BOOL
))
{
return
NULL
;
}
size_t
nodeSize
=
sizeof
(
t
SQLSyntax
Node
);
t
SQLSyntax
Node
*
pNode
=
NULL
;
size_t
nodeSize
=
sizeof
(
t
Expr
Node
);
t
Expr
Node
*
pNode
=
NULL
;
if
(
pToken
->
type
==
TK_ID
||
pToken
->
type
==
TK_TBNAME
)
{
int32_t
i
=
0
;
...
...
@@ -130,7 +132,7 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
nodeSize
+=
sizeof
(
SSchema
);
pNode
=
calloc
(
1
,
nodeSize
);
pNode
->
pSchema
=
(
struct
SSchema
*
)((
char
*
)
pNode
+
sizeof
(
t
SQLSyntax
Node
));
pNode
->
pSchema
=
(
struct
SSchema
*
)((
char
*
)
pNode
+
sizeof
(
t
Expr
Node
));
pNode
->
nodeType
=
TSQL_NODE_COL
;
if
(
pToken
->
type
==
TK_ID
)
{
...
...
@@ -145,7 +147,7 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
}
else
{
nodeSize
+=
sizeof
(
tVariant
);
pNode
=
calloc
(
1
,
nodeSize
);
pNode
->
pVal
=
(
tVariant
*
)((
char
*
)
pNode
+
sizeof
(
t
SQLSyntax
Node
));
pNode
->
pVal
=
(
tVariant
*
)((
char
*
)
pNode
+
sizeof
(
t
Expr
Node
));
toTSDBType
(
pToken
->
type
);
tVariantCreate
(
pNode
->
pVal
,
pToken
);
...
...
@@ -191,21 +193,21 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken) {
}
// previous generated expr is reduced as the left child
static
t
SQLSyntaxNode
*
parseRemainStr
(
char
*
pstr
,
tSQLSyntax
Node
*
pExpr
,
SSchema
*
pSchema
,
int32_t
optr
,
static
t
ExprNode
*
parseRemainStr
(
char
*
pstr
,
tExpr
Node
*
pExpr
,
SSchema
*
pSchema
,
int32_t
optr
,
int32_t
numOfCols
,
int32_t
*
i
)
{
// set the previous generated node as the left child of new root
pExpr
->
nodeType
=
TSQL_NODE_EXPR
;
// remain is the right child
t
SQLSyntax
Node
*
pRight
=
createSyntaxTree
(
pSchema
,
numOfCols
,
pstr
,
i
);
t
Expr
Node
*
pRight
=
createSyntaxTree
(
pSchema
,
numOfCols
,
pstr
,
i
);
if
(
pRight
==
NULL
||
(
pRight
->
nodeType
==
TSQL_NODE_COL
&&
pExpr
->
nodeType
!=
TSQL_NODE_VALUE
)
||
(
pExpr
->
nodeType
==
TSQL_NODE_VALUE
&&
pRight
->
nodeType
!=
TSQL_NODE_COL
))
{
t
SQLSyntax
NodeDestroy
(
pExpr
,
NULL
);
t
SQLSyntax
NodeDestroy
(
pRight
,
NULL
);
t
Expr
NodeDestroy
(
pExpr
,
NULL
);
t
Expr
NodeDestroy
(
pRight
,
NULL
);
return
NULL
;
}
t
SQLSyntaxNode
*
pNewExpr
=
(
tSQLSyntaxNode
*
)
calloc
(
1
,
sizeof
(
tSQLSyntax
Node
));
t
ExprNode
*
pNewExpr
=
(
tExprNode
*
)
calloc
(
1
,
sizeof
(
tExpr
Node
));
uint8_t
k
=
optr
;
reviseBinaryExprIfNecessary
(
&
pExpr
,
&
pRight
,
&
k
);
pNewExpr
->
_node
.
pLeft
=
pExpr
;
...
...
@@ -218,7 +220,7 @@ static tSQLSyntaxNode *parseRemainStr(char *pstr, tSQLSyntaxNode *pExpr, SSchema
return
pNewExpr
;
}
uint8_t
isQueryOnPrimaryKey
(
const
char
*
primaryColumnName
,
const
t
SQLSyntaxNode
*
pLeft
,
const
tSQLSyntax
Node
*
pRight
)
{
uint8_t
isQueryOnPrimaryKey
(
const
char
*
primaryColumnName
,
const
t
ExprNode
*
pLeft
,
const
tExpr
Node
*
pRight
)
{
if
(
pLeft
->
nodeType
==
TSQL_NODE_COL
)
{
// if left node is the primary column,return true
return
(
strcmp
(
primaryColumnName
,
pLeft
->
pSchema
->
name
)
==
0
)
?
1
:
0
;
...
...
@@ -231,20 +233,20 @@ uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode
}
}
static
t
SQLSyntax
Node
*
createSyntaxTree
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
str
,
int32_t
*
i
)
{
static
t
Expr
Node
*
createSyntaxTree
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
str
,
int32_t
*
i
)
{
SSQLToken
t0
=
tStrGetToken
(
str
,
i
,
false
,
0
,
NULL
);
if
(
t0
.
n
==
0
)
{
return
NULL
;
}
t
SQLSyntax
Node
*
pLeft
=
NULL
;
t
Expr
Node
*
pLeft
=
NULL
;
if
(
t0
.
type
==
TK_LP
)
{
// start new left child branch
pLeft
=
createSyntaxTree
(
pSchema
,
numOfCols
,
str
,
i
);
}
else
{
if
(
t0
.
type
==
TK_RP
)
{
return
NULL
;
}
pLeft
=
t
SQLSyntax
NodeCreate
(
pSchema
,
numOfCols
,
&
t0
);
pLeft
=
t
Expr
NodeCreate
(
pSchema
,
numOfCols
,
&
t0
);
}
if
(
pLeft
==
NULL
)
{
...
...
@@ -254,7 +256,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
t0
=
tStrGetToken
(
str
,
i
,
false
,
0
,
NULL
);
if
(
t0
.
n
==
0
||
t0
.
type
==
TK_RP
)
{
if
(
pLeft
->
nodeType
!=
TSQL_NODE_EXPR
)
{
// if left is not the expr, it is not a legal expr
t
SQLSyntax
NodeDestroy
(
pLeft
,
NULL
);
t
Expr
NodeDestroy
(
pLeft
,
NULL
);
return
NULL
;
}
...
...
@@ -265,12 +267,12 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
uint8_t
optr
=
getBinaryExprOptr
(
&
t0
);
if
(
optr
==
0
)
{
pError
(
"not support binary operator:%d"
,
t0
.
type
);
t
SQLSyntax
NodeDestroy
(
pLeft
,
NULL
);
t
Expr
NodeDestroy
(
pLeft
,
NULL
);
return
NULL
;
}
assert
(
pLeft
!=
NULL
);
t
SQLSyntax
Node
*
pRight
=
NULL
;
t
Expr
Node
*
pRight
=
NULL
;
if
(
t0
.
type
==
TK_AND
||
t0
.
type
==
TK_OR
||
t0
.
type
==
TK_LP
)
{
pRight
=
createSyntaxTree
(
pSchema
,
numOfCols
,
str
,
i
);
...
...
@@ -283,51 +285,51 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
*/
t0
=
tStrGetToken
(
str
,
i
,
true
,
0
,
NULL
);
if
(
t0
.
n
==
0
)
{
t
SQLSyntax
NodeDestroy
(
pLeft
,
NULL
);
// illegal expression
t
Expr
NodeDestroy
(
pLeft
,
NULL
);
// illegal expression
return
NULL
;
}
if
(
t0
.
type
==
TK_LP
)
{
pRight
=
createSyntaxTree
(
pSchema
,
numOfCols
,
str
,
i
);
}
else
{
pRight
=
t
SQLSyntax
NodeCreate
(
pSchema
,
numOfCols
,
&
t0
);
pRight
=
t
Expr
NodeCreate
(
pSchema
,
numOfCols
,
&
t0
);
}
}
if
(
pRight
==
NULL
)
{
t
SQLSyntax
NodeDestroy
(
pLeft
,
NULL
);
t
Expr
NodeDestroy
(
pLeft
,
NULL
);
return
NULL
;
}
/* create binary expr as the child of new parent node */
t
SQLSyntaxNode
*
pBinExpr
=
(
tSQLSyntaxNode
*
)
calloc
(
1
,
sizeof
(
tSQLSyntax
Node
));
t
ExprNode
*
pExpr
=
(
tExprNode
*
)
calloc
(
1
,
sizeof
(
tExpr
Node
));
reviseBinaryExprIfNecessary
(
&
pLeft
,
&
pRight
,
&
optr
);
p
Bin
Expr
->
_node
.
hasPK
=
isQueryOnPrimaryKey
(
pSchema
[
0
].
name
,
pLeft
,
pRight
);
p
Bin
Expr
->
_node
.
pLeft
=
pLeft
;
p
Bin
Expr
->
_node
.
pRight
=
pRight
;
p
Bin
Expr
->
_node
.
optr
=
optr
;
pExpr
->
_node
.
hasPK
=
isQueryOnPrimaryKey
(
pSchema
[
0
].
name
,
pLeft
,
pRight
);
pExpr
->
_node
.
pLeft
=
pLeft
;
pExpr
->
_node
.
pRight
=
pRight
;
pExpr
->
_node
.
optr
=
optr
;
t0
=
tStrGetToken
(
str
,
i
,
true
,
0
,
NULL
);
if
(
t0
.
n
==
0
||
t0
.
type
==
TK_RP
)
{
tSQLSyntaxNode
*
pn
=
malloc
(
sizeof
(
tSQLSyntaxNode
));
pBinExpr
->
nodeType
=
TSQL_NODE_EXPR
;
return
pBinExpr
;
pExpr
->
nodeType
=
TSQL_NODE_EXPR
;
return
pExpr
;
}
else
{
uint8_t
localOptr
=
getBinaryExprOptr
(
&
t0
);
if
(
localOptr
==
0
)
{
pError
(
"not support binary operator:%d"
,
t0
.
type
);
free
(
p
Bin
Expr
);
free
(
pExpr
);
return
NULL
;
}
return
parseRemainStr
(
str
,
p
Bin
Expr
,
pSchema
,
localOptr
,
numOfCols
,
i
);
return
parseRemainStr
(
str
,
pExpr
,
pSchema
,
localOptr
,
numOfCols
,
i
);
}
}
void
tSQLBinaryExprFromString
(
t
SQLSyntax
Node
**
pExpr
,
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
src
,
int32_t
len
)
{
void
tSQLBinaryExprFromString
(
t
Expr
Node
**
pExpr
,
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
src
,
int32_t
len
)
{
*
pExpr
=
NULL
;
if
(
len
<=
0
||
src
==
NULL
||
pSchema
==
NULL
||
numOfCols
<=
0
)
{
return
;
}
...
...
@@ -340,7 +342,7 @@ void tSQLBinaryExprFromString(tSQLSyntaxNode **pExpr, SSchema *pSchema, int32_t
}
}
int32_t
tSQLBinaryExprToStringImpl
(
t
SQLSyntax
Node
*
pNode
,
char
*
dst
,
uint8_t
type
)
{
int32_t
tSQLBinaryExprToStringImpl
(
t
Expr
Node
*
pNode
,
char
*
dst
,
uint8_t
type
)
{
int32_t
len
=
0
;
if
(
type
==
TSQL_NODE_EXPR
)
{
*
dst
=
'('
;
...
...
@@ -406,7 +408,7 @@ static char *tSQLOptrToString(uint8_t optr, char *dst) {
return
dst
;
}
void
tSQLBinaryExprToString
(
t
SQLSyntax
Node
*
pExpr
,
char
*
dst
,
int32_t
*
len
)
{
void
tSQLBinaryExprToString
(
t
Expr
Node
*
pExpr
,
char
*
dst
,
int32_t
*
len
)
{
if
(
pExpr
==
NULL
)
{
*
dst
=
0
;
*
len
=
0
;
...
...
@@ -423,9 +425,9 @@ void tSQLBinaryExprToString(tSQLSyntaxNode *pExpr, char *dst, int32_t *len) {
*
len
+=
tSQLBinaryExprToStringImpl
(
pExpr
->
_node
.
pRight
,
start
,
pExpr
->
_node
.
pRight
->
nodeType
);
}
static
void
UNUSED_FUNC
destroySyntaxTree
(
t
SQLSyntaxNode
*
pNode
)
{
tSQLSyntax
NodeDestroy
(
pNode
,
NULL
);
}
static
void
UNUSED_FUNC
destroySyntaxTree
(
t
ExprNode
*
pNode
)
{
tExpr
NodeDestroy
(
pNode
,
NULL
);
}
static
void
t
SQLSyntaxNodeDestroy
(
tSQLSyntax
Node
*
pNode
,
void
(
*
fp
)(
void
*
))
{
static
void
t
ExprNodeDestroy
(
tExpr
Node
*
pNode
,
void
(
*
fp
)(
void
*
))
{
if
(
pNode
==
NULL
)
{
return
;
}
...
...
@@ -439,13 +441,13 @@ static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *)) {
free
(
pNode
);
}
void
tSQLBinaryExprDestroy
(
t
SQLSyntax
Node
**
pExpr
,
void
(
*
fp
)(
void
*
))
{
void
tSQLBinaryExprDestroy
(
t
Expr
Node
**
pExpr
,
void
(
*
fp
)(
void
*
))
{
if
(
*
pExpr
==
NULL
)
{
return
;
}
t
SQLSyntax
NodeDestroy
((
*
pExpr
)
->
_node
.
pLeft
,
fp
);
t
SQLSyntax
NodeDestroy
((
*
pExpr
)
->
_node
.
pRight
,
fp
);
t
Expr
NodeDestroy
((
*
pExpr
)
->
_node
.
pLeft
,
fp
);
t
Expr
NodeDestroy
((
*
pExpr
)
->
_node
.
pRight
,
fp
);
if
(
fp
!=
NULL
)
{
fp
((
*
pExpr
)
->
_node
.
info
);
...
...
@@ -559,7 +561,7 @@ void tSQLBinaryExprDestroy(tSQLSyntaxNode **pExpr, void (*fp)(void *)) {
// DEFAULT_COMP(p1, p2);
//}
int32_t
merge
(
tQueryResultset
*
pLeft
,
tQueryResultset
*
pRight
,
tQueryResultset
*
pFinalRes
)
{
int32_t
merge
(
SArray
*
pLeft
,
SArray
*
pRight
,
SArray
*
pFinalRes
)
{
// assert(pFinalRes->pRes == 0);
//
// pFinalRes->pRes = calloc((size_t)(pLeft->num + pRight->num), POINTER_BYTES);
...
...
@@ -600,7 +602,7 @@ int32_t merge(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *
return
0
;
}
int32_t
intersect
(
tQueryResultset
*
pLeft
,
tQueryResultset
*
pRight
,
tQueryResultset
*
pFinalRes
)
{
int32_t
intersect
(
SArray
*
pLeft
,
SArray
*
pRight
,
SArray
*
pFinalRes
)
{
// int64_t num = MIN(pLeft->num, pRight->num);
//
// assert(pFinalRes->pRes == 0);
...
...
@@ -638,25 +640,26 @@ int32_t intersect(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResults
/*
* traverse the result and apply the function to each item to check if the item is qualified or not
*/
static
UNUSED_FUNC
void
tSQLListTraverseOnResult
(
struct
tSQLSyntaxNode
*
pExpr
,
__result_filter_fn_t
fp
,
tQueryResultset
*
pResult
)
{
assert
(
pExpr
->
_node
.
pLeft
->
nodeType
==
TSQL_NODE_COL
&&
pExpr
->
_node
.
pRight
->
nodeType
==
TSQL_NODE_VALUE
);
// brutal force scan the result list and check for each item in the list
int64_t
num
=
pResult
->
num
;
for
(
int32_t
i
=
0
,
j
=
0
;
i
<
pResult
->
num
;
++
i
)
{
if
(
fp
==
NULL
||
(
fp
(
pResult
->
pRes
[
i
],
pExpr
->
_node
.
info
)
==
true
))
{
pResult
->
pRes
[
j
++
]
=
pResult
->
pRes
[
i
];
}
else
{
num
--
;
}
}
pResult
->
num
=
num
;
static
UNUSED_FUNC
void
tSQLListTraverseOnResult
(
struct
tExprNode
*
pExpr
,
__result_filter_fn_t
fp
,
SArray
*
pResult
)
{
// assert(pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_VALUE);
//
// // brutal force scan the result list and check for each item in the list
// int64_t num = pResult->num;
// for (int32_t i = 0, j = 0; i < pResult->num; ++i) {
// if (fp == NULL || (fp(pResult->pRes[i], pExpr->_node.info) == true)) {
// pResult->pRes[j++] = pResult->pRes[i];
// } else {
// num--;
// }
// }
//
// pResult->num = num;
assert
(
0
);
}
static
bool
filterItem
(
t
SQLSyntax
Node
*
pExpr
,
const
void
*
pItem
,
SBinaryFilterSupp
*
param
)
{
t
SQLSyntax
Node
*
pLeft
=
pExpr
->
_node
.
pLeft
;
t
SQLSyntax
Node
*
pRight
=
pExpr
->
_node
.
pRight
;
static
bool
filterItem
(
t
Expr
Node
*
pExpr
,
const
void
*
pItem
,
SBinaryFilterSupp
*
param
)
{
t
Expr
Node
*
pLeft
=
pExpr
->
_node
.
pLeft
;
t
Expr
Node
*
pRight
=
pExpr
->
_node
.
pRight
;
/*
* non-leaf nodes, recursively traverse the syntax tree in the post-root order
...
...
@@ -695,7 +698,7 @@ static bool filterItem(tSQLSyntaxNode *pExpr, const void *pItem, SBinaryFilterSu
* @param pSchema tag schemas
* @param fp filter callback function
*/
static
void
tSQLBinaryTraverseOnResult
(
t
SQLSyntax
Node
*
pExpr
,
SArray
*
pResult
,
SBinaryFilterSupp
*
param
)
{
static
void
tSQLBinaryTraverseOnResult
(
t
Expr
Node
*
pExpr
,
SArray
*
pResult
,
SBinaryFilterSupp
*
param
)
{
size_t
size
=
taosArrayGetSize
(
pResult
);
SArray
*
array
=
taosArrayInit
(
size
,
POINTER_BYTES
);
...
...
@@ -710,7 +713,7 @@ static void tSQLBinaryTraverseOnResult(tSQLSyntaxNode *pExpr, SArray *pResult, S
taosArrayCopy
(
pResult
,
array
);
}
static
void
tSQLBinaryTraverseOnSkipList
(
t
SQLSyntax
Node
*
pExpr
,
SArray
*
pResult
,
SSkipList
*
pSkipList
,
static
void
tSQLBinaryTraverseOnSkipList
(
t
Expr
Node
*
pExpr
,
SArray
*
pResult
,
SSkipList
*
pSkipList
,
SBinaryFilterSupp
*
param
)
{
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
pSkipList
);
...
...
@@ -724,13 +727,13 @@ static void tSQLBinaryTraverseOnSkipList(tSQLSyntaxNode *pExpr, SArray *pResult,
}
// post-root order traverse syntax tree
void
tSQLBinaryExprTraverse
(
t
SQLSyntax
Node
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
)
{
void
tSQLBinaryExprTraverse
(
t
Expr
Node
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
)
{
if
(
pExpr
==
NULL
)
{
return
;
}
t
SQLSyntax
Node
*
pLeft
=
pExpr
->
_node
.
pLeft
;
t
SQLSyntax
Node
*
pRight
=
pExpr
->
_node
.
pRight
;
t
Expr
Node
*
pLeft
=
pExpr
->
_node
.
pLeft
;
t
Expr
Node
*
pRight
=
pExpr
->
_node
.
pRight
;
// recursive traverse left child branch
if
(
pLeft
->
nodeType
==
TSQL_NODE_EXPR
||
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
...
...
@@ -751,22 +754,22 @@ void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray
assert
(
taosArrayGetSize
(
result
)
==
0
);
tSQLBinaryTraverseOnSkipList
(
pExpr
,
result
,
pSkipList
,
param
);
}
else
if
(
weight
==
2
||
(
weight
==
1
&&
pExpr
->
_node
.
optr
==
TSDB_RELATION_OR
))
{
tQueryResultset
rLeft
=
{
0
}
;
tQueryResultset
rRight
=
{
0
}
;
SArray
*
rLeft
=
taosArrayInit
(
10
,
POINTER_BYTES
)
;
SArray
*
rRight
=
taosArrayInit
(
10
,
POINTER_BYTES
)
;
tSQLBinaryExprTraverse
(
pLeft
,
pSkipList
,
&
rLeft
,
param
);
tSQLBinaryExprTraverse
(
pRight
,
pSkipList
,
&
rRight
,
param
);
tSQLBinaryExprTraverse
(
pLeft
,
pSkipList
,
rLeft
,
param
);
tSQLBinaryExprTraverse
(
pRight
,
pSkipList
,
rRight
,
param
);
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_AND
)
{
// CROSS
intersect
(
&
rLeft
,
&
rRight
,
result
);
intersect
(
rLeft
,
rRight
,
result
);
}
else
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_OR
)
{
// or
merge
(
&
rLeft
,
&
rRight
,
result
);
merge
(
rLeft
,
rRight
,
result
);
}
else
{
assert
(
false
);
}
free
(
rLeft
.
pRes
);
free
(
rRight
.
pRes
);
taosArrayDestroy
(
rLeft
);
taosArrayDestroy
(
rRight
);
}
else
{
/*
* (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here
...
...
@@ -776,8 +779,8 @@ void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray
*/
assert
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_AND
);
t
SQLSyntax
Node
*
pFirst
=
NULL
;
t
SQLSyntax
Node
*
pSecond
=
NULL
;
t
Expr
Node
*
pFirst
=
NULL
;
t
Expr
Node
*
pSecond
=
NULL
;
if
(
pLeft
->
_node
.
hasPK
==
1
)
{
pFirst
=
pLeft
;
pSecond
=
pRight
;
...
...
@@ -810,14 +813,14 @@ void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray
}
}
void
tSQLBinaryExprCalcTraverse
(
t
SQLSyntax
Node
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
void
tSQLBinaryExprCalcTraverse
(
t
Expr
Node
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
char
*
(
*
getSourceDataBlock
)(
void
*
,
char
*
,
int32_t
))
{
if
(
pExprs
==
NULL
)
{
return
;
}
t
SQLSyntax
Node
*
pLeft
=
pExprs
->
_node
.
pLeft
;
t
SQLSyntax
Node
*
pRight
=
pExprs
->
_node
.
pRight
;
t
Expr
Node
*
pLeft
=
pExprs
->
_node
.
pLeft
;
t
Expr
Node
*
pRight
=
pExprs
->
_node
.
pRight
;
/* the left output has result from the left child syntax tree */
char
*
pLeftOutput
=
(
char
*
)
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
...
...
@@ -890,13 +893,13 @@ void tSQLBinaryExprCalcTraverse(tSQLSyntaxNode *pExprs, int32_t numOfRows, char
free
(
pRightOutput
);
}
void
tSQLBinaryExprTrv
(
t
SQLSyntax
Node
*
pExprs
,
int32_t
*
val
,
int16_t
*
ids
)
{
void
tSQLBinaryExprTrv
(
t
Expr
Node
*
pExprs
,
int32_t
*
val
,
int16_t
*
ids
)
{
if
(
pExprs
==
NULL
)
{
return
;
}
t
SQLSyntax
Node
*
pLeft
=
pExprs
->
_node
.
pLeft
;
t
SQLSyntax
Node
*
pRight
=
pExprs
->
_node
.
pRight
;
t
Expr
Node
*
pLeft
=
pExprs
->
_node
.
pLeft
;
t
Expr
Node
*
pRight
=
pExprs
->
_node
.
pRight
;
// recursive traverse left child branch
if
(
pLeft
->
nodeType
==
TSQL_NODE_EXPR
)
{
...
...
@@ -913,12 +916,3 @@ void tSQLBinaryExprTrv(tSQLSyntaxNode *pExprs, int32_t *val, int16_t *ids) {
(
*
val
)
+=
1
;
}
}
void
tQueryResultClean
(
tQueryResultset
*
pRes
)
{
if
(
pRes
==
NULL
)
{
return
;
}
tfree
(
pRes
->
pRes
);
pRes
->
num
=
0
;
}
src/query/src/qtokenizer.c
浏览文件 @
ce88438b
...
...
@@ -13,10 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "hash.h"
#include "hashfunc.h"
#include "os.h"
#include "shash.h"
#include "taosdef.h"
#include "tstoken.h"
#include "ttokendef.h"
...
...
src/query/src/queryExecutor.c
浏览文件 @
ce88438b
...
...
@@ -2609,7 +2609,6 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
GET_QINFO_ADDR
(
pRuntimeEnv
),
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
lastKey
,
pQuery
->
order
.
order
);
tsdb_query_handle_t
pQueryHandle
=
pRuntimeEnv
->
pQueryHandle
;
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
// check if query is killed or not set the status of query to pass the status check
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
...
...
@@ -5461,7 +5460,7 @@ static int32_t buildAirthmeticExprFromMsg(SSqlFunctionExpr *pExpr, SQueryTableMs
SSqlBinaryExprInfo
*
pBinaryExprInfo
=
&
pExpr
->
binExprInfo
;
SColumnInfo
*
pColMsg
=
pQueryMsg
->
colList
;
#if 0
t
SQLSyntax
Node* pBinExpr = NULL;
t
Expr
Node* pBinExpr = NULL;
SSchema* pSchema = toSchema(pQueryMsg, pColMsg, pQueryMsg->numOfCols);
dTrace("qmsg:%p create binary expr from string:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz);
...
...
src/query/src/queryUtil.c
浏览文件 @
ce88438b
...
...
@@ -24,6 +24,7 @@
#include "ttime.h"
#include "queryExecutor.h"
#include "queryUtil.h"
int32_t
initWindowResInfo
(
SWindowResInfo
*
pWindowResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
size
,
int32_t
threshold
,
int16_t
type
)
{
...
...
src/vnode/tsdb/src/tsdbRead.c
浏览文件 @
ce88438b
...
...
@@ -424,39 +424,48 @@ static SDataBlockInfo getTrueDataBlockInfo(STsdbQueryHandle* pHandle, STableChec
SArray
*
getDefaultLoadColumns
(
STsdbQueryHandle
*
pQueryHandle
,
bool
loadTS
);
static
void
filterDataInDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
SDataCols
*
pCols
,
SArray
*
sa
);
static
bool
loadQualifie
dDataFromFileBlock
(
STsdbQueryHandle
*
pQueryHandle
)
{
static
bool
doLoa
dDataFromFileBlock
(
STsdbQueryHandle
*
pQueryHandle
)
{
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
pQueryHandle
->
activeIndex
);
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
))
{
if
(
pQueryHandle
->
window
.
ekey
<
pBlock
->
keyLast
)
{
SCompData
*
data
=
calloc
(
1
,
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pBlock
->
numOfCols
);
SCompData
*
data
=
calloc
(
1
,
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pBlock
->
numOfCols
);
data
->
numOfCols
=
pBlock
->
numOfCols
;
data
->
uid
=
pCheckInfo
->
pTableObj
->
tableId
.
uid
;
data
->
numOfCols
=
pBlock
->
numOfCols
;
data
->
uid
=
pCheckInfo
->
pTableObj
->
tableId
.
uid
;
pCheckInfo
->
pDataCols
=
tdNewDataCols
(
1000
,
2
,
4096
);
tdInitDataCols
(
pCheckInfo
->
pDataCols
,
pCheckInfo
->
pTableObj
->
schema
);
pCheckInfo
->
pDataCols
=
tdNewDataCols
(
1000
,
2
,
4096
);
tdInitDataCols
(
pCheckInfo
->
pDataCols
,
pCheckInfo
->
pTableObj
->
schema
);
SFile
*
pFile
=
&
pCheckInfo
->
pFileGroup
->
files
[
TSDB_FILE_TYPE_DATA
];
if
(
pFile
->
fd
==
FD_INITIALIZER
)
{
pFile
->
fd
=
open
(
pFile
->
fname
,
O_RDONLY
);
}
SFile
*
pFile
=
&
pCheckInfo
->
pFileGroup
->
files
[
TSDB_FILE_TYPE_DATA
];
if
(
pFile
->
fd
==
FD_INITIALIZER
)
{
pFile
->
fd
=
open
(
pFile
->
fname
,
O_RDONLY
);
}
if
(
tsdbLoadDataBlock
(
pFile
,
pBlock
,
1
,
pCheckInfo
->
pDataCols
,
data
)
==
0
)
{
//do something
}
tsdbLoadDataBlock
(
pFile
,
pBlock
,
1
,
pCheckInfo
->
pDataCols
,
data
);
}
static
bool
loadQualifiedDataFromFileBlock
(
STsdbQueryHandle
*
pQueryHandle
)
{
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
pQueryHandle
->
activeIndex
);
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
))
{
// query ended in current block
if
(
pQueryHandle
->
window
.
ekey
<
pBlock
->
keyLast
)
{
doLoadDataFromFileBlock
(
pQueryHandle
);
filterDataInDataBlock
(
pQueryHandle
,
pCheckInfo
->
pDataCols
,
sa
);
}
}
else
{
}
else
{
// todo desc query
if
(
pQueryHandle
->
window
.
ekey
>
pBlock
->
keyFirst
)
{
//
loadDataBlockIntoMem_(pQueryHandle, pBlock, &pQueryHandle->pFields[cur->slot], cur->fileId, sa);
//
}
}
filterDataInDataBlock
(
pQueryHandle
,
pCheckInfo
->
pDataCols
,
sa
);
return
pQueryHandle
->
realNumOfRows
>
0
;
}
...
...
@@ -508,7 +517,7 @@ bool moveToNextBlock(STsdbQueryHandle *pQueryHandle, int32_t step) {
// next block in the same file
cur
->
slot
+=
step
;
SCompBlock
*
pBlock
=
&
p
QueryHandle
->
pBlock
[
cur
->
slot
];
SCompBlock
*
pBlock
=
&
p
CheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
cur
->
pos
=
(
step
==
QUERY_ASC_FORWARD_STEP
)
?
0
:
pBlock
->
numOfPoints
-
1
;
return
loadQualifiedDataFromFileBlock
(
pQueryHandle
);
}
...
...
@@ -769,12 +778,11 @@ static bool getQualifiedDataBlock(STsdbQueryHandle *pQueryHandle, STableCheckInf
// load first data block into memory failed, caused by disk block error
bool
blockLoaded
=
false
;
SArray
*
sa
=
NULL
;
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
)
;
// todo no need to loaded at all
cur
->
slot
=
index
;
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
SCompData
*
data
=
calloc
(
1
,
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pBlock
->
numOfCols
);
...
...
@@ -973,11 +981,16 @@ SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
SDataBlockInfo
binfo
=
getTrueDataBlockInfo
(
pHandle
,
pCheckInfo
);
if
(
pHandle
->
realNumOfRows
<=
binfo
.
size
)
{
assert
(
pHandle
->
realNumOfRows
<=
binfo
.
size
);
if
(
pHandle
->
realNumOfRows
<
binfo
.
size
)
{
return
pHandle
->
pColumns
;
}
else
{
// todo do load data block
assert
(
0
);
SArray
*
sa
=
getDefaultLoadColumns
(
pHandle
,
true
);
doLoadDataFromFileBlock
(
pHandle
);
filterDataInDataBlock
(
pHandle
,
pCheckInfo
->
pDataCols
,
sa
);
return
pHandle
->
pColumns
;
}
}
}
...
...
@@ -1197,7 +1210,7 @@ static void getTagColumnInfo(SSyntaxTreeFilterSupporter* pSupporter, SSchema* pS
}
void
filterPrepare
(
void
*
expr
,
void
*
param
)
{
t
SQLSyntaxNode
*
pExpr
=
(
tSQLSyntax
Node
*
)
expr
;
t
ExprNode
*
pExpr
=
(
tExpr
Node
*
)
expr
;
if
(
pExpr
->
_node
.
info
!=
NULL
)
{
return
;
}
...
...
@@ -1276,7 +1289,7 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
static
int32_t
doQueryTableList
(
STable
*
pSTable
,
SArray
*
pRes
,
const
char
*
pCond
)
{
STColumn
*
stcol
=
schemaColAt
(
pSTable
->
tagSchema
,
0
);
t
SQLSyntax
Node
*
pExpr
=
NULL
;
t
Expr
Node
*
pExpr
=
NULL
;
tSQLBinaryExprFromString
(
&
pExpr
,
stcol
,
schemaNCols
(
pSTable
->
tagSchema
),
pCond
,
strlen
(
pCond
));
// failed to build expression, no result, return immediately
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录