Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
632d1865
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
632d1865
编写于
3月 28, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '2.0' into feature/2.0tsdb
上级
db86ba92
0d468d4a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
175 addition
and
166 deletion
+175
-166
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+2
-8
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+4
-4
src/client/src/tscServer.c
src/client/src/tscServer.c
+11
-0
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+1
-1
src/dnode/src/dnodeRead.c
src/dnode/src/dnodeRead.c
+0
-10
src/inc/taosmsg.h
src/inc/taosmsg.h
+2
-1
src/query/inc/queryExecutor.h
src/query/inc/queryExecutor.h
+0
-1
src/query/src/qast.c
src/query/src/qast.c
+5
-5
src/query/src/queryExecutor.c
src/query/src/queryExecutor.c
+105
-98
src/vnode/tsdb/src/tsdbRead.c
src/vnode/tsdb/src/tsdbRead.c
+45
-38
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
632d1865
...
...
@@ -1238,8 +1238,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
goto
_clean
;
}
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
// merge according to vgId
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
// merge according to vgId
if
((
code
=
tscMergeTableDataBlocks
(
pSql
,
pCmd
->
pDataBlocks
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error_clean
;
}
...
...
@@ -1294,12 +1293,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
int
tsParseSql
(
SSqlObj
*
pSql
,
bool
multiVnodeInsertion
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
// if (NULL == pSql->asyncTblPos) {
// tscCleanSqlCmd(&pSql->cmd);
// } else {
tscTrace
(
"continue parse sql: %s"
,
pSql
->
asyncTblPos
);
// }
tscTrace
(
"continue parse sql: %s"
,
pSql
->
asyncTblPos
);
if
(
tscIsInsertOrImportData
(
pSql
->
sqlstr
))
{
/*
...
...
src/client/src/tscSQLParser.c
浏览文件 @
632d1865
...
...
@@ -2789,7 +2789,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tablenameListToString
(
tSQLExpr
*
pExpr
,
/*char* str*/
SStringBuilder
*
sb
)
{
static
int32_t
tablenameListToString
(
tSQLExpr
*
pExpr
,
SStringBuilder
*
sb
)
{
tSQLExprList
*
pList
=
pExpr
->
pParam
;
if
(
pList
->
nExpr
<=
0
)
{
return
TSDB_CODE_INVALID_SQL
;
...
...
@@ -2815,7 +2815,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, /*char* str*/ SStringBuild
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tablenameCondToString
(
tSQLExpr
*
pExpr
,
/*char* str*/
SStringBuilder
*
sb
)
{
static
int32_t
tablenameCondToString
(
tSQLExpr
*
pExpr
,
SStringBuilder
*
sb
)
{
taosStringBuilderAppendStringLen
(
sb
,
QUERY_COND_REL_PREFIX_LIKE
,
QUERY_COND_REL_PREFIX_LIKE_LEN
);
taosStringBuilderAppendString
(
sb
,
pExpr
->
val
.
pz
);
...
...
@@ -3756,8 +3756,8 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
return
TSDB_CODE_SUCCESS
;
}
const
char
*
msg
=
"invalid filter expression"
;
const
char
*
msg1
=
"invalid expression"
;
const
char
*
msg2
=
"invalid filter expression"
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
...
...
@@ -3819,7 +3819,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
taosStringBuilderDestroy
(
&
sb
);
if
(
!
validateFilterExpr
(
pQueryInfo
))
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg
2
);
}
doAddJoinTagsColumnsIntoTagList
(
pQueryInfo
,
&
condExpr
);
...
...
src/client/src/tscServer.c
浏览文件 @
632d1865
...
...
@@ -847,6 +847,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
tsOrder
=
htonl
(
pQueryInfo
->
tsBuf
->
tsOrder
);
}
// serialize tag column query condition
if
(
pQueryInfo
->
tagCond
.
numOfTagCond
>
0
)
{
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
...
...
@@ -865,6 +866,16 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
// tbname in/like query expression should be sent to mgmt node
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
if
(
pTagCond
->
tbnameCond
.
cond
!=
NULL
)
{
size_t
s
=
strlen
(
pTagCond
->
tbnameCond
.
cond
);
memcpy
(
pMsg
,
pTagCond
->
tbnameCond
.
cond
,
s
);
pQueryMsg
->
nameCondLen
=
htons
(
s
);
pMsg
+=
s
;
}
msgLen
=
pMsg
-
pStart
;
tscTrace
(
"%p msg built success,len:%d bytes"
,
pSql
,
msgLen
);
...
...
src/client/src/tscUtil.c
浏览文件 @
632d1865
...
...
@@ -608,7 +608,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
* the payloadLen should be actual message body size
* the old value of payloadLen is the allocated payload size
*/
pCmd
->
payloadLen
=
pDataBlock
->
nAllocSize
-
tsRpcHeadSize
;
pCmd
->
payloadLen
=
pDataBlock
->
nAllocSize
-
tsRpcHeadSize
-
sizeof
(
SMsgDesc
)
;
assert
(
pCmd
->
allocSize
>=
pCmd
->
payloadLen
+
tsRpcHeadSize
+
100
&&
pCmd
->
payloadLen
>
0
);
return
TSDB_CODE_SUCCESS
;
...
...
src/dnode/src/dnodeRead.c
浏览文件 @
632d1865
...
...
@@ -243,16 +243,6 @@ static void dnodeContinueExecuteQuery(void* pVnode, void* qhandle, SReadMsg *pMs
taos_queue
queue
=
dnodeGetVnodeRworker
(
pVnode
);
taosWriteQitem
(
queue
,
TAOS_QTYPE_RPC
,
pRead
);
// SReadMsg readMsg = {
// .rpcMsg = {0},
// .pCont = qhandle,
// .contLen = 0,
// .pRpcContext = pMsg->pRpcContext,
// };
//
// taos_queue queue = dnodeGetVnodeRworker(pVnode);
// taosWriteQitem(queue, TSDB_MSG_TYPE_QUERY, &readMsg);
}
static
void
dnodeProcessQueryMsg
(
void
*
pVnode
,
SReadMsg
*
pMsg
)
{
...
...
src/inc/taosmsg.h
浏览文件 @
632d1865
...
...
@@ -475,9 +475,10 @@ typedef struct {
int64_t
slidingTime
;
// value for sliding window
char
slidingTimeUnit
;
// time interval type, for revisement of interval(1d)
uint16_t
tagCondLen
;
// tag length in current query
uint16_t
nameCondLen
;
// table name in/like query expression string length
int16_t
numOfGroupCols
;
// num of group by columns
int16_t
orderByIdx
;
int16_t
orderType
;
// used in group by xx order by xxx
int16_t
orderType
;
// used in group by xx order by xxx
uint64_t
groupbyTagIds
;
int64_t
limit
;
int64_t
offset
;
...
...
src/query/inc/queryExecutor.h
浏览文件 @
632d1865
...
...
@@ -172,7 +172,6 @@ typedef struct SQueryRuntimeEnv {
typedef
struct
SQInfo
{
void
*
signature
;
// void* param; // pointer to the RpcReadMsg
TSKEY
startTime
;
TSKEY
elapsedTime
;
int32_t
pointsInterpo
;
...
...
src/query/src/qast.c
浏览文件 @
632d1865
...
...
@@ -16,6 +16,7 @@
#include "qast.h"
#include <tarray.h>
#include <tskiplist.h>
#include "../../client/inc/tschemautil.h"
#include "os.h"
#include "qsqlparser.h"
#include "qsyntaxtreefunction.h"
...
...
@@ -107,7 +108,7 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
return
NULL
;
}
size_t
nodeSize
=
sizeof
(
tSQLSyntaxNode
);
size_t
nodeSize
=
sizeof
(
tSQLSyntaxNode
);
tSQLSyntaxNode
*
pNode
=
NULL
;
if
(
pToken
->
type
==
TK_ID
||
pToken
->
type
==
TK_TBNAME
)
{
...
...
@@ -239,9 +240,7 @@ uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode
}
static
tSQLSyntaxNode
*
createSyntaxTree
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
str
,
int32_t
*
i
)
{
SSQLToken
t0
;
t0
=
tStrGetToken
(
str
,
i
,
false
,
0
,
NULL
);
SSQLToken
t0
=
tStrGetToken
(
str
,
i
,
false
,
0
,
NULL
);
if
(
t0
.
n
==
0
)
{
return
NULL
;
}
...
...
@@ -343,7 +342,8 @@ void tSQLBinaryExprFromString(tSQLBinaryExpr **pExpr, SSchema *pSchema, int32_t
return
;
}
int32_t
pos
=
0
;
int32_t
pos
=
0
;
tSQLSyntaxNode
*
pStxNode
=
createSyntaxTree
(
pSchema
,
numOfCols
,
src
,
&
pos
);
if
(
pStxNode
!=
NULL
)
{
assert
(
pStxNode
->
nodeType
==
TSQL_NODE_EXPR
);
...
...
src/query/src/queryExecutor.c
浏览文件 @
632d1865
...
...
@@ -5265,11 +5265,11 @@ void qTableQuery(SQInfo *pQInfo) {
// vnodeDecRefCount(pQInfo);
}
static
int32_t
getColumnIndexInSource
(
SQueryTableMsg
*
pQuery
Table
Msg
,
SSqlFuncExprMsg
*
pExprMsg
)
{
static
int32_t
getColumnIndexInSource
(
SQueryTableMsg
*
pQueryMsg
,
SSqlFuncExprMsg
*
pExprMsg
)
{
int32_t
j
=
0
;
while
(
j
<
pQuery
Table
Msg
->
numOfCols
)
{
if
(
pExprMsg
->
colInfo
.
colId
==
pQuery
Table
Msg
->
colList
[
j
].
colId
)
{
while
(
j
<
pQueryMsg
->
numOfCols
)
{
if
(
pExprMsg
->
colInfo
.
colId
==
pQueryMsg
->
colList
[
j
].
colId
)
{
break
;
}
...
...
@@ -5279,44 +5279,44 @@ static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryTableMsg, SSqlFuncEx
return
j
;
}
bool
vnodeValidateExprColumnInfo
(
SQueryTableMsg
*
pQuery
Table
Msg
,
SSqlFuncExprMsg
*
pExprMsg
)
{
int32_t
j
=
getColumnIndexInSource
(
pQuery
Table
Msg
,
pExprMsg
);
return
j
<
pQuery
Table
Msg
->
numOfCols
;
bool
vnodeValidateExprColumnInfo
(
SQueryTableMsg
*
pQueryMsg
,
SSqlFuncExprMsg
*
pExprMsg
)
{
int32_t
j
=
getColumnIndexInSource
(
pQueryMsg
,
pExprMsg
);
return
j
<
pQueryMsg
->
numOfCols
;
}
static
int32_t
validateQueryMeterMsg
(
SQueryTableMsg
*
pQuery
Table
Msg
)
{
if
(
pQuery
Table
Msg
->
intervalTime
<
0
)
{
dError
(
"qmsg:%p illegal value of aggTimeInterval %"
PRId64
""
,
pQuery
TableMsg
,
pQueryTable
Msg
->
intervalTime
);
static
int32_t
validateQueryMeterMsg
(
SQueryTableMsg
*
pQueryMsg
)
{
if
(
pQueryMsg
->
intervalTime
<
0
)
{
dError
(
"qmsg:%p illegal value of aggTimeInterval %"
PRId64
""
,
pQuery
Msg
,
pQuery
Msg
->
intervalTime
);
return
-
1
;
}
if
(
pQuery
TableMsg
->
numOfCols
<=
0
||
pQueryTable
Msg
->
numOfCols
>
TSDB_MAX_COLUMNS
)
{
dError
(
"qmsg:%p illegal value of numOfCols %d"
,
pQuery
TableMsg
,
pQueryTable
Msg
->
numOfCols
);
if
(
pQuery
Msg
->
numOfCols
<=
0
||
pQuery
Msg
->
numOfCols
>
TSDB_MAX_COLUMNS
)
{
dError
(
"qmsg:%p illegal value of numOfCols %d"
,
pQuery
Msg
,
pQuery
Msg
->
numOfCols
);
return
-
1
;
}
if
(
pQuery
Table
Msg
->
numOfTables
<=
0
)
{
dError
(
"qmsg:%p illegal value of numOfTables %d"
,
pQuery
TableMsg
,
pQueryTable
Msg
->
numOfTables
);
if
(
pQueryMsg
->
numOfTables
<=
0
)
{
dError
(
"qmsg:%p illegal value of numOfTables %d"
,
pQuery
Msg
,
pQuery
Msg
->
numOfTables
);
return
-
1
;
}
if
(
pQuery
Table
Msg
->
numOfGroupCols
<
0
)
{
dError
(
"qmsg:%p illegal value of numOfGroupbyCols %d"
,
pQuery
TableMsg
,
pQueryTable
Msg
->
numOfGroupCols
);
if
(
pQueryMsg
->
numOfGroupCols
<
0
)
{
dError
(
"qmsg:%p illegal value of numOfGroupbyCols %d"
,
pQuery
Msg
,
pQuery
Msg
->
numOfGroupCols
);
return
-
1
;
}
if
(
pQuery
TableMsg
->
numOfOutputCols
>
TSDB_MAX_COLUMNS
||
pQueryTable
Msg
->
numOfOutputCols
<=
0
)
{
dError
(
"qmsg:%p illegal value of output columns %d"
,
pQuery
TableMsg
,
pQueryTable
Msg
->
numOfOutputCols
);
if
(
pQuery
Msg
->
numOfOutputCols
>
TSDB_MAX_COLUMNS
||
pQuery
Msg
->
numOfOutputCols
<=
0
)
{
dError
(
"qmsg:%p illegal value of output columns %d"
,
pQuery
Msg
,
pQuery
Msg
->
numOfOutputCols
);
return
-
1
;
}
return
0
;
}
static
char
*
createTableIdList
(
SQueryTableMsg
*
pQuery
Table
Msg
,
char
*
pMsg
,
SArray
**
pTableIdList
)
{
assert
(
pQuery
Table
Msg
->
numOfTables
>
0
);
static
char
*
createTableIdList
(
SQueryTableMsg
*
pQueryMsg
,
char
*
pMsg
,
SArray
**
pTableIdList
)
{
assert
(
pQueryMsg
->
numOfTables
>
0
);
*
pTableIdList
=
taosArrayInit
(
pQuery
Table
Msg
->
numOfTables
,
sizeof
(
STableIdInfo
));
*
pTableIdList
=
taosArrayInit
(
pQueryMsg
->
numOfTables
,
sizeof
(
STableIdInfo
));
STableIdInfo
*
pTableIdInfo
=
(
STableIdInfo
*
)
pMsg
;
pTableIdInfo
->
sid
=
htonl
(
pTableIdInfo
->
sid
);
...
...
@@ -5326,7 +5326,7 @@ static char* createTableIdList(SQueryTableMsg* pQueryTableMsg, char* pMsg, SArra
taosArrayPush
(
*
pTableIdList
,
pTableIdInfo
);
pMsg
+=
sizeof
(
STableIdInfo
);
for
(
int32_t
j
=
1
;
j
<
pQuery
Table
Msg
->
numOfTables
;
++
j
)
{
for
(
int32_t
j
=
1
;
j
<
pQueryMsg
->
numOfTables
;
++
j
)
{
pTableIdInfo
=
(
STableIdInfo
*
)
pMsg
;
pTableIdInfo
->
sid
=
htonl
(
pTableIdInfo
->
sid
);
...
...
@@ -5341,49 +5341,47 @@ static char* createTableIdList(SQueryTableMsg* pQueryTableMsg, char* pMsg, SArra
}
/**
* pQuery
Table
Msg->head has been converted before this function is called.
* pQueryMsg->head has been converted before this function is called.
*
* @param pQuery
Table
Msg
* @param pQueryMsg
* @param pTableIdList
* @param pExpr
* @return
*/
static
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryTableMsg
,
SArray
**
pTableIdList
,
SSqlFuncExprMsg
***
pExpr
,
wchar_t
**
tagCond
)
{
pQueryTableMsg
->
numOfTables
=
htonl
(
pQueryTableMsg
->
numOfTables
);
pQueryTableMsg
->
window
.
skey
=
htobe64
(
pQueryTableMsg
->
window
.
skey
);
pQueryTableMsg
->
window
.
ekey
=
htobe64
(
pQueryTableMsg
->
window
.
ekey
);
pQueryTableMsg
->
intervalTime
=
htobe64
(
pQueryTableMsg
->
intervalTime
);
pQueryTableMsg
->
slidingTime
=
htobe64
(
pQueryTableMsg
->
slidingTime
);
static
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
SArray
**
pTableIdList
,
SSqlFuncExprMsg
***
pExpr
,
wchar_t
**
tagCond
,
char
**
nameCond
)
{
pQueryMsg
->
numOfTables
=
htonl
(
pQueryMsg
->
numOfTables
);
pQueryMsg
->
window
.
skey
=
htobe64
(
pQueryMsg
->
window
.
skey
);
pQueryMsg
->
window
.
ekey
=
htobe64
(
pQueryMsg
->
window
.
ekey
);
pQueryMsg
->
intervalTime
=
htobe64
(
pQueryMsg
->
intervalTime
);
pQueryMsg
->
slidingTime
=
htobe64
(
pQueryMsg
->
slidingTime
);
pQueryMsg
->
limit
=
htobe64
(
pQueryMsg
->
limit
);
pQueryMsg
->
offset
=
htobe64
(
pQueryMsg
->
offset
);
pQueryTableMsg
->
limit
=
htobe64
(
pQueryTableMsg
->
limit
);
pQueryTableMsg
->
offset
=
htobe64
(
pQueryTableMsg
->
offset
);
pQueryTableMsg
->
order
=
htons
(
pQueryTableMsg
->
order
);
pQueryTableMsg
->
orderColId
=
htons
(
pQueryTableMsg
->
orderColId
);
pQueryTableMsg
->
queryType
=
htons
(
pQueryTableMsg
->
queryType
);
pQueryTableMsg
->
numOfCols
=
htons
(
pQueryTableMsg
->
numOfCols
);
pQueryTableMsg
->
numOfOutputCols
=
htons
(
pQueryTableMsg
->
numOfOutputCols
);
pQueryTableMsg
->
numOfGroupCols
=
htons
(
pQueryTableMsg
->
numOfGroupCols
);
pQueryTableMsg
->
tagCondLen
=
htons
(
pQueryTableMsg
->
tagCondLen
);
pQueryTableMsg
->
tsOffset
=
htonl
(
pQueryTableMsg
->
tsOffset
);
pQueryTableMsg
->
tsLen
=
htonl
(
pQueryTableMsg
->
tsLen
);
pQueryTableMsg
->
tsNumOfBlocks
=
htonl
(
pQueryTableMsg
->
tsNumOfBlocks
);
pQueryTableMsg
->
tsOrder
=
htonl
(
pQueryTableMsg
->
tsOrder
);
pQueryMsg
->
order
=
htons
(
pQueryMsg
->
order
);
pQueryMsg
->
orderColId
=
htons
(
pQueryMsg
->
orderColId
);
pQueryMsg
->
queryType
=
htons
(
pQueryMsg
->
queryType
);
pQueryMsg
->
numOfCols
=
htons
(
pQueryMsg
->
numOfCols
);
pQueryMsg
->
numOfOutputCols
=
htons
(
pQueryMsg
->
numOfOutputCols
);
pQueryMsg
->
numOfGroupCols
=
htons
(
pQueryMsg
->
numOfGroupCols
);
pQueryMsg
->
tagCondLen
=
htons
(
pQueryMsg
->
tagCondLen
);
pQueryMsg
->
nameCondLen
=
htons
(
pQueryMsg
->
nameCondLen
);
pQueryMsg
->
tsOffset
=
htonl
(
pQueryMsg
->
tsOffset
);
pQueryMsg
->
tsLen
=
htonl
(
pQueryMsg
->
tsLen
);
pQueryMsg
->
tsNumOfBlocks
=
htonl
(
pQueryMsg
->
tsNumOfBlocks
);
pQueryMsg
->
tsOrder
=
htonl
(
pQueryMsg
->
tsOrder
);
// query msg safety check
if
(
validateQueryMeterMsg
(
pQuery
Table
Msg
)
!=
0
)
{
if
(
validateQueryMeterMsg
(
pQueryMsg
)
!=
0
)
{
return
TSDB_CODE_INVALID_QUERY_MSG
;
}
char
*
pMsg
=
(
char
*
)(
pQuery
TableMsg
->
colList
)
+
sizeof
(
SColumnInfo
)
*
pQueryTable
Msg
->
numOfCols
;
char
*
pMsg
=
(
char
*
)(
pQuery
Msg
->
colList
)
+
sizeof
(
SColumnInfo
)
*
pQuery
Msg
->
numOfCols
;
for
(
int32_t
col
=
0
;
col
<
pQuery
Table
Msg
->
numOfCols
;
++
col
)
{
SColumnInfo
*
pColInfo
=
&
pQuery
Table
Msg
->
colList
[
col
];
for
(
int32_t
col
=
0
;
col
<
pQueryMsg
->
numOfCols
;
++
col
)
{
SColumnInfo
*
pColInfo
=
&
pQueryMsg
->
colList
[
col
];
pColInfo
->
colId
=
htons
(
pColInfo
->
colId
);
pColInfo
->
type
=
htons
(
pColInfo
->
type
);
...
...
@@ -5423,10 +5421,10 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryTableMsg, SArray **pTableId
bool
hasArithmeticFunction
=
false
;
*
pExpr
=
calloc
(
pQuery
Table
Msg
->
numOfOutputCols
,
POINTER_BYTES
);
*
pExpr
=
calloc
(
pQueryMsg
->
numOfOutputCols
,
POINTER_BYTES
);
SSqlFuncExprMsg
*
pExprMsg
=
(
SSqlFuncExprMsg
*
)
pMsg
;
for
(
int32_t
i
=
0
;
i
<
pQuery
Table
Msg
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryMsg
->
numOfOutputCols
;
++
i
)
{
(
*
pExpr
)[
i
]
=
pExprMsg
;
pExprMsg
->
colInfo
.
colIdx
=
htons
(
pExprMsg
->
colInfo
.
colIdx
);
...
...
@@ -5457,7 +5455,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryTableMsg, SArray **pTableId
return
TSDB_CODE_INVALID_QUERY_MSG
;
}
}
else
{
if
(
!
vnodeValidateExprColumnInfo
(
pQuery
Table
Msg
,
pExprMsg
))
{
if
(
!
vnodeValidateExprColumnInfo
(
pQueryMsg
,
pExprMsg
))
{
return
TSDB_CODE_INVALID_QUERY_MSG
;
}
}
...
...
@@ -5465,55 +5463,59 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryTableMsg, SArray **pTableId
pExprMsg
=
(
SSqlFuncExprMsg
*
)
pMsg
;
}
pQuery
TableMsg
->
colNameLen
=
htonl
(
pQueryTable
Msg
->
colNameLen
);
pQuery
Msg
->
colNameLen
=
htonl
(
pQuery
Msg
->
colNameLen
);
if
(
hasArithmeticFunction
)
{
// column name array
assert
(
pQuery
Table
Msg
->
colNameLen
>
0
);
pQuery
Table
Msg
->
colNameList
=
(
int64_t
)
pMsg
;
pMsg
+=
pQuery
Table
Msg
->
colNameLen
;
assert
(
pQueryMsg
->
colNameLen
>
0
);
pQueryMsg
->
colNameList
=
(
int64_t
)
pMsg
;
pMsg
+=
pQueryMsg
->
colNameLen
;
}
pMsg
=
createTableIdList
(
pQuery
Table
Msg
,
pMsg
,
pTableIdList
);
pMsg
=
createTableIdList
(
pQueryMsg
,
pMsg
,
pTableIdList
);
if
(
pQuery
Table
Msg
->
numOfGroupCols
>
0
)
{
// group by tag columns
// if (pQuery
Table
Msg->numOfGroupCols > 0) {
// pQuery
TableMsg->groupbyTagIds = (uint64_t) & (pTagSchema[pQueryTable
Msg->numOfTagsCols]);
if
(
pQueryMsg
->
numOfGroupCols
>
0
)
{
// group by tag columns
// if (pQueryMsg->numOfGroupCols > 0) {
// pQuery
Msg->groupbyTagIds = (uint64_t) & (pTagSchema[pQuery
Msg->numOfTagsCols]);
// } else {
// pQuery
Table
Msg->groupbyTagIds = 0;
// pQueryMsg->groupbyTagIds = 0;
// }
pQuery
TableMsg
->
orderByIdx
=
htons
(
pQueryTable
Msg
->
orderByIdx
);
pQuery
TableMsg
->
orderType
=
htons
(
pQueryTable
Msg
->
orderType
);
pQuery
Msg
->
orderByIdx
=
htons
(
pQuery
Msg
->
orderByIdx
);
pQuery
Msg
->
orderType
=
htons
(
pQuery
Msg
->
orderType
);
pMsg
+=
sizeof
(
SColIndexEx
)
*
pQuery
Table
Msg
->
numOfGroupCols
;
pMsg
+=
sizeof
(
SColIndexEx
)
*
pQueryMsg
->
numOfGroupCols
;
}
else
{
pQuery
Table
Msg
->
groupbyTagIds
=
0
;
pQueryMsg
->
groupbyTagIds
=
0
;
}
pQuery
TableMsg
->
interpoType
=
htons
(
pQueryTable
Msg
->
interpoType
);
if
(
pQuery
Table
Msg
->
interpoType
!=
TSDB_INTERPO_NONE
)
{
pQuery
Table
Msg
->
defaultVal
=
(
uint64_t
)(
pMsg
);
pQuery
Msg
->
interpoType
=
htons
(
pQuery
Msg
->
interpoType
);
if
(
pQueryMsg
->
interpoType
!=
TSDB_INTERPO_NONE
)
{
pQueryMsg
->
defaultVal
=
(
uint64_t
)(
pMsg
);
int64_t
*
v
=
(
int64_t
*
)
pMsg
;
for
(
int32_t
i
=
0
;
i
<
pQuery
Table
Msg
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryMsg
->
numOfOutputCols
;
++
i
)
{
v
[
i
]
=
htobe64
(
v
[
i
]);
}
pMsg
+=
sizeof
(
int64_t
)
*
pQuery
Table
Msg
->
numOfOutputCols
;
pMsg
+=
sizeof
(
int64_t
)
*
pQueryMsg
->
numOfOutputCols
;
}
// the tag query condition expression string is located at the end of query msg
if
(
pQueryTableMsg
->
tagCondLen
>
0
)
{
*
tagCond
=
calloc
(
1
,
pQueryTableMsg
->
tagCondLen
*
TSDB_NCHAR_SIZE
);
memcpy
(
*
tagCond
,
pMsg
,
pQueryTableMsg
->
tagCondLen
*
TSDB_NCHAR_SIZE
);
if
(
pQueryMsg
->
tagCondLen
>
0
)
{
*
tagCond
=
calloc
(
1
,
pQueryMsg
->
tagCondLen
*
TSDB_NCHAR_SIZE
);
memcpy
(
*
tagCond
,
pMsg
,
pQueryMsg
->
tagCondLen
*
TSDB_NCHAR_SIZE
);
}
if
(
pQueryMsg
->
nameCondLen
>
0
)
{
*
nameCond
=
strndup
(
pMsg
,
pQueryMsg
->
nameCondLen
);
}
dTrace
(
"qmsg:%p query on %d meter(s), qrange:%"
PRId64
"-%"
PRId64
", numOfGroupbyTagCols:%d, numOfTagCols:%d, "
"timestamp order:%d, tags order:%d, tags order col:%d, numOfOutputCols:%d, numOfCols:%d, interval:%"
PRId64
", fillType:%d, comptslen:%d, limit:%"
PRId64
", offset:%"
PRId64
,
pQuery
TableMsg
,
pQueryTableMsg
->
numOfTables
,
pQueryTableMsg
->
window
.
skey
,
pQueryTable
Msg
->
window
.
ekey
,
pQuery
TableMsg
->
numOfGroupCols
,
pQueryTableMsg
->
order
,
pQueryTable
Msg
->
orderType
,
pQuery
TableMsg
->
orderByIdx
,
pQueryTable
Msg
->
numOfOutputCols
,
pQuery
TableMsg
->
numOfCols
,
pQueryTableMsg
->
intervalTime
,
pQueryTableMsg
->
interpoType
,
pQueryTable
Msg
->
tsLen
,
pQuery
TableMsg
->
limit
,
pQueryTable
Msg
->
offset
);
pQuery
Msg
,
pQueryMsg
->
numOfTables
,
pQueryMsg
->
window
.
skey
,
pQuery
Msg
->
window
.
ekey
,
pQuery
Msg
->
numOfGroupCols
,
pQueryMsg
->
order
,
pQuery
Msg
->
orderType
,
pQuery
Msg
->
orderByIdx
,
pQuery
Msg
->
numOfOutputCols
,
pQuery
Msg
->
numOfCols
,
pQueryMsg
->
intervalTime
,
pQueryMsg
->
interpoType
,
pQuery
Msg
->
tsLen
,
pQuery
Msg
->
limit
,
pQuery
Msg
->
offset
);
return
0
;
}
...
...
@@ -6047,54 +6049,59 @@ _error:
return
code
;
}
int32_t
qCreateQueryInfo
(
void
*
tsdb
,
SQueryTableMsg
*
pQuery
Table
Msg
,
SQInfo
**
pQInfo
)
{
assert
(
pQuery
Table
Msg
!=
NULL
);
int32_t
qCreateQueryInfo
(
void
*
tsdb
,
SQueryTableMsg
*
pQueryMsg
,
SQInfo
**
pQInfo
)
{
assert
(
pQueryMsg
!=
NULL
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
SArray
*
pTableIdList
=
NULL
;
SSqlFuncExprMsg
**
pExprMsg
=
NULL
;
wchar_t
*
tagCond
=
NULL
;
char
*
nameCond
=
NULL
;
if
((
code
=
convertQueryMsg
(
pQuery
TableMsg
,
&
pTableIdList
,
&
pExprMsg
,
&
tag
Cond
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
convertQueryMsg
(
pQuery
Msg
,
&
pTableIdList
,
&
pExprMsg
,
&
tagCond
,
&
name
Cond
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
(
pQuery
Table
Msg
->
numOfTables
<=
0
)
{
dError
(
"Invalid number of tables to query, numOfTables:%d"
,
pQuery
Table
Msg
->
numOfTables
);
if
(
pQueryMsg
->
numOfTables
<=
0
)
{
dError
(
"Invalid number of tables to query, numOfTables:%d"
,
pQueryMsg
->
numOfTables
);
code
=
TSDB_CODE_INVALID_QUERY_MSG
;
goto
_query_over
;
}
// todo check vnode status
if
(
pTableIdList
==
NULL
||
taosArrayGetSize
(
pTableIdList
)
==
0
)
{
dError
(
"qmsg:%p, SQueryTableMsg wrong format"
,
pQuery
Table
Msg
);
dError
(
"qmsg:%p, SQueryTableMsg wrong format"
,
pQueryMsg
);
code
=
TSDB_CODE_INVALID_QUERY_MSG
;
goto
_query_over
;
}
SSqlFunctionExpr
*
pExprs
=
NULL
;
if
((
code
=
createSqlFunctionExprFromMsg
(
pQuery
Table
Msg
,
&
pExprs
,
pExprMsg
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
createSqlFunctionExprFromMsg
(
pQueryMsg
,
&
pExprs
,
pExprMsg
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_query_over
;
}
SSqlGroupbyExpr
*
pGroupbyExpr
=
createGroupbyExprFromMsg
(
pQuery
Table
Msg
,
&
code
);
if
((
pGroupbyExpr
==
NULL
&&
pQuery
Table
Msg
->
numOfGroupCols
!=
0
)
||
code
!=
TSDB_CODE_SUCCESS
)
{
SSqlGroupbyExpr
*
pGroupbyExpr
=
createGroupbyExprFromMsg
(
pQueryMsg
,
&
code
);
if
((
pGroupbyExpr
==
NULL
&&
pQueryMsg
->
numOfGroupCols
!=
0
)
||
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_query_over
;
}
// super table query
if
((
pQueryTableMsg
->
queryType
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
!=
0
)
{
SArray
*
res
=
NULL
;
if
((
pQueryMsg
->
queryType
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
!=
0
)
{
STableId
*
id
=
taosArrayGet
(
pTableIdList
,
0
);
id
->
uid
=
-
1
;
SArray
*
res
=
tsdbQueryTableList
(
tsdb
,
id
->
uid
,
tagCond
,
pQueryTable
Msg
->
tagCondLen
);
res
=
tsdbQueryTableList
(
tsdb
,
id
->
uid
,
tagCond
,
pQuery
Msg
->
tagCondLen
);
if
(
taosArrayGetSize
(
res
)
==
0
)
{
// no qualified table in stable query in this vnode
code
=
TSDB_CODE_SUCCESS
;
goto
_query_over
;
}
}
else
{
res
=
pTableIdList
;
}
code
=
createQInfo
(
pQuery
TableMsg
,
pGroupbyExpr
,
pExprs
,
pTableIdList
,
tsdb
,
pQInfo
);
code
=
createQInfo
(
pQuery
Msg
,
pGroupbyExpr
,
pExprs
,
res
,
tsdb
,
pQInfo
);
_query_over:
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -6103,16 +6110,16 @@ _query_over:
// if failed to add ref for all meters in this query, abort current query
// if (code != TSDB_CODE_SUCCESS) {
// vnodeDecQueryRefCount(pQuery
Table
Msg, pMeterObjList, incNumber);
// vnodeDecQueryRefCount(pQueryMsg, pMeterObjList, incNumber);
// }
//
// tfree(pQuery
Table
Msg->pSqlFuncExprs);
// tfree(pQueryMsg->pSqlFuncExprs);
// tfree(pMeterObjList);
// ret = vnodeSendQueryRspMsg(pObj, code, pObj->qhandle);
//
// tfree(pQuery
Table
Msg->pSidExtInfo);
// for(int32_t i = 0; i < pQuery
Table
Msg->numOfCols; ++i) {
// vnodeFreeColumnInfo(&pQuery
Table
Msg->colList[i]);
// tfree(pQueryMsg->pSidExtInfo);
// for(int32_t i = 0; i < pQueryMsg->numOfCols; ++i) {
// vnodeFreeColumnInfo(&pQueryMsg->colList[i]);
// }
//
// atomic_fetch_add_32(&vnodeSelectReqNum, 1);
...
...
src/vnode/tsdb/src/tsdbRead.c
浏览文件 @
632d1865
...
...
@@ -73,14 +73,15 @@ typedef struct SQueryFilesInfo {
char
dbFilePathPrefix
[
PATH_MAX
];
}
SQueryFilesInfo
;
typedef
struct
STableQueryRec
{
typedef
struct
STableQueryInfo
{
STableId
tableId
;
TSKEY
lastKey
;
STable
*
pTableObj
;
int64_t
offsetInHeaderFile
;
int32_t
numOfBlocks
;
int32_t
start
;
SCompBlock
*
pBlock
;
}
STableQuery
Rec
;
}
STableQuery
Info
;
typedef
struct
{
SCompBlock
*
compBlock
;
...
...
@@ -89,7 +90,7 @@ typedef struct {
typedef
struct
STableDataBlockInfoEx
{
SCompBlockFields
pBlock
;
STableQuery
Rec
*
pMeterDataInfo
;
STableQuery
Info
*
pMeterDataInfo
;
int32_t
blockIndex
;
int32_t
groupIdx
;
/* number of group is less than the total number of meters */
}
STableDataBlockInfoEx
;
...
...
@@ -100,12 +101,11 @@ typedef struct STsdbQueryHandle {
SQueryHandlePos
cur
;
// current position
SQueryHandlePos
start
;
// the start position, used for secondary/third iteration
int32_t
unzipBufSize
;
char
*
unzipBuffer
;
char
*
secondaryUnzipBuffer
;
char
*
unzipBuffer
;
char
*
secondaryUnzipBuffer
;
SDataBlockLoadInfo
dataBlockLoadInfo
;
/* record current block load information */
SLoadCompBlockInfo
compBlockLoadInfo
;
/* record current compblock information in SQuery */
SQueryFilesInfo
vnodeFileInfo
;
int16_t
numOfRowsPerPage
;
...
...
@@ -113,21 +113,22 @@ typedef struct STsdbQueryHandle {
int16_t
order
;
STimeWindow
window
;
// the primary query time window that applies to all queries
int32_t
blockBufferSize
;
SCompBlock
*
pBlock
;
SCompBlock
*
pBlock
;
int32_t
numOfBlocks
;
SField
**
pFields
;
SArray
*
pColumns
;
// column list, SColumnInfoEx array list
SArray
*
pTableIdList
;
// table id object list
bool
locateStart
;
int32_t
realNumOfRows
;
bool
loadDataAfterSeek
;
// load data after seek.
STableDataBlockInfoEx
*
pDataBlockInfoEx
;
STableQueryRec
*
pTableQueryInfo
;
int32_t
tableIndex
;
bool
isFirstSlot
;
void
*
qinfo
;
// query info handle, for debug purpose
SArray
*
pTableQueryInfo
;
int32_t
activeIndex
;
int32_t
tableIndex
;
bool
isFirstSlot
;
void
*
qinfo
;
// query info handle, for debug purpose
SSkipListIterator
*
memIter
;
STableDataBlockInfoEx
*
pDataBlockInfoEx
;
}
STsdbQueryHandle
;
int32_t
doAllocateBuf
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
rowsPerFileBlock
)
{
...
...
@@ -263,25 +264,27 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
pQueryHandle
->
window
=
pCond
->
twindow
;
pQueryHandle
->
pTsdb
=
tsdb
;
pQueryHandle
->
pTableIdList
=
idList
;
pQueryHandle
->
pColumns
=
pColumnInfo
;
pQueryHandle
->
loadDataAfterSeek
=
false
;
pQueryHandle
->
isFirstSlot
=
true
;
// only support table query
assert
(
taosArrayGetSize
(
idList
)
==
1
);
pQueryHandle
->
pTableQueryInfo
=
calloc
(
1
,
sizeof
(
STableQueryRec
));
STableQueryRec
*
pTableQRec
=
pQueryHandle
->
pTableQueryInfo
;
pTableQRec
->
lastKey
=
pQueryHandle
->
window
.
skey
;
STableIdInfo
*
idInfo
=
taosArrayGet
(
pQueryHandle
->
pTableIdList
,
0
);
STable
*
pTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
pQueryHandle
->
pTsdb
),
idInfo
->
uid
);
assert
(
pTable
!=
NULL
);
size_t
size
=
taosArrayGetSize
(
idList
);
assert
(
size
>=
1
);
pQueryHandle
->
pTableQueryInfo
=
taosArrayInit
(
size
,
sizeof
(
STableQueryInfo
));
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableId
id
=
*
(
STableId
*
)
taosArrayGet
(
idList
,
i
);
STableQueryInfo
info
=
{
.
lastKey
=
pQueryHandle
->
window
.
skey
,
.
tableId
=
id
,
.
pTableObj
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
id
.
uid
),
//todo this may be failed
};
taosArrayPush
(
pQueryHandle
->
pTableQueryInfo
,
&
info
);
}
p
TableQRec
->
pTableObj
=
pTable
;
p
QueryHandle
->
activeIndex
=
0
;
// malloc buffer in order to load data from file
int32_t
numOfCols
=
taosArrayGetSize
(
pColumnInfo
);
...
...
@@ -313,7 +316,9 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
bool
tsdbNextDataBlock
(
tsdb_query_handle_t
*
pQueryHandle
)
{
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
STable
*
pTable
=
pHandle
->
pTableQueryInfo
->
pTableObj
;
STableQueryInfo
*
pTableQInfo
=
taosArrayGet
(
pHandle
->
pTableQueryInfo
,
pHandle
->
activeIndex
);
STable
*
pTable
=
pTableQInfo
->
pTableObj
;
// no data in cache, abort
if
(
pTable
->
mem
==
NULL
&&
pTable
->
imem
==
NULL
)
{
...
...
@@ -321,7 +326,7 @@ bool tsdbNextDataBlock(tsdb_query_handle_t *pQueryHandle) {
}
// all data in mem are checked already.
if
(
p
Handle
->
pTableQuery
Info
->
lastKey
>
pTable
->
mem
->
keyLast
)
{
if
(
p
TableQ
Info
->
lastKey
>
pTable
->
mem
->
keyLast
)
{
return
false
;
}
...
...
@@ -364,9 +369,9 @@ static int tsdbReadRowsFromCache(SSkipListIterator *pIter, TSKEY maxKey, int max
// copy data from cache into data block
SDataBlockInfo
tsdbRetrieveDataBlockInfo
(
tsdb_query_handle_t
*
pQueryHandle
)
{
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
STableIdInfo
*
idInfo
=
taosArrayGet
(
pHandle
->
pTableIdList
,
0
);
STable
*
pTable
=
pHandle
->
pTableQueryInfo
->
pTableObj
;
STableQueryInfo
*
pTableQInfo
=
taosArrayGet
(
pHandle
->
pTableQueryInfo
,
pHandle
->
activeIndex
);
STable
*
pTable
=
pTableQInfo
->
pTableObj
;
TSKEY
skey
=
0
,
ekey
=
0
;
int32_t
rows
=
0
;
...
...
@@ -382,14 +387,14 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(tsdb_query_handle_t *pQueryHandle) {
}
SDataBlockInfo
blockInfo
=
{
.
uid
=
idInfo
->
uid
,
.
sid
=
idInfo
->
s
id
,
.
uid
=
pTable
->
tableId
.
uid
,
.
sid
=
pTable
->
tableId
.
t
id
,
.
size
=
rows
,
.
window
=
{.
skey
=
skey
,
.
ekey
=
ekey
}
};
// update the last key value
p
Handle
->
pTableQuery
Info
->
lastKey
=
ekey
+
1
;
p
TableQ
Info
->
lastKey
=
ekey
+
1
;
return
blockInfo
;
}
...
...
@@ -427,7 +432,9 @@ static SArray* createTableIdArrayList(struct STsdbRepo* tsdb, int64_t uid) {
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
pTable
->
pIndex
);
while
(
tSkipListIterNext
(
iter
))
{
STable
*
t
=
*
(
STable
**
)
tSkipListIterGet
(
iter
);
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
STable
*
t
=
*
(
STable
**
)
SL_GET_NODE_DATA
(
pNode
);
taosArrayPush
(
pList
,
&
t
->
tableId
);
}
...
...
@@ -696,7 +703,7 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
return
true
;
}
static
int32_t
mgmtFilterMeterByIndex
(
STable
*
pSTable
,
SArray
*
pRes
,
const
char
*
pCond
)
{
static
int32_t
doQueryTableList
(
STable
*
pSTable
,
SArray
*
pRes
,
const
char
*
pCond
)
{
STColumn
*
stcol
=
schemaColAt
(
pSTable
->
tagSchema
,
0
);
tSQLBinaryExpr
*
pExpr
=
NULL
;
...
...
@@ -736,7 +743,7 @@ SArray *tsdbQueryTableList(struct STsdbRepo* tsdb, int64_t uid, const wchar_t *p
STable
*
pSTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
assert
(
pSTable
!=
NULL
);
if
(
mgmtFilterMeterByIndex
(
pSTable
,
result
,
str
)
==
TSDB_CODE_SUCCESS
)
{
if
(
doQueryTableList
(
pSTable
,
result
,
str
)
==
TSDB_CODE_SUCCESS
)
{
return
result
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录