Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
758bd5dc
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
758bd5dc
编写于
6月 22, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
6月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2405 from taosdata/feature/query
Feature/query
上级
b3380242
26a22720
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
422 addition
and
606 deletion
+422
-606
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+4
-10
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+6
-7
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+14
-15
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+13
-9
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+1
-1
src/client/src/tscServer.c
src/client/src/tscServer.c
+33
-182
src/client/src/tscSql.c
src/client/src/tscSql.c
+1
-2
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+22
-20
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+33
-61
src/inc/taosdef.h
src/inc/taosdef.h
+1
-1
src/inc/tsdb.h
src/inc/tsdb.h
+19
-40
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+7
-7
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+149
-153
src/query/src/qUtil.c
src/query/src/qUtil.c
+0
-2
src/query/src/qresultBuf.c
src/query/src/qresultBuf.c
+2
-2
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+10
-11
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+105
-83
tests/script/general/parser/commit.sim
tests/script/general/parser/commit.sim
+1
-0
tests/script/general/parser/selectResNum.sim
tests/script/general/parser/selectResNum.sim
+1
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
758bd5dc
...
@@ -89,27 +89,21 @@ typedef struct SVgroupTableInfo {
...
@@ -89,27 +89,21 @@ typedef struct SVgroupTableInfo {
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
char
*
name
,
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
);
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
);
void
tscAppendDataBlock
(
SDataBlockList
*
pList
,
STableDataBlocks
*
pBlocks
);
void
tscDestroyDataBlock
(
STableDataBlocks
*
pDataBlock
);
void
tscDestroyDataBlock
(
STableDataBlocks
*
pDataBlock
);
void
tscSortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
);
void
tscSortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
);
SParamInfo
*
tscAddParamToDataBlock
(
STableDataBlocks
*
pDataBlock
,
char
type
,
uint8_t
timePrec
,
short
bytes
,
SParamInfo
*
tscAddParamToDataBlock
(
STableDataBlocks
*
pDataBlock
,
char
type
,
uint8_t
timePrec
,
short
bytes
,
uint32_t
offset
);
uint32_t
offset
);
SDataBlockList
*
tscCreateBlockArrayList
();
void
*
tscDestroyBlockArrayList
(
SArray
*
pDataBlockList
);
void
*
tscDestroyBlockArrayList
(
SDataBlockList
*
pList
);
int32_t
tscCopyDataBlockToPayload
(
SSqlObj
*
pSql
,
STableDataBlocks
*
pDataBlock
);
int32_t
tscCopyDataBlockToPayload
(
SSqlObj
*
pSql
,
STableDataBlocks
*
pDataBlock
);
void
tscFreeUnusedDataBlocks
(
S
DataBlockList
*
p
List
);
void
tscFreeUnusedDataBlocks
(
S
Array
*
pDataBlock
List
);
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
,
S
DataBlockList
*
pDataList
);
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
,
S
Array
*
pDataList
);
int32_t
tscGetDataBlockFromList
(
void
*
pHashList
,
S
DataBlockList
*
pDataBlockList
,
int64_t
id
,
int32_t
size
,
int32_t
tscGetDataBlockFromList
(
void
*
pHashList
,
S
Array
*
pDataBlockList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
);
STableDataBlocks
**
dataBlocks
);
//UNUSED_FUNC STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
/**
/**
*
* for the projection query on metric or point interpolation query on metric,
* for the projection query on metric or point interpolation query on metric,
* we iterate all the meters, instead of invoke query on all qualified meters simultaneously.
* we iterate all the meters, instead of invoke query on all qualified meters simultaneously.
*
*
...
...
src/client/inc/tsclient.h
浏览文件 @
758bd5dc
...
@@ -183,11 +183,11 @@ typedef struct STableDataBlocks {
...
@@ -183,11 +183,11 @@ typedef struct STableDataBlocks {
SParamInfo
*
params
;
SParamInfo
*
params
;
}
STableDataBlocks
;
}
STableDataBlocks
;
typedef
struct
SDataBlockList
{
// todo remove
//
typedef struct SDataBlockList { // todo remove
uint32_t
nSize
;
//
uint32_t nSize;
uint32_t
nAlloc
;
//
uint32_t nAlloc;
STableDataBlocks
**
pData
;
//
STableDataBlocks **pData;
}
SDataBlockList
;
//
} SDataBlockList;
typedef
struct
SQueryInfo
{
typedef
struct
SQueryInfo
{
int16_t
command
;
// the command may be different for each subclause, so keep it seperately.
int16_t
command
;
// the command may be different for each subclause, so keep it seperately.
...
@@ -238,8 +238,7 @@ typedef struct {
...
@@ -238,8 +238,7 @@ typedef struct {
void
*
pTableList
;
// referred table involved in sql
void
*
pTableList
;
// referred table involved in sql
int32_t
batchSize
;
// for parameter ('?') binding and batch processing
int32_t
batchSize
;
// for parameter ('?') binding and batch processing
int32_t
numOfParams
;
int32_t
numOfParams
;
SArray
*
pDataBlocks
;
// SArray<STableDataBlocks*> submit data blocks after parsing sql
SDataBlockList
*
pDataBlocks
;
// submit data blocks after parsing sql
}
SSqlCmd
;
}
SSqlCmd
;
typedef
struct
SResRec
{
typedef
struct
SResRec
{
...
...
src/client/src/tscParseInsert.c
浏览文件 @
758bd5dc
...
@@ -1040,8 +1040,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
...
@@ -1040,8 +1040,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
if
(
NULL
==
pCmd
->
pTableList
)
{
if
(
NULL
==
pCmd
->
pTableList
)
{
pCmd
->
pTableList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
);
pCmd
->
pTableList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
);
pCmd
->
pDataBlocks
=
taosArrayInit
(
4
,
POINTER_BYTES
);
pSql
->
cmd
.
pDataBlocks
=
tscCreateBlockArrayList
();
if
(
NULL
==
pCmd
->
pTableList
||
NULL
==
pSql
->
cmd
.
pDataBlocks
)
{
if
(
NULL
==
pCmd
->
pTableList
||
NULL
==
pSql
->
cmd
.
pDataBlocks
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
_error
;
goto
_error
;
...
@@ -1174,7 +1173,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
...
@@ -1174,7 +1173,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
goto
_error
;
goto
_error
;
}
}
t
scAppendDataBlock
(
pCmd
->
pDataBlocks
,
pDataBlock
);
t
aosArrayPush
(
pCmd
->
pDataBlocks
,
&
pDataBlock
);
strcpy
(
pDataBlock
->
filename
,
fname
);
strcpy
(
pDataBlock
->
filename
,
fname
);
}
else
if
(
sToken
.
type
==
TK_LP
)
{
}
else
if
(
sToken
.
type
==
TK_LP
)
{
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
...
@@ -1262,7 +1261,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
...
@@ -1262,7 +1261,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
goto
_clean
;
goto
_clean
;
}
}
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
// merge according to vgId
if
(
taosArrayGetSize
(
pCmd
->
pDataBlocks
)
>
0
)
{
// merge according to vgId
if
((
code
=
tscMergeTableDataBlocks
(
pSql
,
pCmd
->
pDataBlocks
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscMergeTableDataBlocks
(
pSql
,
pCmd
->
pDataBlocks
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
goto
_error
;
}
}
...
@@ -1372,8 +1371,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
...
@@ -1372,8 +1371,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
return
code
;
return
code
;
}
}
// the pDataBlock is different from the pTableDataBlocks
STableDataBlocks
*
pDataBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
0
);
STableDataBlocks
*
pDataBlock
=
pCmd
->
pDataBlocks
->
pData
[
0
];
if
((
code
=
tscCopyDataBlockToPayload
(
pSql
,
pDataBlock
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscCopyDataBlockToPayload
(
pSql
,
pDataBlock
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
@@ -1404,15 +1402,15 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
...
@@ -1404,15 +1402,15 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
int32_t
rowSize
=
tinfo
.
rowSize
;
int32_t
rowSize
=
tinfo
.
rowSize
;
pCmd
->
pDataBlocks
=
t
scCreateBlockArrayList
(
);
pCmd
->
pDataBlocks
=
t
aosArrayInit
(
4
,
POINTER_BYTES
);
STableDataBlocks
*
pTableDataBlock
=
NULL
;
STableDataBlocks
*
pTableDataBlock
=
NULL
;
int32_t
ret
=
tscCreateDataBlock
(
TSDB_PAYLOAD_SIZE
,
rowSize
,
sizeof
(
SSubmitBlk
),
pTableMetaInfo
->
name
,
pTableMeta
,
&
pTableDataBlock
);
int32_t
ret
=
tscCreateDataBlock
(
TSDB_PAYLOAD_SIZE
,
rowSize
,
sizeof
(
SSubmitBlk
),
pTableMetaInfo
->
name
,
pTableMeta
,
&
pTableDataBlock
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
-
1
;
return
ret
;
}
}
t
scAppendDataBlock
(
pCmd
->
pDataBlocks
,
pTableDataBlock
);
t
aosArrayPush
(
pCmd
->
pDataBlocks
,
&
pTableDataBlock
);
code
=
tscAllocateMemIfNeed
(
pTableDataBlock
,
rowSize
,
&
maxRows
);
code
=
tscAllocateMemIfNeed
(
pTableDataBlock
,
rowSize
,
&
maxRows
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
return
-
1
;
if
(
TSDB_CODE_SUCCESS
!=
code
)
return
-
1
;
...
@@ -1446,7 +1444,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
...
@@ -1446,7 +1444,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
return
-
code
;
return
-
code
;
}
}
pTableDataBlock
=
pCmd
->
pDataBlocks
->
pData
[
0
]
;
pTableDataBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
0
)
;
pTableDataBlock
->
size
=
sizeof
(
SSubmitBlk
);
pTableDataBlock
->
size
=
sizeof
(
SSubmitBlk
);
pTableDataBlock
->
rowSize
=
tinfo
.
rowSize
;
pTableDataBlock
->
rowSize
=
tinfo
.
rowSize
;
...
@@ -1483,13 +1481,14 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) {
...
@@ -1483,13 +1481,14 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) {
int32_t
affected_rows
=
0
;
int32_t
affected_rows
=
0
;
assert
(
pCmd
->
dataSourceType
==
DATA_FROM_DATA_FILE
&&
pCmd
->
pDataBlocks
!=
NULL
);
assert
(
pCmd
->
dataSourceType
==
DATA_FROM_DATA_FILE
&&
pCmd
->
pDataBlocks
!=
NULL
);
S
DataBlockList
*
pDataBlockList
=
pCmd
->
pDataBlocks
;
S
Array
*
pDataBlockList
=
pCmd
->
pDataBlocks
;
pCmd
->
pDataBlocks
=
NULL
;
pCmd
->
pDataBlocks
=
NULL
;
char
path
[
PATH_MAX
]
=
{
0
};
char
path
[
PATH_MAX
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pDataBlockList
->
nSize
;
++
i
)
{
size_t
size
=
taosArrayGetSize
(
pDataBlockList
);
pDataBlock
=
pDataBlockList
->
pData
[
i
];
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
pDataBlock
=
taosArrayGetP
(
pDataBlockList
,
i
);
if
(
pDataBlock
==
NULL
)
{
if
(
pDataBlock
==
NULL
)
{
continue
;
continue
;
}
}
...
...
src/client/src/tscPrepare.c
浏览文件 @
758bd5dc
...
@@ -331,8 +331,9 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
...
@@ -331,8 +331,9 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
binded
=
pCmd
->
batchSize
/
2
;
binded
=
pCmd
->
batchSize
/
2
;
}
}
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pDataBlocks
->
nSize
;
++
i
)
{
size_t
size
=
taosArrayGetSize
(
pCmd
->
pDataBlocks
);
STableDataBlocks
*
pBlock
=
pCmd
->
pDataBlocks
->
pData
[
i
];
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableDataBlocks
*
pBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
i
);
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
uint32_t
dataSize
=
totalDataSize
/
alloced
;
uint32_t
dataSize
=
totalDataSize
/
alloced
;
assert
(
dataSize
*
alloced
==
totalDataSize
);
assert
(
dataSize
*
alloced
==
totalDataSize
);
...
@@ -370,8 +371,9 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
...
@@ -370,8 +371,9 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pDataBlocks
->
nSize
;
++
i
)
{
size_t
total
=
taosArrayGetSize
(
pCmd
->
pDataBlocks
);
STableDataBlocks
*
pBlock
=
pCmd
->
pDataBlocks
->
pData
[
i
];
for
(
int32_t
i
=
0
;
i
<
total
;
++
i
)
{
STableDataBlocks
*
pBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
i
);
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
pBlock
->
size
+=
totalDataSize
/
alloced
;
pBlock
->
size
+=
totalDataSize
/
alloced
;
...
@@ -395,8 +397,10 @@ static int insertStmtReset(STscStmt* pStmt) {
...
@@ -395,8 +397,10 @@ static int insertStmtReset(STscStmt* pStmt) {
SSqlCmd
*
pCmd
=
&
pStmt
->
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pStmt
->
pSql
->
cmd
;
if
(
pCmd
->
batchSize
>
2
)
{
if
(
pCmd
->
batchSize
>
2
)
{
int32_t
alloced
=
(
pCmd
->
batchSize
+
1
)
/
2
;
int32_t
alloced
=
(
pCmd
->
batchSize
+
1
)
/
2
;
for
(
int32_t
i
=
0
;
i
<
pCmd
->
pDataBlocks
->
nSize
;
++
i
)
{
STableDataBlocks
*
pBlock
=
pCmd
->
pDataBlocks
->
pData
[
i
];
size_t
size
=
taosArrayGetSize
(
pCmd
->
pDataBlocks
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableDataBlocks
*
pBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
i
);
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
pBlock
->
size
=
sizeof
(
SSubmitBlk
)
+
totalDataSize
/
alloced
;
pBlock
->
size
=
sizeof
(
SSubmitBlk
)
+
totalDataSize
/
alloced
;
...
@@ -423,15 +427,15 @@ static int insertStmtExecute(STscStmt* stmt) {
...
@@ -423,15 +427,15 @@ static int insertStmtExecute(STscStmt* stmt) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
assert
(
pCmd
->
numOfClause
==
1
);
assert
(
pCmd
->
numOfClause
==
1
);
if
(
pCmd
->
pDataBlocks
->
nSize
>
0
)
{
if
(
taosArrayGetSize
(
pCmd
->
pDataBlocks
)
>
0
)
{
// merge according to vgid
// merge according to vgid
int
code
=
tscMergeTableDataBlocks
(
stmt
->
pSql
,
pCmd
->
pDataBlocks
);
int
code
=
tscMergeTableDataBlocks
(
stmt
->
pSql
,
pCmd
->
pDataBlocks
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
STableDataBlocks
*
pDataBlock
=
pCmd
->
pDataBlocks
->
pData
[
0
]
;
STableDataBlocks
*
pDataBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
0
)
;
code
=
tscCopyDataBlockToPayload
(
stmt
->
pSql
,
pDataBlock
);
code
=
tscCopyDataBlockToPayload
(
stmt
->
pSql
,
pDataBlock
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
758bd5dc
...
@@ -4463,7 +4463,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
...
@@ -4463,7 +4463,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
SUpdateTableTagValMsg
*
pUpdateMsg
=
(
SUpdateTableTagValMsg
*
)
(
pCmd
->
payload
+
tsRpcHeadSize
)
;
SUpdateTableTagValMsg
*
pUpdateMsg
=
(
SUpdateTableTagValMsg
*
)
pCmd
->
payload
;
pUpdateMsg
->
head
.
vgId
=
htonl
(
pTableMeta
->
vgroupInfo
.
vgId
);
pUpdateMsg
->
head
.
vgId
=
htonl
(
pTableMeta
->
vgroupInfo
.
vgId
);
pUpdateMsg
->
tid
=
htonl
(
pTableMeta
->
sid
);
pUpdateMsg
->
tid
=
htonl
(
pTableMeta
->
sid
);
pUpdateMsg
->
uid
=
htobe64
(
pTableMeta
->
uid
);
pUpdateMsg
->
uid
=
htobe64
(
pTableMeta
->
uid
);
...
...
src/client/src/tscServer.c
浏览文件 @
758bd5dc
...
@@ -176,18 +176,16 @@ int tscSendMsgToServer(SSqlObj *pSql) {
...
@@ -176,18 +176,16 @@ int tscSendMsgToServer(SSqlObj *pSql) {
char
*
pMsg
=
rpcMallocCont
(
pCmd
->
payloadLen
);
char
*
pMsg
=
rpcMallocCont
(
pCmd
->
payloadLen
);
if
(
NULL
==
pMsg
)
{
if
(
NULL
==
pMsg
)
{
tscError
(
"%p msg:%s malloc fail"
,
pSql
,
taosMsg
[
pSql
->
cmd
.
msgType
]);
tscError
(
"%p msg:%s malloc fail
ed
"
,
pSql
,
taosMsg
[
pSql
->
cmd
.
msgType
]);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
if
(
pSql
->
cmd
.
command
<
TSDB_SQL_MGMT
)
{
// set the mgmt ip list
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
+
tsRpcHeadSize
,
pSql
->
cmd
.
payloadLen
);
if
(
pSql
->
cmd
.
command
>=
TSDB_SQL_MGMT
)
{
}
else
{
pSql
->
ipList
=
tscMgmtIpSet
;
pSql
->
ipList
=
tscMgmtIpSet
;
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
,
pSql
->
cmd
.
payloadLen
);
}
}
// tscTrace("%p msg:%s is sent to server", pSql, taosMsg[pSql->cmd.msgType]
);
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
,
pSql
->
cmd
.
payloadLen
);
SRpcMsg
rpcMsg
=
{
SRpcMsg
rpcMsg
=
{
.
msgType
=
pSql
->
cmd
.
msgType
,
.
msgType
=
pSql
->
cmd
.
msgType
,
...
@@ -222,8 +220,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
...
@@ -222,8 +220,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
if
(
pQueryInfo
!=
NULL
&&
pQueryInfo
->
type
==
TSDB_QUERY_TYPE_FREE_RESOURCE
)
{
if
(
pQueryInfo
!=
NULL
&&
pQueryInfo
->
type
==
TSDB_QUERY_TYPE_FREE_RESOURCE
)
{
tscTrace
(
"%p sqlObj needs to be released or DB connection is closed, cmd:%d
pObj:%p signature:%p"
,
pSql
,
pCmd
->
command
,
tscTrace
(
"%p sqlObj needs to be released or DB connection is closed, cmd:%d
type:%d, pObj:%p signature:%p"
,
pObj
,
pObj
->
signature
);
pSql
,
pCmd
->
command
,
pQueryInfo
->
type
,
pObj
,
pObj
->
signature
);
tscFreeSqlObj
(
pSql
);
tscFreeSqlObj
(
pSql
);
rpcFreeCont
(
rpcMsg
->
pCont
);
rpcFreeCont
(
rpcMsg
->
pCont
);
...
@@ -449,18 +447,11 @@ void tscKillSTableQuery(SSqlObj *pSql) {
...
@@ -449,18 +447,11 @@ void tscKillSTableQuery(SSqlObj *pSql) {
}
}
int
tscBuildFetchMsg
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
{
int
tscBuildFetchMsg
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
{
char
*
pMsg
,
*
pStart
;
SRetrieveTableMsg
*
pRetrieveMsg
=
(
SRetrieveTableMsg
*
)
pSql
->
cmd
.
payload
;
pStart
=
pSql
->
cmd
.
payload
+
tsRpcHeadSize
;
pMsg
=
pStart
;
SRetrieveTableMsg
*
pRetrieveMsg
=
(
SRetrieveTableMsg
*
)
pMsg
;
pRetrieveMsg
->
qhandle
=
htobe64
(
pSql
->
res
.
qhandle
);
pRetrieveMsg
->
qhandle
=
htobe64
(
pSql
->
res
.
qhandle
);
pMsg
+=
sizeof
(
pSql
->
res
.
qhandle
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
pRetrieveMsg
->
free
=
htons
(
pQueryInfo
->
type
);
pRetrieveMsg
->
free
=
htons
(
pQueryInfo
->
type
);
pMsg
+=
sizeof
(
pQueryInfo
->
type
);
// todo valid the vgroupId at the client side
// todo valid the vgroupId at the client side
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
...
@@ -474,12 +465,12 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -474,12 +465,12 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
pRetrieveMsg
->
header
.
vgId
=
htonl
(
pTableMeta
->
vgroupInfo
.
vgId
);
pRetrieveMsg
->
header
.
vgId
=
htonl
(
pTableMeta
->
vgroupInfo
.
vgId
);
}
}
pMsg
+=
sizeof
(
SRetrieveTableMsg
);
pSql
->
cmd
.
payloadLen
=
sizeof
(
SRetrieveTableMsg
);
pRetrieveMsg
->
header
.
contLen
=
htonl
(
pSql
->
cmd
.
payloadLen
);
pSql
->
cmd
.
msgType
=
TSDB_MSG_TYPE_FETCH
;
pSql
->
cmd
.
msgType
=
TSDB_MSG_TYPE_FETCH
;
pRetrieveMsg
->
header
.
contLen
=
htonl
(
sizeof
(
SRetrieveTableMsg
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -487,30 +478,30 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -487,30 +478,30 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
char
*
pMsg
=
pSql
->
cmd
.
payload
+
tsRpcHeadSize
;
char
*
pMsg
=
pSql
->
cmd
.
payload
;
// NOTE: shell message size should not include SMsgDesc
// NOTE: shell message size should not include SMsgDesc
int32_t
size
=
pSql
->
cmd
.
payloadLen
-
sizeof
(
SMsgDesc
);
int32_t
size
=
pSql
->
cmd
.
payloadLen
-
sizeof
(
SMsgDesc
);
int32_t
vgId
=
pTableMeta
->
vgroupInfo
.
vgId
;
SMsgDesc
*
pMsgDesc
=
(
SMsgDesc
*
)
pMsg
;
SMsgDesc
*
pMsgDesc
=
(
SMsgDesc
*
)
pMsg
;
pMsgDesc
->
numOfVnodes
=
htonl
(
1
);
// always one vnode
pMsgDesc
->
numOfVnodes
=
htonl
(
1
);
//todo set the right number of vnodes
pMsg
+=
sizeof
(
SMsgDesc
);
pMsg
+=
sizeof
(
SMsgDesc
);
SSubmitMsg
*
pShellMsg
=
(
SSubmitMsg
*
)
pMsg
;
SSubmitMsg
*
pShellMsg
=
(
SSubmitMsg
*
)
pMsg
;
int32_t
vgId
=
pTableMeta
->
vgroupInfo
.
vgId
;
pShellMsg
->
header
.
vgId
=
htonl
(
vgId
);
pShellMsg
->
header
.
vgId
=
htonl
(
vgId
);
pShellMsg
->
header
.
contLen
=
htonl
(
size
);
pShellMsg
->
header
.
contLen
=
htonl
(
size
);
// the length not includes the size of SMsgDesc
pShellMsg
->
length
=
pShellMsg
->
header
.
contLen
;
pShellMsg
->
length
=
pShellMsg
->
header
.
contLen
;
pShellMsg
->
numOfBlocks
=
htonl
(
pSql
->
cmd
.
numOfTablesInSubmit
);
// number of
meter
s to be inserted
pShellMsg
->
numOfBlocks
=
htonl
(
pSql
->
cmd
.
numOfTablesInSubmit
);
// number of
table
s to be inserted
// pSql->cmd.payloadLen is set during copying data into payload
// pSql->cmd.payloadLen is set during copying data into payload
pSql
->
cmd
.
msgType
=
TSDB_MSG_TYPE_SUBMIT
;
pSql
->
cmd
.
msgType
=
TSDB_MSG_TYPE_SUBMIT
;
tscSetDnodeIpList
(
pSql
,
&
pTableMeta
->
vgroupInfo
);
tscSetDnodeIpList
(
pSql
,
&
pTableMeta
->
vgroupInfo
);
tscTrace
(
"%p build submit msg, vgId:%d numOfVgroup:%d numberOfIP:%d"
,
pSql
,
vgId
,
htonl
(
pMsgDesc
->
numOfVnodes
),
pSql
->
ipList
.
numOfIps
);
tscTrace
(
"%p build submit msg, vgId:%d numOfTables:%d numberOfIP:%d"
,
pSql
,
vgId
,
pSql
->
cmd
.
numOfTablesInSubmit
,
pSql
->
ipList
.
numOfIps
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -620,9 +611,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -620,9 +611,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
-
1
;
return
-
1
;
}
}
char
*
pStart
=
pCmd
->
payload
+
tsRpcHeadSize
;
SQueryTableMsg
*
pQueryMsg
=
(
SQueryTableMsg
*
)
pCmd
->
payload
;
SQueryTableMsg
*
pQueryMsg
=
(
SQueryTableMsg
*
)
pStart
;
int32_t
numOfTags
=
taosArrayGetSize
(
pTableMetaInfo
->
tagColList
);
int32_t
numOfTags
=
taosArrayGetSize
(
pTableMetaInfo
->
tagColList
);
...
@@ -821,7 +810,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -821,7 +810,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
// compressed ts block
// compressed ts block
pQueryMsg
->
tsOffset
=
htonl
(
pMsg
-
p
Start
);
pQueryMsg
->
tsOffset
=
htonl
(
pMsg
-
p
Cmd
->
payload
);
int32_t
tsLen
=
0
;
int32_t
tsLen
=
0
;
int32_t
numOfBlocks
=
0
;
int32_t
numOfBlocks
=
0
;
...
@@ -844,7 +833,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -844,7 +833,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
tsOrder
=
htonl
(
pQueryInfo
->
tsBuf
->
tsOrder
);
pQueryMsg
->
tsOrder
=
htonl
(
pQueryInfo
->
tsBuf
->
tsOrder
);
}
}
int32_t
msgLen
=
pMsg
-
p
Start
;
int32_t
msgLen
=
pMsg
-
p
Cmd
->
payload
;
tscTrace
(
"%p msg built success,len:%d bytes"
,
pSql
,
msgLen
);
tscTrace
(
"%p msg built success,len:%d bytes"
,
pSql
,
msgLen
);
pCmd
->
payloadLen
=
msgLen
;
pCmd
->
payloadLen
=
msgLen
;
...
@@ -1286,10 +1275,12 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) {
...
@@ -1286,10 +1275,12 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_UPDATE_TAG_VAL
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_UPDATE_TAG_VAL
;
SUpdateTableTagValMsg
*
pUpdateMsg
=
(
SUpdateTableTagValMsg
*
)
(
pCmd
->
payload
+
tsRpcHeadSize
)
;
SUpdateTableTagValMsg
*
pUpdateMsg
=
(
SUpdateTableTagValMsg
*
)
pCmd
->
payload
;
pCmd
->
payloadLen
=
htonl
(
pUpdateMsg
->
head
.
contLen
);
pCmd
->
payloadLen
=
htonl
(
pUpdateMsg
->
head
.
contLen
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
tscSetDnodeIpList
(
pSql
,
&
pTableMetaInfo
->
pTableMeta
->
vgroupInfo
);
tscSetDnodeIpList
(
pSql
,
&
pTableMetaInfo
->
pTableMeta
->
vgroupInfo
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1552,150 +1543,6 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1552,150 +1543,6 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
//}
//}
int
tscBuildSTableVgroupMsg
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
{
int
tscBuildSTableVgroupMsg
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
{
#if 0
SSuperTableMetaMsg *pMetaMsg;
char * pMsg, *pStart;
int msgLen = 0;
int tableIndex = 0;
SSqlCmd * pCmd = &pSql->cmd;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
STagCond *pTagCond = &pQueryInfo->tagCond;
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex);
int32_t size = tscEstimateMetricMetaMsgSize(pCmd);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for metric meter msg", pSql);
return -1;
}
pStart = pCmd->payload + tsRpcHeadSize;
pMsg = pStart;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg;
tscGetDBInfoFromTableFullName(pTableMetaInfo->name, pMgmt->db);
pMsg += sizeof(SMgmtHead);
pMetaMsg = (SSuperTableMetaMsg *)pMsg;
pMetaMsg->numOfTables = htonl(pQueryInfo->numOfTables);
pMsg += sizeof(SSuperTableMetaMsg);
int32_t offset = pMsg - (char *)pMetaMsg;
pMetaMsg->join = htonl(offset);
// todo refactor
pMetaMsg->joinCondLen = htonl((TSDB_TABLE_ID_LEN + sizeof(int16_t)) * 2);
memcpy(pMsg, pTagCond->joinInfo.left.tableId, TSDB_TABLE_ID_LEN);
pMsg += TSDB_TABLE_ID_LEN;
*(int16_t *)pMsg = pTagCond->joinInfo.left.tagCol;
pMsg += sizeof(int16_t);
memcpy(pMsg, pTagCond->joinInfo.right.tableId, TSDB_TABLE_ID_LEN);
pMsg += TSDB_TABLE_ID_LEN;
*(int16_t *)pMsg = pTagCond->joinInfo.right.tagCol;
pMsg += sizeof(int16_t);
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, i);
uint64_t uid = pTableMetaInfo->pTableMeta->uid;
offset = pMsg - (char *)pMetaMsg;
pMetaMsg->metaElem[i] = htonl(offset);
SSuperTableMetaElemMsg *pElem = (SSuperTableMetaElemMsg *)pMsg;
pMsg += sizeof(SSuperTableMetaElemMsg);
// convert to unicode before sending to mnode for metric query
int32_t condLen = 0;
if (pTagCond->numOfTagCond > 0) {
SCond *pCond = tsGetSTableQueryCond(pTagCond, uid);
if (pCond != NULL && pCond->cond != NULL) {
condLen = strlen(pCond->cond) + 1;
bool ret = taosMbsToUcs4(pCond->cond, condLen, pMsg, condLen * TSDB_NCHAR_SIZE);
if (!ret) {
tscError("%p mbs to ucs4 failed:%s", pSql, tsGetSTableQueryCond(pTagCond, uid));
return 0;
}
}
}
pElem->condLen = htonl(condLen);
offset = pMsg - (char *)pMetaMsg;
pElem->cond = htonl(offset);
pMsg += condLen * TSDB_NCHAR_SIZE;
pElem->rel = htons(pTagCond->relType);
if (pTagCond->tbnameCond.uid == uid) {
offset = pMsg - (char *)pMetaMsg;
pElem->tableCond = htonl(offset);
uint32_t len = 0;
if (pTagCond->tbnameCond.cond != NULL) {
len = strlen(pTagCond->tbnameCond.cond);
memcpy(pMsg, pTagCond->tbnameCond.cond, len);
}
pElem->tableCondLen = htonl(len);
pMsg += len;
}
SSqlGroupbyExpr *pGroupby = &pQueryInfo->groupbyExpr;
if (pGroupby->tableIndex != i && pGroupby->numOfGroupCols > 0) {
pElem->orderType = 0;
pElem->orderIndex = 0;
pElem->numOfGroupCols = 0;
} else {
pElem->numOfGroupCols = htons(pGroupby->numOfGroupCols);
for (int32_t j = 0; j < pTableMetaInfo->numOfTags; ++j) {
pElem->tagCols[j] = htons(pTableMetaInfo->tagColumnIndex[j]);
}
if (pGroupby->numOfGroupCols != 0) {
pElem->orderIndex = htons(pGroupby->orderIndex);
pElem->orderType = htons(pGroupby->orderType);
offset = pMsg - (char *)pMetaMsg;
pElem->groupbyTagColumnList = htonl(offset);
for (int32_t j = 0; j < pQueryInfo->groupbyExpr.numOfGroupCols; ++j) {
SColIndex *pCol = &pQueryInfo->groupbyExpr.columnInfo[j];
SColIndex *pDestCol = (SColIndex *)pMsg;
pDestCol->colIdxInBuf = 0;
pDestCol->colIndex = htons(pCol->colIndex);
pDestCol->colId = htons(pDestCol->colId);
pDestCol->flag = htons(pDestCol->flag);
strncpy(pDestCol->name, pCol->name, tListLen(pCol->name));
pMsg += sizeof(SColIndex);
}
}
}
strcpy(pElem->tableId, pTableMetaInfo->name);
pElem->numOfTags = htons(pTableMetaInfo->numOfTags);
int16_t len = pMsg - (char *)pElem;
pElem->elemLen = htons(len); // redundant data for integrate check
}
msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_CM_STABLE_VGROUP;
assert(msgLen + minMsgSize() <= size);
#endif
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
char
*
pMsg
=
pCmd
->
payload
;
char
*
pMsg
=
pCmd
->
payload
;
...
@@ -1795,7 +1642,11 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
...
@@ -1795,7 +1642,11 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
for
(
int
i
=
0
;
i
<
numOfTotalCols
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfTotalCols
;
++
i
)
{
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
colId
=
htons
(
pSchema
->
colId
);
pSchema
->
colId
=
htons
(
pSchema
->
colId
);
if
(
pSchema
->
colId
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
assert
(
i
==
0
);
}
assert
(
pSchema
->
type
>=
TSDB_DATA_TYPE_BOOL
&&
pSchema
->
type
<=
TSDB_DATA_TYPE_NCHAR
);
assert
(
pSchema
->
type
>=
TSDB_DATA_TYPE_BOOL
&&
pSchema
->
type
<=
TSDB_DATA_TYPE_NCHAR
);
pSchema
++
;
pSchema
++
;
}
}
...
...
src/client/src/tscSql.c
浏览文件 @
758bd5dc
...
@@ -133,8 +133,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
...
@@ -133,8 +133,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
return
NULL
;
return
NULL
;
}
}
// tsRpcHeaderSize will be updated during RPC initialization, so only after it initialization, this value is valid
tsInsertHeadSize
=
sizeof
(
SMsgDesc
)
+
sizeof
(
SSubmitMsg
);
tsInsertHeadSize
=
tsRpcHeadSize
+
sizeof
(
SMsgDesc
)
+
sizeof
(
SSubmitMsg
);
return
pSql
;
return
pSql
;
}
}
...
...
src/client/src/tscSubquery.c
浏览文件 @
758bd5dc
...
@@ -180,6 +180,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
...
@@ -180,6 +180,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
getTmpfilePath
(
"join-"
,
pSupporter
->
path
);
getTmpfilePath
(
"join-"
,
pSupporter
->
path
);
pSupporter
->
f
=
fopen
(
pSupporter
->
path
,
"w"
);
pSupporter
->
f
=
fopen
(
pSupporter
->
path
,
"w"
);
// todo handle error
if
(
pSupporter
->
f
==
NULL
)
{
if
(
pSupporter
->
f
==
NULL
)
{
tscError
(
"%p failed to create tmp file:%s, reason:%s"
,
pSql
,
pSupporter
->
path
,
strerror
(
errno
));
tscError
(
"%p failed to create tmp file:%s, reason:%s"
,
pSql
,
pSupporter
->
path
,
strerror
(
errno
));
}
}
...
@@ -234,7 +235,7 @@ static UNUSED_FUNC bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
...
@@ -234,7 +235,7 @@ static UNUSED_FUNC bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
/*
/*
* launch secondary stage query to fetch the result that contains timestamp in set
* launch secondary stage query to fetch the result that contains timestamp in set
*/
*/
static
int32_t
tscLaunch
SecondPhase
Subqueries
(
SSqlObj
*
pSql
)
{
static
int32_t
tscLaunch
Real
Subqueries
(
SSqlObj
*
pSql
)
{
int32_t
numOfSub
=
0
;
int32_t
numOfSub
=
0
;
SJoinSupporter
*
pSupporter
=
NULL
;
SJoinSupporter
*
pSupporter
=
NULL
;
...
@@ -249,7 +250,7 @@ static int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
...
@@ -249,7 +250,7 @@ static int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
assert
(
numOfSub
>
0
);
assert
(
numOfSub
>
0
);
// scan all subquery, if one sub query has only ts, ignore it
// scan all subquery, if one sub query has only ts, ignore it
tscTrace
(
"%p start to launch secondary subquer
y
, total:%d, only:%d needs to query"
,
pSql
,
pSql
->
numOfSubs
,
numOfSub
);
tscTrace
(
"%p start to launch secondary subquer
ies
, total:%d, only:%d needs to query"
,
pSql
,
pSql
->
numOfSubs
,
numOfSub
);
//the subqueries that do not actually launch the secondary query to virtual node is set as completed.
//the subqueries that do not actually launch the secondary query to virtual node is set as completed.
SSubqueryState
*
pState
=
pSupporter
->
pState
;
SSubqueryState
*
pState
=
pSupporter
->
pState
;
...
@@ -451,7 +452,7 @@ static UNUSED_FUNC void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupport
...
@@ -451,7 +452,7 @@ static UNUSED_FUNC void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupport
freeJoinSubqueryObj
(
pParentSql
);
freeJoinSubqueryObj
(
pParentSql
);
}
else
{
}
else
{
updateQueryTimeRange
(
pParentQueryInfo
,
&
win
);
updateQueryTimeRange
(
pParentQueryInfo
,
&
win
);
tscLaunch
SecondPhase
Subqueries
(
pParentSql
);
tscLaunch
Real
Subqueries
(
pParentSql
);
}
}
}
}
...
@@ -851,7 +852,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
...
@@ -851,7 +852,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
// launch the query the retrieve actual results from vnode along with the filtered timestamp
// launch the query the retrieve actual results from vnode along with the filtered timestamp
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
pParentSql
->
cmd
.
clauseIndex
);
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
pParentSql
->
cmd
.
clauseIndex
);
updateQueryTimeRange
(
pPQueryInfo
,
&
win
);
updateQueryTimeRange
(
pPQueryInfo
,
&
win
);
tscLaunch
SecondPhase
Subqueries
(
pParentSql
);
tscLaunch
Real
Subqueries
(
pParentSql
);
}
}
static
void
joinRetrieveFinalResCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
static
void
joinRetrieveFinalResCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
...
@@ -1159,7 +1160,6 @@ static void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code);
...
@@ -1159,7 +1160,6 @@ static void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code);
static
SSqlObj
*
tscCreateSqlObjForSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
);
static
SSqlObj
*
tscCreateSqlObjForSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
);
// todo merge with callback
int32_t
tscLaunchJoinSubquery
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
SJoinSupporter
*
pSupporter
)
{
int32_t
tscLaunchJoinSubquery
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
SJoinSupporter
*
pSupporter
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
...
@@ -1302,7 +1302,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
...
@@ -1302,7 +1302,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
pState
->
numOfTotal
=
pQueryInfo
->
numOfTables
;
pState
->
numOfTotal
=
pQueryInfo
->
numOfTables
;
pState
->
numOfRemain
=
pState
->
numOfTotal
;
pState
->
numOfRemain
=
pState
->
numOfTotal
;
tscTrace
(
"%p start
launch
subquery, total:%d"
,
pSql
,
pQueryInfo
->
numOfTables
);
tscTrace
(
"%p start subquery, total:%d"
,
pSql
,
pQueryInfo
->
numOfTables
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
SJoinSupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
SJoinSupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
...
@@ -1848,8 +1848,6 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1848,8 +1848,6 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
static
void
multiVnodeInsertFinalize
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
static
void
multiVnodeInsertFinalize
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
SInsertSupporter
*
pSupporter
=
(
SInsertSupporter
*
)
param
;
SInsertSupporter
*
pSupporter
=
(
SInsertSupporter
*
)
param
;
SSqlObj
*
pParentObj
=
pSupporter
->
pSql
;
SSqlObj
*
pParentObj
=
pSupporter
->
pSql
;
SSqlCmd
*
pParentCmd
=
&
pParentObj
->
cmd
;
SSubqueryState
*
pState
=
pSupporter
->
pState
;
SSubqueryState
*
pState
=
pSupporter
->
pState
;
// record the total inserted rows
// record the total inserted rows
...
@@ -1864,7 +1862,6 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
...
@@ -1864,7 +1862,6 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
pParentObj
->
res
.
code
=
pSql
->
res
.
code
;
pParentObj
->
res
.
code
=
pSql
->
res
.
code
;
}
}
// it is not the initial sqlObj, free it
taos_free_result
(
tres
);
taos_free_result
(
tres
);
tfree
(
pSupporter
);
tfree
(
pSupporter
);
...
@@ -1876,7 +1873,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
...
@@ -1876,7 +1873,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
// release data block data
// release data block data
tfree
(
pState
);
tfree
(
pState
);
pParentCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pParentCmd
->
pDataBlocks
);
//
pParentCmd->pDataBlocks = tscDestroyBlockArrayList(pParentCmd->pDataBlocks);
// restore user defined fp
// restore user defined fp
pParentObj
->
fp
=
pParentObj
->
fetchFp
;
pParentObj
->
fp
=
pParentObj
->
fetchFp
;
...
@@ -1889,12 +1886,14 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
...
@@ -1889,12 +1886,14 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SDataBlockList
*
pDataBlocks
=
pCmd
->
pDataBlocks
;
size_t
size
=
taosArrayGetSize
(
pCmd
->
pDataBlocks
);
pSql
->
pSubs
=
calloc
(
pDataBlocks
->
nSize
,
POINTER_BYTES
);
assert
(
size
>
0
);
pSql
->
numOfSubs
=
pDataBlocks
->
nSize
;
assert
(
pDataBlocks
->
nSize
>
0
);
pSql
->
pSubs
=
calloc
(
size
,
POINTER_BYTES
);
pSql
->
numOfSubs
=
size
;
tscTrace
(
"%p submit data to %d vnode(s)"
,
pSql
,
pDataBlocks
->
nSize
);
tscTrace
(
"%p submit data to %zu vnode(s)"
,
pSql
,
size
);
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOfRemain
=
pSql
->
numOfSubs
;
pState
->
numOfRemain
=
pSql
->
numOfSubs
;
...
@@ -1920,12 +1919,14 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
...
@@ -1920,12 +1919,14 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
pNew
->
fetchFp
=
pNew
->
fp
;
pNew
->
fetchFp
=
pNew
->
fp
;
pSql
->
pSubs
[
numOfSub
]
=
pNew
;
pSql
->
pSubs
[
numOfSub
]
=
pNew
;
pRes
->
code
=
tscCopyDataBlockToPayload
(
pNew
,
pDataBlocks
->
pData
[
numOfSub
++
]);
STableDataBlocks
*
pTableDataBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
numOfSub
);
pRes
->
code
=
tscCopyDataBlockToPayload
(
pNew
,
pTableDataBlock
);
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
)
{
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
)
{
tscTrace
(
"%p sub:%p create subObj success. orderOfSub:%d"
,
pSql
,
pNew
,
numOfSub
);
tscTrace
(
"%p sub:%p create subObj success. orderOfSub:%d"
,
pSql
,
pNew
,
numOfSub
);
numOfSub
++
;
}
else
{
}
else
{
tscTrace
(
"%p prepare submit data block failed in async insertion, vnodeIdx:%d, total:%
d
, code:%s"
,
pSql
,
numOfSub
,
tscTrace
(
"%p prepare submit data block failed in async insertion, vnodeIdx:%d, total:%
zu
, code:%s"
,
pSql
,
numOfSub
,
pDataBlocks
->
nS
ize
,
tstrerror
(
pRes
->
code
));
s
ize
,
tstrerror
(
pRes
->
code
));
goto
_error
;
goto
_error
;
}
}
}
}
...
@@ -1942,7 +1943,8 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
...
@@ -1942,7 +1943,8 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
tscTrace
(
"%p sub:%p launch sub insert, orderOfSub:%d"
,
pSql
,
pSub
,
j
);
tscTrace
(
"%p sub:%p launch sub insert, orderOfSub:%d"
,
pSql
,
pSub
,
j
);
tscProcessSql
(
pSub
);
tscProcessSql
(
pSub
);
}
}
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_error:
_error:
...
...
src/client/src/tscUtil.c
浏览文件 @
758bd5dc
...
@@ -13,8 +13,6 @@
...
@@ -13,8 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "tscUtil.h"
#include "hash.h"
#include "os.h"
#include "os.h"
#include "qast.h"
#include "qast.h"
#include "taosmsg.h"
#include "taosmsg.h"
...
@@ -29,6 +27,8 @@
...
@@ -29,6 +27,8 @@
#include "ttimer.h"
#include "ttimer.h"
#include "ttokendef.h"
#include "ttokendef.h"
#include "tscLog.h"
#include "tscLog.h"
#include "tscUtil.h"
#include "hash.h"
static
void
freeQueryInfoImpl
(
SQueryInfo
*
pQueryInfo
);
static
void
freeQueryInfoImpl
(
SQueryInfo
*
pQueryInfo
);
static
void
clearAllTableMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
address
,
bool
removeFromCache
);
static
void
clearAllTableMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
address
,
bool
removeFromCache
);
...
@@ -428,48 +428,18 @@ SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint
...
@@ -428,48 +428,18 @@ SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint
return
param
;
return
param
;
}
}
SDataBlockList
*
tscCreateBlockArrayList
()
{
void
*
tscDestroyBlockArrayList
(
SArray
*
pDataBlockList
)
{
const
int32_t
DEFAULT_INITIAL_NUM_OF_BLOCK
=
16
;
if
(
pDataBlockList
==
NULL
)
{
SDataBlockList
*
pDataBlockArrayList
=
calloc
(
1
,
sizeof
(
SDataBlockList
));
if
(
pDataBlockArrayList
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
pDataBlockArrayList
->
nAlloc
=
DEFAULT_INITIAL_NUM_OF_BLOCK
;
pDataBlockArrayList
->
pData
=
calloc
(
1
,
POINTER_BYTES
*
pDataBlockArrayList
->
nAlloc
);
if
(
pDataBlockArrayList
->
pData
==
NULL
)
{
free
(
pDataBlockArrayList
);
return
NULL
;
}
return
pDataBlockArrayList
;
}
void
tscAppendDataBlock
(
SDataBlockList
*
pList
,
STableDataBlocks
*
pBlocks
)
{
if
(
pList
->
nSize
>=
pList
->
nAlloc
)
{
pList
->
nAlloc
=
(
pList
->
nAlloc
)
<<
1U
;
pList
->
pData
=
realloc
(
pList
->
pData
,
POINTER_BYTES
*
(
size_t
)
pList
->
nAlloc
);
// reset allocated memory
size_t
size
=
taosArrayGetSize
(
pDataBlockList
);
memset
(
pList
->
pData
+
pList
->
nSize
,
0
,
POINTER_BYTES
*
(
pList
->
nAlloc
-
pList
->
nSize
));
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
void
*
d
=
taosArrayGetP
(
pDataBlockList
,
i
);
tscDestroyDataBlock
(
d
);
}
}
pList
->
pData
[
pList
->
nSize
++
]
=
pBlocks
;
taosArrayDestroy
(
pDataBlockList
);
}
void
*
tscDestroyBlockArrayList
(
SDataBlockList
*
pList
)
{
if
(
pList
==
NULL
)
{
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
pList
->
nSize
;
i
++
)
{
tscDestroyDataBlock
(
pList
->
pData
[
i
]);
}
tfree
(
pList
->
pData
);
tfree
(
pList
);
return
NULL
;
return
NULL
;
}
}
...
@@ -484,7 +454,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
...
@@ -484,7 +454,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
// set the correct table meta object, the table meta has been locked in pDataBlocks, so it must be in the cache
// set the correct table meta object, the table meta has been locked in pDataBlocks, so it must be in the cache
if
(
pTableMetaInfo
->
pTableMeta
!=
pDataBlock
->
pTableMeta
)
{
if
(
pTableMetaInfo
->
pTableMeta
!=
pDataBlock
->
pTableMeta
)
{
strcpy
(
pTableMetaInfo
->
name
,
pDataBlock
->
tableId
);
tstrncpy
(
pTableMetaInfo
->
name
,
pDataBlock
->
tableId
,
sizeof
(
pTableMetaInfo
->
name
)
);
taosCacheRelease
(
tscCacheHandle
,
(
void
**
)
&
(
pTableMetaInfo
->
pTableMeta
),
false
);
taosCacheRelease
(
tscCacheHandle
,
(
void
**
)
&
(
pTableMetaInfo
->
pTableMeta
),
false
);
pTableMetaInfo
->
pTableMeta
=
taosCacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pDataBlock
->
pTableMeta
);
pTableMetaInfo
->
pTableMeta
=
taosCacheTransfer
(
tscCacheHandle
,
(
void
**
)
&
pDataBlock
->
pTableMeta
);
...
@@ -497,31 +467,32 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
...
@@ -497,31 +467,32 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
* the dataBlock only includes the RPC Header buffer and actual submit message body, space for digest needs
* the dataBlock only includes the RPC Header buffer and actual submit message body, space for digest needs
* additional space.
* additional space.
*/
*/
int
ret
=
tscAllocPayload
(
pCmd
,
pDataBlock
->
nAllocS
ize
+
100
);
int
ret
=
tscAllocPayload
(
pCmd
,
pDataBlock
->
s
ize
+
100
);
if
(
TSDB_CODE_SUCCESS
!=
ret
)
{
if
(
TSDB_CODE_SUCCESS
!=
ret
)
{
return
ret
;
return
ret
;
}
}
memcpy
(
pCmd
->
payload
,
pDataBlock
->
pData
,
pDataBlock
->
nAllocSize
);
assert
(
pDataBlock
->
size
<=
pDataBlock
->
nAllocSize
);
memcpy
(
pCmd
->
payload
,
pDataBlock
->
pData
,
pDataBlock
->
size
);
/*
/*
* the payloadLen should be actual message body size
* the payloadLen should be actual message body size
* the old value of payloadLen is the allocated payload size
* the old value of payloadLen is the allocated payload size
*/
*/
pCmd
->
payloadLen
=
pDataBlock
->
nAllocSize
-
tsRpcHeadS
ize
;
pCmd
->
payloadLen
=
pDataBlock
->
s
ize
;
assert
(
pCmd
->
allocSize
>=
pCmd
->
payloadLen
+
tsRpcHeadSize
+
100
&&
pCmd
->
payloadLen
>
0
);
assert
(
pCmd
->
allocSize
>=
pCmd
->
payloadLen
+
100
&&
pCmd
->
payloadLen
>
0
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
void
tscFreeUnusedDataBlocks
(
SDataBlockList
*
pList
)
{
//
void tscFreeUnusedDataBlocks(SDataBlockList* pList) {
/* release additional memory consumption */
//
/* release additional memory consumption */
for
(
int32_t
i
=
0
;
i
<
pList
->
nSize
;
++
i
)
{
//
for (int32_t i = 0; i < pList->nSize; ++i) {
STableDataBlocks
*
pDataBlock
=
pList
->
pData
[
i
];
//
STableDataBlocks* pDataBlock = pList->pData[i];
pDataBlock
->
pData
=
realloc
(
pDataBlock
->
pData
,
pDataBlock
->
size
);
//
pDataBlock->pData = realloc(pDataBlock->pData, pDataBlock->size);
pDataBlock
->
nAllocSize
=
(
uint32_t
)
pDataBlock
->
size
;
//
pDataBlock->nAllocSize = (uint32_t)pDataBlock->size;
}
//
}
}
//
}
/**
/**
* create the in-memory buffer for each table to keep the submitted data block
* create the in-memory buffer for each table to keep the submitted data block
...
@@ -568,7 +539,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
...
@@ -568,7 +539,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
tscGetDataBlockFromList
(
void
*
pHashList
,
S
DataBlockList
*
pDataBlockList
,
int64_t
id
,
int32_t
size
,
int32_t
tscGetDataBlockFromList
(
void
*
pHashList
,
S
Array
*
pDataBlockList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
STableDataBlocks
**
dataBlocks
)
{
*
dataBlocks
=
NULL
;
*
dataBlocks
=
NULL
;
...
@@ -585,7 +556,7 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
...
@@ -585,7 +556,7 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
}
}
taosHashPut
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
int64_t
),
(
char
*
)
dataBlocks
,
POINTER_BYTES
);
taosHashPut
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
int64_t
),
(
char
*
)
dataBlocks
,
POINTER_BYTES
);
t
scAppendDataBlock
(
pDataBlockList
,
*
dataBlocks
);
t
aosArrayPush
(
pDataBlockList
,
dataBlocks
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -634,14 +605,15 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock) {
...
@@ -634,14 +605,15 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock) {
return
len
;
return
len
;
}
}
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
,
S
DataBlockList
*
pTableDataBlockList
)
{
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
,
S
Array
*
pTableDataBlockList
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
void
*
pVnodeDataBlockHashList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
);
void
*
pVnodeDataBlockHashList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
);
S
DataBlockList
*
pVnodeDataBlockList
=
tscCreateBlockArrayList
(
);
S
Array
*
pVnodeDataBlockList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
for
(
int32_t
i
=
0
;
i
<
pTableDataBlockList
->
nSize
;
++
i
)
{
size_t
total
=
taosArrayGetSize
(
pTableDataBlockList
);
STableDataBlocks
*
pOneTableBlock
=
pTableDataBlockList
->
pData
[
i
];
for
(
int32_t
i
=
0
;
i
<
total
;
++
i
)
{
STableDataBlocks
*
pOneTableBlock
=
taosArrayGetP
(
pTableDataBlockList
,
i
);
STableDataBlocks
*
dataBuf
=
NULL
;
STableDataBlocks
*
dataBuf
=
NULL
;
...
@@ -679,10 +651,10 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
...
@@ -679,10 +651,10 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
tscSortRemoveDataBlockDupRows
(
pOneTableBlock
);
tscSortRemoveDataBlockDupRows
(
pOneTableBlock
);
char
*
e
=
(
char
*
)
pBlocks
->
data
+
pOneTableBlock
->
rowSize
*
(
pBlocks
->
numOfRows
-
1
);
char
*
e
key
=
(
char
*
)
pBlocks
->
data
+
pOneTableBlock
->
rowSize
*
(
pBlocks
->
numOfRows
-
1
);
tscTrace
(
"%p tableId:%s, sid:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pSql
,
pOneTableBlock
->
tableId
,
tscTrace
(
"%p tableId:%s, sid:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pSql
,
pOneTableBlock
->
tableId
,
pBlocks
->
tid
,
pBlocks
->
numOfRows
,
pBlocks
->
sversion
,
GET_INT64_VAL
(
pBlocks
->
data
),
GET_INT64_VAL
(
e
));
pBlocks
->
tid
,
pBlocks
->
numOfRows
,
pBlocks
->
sversion
,
GET_INT64_VAL
(
pBlocks
->
data
),
GET_INT64_VAL
(
e
key
));
int32_t
len
=
pBlocks
->
numOfRows
*
(
pOneTableBlock
->
rowSize
+
sizeof
(
int32_t
)
*
2
);
int32_t
len
=
pBlocks
->
numOfRows
*
(
pOneTableBlock
->
rowSize
+
sizeof
(
int32_t
)
*
2
);
...
@@ -704,7 +676,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
...
@@ -704,7 +676,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
// free the table data blocks;
// free the table data blocks;
pCmd
->
pDataBlocks
=
pVnodeDataBlockList
;
pCmd
->
pDataBlocks
=
pVnodeDataBlockList
;
tscFreeUnusedDataBlocks
(
pCmd
->
pDataBlocks
);
//
tscFreeUnusedDataBlocks(pCmd->pDataBlocks);
taosHashCleanup
(
pVnodeDataBlockHashList
);
taosHashCleanup
(
pVnodeDataBlockHashList
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
src/inc/taosdef.h
浏览文件 @
758bd5dc
...
@@ -244,7 +244,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
...
@@ -244,7 +244,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE
#define TSDB_PAYLOAD_SIZE
(TSDB_DEFAULT_PKT_SIZE - 100)
#define TSDB_PAYLOAD_SIZE
TSDB_DEFAULT_PKT_SIZE
#define TSDB_DEFAULT_PAYLOAD_SIZE 2048 // default payload size
#define TSDB_DEFAULT_PAYLOAD_SIZE 2048 // default payload size
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
#define TSDB_CQ_SQL_SIZE 1024
#define TSDB_CQ_SQL_SIZE 1024
...
...
src/inc/tsdb.h
浏览文件 @
758bd5dc
...
@@ -105,8 +105,9 @@ typedef struct {
...
@@ -105,8 +105,9 @@ typedef struct {
void
tsdbClearTableCfg
(
STableCfg
*
config
);
void
tsdbClearTableCfg
(
STableCfg
*
config
);
void
*
tsdbGetTableTagVal
(
TSDB_REPO_T
*
repo
,
const
STableId
*
id
,
int32_t
colId
,
int16_t
type
,
int16_t
bytes
);
void
*
tsdbGetTableTagVal
(
const
void
*
pTable
,
int32_t
colId
,
int16_t
type
,
int16_t
bytes
);
char
*
tsdbGetTableName
(
TSDB_REPO_T
*
repo
,
const
STableId
*
id
);
char
*
tsdbGetTableName
(
void
*
pTable
);
STableId
tsdbGetTableId
(
void
*
pTable
);
STableCfg
*
tsdbCreateTableCfgFromMsg
(
SMDCreateTableMsg
*
pMsg
);
STableCfg
*
tsdbCreateTableCfgFromMsg
(
SMDCreateTableMsg
*
pMsg
);
int
tsdbCreateTable
(
TSDB_REPO_T
*
repo
,
STableCfg
*
pCfg
);
int
tsdbCreateTable
(
TSDB_REPO_T
*
repo
,
STableCfg
*
pCfg
);
...
@@ -176,18 +177,16 @@ typedef struct SQueryRowCond {
...
@@ -176,18 +177,16 @@ typedef struct SQueryRowCond {
TSKEY
ts
;
TSKEY
ts
;
}
SQueryRowCond
;
}
SQueryRowCond
;
typedef
void
*
TsdbPosT
;
/**
/**
* Get the data block iterator, starting from position according to the query condition
* Get the data block iterator, starting from position according to the query condition
*
*
* @param tsdb tsdb handle
* @param tsdb tsdb handle
* @param pCond query condition, including time window, result set order, and basic required columns for each block
* @param pCond query condition, including time window, result set order, and basic required columns for each block
* @param
g
roupInfo tableId list in the form of set, seperated into different groups according to group by condition
* @param
tableqinfoG
roupInfo tableId list in the form of set, seperated into different groups according to group by condition
* @param qinfo query info handle from query processor
* @param qinfo query info handle from query processor
* @return
* @return
*/
*/
TsdbQueryHandleT
*
tsdbQueryTables
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
g
roupInfo
,
void
*
qinfo
);
TsdbQueryHandleT
*
tsdbQueryTables
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
tableqinfoG
roupInfo
,
void
*
qinfo
);
/**
/**
* Get the last row of the given query time window for all the tables in STableGroupInfo object.
* Get the last row of the given query time window for all the tables in STableGroupInfo object.
...
@@ -197,12 +196,17 @@ TsdbQueryHandleT *tsdbQueryTables(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STab
...
@@ -197,12 +196,17 @@ TsdbQueryHandleT *tsdbQueryTables(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STab
* @param tsdb tsdb handle
* @param tsdb tsdb handle
* @param pCond query condition, including time window, result set order, and basic required columns for each
* @param pCond query condition, including time window, result set order, and basic required columns for each
* block
* block
* @param
g
roupInfo tableId list.
* @param
tableqinfoG
roupInfo tableId list.
* @return
* @return
*/
*/
TsdbQueryHandleT
tsdbQueryLastRow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
g
roupInfo
,
void
*
qinfo
);
TsdbQueryHandleT
tsdbQueryLastRow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
tableqinfoG
roupInfo
,
void
*
qinfo
);
SArray
*
tsdbGetQueriedTableIdList
(
TsdbQueryHandleT
*
pHandle
);
/**
* get the queried table object list
* @param pHandle
* @return
*/
SArray
*
tsdbGetQueriedTableList
(
TsdbQueryHandleT
*
pHandle
);
TsdbQueryHandleT
tsdbQueryRowsInExternalWindow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
TsdbQueryHandleT
tsdbQueryRowsInExternalWindow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
);
void
*
qinfo
);
...
@@ -247,37 +251,6 @@ int32_t tsdbRetrieveDataBlockStatisInfo(TsdbQueryHandleT *pQueryHandle, SDataSta
...
@@ -247,37 +251,6 @@ int32_t tsdbRetrieveDataBlockStatisInfo(TsdbQueryHandleT *pQueryHandle, SDataSta
*/
*/
SArray
*
tsdbRetrieveDataBlock
(
TsdbQueryHandleT
*
pQueryHandle
,
SArray
*
pColumnIdList
);
SArray
*
tsdbRetrieveDataBlock
(
TsdbQueryHandleT
*
pQueryHandle
,
SArray
*
pColumnIdList
);
/**
* todo remove this function later
* @param pQueryHandle
* @param pIdList
* @return
*/
SArray
*
tsdbRetrieveDataRow
(
TsdbQueryHandleT
*
pQueryHandle
,
SArray
*
pIdList
,
SQueryRowCond
*
pCond
);
/**
* Get iterator for super tables, of which tags values satisfy the tag filter info
*
* NOTE: the tagFilterStr is an bin-expression for tag filter, such as ((tag_col = 5) and (tag_col2 > 7))
* The filter string is sent from client directly.
* The build of the tags filter expression from string is done in the iterator generating function.
*
* @param pCond query condition
* @param pTagFilterStr tag filter info
* @return
*/
TsdbQueryHandleT
*
tsdbQueryFromTagConds
(
STsdbQueryCond
*
pCond
,
int16_t
stableId
,
const
char
*
pTagFilterStr
);
/**
* Get the qualified tables for (super) table query.
* Used to handle the super table projection queries, the last_row query, the group by on normal columns query,
* the interpolation query, and timestamp-comp query for join processing.
*
* @param pQueryHandle
* @return table sid list. the invoker is responsible for the release of this the sid list.
*/
SArray
*
tsdbGetTableList
(
TsdbQueryHandleT
*
pQueryHandle
);
/**
/**
* Get the qualified table id for a super table according to the tag query expression.
* Get the qualified table id for a super table according to the tag query expression.
* @param stableid. super table sid
* @param stableid. super table sid
...
@@ -287,6 +260,12 @@ int32_t tsdbQuerySTableByTagCond(TSDB_REPO_T *tsdb, uint64_t uid, const char *pT
...
@@ -287,6 +260,12 @@ int32_t tsdbQuerySTableByTagCond(TSDB_REPO_T *tsdb, uint64_t uid, const char *pT
int16_t
tagNameRelType
,
const
char
*
tbnameCond
,
STableGroupInfo
*
pGroupList
,
int16_t
tagNameRelType
,
const
char
*
tbnameCond
,
STableGroupInfo
*
pGroupList
,
SColIndex
*
pColIndex
,
int32_t
numOfCols
);
SColIndex
*
pColIndex
,
int32_t
numOfCols
);
/**
* destory the created table group list, which is generated by tag query
* @param pGroupList
*/
void
tsdbDestoryTableGroup
(
STableGroupInfo
*
pGroupList
);
/**
/**
* create the table group result including only one table, used to handle the normal table query
* create the table group result including only one table, used to handle the normal table query
*
*
...
...
src/query/inc/qExecutor.h
浏览文件 @
758bd5dc
...
@@ -102,7 +102,7 @@ typedef struct STableQueryInfo { // todo merge with the STableQueryInfo struct
...
@@ -102,7 +102,7 @@ typedef struct STableQueryInfo { // todo merge with the STableQueryInfo struct
int64_t
tag
;
int64_t
tag
;
STimeWindow
win
;
STimeWindow
win
;
STSCursor
cur
;
STSCursor
cur
;
STableId
id
;
// for retrieve the page id list
void
*
pTable
;
// for retrieve the page id list
SWindowResInfo
windowResInfo
;
SWindowResInfo
windowResInfo
;
}
STableQueryInfo
;
}
STableQueryInfo
;
...
@@ -126,10 +126,10 @@ typedef struct SQueryCostInfo {
...
@@ -126,10 +126,10 @@ typedef struct SQueryCostInfo {
uint64_t
computTime
;
uint64_t
computTime
;
}
SQueryCostInfo
;
}
SQueryCostInfo
;
typedef
struct
SGroupItem
{
//
typedef struct SGroupItem {
STableId
id
;
// void *pTable
;
STableQueryInfo
*
info
;
// STableQueryInfo *
info;
}
SGroupItem
;
//
} SGroupItem;
typedef
struct
SQuery
{
typedef
struct
SQuery
{
int16_t
numOfCols
;
int16_t
numOfCols
;
...
@@ -187,8 +187,8 @@ typedef struct SQInfo {
...
@@ -187,8 +187,8 @@ typedef struct SQInfo {
void
*
tsdb
;
void
*
tsdb
;
int32_t
vgId
;
int32_t
vgId
;
STableGroupInfo
table
IdGroupInfo
;
// table id list < only includes the STableId
list>
STableGroupInfo
table
GroupInfo
;
// table id list < only includes the STable
list>
STableGroupInfo
groupInfo
;
//
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
SQueryRuntimeEnv
runtimeEnv
;
SQueryRuntimeEnv
runtimeEnv
;
int32_t
groupIndex
;
int32_t
groupIndex
;
int32_t
offset
;
// offset in group result set of subgroup, todo refactor
int32_t
offset
;
// offset in group result set of subgroup, todo refactor
...
...
src/query/src/qExecutor.c
浏览文件 @
758bd5dc
...
@@ -113,7 +113,7 @@ static void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv);
...
@@ -113,7 +113,7 @@ static void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv);
static
bool
hasMainOutput
(
SQuery
*
pQuery
);
static
bool
hasMainOutput
(
SQuery
*
pQuery
);
static
void
buildTagQueryResult
(
SQInfo
*
pQInfo
);
static
void
buildTagQueryResult
(
SQInfo
*
pQInfo
);
static
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
STableId
*
pTableId
,
STableQueryInfo
*
pTableQueryInfo
);
static
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
void
*
pTable
,
STableQueryInfo
*
pTableQueryInfo
);
static
int32_t
flushFromResultBuf
(
SQInfo
*
pQInfo
);
static
int32_t
flushFromResultBuf
(
SQInfo
*
pQInfo
);
bool
doFilterData
(
SQuery
*
pQuery
,
int32_t
elemPos
)
{
bool
doFilterData
(
SQuery
*
pQuery
,
int32_t
elemPos
)
{
...
@@ -1495,6 +1495,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -1495,6 +1495,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
}
}
static
bool
isQueryKilled
(
SQInfo
*
pQInfo
)
{
static
bool
isQueryKilled
(
SQInfo
*
pQInfo
)
{
return
false
;
return
(
pQInfo
->
code
==
TSDB_CODE_TSC_QUERY_CANCELLED
);
return
(
pQInfo
->
code
==
TSDB_CODE_TSC_QUERY_CANCELLED
);
}
}
...
@@ -1781,7 +1782,7 @@ static int32_t getInitialPageNum(SQInfo *pQInfo) {
...
@@ -1781,7 +1782,7 @@ static int32_t getInitialPageNum(SQInfo *pQInfo) {
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
num
=
128
;
num
=
128
;
}
else
if
(
isIntervalQuery
(
pQuery
))
{
// time window query, allocate one page for each table
}
else
if
(
isIntervalQuery
(
pQuery
))
{
// time window query, allocate one page for each table
size_t
s
=
pQInfo
->
g
roupInfo
.
numOfTables
;
size_t
s
=
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
;
num
=
MAX
(
s
,
INITIAL_RESULT_ROWS_VALUE
);
num
=
MAX
(
s
,
INITIAL_RESULT_ROWS_VALUE
);
}
else
{
// for super table query, one page for each subset
}
else
{
// for super table query, one page for each subset
num
=
1
;
// pQInfo->pSidSet->numOfSubSet;
num
=
1
;
// pQInfo->pSidSet->numOfSubSet;
...
@@ -1815,18 +1816,18 @@ char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWi
...
@@ -1815,18 +1816,18 @@ char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWi
*/
*/
UNUSED_FUNC
void
vnodeDecMeterRefcnt
(
SQInfo
*
pQInfo
)
{
UNUSED_FUNC
void
vnodeDecMeterRefcnt
(
SQInfo
*
pQInfo
)
{
if
(
pQInfo
!=
NULL
)
{
if
(
pQInfo
!=
NULL
)
{
// assert(taosHashGetSize(pQInfo->
g
roupInfo) >= 1);
// assert(taosHashGetSize(pQInfo->
tableqinfoG
roupInfo) >= 1);
}
}
#if 0
#if 0
if (pQInfo == NULL || pQInfo->
g
roupInfo.numOfTables == 1) {
if (pQInfo == NULL || pQInfo->
tableqinfoG
roupInfo.numOfTables == 1) {
atomic_fetch_sub_32(&pQInfo->pObj->numOfQueries, 1);
atomic_fetch_sub_32(&pQInfo->pObj->numOfQueries, 1);
qTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pQInfo->pObj->vnode,
qTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pQInfo->pObj->vnode,
pQInfo->pObj->sid, pQInfo->pObj->meterId, pQInfo->pObj->numOfQueries);
pQInfo->pObj->sid, pQInfo->pObj->meterId, pQInfo->pObj->numOfQueries);
} else {
} else {
int32_t num = 0;
int32_t num = 0;
for (int32_t i = 0; i < pQInfo->
g
roupInfo.numOfTables; ++i) {
for (int32_t i = 0; i < pQInfo->
tableqinfoG
roupInfo.numOfTables; ++i) {
SMeterObj *pMeter = getMeterObj(pQInfo->
g
roupInfo, pQInfo->pSidSet->pTableIdList[i]->sid);
SMeterObj *pMeter = getMeterObj(pQInfo->
tableqinfoG
roupInfo, pQInfo->pSidSet->pTableIdList[i]->sid);
atomic_fetch_sub_32(&(pMeter->numOfQueries), 1);
atomic_fetch_sub_32(&(pMeter->numOfQueries), 1);
if (pMeter->numOfQueries > 0) {
if (pMeter->numOfQueries > 0) {
...
@@ -1840,9 +1841,9 @@ UNUSED_FUNC void vnodeDecMeterRefcnt(SQInfo *pQInfo) {
...
@@ -1840,9 +1841,9 @@ UNUSED_FUNC void vnodeDecMeterRefcnt(SQInfo *pQInfo) {
* in order to reduce log output, for all meters of which numOfQueries count are 0,
* in order to reduce log output, for all meters of which numOfQueries count are 0,
* we do not output corresponding information
* we do not output corresponding information
*/
*/
num = pQInfo->
g
roupInfo.numOfTables - num;
num = pQInfo->
tableqinfoG
roupInfo.numOfTables - num;
qTrace("QInfo:%p metric query is over, dec query ref for %d meters, numOfQueries on %d meters are 0", pQInfo,
qTrace("QInfo:%p metric query is over, dec query ref for %d meters, numOfQueries on %d meters are 0", pQInfo,
pQInfo->
g
roupInfo.numOfTables, num);
pQInfo->
tableqinfoG
roupInfo.numOfTables, num);
}
}
#endif
#endif
}
}
...
@@ -2188,16 +2189,16 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -2188,16 +2189,16 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
* set tag value in SQLFunctionCtx
* set tag value in SQLFunctionCtx
* e.g.,tag information into input buffer
* e.g.,tag information into input buffer
*/
*/
static
void
doSetTagValueInParam
(
void
*
tsdb
,
STableId
*
pTableId
,
int32_t
tagColId
,
tVariant
*
tag
,
int16_t
type
,
int16_t
bytes
)
{
static
void
doSetTagValueInParam
(
void
*
tsdb
,
void
*
pTable
,
int32_t
tagColId
,
tVariant
*
tag
,
int16_t
type
,
int16_t
bytes
)
{
tVariantDestroy
(
tag
);
tVariantDestroy
(
tag
);
if
(
tagColId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
tagColId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
char
*
val
=
tsdbGetTableName
(
tsdb
,
pTableId
);
char
*
val
=
tsdbGetTableName
(
pTable
);
assert
(
val
!=
NULL
);
assert
(
val
!=
NULL
);
tVariantCreateFromBinary
(
tag
,
varDataVal
(
val
),
varDataLen
(
val
),
TSDB_DATA_TYPE_BINARY
);
tVariantCreateFromBinary
(
tag
,
varDataVal
(
val
),
varDataLen
(
val
),
TSDB_DATA_TYPE_BINARY
);
}
else
{
}
else
{
char
*
val
=
tsdbGetTableTagVal
(
tsdb
,
pTableId
,
tagColId
,
type
,
bytes
);
char
*
val
=
tsdbGetTableTagVal
(
pTable
,
tagColId
,
type
,
bytes
);
if
(
val
==
NULL
)
{
if
(
val
==
NULL
)
{
tag
->
nType
=
TSDB_DATA_TYPE_NULL
;
tag
->
nType
=
TSDB_DATA_TYPE_NULL
;
return
;
return
;
...
@@ -2221,7 +2222,7 @@ static void doSetTagValueInParam(void *tsdb, STableId* pTableId, int32_t tagColI
...
@@ -2221,7 +2222,7 @@ static void doSetTagValueInParam(void *tsdb, STableId* pTableId, int32_t tagColI
}
}
}
}
void
setTagVal
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableId
*
pTableId
,
void
*
tsdb
)
{
void
setTagVal
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
void
*
pTable
,
void
*
tsdb
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQInfo
*
pQInfo
=
GET_QINFO_ADDR
(
pRuntimeEnv
);
SQInfo
*
pQInfo
=
GET_QINFO_ADDR
(
pRuntimeEnv
);
...
@@ -2238,7 +2239,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId* pTableId, void *tsdb) {
...
@@ -2238,7 +2239,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId* pTableId, void *tsdb) {
}
}
}
}
doSetTagValueInParam
(
tsdb
,
pTable
Id
,
pExprInfo
->
base
.
arg
->
argValue
.
i64
,
&
pRuntimeEnv
->
pCtx
[
0
].
tag
,
type
,
bytes
);
doSetTagValueInParam
(
tsdb
,
pTable
,
pExprInfo
->
base
.
arg
->
argValue
.
i64
,
&
pRuntimeEnv
->
pCtx
[
0
].
tag
,
type
,
bytes
);
}
else
{
}
else
{
// set tag value, by which the results are aggregated.
// set tag value, by which the results are aggregated.
for
(
int32_t
idx
=
0
;
idx
<
pQuery
->
numOfOutput
;
++
idx
)
{
for
(
int32_t
idx
=
0
;
idx
<
pQuery
->
numOfOutput
;
++
idx
)
{
...
@@ -2250,7 +2251,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId* pTableId, void *tsdb) {
...
@@ -2250,7 +2251,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId* pTableId, void *tsdb) {
}
}
// todo use tag column index to optimize performance
// todo use tag column index to optimize performance
doSetTagValueInParam
(
tsdb
,
pTable
Id
,
pLocalExprInfo
->
base
.
colInfo
.
colId
,
&
pRuntimeEnv
->
pCtx
[
idx
].
tag
,
doSetTagValueInParam
(
tsdb
,
pTable
,
pLocalExprInfo
->
base
.
colInfo
.
colId
,
&
pRuntimeEnv
->
pCtx
[
idx
].
tag
,
pLocalExprInfo
->
type
,
pLocalExprInfo
->
bytes
);
pLocalExprInfo
->
type
,
pLocalExprInfo
->
bytes
);
}
}
...
@@ -2269,7 +2270,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId* pTableId, void *tsdb) {
...
@@ -2269,7 +2270,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, STableId* pTableId, void *tsdb) {
}
}
}
}
doSetTagValueInParam
(
tsdb
,
pTable
Id
,
pExprInfo
->
base
.
arg
->
argValue
.
i64
,
&
pRuntimeEnv
->
pCtx
[
0
].
tag
,
type
,
bytes
);
doSetTagValueInParam
(
tsdb
,
pTable
,
pExprInfo
->
base
.
arg
->
argValue
.
i64
,
&
pRuntimeEnv
->
pCtx
[
0
].
tag
,
type
,
bytes
);
qTrace
(
"QInfo:%p set tag value for join comparison, colId:%"
PRId64
", val:%"
PRId64
,
pQInfo
,
pExprInfo
->
base
.
arg
->
argValue
.
i64
,
qTrace
(
"QInfo:%p set tag value for join comparison, colId:%"
PRId64
", val:%"
PRId64
,
pQInfo
,
pExprInfo
->
base
.
arg
->
argValue
.
i64
,
pRuntimeEnv
->
pCtx
[
0
].
tag
.
i64Key
)
pRuntimeEnv
->
pCtx
[
0
].
tag
.
i64Key
)
}
}
...
@@ -2474,10 +2475,10 @@ int32_t mergeIntoGroupResult(SQInfo *pQInfo) {
...
@@ -2474,10 +2475,10 @@ int32_t mergeIntoGroupResult(SQInfo *pQInfo) {
int64_t
st
=
taosGetTimestampMs
();
int64_t
st
=
taosGetTimestampMs
();
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
int32_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
pQInfo
->
groupIndex
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
pQInfo
->
groupIndex
);
ret
=
mergeIntoGroupResultImpl
(
pQInfo
,
group
);
ret
=
mergeIntoGroupResultImpl
(
pQInfo
,
group
);
if
(
ret
<
0
)
{
// not enough disk space to save the data into disk
if
(
ret
<
0
)
{
// not enough disk space to save the data into disk
return
-
1
;
return
-
1
;
...
@@ -2510,9 +2511,9 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) {
...
@@ -2510,9 +2511,9 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) {
}
}
// check if all results has been sent to client
// check if all results has been sent to client
int32_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
int32_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
if
(
pQInfo
->
numOfGroupResultPages
==
0
&&
pQInfo
->
groupIndex
==
numOfGroup
)
{
if
(
pQInfo
->
numOfGroupResultPages
==
0
&&
pQInfo
->
groupIndex
==
numOfGroup
)
{
pQInfo
->
tableIndex
=
pQInfo
->
g
roupInfo
.
numOfTables
;
// set query completed
pQInfo
->
tableIndex
=
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
;
// set query completed
return
;
return
;
}
}
}
}
...
@@ -2599,12 +2600,11 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) {
...
@@ -2599,12 +2600,11 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) {
// todo opt for the case of one table per group
// todo opt for the case of one table per group
int32_t
numOfTables
=
0
;
int32_t
numOfTables
=
0
;
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SGroupItem
*
item
=
taosArrayGet
(
pGroup
,
i
);
STableQueryInfo
*
item
=
taosArrayGetP
(
pGroup
,
i
);
STableQueryInfo
*
pInfo
=
item
->
info
;
SIDList
list
=
getDataBufPagesIdList
(
pRuntimeEnv
->
pResultBuf
,
pInfo
->
id
.
tid
);
SIDList
list
=
getDataBufPagesIdList
(
pRuntimeEnv
->
pResultBuf
,
tsdbGetTableId
(
item
->
pTable
)
.
tid
);
if
(
list
.
size
>
0
&&
pInfo
->
windowResInfo
.
size
>
0
)
{
if
(
list
.
size
>
0
&&
item
->
windowResInfo
.
size
>
0
)
{
pTableList
[
numOfTables
]
=
pInfo
;
pTableList
[
numOfTables
]
=
item
;
numOfTables
+=
1
;
numOfTables
+=
1
;
}
}
}
}
...
@@ -2845,15 +2845,15 @@ void disableFuncInReverseScan(SQInfo *pQInfo) {
...
@@ -2845,15 +2845,15 @@ void disableFuncInReverseScan(SQInfo *pQInfo) {
}
}
}
}
int32_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
int32_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
i
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
i
);
size_t
t
=
taosArrayGetSize
(
group
);
size_t
t
=
taosArrayGetSize
(
group
);
for
(
int32_t
j
=
0
;
j
<
t
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
t
;
++
j
)
{
S
GroupItem
*
item
=
taosArrayGet
(
group
,
j
);
S
TableQueryInfo
*
pCheckInfo
=
taosArrayGetP
(
group
,
j
);
updateTableQueryInfoForReverseScan
(
pQuery
,
item
->
i
nfo
);
updateTableQueryInfoForReverseScan
(
pQuery
,
pCheckI
nfo
);
}
}
}
}
}
}
...
@@ -3088,7 +3088,8 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
...
@@ -3088,7 +3088,8 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
}
}
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableIdGroupInfo
,
pQInfo
);
// add ref for table
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
switchCtxOrder
(
pRuntimeEnv
);
switchCtxOrder
(
pRuntimeEnv
);
...
@@ -3160,7 +3161,7 @@ void scanOneTableDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) {
...
@@ -3160,7 +3161,7 @@ void scanOneTableDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) {
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
}
}
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
table
Id
GroupInfo
,
pQInfo
);
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
pRuntimeEnv
->
windowResInfo
.
curIndex
=
qstatus
.
windowIndex
;
pRuntimeEnv
->
windowResInfo
.
curIndex
=
qstatus
.
windowIndex
;
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
...
@@ -3236,17 +3237,13 @@ static bool hasMainOutput(SQuery *pQuery) {
...
@@ -3236,17 +3237,13 @@ static bool hasMainOutput(SQuery *pQuery) {
return
false
;
return
false
;
}
}
static
STableQueryInfo
*
createTableQueryInfo
(
static
STableQueryInfo
*
createTableQueryInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
void
*
pTable
,
STimeWindow
win
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableId
tableId
,
STimeWindow
win
)
{
STableQueryInfo
*
pTableQueryInfo
=
calloc
(
1
,
sizeof
(
STableQueryInfo
));
STableQueryInfo
*
pTableQueryInfo
=
calloc
(
1
,
sizeof
(
STableQueryInfo
));
pTableQueryInfo
->
win
=
win
;
pTableQueryInfo
->
win
=
win
;
pTableQueryInfo
->
lastKey
=
win
.
skey
;
pTableQueryInfo
->
lastKey
=
win
.
skey
;
pTableQueryInfo
->
id
=
tableId
;
pTableQueryInfo
->
pTable
=
pTable
;
pTableQueryInfo
->
cur
.
vgroupIndex
=
-
1
;
pTableQueryInfo
->
cur
.
vgroupIndex
=
-
1
;
initWindowResInfo
(
&
pTableQueryInfo
->
windowResInfo
,
pRuntimeEnv
,
100
,
100
,
TSDB_DATA_TYPE_INT
);
initWindowResInfo
(
&
pTableQueryInfo
->
windowResInfo
,
pRuntimeEnv
,
100
,
100
,
TSDB_DATA_TYPE_INT
);
...
@@ -3275,7 +3272,7 @@ void setCurrentQueryTable(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTable
...
@@ -3275,7 +3272,7 @@ void setCurrentQueryTable(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTable
* @param pRuntimeEnv
* @param pRuntimeEnv
* @param pDataBlockInfo
* @param pDataBlockInfo
*/
*/
void
setExecutionContext
(
SQInfo
*
pQInfo
,
STableId
*
pTableId
,
int32_t
groupIndex
,
TSKEY
nextKey
)
{
void
setExecutionContext
(
SQInfo
*
pQInfo
,
void
*
pTable
,
int32_t
groupIndex
,
TSKEY
nextKey
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
pQuery
->
current
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
pQuery
->
current
;
...
@@ -3302,7 +3299,7 @@ void setExecutionContext(SQInfo *pQInfo, STableId* pTableId, int32_t groupIndex,
...
@@ -3302,7 +3299,7 @@ void setExecutionContext(SQInfo *pQInfo, STableId* pTableId, int32_t groupIndex,
initCtxOutputBuf
(
pRuntimeEnv
);
initCtxOutputBuf
(
pRuntimeEnv
);
pTableQueryInfo
->
lastKey
=
nextKey
;
pTableQueryInfo
->
lastKey
=
nextKey
;
setAdditionalInfo
(
pQInfo
,
pTable
Id
,
pTableQueryInfo
);
setAdditionalInfo
(
pQInfo
,
pTable
QueryInfo
->
pTable
,
pTableQueryInfo
);
}
}
void
setWindowResOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
pResult
)
{
void
setWindowResOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
pResult
)
{
...
@@ -3362,11 +3359,10 @@ void setWindowResOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
...
@@ -3362,11 +3359,10 @@ void setWindowResOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
}
}
}
}
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
STableId
*
pTableId
,
STableQueryInfo
*
pTableQueryInfo
)
{
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
void
*
pTable
,
STableQueryInfo
*
pTableQueryInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
//assert(pTableQueryInfo->lastKey >= TSKEY_INITIAL_VAL);
setTagVal
(
pRuntimeEnv
,
pTable
Id
,
pQInfo
->
tsdb
);
setTagVal
(
pRuntimeEnv
,
pTable
,
pQInfo
->
tsdb
);
// both the master and supplement scan needs to set the correct ts comp start position
// both the master and supplement scan needs to set the correct ts comp start position
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
...
@@ -3469,7 +3465,7 @@ static int32_t getNumOfSubset(SQInfo *pQInfo) {
...
@@ -3469,7 +3465,7 @@ static int32_t getNumOfSubset(SQInfo *pQInfo) {
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
||
(
isIntervalQuery
(
pQuery
)))
{
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
||
(
isIntervalQuery
(
pQuery
)))
{
totalSubset
=
numOfClosedTimeWindow
(
&
pQInfo
->
runtimeEnv
.
windowResInfo
);
totalSubset
=
numOfClosedTimeWindow
(
&
pQInfo
->
runtimeEnv
.
windowResInfo
);
}
else
{
}
else
{
totalSubset
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
totalSubset
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
}
}
return
totalSubset
;
return
totalSubset
;
...
@@ -3669,7 +3665,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
...
@@ -3669,7 +3665,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
// all data returned, set query over
// all data returned, set query over
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
if
(
pQInfo
->
runtimeEnv
.
stableQuery
)
{
if
(
pQInfo
->
runtimeEnv
.
stableQuery
)
{
if
(
pQInfo
->
tableIndex
>=
pQInfo
->
g
roupInfo
.
numOfTables
)
{
if
(
pQInfo
->
tableIndex
>=
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
)
{
setQueryStatus
(
pQuery
,
QUERY_OVER
);
setQueryStatus
(
pQuery
,
QUERY_OVER
);
}
}
}
else
{
}
else
{
...
@@ -3979,23 +3975,23 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) {
...
@@ -3979,23 +3975,23 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) {
};
};
if
(
!
isSTableQuery
if
(
!
isSTableQuery
&&
(
pQInfo
->
g
roupInfo
.
numOfTables
==
1
)
&&
(
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
==
1
)
&&
(
cond
.
order
==
TSDB_ORDER_ASC
)
&&
(
cond
.
order
==
TSDB_ORDER_ASC
)
&&
(
!
isIntervalQuery
(
pQuery
))
&&
(
!
isIntervalQuery
(
pQuery
))
&&
(
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
&&
(
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
&&
(
!
isFixedOutputQuery
(
pQuery
))
&&
(
!
isFixedOutputQuery
(
pQuery
))
)
{
)
{
SArray
*
pa
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
0
);
SArray
*
pa
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
0
);
S
GroupItem
*
pItem
=
taosArrayGet
(
pa
,
0
);
S
TableQueryInfo
*
pCheckInfo
=
taosArrayGetP
(
pa
,
0
);
cond
.
twindow
=
p
Item
->
i
nfo
->
win
;
cond
.
twindow
=
p
CheckI
nfo
->
win
;
}
}
if
(
isFirstLastRowQuery
(
pQuery
))
{
if
(
isFirstLastRowQuery
(
pQuery
))
{
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryLastRow
(
tsdb
,
&
cond
,
&
pQInfo
->
table
Id
GroupInfo
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryLastRow
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
}
else
if
(
isPointInterpoQuery
(
pQuery
))
{
}
else
if
(
isPointInterpoQuery
(
pQuery
))
{
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryRowsInExternalWindow
(
tsdb
,
&
cond
,
&
pQInfo
->
table
Id
GroupInfo
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryRowsInExternalWindow
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
}
else
{
}
else
{
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
tsdb
,
&
cond
,
&
pQInfo
->
table
Id
GroupInfo
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
}
}
}
}
...
@@ -4132,18 +4128,18 @@ static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) {
...
@@ -4132,18 +4128,18 @@ static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) {
STableQueryInfo
*
pTableQueryInfo
=
NULL
;
STableQueryInfo
*
pTableQueryInfo
=
NULL
;
// todo opt performance using hash table
// todo opt performance using hash table
size_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
size_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroup
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfGroup
;
++
i
)
{
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
i
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
i
);
size_t
num
=
taosArrayGetSize
(
group
);
size_t
num
=
taosArrayGetSize
(
group
);
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
SGroupItem
*
item
=
taosArrayGet
(
group
,
j
);
STableQueryInfo
*
p
=
taosArrayGetP
(
group
,
j
);
STableQueryInfo
*
pInfo
=
item
->
info
;
if
(
pInfo
->
id
.
tid
==
blockInfo
.
tid
)
{
STableId
id
=
tsdbGetTableId
(
p
->
pTable
);
assert
(
pInfo
->
id
.
uid
==
blockInfo
.
uid
);
if
(
id
.
tid
==
blockInfo
.
tid
)
{
pTableQueryInfo
=
item
->
info
;
assert
(
id
.
uid
==
blockInfo
.
uid
);
pTableQueryInfo
=
p
;
break
;
break
;
}
}
...
@@ -4163,11 +4159,11 @@ static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) {
...
@@ -4163,11 +4159,11 @@ static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) {
if
(
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
if
(
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
if
(
!
isIntervalQuery
(
pQuery
))
{
if
(
!
isIntervalQuery
(
pQuery
))
{
int32_t
step
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
1
:-
1
;
int32_t
step
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
1
:-
1
;
setExecutionContext
(
pQInfo
,
&
pTableQueryInfo
->
id
,
pTableQueryInfo
->
groupIndex
,
blockInfo
.
window
.
ekey
+
step
);
setExecutionContext
(
pQInfo
,
pTableQueryInfo
->
pTable
,
pTableQueryInfo
->
groupIndex
,
blockInfo
.
window
.
ekey
+
step
);
}
else
{
// interval query
}
else
{
// interval query
TSKEY
nextKey
=
blockInfo
.
window
.
skey
;
TSKEY
nextKey
=
blockInfo
.
window
.
skey
;
setIntervalQueryRange
(
pQInfo
,
nextKey
);
setIntervalQueryRange
(
pQInfo
,
nextKey
);
/*int32_t ret = */
setAdditionalInfo
(
pQInfo
,
&
pTableQueryInfo
->
id
,
pTableQueryInfo
);
/*int32_t ret = */
setAdditionalInfo
(
pQInfo
,
pTableQueryInfo
->
pTable
,
pTableQueryInfo
);
}
}
}
}
...
@@ -4187,16 +4183,17 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
...
@@ -4187,16 +4183,17 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
0
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
0
);
S
GroupItem
*
item
=
taosArrayGet
(
group
,
index
);
S
TableQueryInfo
*
pCheckInfo
=
taosArrayGetP
(
group
,
index
);
setTagVal
(
pRuntimeEnv
,
&
item
->
id
,
pQInfo
->
tsdb
);
setTagVal
(
pRuntimeEnv
,
pCheckInfo
->
pTable
,
pQInfo
->
tsdb
);
STableId
id
=
tsdbGetTableId
(
pCheckInfo
->
pTable
);
qTrace
(
"QInfo:%p query on (%d): uid:%"
PRIu64
", tid:%d, qrange:%"
PRId64
"-%"
PRId64
,
pQInfo
,
index
,
qTrace
(
"QInfo:%p query on (%d): uid:%"
PRIu64
", tid:%d, qrange:%"
PRId64
"-%"
PRId64
,
pQInfo
,
index
,
i
tem
->
id
.
uid
,
item
->
id
.
tid
,
item
->
info
->
lastKey
,
item
->
i
nfo
->
win
.
ekey
);
i
d
.
uid
,
id
.
tid
,
pCheckInfo
->
lastKey
,
pCheckI
nfo
->
win
.
ekey
);
STsdbQueryCond
cond
=
{
STsdbQueryCond
cond
=
{
.
twindow
=
{
item
->
info
->
lastKey
,
item
->
i
nfo
->
win
.
ekey
},
.
twindow
=
{
pCheckInfo
->
lastKey
,
pCheckI
nfo
->
win
.
ekey
},
.
order
=
pQuery
->
order
.
order
,
.
order
=
pQuery
->
order
.
order
,
.
colList
=
pQuery
->
colList
,
.
colList
=
pQuery
->
colList
,
.
numOfCols
=
pQuery
->
numOfCols
,
.
numOfCols
=
pQuery
->
numOfCols
,
...
@@ -4204,9 +4201,9 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
...
@@ -4204,9 +4201,9 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
// todo refactor
// todo refactor
SArray
*
g1
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
g1
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
tx
=
taosArrayInit
(
1
,
sizeof
(
STableId
)
);
SArray
*
tx
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
tx
,
&
item
->
info
->
id
);
taosArrayPush
(
tx
,
&
pCheckInfo
->
pTable
);
taosArrayPush
(
g1
,
&
tx
);
taosArrayPush
(
g1
,
&
tx
);
STableGroupInfo
gp
=
{.
numOfTables
=
1
,
.
pGroupList
=
g1
};
STableGroupInfo
gp
=
{.
numOfTables
=
1
,
.
pGroupList
=
g1
};
...
@@ -4250,14 +4247,14 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4250,14 +4247,14 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
size_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
size_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
if
(
isPointInterpoQuery
(
pQuery
)
||
isFirstLastRowQuery
(
pQuery
))
{
if
(
isPointInterpoQuery
(
pQuery
)
||
isFirstLastRowQuery
(
pQuery
))
{
resetCtxOutputBuf
(
pRuntimeEnv
);
resetCtxOutputBuf
(
pRuntimeEnv
);
assert
(
pQuery
->
limit
.
offset
==
0
&&
pQuery
->
limit
.
limit
!=
0
);
assert
(
pQuery
->
limit
.
offset
==
0
&&
pQuery
->
limit
.
limit
!=
0
);
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
pQInfo
->
groupIndex
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableG
roupInfo
.
pGroupList
,
pQInfo
->
groupIndex
);
qTrace
(
"QInfo:%p last_row query on group:%d, total group:%zu, current group:%p"
,
pQInfo
,
pQInfo
->
groupIndex
,
qTrace
(
"QInfo:%p last_row query on group:%d, total group:%zu, current group:%p"
,
pQInfo
,
pQInfo
->
groupIndex
,
numOfGroups
,
group
);
numOfGroups
,
group
);
...
@@ -4289,10 +4286,10 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4289,10 +4286,10 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
initCtxOutputBuf
(
pRuntimeEnv
);
initCtxOutputBuf
(
pRuntimeEnv
);
SArray
*
s
=
tsdbGetQueriedTable
Id
List
(
pRuntimeEnv
->
pQueryHandle
);
SArray
*
s
=
tsdbGetQueriedTableList
(
pRuntimeEnv
->
pQueryHandle
);
assert
(
taosArrayGetSize
(
s
)
>=
1
);
assert
(
taosArrayGetSize
(
s
)
>=
1
);
setTagVal
(
pRuntimeEnv
,
(
STableId
*
)
taosArrayGet
(
s
,
0
),
pQInfo
->
tsdb
);
setTagVal
(
pRuntimeEnv
,
taosArrayGetP
(
s
,
0
),
pQInfo
->
tsdb
);
if
(
isFirstLastRowQuery
(
pQuery
))
{
if
(
isFirstLastRowQuery
(
pQuery
))
{
assert
(
taosArrayGetSize
(
s
)
==
1
);
assert
(
taosArrayGetSize
(
s
)
==
1
);
}
}
...
@@ -4300,7 +4297,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4300,7 +4297,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
taosArrayDestroy
(
s
);
taosArrayDestroy
(
s
);
// here we simply set the first table as current table
// here we simply set the first table as current table
pQuery
->
current
=
(
(
SGroupItem
*
)
taosArrayGet
(
group
,
0
))
->
info
;
pQuery
->
current
=
(
STableQueryInfo
*
)
taosArrayGetP
(
pQInfo
->
tableqinfoGroupInfo
.
pGroupList
,
0
)
;
scanOneTableDataBlocks
(
pRuntimeEnv
,
pQuery
->
current
->
lastKey
);
scanOneTableDataBlocks
(
pRuntimeEnv
,
pQuery
->
current
->
lastKey
);
int64_t
numOfRes
=
getNumOfResult
(
pRuntimeEnv
);
int64_t
numOfRes
=
getNumOfResult
(
pRuntimeEnv
);
...
@@ -4322,7 +4319,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4322,7 +4319,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
}
}
}
else
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
// group-by on normal columns query
}
else
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
// group-by on normal columns query
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
pQInfo
->
groupIndex
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableG
roupInfo
.
pGroupList
,
pQInfo
->
groupIndex
);
qTrace
(
"QInfo:%p group by normal columns group:%d, total group:%zu"
,
pQInfo
,
pQInfo
->
groupIndex
,
numOfGroups
);
qTrace
(
"QInfo:%p group by normal columns group:%d, total group:%zu"
,
pQInfo
,
pQInfo
->
groupIndex
,
numOfGroups
);
...
@@ -4347,10 +4344,10 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4347,10 +4344,10 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
);
SArray
*
s
=
tsdbGetQueriedTable
Id
List
(
pRuntimeEnv
->
pQueryHandle
);
SArray
*
s
=
tsdbGetQueriedTableList
(
pRuntimeEnv
->
pQueryHandle
);
assert
(
taosArrayGetSize
(
s
)
>=
1
);
assert
(
taosArrayGetSize
(
s
)
>=
1
);
setTagVal
(
pRuntimeEnv
,
(
STableId
*
)
taosArrayGet
(
s
,
0
),
pQInfo
->
tsdb
);
setTagVal
(
pRuntimeEnv
,
taosArrayGetP
(
s
,
0
),
pQInfo
->
tsdb
);
// here we simply set the first table as current table
// here we simply set the first table as current table
scanMultiTableDataBlocks
(
pQInfo
);
scanMultiTableDataBlocks
(
pQInfo
);
...
@@ -4406,25 +4403,23 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4406,25 +4403,23 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
}
}
// all data have returned already
// all data have returned already
if
(
pQInfo
->
tableIndex
>=
pQInfo
->
g
roupInfo
.
numOfTables
)
{
if
(
pQInfo
->
tableIndex
>=
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
)
{
return
;
return
;
}
}
resetCtxOutputBuf
(
pRuntimeEnv
);
resetCtxOutputBuf
(
pRuntimeEnv
);
resetTimeWindowInfo
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
);
resetTimeWindowInfo
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
0
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
0
);
assert
(
taosArrayGetSize
(
group
)
==
pQInfo
->
g
roupInfo
.
numOfTables
&&
assert
(
taosArrayGetSize
(
group
)
==
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
&&
1
==
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
));
1
==
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
));
while
(
pQInfo
->
tableIndex
<
pQInfo
->
g
roupInfo
.
numOfTables
)
{
while
(
pQInfo
->
tableIndex
<
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
)
{
if
(
isQueryKilled
(
pQInfo
))
{
if
(
isQueryKilled
(
pQInfo
))
{
return
;
return
;
}
}
SGroupItem
*
item
=
taosArrayGet
(
group
,
pQInfo
->
tableIndex
);
pQuery
->
current
=
taosArrayGetP
(
group
,
pQInfo
->
tableIndex
);
pQuery
->
current
=
item
->
info
;
if
(
!
multiTableMultioutputHelper
(
pQInfo
,
pQInfo
->
tableIndex
))
{
if
(
!
multiTableMultioutputHelper
(
pQInfo
,
pQInfo
->
tableIndex
))
{
pQInfo
->
tableIndex
++
;
pQInfo
->
tableIndex
++
;
continue
;
continue
;
...
@@ -4444,7 +4439,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4444,7 +4439,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
// the limitation of output result is reached, set the query completed
// the limitation of output result is reached, set the query completed
if
(
limitResults
(
pRuntimeEnv
))
{
if
(
limitResults
(
pRuntimeEnv
))
{
pQInfo
->
tableIndex
=
pQInfo
->
g
roupInfo
.
numOfTables
;
pQInfo
->
tableIndex
=
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
;
break
;
break
;
}
}
...
@@ -4461,8 +4456,10 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4461,8 +4456,10 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
pQInfo
->
tableIndex
++
;
pQInfo
->
tableIndex
++
;
STableIdInfo
tidInfo
;
STableIdInfo
tidInfo
;
tidInfo
.
uid
=
item
->
id
.
uid
;
STableId
id
=
tsdbGetTableId
(
pQuery
->
current
->
pTable
);
tidInfo
.
tid
=
item
->
id
.
tid
;
tidInfo
.
uid
=
id
.
uid
;
tidInfo
.
tid
=
id
.
tid
;
tidInfo
.
key
=
pQuery
->
current
->
lastKey
;
tidInfo
.
key
=
pQuery
->
current
->
lastKey
;
taosArrayPush
(
pQInfo
->
arrTableIdInfo
,
&
tidInfo
);
taosArrayPush
(
pQInfo
->
arrTableIdInfo
,
&
tidInfo
);
...
@@ -4485,7 +4482,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4485,7 +4482,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
}
}
}
}
if
(
pQInfo
->
tableIndex
>=
pQInfo
->
g
roupInfo
.
numOfTables
)
{
if
(
pQInfo
->
tableIndex
>=
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
)
{
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
}
}
}
}
...
@@ -4511,7 +4508,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4511,7 +4508,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
qTrace
(
qTrace
(
"QInfo %p numOfTables:%"
PRIu64
", index:%d, numOfGroups:%zu, %"
PRId64
" points returned, total:%"
PRId64
", offset:%"
PRId64
,
"QInfo %p numOfTables:%"
PRIu64
", index:%d, numOfGroups:%zu, %"
PRId64
" points returned, total:%"
PRId64
", offset:%"
PRId64
,
pQInfo
,
pQInfo
->
g
roupInfo
.
numOfTables
,
pQInfo
->
tableIndex
,
numOfGroups
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
,
pQInfo
,
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
,
pQInfo
->
tableIndex
,
numOfGroups
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
,
pQuery
->
limit
.
offset
);
pQuery
->
limit
.
offset
);
}
}
...
@@ -4539,7 +4536,7 @@ static void doSaveContext(SQInfo *pQInfo) {
...
@@ -4539,7 +4536,7 @@ static void doSaveContext(SQInfo *pQInfo) {
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
}
}
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
table
Id
GroupInfo
,
pQInfo
);
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_NOT_COMPLETED
);
switchCtxOrder
(
pRuntimeEnv
);
switchCtxOrder
(
pRuntimeEnv
);
...
@@ -4564,14 +4561,14 @@ static void doCloseAllTimeWindowAfterScan(SQInfo *pQInfo) {
...
@@ -4564,14 +4561,14 @@ static void doCloseAllTimeWindowAfterScan(SQInfo *pQInfo) {
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
if
(
isIntervalQuery
(
pQuery
))
{
if
(
isIntervalQuery
(
pQuery
))
{
size_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
size_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroup
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfGroup
;
++
i
)
{
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
i
);
SArray
*
group
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
i
);
size_t
num
=
taosArrayGetSize
(
group
);
size_t
num
=
taosArrayGetSize
(
group
);
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
S
GroupItem
*
item
=
taosArrayGet
(
group
,
j
);
S
TableQueryInfo
*
item
=
taosArrayGetP
(
group
,
j
);
closeAllTimeWindow
(
&
item
->
info
->
windowResInfo
);
closeAllTimeWindow
(
&
item
->
windowResInfo
);
}
}
}
}
}
else
{
// close results for group result
}
else
{
// close results for group result
...
@@ -4732,8 +4729,10 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
...
@@ -4732,8 +4729,10 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
pQuery
->
current
->
lastKey
,
pQuery
->
window
.
ekey
);
pQuery
->
current
->
lastKey
,
pQuery
->
window
.
ekey
);
}
else
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
}
else
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
STableIdInfo
tidInfo
;
STableIdInfo
tidInfo
;
tidInfo
.
uid
=
pQuery
->
current
->
id
.
uid
;
STableId
id
=
tsdbGetTableId
(
pQuery
->
current
);
tidInfo
.
tid
=
pQuery
->
current
->
id
.
tid
;
tidInfo
.
uid
=
id
.
uid
;
tidInfo
.
tid
=
id
.
tid
;
tidInfo
.
key
=
pQuery
->
current
->
lastKey
;
tidInfo
.
key
=
pQuery
->
current
->
lastKey
;
taosArrayPush
(
pQInfo
->
arrTableIdInfo
,
&
tidInfo
);
taosArrayPush
(
pQInfo
->
arrTableIdInfo
,
&
tidInfo
);
}
}
...
@@ -4883,23 +4882,23 @@ static void tableQueryImpl(SQInfo *pQInfo) {
...
@@ -4883,23 +4882,23 @@ static void tableQueryImpl(SQInfo *pQInfo) {
pQuery
->
rec
.
rows
=
0
;
pQuery
->
rec
.
rows
=
0
;
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
assert
(
pQInfo
->
g
roupInfo
.
numOfTables
==
1
);
assert
(
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
==
1
);
SArray
*
g
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
0
);
SArray
*
g
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
0
);
S
GroupItem
*
item
=
taosArrayGet
(
g
,
0
);
S
TableQueryInfo
*
item
=
taosArrayGetP
(
g
,
0
);
// group by normal column, sliding window query, interval query are handled by interval query processor
// group by normal column, sliding window query, interval query are handled by interval query processor
if
(
isIntervalQuery
(
pQuery
)
||
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
// interval (down sampling operation)
if
(
isIntervalQuery
(
pQuery
)
||
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
// interval (down sampling operation)
tableIntervalProcess
(
pQInfo
,
item
->
info
);
tableIntervalProcess
(
pQInfo
,
item
);
}
else
if
(
isFixedOutputQuery
(
pQuery
))
{
}
else
if
(
isFixedOutputQuery
(
pQuery
))
{
tableFixedOutputProcess
(
pQInfo
,
item
->
info
);
tableFixedOutputProcess
(
pQInfo
,
item
);
}
else
{
// diff/add/multiply/subtract/division
}
else
{
// diff/add/multiply/subtract/division
assert
(
pQuery
->
checkBuffer
==
1
);
assert
(
pQuery
->
checkBuffer
==
1
);
tableMultiOutputProcess
(
pQInfo
,
item
->
info
);
tableMultiOutputProcess
(
pQInfo
,
item
);
}
}
// record the total elapsed time
// record the total elapsed time
pRuntimeEnv
->
summary
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
pRuntimeEnv
->
summary
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
assert
(
pQInfo
->
g
roupInfo
.
numOfTables
==
1
);
assert
(
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
==
1
);
/* check if query is killed or not */
/* check if query is killed or not */
if
(
isQueryKilled
(
pQInfo
))
{
if
(
isQueryKilled
(
pQInfo
))
{
...
@@ -4931,7 +4930,7 @@ static void stableQueryImpl(SQInfo *pQInfo) {
...
@@ -4931,7 +4930,7 @@ static void stableQueryImpl(SQInfo *pQInfo) {
pQInfo
->
runtimeEnv
.
summary
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
pQInfo
->
runtimeEnv
.
summary
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
if
(
pQuery
->
rec
.
rows
==
0
)
{
if
(
pQuery
->
rec
.
rows
==
0
)
{
qTrace
(
"QInfo:%p over, %zu tables queried, %"
PRId64
" rows are returned"
,
pQInfo
,
pQInfo
->
g
roupInfo
.
numOfTables
,
pQuery
->
rec
.
total
);
qTrace
(
"QInfo:%p over, %zu tables queried, %"
PRId64
" rows are returned"
,
pQInfo
,
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
,
pQuery
->
rec
.
total
);
}
}
}
}
...
@@ -5487,7 +5486,7 @@ static void doUpdateExprColumnIndex(SQuery *pQuery) {
...
@@ -5487,7 +5486,7 @@ static void doUpdateExprColumnIndex(SQuery *pQuery) {
}
}
static
int
compareTableIdInfo
(
const
void
*
a
,
const
void
*
b
)
{
static
int
compareTableIdInfo
(
const
void
*
a
,
const
void
*
b
)
{
const
STableIdInfo
*
x
=
(
const
STableIdInfo
*
)
a
;
const
STableIdInfo
*
x
=
(
const
STableIdInfo
*
)
a
;
const
STableIdInfo
*
y
=
(
const
STableIdInfo
*
)
b
;
const
STableIdInfo
*
y
=
(
const
STableIdInfo
*
)
b
;
if
(
x
->
uid
>
y
->
uid
)
return
1
;
if
(
x
->
uid
>
y
->
uid
)
return
1
;
...
@@ -5496,7 +5495,7 @@ static int compareTableIdInfo( const void* a, const void* b ) {
...
@@ -5496,7 +5495,7 @@ static int compareTableIdInfo( const void* a, const void* b ) {
}
}
static
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
SArray
*
pTableIdList
,
SSqlGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
static
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
SArray
*
pTableIdList
,
SSqlGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
STableGroupInfo
*
g
roupInfo
,
SColumnInfo
*
pTagCols
)
{
STableGroupInfo
*
tableqinfoG
roupInfo
,
SColumnInfo
*
pTagCols
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
calloc
(
1
,
sizeof
(
SQInfo
));
SQInfo
*
pQInfo
=
(
SQInfo
*
)
calloc
(
1
,
sizeof
(
SQInfo
));
if
(
pQInfo
==
NULL
)
{
if
(
pQInfo
==
NULL
)
{
return
NULL
;
return
NULL
;
...
@@ -5582,39 +5581,41 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
...
@@ -5582,39 +5581,41 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
// to make sure third party won't overwrite this structure
// to make sure third party won't overwrite this structure
pQInfo
->
signature
=
pQInfo
;
pQInfo
->
signature
=
pQInfo
;
pQInfo
->
table
IdGroupInfo
=
*
g
roupInfo
;
pQInfo
->
table
GroupInfo
=
*
tableqinfoG
roupInfo
;
size_t
numOfGroups
=
taosArrayGetSize
(
g
roupInfo
->
pGroupList
);
size_t
numOfGroups
=
taosArrayGetSize
(
tableqinfoG
roupInfo
->
pGroupList
);
pQInfo
->
g
roupInfo
.
pGroupList
=
taosArrayInit
(
numOfGroups
,
POINTER_BYTES
);
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
=
taosArrayInit
(
numOfGroups
,
POINTER_BYTES
);
pQInfo
->
groupInfo
.
numOfTables
=
g
roupInfo
->
numOfTables
;
pQInfo
->
tableqinfoGroupInfo
.
numOfTables
=
tableqinfoG
roupInfo
->
numOfTables
;
int
tableIndex
=
0
;
int
tableIndex
=
0
;
STimeWindow
window
=
pQueryMsg
->
window
;
STimeWindow
window
=
pQueryMsg
->
window
;
taosArraySort
(
pTableIdList
,
compareTableIdInfo
);
taosArraySort
(
pTableIdList
,
compareTableIdInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
pa
=
taosArrayGetP
(
g
roupInfo
->
pGroupList
,
i
);
SArray
*
pa
=
taosArrayGetP
(
tableqinfoG
roupInfo
->
pGroupList
,
i
);
size_t
s
=
taosArrayGetSize
(
pa
);
size_t
s
=
taosArrayGetSize
(
pa
);
SArray
*
p1
=
taosArrayInit
(
s
,
sizeof
(
SGroupItem
)
);
SArray
*
p1
=
taosArrayInit
(
s
,
POINTER_BYTES
);
for
(
int32_t
j
=
0
;
j
<
s
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
s
;
++
j
)
{
STableId
id
=
*
(
STableId
*
)
taosArrayGet
(
pa
,
j
);
void
*
pTable
=
taosArrayGetP
(
pa
,
j
);
SGroupItem
item
=
{
.
id
=
id
};
// NOTE: compare STableIdInfo with STableId
// NOTE: compare STableIdInfo with STableId
STableIdInfo
*
pTableId
=
taosArraySearch
(
pTableIdList
,
&
id
,
compareTableIdInfo
);
STableId
id
=
tsdbGetTableId
(
pTable
);
STableIdInfo
*
pTableId
=
taosArraySearch
(
pTableIdList
,
&
id
,
compareTableIdInfo
);
if
(
pTableId
!=
NULL
)
{
if
(
pTableId
!=
NULL
)
{
window
.
skey
=
pTableId
->
key
;
window
.
skey
=
pTableId
->
key
;
}
else
{
}
else
{
window
.
skey
=
pQueryMsg
->
window
.
skey
;
window
.
skey
=
pQueryMsg
->
window
.
skey
;
}
}
item
.
info
=
createTableQueryInfo
(
&
pQInfo
->
runtimeEnv
,
item
.
id
,
window
);
item
.
info
->
groupIndex
=
i
;
STableQueryInfo
*
item
=
createTableQueryInfo
(
&
pQInfo
->
runtimeEnv
,
pTable
,
window
);
item
.
info
->
tableIndex
=
tableIndex
++
;
item
->
groupIndex
=
i
;
item
->
tableIndex
=
tableIndex
++
;
taosArrayPush
(
p1
,
&
item
);
taosArrayPush
(
p1
,
&
item
);
}
}
taosArrayPush
(
pQInfo
->
g
roupInfo
.
pGroupList
,
&
p1
);
taosArrayPush
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
&
p1
);
}
}
pQInfo
->
arrTableIdInfo
=
taosArrayInit
(
tableIndex
,
sizeof
(
STableIdInfo
));
pQInfo
->
arrTableIdInfo
=
taosArrayInit
(
tableIndex
,
sizeof
(
STableIdInfo
));
...
@@ -5693,7 +5694,7 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ
...
@@ -5693,7 +5694,7 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
pQInfo
->
g
roupInfo
.
numOfTables
==
0
)
{
if
(
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
==
0
)
{
qTrace
(
"QInfo:%p no table qualified for tag filter, abort query"
,
pQInfo
);
qTrace
(
"QInfo:%p no table qualified for tag filter, abort query"
,
pQInfo
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
...
@@ -5754,29 +5755,24 @@ static void freeQInfo(SQInfo *pQInfo) {
...
@@ -5754,29 +5755,24 @@ static void freeQInfo(SQInfo *pQInfo) {
}
}
// todo refactor, extract method to destroytableDataInfo
// todo refactor, extract method to destroytableDataInfo
int32_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
int32_t
numOfGroups
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
p
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
i
);
SArray
*
p
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
i
);
size_t
num
=
taosArrayGetSize
(
p
);
size_t
num
=
taosArrayGetSize
(
p
);
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
S
GroupItem
*
item
=
taosArrayGet
(
p
,
j
);
S
TableQueryInfo
*
item
=
taosArrayGetP
(
p
,
j
);
if
(
item
->
info
!=
NULL
)
{
if
(
item
!=
NULL
)
{
destroyTableQueryInfo
(
item
->
info
,
pQuery
->
numOfOutput
);
destroyTableQueryInfo
(
item
,
pQuery
->
numOfOutput
);
}
}
}
}
taosArrayDestroy
(
p
);
taosArrayDestroy
(
p
);
}
}
taosArrayDestroy
(
pQInfo
->
g
roupInfo
.
pGroupList
);
taosArrayDestroy
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
tsdbDestoryTableGroup
(
&
pQInfo
->
tableGroupInfo
);
SArray
*
p
=
taosArrayGetP
(
pQInfo
->
tableIdGroupInfo
.
pGroupList
,
i
);
taosArrayDestroy
(
p
);
}
taosArrayDestroy
(
pQInfo
->
tableIdGroupInfo
.
pGroupList
);
taosArrayDestroy
(
pQInfo
->
arrTableIdInfo
);
taosArrayDestroy
(
pQInfo
->
arrTableIdInfo
);
if
(
pQuery
->
pGroupbyExpr
!=
NULL
)
{
if
(
pQuery
->
pGroupbyExpr
!=
NULL
)
{
...
@@ -5861,8 +5857,6 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
...
@@ -5861,8 +5857,6 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
// todo if interpolation exists, the result may be dump to client by several rounds
}
}
int32_t
qCreateQueryInfo
(
void
*
tsdb
,
int32_t
vgId
,
SQueryTableMsg
*
pQueryMsg
,
qinfo_t
*
pQInfo
)
{
int32_t
qCreateQueryInfo
(
void
*
tsdb
,
int32_t
vgId
,
SQueryTableMsg
*
pQueryMsg
,
qinfo_t
*
pQInfo
)
{
...
@@ -5904,13 +5898,13 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
...
@@ -5904,13 +5898,13 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
}
}
bool
isSTableQuery
=
false
;
bool
isSTableQuery
=
false
;
STableGroupInfo
g
roupInfo
=
{
0
};
STableGroupInfo
tableqinfoG
roupInfo
=
{
0
};
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryMsg
->
queryType
,
TSDB_QUERY_TYPE_TABLE_QUERY
))
{
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryMsg
->
queryType
,
TSDB_QUERY_TYPE_TABLE_QUERY
))
{
STableIdInfo
*
id
=
taosArrayGet
(
pTableIdList
,
0
);
STableIdInfo
*
id
=
taosArrayGet
(
pTableIdList
,
0
);
qTrace
(
"qmsg:%p query normal table, uid:%"
PRId64
", tid:%d"
,
pQueryMsg
,
id
->
uid
,
id
->
tid
);
qTrace
(
"qmsg:%p query normal table, uid:%"
PRId64
", tid:%d"
,
pQueryMsg
,
id
->
uid
,
id
->
tid
);
if
((
code
=
tsdbGetOneTableGroup
(
tsdb
,
id
->
uid
,
&
g
roupInfo
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tsdbGetOneTableGroup
(
tsdb
,
id
->
uid
,
&
tableqinfoG
roupInfo
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_over
;
goto
_over
;
}
}
}
else
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryMsg
->
queryType
,
TSDB_QUERY_TYPE_MULTITABLE_QUERY
|
TSDB_QUERY_TYPE_STABLE_QUERY
))
{
}
else
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryMsg
->
queryType
,
TSDB_QUERY_TYPE_MULTITABLE_QUERY
|
TSDB_QUERY_TYPE_STABLE_QUERY
))
{
...
@@ -5927,25 +5921,25 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
...
@@ -5927,25 +5921,25 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
numOfGroupByCols
=
0
;
numOfGroupByCols
=
0
;
}
}
code
=
tsdbQuerySTableByTagCond
(
tsdb
,
id
->
uid
,
tagCond
,
pQueryMsg
->
tagCondLen
,
pQueryMsg
->
tagNameRelType
,
tbnameCond
,
&
g
roupInfo
,
pGroupColIndex
,
code
=
tsdbQuerySTableByTagCond
(
tsdb
,
id
->
uid
,
tagCond
,
pQueryMsg
->
tagCondLen
,
pQueryMsg
->
tagNameRelType
,
tbnameCond
,
&
tableqinfoG
roupInfo
,
pGroupColIndex
,
numOfGroupByCols
);
numOfGroupByCols
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_over
;
goto
_over
;
}
}
}
else
{
}
else
{
g
roupInfo
.
pGroupList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
tableqinfoG
roupInfo
.
pGroupList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
g
roupInfo
.
numOfTables
=
taosArrayGetSize
(
pTableIdList
);
tableqinfoG
roupInfo
.
numOfTables
=
taosArrayGetSize
(
pTableIdList
);
SArray
*
p
=
taosArrayClone
(
pTableIdList
);
SArray
*
p
=
taosArrayClone
(
pTableIdList
);
taosArrayPush
(
g
roupInfo
.
pGroupList
,
&
p
);
taosArrayPush
(
tableqinfoG
roupInfo
.
pGroupList
,
&
p
);
qTrace
(
"qmsg:%p query on %zu tables in one group from client"
,
pQueryMsg
,
g
roupInfo
.
numOfTables
);
qTrace
(
"qmsg:%p query on %zu tables in one group from client"
,
pQueryMsg
,
tableqinfoG
roupInfo
.
numOfTables
);
}
}
}
else
{
}
else
{
assert
(
0
);
assert
(
0
);
}
}
(
*
pQInfo
)
=
createQInfoImpl
(
pQueryMsg
,
pTableIdList
,
pGroupbyExpr
,
pExprs
,
&
g
roupInfo
,
pTagColumnInfo
);
(
*
pQInfo
)
=
createQInfoImpl
(
pQueryMsg
,
pTableIdList
,
pGroupbyExpr
,
pExprs
,
&
tableqinfoG
roupInfo
,
pTagColumnInfo
);
if
((
*
pQInfo
)
==
NULL
)
{
if
((
*
pQInfo
)
==
NULL
)
{
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
goto
_over
;
goto
_over
;
...
@@ -6134,17 +6128,17 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
...
@@ -6134,17 +6128,17 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
size_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
g
roupInfo
.
pGroupList
);
size_t
numOfGroup
=
taosArrayGetSize
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
);
assert
(
numOfGroup
==
0
||
numOfGroup
==
1
);
assert
(
numOfGroup
==
0
||
numOfGroup
==
1
);
if
(
numOfGroup
==
0
)
{
if
(
numOfGroup
==
0
)
{
return
;
return
;
}
}
SArray
*
pa
=
taosArrayGetP
(
pQInfo
->
g
roupInfo
.
pGroupList
,
0
);
SArray
*
pa
=
taosArrayGetP
(
pQInfo
->
tableqinfoG
roupInfo
.
pGroupList
,
0
);
size_t
num
=
taosArrayGetSize
(
pa
);
size_t
num
=
taosArrayGetSize
(
pa
);
assert
(
num
==
pQInfo
->
g
roupInfo
.
numOfTables
);
assert
(
num
==
pQInfo
->
tableqinfoG
roupInfo
.
numOfTables
);
int32_t
count
=
0
;
int32_t
count
=
0
;
int32_t
functionId
=
pQuery
->
pSelectExpr
[
0
].
base
.
functionId
;
int32_t
functionId
=
pQuery
->
pSelectExpr
[
0
].
base
.
functionId
;
...
@@ -6168,26 +6162,28 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
...
@@ -6168,26 +6162,28 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
while
(
pQInfo
->
tableIndex
<
num
&&
count
<
pQuery
->
rec
.
capacity
)
{
while
(
pQInfo
->
tableIndex
<
num
&&
count
<
pQuery
->
rec
.
capacity
)
{
int32_t
i
=
pQInfo
->
tableIndex
++
;
int32_t
i
=
pQInfo
->
tableIndex
++
;
S
GroupItem
*
item
=
taosArrayGet
(
pa
,
i
);
S
TableQueryInfo
*
item
=
taosArrayGet
(
pa
,
i
);
char
*
output
=
pQuery
->
sdata
[
0
]
->
data
+
i
*
rsize
;
char
*
output
=
pQuery
->
sdata
[
0
]
->
data
+
i
*
rsize
;
varDataSetLen
(
output
,
rsize
-
VARSTR_HEADER_SIZE
);
varDataSetLen
(
output
,
rsize
-
VARSTR_HEADER_SIZE
);
output
=
varDataVal
(
output
);
output
=
varDataVal
(
output
);
*
(
int64_t
*
)
output
=
item
->
id
.
uid
;
// memory align problem, todo serialize
STableId
id
=
tsdbGetTableId
(
item
->
pTable
);
output
+=
sizeof
(
item
->
id
.
uid
);
*
(
int64_t
*
)
output
=
id
.
uid
;
// memory align problem, todo serialize
output
+=
sizeof
(
id
.
uid
);
*
(
int32_t
*
)
output
=
i
tem
->
i
d
.
tid
;
*
(
int32_t
*
)
output
=
id
.
tid
;
output
+=
sizeof
(
i
tem
->
i
d
.
tid
);
output
+=
sizeof
(
id
.
tid
);
*
(
int32_t
*
)
output
=
pQInfo
->
vgId
;
*
(
int32_t
*
)
output
=
pQInfo
->
vgId
;
output
+=
sizeof
(
pQInfo
->
vgId
);
output
+=
sizeof
(
pQInfo
->
vgId
);
if
(
pExprInfo
->
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
pExprInfo
->
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
char
*
data
=
tsdbGetTableName
(
pQInfo
->
tsdb
,
&
item
->
id
);
char
*
data
=
tsdbGetTableName
(
item
->
pTable
);
memcpy
(
output
,
data
,
varDataTLen
(
data
));
memcpy
(
output
,
data
,
varDataTLen
(
data
));
}
else
{
}
else
{
char
*
val
=
tsdbGetTableTagVal
(
pQInfo
->
tsdb
,
&
item
->
id
,
pExprInfo
->
base
.
colInfo
.
colId
,
type
,
bytes
);
char
*
val
=
tsdbGetTableTagVal
(
item
->
pTable
,
pExprInfo
->
base
.
colInfo
.
colId
,
type
,
bytes
);
// todo refactor
// todo refactor
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
@@ -6223,18 +6219,18 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
...
@@ -6223,18 +6219,18 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
int32_t
i
=
pQInfo
->
tableIndex
++
;
int32_t
i
=
pQInfo
->
tableIndex
++
;
SExprInfo
*
pExprInfo
=
pQuery
->
pSelectExpr
;
SExprInfo
*
pExprInfo
=
pQuery
->
pSelectExpr
;
S
GroupItem
*
item
=
taosArrayGet
(
pa
,
i
);
S
TableQueryInfo
*
item
=
taosArrayGetP
(
pa
,
i
);
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
if
(
pExprInfo
[
j
].
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
pExprInfo
[
j
].
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
char
*
data
=
tsdbGetTableName
(
pQInfo
->
tsdb
,
&
item
->
id
);
char
*
data
=
tsdbGetTableName
(
item
->
pTable
);
char
*
dst
=
pQuery
->
sdata
[
j
]
->
data
+
count
*
tbnameSchema
.
bytes
;
char
*
dst
=
pQuery
->
sdata
[
j
]
->
data
+
count
*
tbnameSchema
.
bytes
;
memcpy
(
dst
,
data
,
varDataTLen
(
data
));
memcpy
(
dst
,
data
,
varDataTLen
(
data
));
}
else
{
// todo refactor
}
else
{
// todo refactor
int16_t
type
=
pExprInfo
[
j
].
type
;
int16_t
type
=
pExprInfo
[
j
].
type
;
int16_t
bytes
=
pExprInfo
[
j
].
bytes
;
int16_t
bytes
=
pExprInfo
[
j
].
bytes
;
char
*
data
=
tsdbGetTableTagVal
(
pQInfo
->
tsdb
,
&
item
->
id
,
pExprInfo
[
j
].
base
.
colInfo
.
colId
,
type
,
bytes
);
char
*
data
=
tsdbGetTableTagVal
(
item
->
pTable
,
pExprInfo
[
j
].
base
.
colInfo
.
colId
,
type
,
bytes
);
char
*
dst
=
pQuery
->
sdata
[
j
]
->
data
+
count
*
pExprInfo
[
j
].
bytes
;
char
*
dst
=
pQuery
->
sdata
[
j
]
->
data
+
count
*
pExprInfo
[
j
].
bytes
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
src/query/src/qUtil.c
浏览文件 @
758bd5dc
...
@@ -114,8 +114,6 @@ void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
...
@@ -114,8 +114,6 @@ void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
SWindowResult
*
pResult
=
&
pWindowResInfo
->
pResult
[
i
];
SWindowResult
*
pResult
=
&
pWindowResInfo
->
pResult
[
i
];
if
(
pResult
->
status
.
closed
)
{
// remove the window slot from hash table
if
(
pResult
->
status
.
closed
)
{
// remove the window slot from hash table
taosHashRemove
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
window
.
skey
,
pWindowResInfo
->
type
);
taosHashRemove
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
window
.
skey
,
pWindowResInfo
->
type
);
printf
(
"remove ============>%ld, remain size:%ld
\n
"
,
pResult
->
window
.
skey
,
pWindowResInfo
->
hashList
->
size
);
}
else
{
}
else
{
break
;
break
;
}
}
...
...
src/query/src/qresultBuf.c
浏览文件 @
758bd5dc
...
@@ -72,7 +72,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf
...
@@ -72,7 +72,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
// dError("QInfo:%p failed to create intermediate result output file:%s. %s", pQInfo, pSupporter->extBufFile,
// dError("QInfo:%p failed to create intermediate result output file:%s. %s", pQInfo, pSupporter->extBufFile,
// strerror(errno));
// strerror(errno));
return
-
TSDB_CODE_QRY_NO_DISKSPACE
;
return
TSDB_CODE_QRY_NO_DISKSPACE
;
}
}
pResultBuf
->
totalBufSize
=
pResultBuf
->
numOfPages
*
DEFAULT_INTERN_BUF_PAGE_SIZE
;
pResultBuf
->
totalBufSize
=
pResultBuf
->
numOfPages
*
DEFAULT_INTERN_BUF_PAGE_SIZE
;
...
@@ -80,7 +80,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf
...
@@ -80,7 +80,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf
if
(
pResultBuf
->
pBuf
==
MAP_FAILED
)
{
if
(
pResultBuf
->
pBuf
==
MAP_FAILED
)
{
// dError("QInfo:%p failed to map temp file: %s. %s", pQInfo, pSupporter->extBufFile, strerror(errno));
// dError("QInfo:%p failed to map temp file: %s. %s", pQInfo, pSupporter->extBufFile, strerror(errno));
return
-
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
758bd5dc
...
@@ -158,18 +158,16 @@ int tsdbDropTable(TSDB_REPO_T *repo, STableId tableId) {
...
@@ -158,18 +158,16 @@ int tsdbDropTable(TSDB_REPO_T *repo, STableId tableId) {
return
0
;
return
0
;
}
}
void
*
tsdbGetTableTagVal
(
TSDB_REPO_T
*
repo
,
const
STableId
*
id
,
int32_t
colId
,
int16_t
type
,
int16_t
bytes
)
{
void
*
tsdbGetTableTagVal
(
const
void
*
pTable
,
int32_t
colId
,
int16_t
type
,
int16_t
bytes
)
{
// TODO: this function should be changed also
// TODO: this function should be changed also
STsdbMeta
*
pMeta
=
tsdbGetMeta
(
repo
);
STable
*
pTable
=
tsdbGetTableByUid
(
pMeta
,
id
->
uid
);
STSchema
*
pSchema
=
tsdbGetTableTagSchema
(
pTable
);
STSchema
*
pSchema
=
tsdbGetTableTagSchema
(
(
STable
*
)
pTable
);
STColumn
*
pCol
=
tdGetColOfID
(
pSchema
,
colId
);
STColumn
*
pCol
=
tdGetColOfID
(
pSchema
,
colId
);
if
(
pCol
==
NULL
)
{
if
(
pCol
==
NULL
)
{
return
NULL
;
// No matched tag volumn
return
NULL
;
// No matched tag volumn
}
}
char
*
val
=
tdGetKVRowValOfCol
(
pTable
->
tagVal
,
colId
);
char
*
val
=
tdGetKVRowValOfCol
(
((
STable
*
)
pTable
)
->
tagVal
,
colId
);
assert
(
type
==
pCol
->
type
&&
bytes
==
pCol
->
bytes
);
assert
(
type
==
pCol
->
type
&&
bytes
==
pCol
->
bytes
);
if
(
val
!=
NULL
&&
IS_VAR_DATA_TYPE
(
type
))
{
if
(
val
!=
NULL
&&
IS_VAR_DATA_TYPE
(
type
))
{
...
@@ -179,20 +177,21 @@ void *tsdbGetTableTagVal(TSDB_REPO_T *repo, const STableId *id, int32_t colId, i
...
@@ -179,20 +177,21 @@ void *tsdbGetTableTagVal(TSDB_REPO_T *repo, const STableId *id, int32_t colId, i
return
val
;
return
val
;
}
}
char
*
tsdbGetTableName
(
TSDB_REPO_T
*
repo
,
const
STableId
*
id
)
{
char
*
tsdbGetTableName
(
void
*
pTable
)
{
// TODO: need to change as thread-safe
// TODO: need to change as thread-safe
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
repo
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
STable
*
pTable
=
tsdbGetTableByUid
(
pMeta
,
id
->
uid
);
if
(
pTable
==
NULL
)
{
if
(
pTable
==
NULL
)
{
return
NULL
;
return
NULL
;
}
else
{
}
else
{
return
(
char
*
)
pTable
->
name
;
return
(
char
*
)
(((
STable
*
)
pTable
)
->
name
)
;
}
}
}
}
STableId
tsdbGetTableId
(
void
*
pTable
)
{
assert
(
pTable
);
return
((
STable
*
)
pTable
)
->
tableId
;
}
STableCfg
*
tsdbCreateTableCfgFromMsg
(
SMDCreateTableMsg
*
pMsg
)
{
STableCfg
*
tsdbCreateTableCfgFromMsg
(
SMDCreateTableMsg
*
pMsg
)
{
if
(
pMsg
==
NULL
)
return
NULL
;
if
(
pMsg
==
NULL
)
return
NULL
;
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
758bd5dc
...
@@ -184,15 +184,17 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab
...
@@ -184,15 +184,17 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab
assert
(
gsize
>
0
);
assert
(
gsize
>
0
);
for
(
int32_t
j
=
0
;
j
<
gsize
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
gsize
;
++
j
)
{
STable
Id
*
id
=
(
STableId
*
)
taosArrayGet
(
group
,
j
);
STable
*
pTable
=
(
STable
*
)
taosArrayGetP
(
group
,
j
);
STableCheckInfo
info
=
{
STableCheckInfo
info
=
{
.
lastKey
=
pQueryHandle
->
window
.
skey
,
.
lastKey
=
pQueryHandle
->
window
.
skey
,
.
tableId
=
*
i
d
,
.
tableId
=
pTable
->
tableI
d
,
.
pTableObj
=
tsdbGetTableByUid
(
pMeta
,
id
->
uid
)
,
.
pTableObj
=
pTable
,
};
};
assert
(
info
.
pTableObj
!=
NULL
&&
info
.
pTableObj
->
tableId
.
tid
==
id
->
tid
);
assert
(
info
.
pTableObj
!=
NULL
&&
(
info
.
pTableObj
->
type
==
TSDB_NORMAL_TABLE
||
info
.
pTableObj
->
type
==
TSDB_CHILD_TABLE
));
taosArrayPush
(
pQueryHandle
->
pTableCheckInfo
,
&
info
);
taosArrayPush
(
pQueryHandle
->
pTableCheckInfo
,
&
info
);
}
}
}
}
...
@@ -215,17 +217,17 @@ TsdbQueryHandleT tsdbQueryLastRow(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STab
...
@@ -215,17 +217,17 @@ TsdbQueryHandleT tsdbQueryLastRow(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STab
return
pQueryHandle
;
return
pQueryHandle
;
}
}
SArray
*
tsdbGetQueriedTable
Id
List
(
TsdbQueryHandleT
*
pHandle
)
{
SArray
*
tsdbGetQueriedTableList
(
TsdbQueryHandleT
*
pHandle
)
{
assert
(
pHandle
!=
NULL
);
assert
(
pHandle
!=
NULL
);
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
pHandle
;
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
pHandle
;
size_t
size
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
size_t
size
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
SArray
*
res
=
taosArrayInit
(
size
,
sizeof
(
STableId
)
);
SArray
*
res
=
taosArrayInit
(
size
,
POINTER_BYTES
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
taosArrayPush
(
res
,
&
pCheckInfo
->
tableId
);
taosArrayPush
(
res
,
&
pCheckInfo
->
pTableObj
);
}
}
return
res
;
return
res
;
...
@@ -1052,7 +1054,7 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
...
@@ -1052,7 +1054,7 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
int32_t
end
=
doBinarySearchKey
(
pCols
->
cols
[
0
].
pData
,
pCols
->
numOfRows
,
key
,
order
);
int32_t
end
=
doBinarySearchKey
(
pCols
->
cols
[
0
].
pData
,
pCols
->
numOfRows
,
key
,
order
);
if
(
tsArray
[
end
]
==
key
)
{
// the value of key in cache equals to the end timestamp value, ignore it
if
(
tsArray
[
end
]
==
key
)
{
// the value of key in cache equals to the end timestamp value, ignore it
tSkipListIterNext
(
pCheckInfo
->
iter
);
moveToNextRow
(
pCheckInfo
);
}
}
int32_t
start
=
-
1
;
int32_t
start
=
-
1
;
...
@@ -1607,6 +1609,7 @@ void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle) {
...
@@ -1607,6 +1609,7 @@ void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle) {
}
}
if
(
index
==
-
1
)
{
if
(
index
==
-
1
)
{
// todo add failure test cases
return
;
return
;
}
}
...
@@ -1856,42 +1859,19 @@ SArray* tsdbRetrieveDataBlock(TsdbQueryHandleT* pQueryHandle, SArray* pIdList) {
...
@@ -1856,42 +1859,19 @@ SArray* tsdbRetrieveDataBlock(TsdbQueryHandleT* pQueryHandle, SArray* pIdList) {
SArray
*
tsdbRetrieveDataRow
(
TsdbQueryHandleT
*
pQueryHandle
,
SArray
*
pIdList
,
SQueryRowCond
*
pCond
)
{
return
NULL
;
}
SArray
*
tsdbRetrieveDataRow
(
TsdbQueryHandleT
*
pQueryHandle
,
SArray
*
pIdList
,
SQueryRowCond
*
pCond
)
{
return
NULL
;
}
TsdbQueryHandleT
*
tsdbQueryFromTagConds
(
STsdbQueryCond
*
pCond
,
int16_t
stableId
,
const
char
*
pTagFilterStr
)
{
static
int32_t
getAllTableList
(
STable
*
pSuperTable
,
SArray
*
list
)
{
return
NULL
;
}
SArray
*
tsdbGetTableList
(
TsdbQueryHandleT
*
pQueryHandle
)
{
return
NULL
;
}
static
int32_t
getAllTableIdList
(
STable
*
pSuperTable
,
SArray
*
list
)
{
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
pSuperTable
->
pIndex
);
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
pSuperTable
->
pIndex
);
while
(
tSkipListIterNext
(
iter
))
{
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
STable
**
pTable
=
(
STable
**
)
SL_GET_NODE_DATA
((
SSkipListNode
*
)
pNode
);
STable
**
pTable
=
(
STable
**
)
SL_GET_NODE_DATA
((
SSkipListNode
*
)
pNode
);
taosArrayPush
(
list
,
&
(
*
pTable
)
->
tableId
);
taosArrayPush
(
list
,
pTable
);
}
}
tSkipListDestroyIter
(
iter
);
tSkipListDestroyIter
(
iter
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
/**
* convert the result pointer to table id instead of table object pointer
* todo remove it by using callback function to change the final result in-time.
* @param pRes
*/
static
void
convertQueryResult
(
SArray
*
pRes
,
SArray
*
pTableList
)
{
if
(
pTableList
==
NULL
||
taosArrayGetSize
(
pTableList
)
==
0
)
{
return
;
}
size_t
size
=
taosArrayGetSize
(
pTableList
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
// todo speedup by using reserve space.
STable
*
pTable
=
taosArrayGetP
(
pTableList
,
i
);
taosArrayPush
(
pRes
,
&
pTable
->
tableId
);
}
}
static
void
destroyHelper
(
void
*
param
)
{
static
void
destroyHelper
(
void
*
param
)
{
if
(
param
==
NULL
)
{
if
(
param
==
NULL
)
{
return
;
return
;
...
@@ -1960,16 +1940,13 @@ typedef struct STableGroupSupporter {
...
@@ -1960,16 +1940,13 @@ typedef struct STableGroupSupporter {
int32_t
numOfCols
;
int32_t
numOfCols
;
SColIndex
*
pCols
;
SColIndex
*
pCols
;
STSchema
*
pTagSchema
;
STSchema
*
pTagSchema
;
void
*
tsdbMeta
;
//
void* tsdbMeta;
}
STableGroupSupporter
;
}
STableGroupSupporter
;
int32_t
tableGroupComparFn
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
)
{
int32_t
tableGroupComparFn
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
)
{
STableGroupSupporter
*
pTableGroupSupp
=
(
STableGroupSupporter
*
)
param
;
STableGroupSupporter
*
pTableGroupSupp
=
(
STableGroupSupporter
*
)
param
;
STableId
*
id1
=
(
STableId
*
)
p1
;
STable
*
pTable1
=
*
(
STable
**
)
p1
;
STableId
*
id2
=
(
STableId
*
)
p2
;
STable
*
pTable2
=
*
(
STable
**
)
p2
;
STable
*
pTable1
=
tsdbGetTableByUid
(
pTableGroupSupp
->
tsdbMeta
,
id1
->
uid
);
STable
*
pTable2
=
tsdbGetTableByUid
(
pTableGroupSupp
->
tsdbMeta
,
id2
->
uid
);
for
(
int32_t
i
=
0
;
i
<
pTableGroupSupp
->
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pTableGroupSupp
->
numOfCols
;
++
i
)
{
SColIndex
*
pColIndex
=
&
pTableGroupSupp
->
pCols
[
i
];
SColIndex
*
pColIndex
=
&
pTableGroupSupp
->
pCols
[
i
];
...
@@ -2019,26 +1996,29 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
...
@@ -2019,26 +1996,29 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
return
0
;
return
0
;
}
}
void
createTableGroupImpl
(
SArray
*
pGroups
,
SArray
*
pTable
Id
List
,
size_t
numOfTables
,
STableGroupSupporter
*
pSupp
,
void
createTableGroupImpl
(
SArray
*
pGroups
,
SArray
*
pTableList
,
size_t
numOfTables
,
STableGroupSupporter
*
pSupp
,
__ext_compar_fn_t
compareFn
)
{
__ext_compar_fn_t
compareFn
)
{
STableId
*
pId
=
taosArrayGet
(
pTableIdList
,
0
);
STable
*
pTable
=
taosArrayGetP
(
pTableList
,
0
);
SArray
*
g
=
taosArrayInit
(
16
,
sizeof
(
STableId
));
taosArrayPush
(
g
,
pId
);
SArray
*
g
=
taosArrayInit
(
16
,
POINTER_BYTES
);
taosArrayPush
(
g
,
&
pTable
);
tsdbRefTable
(
pTable
);
for
(
int32_t
i
=
1
;
i
<
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
numOfTables
;
++
i
)
{
STable
Id
*
prev
=
taosArrayGet
(
pTableId
List
,
i
-
1
);
STable
**
prev
=
taosArrayGet
(
pTable
List
,
i
-
1
);
STable
Id
*
p
=
taosArrayGet
(
pTableId
List
,
i
);
STable
**
p
=
taosArrayGet
(
pTable
List
,
i
);
int32_t
ret
=
compareFn
(
prev
,
p
,
pSupp
);
int32_t
ret
=
compareFn
(
prev
,
p
,
pSupp
);
assert
(
ret
==
0
||
ret
==
-
1
);
assert
(
ret
==
0
||
ret
==
-
1
);
tsdbRefTable
(
*
p
);
assert
((
*
p
)
->
type
==
TSDB_CHILD_TABLE
);
if
(
ret
==
0
)
{
if
(
ret
==
0
)
{
taosArrayPush
(
g
,
p
);
taosArrayPush
(
g
,
p
);
}
else
{
}
else
{
taosArrayPush
(
pGroups
,
&
g
);
// current group is ended, start a new group
taosArrayPush
(
pGroups
,
&
g
);
// current group is ended, start a new group
g
=
taosArrayInit
(
16
,
sizeof
(
STableId
));
g
=
taosArrayInit
(
16
,
POINTER_BYTES
);
taosArrayPush
(
g
,
p
);
taosArrayPush
(
g
,
p
);
}
}
}
}
...
@@ -2046,8 +2026,7 @@ void createTableGroupImpl(SArray* pGroups, SArray* pTableIdList, size_t numOfTab
...
@@ -2046,8 +2026,7 @@ void createTableGroupImpl(SArray* pGroups, SArray* pTableIdList, size_t numOfTab
taosArrayPush
(
pGroups
,
&
g
);
taosArrayPush
(
pGroups
,
&
g
);
}
}
SArray
*
createTableGroup
(
SArray
*
pTableList
,
STSchema
*
pTagSchema
,
SColIndex
*
pCols
,
int32_t
numOfOrderCols
,
SArray
*
createTableGroup
(
SArray
*
pTableList
,
STSchema
*
pTagSchema
,
SColIndex
*
pCols
,
int32_t
numOfOrderCols
)
{
TSDB_REPO_T
*
tsdb
)
{
assert
(
pTableList
!=
NULL
);
assert
(
pTableList
!=
NULL
);
SArray
*
pTableGroup
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
pTableGroup
=
taosArrayInit
(
1
,
POINTER_BYTES
);
...
@@ -2058,22 +2037,24 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
...
@@ -2058,22 +2037,24 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
}
}
if
(
numOfOrderCols
==
0
||
size
==
1
)
{
// no group by tags clause or only one table
if
(
numOfOrderCols
==
0
||
size
==
1
)
{
// no group by tags clause or only one table
SArray
*
sa
=
taosArrayInit
(
size
,
sizeof
(
STableId
)
);
SArray
*
sa
=
taosArrayInit
(
size
,
POINTER_BYTES
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableId
*
tableId
=
taosArrayGet
(
pTableList
,
i
);
STable
**
pTable
=
taosArrayGet
(
pTableList
,
i
);
taosArrayPush
(
sa
,
tableId
);
assert
((
*
pTable
)
->
type
==
TSDB_CHILD_TABLE
);
tsdbRefTable
(
*
pTable
);
taosArrayPush
(
sa
,
pTable
);
}
}
taosArrayPush
(
pTableGroup
,
&
sa
);
taosArrayPush
(
pTableGroup
,
&
sa
);
tsdbTrace
(
"all %zu tables belong to one group"
,
size
);
tsdbTrace
(
"all %zu tables belong to one group"
,
size
);
}
else
{
}
else
{
STableGroupSupporter
*
pSupp
=
(
STableGroupSupporter
*
)
calloc
(
1
,
sizeof
(
STableGroupSupporter
));
STableGroupSupporter
*
pSupp
=
(
STableGroupSupporter
*
)
calloc
(
1
,
sizeof
(
STableGroupSupporter
));
pSupp
->
tsdbMeta
=
tsdbGetMeta
(
tsdb
);
pSupp
->
numOfCols
=
numOfOrderCols
;
pSupp
->
numOfCols
=
numOfOrderCols
;
pSupp
->
pTagSchema
=
pTagSchema
;
pSupp
->
pTagSchema
=
pTagSchema
;
pSupp
->
pCols
=
pCols
;
pSupp
->
pCols
=
pCols
;
taosqsort
(
pTableList
->
pData
,
size
,
sizeof
(
STableId
)
,
pSupp
,
tableGroupComparFn
);
taosqsort
(
pTableList
->
pData
,
size
,
POINTER_BYTES
,
pSupp
,
tableGroupComparFn
);
createTableGroupImpl
(
pTableGroup
,
pTableList
,
size
,
pSupp
,
tableGroupComparFn
);
createTableGroupImpl
(
pTableGroup
,
pTableList
,
size
,
pSupp
,
tableGroupComparFn
);
tfree
(
pSupp
);
tfree
(
pSupp
);
}
}
...
@@ -2149,48 +2130,53 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr)
...
@@ -2149,48 +2130,53 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr)
.
pExtInfo
=
pSTable
->
tagSchema
,
.
pExtInfo
=
pSTable
->
tagSchema
,
};
};
SArray
*
pTableList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
tExprTreeTraverse
(
pExpr
,
pSTable
->
pIndex
,
pRes
,
&
supp
);
tExprTreeTraverse
(
pExpr
,
pSTable
->
pIndex
,
pTableList
,
&
supp
);
tExprTreeDestroy
(
&
pExpr
,
destroyHelper
);
tExprTreeDestroy
(
&
pExpr
,
destroyHelper
);
convertQueryResult
(
pRes
,
pTableList
);
taosArrayDestroy
(
pTableList
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
tsdbQuerySTableByTagCond
(
TSDB_REPO_T
*
tsdb
,
uint64_t
uid
,
const
char
*
pTagCond
,
size_t
len
,
int32_t
tsdbQuerySTableByTagCond
(
TSDB_REPO_T
*
tsdb
,
uint64_t
uid
,
const
char
*
pTagCond
,
size_t
len
,
int16_t
tagNameRelType
,
const
char
*
tbnameCond
,
STableGroupInfo
*
pGroupInfo
,
int16_t
tagNameRelType
,
const
char
*
tbnameCond
,
STableGroupInfo
*
pGroupInfo
,
SColIndex
*
pColIndex
,
int32_t
numOfCols
)
{
SColIndex
*
pColIndex
,
int32_t
numOfCols
)
{
if
(
tsdbRLockRepoMeta
(
tsdb
)
<
0
)
goto
_error
;
STable
*
pTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
STable
*
pTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
if
(
pTable
==
NULL
)
{
if
(
pTable
==
NULL
)
{
tsdbError
(
"%p failed to get stable, uid:%"
PRIu64
,
tsdb
,
uid
);
tsdbError
(
"%p failed to get stable, uid:%"
PRIu64
,
tsdb
,
uid
);
return
TSDB_CODE_TDB_INVALID_TABLE_ID
;
terrno
=
TSDB_CODE_TDB_INVALID_TABLE_ID
;
tsdbUnlockRepoMeta
(
tsdb
);
goto
_error
;
}
}
if
(
pTable
->
type
!=
TSDB_SUPER_TABLE
)
{
if
(
pTable
->
type
!=
TSDB_SUPER_TABLE
)
{
tsdbError
(
"%p query normal tag not allowed, uid:%"
PRIu64
", tid:%d, name:%s"
,
tsdb
,
uid
,
pTable
->
tableId
.
tid
,
tsdbError
(
"%p query normal tag not allowed, uid:%"
PRIu64
", tid:%d, name:%s"
,
tsdb
,
uid
,
pTable
->
tableId
.
tid
,
pTable
->
name
->
data
);
pTable
->
name
->
data
);
terrno
=
TSDB_CODE_COM_OPS_NOT_SUPPORT
;
//basically, this error is caused by invalid sql issued by client
return
TSDB_CODE_COM_OPS_NOT_SUPPORT
;
//basically, this error is caused by invalid sql issued by client
tsdbUnlockRepoMeta
(
tsdb
);
goto
_error
;
}
}
SArray
*
res
=
taosArrayInit
(
8
,
sizeof
(
STableId
));
//NOTE: not add ref count for super table
SArray
*
res
=
taosArrayInit
(
8
,
POINTER_BYTES
);
STSchema
*
pTagSchema
=
tsdbGetTableTagSchema
(
pTable
);
STSchema
*
pTagSchema
=
tsdbGetTableTagSchema
(
pTable
);
// no tags and tbname condition, all child tables of this stable are involved
// no tags and tbname condition, all child tables of this stable are involved
if
(
tbnameCond
==
NULL
&&
(
pTagCond
==
NULL
||
len
==
0
))
{
if
(
tbnameCond
==
NULL
&&
(
pTagCond
==
NULL
||
len
==
0
))
{
int32_t
ret
=
getAllTableIdList
(
pTable
,
res
);
int32_t
ret
=
getAllTableList
(
pTable
,
res
);
if
(
ret
==
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
pGroupInfo
->
numOfTables
=
taosArrayGetSize
(
res
);
tsdbUnlockRepoMeta
(
tsdb
);
pGroupInfo
->
pGroupList
=
createTableGroup
(
res
,
pTagSchema
,
pColIndex
,
numOfCols
,
tsdb
);
goto
_error
;
tsdbTrace
(
"%p no table name/tag condition, all tables belong to one group, numOfTables:%zu"
,
tsdb
,
pGroupInfo
->
numOfTables
);
}
else
{
// todo add error
}
}
pGroupInfo
->
numOfTables
=
taosArrayGetSize
(
res
);
pGroupInfo
->
pGroupList
=
createTableGroup
(
res
,
pTagSchema
,
pColIndex
,
numOfCols
);
tsdbTrace
(
"%p no table name/tag condition, all tables belong to one group, numOfTables:%zu"
,
tsdb
,
pGroupInfo
->
numOfTables
);
taosArrayDestroy
(
res
);
taosArrayDestroy
(
res
);
if
(
tsdbUnlockRepoMeta
(
tsdb
)
<
0
)
goto
_error
;
return
ret
;
return
ret
;
}
}
...
@@ -2227,31 +2213,45 @@ int32_t tsdbQuerySTableByTagCond(TSDB_REPO_T* tsdb, uint64_t uid, const char* pT
...
@@ -2227,31 +2213,45 @@ int32_t tsdbQuerySTableByTagCond(TSDB_REPO_T* tsdb, uint64_t uid, const char* pT
doQueryTableList
(
pTable
,
res
,
expr
);
doQueryTableList
(
pTable
,
res
,
expr
);
pGroupInfo
->
numOfTables
=
taosArrayGetSize
(
res
);
pGroupInfo
->
numOfTables
=
taosArrayGetSize
(
res
);
pGroupInfo
->
pGroupList
=
createTableGroup
(
res
,
pTagSchema
,
pColIndex
,
numOfCols
,
tsdb
);
pGroupInfo
->
pGroupList
=
createTableGroup
(
res
,
pTagSchema
,
pColIndex
,
numOfCols
);
tsdbTrace
(
"%p stable tid:%d, uid:%"
PRIu64
" query, numOfTables:%zu, belong to %zu groups"
,
tsdb
,
pTable
->
tableId
.
tid
,
tsdbTrace
(
"%p stable tid:%d, uid:%"
PRIu64
" query, numOfTables:%zu, belong to %zu groups"
,
tsdb
,
pTable
->
tableId
.
tid
,
pTable
->
tableId
.
uid
,
pGroupInfo
->
numOfTables
,
taosArrayGetSize
(
pGroupInfo
->
pGroupList
));
pTable
->
tableId
.
uid
,
pGroupInfo
->
numOfTables
,
taosArrayGetSize
(
pGroupInfo
->
pGroupList
));
taosArrayDestroy
(
res
);
taosArrayDestroy
(
res
);
if
(
tsdbUnlockRepoMeta
(
tsdb
)
<
0
)
goto
_error
;
return
ret
;
return
ret
;
_error:
return
terrno
;
}
}
int32_t
tsdbGetOneTableGroup
(
TSDB_REPO_T
*
tsdb
,
uint64_t
uid
,
STableGroupInfo
*
pGroupInfo
)
{
int32_t
tsdbGetOneTableGroup
(
TSDB_REPO_T
*
tsdb
,
uint64_t
uid
,
STableGroupInfo
*
pGroupInfo
)
{
if
(
tsdbRLockRepoMeta
(
tsdb
)
<
0
)
goto
_error
;
STable
*
pTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
STable
*
pTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
if
(
pTable
==
NULL
)
{
if
(
pTable
==
NULL
)
{
return
TSDB_CODE_TDB_INVALID_TABLE_ID
;
terrno
=
TSDB_CODE_TDB_INVALID_TABLE_ID
;
goto
_error
;
}
}
//todo assert table type, add the table ref count
assert
(
pTable
->
type
==
TSDB_CHILD_TABLE
||
pTable
->
type
==
TSDB_NORMAL_TABLE
);
tsdbRefTable
(
pTable
);
if
(
tsdbUnlockRepoMeta
(
tsdb
)
<
0
)
goto
_error
;
pGroupInfo
->
numOfTables
=
1
;
pGroupInfo
->
numOfTables
=
1
;
pGroupInfo
->
pGroupList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
pGroupInfo
->
pGroupList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SArray
*
group
=
taosArrayInit
(
1
,
sizeof
(
STableId
)
);
SArray
*
group
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
group
,
&
pTable
->
tableId
);
taosArrayPush
(
group
,
&
pTable
);
taosArrayPush
(
pGroupInfo
->
pGroupList
,
&
group
);
taosArrayPush
(
pGroupInfo
->
pGroupList
,
&
group
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_error:
return
terrno
;
}
}
void
tsdbCleanupQueryHandle
(
TsdbQueryHandleT
queryHandle
)
{
void
tsdbCleanupQueryHandle
(
TsdbQueryHandleT
queryHandle
)
{
...
@@ -2263,12 +2263,11 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
...
@@ -2263,12 +2263,11 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
size_t
size
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
size_t
size
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableCheckInfo
*
pTableCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
STableCheckInfo
*
pTableCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
tSkipListDestroyIter
(
pTableCheckInfo
->
iter
);
tsdbUnRefMemTable
(
pQueryHandle
->
pTsdb
,
pTableCheckInfo
->
mem
);
tsdbUnRefMemTable
(
pQueryHandle
->
pTsdb
,
pTableCheckInfo
->
mem
);
tsdbUnRefMemTable
(
pQueryHandle
->
pTsdb
,
pTableCheckInfo
->
imem
);
tsdbUnRefMemTable
(
pQueryHandle
->
pTsdb
,
pTableCheckInfo
->
imem
);
tSkipListDestroyIter
(
pTableCheckInfo
->
iter
);
if
(
pTableCheckInfo
->
pDataCols
!=
NULL
)
{
if
(
pTableCheckInfo
->
pDataCols
!=
NULL
)
{
tfree
(
pTableCheckInfo
->
pDataCols
->
buf
);
tfree
(
pTableCheckInfo
->
pDataCols
->
buf
);
}
}
...
@@ -2293,3 +2292,26 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
...
@@ -2293,3 +2292,26 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
tfree
(
pQueryHandle
);
tfree
(
pQueryHandle
);
}
}
void
tsdbDestoryTableGroup
(
STableGroupInfo
*
pGroupList
)
{
assert
(
pGroupList
!=
NULL
);
size_t
numOfGroup
=
taosArrayGetSize
(
pGroupList
->
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroup
;
++
i
)
{
SArray
*
p
=
taosArrayGetP
(
pGroupList
->
pGroupList
,
i
);
size_t
numOfTables
=
taosArrayGetSize
(
p
);
for
(
int32_t
j
=
0
;
j
<
numOfTables
;
++
j
)
{
STable
*
pTable
=
taosArrayGetP
(
p
,
j
);
assert
(
pTable
!=
NULL
);
tsdbUnRefTable
(
pTable
);
}
taosArrayDestroy
(
p
);
}
taosArrayDestroy
(
pGroupList
->
pGroupList
);
}
tests/script/general/parser/commit.sim
浏览文件 @
758bd5dc
...
@@ -68,6 +68,7 @@ while $loop <= $loops
...
@@ -68,6 +68,7 @@ while $loop <= $loops
while $i < 10
while $i < 10
sql select count(*) from $stb where t1 = $i
sql select count(*) from $stb where t1 = $i
if $data00 != $rowNum then
if $data00 != $rowNum then
print expect $rowNum, actual: $data00
return -1
return -1
endi
endi
$i = $i + 1
$i = $i + 1
...
...
tests/script/general/parser/selectResNum.sim
浏览文件 @
758bd5dc
...
@@ -172,6 +172,7 @@ while $loop <= $loops
...
@@ -172,6 +172,7 @@ while $loop <= $loops
endi
endi
sql select c8 from $stb where t1 = $i
sql select c8 from $stb where t1 = $i
if $rows != $rowNum then
if $rows != $rowNum then
print expect $rowNum, actual: $rows
return -1
return -1
endi
endi
sql select c9 from $stb where t1 = $i
sql select c9 from $stb where t1 = $i
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录