Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3f9d5cca
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3f9d5cca
编写于
4月 10, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-98] fix bug for query table, tag query cond serialization,
上级
235b0da1
变更
31
显示空白变更内容
内联
并排
Showing
31 changed file
with
1858 addition
and
1339 deletion
+1858
-1339
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+4
-3
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+4
-4
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+3
-1
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+28
-28
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+3
-3
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+126
-105
src/client/src/tscSecondaryMerge.c
src/client/src/tscSecondaryMerge.c
+4
-4
src/client/src/tscServer.c
src/client/src/tscServer.c
+75
-76
src/client/src/tscSql.c
src/client/src/tscSql.c
+3
-3
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+14
-15
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+83
-46
src/inc/taosdef.h
src/inc/taosdef.h
+4
-4
src/inc/taosmsg.h
src/inc/taosmsg.h
+6
-8
src/query/inc/qast.h
src/query/inc/qast.h
+3
-3
src/query/inc/queryExecutor.h
src/query/inc/queryExecutor.h
+3
-3
src/query/inc/sql.y
src/query/inc/sql.y
+3
-3
src/query/inc/tsqlfunction.h
src/query/inc/tsqlfunction.h
+1
-1
src/query/src/qast.c
src/query/src/qast.c
+143
-84
src/query/src/qextbuffer.c
src/query/src/qextbuffer.c
+2
-2
src/query/src/qinterpolation.c
src/query/src/qinterpolation.c
+2
-2
src/query/src/qpercentile.c
src/query/src/qpercentile.c
+1
-1
src/query/src/qsyntaxtreefunction.c
src/query/src/qsyntaxtreefunction.c
+16
-16
src/query/src/qtsbuf.c
src/query/src/qtsbuf.c
+27
-27
src/query/src/queryExecutor.c
src/query/src/queryExecutor.c
+229
-229
src/query/src/sql.c
src/query/src/sql.c
+3
-3
src/util/inc/tcompare.h
src/util/inc/tcompare.h
+43
-0
src/util/src/tcompare.c
src/util/src/tcompare.c
+192
-0
src/vnode/tsdb/inc/tsdb.h
src/vnode/tsdb/inc/tsdb.h
+2
-2
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+3
-1
src/vnode/tsdb/src/tsdbMeta.c
src/vnode/tsdb/src/tsdbMeta.c
+8
-5
src/vnode/tsdb/src/tsdbRead.c
src/vnode/tsdb/src/tsdbRead.c
+820
-657
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
3f9d5cca
...
@@ -24,6 +24,7 @@ extern "C" {
...
@@ -24,6 +24,7 @@ extern "C" {
* @date 2018/09/30
* @date 2018/09/30
*/
*/
#include "os.h"
#include "os.h"
#include "tbuffer.h"
#include "qextbuffer.h"
#include "qextbuffer.h"
#include "taosdef.h"
#include "taosdef.h"
#include "tscSecondaryMerge.h"
#include "tscSecondaryMerge.h"
...
@@ -176,8 +177,8 @@ void tscIncStreamExecutionCount(void* pStream);
...
@@ -176,8 +177,8 @@ void tscIncStreamExecutionCount(void* pStream);
bool
tscValidateColumnId
(
STableMetaInfo
*
pTableMetaInfo
,
int32_t
colId
);
bool
tscValidateColumnId
(
STableMetaInfo
*
pTableMetaInfo
,
int32_t
colId
);
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
SCond
*
tsGetSTableQueryCond
Pos
(
STagCond
*
pCond
,
uint64_t
tableIndex
);
SCond
*
tsGetSTableQueryCond
(
STagCond
*
pCond
,
uint64_t
uid
);
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
const
char
*
str
);
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
*
pBuf
);
void
tscTagCondCopy
(
STagCond
*
dest
,
const
STagCond
*
src
);
void
tscTagCondCopy
(
STagCond
*
dest
,
const
STagCond
*
src
);
void
tscTagCondRelease
(
STagCond
*
pCond
);
void
tscTagCondRelease
(
STagCond
*
pCond
);
...
@@ -199,7 +200,7 @@ int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQuer
...
@@ -199,7 +200,7 @@ int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQuer
STableMetaInfo
*
tscGetMeterMetaInfoByUid
(
SQueryInfo
*
pQueryInfo
,
uint64_t
uid
,
int32_t
*
index
);
STableMetaInfo
*
tscGetMeterMetaInfoByUid
(
SQueryInfo
*
pQueryInfo
,
uint64_t
uid
,
int32_t
*
index
);
void
tscClearMeterMetaInfo
(
STableMetaInfo
*
pTableMetaInfo
,
bool
removeFromCache
);
void
tscClearMeterMetaInfo
(
STableMetaInfo
*
pTableMetaInfo
,
bool
removeFromCache
);
STableMetaInfo
*
tscAdd
MeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
SSuperTableMeta
*
pMetricMeta
,
STableMetaInfo
*
tscAdd
TableMetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
SArray
*
vgroupList
,
int16_t
numOfTags
,
int16_t
*
tags
);
int16_t
numOfTags
,
int16_t
*
tags
);
STableMetaInfo
*
tscAddEmptyMetaInfo
(
SQueryInfo
*
pQueryInfo
);
STableMetaInfo
*
tscAddEmptyMetaInfo
(
SQueryInfo
*
pQueryInfo
);
int32_t
tscAddSubqueryInfo
(
SSqlCmd
*
pCmd
);
int32_t
tscAddSubqueryInfo
(
SSqlCmd
*
pCmd
);
...
...
src/client/inc/tsclient.h
浏览文件 @
3f9d5cca
...
@@ -43,7 +43,7 @@ struct SSqlInfo;
...
@@ -43,7 +43,7 @@ struct SSqlInfo;
typedef
struct
SSqlGroupbyExpr
{
typedef
struct
SSqlGroupbyExpr
{
int16_t
tableIndex
;
int16_t
tableIndex
;
int16_t
numOfGroupCols
;
int16_t
numOfGroupCols
;
SColIndex
Ex
columnInfo
[
TSDB_MAX_TAGS
];
// group by columns information
SColIndex
columnInfo
[
TSDB_MAX_TAGS
];
// group by columns information
int16_t
orderIndex
;
// order by column index
int16_t
orderIndex
;
// order by column index
int16_t
orderType
;
// order by type: asc/desc
int16_t
orderType
;
// order by type: asc/desc
}
SSqlGroupbyExpr
;
}
SSqlGroupbyExpr
;
...
@@ -86,7 +86,7 @@ typedef struct STableMetaInfo {
...
@@ -86,7 +86,7 @@ typedef struct STableMetaInfo {
/* the structure for sql function in select clause */
/* the structure for sql function in select clause */
typedef
struct
SSqlExpr
{
typedef
struct
SSqlExpr
{
char
aliasName
[
TSDB_COL_NAME_LEN
];
// as aliasName
char
aliasName
[
TSDB_COL_NAME_LEN
];
// as aliasName
SColIndex
Ex
colInfo
;
SColIndex
colInfo
;
int64_t
uid
;
// refactor use the pointer
int64_t
uid
;
// refactor use the pointer
int16_t
functionId
;
// function id in aAgg array
int16_t
functionId
;
// function id in aAgg array
int16_t
resType
;
// return value type
int16_t
resType
;
// return value type
...
@@ -141,6 +141,7 @@ struct SLocalReducer;
...
@@ -141,6 +141,7 @@ struct SLocalReducer;
typedef
struct
SCond
{
typedef
struct
SCond
{
uint64_t
uid
;
uint64_t
uid
;
int32_t
len
;
// length of tag query condition data
char
*
cond
;
char
*
cond
;
}
SCond
;
}
SCond
;
...
@@ -167,8 +168,7 @@ typedef struct STagCond {
...
@@ -167,8 +168,7 @@ typedef struct STagCond {
SJoinInfo
joinInfo
;
SJoinInfo
joinInfo
;
// for different table, the query condition must be seperated
// for different table, the query condition must be seperated
SCond
cond
[
TSDB_MAX_JOIN_TABLE_NUM
];
SArray
*
pCond
;
int16_t
numOfTagCond
;
}
STagCond
;
}
STagCond
;
typedef
struct
SParamInfo
{
typedef
struct
SParamInfo
{
...
...
src/client/src/tscAsync.c
浏览文件 @
3f9d5cca
...
@@ -464,13 +464,15 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
...
@@ -464,13 +464,15 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
}
else
{
// normal async query continues
}
else
{
// normal async query continues
if
(
pCmd
->
isParseFinish
)
{
if
(
pCmd
->
isParseFinish
)
{
tscTrace
(
"%p re
send data to vnode in metermeta callback since sql has been
parsed completed"
,
pSql
);
tscTrace
(
"%p re
-send data to vnode in table Meta callback since sql
parsed completed"
,
pSql
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
assert
(
code
==
TSDB_CODE_SUCCESS
);
assert
(
code
==
TSDB_CODE_SUCCESS
);
if
(
pTableMetaInfo
->
pTableMeta
)
{
if
(
pTableMetaInfo
->
pTableMeta
)
{
// todo update the submit message according to the new table meta
// 1. table uid, 2. ip address
code
=
tscSendMsgToServer
(
pSql
);
code
=
tscSendMsgToServer
(
pSql
);
if
(
code
==
TSDB_CODE_SUCCESS
)
return
;
if
(
code
==
TSDB_CODE_SUCCESS
)
return
;
}
}
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
3f9d5cca
...
@@ -691,7 +691,7 @@ static int32_t data_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
...
@@ -691,7 +691,7 @@ static int32_t data_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
// todo: if column in current data block are null, opt for this case
// todo: if column in current data block are null, opt for this case
static
int32_t
first_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
static
int32_t
first_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
BLK_DATA_NO_NEEDED
;
return
BLK_DATA_NO_NEEDED
;
}
}
...
@@ -704,7 +704,7 @@ static int32_t first_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
...
@@ -704,7 +704,7 @@ static int32_t first_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
}
}
static
int32_t
last_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
static
int32_t
last_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
BLK_DATA_NO_NEEDED
;
return
BLK_DATA_NO_NEEDED
;
}
}
...
@@ -716,7 +716,7 @@ static int32_t last_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
...
@@ -716,7 +716,7 @@ static int32_t last_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
}
}
static
int32_t
first_dist_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
static
int32_t
first_dist_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
BLK_DATA_NO_NEEDED
;
return
BLK_DATA_NO_NEEDED
;
}
}
...
@@ -732,7 +732,7 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
...
@@ -732,7 +732,7 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
}
}
static
int32_t
last_dist_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
static
int32_t
last_dist_data_req_info
(
SQLFunctionCtx
*
pCtx
,
TSKEY
start
,
TSKEY
end
,
int32_t
colId
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
BLK_DATA_NO_NEEDED
;
return
BLK_DATA_NO_NEEDED
;
}
}
...
@@ -1483,7 +1483,7 @@ static bool first_last_function_setup(SQLFunctionCtx *pCtx) {
...
@@ -1483,7 +1483,7 @@ static bool first_last_function_setup(SQLFunctionCtx *pCtx) {
// todo opt for null block
// todo opt for null block
static
void
first_function
(
SQLFunctionCtx
*
pCtx
)
{
static
void
first_function
(
SQLFunctionCtx
*
pCtx
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
;
return
;
}
}
...
@@ -1513,7 +1513,7 @@ static void first_function(SQLFunctionCtx *pCtx) {
...
@@ -1513,7 +1513,7 @@ static void first_function(SQLFunctionCtx *pCtx) {
}
}
static
void
first_function_f
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
)
{
static
void
first_function_f
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
;
return
;
}
}
...
@@ -1561,7 +1561,7 @@ static void first_dist_function(SQLFunctionCtx *pCtx) {
...
@@ -1561,7 +1561,7 @@ static void first_dist_function(SQLFunctionCtx *pCtx) {
* 1. data block that are not loaded
* 1. data block that are not loaded
* 2. scan data files in desc order
* 2. scan data files in desc order
*/
*/
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
;
return
;
}
}
...
@@ -1596,7 +1596,7 @@ static void first_dist_function_f(SQLFunctionCtx *pCtx, int32_t index) {
...
@@ -1596,7 +1596,7 @@ static void first_dist_function_f(SQLFunctionCtx *pCtx, int32_t index) {
return
;
return
;
}
}
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
;
return
;
}
}
...
@@ -1654,7 +1654,7 @@ static void first_dist_func_second_merge(SQLFunctionCtx *pCtx) {
...
@@ -1654,7 +1654,7 @@ static void first_dist_func_second_merge(SQLFunctionCtx *pCtx) {
* least one data in this block that is not null.(TODO opt for this case)
* least one data in this block that is not null.(TODO opt for this case)
*/
*/
static
void
last_function
(
SQLFunctionCtx
*
pCtx
)
{
static
void
last_function
(
SQLFunctionCtx
*
pCtx
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
;
return
;
}
}
...
@@ -1683,7 +1683,7 @@ static void last_function(SQLFunctionCtx *pCtx) {
...
@@ -1683,7 +1683,7 @@ static void last_function(SQLFunctionCtx *pCtx) {
}
}
static
void
last_function_f
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
)
{
static
void
last_function_f
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
;
return
;
}
}
...
@@ -1730,7 +1730,7 @@ static void last_dist_function(SQLFunctionCtx *pCtx) {
...
@@ -1730,7 +1730,7 @@ static void last_dist_function(SQLFunctionCtx *pCtx) {
* 1. for scan data in asc order, no need to check data
* 1. for scan data in asc order, no need to check data
* 2. for data blocks that are not loaded, no need to check data
* 2. for data blocks that are not loaded, no need to check data
*/
*/
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
;
return
;
}
}
...
@@ -1768,7 +1768,7 @@ static void last_dist_function_f(SQLFunctionCtx *pCtx, int32_t index) {
...
@@ -1768,7 +1768,7 @@ static void last_dist_function_f(SQLFunctionCtx *pCtx, int32_t index) {
* 1. for scan data in asc order, no need to check data
* 1. for scan data in asc order, no need to check data
* 2. for data blocks that are not loaded, no need to check data
* 2. for data blocks that are not loaded, no need to check data
*/
*/
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
;
return
;
}
}
...
@@ -2420,10 +2420,10 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) {
...
@@ -2420,10 +2420,10 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) {
// user specify the order of output by sort the result according to timestamp
// user specify the order of output by sort the result according to timestamp
if
(
pCtx
->
param
[
1
].
i64Key
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
if
(
pCtx
->
param
[
1
].
i64Key
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
__compar_fn_t
comparator
=
(
pCtx
->
param
[
2
].
i64Key
==
TS
QL_SO
_ASC
)
?
resAscComparFn
:
resDescComparFn
;
__compar_fn_t
comparator
=
(
pCtx
->
param
[
2
].
i64Key
==
TS
DB_ORDER
_ASC
)
?
resAscComparFn
:
resDescComparFn
;
qsort
(
tvp
,
pResInfo
->
numOfRes
,
POINTER_BYTES
,
comparator
);
qsort
(
tvp
,
pResInfo
->
numOfRes
,
POINTER_BYTES
,
comparator
);
}
else
if
(
pCtx
->
param
[
1
].
i64Key
>
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
}
else
if
(
pCtx
->
param
[
1
].
i64Key
>
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
__compar_fn_t
comparator
=
(
pCtx
->
param
[
2
].
i64Key
==
TS
QL_SO
_ASC
)
?
resDataAscComparFn
:
resDataDescComparFn
;
__compar_fn_t
comparator
=
(
pCtx
->
param
[
2
].
i64Key
==
TS
DB_ORDER
_ASC
)
?
resDataAscComparFn
:
resDataDescComparFn
;
qsort
(
tvp
,
pResInfo
->
numOfRes
,
POINTER_BYTES
,
comparator
);
qsort
(
tvp
,
pResInfo
->
numOfRes
,
POINTER_BYTES
,
comparator
);
}
}
...
@@ -2449,7 +2449,7 @@ static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
...
@@ -2449,7 +2449,7 @@ static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
int32_t
orderIdx
=
0
;
int32_t
orderIdx
=
0
;
// tOrderDesc object
// tOrderDesc object
tOrderDescriptor
*
pDesc
=
tOrderDesCreate
(
&
orderIdx
,
NUMOFCOLS
,
pModel
,
TS
QL_SO
_DESC
);
tOrderDescriptor
*
pDesc
=
tOrderDesCreate
(
&
orderIdx
,
NUMOFCOLS
,
pModel
,
TS
DB_ORDER
_DESC
);
((
SPercentileInfo
*
)(
pResInfo
->
interResultBuf
))
->
pMemBucket
=
((
SPercentileInfo
*
)(
pResInfo
->
interResultBuf
))
->
pMemBucket
=
tMemBucketCreate
(
1024
,
MAX_AVAILABLE_BUFFER_SIZE
,
pCtx
->
inputBytes
,
pCtx
->
inputType
,
pDesc
);
tMemBucketCreate
(
1024
,
MAX_AVAILABLE_BUFFER_SIZE
,
pCtx
->
inputBytes
,
pCtx
->
inputType
,
pDesc
);
...
@@ -2916,7 +2916,7 @@ static void col_project_function(SQLFunctionCtx *pCtx) {
...
@@ -2916,7 +2916,7 @@ static void col_project_function(SQLFunctionCtx *pCtx) {
INC_INIT_VAL
(
pCtx
,
pCtx
->
size
);
INC_INIT_VAL
(
pCtx
,
pCtx
->
size
);
char
*
pData
=
GET_INPUT_CHAR
(
pCtx
);
char
*
pData
=
GET_INPUT_CHAR
(
pCtx
);
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
(
size_t
)
pCtx
->
size
*
pCtx
->
inputBytes
);
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
(
size_t
)
pCtx
->
size
*
pCtx
->
inputBytes
);
}
else
{
}
else
{
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
...
@@ -3011,7 +3011,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
...
@@ -3011,7 +3011,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
int32_t
notNullElems
=
0
;
int32_t
notNullElems
=
0
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pCtx
->
order
);
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pCtx
->
order
);
int32_t
i
=
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
?
0
:
pCtx
->
size
-
1
;
int32_t
i
=
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
?
0
:
pCtx
->
size
-
1
;
TSKEY
*
pTimestamp
=
pCtx
->
ptsOutputBuf
;
TSKEY
*
pTimestamp
=
pCtx
->
ptsOutputBuf
;
...
@@ -3028,7 +3028,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
...
@@ -3028,7 +3028,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
QL_SO_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSQL_SO
_DESC
))
{
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
DB_ORDER_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSDB_ORDER
_DESC
))
{
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
@@ -3060,7 +3060,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
...
@@ -3060,7 +3060,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
QL_SO_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSQL_SO
_DESC
))
{
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
DB_ORDER_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSDB_ORDER
_DESC
))
{
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
@@ -3092,7 +3092,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
...
@@ -3092,7 +3092,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
pCtx
->
param
[
1
].
dKey
=
pData
[
i
];
pCtx
->
param
[
1
].
dKey
=
pData
[
i
];
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
QL_SO_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSQL_SO
_DESC
))
{
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
DB_ORDER_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSDB_ORDER
_DESC
))
{
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
dKey
;
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
dKey
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
pOutput
+=
1
;
pOutput
+=
1
;
...
@@ -3122,7 +3122,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
...
@@ -3122,7 +3122,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
pCtx
->
param
[
1
].
dKey
=
pData
[
i
];
pCtx
->
param
[
1
].
dKey
=
pData
[
i
];
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
QL_SO_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSQL_SO
_DESC
))
{
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
DB_ORDER_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSDB_ORDER
_DESC
))
{
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
dKey
;
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
dKey
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
@@ -3155,7 +3155,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
...
@@ -3155,7 +3155,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
QL_SO_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSQL_SO
_DESC
))
{
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
DB_ORDER_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSDB_ORDER
_DESC
))
{
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
pOutput
+=
1
;
pOutput
+=
1
;
...
@@ -3186,7 +3186,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
...
@@ -3186,7 +3186,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
if
(
pCtx
->
param
[
1
].
nType
==
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
pCtx
->
param
[
1
].
nType
=
pCtx
->
inputType
;
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
QL_SO_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSQL_SO
_DESC
))
{
}
else
if
((
i
==
0
&&
pCtx
->
order
==
TS
DB_ORDER_ASC
)
||
(
i
==
pCtx
->
size
-
1
&&
pCtx
->
order
==
TSDB_ORDER
_DESC
))
{
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64Key
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
@@ -3298,17 +3298,17 @@ char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
...
@@ -3298,17 +3298,17 @@ char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
SArithmeticSupport
*
pSupport
=
(
SArithmeticSupport
*
)
param
;
SArithmeticSupport
*
pSupport
=
(
SArithmeticSupport
*
)
param
;
SSqlFunctionExpr
*
pExpr
=
pSupport
->
pExpr
;
SSqlFunctionExpr
*
pExpr
=
pSupport
->
pExpr
;
int32_t
colIndex
InBuf
=
-
1
;
int32_t
colIndex
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pExpr
->
binExprInfo
.
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pExpr
->
binExprInfo
.
numOfCols
;
++
i
)
{
if
(
colId
==
pExpr
->
binExprInfo
.
pReqColumns
[
i
].
colId
)
{
if
(
colId
==
pExpr
->
binExprInfo
.
pReqColumns
[
i
].
colId
)
{
colIndex
InBuf
=
pExpr
->
binExprInfo
.
pReqColumns
[
i
].
colIdxInBuf
;
colIndex
=
pExpr
->
binExprInfo
.
pReqColumns
[
i
].
colIndex
;
break
;
break
;
}
}
}
}
assert
(
colIndex
InBuf
>=
0
&&
colId
>=
0
);
assert
(
colIndex
>=
0
&&
colId
>=
0
);
return
pSupport
->
data
[
colIndex
InBuf
]
+
pSupport
->
offset
*
pSupport
->
elemSize
[
colIndexInBuf
];
return
pSupport
->
data
[
colIndex
]
+
pSupport
->
offset
*
pSupport
->
elemSize
[
colIndex
];
}
}
static
void
arithmetic_function
(
SQLFunctionCtx
*
pCtx
)
{
static
void
arithmetic_function
(
SQLFunctionCtx
*
pCtx
)
{
...
@@ -4327,7 +4327,7 @@ static void ts_comp_function(SQLFunctionCtx *pCtx) {
...
@@ -4327,7 +4327,7 @@ static void ts_comp_function(SQLFunctionCtx *pCtx) {
const
char
*
input
=
GET_INPUT_CHAR
(
pCtx
);
const
char
*
input
=
GET_INPUT_CHAR
(
pCtx
);
// primary ts must be existed, so no need to check its existance
// primary ts must be existed, so no need to check its existance
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
tsBufAppend
(
pTSbuf
,
0
,
pCtx
->
tag
.
i64Key
,
input
,
pCtx
->
size
*
TSDB_KEYSIZE
);
tsBufAppend
(
pTSbuf
,
0
,
pCtx
->
tag
.
i64Key
,
input
,
pCtx
->
size
*
TSDB_KEYSIZE
);
}
else
{
}
else
{
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
...
...
src/client/src/tscLocal.c
浏览文件 @
3f9d5cca
...
@@ -240,7 +240,7 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
...
@@ -240,7 +240,7 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
pCmd
->
numOfCols
=
numOfCols
;
pCmd
->
numOfCols
=
numOfCols
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
pQueryInfo
->
order
.
order
=
TS
QL_SO
_ASC
;
pQueryInfo
->
order
.
order
=
TS
DB_ORDER
_ASC
;
tscFieldInfoSetValue
(
&
pQueryInfo
->
fieldsInfo
,
0
,
TSDB_DATA_TYPE_BINARY
,
"Field"
,
TSDB_COL_NAME_LEN
);
tscFieldInfoSetValue
(
&
pQueryInfo
->
fieldsInfo
,
0
,
TSDB_DATA_TYPE_BINARY
,
"Field"
,
TSDB_COL_NAME_LEN
);
rowLen
+=
TSDB_COL_NAME_LEN
;
rowLen
+=
TSDB_COL_NAME_LEN
;
...
@@ -322,7 +322,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
...
@@ -322,7 +322,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
STableIdInfo *pSidExt = tscGetMeterSidInfo(pSidList, j);
STableIdInfo *pSidExt = tscGetMeterSidInfo(pSidList, j);
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
SColIndex
Ex
*pColIndex = &tscSqlExprGet(pQueryInfo, k)->colInfo;
SColIndex *pColIndex = &tscSqlExprGet(pQueryInfo, k)->colInfo;
int16_t offsetId = pColIndex->colIdx;
int16_t offsetId = pColIndex->colIdx;
assert((pColIndex->flag & TSDB_COL_TAG) != 0);
assert((pColIndex->flag & TSDB_COL_TAG) != 0);
...
@@ -460,7 +460,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
...
@@ -460,7 +460,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
pCmd
->
numOfCols
=
1
;
pCmd
->
numOfCols
=
1
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
pQueryInfo
->
order
.
order
=
TS
QL_SO
_ASC
;
pQueryInfo
->
order
.
order
=
TS
DB_ORDER
_ASC
;
tscClearFieldInfo
(
&
pQueryInfo
->
fieldsInfo
);
tscClearFieldInfo
(
&
pQueryInfo
->
fieldsInfo
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
3f9d5cca
...
@@ -45,7 +45,7 @@ typedef struct SColumnList {
...
@@ -45,7 +45,7 @@ typedef struct SColumnList {
SColumnIndex
ids
[
TSDB_MAX_COLUMNS
];
SColumnIndex
ids
[
TSDB_MAX_COLUMNS
];
}
SColumnList
;
}
SColumnList
;
static
SSqlExpr
*
doAddProjectCol
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
int32_t
colI
d
x
,
int32_t
tableIndex
);
static
SSqlExpr
*
doAddProjectCol
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
int32_t
colI
nde
x
,
int32_t
tableIndex
);
static
int32_t
setShowInfo
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
setShowInfo
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
char
*
getAccountId
(
SSqlObj
*
pSql
);
static
char
*
getAccountId
(
SSqlObj
*
pSql
);
...
@@ -61,7 +61,7 @@ static int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pD
...
@@ -61,7 +61,7 @@ static int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pD
static
void
getColumnName
(
tSQLExprItem
*
pItem
,
char
*
resultFieldName
,
int32_t
nameLength
);
static
void
getColumnName
(
tSQLExprItem
*
pItem
,
char
*
resultFieldName
,
int32_t
nameLength
);
static
void
getRevisedName
(
char
*
resultFieldName
,
int32_t
functionId
,
int32_t
maxLen
,
char
*
columnName
);
static
void
getRevisedName
(
char
*
resultFieldName
,
int32_t
functionId
,
int32_t
maxLen
,
char
*
columnName
);
static
int32_t
addExprAndResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
colI
d
x
,
tSQLExprItem
*
pItem
,
bool
finalResult
);
static
int32_t
addExprAndResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
colI
nde
x
,
tSQLExprItem
*
pItem
,
bool
finalResult
);
static
int32_t
insertResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
SColumnList
*
pIdList
,
int16_t
bytes
,
static
int32_t
insertResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
SColumnList
*
pIdList
,
int16_t
bytes
,
int8_t
type
,
char
*
fieldName
,
SSqlExpr
*
pSqlExpr
);
int8_t
type
,
char
*
fieldName
,
SSqlExpr
*
pSqlExpr
);
static
int32_t
changeFunctionID
(
int32_t
optr
,
int16_t
*
functionId
);
static
int32_t
changeFunctionID
(
int32_t
optr
,
int16_t
*
functionId
);
...
@@ -116,9 +116,7 @@ static int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSql
...
@@ -116,9 +116,7 @@ static int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSql
static
int32_t
doCheckForCreateFromStable
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForCreateFromStable
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForStream
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForStream
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForQuery
(
SSqlObj
*
pSql
,
SQuerySQL
*
pQuerySql
,
int32_t
index
);
static
int32_t
doCheckForQuery
(
SSqlObj
*
pSql
,
SQuerySQL
*
pQuerySql
,
int32_t
index
);
static
int32_t
exprTreeFromSqlExpr
(
tExprNode
**
pExpr
,
tSQLExpr
*
pSqlExpr
,
SSqlExprInfo
*
pExprInfo
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pCols
);
static
int32_t
convertSyntaxTreeToExprTree
(
tExprNode
**
pExpr
,
tSQLExpr
*
pAst
,
int32_t
*
num
,
SColIndexEx
**
pColIndex
,
SSqlExprInfo
*
pExprInfo
);
/*
/*
* Used during parsing query sql. Since the query sql usually small in length, error position
* Used during parsing query sql. Since the query sql usually small in length, error position
...
@@ -136,7 +134,7 @@ static int32_t tscQueryOnlyMetricTags(SQueryInfo* pQueryInfo, bool* queryOnMetri
...
@@ -136,7 +134,7 @@ static int32_t tscQueryOnlyMetricTags(SQueryInfo* pQueryInfo, bool* queryOnMetri
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
->
functionId
!=
TSDB_FUNC_TAGPRJ
&&
if
(
pExpr
->
functionId
!=
TSDB_FUNC_TAGPRJ
&&
!
(
pExpr
->
functionId
==
TSDB_FUNC_COUNT
&&
pExpr
->
colInfo
.
colI
d
x
==
TSDB_TBNAME_COLUMN_INDEX
))
{
!
(
pExpr
->
functionId
==
TSDB_FUNC_COUNT
&&
pExpr
->
colInfo
.
colI
nde
x
==
TSDB_TBNAME_COLUMN_INDEX
))
{
*
queryOnMetricTags
=
false
;
*
queryOnMetricTags
=
false
;
break
;
break
;
}
}
...
@@ -1209,28 +1207,29 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
...
@@ -1209,28 +1207,29 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
SSqlBinaryExprInfo
*
pBinExprInfo
=
&
pFuncExpr
->
binExprInfo
;
SSqlBinaryExprInfo
*
pBinExprInfo
=
&
pFuncExpr
->
binExprInfo
;
tExprNode
*
pNode
=
NULL
;
tExprNode
*
pNode
=
NULL
;
SColIndexEx
*
pColIndex
=
NULL
;
// SArray* colList = taosArrayInit(10, sizeof(SColIndex))
;
int32_t
ret
=
convertSyntaxTreeToExprTree
(
&
pNode
,
pItem
->
pNode
,
&
pBinExprInfo
->
numOfCols
,
&
pColIndex
,
&
pQueryInfo
->
exprsInfo
);
int32_t
ret
=
exprTreeFromSqlExpr
(
&
pNode
,
pItem
->
pNode
,
&
pQueryInfo
->
exprsInfo
,
pQueryInfo
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tExprTreeDestroy
(
&
pNode
,
NULL
);
tExprTreeDestroy
(
&
pNode
,
NULL
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
"invalid expression in select clause"
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
"invalid expression in select clause"
);
}
}
pBinExprInfo
->
pBinExpr
=
pNode
;
pBinExprInfo
->
pBinExpr
=
pNode
;
pBinExprInfo
->
pReqColumns
=
pColIndex
;
assert
(
0
);
// pBinExprInfo->pReqColumns = pColIndex;
for
(
int32_t
k
=
0
;
k
<
pBinExprInfo
->
numOfCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pBinExprInfo
->
numOfCols
;
++
k
)
{
SColIndex
Ex
*
pCol
=
&
pBinExprInfo
->
pReqColumns
[
k
];
SColIndex
*
pCol
=
&
pBinExprInfo
->
pReqColumns
[
k
];
for
(
int32_t
f
=
0
;
f
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
f
)
{
for
(
int32_t
f
=
0
;
f
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
f
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
f
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
f
);
if
(
strcmp
(
pExpr
->
aliasName
,
pCol
->
name
)
==
0
)
{
if
(
strcmp
(
pExpr
->
aliasName
,
pCol
->
name
)
==
0
)
{
pCol
->
colI
dxInBuf
=
f
;
pCol
->
colI
ndex
=
f
;
break
;
break
;
}
}
}
}
assert
(
pCol
->
colI
dxInBuf
>=
0
&&
pCol
->
colIdxInBuf
<
pQueryInfo
->
exprsInfo
.
numOfExprs
);
assert
(
pCol
->
colI
ndex
>=
0
&&
pCol
->
colIndex
<
pQueryInfo
->
exprsInfo
.
numOfExprs
);
tfree
(
pNode
);
tfree
(
pNode
);
}
}
}
}
...
@@ -1288,23 +1287,23 @@ int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnLi
...
@@ -1288,23 +1287,23 @@ int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnLi
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SSqlExpr
*
doAddProjectCol
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
int32_t
colI
d
x
,
int32_t
tableIndex
)
{
SSqlExpr
*
doAddProjectCol
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
int32_t
colI
nde
x
,
int32_t
tableIndex
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
tableIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMeta
);
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMeta
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
colI
d
x
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
colI
nde
x
);
int16_t
functionId
=
(
int16_t
)((
colI
d
x
>=
numOfCols
)
?
TSDB_FUNC_TAGPRJ
:
TSDB_FUNC_PRJ
);
int16_t
functionId
=
(
int16_t
)((
colI
nde
x
>=
numOfCols
)
?
TSDB_FUNC_TAGPRJ
:
TSDB_FUNC_PRJ
);
if
(
functionId
==
TSDB_FUNC_TAGPRJ
)
{
if
(
functionId
==
TSDB_FUNC_TAGPRJ
)
{
// addRequiredTagColumn(pQueryInfo, colI
d
x - numOfCols, tableIndex);
// addRequiredTagColumn(pQueryInfo, colI
nde
x - numOfCols, tableIndex);
pQueryInfo
->
type
=
TSDB_QUERY_TYPE_STABLE_QUERY
;
pQueryInfo
->
type
=
TSDB_QUERY_TYPE_STABLE_QUERY
;
}
else
{
}
else
{
pQueryInfo
->
type
=
TSDB_QUERY_TYPE_PROJECTION_QUERY
;
pQueryInfo
->
type
=
TSDB_QUERY_TYPE_PROJECTION_QUERY
;
}
}
SColumnIndex
index
=
{
tableIndex
,
colI
d
x
};
SColumnIndex
index
=
{
tableIndex
,
colI
nde
x
};
SSqlExpr
*
pExpr
=
SSqlExpr
*
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
outputIndex
,
functionId
,
&
index
,
pSchema
->
type
,
pSchema
->
bytes
,
pSchema
->
bytes
);
tscSqlExprInsert
(
pQueryInfo
,
outputIndex
,
functionId
,
&
index
,
pSchema
->
type
,
pSchema
->
bytes
,
pSchema
->
bytes
);
...
@@ -1503,7 +1502,7 @@ static int32_t setExprInfoForFunctions(SQueryInfo* pQueryInfo, SSchema* pSchema,
...
@@ -1503,7 +1502,7 @@ static int32_t setExprInfoForFunctions(SQueryInfo* pQueryInfo, SSchema* pSchema,
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
addExprAndResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
colI
d
x
,
tSQLExprItem
*
pItem
,
bool
finalResult
)
{
int32_t
addExprAndResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
colI
nde
x
,
tSQLExprItem
*
pItem
,
bool
finalResult
)
{
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
int32_t
optr
=
pItem
->
pNode
->
nSQLOptr
;
int32_t
optr
=
pItem
->
pNode
->
nSQLOptr
;
...
@@ -1547,7 +1546,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1547,7 +1546,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
int32_t
size
=
tDataTypeDesc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
int32_t
size
=
tDataTypeDesc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
d
x
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
size
);
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
nde
x
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
size
);
}
else
{
}
else
{
// count the number of meters created according to the metric
// count the number of meters created according to the metric
if
(
getColumnIndexByName
(
pToken
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
pToken
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -1562,13 +1561,13 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1562,13 +1561,13 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
}
}
int32_t
size
=
tDataTypeDesc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
int32_t
size
=
tDataTypeDesc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
d
x
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
size
);
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
nde
x
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
size
);
}
}
}
else
{
// count(*) is equalled to count(primary_timestamp_key)
}
else
{
// count(*) is equalled to count(primary_timestamp_key)
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
int32_t
size
=
tDataTypeDesc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
int32_t
size
=
tDataTypeDesc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
d
x
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
size
);
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
nde
x
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
size
);
}
}
memset
(
pExpr
->
aliasName
,
0
,
tListLen
(
pExpr
->
aliasName
));
memset
(
pExpr
->
aliasName
,
0
,
tListLen
(
pExpr
->
aliasName
));
...
@@ -1646,7 +1645,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1646,7 +1645,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
// set the first column ts for diff query
// set the first column ts for diff query
if
(
optr
==
TK_DIFF
)
{
if
(
optr
==
TK_DIFF
)
{
colI
d
x
+=
1
;
colI
nde
x
+=
1
;
SColumnIndex
indexTS
=
{.
tableIndex
=
index
.
tableIndex
,
.
columnIndex
=
0
};
SColumnIndex
indexTS
=
{.
tableIndex
=
index
.
tableIndex
,
.
columnIndex
=
0
};
SSqlExpr
*
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
0
,
TSDB_FUNC_TS_DUMMY
,
&
indexTS
,
TSDB_DATA_TYPE_TIMESTAMP
,
TSDB_KEYSIZE
,
SSqlExpr
*
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
0
,
TSDB_FUNC_TS_DUMMY
,
&
indexTS
,
TSDB_DATA_TYPE_TIMESTAMP
,
TSDB_KEYSIZE
,
TSDB_KEYSIZE
);
TSDB_KEYSIZE
);
...
@@ -1660,7 +1659,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1660,7 +1659,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg6
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg6
);
}
}
SSqlExpr
*
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
d
x
,
functionID
,
&
index
,
resultType
,
resultSize
,
resultSize
);
SSqlExpr
*
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
nde
x
,
functionID
,
&
index
,
resultType
,
resultSize
,
resultSize
);
if
(
optr
==
TK_LEASTSQUARES
)
{
if
(
optr
==
TK_LEASTSQUARES
)
{
/* set the leastsquares parameters */
/* set the leastsquares parameters */
...
@@ -1737,7 +1736,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1737,7 +1736,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
for
(
int32_t
j
=
0
;
j
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
j
)
{
index
.
columnIndex
=
j
;
index
.
columnIndex
=
j
;
if
(
setExprInfoForFunctions
(
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colI
d
x
++
,
&
index
)
!=
0
)
{
if
(
setExprInfoForFunctions
(
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colI
nde
x
++
,
&
index
)
!=
0
)
{
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
}
}
}
}
...
@@ -1755,7 +1754,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1755,7 +1754,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg6
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg6
);
}
}
if
(
setExprInfoForFunctions
(
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colI
d
x
+
i
,
&
index
)
!=
0
)
{
if
(
setExprInfoForFunctions
(
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colI
nde
x
+
i
,
&
index
)
!=
0
)
{
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
}
}
}
}
...
@@ -1771,7 +1770,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1771,7 +1770,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
for
(
int32_t
i
=
0
;
i
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
i
)
{
SColumnIndex
index
=
{.
tableIndex
=
j
,
.
columnIndex
=
i
};
SColumnIndex
index
=
{.
tableIndex
=
j
,
.
columnIndex
=
i
};
if
(
setExprInfoForFunctions
(
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colI
d
x
+
i
+
j
,
&
index
)
!=
if
(
setExprInfoForFunctions
(
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colI
nde
x
+
i
+
j
,
&
index
)
!=
0
)
{
0
)
{
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
}
}
...
@@ -1852,7 +1851,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1852,7 +1851,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
}
}
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
d
x
,
functionId
,
&
index
,
resultType
,
resultSize
,
resultSize
);
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
nde
x
,
functionId
,
&
index
,
resultType
,
resultSize
,
resultSize
);
addExprParams
(
pExpr
,
val
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
),
0
);
addExprParams
(
pExpr
,
val
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
),
0
);
}
else
{
}
else
{
tVariantDump
(
pVariant
,
val
,
TSDB_DATA_TYPE_BIGINT
);
tVariantDump
(
pVariant
,
val
,
TSDB_DATA_TYPE_BIGINT
);
...
@@ -1876,9 +1875,9 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1876,9 +1875,9 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
insertResultField
(
pQueryInfo
,
TS_COLUMN_INDEX
,
&
ids
,
TSDB_KEYSIZE
,
TSDB_DATA_TYPE_TIMESTAMP
,
insertResultField
(
pQueryInfo
,
TS_COLUMN_INDEX
,
&
ids
,
TSDB_KEYSIZE
,
TSDB_DATA_TYPE_TIMESTAMP
,
aAggs
[
TSDB_FUNC_TS
].
aName
,
pExpr
);
aAggs
[
TSDB_FUNC_TS
].
aName
,
pExpr
);
colI
d
x
+=
1
;
// the first column is ts
colI
nde
x
+=
1
;
// the first column is ts
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
d
x
,
functionId
,
&
index
,
resultType
,
resultSize
,
resultSize
);
pExpr
=
tscSqlExprInsert
(
pQueryInfo
,
colI
nde
x
,
functionId
,
&
index
,
resultType
,
resultSize
,
resultSize
);
addExprParams
(
pExpr
,
val
,
TSDB_DATA_TYPE_BIGINT
,
sizeof
(
int64_t
),
0
);
addExprParams
(
pExpr
,
val
,
TSDB_DATA_TYPE_BIGINT
,
sizeof
(
int64_t
),
0
);
}
}
...
@@ -1887,7 +1886,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
...
@@ -1887,7 +1886,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIdx, tSQLExprIt
SColumnList
ids
=
getColumnList
(
1
,
0
,
index
.
columnIndex
);
SColumnList
ids
=
getColumnList
(
1
,
0
,
index
.
columnIndex
);
if
(
finalResult
)
{
if
(
finalResult
)
{
insertResultField
(
pQueryInfo
,
colI
d
x
,
&
ids
,
resultSize
,
resultType
,
pExpr
->
aliasName
,
pExpr
);
insertResultField
(
pQueryInfo
,
colI
nde
x
,
&
ids
,
resultSize
,
resultType
,
pExpr
->
aliasName
,
pExpr
);
}
else
{
}
else
{
for
(
int32_t
i
=
0
;
i
<
ids
.
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
ids
.
num
;
++
i
)
{
tscColumnBaseInfoInsert
(
pQueryInfo
,
&
(
ids
.
ids
[
i
]));
tscColumnBaseInfoInsert
(
pQueryInfo
,
&
(
ids
.
ids
[
i
]));
...
@@ -2275,7 +2274,7 @@ int32_t tscTansformSQLFunctionForSTableQuery(SQueryInfo* pQueryInfo) {
...
@@ -2275,7 +2274,7 @@ int32_t tscTansformSQLFunctionForSTableQuery(SQueryInfo* pQueryInfo) {
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
k
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
k
);
int16_t
functionId
=
aAggs
[
pExpr
->
functionId
].
stableFuncId
;
int16_t
functionId
=
aAggs
[
pExpr
->
functionId
].
stableFuncId
;
int32_t
colIndex
=
pExpr
->
colInfo
.
colI
d
x
;
int32_t
colIndex
=
pExpr
->
colInfo
.
colI
nde
x
;
SSchema
*
pSrcSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
colIndex
);
SSchema
*
pSrcSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
colIndex
);
if
((
functionId
>=
TSDB_FUNC_SUM
&&
functionId
<=
TSDB_FUNC_TWA
)
||
if
((
functionId
>=
TSDB_FUNC_SUM
&&
functionId
<=
TSDB_FUNC_TWA
)
||
...
@@ -2286,7 +2285,7 @@ int32_t tscTansformSQLFunctionForSTableQuery(SQueryInfo* pQueryInfo) {
...
@@ -2286,7 +2285,7 @@ int32_t tscTansformSQLFunctionForSTableQuery(SQueryInfo* pQueryInfo) {
return
TSDB_CODE_INVALID_SQL
;
return
TSDB_CODE_INVALID_SQL
;
}
}
tscSqlExprUpdate
(
pQueryInfo
,
k
,
functionId
,
pExpr
->
colInfo
.
colI
d
x
,
TSDB_DATA_TYPE_BINARY
,
bytes
);
tscSqlExprUpdate
(
pQueryInfo
,
k
,
functionId
,
pExpr
->
colInfo
.
colI
nde
x
,
TSDB_DATA_TYPE_BINARY
,
bytes
);
// todo refactor
// todo refactor
pExpr
->
interResBytes
=
intermediateBytes
;
pExpr
->
interResBytes
=
intermediateBytes
;
}
}
...
@@ -2305,7 +2304,7 @@ void tscRestoreSQLFunctionForMetricQuery(SQueryInfo* pQueryInfo) {
...
@@ -2305,7 +2304,7 @@ void tscRestoreSQLFunctionForMetricQuery(SQueryInfo* pQueryInfo) {
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
pExpr
->
colInfo
.
colI
d
x
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
pExpr
->
colInfo
.
colI
nde
x
);
// if (/*(pExpr->functionId >= TSDB_FUNC_FIRST_DST && pExpr->functionId <= TSDB_FUNC_LAST_DST) ||
// if (/*(pExpr->functionId >= TSDB_FUNC_FIRST_DST && pExpr->functionId <= TSDB_FUNC_LAST_DST) ||
// (pExpr->functionId >= TSDB_FUNC_SUM && pExpr->functionId <= TSDB_FUNC_MAX) ||
// (pExpr->functionId >= TSDB_FUNC_SUM && pExpr->functionId <= TSDB_FUNC_MAX) ||
...
@@ -2352,7 +2351,7 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) {
...
@@ -2352,7 +2351,7 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) {
}
}
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
!=
1
||
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
!=
1
||
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
d
x
!=
TSDB_TBNAME_COLUMN_INDEX
)
{
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
nde
x
!=
TSDB_TBNAME_COLUMN_INDEX
)
{
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
return
true
;
return
true
;
}
}
...
@@ -2403,12 +2402,12 @@ void updateTagColumnIndex(SQueryInfo* pQueryInfo, int32_t tableIndex) {
...
@@ -2403,12 +2402,12 @@ void updateTagColumnIndex(SQueryInfo* pQueryInfo, int32_t tableIndex) {
*/
*/
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
>
0
&&
pQueryInfo
->
groupbyExpr
.
tableIndex
==
tableIndex
)
{
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
>
0
&&
pQueryInfo
->
groupbyExpr
.
tableIndex
==
tableIndex
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
int32_t
index
=
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
].
colI
d
x
;
int32_t
index
=
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
].
colI
nde
x
;
for
(
int32_t
j
=
0
;
j
<
pTableMetaInfo
->
numOfTags
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pTableMetaInfo
->
numOfTags
;
++
j
)
{
int32_t
tagColIndex
=
pTableMetaInfo
->
tagColumnIndex
[
j
];
int32_t
tagColIndex
=
pTableMetaInfo
->
tagColumnIndex
[
j
];
if
(
tagColIndex
==
index
)
{
if
(
tagColIndex
==
index
)
{
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
].
colI
d
x
=
j
;
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
].
colI
nde
x
=
j
;
break
;
break
;
}
}
}
}
...
@@ -2429,8 +2428,8 @@ void updateTagColumnIndex(SQueryInfo* pQueryInfo, int32_t tableIndex) {
...
@@ -2429,8 +2428,8 @@ void updateTagColumnIndex(SQueryInfo* pQueryInfo, int32_t tableIndex) {
}
}
for
(
int32_t
j
=
0
;
j
<
pTableMetaInfo
->
numOfTags
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pTableMetaInfo
->
numOfTags
;
++
j
)
{
if
(
pExpr
->
colInfo
.
colI
d
x
==
pTableMetaInfo
->
tagColumnIndex
[
j
])
{
if
(
pExpr
->
colInfo
.
colI
nde
x
==
pTableMetaInfo
->
tagColumnIndex
[
j
])
{
pExpr
->
colInfo
.
colI
d
x
=
j
;
pExpr
->
colInfo
.
colI
nde
x
=
j
;
break
;
break
;
}
}
}
}
...
@@ -2529,8 +2528,8 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
...
@@ -2529,8 +2528,8 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
}
}
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
]
=
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
]
=
(
SColIndex
Ex
){.
colId
x
=
relIndex
,
.
flag
=
TSDB_COL_TAG
,
.
colId
=
pSchema
->
colId
};
// relIndex;
(
SColIndex
){.
colInde
x
=
relIndex
,
.
flag
=
TSDB_COL_TAG
,
.
colId
=
pSchema
->
colId
};
// relIndex;
addRequiredTagColumn
(
pQueryInfo
,
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
].
colI
d
x
,
index
.
tableIndex
);
addRequiredTagColumn
(
pQueryInfo
,
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
].
colI
nde
x
,
index
.
tableIndex
);
}
else
{
}
else
{
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by
if
(
pSchema
->
type
>
TSDB_DATA_TYPE_BINARY
)
{
if
(
pSchema
->
type
>
TSDB_DATA_TYPE_BINARY
)
{
...
@@ -2539,8 +2538,8 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
...
@@ -2539,8 +2538,8 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
tscColumnBaseInfoInsert
(
pQueryInfo
,
&
index
);
tscColumnBaseInfoInsert
(
pQueryInfo
,
&
index
);
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
]
=
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
]
=
(
SColIndex
Ex
){.
colId
x
=
index
.
columnIndex
,
.
flag
=
TSDB_COL_NORMAL
,
.
colId
=
pSchema
->
colId
};
// relIndex;
(
SColIndex
){.
colInde
x
=
index
.
columnIndex
,
.
flag
=
TSDB_COL_NORMAL
,
.
colId
=
pSchema
->
colId
};
// relIndex;
pQueryInfo
->
groupbyExpr
.
orderType
=
TS
QL_SO
_ASC
;
pQueryInfo
->
groupbyExpr
.
orderType
=
TS
DB_ORDER
_ASC
;
if
(
i
==
0
&&
pList
->
nExpr
>
1
)
{
if
(
i
==
0
&&
pList
->
nExpr
>
1
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg7
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg7
);
...
@@ -2630,10 +2629,10 @@ static int32_t doExtractColumnFilterInfo(SQueryInfo* pQueryInfo, SColumnFilterIn
...
@@ -2630,10 +2629,10 @@ static int32_t doExtractColumnFilterInfo(SQueryInfo* pQueryInfo, SColumnFilterIn
pColumnFilter
->
upperRelOptr
=
TSDB_RELATION_LESS
;
pColumnFilter
->
upperRelOptr
=
TSDB_RELATION_LESS
;
break
;
break
;
case
TK_GT
:
case
TK_GT
:
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_
LARGE
;
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_
GREATER
;
break
;
break
;
case
TK_GE
:
case
TK_GE
:
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_
LARGE
_EQUAL
;
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_
GREATER
_EQUAL
;
break
;
break
;
case
TK_EQ
:
case
TK_EQ
:
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_EQUAL
;
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_EQUAL
;
...
@@ -2892,6 +2891,7 @@ static void relToString(tSQLExpr* pExpr, char** str) {
...
@@ -2892,6 +2891,7 @@ static void relToString(tSQLExpr* pExpr, char** str) {
}
}
}
}
UNUSED_FUNC
static
int32_t
getTagCondString
(
tSQLExpr
*
pExpr
,
char
**
str
)
{
static
int32_t
getTagCondString
(
tSQLExpr
*
pExpr
,
char
**
str
)
{
if
(
pExpr
==
NULL
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -3593,7 +3593,7 @@ static bool validateFilterExpr(SQueryInfo* pQueryInfo) {
...
@@ -3593,7 +3593,7 @@ static bool validateFilterExpr(SQueryInfo* pQueryInfo) {
int32_t
lowerOptr
=
pColFilter
->
lowerRelOptr
;
int32_t
lowerOptr
=
pColFilter
->
lowerRelOptr
;
int32_t
upperOptr
=
pColFilter
->
upperRelOptr
;
int32_t
upperOptr
=
pColFilter
->
upperRelOptr
;
if
((
lowerOptr
==
TSDB_RELATION_
LARGE_EQUAL
||
lowerOptr
==
TSDB_RELATION_LARGE
)
&&
if
((
lowerOptr
==
TSDB_RELATION_
GREATER_EQUAL
||
lowerOptr
==
TSDB_RELATION_GREATER
)
&&
(
upperOptr
==
TSDB_RELATION_LESS_EQUAL
||
upperOptr
==
TSDB_RELATION_LESS
))
{
(
upperOptr
==
TSDB_RELATION_LESS_EQUAL
||
upperOptr
==
TSDB_RELATION_LESS
))
{
continue
;
continue
;
}
}
...
@@ -3727,28 +3727,27 @@ static void doAddJoinTagsColumnsIntoTagList(SQueryInfo* pQueryInfo, SCondExpr* p
...
@@ -3727,28 +3727,27 @@ static void doAddJoinTagsColumnsIntoTagList(SQueryInfo* pQueryInfo, SCondExpr* p
static
int32_t
getTagQueryCondExpr
(
SQueryInfo
*
pQueryInfo
,
SCondExpr
*
pCondExpr
,
tSQLExpr
**
pExpr
)
{
static
int32_t
getTagQueryCondExpr
(
SQueryInfo
*
pQueryInfo
,
SCondExpr
*
pCondExpr
,
tSQLExpr
**
pExpr
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
if
(
pCondExpr
->
pTagCond
!=
NULL
)
{
if
(
pCondExpr
->
pTagCond
==
NULL
)
{
return
ret
;
}
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
tSQLExpr
*
p1
=
extractExprForSTable
(
pExpr
,
pQueryInfo
,
i
);
tSQLExpr
*
p1
=
extractExprForSTable
(
pExpr
,
pQueryInfo
,
i
);
tExprNode
*
p
=
NULL
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
ret
=
exprTreeFromSqlExpr
(
&
p
,
p1
,
NULL
,
pQueryInfo
,
NULL
);
SBuffer
buf
=
exprTreeToBinary
(
p
);
char
c
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
char
*
str
=
c
;
if
((
ret
=
getTagCondString
(
p1
,
&
str
))
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
tsSetSTableQueryCond
(
&
pQueryInfo
->
tagCond
,
pTableMetaInfo
->
pTableMeta
->
uid
,
c
);
int64_t
uid
=
tscGetMetaInfo
(
pQueryInfo
,
i
)
->
pTableMeta
->
uid
;
tsSetSTableQueryCond
(
&
pQueryInfo
->
tagCond
,
uid
,
&
buf
);
doCompactQueryExpr
(
pExpr
);
doCompactQueryExpr
(
pExpr
);
tSQLExprDestroy
(
p1
);
tSQLExprDestroy
(
p1
);
tExprTreeDestroy
(
&
p
,
NULL
);
}
}
pCondExpr
->
pTagCond
=
NULL
;
pCondExpr
->
pTagCond
=
NULL
;
}
return
ret
;
return
ret
;
}
}
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tSQLExpr
**
pExpr
,
SSqlObj
*
pSql
)
{
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tSQLExpr
**
pExpr
,
SSqlObj
*
pSql
)
{
...
@@ -4044,11 +4043,11 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
...
@@ -4044,11 +4043,11 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
static
void
setDefaultOrderInfo
(
SQueryInfo
*
pQueryInfo
)
{
static
void
setDefaultOrderInfo
(
SQueryInfo
*
pQueryInfo
)
{
/* set default timestamp order information for all queries */
/* set default timestamp order information for all queries */
pQueryInfo
->
order
.
order
=
TS
QL_SO
_ASC
;
pQueryInfo
->
order
.
order
=
TS
DB_ORDER
_ASC
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
isTopBottomQuery
(
pQueryInfo
))
{
if
(
isTopBottomQuery
(
pQueryInfo
))
{
pQueryInfo
->
order
.
order
=
TS
QL_SO
_ASC
;
pQueryInfo
->
order
.
order
=
TS
DB_ORDER
_ASC
;
pQueryInfo
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
pQueryInfo
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
}
else
{
}
else
{
pQueryInfo
->
order
.
orderColId
=
-
1
;
pQueryInfo
->
order
.
orderColId
=
-
1
;
...
@@ -4056,7 +4055,7 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) {
...
@@ -4056,7 +4055,7 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) {
/* for metric query, set default ascending order for group output */
/* for metric query, set default ascending order for group output */
if
(
UTIL_TABLE_IS_SUPERTABLE
(
pTableMetaInfo
))
{
if
(
UTIL_TABLE_IS_SUPERTABLE
(
pTableMetaInfo
))
{
pQueryInfo
->
groupbyExpr
.
orderType
=
TS
QL_SO
_ASC
;
pQueryInfo
->
groupbyExpr
.
orderType
=
TS
DB_ORDER
_ASC
;
}
}
}
}
...
@@ -4112,7 +4111,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema
...
@@ -4112,7 +4111,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema
if
(
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
{
if
(
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
{
int32_t
relTagIndex
=
index
.
columnIndex
-
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
int32_t
relTagIndex
=
index
.
columnIndex
-
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
if
(
relTagIndex
==
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
d
x
)
{
if
(
relTagIndex
==
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
nde
x
)
{
orderByTags
=
true
;
orderByTags
=
true
;
}
}
}
else
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
}
else
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
...
@@ -4139,7 +4138,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema
...
@@ -4139,7 +4138,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema
assert
(
pExpr
->
functionId
==
TSDB_FUNC_TS
);
assert
(
pExpr
->
functionId
==
TSDB_FUNC_TS
);
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
1
);
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
1
);
if
(
pExpr
->
colInfo
.
colI
d
x
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
if
(
pExpr
->
colInfo
.
colI
nde
x
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
}
}
...
@@ -4190,7 +4189,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema
...
@@ -4190,7 +4189,7 @@ int32_t parseOrderbyClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema
assert
(
pExpr
->
functionId
==
TSDB_FUNC_TS
);
assert
(
pExpr
->
functionId
==
TSDB_FUNC_TS
);
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
1
);
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
1
);
if
(
pExpr
->
colInfo
.
colI
d
x
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
if
(
pExpr
->
colInfo
.
colI
nde
x
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
}
}
...
@@ -4705,7 +4704,7 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
...
@@ -4705,7 +4704,7 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
// filter the query functions operating on "tbname" column that are not supported by normal columns.
// filter the query functions operating on "tbname" column that are not supported by normal columns.
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
->
colInfo
.
colI
d
x
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
pExpr
->
colInfo
.
colI
nde
x
==
TSDB_TBNAME_COLUMN_INDEX
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
}
}
}
}
...
@@ -4851,10 +4850,10 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau
...
@@ -4851,10 +4850,10 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau
int32_t
relIndex
=
index
.
columnIndex
;
int32_t
relIndex
=
index
.
columnIndex
;
pExpr
->
colInfo
.
colI
d
x
=
relIndex
;
pExpr
->
colInfo
.
colI
nde
x
=
relIndex
;
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
d
x
=
relIndex
;
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
nde
x
=
relIndex
;
addRequiredTagColumn
(
pQueryInfo
,
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
d
x
,
0
);
addRequiredTagColumn
(
pQueryInfo
,
pQueryInfo
->
groupbyExpr
.
columnInfo
[
0
].
colI
nde
x
,
0
);
}
}
}
}
}
}
...
@@ -4867,7 +4866,7 @@ static void doLimitOutputNormalColOfGroupby(SSqlExpr* pExpr) {
...
@@ -4867,7 +4866,7 @@ static void doLimitOutputNormalColOfGroupby(SSqlExpr* pExpr) {
}
}
void
doAddGroupColumnForSubquery
(
SQueryInfo
*
pQueryInfo
,
int32_t
tagIndex
)
{
void
doAddGroupColumnForSubquery
(
SQueryInfo
*
pQueryInfo
,
int32_t
tagIndex
)
{
int32_t
index
=
pQueryInfo
->
groupbyExpr
.
columnInfo
[
tagIndex
].
colI
d
x
;
int32_t
index
=
pQueryInfo
->
groupbyExpr
.
columnInfo
[
tagIndex
].
colI
nde
x
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
...
@@ -4909,7 +4908,7 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
...
@@ -4909,7 +4908,7 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
->
functionId
!=
TSDB_FUNC_TAG_DUMMY
&&
pExpr
->
functionId
!=
TSDB_FUNC_TS_DUMMY
)
{
if
(
pExpr
->
functionId
!=
TSDB_FUNC_TAG_DUMMY
&&
pExpr
->
functionId
!=
TSDB_FUNC_TS_DUMMY
)
{
SSchema
*
pColSchema
=
&
pSchema
[
pExpr
->
colInfo
.
colI
d
x
];
SSchema
*
pColSchema
=
&
pSchema
[
pExpr
->
colInfo
.
colI
nde
x
];
getResultDataInfo
(
pColSchema
->
type
,
pColSchema
->
bytes
,
pExpr
->
functionId
,
pExpr
->
param
[
0
].
i64Key
,
&
pExpr
->
resType
,
getResultDataInfo
(
pColSchema
->
type
,
pColSchema
->
bytes
,
pExpr
->
functionId
,
pExpr
->
param
[
0
].
i64Key
,
&
pExpr
->
resType
,
&
pExpr
->
resBytes
,
&
pExpr
->
interResBytes
,
tagLength
,
true
);
&
pExpr
->
resBytes
,
&
pExpr
->
interResBytes
,
tagLength
,
true
);
}
}
...
@@ -5087,16 +5086,16 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) {
...
@@ -5087,16 +5086,16 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) {
char
*
name
=
NULL
;
char
*
name
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
i
)
{
SColIndex
Ex
*
pColIndex
=
&
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
];
SColIndex
*
pColIndex
=
&
pQueryInfo
->
groupbyExpr
.
columnInfo
[
i
];
int16_t
colIndex
=
pColIndex
->
colI
d
x
;
int16_t
colIndex
=
pColIndex
->
colI
nde
x
;
if
(
pColIndex
->
colI
d
x
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
pColIndex
->
colI
nde
x
==
TSDB_TBNAME_COLUMN_INDEX
)
{
type
=
TSDB_DATA_TYPE_BINARY
;
type
=
TSDB_DATA_TYPE_BINARY
;
bytes
=
TSDB_TABLE_NAME_LEN
;
bytes
=
TSDB_TABLE_NAME_LEN
;
name
=
TSQL_TBNAME_L
;
name
=
TSQL_TBNAME_L
;
}
else
{
}
else
{
colIndex
=
(
TSDB_COL_IS_TAG
(
pColIndex
->
flag
))
?
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
)
+
pColIndex
->
colI
d
x
colIndex
=
(
TSDB_COL_IS_TAG
(
pColIndex
->
flag
))
?
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
)
+
pColIndex
->
colI
nde
x
:
pColIndex
->
colI
d
x
;
:
pColIndex
->
colI
nde
x
;
type
=
pSchema
[
colIndex
].
type
;
type
=
pSchema
[
colIndex
].
type
;
bytes
=
pSchema
[
colIndex
].
bytes
;
bytes
=
pSchema
[
colIndex
].
bytes
;
...
@@ -5175,7 +5174,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
...
@@ -5175,7 +5174,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
if
(
functId
==
TSDB_FUNC_PRJ
&&
pExpr
->
colInfo
.
colId
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
if
(
functId
==
TSDB_FUNC_PRJ
&&
pExpr
->
colInfo
.
colId
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
bool
qualified
=
false
;
bool
qualified
=
false
;
for
(
int32_t
j
=
0
;
j
<
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
;
++
j
)
{
SColIndex
Ex
*
pColIndex
=
&
pQueryInfo
->
groupbyExpr
.
columnInfo
[
j
];
SColIndex
*
pColIndex
=
&
pQueryInfo
->
groupbyExpr
.
columnInfo
[
j
];
if
(
pColIndex
->
colId
==
pExpr
->
colInfo
.
colId
)
{
if
(
pColIndex
->
colId
==
pExpr
->
colInfo
.
colId
)
{
qualified
=
true
;
qualified
=
true
;
break
;
break
;
...
@@ -5192,7 +5191,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
...
@@ -5192,7 +5191,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg1
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg1
);
}
}
if
(
functId
==
TSDB_FUNC_COUNT
&&
pExpr
->
colInfo
.
colI
d
x
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
functId
==
TSDB_FUNC_COUNT
&&
pExpr
->
colInfo
.
colI
nde
x
==
TSDB_TBNAME_COLUMN_INDEX
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg1
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg1
);
}
}
}
}
...
@@ -5807,36 +5806,37 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
...
@@ -5807,36 +5806,37 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return
TSDB_CODE_SUCCESS
;
// Does not build query message here
return
TSDB_CODE_SUCCESS
;
// Does not build query message here
}
}
static
int32_t
convertSyntaxTreeToExprTree
(
tExprNode
**
pExpr
,
tSQLExpr
*
pAst
,
int32_t
*
num
,
int32_t
exprTreeFromSqlExpr
(
tExprNode
**
pExpr
,
tSQLExpr
*
pSqlExpr
,
SSqlExprInfo
*
pExprInfo
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pCols
)
{
SColIndexEx
**
pColIndex
,
SSqlExprInfo
*
pExprInfo
)
{
tExprNode
*
pLeft
=
NULL
;
tExprNode
*
pLeft
=
NULL
;
tExprNode
*
pRight
=
NULL
;
tExprNode
*
pRight
=
NULL
;
if
(
p
Ast
->
pLeft
!=
NULL
)
{
if
(
p
SqlExpr
->
pLeft
!=
NULL
)
{
int32_t
ret
=
convertSyntaxTreeToExprTree
(
&
pLeft
,
pAst
->
pLeft
,
num
,
pColIndex
,
pExprInfo
);
int32_t
ret
=
exprTreeFromSqlExpr
(
&
pLeft
,
pSqlExpr
->
pLeft
,
pExprInfo
,
pQueryInfo
,
pCols
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
}
}
if
(
p
Ast
->
pRight
!=
NULL
)
{
if
(
p
SqlExpr
->
pRight
!=
NULL
)
{
int32_t
ret
=
convertSyntaxTreeToExprTree
(
&
pRight
,
pAst
->
pRight
,
num
,
pColIndex
,
pExprInfo
);
int32_t
ret
=
exprTreeFromSqlExpr
(
&
pRight
,
pSqlExpr
->
pRight
,
pExprInfo
,
pQueryInfo
,
pCols
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
}
}
if
(
p
Ast
->
pLeft
==
NULL
)
{
if
(
p
SqlExpr
->
pLeft
==
NULL
)
{
if
(
p
Ast
->
nSQLOptr
>=
TK_TINYINT
&&
pAst
->
nSQLOptr
<=
TK_DOUBLE
)
{
if
(
p
SqlExpr
->
nSQLOptr
>=
TK_TINYINT
&&
pSqlExpr
->
nSQLOptr
<=
TK_DOUBLE
)
{
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
)
+
sizeof
(
tVariant
)
);
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_VALUE
;
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_VALUE
;
(
*
pExpr
)
->
pVal
=
(
tVariant
*
)
((
char
*
)(
*
pExpr
)
+
sizeof
(
tExprNode
));
(
*
pExpr
)
->
pVal
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariantAssign
((
*
pExpr
)
->
pVal
,
&
pAst
->
val
);
}
else
if
(
pAst
->
nSQLOptr
>=
TK_COUNT
&&
pAst
->
nSQLOptr
<=
TK_AVG_IRATE
)
{
tVariantAssign
((
*
pExpr
)
->
pVal
,
&
pSqlExpr
->
val
);
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
)
+
sizeof
(
SSchemaEx
));
}
else
if
(
pSqlExpr
->
nSQLOptr
>=
TK_COUNT
&&
pSqlExpr
->
nSQLOptr
<=
TK_AVG_IRATE
)
{
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_COL
;
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_COL
;
(
*
pExpr
)
->
pSchema
=
(
SSchema
*
)((
char
*
)(
*
pExpr
)
+
sizeof
(
tExprNode
));
(
*
pExpr
)
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
strncpy
((
*
pExpr
)
->
pSchema
->
name
,
p
Ast
->
operand
.
z
,
pAst
->
operand
.
n
);
strncpy
((
*
pExpr
)
->
pSchema
->
name
,
p
SqlExpr
->
operand
.
z
,
pSqlExpr
->
operand
.
n
);
// set the input column data byte and type.
// set the input column data byte and type.
for
(
int32_t
i
=
0
;
i
<
pExprInfo
->
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pExprInfo
->
numOfExprs
;
++
i
)
{
...
@@ -5846,20 +5846,41 @@ static int32_t convertSyntaxTreeToExprTree(tExprNode **pExpr, tSQLExpr* pAst, in
...
@@ -5846,20 +5846,41 @@ static int32_t convertSyntaxTreeToExprTree(tExprNode **pExpr, tSQLExpr* pAst, in
break
;
break
;
}
}
}
}
}
else
{
//todo return error
}
else
if
(
pSqlExpr
->
nSQLOptr
==
TK_ID
)
{
// column name
SColumnIndex
index
=
{
0
};
int32_t
ret
=
getColumnIndexByName
(
&
pSqlExpr
->
colInfo
,
pQueryInfo
,
&
index
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_COL
;
(
*
pExpr
)
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
index
.
columnIndex
);
*
(
*
pExpr
)
->
pSchema
=
*
pSchema
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
else
{
return
TSDB_CODE_INVALID_SQL
;
}
}
*
pColIndex
=
realloc
(
*
pColIndex
,
(
++
(
*
num
))
*
sizeof
(
SColIndexEx
));
if
(
pCols
!=
NULL
)
{
// record the involved columns
memset
(
&
(
*
pColIndex
)[(
*
num
)
-
1
],
0
,
sizeof
(
SColIndexEx
));
SColIndex
colIndex
=
{
0
};
strncpy
(
colIndex
.
name
,
pSqlExpr
->
operand
.
z
,
pSqlExpr
->
operand
.
n
);
taosArrayPush
(
pCols
,
&
colIndex
);
}
strncpy
((
*
pColIndex
)[(
*
num
)
-
1
].
name
,
pAst
->
operand
.
z
,
pAst
->
operand
.
n
);
}
else
{
}
else
{
*
pExpr
=
(
tExprNode
*
)
calloc
(
1
,
sizeof
(
tExprNode
));
*
pExpr
=
(
tExprNode
*
)
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_EXPR
;
(
*
pExpr
)
->
_node
.
hasPK
=
false
;
(
*
pExpr
)
->
_node
.
hasPK
=
false
;
(
*
pExpr
)
->
_node
.
pLeft
=
pLeft
;
(
*
pExpr
)
->
_node
.
pLeft
=
pLeft
;
(
*
pExpr
)
->
_node
.
pRight
=
pRight
;
(
*
pExpr
)
->
_node
.
pRight
=
pRight
;
SSQLToken
t
=
{.
type
=
pAst
->
nSQLOptr
};
SSQLToken
t
=
{.
type
=
pSqlExpr
->
nSQLOptr
};
(
*
pExpr
)
->
_node
.
optr
=
getBinaryExprOptr
(
&
t
);
(
*
pExpr
)
->
_node
.
optr
=
getBinaryExprOptr
(
&
t
);
assert
((
*
pExpr
)
->
_node
.
optr
!=
0
);
assert
((
*
pExpr
)
->
_node
.
optr
!=
0
);
...
...
src/client/src/tscSecondaryMerge.c
浏览文件 @
3f9d5cca
...
@@ -45,7 +45,7 @@ int32_t treeComparator(const void *pLeft, const void *pRight, void *param) {
...
@@ -45,7 +45,7 @@ int32_t treeComparator(const void *pLeft, const void *pRight, void *param) {
return
-
1
;
return
-
1
;
}
}
if
(
pParam
->
groupOrderType
==
TS
QL_SO
_DESC
)
{
// desc
if
(
pParam
->
groupOrderType
==
TS
DB_ORDER
_DESC
)
{
// desc
return
compare_d
(
pDesc
,
pParam
->
numOfElems
,
pLocalData
[
pLeftIdx
]
->
rowIdx
,
pLocalData
[
pLeftIdx
]
->
filePage
.
data
,
return
compare_d
(
pDesc
,
pParam
->
numOfElems
,
pLocalData
[
pLeftIdx
]
->
rowIdx
,
pLocalData
[
pLeftIdx
]
->
filePage
.
data
,
pParam
->
numOfElems
,
pLocalData
[
pRightIdx
]
->
rowIdx
,
pLocalData
[
pRightIdx
]
->
filePage
.
data
);
pParam
->
numOfElems
,
pLocalData
[
pRightIdx
]
->
rowIdx
,
pLocalData
[
pRightIdx
]
->
filePage
.
data
);
}
else
{
}
else
{
...
@@ -652,7 +652,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
...
@@ -652,7 +652,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSchema
*
p1
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
pExpr
->
colInfo
.
colI
d
x
);
SSchema
*
p1
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
pExpr
->
colInfo
.
colI
nde
x
);
int16_t
inter
=
0
;
int16_t
inter
=
0
;
int16_t
type
=
-
1
;
int16_t
type
=
-
1
;
...
@@ -990,7 +990,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
...
@@ -990,7 +990,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
savePrevRecordAndSetupInterpoInfo
(
pLocalReducer
,
pQueryInfo
,
pInterpoInfo
);
savePrevRecordAndSetupInterpoInfo
(
pLocalReducer
,
pQueryInfo
,
pInterpoInfo
);
}
}
if
(
pQueryInfo
->
order
.
order
==
TS
QL_SO
_ASC
)
{
if
(
pQueryInfo
->
order
.
order
==
TS
DB_ORDER
_ASC
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pLocalReducer
->
resColModel
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pLocalReducer
->
resColModel
,
i
);
...
@@ -1168,7 +1168,7 @@ bool needToMerge(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer, tFilePage
...
@@ -1168,7 +1168,7 @@ bool needToMerge(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer, tFilePage
}
else
{
}
else
{
tOrderDescriptor
*
pDesc
=
pLocalReducer
->
pDesc
;
tOrderDescriptor
*
pDesc
=
pLocalReducer
->
pDesc
;
if
(
pDesc
->
orderIdx
.
numOfCols
>
0
)
{
if
(
pDesc
->
orderIdx
.
numOfCols
>
0
)
{
if
(
pDesc
->
tsOrder
==
TS
QL_SO
_ASC
)
{
// asc
if
(
pDesc
->
tsOrder
==
TS
DB_ORDER
_ASC
)
{
// asc
// todo refactor comparator
// todo refactor comparator
ret
=
compare_a
(
pLocalReducer
->
pDesc
,
1
,
0
,
pLocalReducer
->
prevRowOfInput
,
1
,
0
,
tmpBuffer
->
data
);
ret
=
compare_a
(
pLocalReducer
->
pDesc
,
1
,
0
,
pLocalReducer
->
prevRowOfInput
,
1
,
0
,
tmpBuffer
->
data
);
}
else
{
// desc
}
else
{
// desc
...
...
src/client/src/tscServer.c
浏览文件 @
3f9d5cca
...
@@ -37,12 +37,25 @@ int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0};
...
@@ -37,12 +37,25 @@ int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0};
int
(
*
tscProcessMsgRsp
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
);
int
(
*
tscProcessMsgRsp
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
);
void
tscProcessActivityTimer
(
void
*
handle
,
void
*
tmrId
);
void
tscProcessActivityTimer
(
void
*
handle
,
void
*
tmrId
);
int
tscKeepConn
[
TSDB_SQL_MAX
]
=
{
0
};
int
tscKeepConn
[
TSDB_SQL_MAX
]
=
{
0
};
TSKEY
tscGetSubscriptionProgress
(
void
*
sub
,
int64_t
uid
);
TSKEY
tscGetSubscriptionProgress
(
void
*
sub
,
int64_t
uid
);
void
tscUpdateSubscriptionProgress
(
void
*
sub
,
int64_t
uid
,
TSKEY
ts
);
void
tscUpdateSubscriptionProgress
(
void
*
sub
,
int64_t
uid
,
TSKEY
ts
);
void
tscSaveSubscriptionProgress
(
void
*
sub
);
void
tscSaveSubscriptionProgress
(
void
*
sub
);
static
int32_t
minMsgSize
()
{
return
tsRpcHeadSize
+
100
;
}
static
int32_t
minMsgSize
()
{
return
tsRpcHeadSize
+
100
;
}
static
void
tscSetDnodeIpList
(
SSqlObj
*
pSql
,
STableMeta
*
pTableMeta
)
{
SRpcIpSet
*
pIpList
=
&
pSql
->
ipList
;
pIpList
->
numOfIps
=
pTableMeta
->
numOfVpeers
;
pIpList
->
port
=
tsDnodeShellPort
;
pIpList
->
inUse
=
0
;
for
(
int32_t
i
=
0
;
i
<
pTableMeta
->
numOfVpeers
;
++
i
)
{
pIpList
->
ip
[
i
]
=
pTableMeta
->
vpeerDesc
[
i
].
ip
;
}
}
void
tscPrintMgmtIp
()
{
void
tscPrintMgmtIp
()
{
if
(
tscMgmtIpList
.
numOfIps
<=
0
)
{
if
(
tscMgmtIpList
.
numOfIps
<=
0
)
{
tscError
(
"invalid mgmt IP list:%d"
,
tscMgmtIpList
.
numOfIps
);
tscError
(
"invalid mgmt IP list:%d"
,
tscMgmtIpList
.
numOfIps
);
...
@@ -178,17 +191,6 @@ int tscSendMsgToServer(SSqlObj *pSql) {
...
@@ -178,17 +191,6 @@ int tscSendMsgToServer(SSqlObj *pSql) {
}
}
if
(
pSql
->
cmd
.
command
<
TSDB_SQL_MGMT
)
{
if
(
pSql
->
cmd
.
command
<
TSDB_SQL_MGMT
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
pSql
->
ipList
.
numOfIps
=
pTableMeta
->
numOfVpeers
;
pSql
->
ipList
.
port
=
tsDnodeShellPort
;
pSql
->
ipList
.
inUse
=
0
;
for
(
int32_t
i
=
0
;
i
<
pTableMeta
->
numOfVpeers
;
++
i
)
{
pSql
->
ipList
.
ip
[
i
]
=
pTableMeta
->
vpeerDesc
[
i
].
ip
;
}
tscPrint
(
"%p msg:%s is sent to server %d"
,
pSql
,
taosMsg
[
pSql
->
cmd
.
msgType
],
pSql
->
ipList
.
port
);
tscPrint
(
"%p msg:%s is sent to server %d"
,
pSql
,
taosMsg
[
pSql
->
cmd
.
msgType
],
pSql
->
ipList
.
port
);
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
+
tsRpcHeadSize
,
pSql
->
cmd
.
payloadLen
);
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
+
tsRpcHeadSize
,
pSql
->
cmd
.
payloadLen
);
...
@@ -266,19 +268,18 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
...
@@ -266,19 +268,18 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
rpcFreeCont
(
rpcMsg
->
pCont
);
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
return
;
}
else
{
}
else
{
tsc
Trace
(
"%p it shall renew table meta, code:%d"
,
pSql
,
tstrerror
(
rpcMsg
->
code
)
);
tsc
Warn
(
"%p it shall renew table meta, code:%s, retry:%d"
,
pSql
,
tstrerror
(
rpcMsg
->
code
),
++
pSql
->
retry
);
pSql
->
maxRetry
=
TSDB_VNODES_SUPPORT
*
2
;
pSql
->
maxRetry
=
TSDB_VNODES_SUPPORT
*
2
;
// todo move away
pSql
->
res
.
code
=
rpcMsg
->
code
;
// keep the previous error code
pSql
->
res
.
code
=
rpcMsg
->
code
;
// keep the previous error code
if
(
++
pSql
->
retry
>
pSql
->
maxRetry
)
{
if
(
pSql
->
retry
>
pSql
->
maxRetry
)
{
tscError
(
"%p max retry %d reached, "
,
pSql
,
pSql
->
retry
);
tscError
(
"%p max retry %d reached, give up"
,
pSql
,
pSql
->
maxRetry
);
return
;
}
else
{
}
rpcMsg
->
code
=
tscRenewMeterMeta
(
pSql
,
pTableMetaInfo
->
name
);
rpcMsg
->
code
=
tscRenewMeterMeta
(
pSql
,
pTableMetaInfo
->
name
);
if
(
pTableMetaInfo
->
pTableMeta
)
{
if
(
pTableMetaInfo
->
pTableMeta
)
{
tscSendMsgToServer
(
pSql
);
tscSendMsgToServer
(
pSql
);
}
rpcFreeCont
(
rpcMsg
->
pCont
);
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
return
;
}
}
...
@@ -286,7 +287,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
...
@@ -286,7 +287,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
}
}
}
}
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
)
{
tscTrace
(
"%p reset retry counter to be 0 due to success rsp, old:%d"
,
pSql
,
pSql
->
retry
);
pSql
->
retry
=
0
;
pSql
->
retry
=
0
;
}
pRes
->
rspLen
=
0
;
pRes
->
rspLen
=
0
;
if
(
pRes
->
code
!=
TSDB_CODE_QUERY_CANCELLED
)
{
if
(
pRes
->
code
!=
TSDB_CODE_QUERY_CANCELLED
)
{
...
@@ -331,7 +336,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
...
@@ -331,7 +336,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
pMsg
->
numOfFailedBlocks
=
htonl
(
pMsg
->
numOfFailedBlocks
);
pMsg
->
numOfFailedBlocks
=
htonl
(
pMsg
->
numOfFailedBlocks
);
pRes
->
numOfRows
+=
pMsg
->
affectedRows
;
pRes
->
numOfRows
+=
pMsg
->
affectedRows
;
tscTrace
(
"%p cmd:%d code:%
d, inserted rows:%d, rsp len:%d"
,
pSql
,
pCmd
->
command
,
pRes
->
code
,
tscTrace
(
"%p cmd:%d code:%
s, inserted rows:%d, rsp len:%d"
,
pSql
,
pCmd
->
command
,
tstrerror
(
pRes
->
code
)
,
pMsg
->
affectedRows
,
pRes
->
rspLen
);
pMsg
->
affectedRows
,
pRes
->
rspLen
);
}
else
{
}
else
{
tscTrace
(
"%p cmd:%d code:%s rsp len:%d"
,
pSql
,
pCmd
->
command
,
tstrerror
(
pRes
->
code
),
pRes
->
rspLen
);
tscTrace
(
"%p cmd:%d code:%s rsp len:%d"
,
pSql
,
pCmd
->
command
,
tstrerror
(
pRes
->
code
),
pRes
->
rspLen
);
...
@@ -550,8 +555,9 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -550,8 +555,9 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
// 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
;
tsc
Trace
(
"%p build submit msg, vgId:%d numOfVnodes:%d"
,
pSql
,
pTableMeta
->
vgId
,
htonl
(
pMsgDesc
->
numOfVnodes
)
);
tsc
SetDnodeIpList
(
pSql
,
pTableMeta
);
tscTrace
(
"%p build submit msg, vgId:%d numOfVnodes:%d"
,
pSql
,
pTableMeta
->
vgId
,
htonl
(
pMsgDesc
->
numOfVnodes
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -644,15 +650,22 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -644,15 +650,22 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if
(
UTIL_TABLE_IS_NOMRAL_TABLE
(
pTableMetaInfo
))
{
if
(
UTIL_TABLE_IS_NOMRAL_TABLE
(
pTableMetaInfo
))
{
numOfTables
=
1
;
numOfTables
=
1
;
tscSetDnodeIpList
(
pSql
,
pTableMeta
);
pQueryMsg
->
head
.
vgId
=
htonl
(
pTableMeta
->
vgId
);
pQueryMsg
->
head
.
vgId
=
htonl
(
pTableMeta
->
vgId
);
tscTrace
(
"%p queried tables:%d, table id: %s"
,
pSql
,
1
,
pTableMetaInfo
->
name
);
tscTrace
(
"%p queried tables:%d, table id: %s"
,
pSql
,
1
,
pTableMetaInfo
->
name
);
}
else
{
// query
on
super table
}
else
{
// query super table
if
(
pTableMetaInfo
->
vnodeIndex
<
0
)
{
if
(
pTableMetaInfo
->
vnodeIndex
<
0
)
{
tscError
(
"%p error vnodeIdx:%d"
,
pSql
,
pTableMetaInfo
->
vnodeIndex
);
tscError
(
"%p error vnodeIdx:%d"
,
pSql
,
pTableMetaInfo
->
vnodeIndex
);
return
-
1
;
return
-
1
;
}
}
uint32_t
vnodeId
=
1
;
pSql
->
ipList
.
numOfIps
=
taosArrayGetSize
(
pTableMetaInfo
->
vgroupIdList
);
pSql
->
ipList
.
port
=
tsDnodeShellPort
;
pSql
->
ipList
.
inUse
=
0
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
ipList
.
numOfIps
;
++
i
)
{
pSql
->
ipList
.
ip
[
i
]
=
*
(
uint32_t
*
)
taosArrayGet
(
pTableMetaInfo
->
vgroupIdList
,
i
);
}
#if 0
#if 0
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pTableMetaInfo->vnodeIndex);
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pTableMetaInfo->vnodeIndex);
...
@@ -665,12 +678,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -665,12 +678,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
#endif
#endif
uint32_t
vnodeId
=
1
;
tscTrace
(
"%p query on vid:%d, number of tables:%d"
,
pSql
,
vnodeId
,
numOfTables
);
tscTrace
(
"%p query on vid:%d, number of tables:%d"
,
pSql
,
vnodeId
,
numOfTables
);
pQueryMsg
->
head
.
vgId
=
htonl
(
vnodeId
);
pQueryMsg
->
head
.
vgId
=
htonl
(
vnodeId
);
numOfTables
=
1
;
numOfTables
=
1
;
}
}
if
(
pQueryInfo
->
order
.
order
==
TS
QL_SO
_ASC
)
{
if
(
pQueryInfo
->
order
.
order
==
TS
DB_ORDER
_ASC
)
{
pQueryMsg
->
window
.
skey
=
htobe64
(
pQueryInfo
->
stime
);
pQueryMsg
->
window
.
skey
=
htobe64
(
pQueryInfo
->
stime
);
pQueryMsg
->
window
.
ekey
=
htobe64
(
pQueryInfo
->
etime
);
pQueryMsg
->
window
.
ekey
=
htobe64
(
pQueryInfo
->
etime
);
}
else
{
}
else
{
...
@@ -760,13 +774,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -760,13 +774,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
if
(
!
tscValidateColumnId
(
pTableMetaInfo
,
pExpr
->
colInfo
.
colId
))
{
if
(
!
tscValidateColumnId
(
pTableMetaInfo
,
pExpr
->
colInfo
.
colId
))
{
/* column id is not valid according to the cached metermeta, the
meter
meta is expired */
/* column id is not valid according to the cached metermeta, the
table
meta is expired */
tscError
(
"%p table schema is not matched with parsed sql"
,
pSql
);
tscError
(
"%p table schema is not matched with parsed sql"
,
pSql
);
return
-
1
;
return
-
1
;
}
}
pSqlFuncExpr
->
colInfo
.
colId
=
htons
(
pExpr
->
colInfo
.
colId
);
pSqlFuncExpr
->
colInfo
.
colId
=
htons
(
pExpr
->
colInfo
.
colId
);
pSqlFuncExpr
->
colInfo
.
colI
dx
=
htons
(
pExpr
->
colInfo
.
colId
x
);
pSqlFuncExpr
->
colInfo
.
colI
ndex
=
htons
(
pExpr
->
colInfo
.
colInde
x
);
pSqlFuncExpr
->
colInfo
.
flag
=
htons
(
pExpr
->
colInfo
.
flag
);
pSqlFuncExpr
->
colInfo
.
flag
=
htons
(
pExpr
->
colInfo
.
flag
);
pSqlFuncExpr
->
functionId
=
htons
(
pExpr
->
functionId
);
pSqlFuncExpr
->
functionId
=
htons
(
pExpr
->
functionId
);
...
@@ -815,16 +829,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -815,16 +829,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
orderType
=
htons
(
pGroupbyExpr
->
orderType
);
pQueryMsg
->
orderType
=
htons
(
pGroupbyExpr
->
orderType
);
for
(
int32_t
j
=
0
;
j
<
pGroupbyExpr
->
numOfGroupCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pGroupbyExpr
->
numOfGroupCols
;
++
j
)
{
SColIndex
Ex
*
pCol
=
&
pGroupbyExpr
->
columnInfo
[
j
];
SColIndex
*
pCol
=
&
pGroupbyExpr
->
columnInfo
[
j
];
*
((
int16_t
*
)
pMsg
)
=
pCol
->
colId
;
*
((
int16_t
*
)
pMsg
)
=
pCol
->
colId
;
pMsg
+=
sizeof
(
pCol
->
colId
);
pMsg
+=
sizeof
(
pCol
->
colId
);
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
colIdx
;
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
colIndex
;
pMsg
+=
sizeof
(
pCol
->
colIdx
);
pMsg
+=
sizeof
(
pCol
->
colIndex
);
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
colIdxInBuf
;
pMsg
+=
sizeof
(
pCol
->
colIdxInBuf
);
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
flag
;
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
flag
;
pMsg
+=
sizeof
(
pCol
->
flag
);
pMsg
+=
sizeof
(
pCol
->
flag
);
...
@@ -866,34 +877,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -866,34 +877,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
// serialize tag column query condition
// serialize tag column query condition
if
(
pQueryInfo
->
tagCond
.
numOfTagCond
>
0
)
{
if
(
pQueryInfo
->
tagCond
.
pCond
!=
NULL
&&
taosArrayGetSize
(
pQueryInfo
->
tagCond
.
pCond
)
>
0
)
{
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
SCond
*
pCond
=
tsGetSTableQueryCond
Pos
(
pTagCond
,
pTableMeta
->
uid
);
SCond
*
pCond
=
tsGetSTableQueryCond
(
pTagCond
,
pTableMeta
->
uid
);
if
(
pCond
!=
NULL
&&
pCond
->
cond
!=
NULL
)
{
if
(
pCond
!=
NULL
&&
pCond
->
cond
!=
NULL
)
{
size_t
condLen
=
strlen
(
pCond
->
cond
)
+
1
;
pQueryMsg
->
tagCondLen
=
htons
(
pCond
->
len
);
memcpy
(
pMsg
,
pCond
->
cond
,
pCond
->
len
);
bool
ret
=
taosMbsToUcs4
(
pCond
->
cond
,
condLen
,
pMsg
,
condLen
*
TSDB_NCHAR_SIZE
);
if
(
!
ret
)
{
tscError
(
"%p mbs to ucs4 failed:%d"
,
pSql
,
tsGetSTableQueryCondPos
(
pTagCond
,
pTableMeta
->
uid
));
return
0
;
}
pQueryMsg
->
tagCondLen
=
htons
(
condLen
);
pMsg
+=
pCond
->
len
;
pMsg
+=
condLen
*
TSDB_NCHAR_SIZE
;
}
}
}
}
// tbname in/like query expression should be sent to mgmt node
// tbname in/like query expression should be sent to mgmt node
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
if
(
pTagCond
->
tbnameCond
.
cond
!=
NULL
)
{
size_t
s
=
strlen
(
pTagCond
->
tbnameCond
.
cond
);
memcpy
(
pMsg
,
pTagCond
->
tbnameCond
.
cond
,
s
);
pQueryMsg
->
nameCondLen
=
htons
(
s
);
pMsg
+=
s
;
}
msgLen
=
pMsg
-
pStart
;
msgLen
=
pMsg
-
pStart
;
tscTrace
(
"%p msg built success,len:%d bytes"
,
pSql
,
msgLen
);
tscTrace
(
"%p msg built success,len:%d bytes"
,
pSql
,
msgLen
);
...
@@ -1546,7 +1542,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1546,7 +1542,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
/**
/**
* multi
meter
meta req pkg format:
* multi
table
meta req pkg format:
* | SMgmtHead | SCMMultiTableInfoMsg | tableId0 | tableId1 | tableId2 | ......
* | SMgmtHead | SCMMultiTableInfoMsg | tableId0 | tableId1 | tableId2 | ......
* no used 4B
* no used 4B
**/
**/
...
@@ -1591,8 +1587,10 @@ static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
...
@@ -1591,8 +1587,10 @@ static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
int32_t
n
=
0
;
int32_t
n
=
0
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
tagCond
.
numOfTagCond
;
++
i
)
{
size_t
size
=
taosArrayGetSize
(
pQueryInfo
->
tagCond
.
pCond
);
n
+=
strlen
(
pQueryInfo
->
tagCond
.
cond
[
i
].
cond
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
assert
(
0
);
// n += strlen(pQueryInfo->tagCond.cond[i].cond);
}
}
int32_t
tagLen
=
n
*
TSDB_NCHAR_SIZE
;
int32_t
tagLen
=
n
*
TSDB_NCHAR_SIZE
;
...
@@ -1603,7 +1601,7 @@ static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
...
@@ -1603,7 +1601,7 @@ static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
int32_t
joinCondLen
=
(
TSDB_TABLE_ID_LEN
+
sizeof
(
int16_t
))
*
2
;
int32_t
joinCondLen
=
(
TSDB_TABLE_ID_LEN
+
sizeof
(
int16_t
))
*
2
;
int32_t
elemSize
=
sizeof
(
SSuperTableMetaElemMsg
)
*
pQueryInfo
->
numOfTables
;
int32_t
elemSize
=
sizeof
(
SSuperTableMetaElemMsg
)
*
pQueryInfo
->
numOfTables
;
int32_t
colSize
=
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
*
sizeof
(
SColIndex
Ex
);
int32_t
colSize
=
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
*
sizeof
(
SColIndex
);
int32_t
len
=
tagLen
+
joinCondLen
+
elemSize
+
colSize
+
defaultSize
;
int32_t
len
=
tagLen
+
joinCondLen
+
elemSize
+
colSize
+
defaultSize
;
...
@@ -1675,13 +1673,13 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1675,13 +1673,13 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
// convert to unicode before sending to mnode for metric query
// convert to unicode before sending to mnode for metric query
int32_t condLen = 0;
int32_t condLen = 0;
if (pTagCond->numOfTagCond > 0) {
if (pTagCond->numOfTagCond > 0) {
SCond *pCond = tsGetSTableQueryCond
Pos
(pTagCond, uid);
SCond *pCond = tsGetSTableQueryCond(pTagCond, uid);
if (pCond != NULL && pCond->cond != NULL) {
if (pCond != NULL && pCond->cond != NULL) {
condLen = strlen(pCond->cond) + 1;
condLen = strlen(pCond->cond) + 1;
bool ret = taosMbsToUcs4(pCond->cond, condLen, pMsg, condLen * TSDB_NCHAR_SIZE);
bool ret = taosMbsToUcs4(pCond->cond, condLen, pMsg, condLen * TSDB_NCHAR_SIZE);
if (!ret) {
if (!ret) {
tscError("%p mbs to ucs4 failed:%s", pSql, tsGetSTableQueryCond
Pos
(pTagCond, uid));
tscError("%p mbs to ucs4 failed:%s", pSql, tsGetSTableQueryCond(pTagCond, uid));
return 0;
return 0;
}
}
}
}
...
@@ -1728,16 +1726,16 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -1728,16 +1726,16 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pElem->groupbyTagColumnList = htonl(offset);
pElem->groupbyTagColumnList = htonl(offset);
for (int32_t j = 0; j < pQueryInfo->groupbyExpr.numOfGroupCols; ++j) {
for (int32_t j = 0; j < pQueryInfo->groupbyExpr.numOfGroupCols; ++j) {
SColIndex
Ex
*pCol = &pQueryInfo->groupbyExpr.columnInfo[j];
SColIndex *pCol = &pQueryInfo->groupbyExpr.columnInfo[j];
SColIndex
Ex *pDestCol = (SColIndexE
x *)pMsg;
SColIndex
*pDestCol = (SColInde
x *)pMsg;
pDestCol->colIdxInBuf = 0;
pDestCol->colIdxInBuf = 0;
pDestCol->colI
dx = htons(pCol->colId
x);
pDestCol->colI
ndex = htons(pCol->colInde
x);
pDestCol->colId = htons(pDestCol->colId);
pDestCol->colId = htons(pDestCol->colId);
pDestCol->flag = htons(pDestCol->flag);
pDestCol->flag = htons(pDestCol->flag);
strncpy(pDestCol->name, pCol->name, tListLen(pCol->name));
strncpy(pDestCol->name, pCol->name, tListLen(pCol->name));
pMsg += sizeof(SColIndex
Ex
);
pMsg += sizeof(SColIndex);
}
}
}
}
}
}
...
@@ -1897,7 +1895,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
...
@@ -1897,7 +1895,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
}
}
/**
/**
* multi
meter
meta rsp pkg format:
* multi
table
meta rsp pkg format:
* | STaosRsp | ieType | SCMMultiTableInfoMsg | SMeterMeta0 | SSchema0 | SMeterMeta1 | SSchema1 | SMeterMeta2 | SSchema2
* | STaosRsp | ieType | SCMMultiTableInfoMsg | SMeterMeta0 | SSchema0 | SMeterMeta1 | SSchema1 | SMeterMeta2 | SSchema2
* |...... 1B 1B 4B
* |...... 1B 1B 4B
**/
**/
...
@@ -2129,7 +2127,8 @@ _error_clean:
...
@@ -2129,7 +2127,8 @@ _error_clean:
// todo opt performance
// todo opt performance
for
(
int32_t
i
=
0
;
i
<
pStableVgroup
->
numOfDnodes
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pStableVgroup
->
numOfDnodes
;
++
i
)
{
taosArrayPush
(
pInfo
->
vgroupIdList
,
&
pStableVgroup
->
dnodeIps
[
i
]);
int32_t
ip
=
htonl
(
pStableVgroup
->
dnodeIps
[
i
]);
taosArrayPush
(
pInfo
->
vgroupIdList
,
&
ip
);
}
}
return
pSql
->
res
.
code
;
return
pSql
->
res
.
code
;
...
@@ -2367,7 +2366,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code);
...
@@ -2367,7 +2366,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code);
static
int32_t
getTableMetaFromMgmt
(
SSqlObj
*
pSql
,
STableMetaInfo
*
pTableMetaInfo
)
{
static
int32_t
getTableMetaFromMgmt
(
SSqlObj
*
pSql
,
STableMetaInfo
*
pTableMetaInfo
)
{
SSqlObj
*
pNew
=
calloc
(
1
,
sizeof
(
SSqlObj
));
SSqlObj
*
pNew
=
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
NULL
==
pNew
)
{
if
(
NULL
==
pNew
)
{
tscError
(
"%p malloc failed for new sqlobj to get
meter
meta"
,
pSql
);
tscError
(
"%p malloc failed for new sqlobj to get
table
meta"
,
pSql
);
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
}
}
...
@@ -2382,7 +2381,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf
...
@@ -2382,7 +2381,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf
pNew
->
cmd
.
autoCreated
=
pSql
->
cmd
.
autoCreated
;
// create table if not exists
pNew
->
cmd
.
autoCreated
=
pSql
->
cmd
.
autoCreated
;
// create table if not exists
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
tscError
(
"%p malloc failed for payload to get
meter
meta"
,
pSql
);
tscError
(
"%p malloc failed for payload to get
table
meta"
,
pSql
);
free
(
pNew
);
free
(
pNew
);
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
...
@@ -2464,9 +2463,10 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) {
...
@@ -2464,9 +2463,10 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) {
* 2. if get metermeta failed, still get the metermeta
* 2. if get metermeta failed, still get the metermeta
*/
*/
if
(
pTableMetaInfo
->
pTableMeta
==
NULL
||
!
tscQueryOnMetric
(
pCmd
))
{
if
(
pTableMetaInfo
->
pTableMeta
==
NULL
||
!
tscQueryOnMetric
(
pCmd
))
{
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
pTableMetaInfo
->
pTableMeta
)
{
if
(
pTableMetaInfo
->
pTableMeta
)
{
tscTrace
(
"%p update
meter
meta, old: numOfTags:%d, numOfCols:%d, uid:%"
PRId64
", addr:%p"
,
pSql
,
tscTrace
(
"%p update
table
meta, old: numOfTags:%d, numOfCols:%d, uid:%"
PRId64
", addr:%p"
,
pSql
,
pTableMetaInfo
->
numOfTags
,
pCmd
->
numOfCols
,
pTableMetaInfo
->
pTableMeta
->
uid
,
pTableMetaInfo
->
pTableMeta
);
tscGetNumOfTags
(
pTableMeta
),
tscGetNumOfColumns
(
pTableMeta
),
pTableMeta
->
uid
,
pTableMeta
);
}
}
tscWaitingForCreateTable
(
pCmd
);
tscWaitingForCreateTable
(
pCmd
);
...
@@ -2495,7 +2495,6 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
...
@@ -2495,7 +2495,6 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
}
}
#if 0
#if 0
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
char tagstr[TSDB_MAX_TAGS_LEN + 1] = {0};
char tagstr[TSDB_MAX_TAGS_LEN + 1] = {0};
...
@@ -2534,7 +2533,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
...
@@ -2534,7 +2533,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
STableMetaInfo
*
pMMInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
STableMetaInfo
*
pMMInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
pMMInfo
->
name
);
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
pMMInfo
->
name
);
tscAdd
Meter
MetaInfo
(
pNewQueryInfo
,
pMMInfo
->
name
,
pTableMeta
,
NULL
,
pMMInfo
->
numOfTags
,
pMMInfo
->
tagColumnIndex
);
tscAdd
Table
MetaInfo
(
pNewQueryInfo
,
pMMInfo
->
name
,
pTableMeta
,
NULL
,
pMMInfo
->
numOfTags
,
pMMInfo
->
tagColumnIndex
);
}
}
if
((
code
=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscAllocPayload
(
&
pNew
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
!=
TSDB_CODE_SUCCESS
)
{
...
...
src/client/src/tscSql.c
浏览文件 @
3f9d5cca
...
@@ -407,7 +407,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
...
@@ -407,7 +407,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
*
rows
=
pRes
->
tsrow
;
*
rows
=
pRes
->
tsrow
;
return
(
pQueryInfo
->
order
.
order
==
TS
QL_SO
_DESC
)
?
pRes
->
numOfRows
:
-
pRes
->
numOfRows
;
return
(
pQueryInfo
->
order
.
order
==
TS
DB_ORDER
_DESC
)
?
pRes
->
numOfRows
:
-
pRes
->
numOfRows
;
}
}
static
void
transferNcharData
(
SSqlObj
*
pSql
,
int32_t
columnIndex
,
TAOS_FIELD
*
pField
)
{
static
void
transferNcharData
(
SSqlObj
*
pSql
,
int32_t
columnIndex
,
TAOS_FIELD
*
pField
)
{
...
@@ -502,14 +502,14 @@ static void **doSetResultRowData(SSqlObj *pSql) {
...
@@ -502,14 +502,14 @@ static void **doSetResultRowData(SSqlObj *pSql) {
}
}
for
(
int32_t
k
=
0
;
k
<
sas
->
numOfCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
sas
->
numOfCols
;
++
k
)
{
int32_t
columnIndex
=
sas
->
pExpr
->
binExprInfo
.
pReqColumns
[
k
].
colI
dxInBuf
;
int32_t
columnIndex
=
sas
->
pExpr
->
binExprInfo
.
pReqColumns
[
k
].
colI
ndex
;
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
columnIndex
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
columnIndex
);
sas
->
elemSize
[
k
]
=
pExpr
->
resBytes
;
sas
->
elemSize
[
k
]
=
pExpr
->
resBytes
;
sas
->
data
[
k
]
=
(
pRes
->
data
+
pRes
->
numOfRows
*
pExpr
->
offset
)
+
pRes
->
row
*
pExpr
->
resBytes
;
sas
->
data
[
k
]
=
(
pRes
->
data
+
pRes
->
numOfRows
*
pExpr
->
offset
)
+
pRes
->
row
*
pExpr
->
resBytes
;
}
}
tSQLBinaryExprCalcTraverse
(
sas
->
pExpr
->
binExprInfo
.
pBinExpr
,
1
,
pRes
->
buffer
[
i
],
sas
,
TS
QL_SO
_ASC
,
getArithemicInputSrc
);
tSQLBinaryExprCalcTraverse
(
sas
->
pExpr
->
binExprInfo
.
pBinExpr
,
1
,
pRes
->
buffer
[
i
],
sas
,
TS
DB_ORDER
_ASC
,
getArithemicInputSrc
);
pRes
->
tsrow
[
i
]
=
pRes
->
buffer
[
i
];
pRes
->
tsrow
[
i
]
=
pRes
->
buffer
[
i
];
free
(
sas
);
//todo optimization
free
(
sas
);
//todo optimization
...
...
src/client/src/tscSubquery.c
浏览文件 @
3f9d5cca
...
@@ -26,7 +26,7 @@ typedef struct SInsertSupporter {
...
@@ -26,7 +26,7 @@ typedef struct SInsertSupporter {
static
void
freeSubqueryObj
(
SSqlObj
*
pSql
);
static
void
freeSubqueryObj
(
SSqlObj
*
pSql
);
static
bool
doCompare
(
int32_t
order
,
int64_t
left
,
int64_t
right
)
{
static
bool
doCompare
(
int32_t
order
,
int64_t
left
,
int64_t
right
)
{
if
(
order
==
TS
QL_SO
_ASC
)
{
if
(
order
==
TS
DB_ORDER
_ASC
)
{
return
left
<
right
;
return
left
<
right
;
}
else
{
}
else
{
return
left
>
right
;
return
left
>
right
;
...
@@ -136,8 +136,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
...
@@ -136,8 +136,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
* 2. only one element for each tag.
* 2. only one element for each tag.
*/
*/
if
(
output1
->
tsOrder
==
-
1
)
{
if
(
output1
->
tsOrder
==
-
1
)
{
output1
->
tsOrder
=
TS
QL_SO
_ASC
;
output1
->
tsOrder
=
TS
DB_ORDER
_ASC
;
output2
->
tsOrder
=
TS
QL_SO
_ASC
;
output2
->
tsOrder
=
TS
DB_ORDER
_ASC
;
}
}
tsBufFlush
(
output1
);
tsBufFlush
(
output1
);
...
@@ -1005,8 +1005,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
...
@@ -1005,8 +1005,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
int32_t
numOfSubQuerie
s
=
taosArrayGetSize
(
pTableMetaInfo
->
vgroupIdList
);
pSql
->
numOfSub
s
=
taosArrayGetSize
(
pTableMetaInfo
->
vgroupIdList
);
assert
(
numOfSubQuerie
s
>
0
);
assert
(
pSql
->
numOfSub
s
>
0
);
int32_t
ret
=
tscLocalReducerEnvCreate
(
pSql
,
&
pMemoryBuf
,
&
pDesc
,
&
pModel
,
nBufferSize
);
int32_t
ret
=
tscLocalReducerEnvCreate
(
pSql
,
&
pMemoryBuf
,
&
pDesc
,
&
pModel
,
nBufferSize
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
...
@@ -1017,16 +1017,15 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
...
@@ -1017,16 +1017,15 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
return
pRes
->
code
;
return
pRes
->
code
;
}
}
pSql
->
pSubs
=
calloc
(
numOfSubQueries
,
POINTER_BYTES
);
pSql
->
pSubs
=
calloc
(
pSql
->
numOfSubs
,
POINTER_BYTES
);
pSql
->
numOfSubs
=
numOfSubQueries
;
tscTrace
(
"%p retrieved query data from %d vnode(s)"
,
pSql
,
numOfSubQuerie
s
);
tscTrace
(
"%p retrieved query data from %d vnode(s)"
,
pSql
,
pSql
->
numOfSub
s
);
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
pState
->
numOfTotal
=
numOfSubQuerie
s
;
pState
->
numOfTotal
=
pSql
->
numOfSub
s
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
int32_t
i
=
0
;
int32_t
i
=
0
;
for
(;
i
<
numOfSubQuerie
s
;
++
i
)
{
for
(;
i
<
pSql
->
numOfSub
s
;
++
i
)
{
SRetrieveSupport
*
trs
=
(
SRetrieveSupport
*
)
calloc
(
1
,
sizeof
(
SRetrieveSupport
));
SRetrieveSupport
*
trs
=
(
SRetrieveSupport
*
)
calloc
(
1
,
sizeof
(
SRetrieveSupport
));
if
(
trs
==
NULL
)
{
if
(
trs
==
NULL
)
{
tscError
(
"%p failed to malloc buffer for SRetrieveSupport, orderOfSub:%d, reason:%s"
,
pSql
,
i
,
strerror
(
errno
));
tscError
(
"%p failed to malloc buffer for SRetrieveSupport, orderOfSub:%d, reason:%s"
,
pSql
,
i
,
strerror
(
errno
));
...
@@ -1070,22 +1069,22 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
...
@@ -1070,22 +1069,22 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
tscTrace
(
"%p sub:%p create subquery success. orderOfSub:%d"
,
pSql
,
pNew
,
trs
->
subqueryIndex
);
tscTrace
(
"%p sub:%p create subquery success. orderOfSub:%d"
,
pSql
,
pNew
,
trs
->
subqueryIndex
);
}
}
if
(
i
<
numOfSubQuerie
s
)
{
if
(
i
<
pSql
->
numOfSub
s
)
{
tscError
(
"%p failed to prepare subquery structure and launch subqueries"
,
pSql
);
tscError
(
"%p failed to prepare subquery structure and launch subqueries"
,
pSql
);
pRes
->
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
pRes
->
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
tscLocalReducerEnvDestroy
(
pMemoryBuf
,
pDesc
,
pModel
,
numOfSubQuerie
s
);
tscLocalReducerEnvDestroy
(
pMemoryBuf
,
pDesc
,
pModel
,
pSql
->
numOfSub
s
);
doCleanupSubqueries
(
pSql
,
i
,
pState
);
doCleanupSubqueries
(
pSql
,
i
,
pState
);
return
pRes
->
code
;
// free all allocated resource
return
pRes
->
code
;
// free all allocated resource
}
}
if
(
pRes
->
code
==
TSDB_CODE_QUERY_CANCELLED
)
{
if
(
pRes
->
code
==
TSDB_CODE_QUERY_CANCELLED
)
{
tscLocalReducerEnvDestroy
(
pMemoryBuf
,
pDesc
,
pModel
,
numOfSubQuerie
s
);
tscLocalReducerEnvDestroy
(
pMemoryBuf
,
pDesc
,
pModel
,
pSql
->
numOfSub
s
);
doCleanupSubqueries
(
pSql
,
i
,
pState
);
doCleanupSubqueries
(
pSql
,
i
,
pState
);
return
pRes
->
code
;
return
pRes
->
code
;
}
}
for
(
int32_t
j
=
0
;
j
<
numOfSubQuerie
s
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pSql
->
numOfSub
s
;
++
j
)
{
SSqlObj
*
pSub
=
pSql
->
pSubs
[
j
];
SSqlObj
*
pSub
=
pSql
->
pSubs
[
j
];
SRetrieveSupport
*
pSupport
=
pSub
->
param
;
SRetrieveSupport
*
pSupport
=
pSub
->
param
;
...
@@ -1449,7 +1448,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1449,7 +1448,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
tscTrace
(
"%p sub:%p reach the max retry count,set global code:%d"
,
pParentSql
,
pSql
,
code
);
tscTrace
(
"%p sub:%p reach the max retry count,set global code:%d"
,
pParentSql
,
pSql
,
code
);
atomic_val_compare_exchange_32
(
&
pState
->
code
,
0
,
code
);
atomic_val_compare_exchange_32
(
&
pState
->
code
,
0
,
code
);
}
else
{
// does not reach the maximum retry count, go on
}
else
{
// does not reach the maximum retry count, go on
tscTrace
(
"%p sub:%p failed code:%
d, retry:%d"
,
pParentSql
,
pSql
,
code
,
trsupport
->
numOfRetry
);
tscTrace
(
"%p sub:%p failed code:%
s, retry:%d"
,
pParentSql
,
pSql
,
tstrerror
(
code
)
,
trsupport
->
numOfRetry
);
SSqlObj
*
pNew
=
tscCreateSqlObjForSubquery
(
pParentSql
,
trsupport
,
pSql
);
SSqlObj
*
pNew
=
tscCreateSqlObjForSubquery
(
pParentSql
,
trsupport
,
pSql
);
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
...
...
src/client/src/tscUtil.c
浏览文件 @
3f9d5cca
...
@@ -53,7 +53,7 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
...
@@ -53,7 +53,7 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
const
int32_t
maxKeySize
=
TSDB_MAX_TAGS_LEN
;
// allowed max key size
const
int32_t
maxKeySize
=
TSDB_MAX_TAGS_LEN
;
// allowed max key size
SCond
*
cond
=
tsGetSTableQueryCond
Pos
(
pTagCond
,
uid
);
SCond
*
cond
=
tsGetSTableQueryCond
(
pTagCond
,
uid
);
char
join
[
512
]
=
{
0
};
char
join
[
512
]
=
{
0
};
if
(
pTagCond
->
joinInfo
.
hasJoin
)
{
if
(
pTagCond
->
joinInfo
.
hasJoin
)
{
...
@@ -92,28 +92,41 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
...
@@ -92,28 +92,41 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
free
(
tmp
);
free
(
tmp
);
}
}
SCond
*
tsGetSTableQueryCondPos
(
STagCond
*
pTagCond
,
uint64_t
uid
)
{
SCond
*
tsGetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_MAX_JOIN_TABLE_NUM
;
++
i
)
{
if
(
pTagCond
->
pCond
==
NULL
)
{
if
(
uid
==
pTagCond
->
cond
[
i
].
uid
)
{
return
NULL
;
return
&
pTagCond
->
cond
[
i
];
}
size_t
size
=
taosArrayGetSize
(
pTagCond
->
pCond
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SCond
*
pCond
=
taosArrayGet
(
pTagCond
->
pCond
,
i
);
if
(
uid
==
pCond
->
uid
)
{
return
pCond
;
}
}
}
}
return
NULL
;
return
NULL
;
}
}
// todo refactor by using SArray
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
*
pBuf
)
{
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
const
char
*
str
)
{
if
(
tbufTell
(
pBuf
)
==
0
)
{
size_t
len
=
strlen
(
str
);
if
(
len
==
0
)
{
return
;
return
;
}
}
SCond
*
pDest
=
&
pTagCond
->
cond
[
pTagCond
->
numOfTagCond
];
SCond
cond
=
{
pDest
->
uid
=
uid
;
.
uid
=
uid
,
pDest
->
cond
=
strdup
(
str
);
.
len
=
tbufTell
(
pBuf
),
.
cond
=
NULL
,
};
cond
.
cond
=
tbufGetData
(
pBuf
,
true
);
if
(
pTagCond
->
pCond
==
NULL
)
{
pTagCond
->
pCond
=
taosArrayInit
(
3
,
sizeof
(
SCond
));
}
pTagCond
->
numOfTagCond
+=
1
;
taosArrayPush
(
pTagCond
->
pCond
,
&
cond
)
;
}
}
bool
tscQueryOnMetric
(
SSqlCmd
*
pCmd
)
{
bool
tscQueryOnMetric
(
SSqlCmd
*
pCmd
)
{
...
@@ -1185,7 +1198,7 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
...
@@ -1185,7 +1198,7 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
}
}
}
}
pExpr
->
colInfo
.
colI
d
x
=
pColIndex
->
columnIndex
;
pExpr
->
colInfo
.
colI
nde
x
=
pColIndex
->
columnIndex
;
pExpr
->
resType
=
type
;
pExpr
->
resType
=
type
;
pExpr
->
resBytes
=
size
;
pExpr
->
resBytes
=
size
;
pExpr
->
interResBytes
=
interSize
;
pExpr
->
interResBytes
=
interSize
;
...
@@ -1207,7 +1220,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
...
@@ -1207,7 +1220,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
pExpr
->
functionId
=
functionId
;
pExpr
->
functionId
=
functionId
;
pExpr
->
colInfo
.
colI
d
x
=
srcColumnIndex
;
pExpr
->
colInfo
.
colI
nde
x
=
srcColumnIndex
;
pExpr
->
colInfo
.
colId
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
srcColumnIndex
)
->
colId
;
pExpr
->
colInfo
.
colId
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
srcColumnIndex
)
->
colId
;
pExpr
->
resType
=
type
;
pExpr
->
resType
=
type
;
...
@@ -1642,26 +1655,46 @@ void tscTagCondCopy(STagCond* dest, const STagCond* src) {
...
@@ -1642,26 +1655,46 @@ void tscTagCondCopy(STagCond* dest, const STagCond* src) {
dest
->
tbnameCond
.
uid
=
src
->
tbnameCond
.
uid
;
dest
->
tbnameCond
.
uid
=
src
->
tbnameCond
.
uid
;
memcpy
(
&
dest
->
joinInfo
,
&
src
->
joinInfo
,
sizeof
(
SJoinInfo
));
memcpy
(
&
dest
->
joinInfo
,
&
src
->
joinInfo
,
sizeof
(
SJoinInfo
));
dest
->
relType
=
src
->
relType
;
for
(
int32_t
i
=
0
;
i
<
src
->
numOfTagCond
;
++
i
)
{
if
(
src
->
pCond
==
NULL
)
{
if
(
src
->
cond
[
i
].
cond
!=
NULL
)
{
return
;
dest
->
cond
[
i
].
cond
=
strdup
(
src
->
cond
[
i
].
cond
);
}
}
dest
->
cond
[
i
].
uid
=
src
->
cond
[
i
].
uid
;
size_t
s
=
taosArrayGetSize
(
src
->
pCond
);
dest
->
pCond
=
taosArrayInit
(
s
,
sizeof
(
SCond
));
for
(
int32_t
i
=
0
;
i
<
s
;
++
i
)
{
SCond
*
pCond
=
taosArrayGet
(
src
->
pCond
,
i
);
SCond
c
=
{
0
};
c
.
len
=
pCond
->
len
;
c
.
uid
=
pCond
->
uid
;
if
(
pCond
->
len
>
0
)
{
assert
(
pCond
->
cond
!=
NULL
);
c
.
cond
=
malloc
(
c
.
len
);
memcpy
(
c
.
cond
,
pCond
->
cond
,
c
.
len
);
}
}
dest
->
relType
=
src
->
relType
;
taosArrayPush
(
dest
->
pCond
,
&
c
)
;
dest
->
numOfTagCond
=
src
->
numOfTagCond
;
}
}
}
void
tscTagCondRelease
(
STagCond
*
pCond
)
{
void
tscTagCondRelease
(
STagCond
*
pTagCond
)
{
free
(
pCond
->
tbnameCond
.
cond
);
free
(
pTagCond
->
tbnameCond
.
cond
);
for
(
int32_t
i
=
0
;
i
<
pCond
->
numOfTagCond
;
++
i
)
{
free
(
pCond
->
cond
[
i
].
cond
);
if
(
pTagCond
->
pCond
!=
NULL
)
{
size_t
s
=
taosArrayGetSize
(
pTagCond
->
pCond
);
for
(
int32_t
i
=
0
;
i
<
s
;
++
i
)
{
SCond
*
p
=
taosArrayGet
(
pTagCond
->
pCond
,
i
);
tfree
(
p
->
cond
);
}
taosArrayDestroy
(
pTagCond
->
pCond
);
}
}
memset
(
pCond
,
0
,
sizeof
(
STagCond
));
memset
(
p
Tag
Cond
,
0
,
sizeof
(
STagCond
));
}
}
void
tscGetSrcColumnInfo
(
SSrcColumnInfo
*
pColInfo
,
SQueryInfo
*
pQueryInfo
)
{
void
tscGetSrcColumnInfo
(
SSrcColumnInfo
*
pColInfo
,
SQueryInfo
*
pQueryInfo
)
{
...
@@ -1674,11 +1707,11 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo) {
...
@@ -1674,11 +1707,11 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo) {
if
(
TSDB_COL_IS_TAG
(
pExpr
->
colInfo
.
flag
))
{
if
(
TSDB_COL_IS_TAG
(
pExpr
->
colInfo
.
flag
))
{
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
int16_t
actualTagIndex
=
pTableMetaInfo
->
tagColumnIndex
[
pExpr
->
colInfo
.
colI
d
x
];
int16_t
actualTagIndex
=
pTableMetaInfo
->
tagColumnIndex
[
pExpr
->
colInfo
.
colI
nde
x
];
pColInfo
[
i
].
type
=
(
actualTagIndex
!=
-
1
)
?
pTagSchema
[
actualTagIndex
].
type
:
TSDB_DATA_TYPE_BINARY
;
pColInfo
[
i
].
type
=
(
actualTagIndex
!=
-
1
)
?
pTagSchema
[
actualTagIndex
].
type
:
TSDB_DATA_TYPE_BINARY
;
}
else
{
}
else
{
pColInfo
[
i
].
type
=
pSchema
[
pExpr
->
colInfo
.
colI
d
x
].
type
;
pColInfo
[
i
].
type
=
pSchema
[
pExpr
->
colInfo
.
colI
nde
x
].
type
;
}
}
}
}
}
}
...
@@ -1880,8 +1913,8 @@ void tscFreeSubqueryInfo(SSqlCmd* pCmd) {
...
@@ -1880,8 +1913,8 @@ void tscFreeSubqueryInfo(SSqlCmd* pCmd) {
tfree
(
pCmd
->
pQueryInfo
);
tfree
(
pCmd
->
pQueryInfo
);
}
}
STableMetaInfo
*
tscAdd
Meter
MetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
STableMetaInfo
*
tscAdd
Table
MetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
S
SuperTableMeta
*
pMetricMeta
,
int16_t
numOfTags
,
int16_t
*
tags
)
{
S
Array
*
vgroupList
,
int16_t
numOfTags
,
int16_t
*
tags
)
{
void
*
pAlloc
=
realloc
(
pQueryInfo
->
pTableMetaInfo
,
(
pQueryInfo
->
numOfTables
+
1
)
*
POINTER_BYTES
);
void
*
pAlloc
=
realloc
(
pQueryInfo
->
pTableMetaInfo
,
(
pQueryInfo
->
numOfTables
+
1
)
*
POINTER_BYTES
);
if
(
pAlloc
==
NULL
)
{
if
(
pAlloc
==
NULL
)
{
return
NULL
;
return
NULL
;
...
@@ -1901,6 +1934,10 @@ STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
...
@@ -1901,6 +1934,10 @@ STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
pTableMetaInfo
->
pTableMeta
=
pTableMeta
;
pTableMetaInfo
->
pTableMeta
=
pTableMeta
;
pTableMetaInfo
->
numOfTags
=
numOfTags
;
pTableMetaInfo
->
numOfTags
=
numOfTags
;
if
(
vgroupList
!=
NULL
)
{
pTableMetaInfo
->
vgroupIdList
=
taosArrayClone
(
vgroupList
);
}
if
(
tags
!=
NULL
)
{
if
(
tags
!=
NULL
)
{
memcpy
(
pTableMetaInfo
->
tagColumnIndex
,
tags
,
sizeof
(
pTableMetaInfo
->
tagColumnIndex
[
0
])
*
numOfTags
);
memcpy
(
pTableMetaInfo
->
tagColumnIndex
,
tags
,
sizeof
(
pTableMetaInfo
->
tagColumnIndex
[
0
])
*
numOfTags
);
}
}
...
@@ -1910,7 +1947,7 @@ STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
...
@@ -1910,7 +1947,7 @@ STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
}
}
STableMetaInfo
*
tscAddEmptyMetaInfo
(
SQueryInfo
*
pQueryInfo
)
{
STableMetaInfo
*
tscAddEmptyMetaInfo
(
SQueryInfo
*
pQueryInfo
)
{
return
tscAdd
Meter
MetaInfo
(
pQueryInfo
,
NULL
,
NULL
,
NULL
,
0
,
NULL
);
return
tscAdd
Table
MetaInfo
(
pQueryInfo
,
NULL
,
NULL
,
NULL
,
0
,
NULL
);
}
}
void
doRemoveMeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
bool
removeFromCache
)
{
void
doRemoveMeterMetaInfo
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
bool
removeFromCache
)
{
...
@@ -1962,14 +1999,14 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
...
@@ -1962,14 +1999,14 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
)
{
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
tableIndex
);
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
tscError
(
"%p new subquery failed, tableIndex:%d
, vnodeIndex:%d"
,
pSql
,
tableIndex
,
pTableMetaInfo
->
vnod
eIndex
);
tscError
(
"%p new subquery failed, tableIndex:%d
"
,
pSql
,
tabl
eIndex
);
return
NULL
;
return
NULL
;
}
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
tableIndex
);
pNew
->
pTscObj
=
pSql
->
pTscObj
;
pNew
->
pTscObj
=
pSql
->
pTscObj
;
pNew
->
signature
=
pNew
;
pNew
->
signature
=
pNew
;
...
@@ -2084,12 +2121,12 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
...
@@ -2084,12 +2121,12 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
if
(
pPrevSql
==
NULL
)
{
if
(
pPrevSql
==
NULL
)
{
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
name
);
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
name
);
SSuperTableMeta
*
pMetricMeta
=
NULL
;
//
SSuperTableMeta* pMetricMeta = NULL;
if
(
cmd
==
TSDB_SQL_SELECT
)
{
//
if (cmd == TSDB_SQL_SELECT) {
pMetricMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
key
);
//
pMetricMeta = taosCacheAcquireByName(tscCacheHandle, key);
}
//
}
pFinalInfo
=
tscAdd
MeterMetaInfo
(
pNewQueryInfo
,
name
,
pTableMeta
,
pMetricMeta
,
pTableMetaInfo
->
numOfTags
,
pFinalInfo
=
tscAdd
TableMetaInfo
(
pNewQueryInfo
,
name
,
pTableMeta
,
pTableMetaInfo
->
vgroupIdList
,
pTableMetaInfo
->
numOfTags
,
pTableMetaInfo
->
tagColumnIndex
);
pTableMetaInfo
->
tagColumnIndex
);
}
else
{
// transfer the ownership of pTableMeta/pMetricMeta to the newly create sql object.
}
else
{
// transfer the ownership of pTableMeta/pMetricMeta to the newly create sql object.
// STableMetaInfo* pPrevInfo = tscGetTableMetaInfoFromCmd(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0);
// STableMetaInfo* pPrevInfo = tscGetTableMetaInfoFromCmd(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0);
...
@@ -2097,7 +2134,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
...
@@ -2097,7 +2134,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
// STableMeta* pPrevMeterMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pTableMeta);
// STableMeta* pPrevMeterMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pTableMeta);
// SSuperTableMeta* pPrevMetricMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pMetricMeta);
// SSuperTableMeta* pPrevMetricMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pMetricMeta);
// pFinalInfo = tscAdd
Meter
MetaInfo(pNewQueryInfo, name, pPrevMeterMeta, pPrevMetricMeta, pTableMetaInfo->numOfTags,
// pFinalInfo = tscAdd
Table
MetaInfo(pNewQueryInfo, name, pPrevMeterMeta, pPrevMetricMeta, pTableMetaInfo->numOfTags,
// pTableMetaInfo->tagColumnIndex);
// pTableMetaInfo->tagColumnIndex);
}
}
...
...
src/inc/taosdef.h
浏览文件 @
3f9d5cca
...
@@ -147,10 +147,10 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
...
@@ -147,10 +147,10 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
// TODO: check if below is necessary
// TODO: check if below is necessary
#define TSDB_RELATION_INVALID 0
#define TSDB_RELATION_INVALID 0
#define TSDB_RELATION_LESS 1
#define TSDB_RELATION_LESS 1
#define TSDB_RELATION_
LARGE
2
#define TSDB_RELATION_
GREATER
2
#define TSDB_RELATION_EQUAL 3
#define TSDB_RELATION_EQUAL 3
#define TSDB_RELATION_LESS_EQUAL 4
#define TSDB_RELATION_LESS_EQUAL 4
#define TSDB_RELATION_
LARGE
_EQUAL 5
#define TSDB_RELATION_
GREATER
_EQUAL 5
#define TSDB_RELATION_NOT_EQUAL 6
#define TSDB_RELATION_NOT_EQUAL 6
#define TSDB_RELATION_LIKE 7
#define TSDB_RELATION_LIKE 7
...
@@ -303,8 +303,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
...
@@ -303,8 +303,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
#define TS
QL_SO
_ASC 1
#define TS
DB_ORDER
_ASC 1
#define TS
QL_SO_DESC 0
#define TS
DB_ORDER_DESC 2
#define TSDB_SESSIONS_PER_VNODE (300)
#define TSDB_SESSIONS_PER_VNODE (300)
#define TSDB_SESSIONS_PER_DNODE (TSDB_SESSIONS_PER_VNODE * TSDB_MAX_VNODES)
#define TSDB_SESSIONS_PER_DNODE (TSDB_SESSIONS_PER_VNODE * TSDB_MAX_VNODES)
...
...
src/inc/taosmsg.h
浏览文件 @
3f9d5cca
...
@@ -358,7 +358,7 @@ typedef struct {
...
@@ -358,7 +358,7 @@ typedef struct {
int32_t
vgId
;
int32_t
vgId
;
}
SMDDropVnodeMsg
;
}
SMDDropVnodeMsg
;
typedef
struct
SColIndex
Ex
{
typedef
struct
SColIndex
{
int16_t
colId
;
int16_t
colId
;
/*
/*
* colIdx is the index of column in latest schema of table
* colIdx is the index of column in latest schema of table
...
@@ -368,11 +368,10 @@ typedef struct SColIndexEx {
...
@@ -368,11 +368,10 @@ typedef struct SColIndexEx {
* colIdxInBuf is used to denote the index of column in pQuery->colList,
* colIdxInBuf is used to denote the index of column in pQuery->colList,
* this value is invalid in client side, as well as in cache block of vnode either.
* this value is invalid in client side, as well as in cache block of vnode either.
*/
*/
int16_t
colIdx
;
int16_t
colIndex
;
int16_t
colIdxInBuf
;
uint16_t
flag
;
// denote if it is a tag or not
uint16_t
flag
;
// denote if it is a tag or not
char
name
[
TSDB_COL_NAME_LEN
];
char
name
[
TSDB_COL_NAME_LEN
];
}
SColIndex
Ex
;
}
SColIndex
;
/* sql function msg, to describe the message to vnode about sql function
/* sql function msg, to describe the message to vnode about sql function
* operations in select clause */
* operations in select clause */
...
@@ -380,7 +379,7 @@ typedef struct SSqlFuncExprMsg {
...
@@ -380,7 +379,7 @@ typedef struct SSqlFuncExprMsg {
int16_t
functionId
;
int16_t
functionId
;
int16_t
numOfParams
;
int16_t
numOfParams
;
SColIndex
Ex
colInfo
;
SColIndex
colInfo
;
struct
ArgElem
{
struct
ArgElem
{
int16_t
argType
;
int16_t
argType
;
int16_t
argBytes
;
int16_t
argBytes
;
...
@@ -395,7 +394,7 @@ typedef struct SSqlFuncExprMsg {
...
@@ -395,7 +394,7 @@ typedef struct SSqlFuncExprMsg {
typedef
struct
SSqlBinaryExprInfo
{
typedef
struct
SSqlBinaryExprInfo
{
struct
tExprNode
*
pBinExpr
;
/* for binary expression */
struct
tExprNode
*
pBinExpr
;
/* for binary expression */
int32_t
numOfCols
;
/* binary expression involves the readed number of columns*/
int32_t
numOfCols
;
/* binary expression involves the readed number of columns*/
SColIndex
Ex
*
pReqColumns
;
/* source column list */
SColIndex
*
pReqColumns
;
/* source column list */
}
SSqlBinaryExprInfo
;
}
SSqlBinaryExprInfo
;
typedef
struct
SSqlFunctionExpr
{
typedef
struct
SSqlFunctionExpr
{
...
@@ -467,7 +466,6 @@ typedef struct {
...
@@ -467,7 +466,6 @@ typedef struct {
int64_t
slidingTime
;
// value for sliding window
int64_t
slidingTime
;
// value for sliding window
char
slidingTimeUnit
;
// time interval type, for revisement of interval(1d)
char
slidingTimeUnit
;
// time interval type, for revisement of interval(1d)
uint16_t
tagCondLen
;
// tag length in current query
uint16_t
tagCondLen
;
// tag length in current query
uint16_t
nameCondLen
;
// table name in/like query expression string length
int16_t
numOfGroupCols
;
// num of group by columns
int16_t
numOfGroupCols
;
// num of group by columns
int16_t
orderByIdx
;
int16_t
orderByIdx
;
int16_t
orderType
;
// used in group by xx order by xxx
int16_t
orderType
;
// used in group by xx order by xxx
...
...
src/query/inc/qast.h
浏览文件 @
3f9d5cca
...
@@ -48,7 +48,7 @@ typedef void (*__do_filter_suppl_fn_t)(void *, void *);
...
@@ -48,7 +48,7 @@ typedef void (*__do_filter_suppl_fn_t)(void *, void *);
*/
*/
typedef
struct
tQueryInfo
{
typedef
struct
tQueryInfo
{
int32_t
offset
;
// offset value in tags
int32_t
offset
;
// offset value in tags
int32_t
colI
dx
;
// index of column in schema
int32_t
colI
ndex
;
// index of column in schema
uint8_t
optr
;
// expression operator
uint8_t
optr
;
// expression operator
SSchema
sch
;
// schema of tags
SSchema
sch
;
// schema of tags
tVariant
q
;
// query condition value on the specific schema, filter expression
tVariant
q
;
// query condition value on the specific schema, filter expression
...
@@ -83,7 +83,7 @@ void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len);
...
@@ -83,7 +83,7 @@ void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len);
void
tExprTreeDestroy
(
tExprNode
**
pExprs
,
void
(
*
fp
)(
void
*
));
void
tExprTreeDestroy
(
tExprNode
**
pExprs
,
void
(
*
fp
)(
void
*
));
void
t
SQLBinaryExpr
Traverse
(
tExprNode
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
);
void
t
ExprTree
Traverse
(
tExprNode
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
);
void
tSQLBinaryExprCalcTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
void
tSQLBinaryExprCalcTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
char
*
(
*
cb
)(
void
*
,
char
*
,
int32_t
));
char
*
(
*
cb
)(
void
*
,
char
*
,
int32_t
));
...
@@ -94,7 +94,7 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken);
...
@@ -94,7 +94,7 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken);
SBuffer
exprTreeToBinary
(
tExprNode
*
pExprTree
);
SBuffer
exprTreeToBinary
(
tExprNode
*
pExprTree
);
tExprNode
*
exprTreeFromBinary
(
const
void
*
pBuf
,
size_t
siz
e
);
int32_t
exprTreeFromBinary
(
const
void
*
pBuf
,
size_t
size
,
tExprNode
**
pExprNod
e
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/query/inc/queryExecutor.h
浏览文件 @
3f9d5cca
...
@@ -39,7 +39,7 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
...
@@ -39,7 +39,7 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
typedef
struct
SSqlGroupbyExpr
{
typedef
struct
SSqlGroupbyExpr
{
int16_t
tableIndex
;
int16_t
tableIndex
;
int16_t
numOfGroupCols
;
int16_t
numOfGroupCols
;
SColIndex
Ex
columnInfo
[
TSDB_MAX_TAGS
];
// group by columns information
SColIndex
columnInfo
[
TSDB_MAX_TAGS
];
// group by columns information
int16_t
orderIndex
;
// order by column index
int16_t
orderIndex
;
// order by column index
int16_t
orderType
;
// order by type: asc/desc
int16_t
orderType
;
// order by type: asc/desc
}
SSqlGroupbyExpr
;
}
SSqlGroupbyExpr
;
...
@@ -63,7 +63,7 @@ typedef struct SWindowResult {
...
@@ -63,7 +63,7 @@ typedef struct SWindowResult {
typedef
struct
SResultRec
{
typedef
struct
SResultRec
{
int64_t
total
;
// total generated result size in rows
int64_t
total
;
// total generated result size in rows
int64_t
size
;
// current result set size in rows
int64_t
rows
;
// current result set size in rows
int64_t
capacity
;
// capacity of current result output buffer
int64_t
capacity
;
// capacity of current result output buffer
// result size threshold in rows. If the result buffer is larger than this, pause query and return to client
// result size threshold in rows. If the result buffer is larger than this, pause query and return to client
...
@@ -125,7 +125,7 @@ typedef struct SQuery {
...
@@ -125,7 +125,7 @@ typedef struct SQuery {
int8_t
precision
;
int8_t
precision
;
int16_t
numOfOutputCols
;
int16_t
numOfOutputCols
;
int16_t
interpoType
;
int16_t
interpoType
;
int16_t
checkBuffer
InLoop
;
// check if the buffer is full during scan each block
int16_t
checkBuffer
;
// check if the buffer is full during scan each block
SLimitVal
limit
;
SLimitVal
limit
;
int32_t
rowSize
;
int32_t
rowSize
;
SSqlGroupbyExpr
*
pGroupbyExpr
;
SSqlGroupbyExpr
*
pGroupbyExpr
;
...
...
src/query/inc/sql.y
浏览文件 @
3f9d5cca
...
@@ -466,9 +466,9 @@ item(A) ::= ids(X) cpxName(Y). {
...
@@ -466,9 +466,9 @@ item(A) ::= ids(X) cpxName(Y). {
}
}
%type sortorder {int}
%type sortorder {int}
sortorder(A) ::= ASC. {A = TS
QL_SO
_ASC; }
sortorder(A) ::= ASC. {A = TS
DB_ORDER
_ASC; }
sortorder(A) ::= DESC. {A = TS
QL_SO
_DESC;}
sortorder(A) ::= DESC. {A = TS
DB_ORDER
_DESC;}
sortorder(A) ::= . {A = TS
QL_SO
_ASC;} //default is descend order
sortorder(A) ::= . {A = TS
DB_ORDER
_ASC;} //default is descend order
//group by clause
//group by clause
%type groupby_opt {tVariantList*}
%type groupby_opt {tVariantList*}
...
...
src/query/inc/tsqlfunction.h
浏览文件 @
3f9d5cca
...
@@ -102,7 +102,7 @@ extern "C" {
...
@@ -102,7 +102,7 @@ extern "C" {
#define QUERY_ASC_FORWARD_STEP 1
#define QUERY_ASC_FORWARD_STEP 1
#define QUERY_DESC_FORWARD_STEP -1
#define QUERY_DESC_FORWARD_STEP -1
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TS
QL_SO
_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TS
DB_ORDER
_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
#define MAX_RETRIEVE_ROWS_IN_INTERVAL_QUERY 10000000
#define MAX_RETRIEVE_ROWS_IN_INTERVAL_QUERY 10000000
#define TOP_BOTTOM_QUERY_LIMIT 100
#define TOP_BOTTOM_QUERY_LIMIT 100
...
...
src/query/src/qast.c
浏览文件 @
3f9d5cca
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "tutil.h"
#include "tutil.h"
#include "tbuffer.h"
#include "tbuffer.h"
#include "qast.h"
#include "qast.h"
#include "tcompare.h"
#include "qsqlparser.h"
#include "qsqlparser.h"
#include "qsyntaxtreefunction.h"
#include "qsyntaxtreefunction.h"
#include "taosdef.h"
#include "taosdef.h"
...
@@ -79,22 +80,22 @@ static void reviseBinaryExprIfNecessary(tExprNode **pLeft, tExprNode **pRight, u
...
@@ -79,22 +80,22 @@ static void reviseBinaryExprIfNecessary(tExprNode **pLeft, tExprNode **pRight, u
* switch left and left and right hand side in expr if possible
* switch left and left and right hand side in expr if possible
*/
*/
if
((
*
pLeft
)
->
nodeType
==
TSQL_NODE_VALUE
&&
(
*
pRight
)
->
nodeType
==
TSQL_NODE_COL
)
{
if
((
*
pLeft
)
->
nodeType
==
TSQL_NODE_VALUE
&&
(
*
pRight
)
->
nodeType
==
TSQL_NODE_COL
)
{
if
(
*
optr
>=
TSDB_RELATION_
LARGE
&&
*
optr
<=
TSDB_RELATION_LARGE
_EQUAL
&&
*
optr
!=
TSDB_RELATION_EQUAL
)
{
if
(
*
optr
>=
TSDB_RELATION_
GREATER
&&
*
optr
<=
TSDB_RELATION_GREATER
_EQUAL
&&
*
optr
!=
TSDB_RELATION_EQUAL
)
{
SWAP
(
*
pLeft
,
*
pRight
,
tExprNode
*
);
SWAP
(
*
pLeft
,
*
pRight
,
tExprNode
*
);
}
}
switch
(
*
optr
)
{
switch
(
*
optr
)
{
case
TSDB_RELATION_
LARGE
:
case
TSDB_RELATION_
GREATER
:
(
*
optr
)
=
TSDB_RELATION_LESS
;
(
*
optr
)
=
TSDB_RELATION_LESS
;
break
;
break
;
case
TSDB_RELATION_LESS
:
case
TSDB_RELATION_LESS
:
(
*
optr
)
=
TSDB_RELATION_
LARGE
;
(
*
optr
)
=
TSDB_RELATION_
GREATER
;
break
;
break
;
case
TSDB_RELATION_
LARGE
_EQUAL
:
case
TSDB_RELATION_
GREATER
_EQUAL
:
(
*
optr
)
=
TSDB_RELATION_LESS_EQUAL
;
(
*
optr
)
=
TSDB_RELATION_LESS_EQUAL
;
break
;
break
;
case
TSDB_RELATION_LESS_EQUAL
:
case
TSDB_RELATION_LESS_EQUAL
:
(
*
optr
)
=
TSDB_RELATION_
LARGE
_EQUAL
;
(
*
optr
)
=
TSDB_RELATION_
GREATER
_EQUAL
;
break
;
break
;
default:
;
default:
;
// for other type of operations, do nothing
// for other type of operations, do nothing
...
@@ -163,9 +164,9 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken) {
...
@@ -163,9 +164,9 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken) {
case
TK_LE
:
case
TK_LE
:
return
TSDB_RELATION_LESS_EQUAL
;
return
TSDB_RELATION_LESS_EQUAL
;
case
TK_GT
:
case
TK_GT
:
return
TSDB_RELATION_
LARGE
;
return
TSDB_RELATION_
GREATER
;
case
TK_GE
:
case
TK_GE
:
return
TSDB_RELATION_
LARGE
_EQUAL
;
return
TSDB_RELATION_
GREATER
_EQUAL
;
case
TK_NE
:
case
TK_NE
:
return
TSDB_RELATION_NOT_EQUAL
;
return
TSDB_RELATION_NOT_EQUAL
;
case
TK_AND
:
case
TK_AND
:
...
@@ -376,12 +377,12 @@ static char *tSQLOptrToString(uint8_t optr, char *dst) {
...
@@ -376,12 +377,12 @@ static char *tSQLOptrToString(uint8_t optr, char *dst) {
dst
+=
1
;
dst
+=
1
;
break
;
break
;
}
}
case
TSDB_RELATION_
LARGE
:
{
case
TSDB_RELATION_
GREATER
:
{
*
dst
=
'>'
;
*
dst
=
'>'
;
dst
+=
1
;
dst
+=
1
;
break
;
break
;
}
}
case
TSDB_RELATION_
LARGE
_EQUAL
:
{
case
TSDB_RELATION_
GREATER
_EQUAL
:
{
*
dst
=
'>'
;
*
dst
=
'>'
;
*
(
dst
+
1
)
=
'='
;
*
(
dst
+
1
)
=
'='
;
dst
+=
2
;
dst
+=
2
;
...
@@ -466,8 +467,18 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
...
@@ -466,8 +467,18 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
*
pExpr
=
NULL
;
*
pExpr
=
NULL
;
}
}
typedef
struct
{
tVariant
v
;
int32_t
optr
;
}
SEndPoint
;
typedef
struct
{
SEndPoint
*
start
;
SEndPoint
*
end
;
}
SQueryCond
;
//static void setInitialValueForRangeQueryCondition(tSKipListQueryCond *q, int8_t type) {
//static void setInitialValueForRangeQueryCondition(tSKipListQueryCond *q, int8_t type) {
// q->lowerBndRelOptr = TSDB_RELATION_
LARGE
;
// q->lowerBndRelOptr = TSDB_RELATION_
GREATER
;
// q->upperBndRelOptr = TSDB_RELATION_LESS;
// q->upperBndRelOptr = TSDB_RELATION_LESS;
//
//
// switch (type) {
// switch (type) {
...
@@ -504,60 +515,100 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
...
@@ -504,60 +515,100 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
// }
// }
//}
//}
//static void tSQLDoFilterInitialResult(tSkipList *pSkipList, bool (*fp)(), tQueryInfo *queryColInfo,
// todo check for malloc failure
// tQueryResultset *result) {
static
int32_t
setQueryCond
(
tQueryInfo
*
queryColInfo
,
SQueryCond
*
pCond
)
{
// // primary key filter, search according to skiplist
int32_t
optr
=
queryColInfo
->
optr
;
// if (queryColInfo->colIdx == 0 && queryColInfo->optr != TSDB_RELATION_LIKE) {
// tSKipListQueryCond q;
if
(
optr
==
TSDB_RELATION_GREATER
||
optr
==
TSDB_RELATION_GREATER_EQUAL
||
// setInitialValueForRangeQueryCondition(&q, queryColInfo->q.nType);
optr
==
TSDB_RELATION_EQUAL
||
optr
==
TSDB_RELATION_NOT_EQUAL
)
{
//
pCond
->
start
=
calloc
(
1
,
sizeof
(
tVariant
));
// switch (queryColInfo->optr) {
// case TSDB_RELATION_EQUAL: {
tVariantAssign
(
&
pCond
->
start
->
v
,
&
queryColInfo
->
q
);
// result->num =
pCond
->
start
->
optr
=
queryColInfo
->
optr
;
// tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, INCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
}
else
if
(
optr
==
TSDB_RELATION_LESS
||
optr
==
TSDB_RELATION_LESS_EQUAL
)
{
// break;
pCond
->
end
=
calloc
(
1
,
sizeof
(
tVariant
));
// }
// case TSDB_RELATION_NOT_EQUAL: {
tVariantAssign
(
&
pCond
->
end
->
v
,
&
queryColInfo
->
q
);
// result->num =
pCond
->
end
->
optr
=
queryColInfo
->
optr
;
// tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, EXCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
}
// break;
// }
return
TSDB_CODE_SUCCESS
;
// case TSDB_RELATION_LESS_EQUAL: {
}
// tVariantAssign(&q.upperBnd, &queryColInfo->q);
// q.upperBndRelOptr = queryColInfo->optr;
static
void
tQueryOnSkipList
(
SSkipList
*
pSkipList
,
SQueryCond
*
pCond
,
int32_t
type
,
SArray
*
result
)
{
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
SSkipListIterator
*
iter
=
NULL
;
// break;
// }
if
(
pCond
->
start
!=
NULL
)
{
// case TSDB_RELATION_LESS: {
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
&
pCond
->
start
->
v
.
i64Key
,
type
,
TSDB_ORDER_ASC
);
// tVariantAssign(&q.upperBnd, &queryColInfo->q);
}
else
{
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
&
pCond
->
end
->
v
.
i64Key
,
type
,
TSDB_ORDER_DESC
);
// break;
}
// }
// case TSDB_RELATION_LARGE: {
__compar_fn_t
func
=
getComparFunc
(
pSkipList
->
keyInfo
.
type
,
type
);
// tVariantAssign(&q.lowerBnd, &queryColInfo->q);
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
if
(
pCond
->
start
!=
NULL
)
{
// break;
int32_t
optr
=
pCond
->
start
->
optr
;
// }
// case TSDB_RELATION_LARGE_EQUAL: {
if
(
optr
==
TSDB_RELATION_EQUAL
)
{
// tVariantAssign(&q.lowerBnd, &queryColInfo->q);
while
(
tSkipListIterNext
(
iter
))
{
// q.lowerBndRelOptr = queryColInfo->optr;
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
// break;
int32_t
ret
=
func
(
SL_GET_NODE_KEY
(
pSkipList
,
pNode
),
&
pCond
->
start
->
v
.
i64Key
);
// }
if
(
ret
==
0
)
{
// default:
taosArrayPush
(
result
,
SL_GET_NODE_DATA
(
pNode
));
// pTrace("skiplist:%p, unsupport query operator:%d", pSkipList, queryColInfo->optr);
}
else
{
// }
break
;
//
}
// tSkipListDestroyKey(&q.upperBnd);
}
// tSkipListDestroyKey(&q.lowerBnd);
}
else
if
(
optr
==
TSDB_RELATION_GREATER
||
optr
==
TSDB_RELATION_GREATER_EQUAL
)
{
// } else {
bool
comp
=
true
;
// /*
int32_t
ret
=
0
;
// * Brutal force scan the whole skiplit to find the appropriate result,
// * since the filter is not applied to indexed column.
while
(
tSkipListIterNext
(
iter
))
{
// */
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
// result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, queryColInfo);
// }
if
(
comp
)
{
//}
ret
=
func
(
SL_GET_NODE_KEY
(
pSkipList
,
pNode
),
&
pCond
->
start
->
v
.
i64Key
);
assert
(
ret
<=
0
);
}
if
(
ret
==
0
&&
optr
==
TSDB_RELATION_GREATER
)
{
continue
;
}
else
{
taosArrayPush
(
result
,
SL_GET_NODE_DATA
(
pNode
));
comp
=
false
;
}
}
}
else
if
(
optr
==
TSDB_RELATION_NOT_EQUAL
)
{
assert
(
0
);
}
else
{
assert
(
0
);
}
}
else
{
int32_t
optr
=
pCond
->
end
->
optr
;
if
(
optr
==
TSDB_RELATION_LESS
||
optr
==
TSDB_RELATION_LESS_EQUAL
)
{
bool
comp
=
true
;
int32_t
ret
=
0
;
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
if
(
comp
)
{
ret
=
func
(
SL_GET_NODE_KEY
(
pSkipList
,
pNode
),
&
pCond
->
start
->
v
.
i64Key
);
assert
(
ret
>=
0
);
}
if
(
ret
==
0
&&
optr
==
TSDB_RELATION_LESS
)
{
continue
;
}
else
{
taosArrayPush
(
result
,
SL_GET_NODE_DATA
(
pNode
));
comp
=
false
;
// no need to compare anymore
}
}
}
}
}
/*
/*
* qsort comparator
* qsort comparator
...
@@ -670,9 +721,7 @@ static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *p
...
@@ -670,9 +721,7 @@ static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *p
tExprNode
*
pLeft
=
pExpr
->
_node
.
pLeft
;
tExprNode
*
pLeft
=
pExpr
->
_node
.
pLeft
;
tExprNode
*
pRight
=
pExpr
->
_node
.
pRight
;
tExprNode
*
pRight
=
pExpr
->
_node
.
pRight
;
/*
//non-leaf nodes, recursively traverse the expression tree in the post-root order
* non-leaf nodes, recursively traverse the syntax tree in the post-root order
*/
if
(
pLeft
->
nodeType
==
TSQL_NODE_EXPR
&&
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
if
(
pLeft
->
nodeType
==
TSQL_NODE_EXPR
&&
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_OR
)
{
// or
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_OR
)
{
// or
if
(
filterItem
(
pLeft
,
pItem
,
param
))
{
if
(
filterItem
(
pLeft
,
pItem
,
param
))
{
...
@@ -707,7 +756,7 @@ static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *p
...
@@ -707,7 +756,7 @@ static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *p
* @param pSchema tag schemas
* @param pSchema tag schemas
* @param fp filter callback function
* @param fp filter callback function
*/
*/
static
void
tSQLBinaryTraverseOnResult
(
tExprNode
*
pExpr
,
SArray
*
pResult
,
SBinaryFilterSupp
*
param
)
{
static
void
exprTreeTraverseImpl
(
tExprNode
*
pExpr
,
SArray
*
pResult
,
SBinaryFilterSupp
*
param
)
{
size_t
size
=
taosArrayGetSize
(
pResult
);
size_t
size
=
taosArrayGetSize
(
pResult
);
SArray
*
array
=
taosArrayInit
(
size
,
POINTER_BYTES
);
SArray
*
array
=
taosArrayInit
(
size
,
POINTER_BYTES
);
...
@@ -736,7 +785,7 @@ static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSki
...
@@ -736,7 +785,7 @@ static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSki
}
}
// post-root order traverse syntax tree
// post-root order traverse syntax tree
void
t
SQLBinaryExpr
Traverse
(
tExprNode
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
)
{
void
t
ExprTree
Traverse
(
tExprNode
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SBinaryFilterSupp
*
param
)
{
if
(
pExpr
==
NULL
)
{
if
(
pExpr
==
NULL
)
{
return
;
return
;
}
}
...
@@ -755,7 +804,7 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
...
@@ -755,7 +804,7 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
*
*
* if the query is a high selectivity filter, only small portion of meters are retrieved.
* if the query is a high selectivity filter, only small portion of meters are retrieved.
*/
*/
tSQLBinaryTraverseOnResult
(
pExpr
,
result
,
param
);
exprTreeTraverseImpl
(
pExpr
,
result
,
param
);
}
else
if
(
weight
==
0
)
{
}
else
if
(
weight
==
0
)
{
/**
/**
* apply the hierarchical expression to every node in skiplist for find the qualified nodes
* apply the hierarchical expression to every node in skiplist for find the qualified nodes
...
@@ -766,8 +815,8 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
...
@@ -766,8 +815,8 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
SArray
*
rLeft
=
taosArrayInit
(
10
,
POINTER_BYTES
);
SArray
*
rLeft
=
taosArrayInit
(
10
,
POINTER_BYTES
);
SArray
*
rRight
=
taosArrayInit
(
10
,
POINTER_BYTES
);
SArray
*
rRight
=
taosArrayInit
(
10
,
POINTER_BYTES
);
t
SQLBinaryExpr
Traverse
(
pLeft
,
pSkipList
,
rLeft
,
param
);
t
ExprTree
Traverse
(
pLeft
,
pSkipList
,
rLeft
,
param
);
t
SQLBinaryExpr
Traverse
(
pRight
,
pSkipList
,
rRight
,
param
);
t
ExprTree
Traverse
(
pRight
,
pSkipList
,
rRight
,
param
);
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_AND
)
{
// CROSS
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_AND
)
{
// CROSS
intersect
(
rLeft
,
rRight
,
result
);
intersect
(
rLeft
,
rRight
,
result
);
...
@@ -801,13 +850,13 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
...
@@ -801,13 +850,13 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
assert
(
pFirst
!=
pSecond
&&
pFirst
!=
NULL
&&
pSecond
!=
NULL
);
assert
(
pFirst
!=
pSecond
&&
pFirst
!=
NULL
&&
pSecond
!=
NULL
);
// we filter the result based on the skiplist index in the first place
// we filter the result based on the skiplist index in the first place
t
SQLBinaryExpr
Traverse
(
pFirst
,
pSkipList
,
result
,
param
);
t
ExprTree
Traverse
(
pFirst
,
pSkipList
,
result
,
param
);
/*
/*
* recursively perform the filter operation based on the initial results,
* recursively perform the filter operation based on the initial results,
* So, we do not set the skiplist index as a parameter
* So, we do not set the skip
list index as a parameter
*/
*/
t
SQLBinaryExpr
Traverse
(
pSecond
,
NULL
,
result
,
param
);
t
ExprTree
Traverse
(
pSecond
,
NULL
,
result
,
param
);
}
}
}
else
{
// column project
}
else
{
// column project
assert
(
pLeft
->
nodeType
==
TSQL_NODE_COL
&&
pRight
->
nodeType
==
TSQL_NODE_VALUE
);
assert
(
pLeft
->
nodeType
==
TSQL_NODE_COL
&&
pRight
->
nodeType
==
TSQL_NODE_VALUE
);
...
@@ -816,8 +865,19 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
...
@@ -816,8 +865,19 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
if
(
pSkipList
==
NULL
)
{
if
(
pSkipList
==
NULL
)
{
tSQLListTraverseOnResult
(
pExpr
,
param
->
fp
,
result
);
tSQLListTraverseOnResult
(
pExpr
,
param
->
fp
,
result
);
}
else
{
}
else
{
// assert(result->num == 0);
tQueryInfo
*
pQueryInfo
=
pExpr
->
_node
.
info
;
// tSQLDoFilterInitialResult(pSkipList, param->fp, pExpr->info, result);
if
(
pQueryInfo
->
colIndex
==
0
&&
pQueryInfo
->
optr
!=
TSDB_RELATION_LIKE
)
{
SQueryCond
cond
=
{
0
};
/*int32_t ret = */
setQueryCond
(
pQueryInfo
,
&
cond
);
tQueryOnSkipList
(
pSkipList
,
&
cond
,
pQueryInfo
->
q
.
nType
,
result
);
}
else
{
/* Brutal force scan the whole skip list to find the appropriate result,
* since the filter is not applied to indexed column.
*/
assert
(
0
);
// result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, queryColInfo);
}
}
}
}
}
}
}
...
@@ -1012,11 +1072,10 @@ static void exprTreeFromBinaryImpl(tExprNode** pExprTree, SBuffer* pBuf) {
...
@@ -1012,11 +1072,10 @@ static void exprTreeFromBinaryImpl(tExprNode** pExprTree, SBuffer* pBuf) {
*
pExprTree
=
pExpr
;
*
pExprTree
=
pExpr
;
}
}
tExprNode
*
exprTreeFromBinary
(
const
void
*
pBuf
,
size_t
siz
e
)
{
int32_t
exprTreeFromBinary
(
const
void
*
pBuf
,
size_t
size
,
tExprNode
**
pExprNod
e
)
{
SBuffer
rbuf
=
{
0
};
SBuffer
rbuf
=
{
0
};
/*int32_t code =*/
tbufBeginRead
(
&
rbuf
,
pBuf
,
size
);
/*int32_t code =*/
tbufBeginRead
(
&
rbuf
,
pBuf
,
size
);
exprTreeFromBinaryImpl
(
pExprNode
,
&
rbuf
);
tExprNode
*
pExprNode
=
NULL
;
return
TSDB_CODE_SUCCESS
;
exprTreeFromBinaryImpl
(
&
pExprNode
,
&
rbuf
);
return
pExprNode
;
}
}
src/query/src/qextbuffer.c
浏览文件 @
3f9d5cca
...
@@ -345,7 +345,7 @@ static FORCE_INLINE int32_t primaryKeyComparator(int64_t f1, int64_t f2, int32_t
...
@@ -345,7 +345,7 @@ static FORCE_INLINE int32_t primaryKeyComparator(int64_t f1, int64_t f2, int32_t
return
0
;
return
0
;
}
}
if
(
colIdx
==
0
&&
tsOrder
==
TS
QL_SO
_DESC
)
{
// primary column desc order
if
(
colIdx
==
0
&&
tsOrder
==
TS
DB_ORDER
_DESC
)
{
// primary column desc order
return
(
f1
<
f2
)
?
1
:
-
1
;
return
(
f1
<
f2
)
?
1
:
-
1
;
}
else
{
// asc
}
else
{
// asc
return
(
f1
<
f2
)
?
-
1
:
1
;
return
(
f1
<
f2
)
?
-
1
:
1
;
...
@@ -628,7 +628,7 @@ static int32_t qsort_call = 0;
...
@@ -628,7 +628,7 @@ static int32_t qsort_call = 0;
void
tColDataQSort
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
void
tColDataQSort
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
int32_t
orderType
)
{
int32_t
orderType
)
{
// short array sort, incur another sort procedure instead of quick sort process
// short array sort, incur another sort procedure instead of quick sort process
__col_compar_fn_t
compareFn
=
(
orderType
==
TS
QL_SO
_ASC
)
?
compare_sa
:
compare_sd
;
__col_compar_fn_t
compareFn
=
(
orderType
==
TS
DB_ORDER
_ASC
)
?
compare_sa
:
compare_sd
;
if
(
end
-
start
+
1
<=
8
)
{
if
(
end
-
start
+
1
<=
8
)
{
tColDataInsertSort
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
compareFn
);
tColDataInsertSort
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
compareFn
);
...
...
src/query/src/qinterpolation.c
浏览文件 @
3f9d5cca
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#include "taosmsg.h"
#include "taosmsg.h"
#include "tsqlfunction.h"
#include "tsqlfunction.h"
#define INTERPOL_IS_ASC_INTERPOL(interp) ((interp)->order == TS
QL_SO
_ASC)
#define INTERPOL_IS_ASC_INTERPOL(interp) ((interp)->order == TS
DB_ORDER
_ASC)
int64_t
taosGetIntervalStartTimestamp
(
int64_t
startTime
,
int64_t
timeRange
,
char
intervalTimeUnit
,
int16_t
precision
)
{
int64_t
taosGetIntervalStartTimestamp
(
int64_t
startTime
,
int64_t
timeRange
,
char
intervalTimeUnit
,
int16_t
precision
)
{
if
(
timeRange
==
0
)
{
if
(
timeRange
==
0
)
{
...
@@ -96,7 +96,7 @@ void taosInterpoSetStartInfo(SInterpolationInfo* pInterpoInfo, int32_t numOfRawD
...
@@ -96,7 +96,7 @@ void taosInterpoSetStartInfo(SInterpolationInfo* pInterpoInfo, int32_t numOfRawD
}
}
TSKEY
taosGetRevisedEndKey
(
TSKEY
ekey
,
int32_t
order
,
int32_t
timeInterval
,
int8_t
intervalTimeUnit
,
int8_t
precision
)
{
TSKEY
taosGetRevisedEndKey
(
TSKEY
ekey
,
int32_t
order
,
int32_t
timeInterval
,
int8_t
intervalTimeUnit
,
int8_t
precision
)
{
if
(
order
==
TS
QL_SO
_ASC
)
{
if
(
order
==
TS
DB_ORDER
_ASC
)
{
return
ekey
;
return
ekey
;
}
else
{
}
else
{
return
taosGetIntervalStartTimestamp
(
ekey
,
timeInterval
,
intervalTimeUnit
,
precision
);
return
taosGetIntervalStartTimestamp
(
ekey
,
timeInterval
,
intervalTimeUnit
,
precision
);
...
...
src/query/src/qpercentile.c
浏览文件 @
3f9d5cca
...
@@ -83,7 +83,7 @@ static tFilePage *loadIntoBucketFromDisk(tMemBucket *pMemBucket, int32_t segIdx,
...
@@ -83,7 +83,7 @@ static tFilePage *loadIntoBucketFromDisk(tMemBucket *pMemBucket, int32_t segIdx,
pListItem
=
pListItem
->
pNext
;
pListItem
=
pListItem
->
pNext
;
}
}
tColDataQSort
(
pDesc
,
buffer
->
numOfElems
,
0
,
buffer
->
numOfElems
-
1
,
buffer
->
data
,
TS
QL_SO
_ASC
);
tColDataQSort
(
pDesc
,
buffer
->
numOfElems
,
0
,
buffer
->
numOfElems
-
1
,
buffer
->
data
,
TS
DB_ORDER
_ASC
);
pDesc
->
pColumnModel
->
capacity
=
oldCapacity
;
// restore value
pDesc
->
pColumnModel
->
capacity
=
oldCapacity
;
// restore value
return
buffer
;
return
buffer
;
...
...
src/query/src/qsyntaxtreefunction.c
浏览文件 @
3f9d5cca
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
#define ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
#define ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
{ \
{ \
int32_t i = ((_ord) == TS
QL_SO
_ASC) ? 0 : MAX(len1, len2) - 1; \
int32_t i = ((_ord) == TS
DB_ORDER
_ASC) ? 0 : MAX(len1, len2) - 1; \
int32_t step = ((_ord) == TS
QL_SO
_ASC) ? 1 : -1; \
int32_t step = ((_ord) == TS
DB_ORDER
_ASC) ? 1 : -1; \
\
\
if ((len1) == (len2)) { \
if ((len1) == (len2)) { \
for (; i < (len2) && i >= 0; i += step, (out) += 1) { \
for (; i < (len2) && i >= 0; i += step, (out) += 1) { \
...
@@ -53,8 +53,8 @@
...
@@ -53,8 +53,8 @@
#define ARRAY_LIST_OP_REM(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
#define ARRAY_LIST_OP_REM(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
{ \
{ \
int32_t i = (_ord == TS
QL_SO
_ASC) ? 0 : MAX(len1, len2) - 1; \
int32_t i = (_ord == TS
DB_ORDER
_ASC) ? 0 : MAX(len1, len2) - 1; \
int32_t step = (_ord == TS
QL_SO
_ASC) ? 1 : -1; \
int32_t step = (_ord == TS
DB_ORDER
_ASC) ? 1 : -1; \
\
\
if (len1 == (len2)) { \
if (len1 == (len2)) { \
for (; i >= 0 && i < (len2); i += step, (out) += 1) { \
for (; i >= 0 && i < (len2); i += step, (out) += 1) { \
...
@@ -107,8 +107,8 @@ void calc_fn_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRi
...
@@ -107,8 +107,8 @@ void calc_fn_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRi
int32_t
*
pRight
=
(
int32_t
*
)
right
;
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
...
@@ -305,8 +305,8 @@ void calc_fn_i32_i32_sub(void *left, void *right, int32_t numLeft, int32_t numRi
...
@@ -305,8 +305,8 @@ void calc_fn_i32_i32_sub(void *left, void *right, int32_t numLeft, int32_t numRi
int32_t
*
pRight
=
(
int32_t
*
)
right
;
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
...
@@ -516,8 +516,8 @@ void calc_fn_i32_i32_multi(void *left, void *right, int32_t numLeft, int32_t num
...
@@ -516,8 +516,8 @@ void calc_fn_i32_i32_multi(void *left, void *right, int32_t numLeft, int32_t num
int32_t
*
pRight
=
(
int32_t
*
)
right
;
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
...
@@ -714,8 +714,8 @@ void calc_fn_i32_i32_div(void *left, void *right, int32_t numLeft, int32_t numRi
...
@@ -714,8 +714,8 @@ void calc_fn_i32_i32_div(void *left, void *right, int32_t numLeft, int32_t numRi
int32_t
*
pRight
=
(
int32_t
*
)
right
;
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
...
@@ -928,8 +928,8 @@ void calc_fn_i32_i32_rem(void *left, void *right, int32_t numLeft, int32_t numRi
...
@@ -928,8 +928,8 @@ void calc_fn_i32_i32_rem(void *left, void *right, int32_t numLeft, int32_t numRi
int32_t
*
pRight
=
(
int32_t
*
)
right
;
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
...
@@ -986,8 +986,8 @@ void calc_fn_i32_d_rem(void *left, void *right, int32_t numLeft, int32_t numRigh
...
@@ -986,8 +986,8 @@ void calc_fn_i32_d_rem(void *left, void *right, int32_t numLeft, int32_t numRigh
double
*
pRight
=
(
double
*
)
right
;
double
*
pRight
=
(
double
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
...
...
src/query/src/qtsbuf.c
浏览文件 @
3f9d5cca
...
@@ -33,11 +33,11 @@ STSBuf* tsBufCreate(bool autoDelete) {
...
@@ -33,11 +33,11 @@ STSBuf* tsBufCreate(bool autoDelete) {
}
}
// update the header info
// update the header info
STSBufFileHeader
header
=
{.
magic
=
TS_COMP_FILE_MAGIC
,
.
numOfVnode
=
pTSBuf
->
numOfVnodes
,
.
tsOrder
=
TS
QL_SO
_ASC
};
STSBufFileHeader
header
=
{.
magic
=
TS_COMP_FILE_MAGIC
,
.
numOfVnode
=
pTSBuf
->
numOfVnodes
,
.
tsOrder
=
TS
DB_ORDER
_ASC
};
STSBufUpdateHeader
(
pTSBuf
,
&
header
);
STSBufUpdateHeader
(
pTSBuf
,
&
header
);
tsBufResetPos
(
pTSBuf
);
tsBufResetPos
(
pTSBuf
);
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
pTSBuf
->
autoDelete
=
autoDelete
;
pTSBuf
->
autoDelete
=
autoDelete
;
pTSBuf
->
tsOrder
=
-
1
;
pTSBuf
->
tsOrder
=
-
1
;
...
@@ -88,7 +88,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
...
@@ -88,7 +88,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
// check the ts order
// check the ts order
pTSBuf
->
tsOrder
=
header
.
tsOrder
;
pTSBuf
->
tsOrder
=
header
.
tsOrder
;
if
(
pTSBuf
->
tsOrder
!=
TS
QL_SO_ASC
&&
pTSBuf
->
tsOrder
!=
TSQL_SO
_DESC
)
{
if
(
pTSBuf
->
tsOrder
!=
TS
DB_ORDER_ASC
&&
pTSBuf
->
tsOrder
!=
TSDB_ORDER
_DESC
)
{
// tscError("invalid order info in buf:%d", pTSBuf->tsOrder);
// tscError("invalid order info in buf:%d", pTSBuf->tsOrder);
tsBufDestory
(
pTSBuf
);
tsBufDestory
(
pTSBuf
);
return
NULL
;
return
NULL
;
...
@@ -118,7 +118,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
...
@@ -118,7 +118,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
tsBufResetPos
(
pTSBuf
);
tsBufResetPos
(
pTSBuf
);
// ascending by default
// ascending by default
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
pTSBuf
->
autoDelete
=
autoDelete
;
pTSBuf
->
autoDelete
=
autoDelete
;
...
@@ -274,7 +274,7 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
...
@@ -274,7 +274,7 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
memset
(
pBlock
,
0
,
sizeof
(
STSBlock
));
memset
(
pBlock
,
0
,
sizeof
(
STSBlock
));
pBlock
->
payload
=
tmp
;
pBlock
->
payload
=
tmp
;
if
(
order
==
TS
QL_SO
_DESC
)
{
if
(
order
==
TS
DB_ORDER
_DESC
)
{
/*
/*
* set the right position for the reversed traverse, the reversed traverse is started from
* set the right position for the reversed traverse, the reversed traverse is started from
* the end of each comp data block
* the end of each comp data block
...
@@ -303,7 +303,7 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
...
@@ -303,7 +303,7 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
fread
(
&
pBlock
->
padding
,
sizeof
(
pBlock
->
padding
),
1
,
pTSBuf
->
f
);
fread
(
&
pBlock
->
padding
,
sizeof
(
pBlock
->
padding
),
1
,
pTSBuf
->
f
);
// for backwards traverse, set the start position at the end of previous block
// for backwards traverse, set the start position at the end of previous block
if
(
order
==
TS
QL_SO
_DESC
)
{
if
(
order
==
TS
DB_ORDER
_DESC
)
{
int32_t
offset
=
pBlock
->
compLen
+
sizeof
(
pBlock
->
compLen
)
*
2
+
sizeof
(
pBlock
->
numOfElem
)
+
sizeof
(
pBlock
->
tag
);
int32_t
offset
=
pBlock
->
compLen
+
sizeof
(
pBlock
->
compLen
)
*
2
+
sizeof
(
pBlock
->
numOfElem
)
+
sizeof
(
pBlock
->
tag
);
int64_t
r
=
fseek
(
pTSBuf
->
f
,
-
offset
,
SEEK_CUR
);
int64_t
r
=
fseek
(
pTSBuf
->
f
,
-
offset
,
SEEK_CUR
);
UNUSED
(
r
);
UNUSED
(
r
);
...
@@ -321,9 +321,9 @@ static int32_t setCheckTSOrder(STSBuf* pTSBuf, const char* pData, int32_t len) {
...
@@ -321,9 +321,9 @@ static int32_t setCheckTSOrder(STSBuf* pTSBuf, const char* pData, int32_t len) {
TSKEY
lastKey
=
*
(
TSKEY
*
)(
ptsData
->
rawBuf
+
ptsData
->
len
-
TSDB_KEYSIZE
);
TSKEY
lastKey
=
*
(
TSKEY
*
)(
ptsData
->
rawBuf
+
ptsData
->
len
-
TSDB_KEYSIZE
);
if
(
lastKey
>
*
(
TSKEY
*
)
pData
)
{
if
(
lastKey
>
*
(
TSKEY
*
)
pData
)
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_DESC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_DESC
;
}
else
{
}
else
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_ASC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_ASC
;
}
}
}
else
if
(
len
>
TSDB_KEYSIZE
)
{
}
else
if
(
len
>
TSDB_KEYSIZE
)
{
// no data in current vnode, more than one ts is added, check the orders
// no data in current vnode, more than one ts is added, check the orders
...
@@ -331,9 +331,9 @@ static int32_t setCheckTSOrder(STSBuf* pTSBuf, const char* pData, int32_t len) {
...
@@ -331,9 +331,9 @@ static int32_t setCheckTSOrder(STSBuf* pTSBuf, const char* pData, int32_t len) {
TSKEY
k2
=
*
(
TSKEY
*
)(
pData
+
TSDB_KEYSIZE
);
TSKEY
k2
=
*
(
TSKEY
*
)(
pData
+
TSDB_KEYSIZE
);
if
(
k1
<
k2
)
{
if
(
k1
<
k2
)
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_ASC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_ASC
;
}
else
if
(
k1
>
k2
)
{
}
else
if
(
k1
>
k2
)
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_DESC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_DESC
;
}
else
{
}
else
{
// todo handle error
// todo handle error
}
}
...
@@ -432,13 +432,13 @@ static int32_t tsBufFindBlock(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo, int
...
@@ -432,13 +432,13 @@ static int32_t tsBufFindBlock(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo, int
bool
decomp
=
false
;
bool
decomp
=
false
;
while
((
i
++
)
<=
blockIndex
)
{
while
((
i
++
)
<=
blockIndex
)
{
if
(
readDataFromDisk
(
pTSBuf
,
TS
QL_SO
_ASC
,
decomp
)
==
NULL
)
{
if
(
readDataFromDisk
(
pTSBuf
,
TS
DB_ORDER
_ASC
,
decomp
)
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
}
}
// set the file position to be the end of previous comp block
// set the file position to be the end of previous comp block
if
(
pTSBuf
->
cur
.
order
==
TS
QL_SO
_DESC
)
{
if
(
pTSBuf
->
cur
.
order
==
TS
DB_ORDER
_DESC
)
{
STSBlock
*
pBlock
=
&
pTSBuf
->
block
;
STSBlock
*
pBlock
=
&
pTSBuf
->
block
;
int32_t
compBlockSize
=
int32_t
compBlockSize
=
pBlock
->
compLen
+
sizeof
(
pBlock
->
compLen
)
*
2
+
sizeof
(
pBlock
->
numOfElem
)
+
sizeof
(
pBlock
->
tag
);
pBlock
->
compLen
+
sizeof
(
pBlock
->
compLen
)
*
2
+
sizeof
(
pBlock
->
numOfElem
)
+
sizeof
(
pBlock
->
tag
);
...
@@ -452,7 +452,7 @@ static int32_t tsBufFindBlockByTag(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo
...
@@ -452,7 +452,7 @@ static int32_t tsBufFindBlockByTag(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo
bool
decomp
=
false
;
bool
decomp
=
false
;
int64_t
offset
=
0
;
int64_t
offset
=
0
;
if
(
pTSBuf
->
cur
.
order
==
TS
QL_SO
_ASC
)
{
if
(
pTSBuf
->
cur
.
order
==
TS
DB_ORDER
_ASC
)
{
offset
=
pBlockInfo
->
offset
;
offset
=
pBlockInfo
->
offset
;
}
else
{
// reversed traverse starts from the end of block
}
else
{
// reversed traverse starts from the end of block
offset
=
pBlockInfo
->
offset
+
pBlockInfo
->
compLen
;
offset
=
pBlockInfo
->
offset
+
pBlockInfo
->
compLen
;
...
@@ -482,8 +482,8 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
...
@@ -482,8 +482,8 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
}
}
STSCursor
*
pCur
=
&
pTSBuf
->
cur
;
STSCursor
*
pCur
=
&
pTSBuf
->
cur
;
if
(
pCur
->
vnodeIndex
==
vnodeIndex
&&
((
pCur
->
blockIndex
<=
blockIndex
&&
pCur
->
order
==
TS
QL_SO
_ASC
)
||
if
(
pCur
->
vnodeIndex
==
vnodeIndex
&&
((
pCur
->
blockIndex
<=
blockIndex
&&
pCur
->
order
==
TS
DB_ORDER
_ASC
)
||
(
pCur
->
blockIndex
>=
blockIndex
&&
pCur
->
order
==
TS
QL_SO
_DESC
)))
{
(
pCur
->
blockIndex
>=
blockIndex
&&
pCur
->
order
==
TS
DB_ORDER
_DESC
)))
{
int32_t
i
=
0
;
int32_t
i
=
0
;
bool
decomp
=
false
;
bool
decomp
=
false
;
int32_t
step
=
abs
(
blockIndex
-
pCur
->
blockIndex
);
int32_t
step
=
abs
(
blockIndex
-
pCur
->
blockIndex
);
...
@@ -520,7 +520,7 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
...
@@ -520,7 +520,7 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
pCur
->
vnodeIndex
=
vnodeIndex
;
pCur
->
vnodeIndex
=
vnodeIndex
;
pCur
->
blockIndex
=
blockIndex
;
pCur
->
blockIndex
=
blockIndex
;
pCur
->
tsIndex
=
(
pCur
->
order
==
TS
QL_SO
_ASC
)
?
0
:
pBlock
->
numOfElem
-
1
;
pCur
->
tsIndex
=
(
pCur
->
order
==
TS
DB_ORDER
_ASC
)
?
0
:
pBlock
->
numOfElem
-
1
;
}
}
STSVnodeBlockInfo
*
tsBufGetVnodeBlockInfo
(
STSBuf
*
pTSBuf
,
int32_t
vnodeId
)
{
STSVnodeBlockInfo
*
tsBufGetVnodeBlockInfo
(
STSBuf
*
pTSBuf
,
int32_t
vnodeId
)
{
...
@@ -555,7 +555,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
...
@@ -555,7 +555,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
// get the first/last position according to traverse order
// get the first/last position according to traverse order
if
(
pCur
->
vnodeIndex
==
-
1
)
{
if
(
pCur
->
vnodeIndex
==
-
1
)
{
if
(
pCur
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCur
->
order
==
TS
DB_ORDER
_ASC
)
{
tsBufGetBlock
(
pTSBuf
,
0
,
0
);
tsBufGetBlock
(
pTSBuf
,
0
,
0
);
if
(
pTSBuf
->
block
.
numOfElem
==
0
)
{
// the whole list is empty, return
if
(
pTSBuf
->
block
.
numOfElem
==
0
)
{
// the whole list is empty, return
...
@@ -587,20 +587,20 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
...
@@ -587,20 +587,20 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
}
}
}
}
int32_t
step
=
pCur
->
order
==
TS
QL_SO
_ASC
?
1
:
-
1
;
int32_t
step
=
pCur
->
order
==
TS
DB_ORDER
_ASC
?
1
:
-
1
;
while
(
1
)
{
while
(
1
)
{
assert
(
pTSBuf
->
tsData
.
len
==
pTSBuf
->
block
.
numOfElem
*
TSDB_KEYSIZE
);
assert
(
pTSBuf
->
tsData
.
len
==
pTSBuf
->
block
.
numOfElem
*
TSDB_KEYSIZE
);
if
((
pCur
->
order
==
TS
QL_SO
_ASC
&&
pCur
->
tsIndex
>=
pTSBuf
->
block
.
numOfElem
-
1
)
||
if
((
pCur
->
order
==
TS
DB_ORDER
_ASC
&&
pCur
->
tsIndex
>=
pTSBuf
->
block
.
numOfElem
-
1
)
||
(
pCur
->
order
==
TS
QL_SO
_DESC
&&
pCur
->
tsIndex
<=
0
))
{
(
pCur
->
order
==
TS
DB_ORDER
_DESC
&&
pCur
->
tsIndex
<=
0
))
{
int32_t
vnodeId
=
pTSBuf
->
pData
[
pCur
->
vnodeIndex
].
info
.
vnode
;
int32_t
vnodeId
=
pTSBuf
->
pData
[
pCur
->
vnodeIndex
].
info
.
vnode
;
STSVnodeBlockInfo
*
pBlockInfo
=
tsBufGetVnodeBlockInfo
(
pTSBuf
,
vnodeId
);
STSVnodeBlockInfo
*
pBlockInfo
=
tsBufGetVnodeBlockInfo
(
pTSBuf
,
vnodeId
);
if
(
pBlockInfo
==
NULL
||
(
pCur
->
blockIndex
>=
pBlockInfo
->
numOfBlocks
-
1
&&
pCur
->
order
==
TS
QL_SO
_ASC
)
||
if
(
pBlockInfo
==
NULL
||
(
pCur
->
blockIndex
>=
pBlockInfo
->
numOfBlocks
-
1
&&
pCur
->
order
==
TS
DB_ORDER
_ASC
)
||
(
pCur
->
blockIndex
<=
0
&&
pCur
->
order
==
TS
QL_SO
_DESC
))
{
(
pCur
->
blockIndex
<=
0
&&
pCur
->
order
==
TS
DB_ORDER
_DESC
))
{
if
((
pCur
->
vnodeIndex
>=
pTSBuf
->
numOfVnodes
-
1
&&
pCur
->
order
==
TS
QL_SO
_ASC
)
||
if
((
pCur
->
vnodeIndex
>=
pTSBuf
->
numOfVnodes
-
1
&&
pCur
->
order
==
TS
DB_ORDER
_ASC
)
||
(
pCur
->
vnodeIndex
<=
0
&&
pCur
->
order
==
TS
QL_SO
_DESC
))
{
(
pCur
->
vnodeIndex
<=
0
&&
pCur
->
order
==
TS
DB_ORDER
_DESC
))
{
pCur
->
vnodeIndex
=
-
1
;
pCur
->
vnodeIndex
=
-
1
;
return
false
;
return
false
;
}
}
...
@@ -609,7 +609,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
...
@@ -609,7 +609,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
return
false
;
return
false
;
}
}
int32_t
blockIndex
=
pCur
->
order
==
TS
QL_SO
_ASC
?
0
:
pBlockInfo
->
numOfBlocks
-
1
;
int32_t
blockIndex
=
pCur
->
order
==
TS
DB_ORDER
_ASC
?
0
:
pBlockInfo
->
numOfBlocks
-
1
;
tsBufGetBlock
(
pTSBuf
,
pCur
->
vnodeIndex
+
step
,
blockIndex
);
tsBufGetBlock
(
pTSBuf
,
pCur
->
vnodeIndex
+
step
,
blockIndex
);
break
;
break
;
...
@@ -766,7 +766,7 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
...
@@ -766,7 +766,7 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
pTSBuf
->
fileSize
+=
len
;
pTSBuf
->
fileSize
+=
len
;
pTSBuf
->
tsOrder
=
order
;
pTSBuf
->
tsOrder
=
order
;
assert
(
order
==
TS
QL_SO_ASC
||
order
==
TSQL_SO
_DESC
);
assert
(
order
==
TS
DB_ORDER_ASC
||
order
==
TSDB_ORDER
_DESC
);
STSBufFileHeader
header
=
{
STSBufFileHeader
header
=
{
.
magic
=
TS_COMP_FILE_MAGIC
,
.
numOfVnode
=
pTSBuf
->
numOfVnodes
,
.
tsOrder
=
pTSBuf
->
tsOrder
};
.
magic
=
TS_COMP_FILE_MAGIC
,
.
numOfVnode
=
pTSBuf
->
numOfVnodes
,
.
tsOrder
=
pTSBuf
->
tsOrder
};
...
@@ -850,7 +850,7 @@ void tsBufDisplay(STSBuf* pTSBuf) {
...
@@ -850,7 +850,7 @@ void tsBufDisplay(STSBuf* pTSBuf) {
printf
(
"number of vnode:%d
\n
"
,
pTSBuf
->
numOfVnodes
);
printf
(
"number of vnode:%d
\n
"
,
pTSBuf
->
numOfVnodes
);
int32_t
old
=
pTSBuf
->
cur
.
order
;
int32_t
old
=
pTSBuf
->
cur
.
order
;
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
tsBufResetPos
(
pTSBuf
);
tsBufResetPos
(
pTSBuf
);
...
...
src/query/src/queryExecutor.c
浏览文件 @
3f9d5cca
...
@@ -53,9 +53,9 @@
...
@@ -53,9 +53,9 @@
/* get the qinfo struct address from the query struct address */
/* get the qinfo struct address from the query struct address */
#define GET_COLUMN_BYTES(query, colidx) \
#define GET_COLUMN_BYTES(query, colidx) \
((query)->colList[(query)->pSelectExpr[colidx].pBase.colInfo.colI
d
x].info.bytes)
((query)->colList[(query)->pSelectExpr[colidx].pBase.colInfo.colI
nde
x].info.bytes)
#define GET_COLUMN_TYPE(query, colidx) \
#define GET_COLUMN_TYPE(query, colidx) \
((query)->colList[(query)->pSelectExpr[colidx].pBase.colInfo.colI
d
x].info.type)
((query)->colList[(query)->pSelectExpr[colidx].pBase.colInfo.colI
nde
x].info.type)
typedef
struct
SPointInterpoSupporter
{
typedef
struct
SPointInterpoSupporter
{
int32_t
numOfCols
;
int32_t
numOfCols
;
...
@@ -280,6 +280,7 @@ int64_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -280,6 +280,7 @@ int64_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv) {
}
}
}
}
assert
(
maxOutput
>=
0
);
return
maxOutput
;
return
maxOutput
;
}
}
...
@@ -294,13 +295,13 @@ bool isGroupbyNormalCol(SSqlGroupbyExpr *pGroupbyExpr) {
...
@@ -294,13 +295,13 @@ bool isGroupbyNormalCol(SSqlGroupbyExpr *pGroupbyExpr) {
}
}
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
SColIndex
Ex
*
pColIndex
=
&
pGroupbyExpr
->
columnInfo
[
i
];
SColIndex
*
pColIndex
=
&
pGroupbyExpr
->
columnInfo
[
i
];
if
(
pColIndex
->
flag
==
TSDB_COL_NORMAL
)
{
if
(
pColIndex
->
flag
==
TSDB_COL_NORMAL
)
{
/*
/*
* make sure the normal column locates at the second position if tbname exists in group by clause
* make sure the normal column locates at the second position if tbname exists in group by clause
*/
*/
if
(
pGroupbyExpr
->
numOfGroupCols
>
1
)
{
if
(
pGroupbyExpr
->
numOfGroupCols
>
1
)
{
assert
(
pColIndex
->
colI
d
x
>
0
);
assert
(
pColIndex
->
colI
nde
x
>
0
);
}
}
return
true
;
return
true
;
...
@@ -317,7 +318,7 @@ int16_t getGroupbyColumnType(SQuery *pQuery, SSqlGroupbyExpr *pGroupbyExpr) {
...
@@ -317,7 +318,7 @@ int16_t getGroupbyColumnType(SQuery *pQuery, SSqlGroupbyExpr *pGroupbyExpr) {
int16_t
type
=
TSDB_DATA_TYPE_NULL
;
int16_t
type
=
TSDB_DATA_TYPE_NULL
;
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
SColIndex
Ex
*
pColIndex
=
&
pGroupbyExpr
->
columnInfo
[
i
];
SColIndex
*
pColIndex
=
&
pGroupbyExpr
->
columnInfo
[
i
];
if
(
pColIndex
->
flag
==
TSDB_COL_NORMAL
)
{
if
(
pColIndex
->
flag
==
TSDB_COL_NORMAL
)
{
colId
=
pColIndex
->
colId
;
colId
=
pColIndex
->
colId
;
break
;
break
;
...
@@ -362,8 +363,8 @@ bool isTSCompQuery(SQuery *pQuery) { return pQuery->pSelectExpr[0].pBase.functio
...
@@ -362,8 +363,8 @@ bool isTSCompQuery(SQuery *pQuery) { return pQuery->pSelectExpr[0].pBase.functio
bool
doRevisedResultsByLimit
(
SQInfo
*
pQInfo
)
{
bool
doRevisedResultsByLimit
(
SQInfo
*
pQInfo
)
{
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
if
((
pQuery
->
limit
.
limit
>
0
)
&&
(
pQuery
->
rec
.
size
+
pQuery
->
rec
.
size
>
pQuery
->
limit
.
limit
))
{
if
((
pQuery
->
limit
.
limit
>
0
)
&&
(
pQuery
->
rec
.
rows
+
pQuery
->
rec
.
rows
>
pQuery
->
limit
.
limit
))
{
pQuery
->
rec
.
size
=
pQuery
->
limit
.
limit
-
pQuery
->
rec
.
size
;
pQuery
->
rec
.
rows
=
pQuery
->
limit
.
limit
-
pQuery
->
rec
.
rows
;
// query completed
// query completed
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
...
@@ -390,7 +391,7 @@ static bool isTopBottomQuery(SQuery *pQuery) {
...
@@ -390,7 +391,7 @@ static bool isTopBottomQuery(SQuery *pQuery) {
static
SDataStatis
*
getStatisInfo
(
SQuery
*
pQuery
,
SDataStatis
*
pStatis
,
SDataBlockInfo
*
pDataBlockInfo
,
int32_t
index
)
{
static
SDataStatis
*
getStatisInfo
(
SQuery
*
pQuery
,
SDataStatis
*
pStatis
,
SDataBlockInfo
*
pDataBlockInfo
,
int32_t
index
)
{
// for a tag column, no corresponding field info
// for a tag column, no corresponding field info
SColIndex
Ex
*
pColIndexEx
=
&
pQuery
->
pSelectExpr
[
index
].
pBase
.
colInfo
;
SColIndex
*
pColIndexEx
=
&
pQuery
->
pSelectExpr
[
index
].
pBase
.
colInfo
;
if
(
TSDB_COL_IS_TAG
(
pColIndexEx
->
flag
))
{
if
(
TSDB_COL_IS_TAG
(
pColIndexEx
->
flag
))
{
return
NULL
;
return
NULL
;
}
}
...
@@ -418,7 +419,7 @@ static SDataStatis *getStatisInfo(SQuery *pQuery, SDataStatis *pStatis, SDataBlo
...
@@ -418,7 +419,7 @@ static SDataStatis *getStatisInfo(SQuery *pQuery, SDataStatis *pStatis, SDataBlo
*/
*/
static
bool
hasNullValue
(
SQuery
*
pQuery
,
int32_t
col
,
SDataBlockInfo
*
pDataBlockInfo
,
SDataStatis
*
pStatis
,
static
bool
hasNullValue
(
SQuery
*
pQuery
,
int32_t
col
,
SDataBlockInfo
*
pDataBlockInfo
,
SDataStatis
*
pStatis
,
SDataStatis
**
pColStatis
)
{
SDataStatis
**
pColStatis
)
{
SColIndex
Ex
*
pColIndex
=
&
pQuery
->
pSelectExpr
[
col
].
pBase
.
colInfo
;
SColIndex
*
pColIndex
=
&
pQuery
->
pSelectExpr
[
col
].
pBase
.
colInfo
;
if
(
TSDB_COL_IS_TAG
(
pColIndex
->
flag
))
{
if
(
TSDB_COL_IS_TAG
(
pColIndex
->
flag
))
{
return
false
;
return
false
;
}
}
...
@@ -593,7 +594,7 @@ static int32_t getForwardStepsInBlock(int32_t numOfPoints, __block_search_fn_t s
...
@@ -593,7 +594,7 @@ static int32_t getForwardStepsInBlock(int32_t numOfPoints, __block_search_fn_t s
int32_t
forwardStep
=
0
;
int32_t
forwardStep
=
0
;
if
(
endPos
>=
0
)
{
if
(
endPos
>=
0
)
{
forwardStep
=
(
order
==
TS
QL_SO
_ASC
)
?
(
endPos
-
pos
)
:
(
pos
-
endPos
);
forwardStep
=
(
order
==
TS
DB_ORDER
_ASC
)
?
(
endPos
-
pos
)
:
(
pos
-
endPos
);
assert
(
forwardStep
>=
0
);
assert
(
forwardStep
>=
0
);
// endPos data is equalled to the key so, we do need to read the element in endPos
// endPos data is equalled to the key so, we do need to read the element in endPos
...
@@ -670,7 +671,7 @@ static void doCheckQueryCompleted(SQueryRuntimeEnv *pRuntimeEnv, TSKEY lastKey,
...
@@ -670,7 +671,7 @@ static void doCheckQueryCompleted(SQueryRuntimeEnv *pRuntimeEnv, TSKEY lastKey,
static
int32_t
getNumOfRowsInTimeWindow
(
SQuery
*
pQuery
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
pPrimaryColumn
,
static
int32_t
getNumOfRowsInTimeWindow
(
SQuery
*
pQuery
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
pPrimaryColumn
,
int32_t
startPos
,
TSKEY
ekey
,
__block_search_fn_t
searchFn
,
int32_t
startPos
,
TSKEY
ekey
,
__block_search_fn_t
searchFn
,
bool
updateLastKey
)
{
bool
updateLastKey
)
{
assert
(
startPos
>=
0
&&
startPos
<
pDataBlockInfo
->
size
);
assert
(
startPos
>=
0
&&
startPos
<
pDataBlockInfo
->
rows
);
int32_t
num
=
-
1
;
int32_t
num
=
-
1
;
int32_t
order
=
pQuery
->
order
.
order
;
int32_t
order
=
pQuery
->
order
.
order
;
...
@@ -679,7 +680,7 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo
...
@@ -679,7 +680,7 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
ekey
<
pDataBlockInfo
->
window
.
ekey
)
{
if
(
ekey
<
pDataBlockInfo
->
window
.
ekey
)
{
num
=
getForwardStepsInBlock
(
pDataBlockInfo
->
size
,
searchFn
,
ekey
,
startPos
,
order
,
pPrimaryColumn
);
num
=
getForwardStepsInBlock
(
pDataBlockInfo
->
rows
,
searchFn
,
ekey
,
startPos
,
order
,
pPrimaryColumn
);
if
(
num
==
0
)
{
// no qualified data in current block, do not update the lastKey value
if
(
num
==
0
)
{
// no qualified data in current block, do not update the lastKey value
assert
(
ekey
<
pPrimaryColumn
[
startPos
]);
assert
(
ekey
<
pPrimaryColumn
[
startPos
]);
}
else
{
}
else
{
...
@@ -688,14 +689,14 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo
...
@@ -688,14 +689,14 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo
}
}
}
}
}
else
{
}
else
{
num
=
pDataBlockInfo
->
size
-
startPos
;
num
=
pDataBlockInfo
->
rows
-
startPos
;
if
(
updateLastKey
)
{
if
(
updateLastKey
)
{
pQuery
->
lastKey
=
pDataBlockInfo
->
window
.
ekey
+
step
;
pQuery
->
lastKey
=
pDataBlockInfo
->
window
.
ekey
+
step
;
}
}
}
}
}
else
{
// desc
}
else
{
// desc
if
(
ekey
>
pDataBlockInfo
->
window
.
skey
)
{
if
(
ekey
>
pDataBlockInfo
->
window
.
skey
)
{
num
=
getForwardStepsInBlock
(
pDataBlockInfo
->
size
,
searchFn
,
ekey
,
startPos
,
order
,
pPrimaryColumn
);
num
=
getForwardStepsInBlock
(
pDataBlockInfo
->
rows
,
searchFn
,
ekey
,
startPos
,
order
,
pPrimaryColumn
);
if
(
num
==
0
)
{
// no qualified data in current block, do not update the lastKey value
if
(
num
==
0
)
{
// no qualified data in current block, do not update the lastKey value
assert
(
ekey
>
pPrimaryColumn
[
startPos
]);
assert
(
ekey
>
pPrimaryColumn
[
startPos
]);
}
else
{
}
else
{
...
@@ -788,7 +789,7 @@ static int32_t getNextQualifiedWindow(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow
...
@@ -788,7 +789,7 @@ static int32_t getNextQualifiedWindow(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow
}
}
}
}
int32_t
startPos
=
searchFn
((
char
*
)
primaryKeys
,
pDataBlockInfo
->
size
,
startKey
,
pQuery
->
order
.
order
);
int32_t
startPos
=
searchFn
((
char
*
)
primaryKeys
,
pDataBlockInfo
->
rows
,
startKey
,
pQuery
->
order
.
order
);
/*
/*
* This time window does not cover any data, try next time window,
* This time window does not cover any data, try next time window,
...
@@ -851,12 +852,12 @@ char *getDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int3
...
@@ -851,12 +852,12 @@ char *getDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int3
sas
->
numOfCols
=
pQuery
->
numOfCols
;
sas
->
numOfCols
=
pQuery
->
numOfCols
;
sas
->
offset
=
0
;
sas
->
offset
=
0
;
}
else
{
// other type of query function
}
else
{
// other type of query function
SColIndex
Ex
*
pCol
=
&
pQuery
->
pSelectExpr
[
col
].
pBase
.
colInfo
;
SColIndex
*
pCol
=
&
pQuery
->
pSelectExpr
[
col
].
pBase
.
colInfo
;
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
))
{
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
))
{
dataBlock
=
NULL
;
dataBlock
=
NULL
;
}
else
{
}
else
{
/*
/*
* the colI
d
x is acquired from the first meter of all qualified meters in this vnode during query prepare stage,
* the colI
nde
x is acquired from the first meter of all qualified meters in this vnode during query prepare stage,
* the remain meter may not have the required column in cache actually.
* the remain meter may not have the required column in cache actually.
* So, the validation of required column in cache with the corresponding meter schema is reinforced.
* So, the validation of required column in cache with the corresponding meter schema is reinforced.
*/
*/
...
@@ -888,7 +889,7 @@ char *getDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int3
...
@@ -888,7 +889,7 @@ char *getDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int3
* @return the incremental number of output value, so it maybe 0 for fixed number of query,
* @return the incremental number of output value, so it maybe 0 for fixed number of query,
* such as count/min/max etc.
* such as count/min/max etc.
*/
*/
static
int32_t
blockwiseApplyAllFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataStatis
*
pStatis
,
static
void
blockwiseApplyAllFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataStatis
*
pStatis
,
SDataBlockInfo
*
pDataBlockInfo
,
SWindowResInfo
*
pWindowResInfo
,
SDataBlockInfo
*
pDataBlockInfo
,
SWindowResInfo
*
pWindowResInfo
,
__block_search_fn_t
searchFn
,
SArray
*
pDataBlock
)
{
__block_search_fn_t
searchFn
,
SArray
*
pDataBlock
)
{
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
...
@@ -902,9 +903,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
...
@@ -902,9 +903,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
primaryKeyCol
=
(
TSKEY
*
)(
pColInfo
->
pData
);
primaryKeyCol
=
(
TSKEY
*
)(
pColInfo
->
pData
);
}
}
pQuery
->
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
size
-
1
;
pQuery
->
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
rows
-
1
;
int64_t
prevNumOfRes
=
getNumOfResult
(
pRuntimeEnv
);
SArithmeticSupport
*
sasArray
=
calloc
((
size_t
)
pQuery
->
numOfOutputCols
,
sizeof
(
SArithmeticSupport
));
SArithmeticSupport
*
sasArray
=
calloc
((
size_t
)
pQuery
->
numOfOutputCols
,
sizeof
(
SArithmeticSupport
));
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
...
@@ -913,9 +912,9 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
...
@@ -913,9 +912,9 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
SDataStatis
*
tpField
=
NULL
;
SDataStatis
*
tpField
=
NULL
;
bool
hasNull
=
hasNullValue
(
pQuery
,
k
,
pDataBlockInfo
,
pStatis
,
&
tpField
);
bool
hasNull
=
hasNullValue
(
pQuery
,
k
,
pDataBlockInfo
,
pStatis
,
&
tpField
);
char
*
dataBlock
=
getDataBlocks
(
pRuntimeEnv
,
&
sasArray
[
k
],
k
,
pDataBlockInfo
->
size
,
pDataBlock
);
char
*
dataBlock
=
getDataBlocks
(
pRuntimeEnv
,
&
sasArray
[
k
],
k
,
pDataBlockInfo
->
rows
,
pDataBlock
);
setExecParams
(
pQuery
,
&
pCtx
[
k
],
dataBlock
,
primaryKeyCol
,
pDataBlockInfo
->
size
,
functionId
,
tpField
,
setExecParams
(
pQuery
,
&
pCtx
[
k
],
dataBlock
,
primaryKeyCol
,
pDataBlockInfo
->
rows
,
functionId
,
tpField
,
hasNull
,
&
sasArray
[
k
],
pRuntimeEnv
->
scanFlag
);
hasNull
,
&
sasArray
[
k
],
pRuntimeEnv
->
scanFlag
);
}
}
...
@@ -925,11 +924,9 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
...
@@ -925,11 +924,9 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
TSKEY
ts
=
primaryKeyCol
[
offset
];
TSKEY
ts
=
primaryKeyCol
[
offset
];
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
assert
(
0
);
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
->
sid
,
&
win
)
!=
TSDB_CODE_SUCCESS
)
{
// if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pRuntimeEnv->pTabObj->sid, &win) !=
return
0
;
// TSDB_CODE_SUCCESS) {
}
// return 0;
// }
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
win
);
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
win
);
int32_t
forwardStep
=
int32_t
forwardStep
=
...
@@ -949,10 +946,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
...
@@ -949,10 +946,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
}
}
// null data, failed to allocate more memory buffer
// null data, failed to allocate more memory buffer
// int32_t sid = pRuntimeEnv->pTabObj->sid;
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
->
sid
,
&
nextWin
)
!=
TSDB_CODE_SUCCESS
)
{
int32_t
sid
=
0
;
assert
(
0
);
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
sid
,
&
nextWin
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
break
;
}
}
...
@@ -960,7 +954,6 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
...
@@ -960,7 +954,6 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
primaryKeyCol
,
startPos
,
ekey
,
searchFn
,
true
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
primaryKeyCol
,
startPos
,
ekey
,
searchFn
,
true
);
pStatus
=
getTimeWindowResStatus
(
pWindowResInfo
,
curTimeWindow
(
pWindowResInfo
));
pStatus
=
getTimeWindowResStatus
(
pWindowResInfo
,
curTimeWindow
(
pWindowResInfo
));
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
pStatus
,
&
nextWin
,
startPos
,
forwardStep
,
primaryKeyCol
);
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
pStatus
,
&
nextWin
,
startPos
,
forwardStep
,
primaryKeyCol
);
}
}
...
@@ -979,17 +972,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
...
@@ -979,17 +972,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataSt
}
}
}
}
/*
* No need to calculate the number of output results for group-by normal columns, interval query
* because the results of group by normal column is put into intermediate buffer.
*/
int32_t
num
=
0
;
if
(
!
isIntervalQuery
(
pQuery
))
{
num
=
getNumOfResult
(
pRuntimeEnv
)
-
prevNumOfRes
;
}
tfree
(
sasArray
);
tfree
(
sasArray
);
return
(
int32_t
)
num
;
}
}
static
int32_t
setGroupResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
)
{
static
int32_t
setGroupResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
)
{
...
@@ -1138,9 +1121,9 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStat
...
@@ -1138,9 +1121,9 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStat
SDataStatis
*
pColStatis
=
NULL
;
SDataStatis
*
pColStatis
=
NULL
;
bool
hasNull
=
hasNullValue
(
pQuery
,
k
,
pDataBlockInfo
,
pStatis
,
&
pColStatis
);
bool
hasNull
=
hasNullValue
(
pQuery
,
k
,
pDataBlockInfo
,
pStatis
,
&
pColStatis
);
char
*
dataBlock
=
getDataBlocks
(
pRuntimeEnv
,
&
sasArray
[
k
],
k
,
pDataBlockInfo
->
size
,
pDataBlock
);
char
*
dataBlock
=
getDataBlocks
(
pRuntimeEnv
,
&
sasArray
[
k
],
k
,
pDataBlockInfo
->
rows
,
pDataBlock
);
setExecParams
(
pQuery
,
&
pCtx
[
k
],
dataBlock
,
primaryKeyCol
,
pDataBlockInfo
->
size
,
functionId
,
pColStatis
,
setExecParams
(
pQuery
,
&
pCtx
[
k
],
dataBlock
,
primaryKeyCol
,
pDataBlockInfo
->
rows
,
functionId
,
pColStatis
,
hasNull
,
&
sasArray
[
k
],
pRuntimeEnv
->
scanFlag
);
hasNull
,
&
sasArray
[
k
],
pRuntimeEnv
->
scanFlag
);
}
}
...
@@ -1162,14 +1145,14 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStat
...
@@ -1162,14 +1145,14 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStat
// from bottom to top in asc order
// from bottom to top in asc order
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
GET_QINFO_ADDR
(
pQuery
);
SQInfo
*
pQInfo
=
(
SQInfo
*
)
GET_QINFO_ADDR
(
pQuery
);
qTrace
(
"QInfo:%p process data rows, numOfRows:%d, query order:%d, ts comp order:%d"
,
pQInfo
,
pDataBlockInfo
->
size
,
qTrace
(
"QInfo:%p process data rows, numOfRows:%d, query order:%d, ts comp order:%d"
,
pQInfo
,
pDataBlockInfo
->
rows
,
pQuery
->
order
.
order
,
pRuntimeEnv
->
pTSBuf
->
cur
.
order
);
pQuery
->
order
.
order
,
pRuntimeEnv
->
pTSBuf
->
cur
.
order
);
}
}
int32_t
j
=
0
;
int32_t
j
=
0
;
TSKEY
lastKey
=
-
1
;
TSKEY
lastKey
=
-
1
;
for
(
j
=
0
;
j
<
pDataBlockInfo
->
size
;
++
j
)
{
for
(
j
=
0
;
j
<
pDataBlockInfo
->
rows
;
++
j
)
{
int32_t
offset
=
GET_COL_DATA_POS
(
pQuery
,
j
,
step
);
int32_t
offset
=
GET_COL_DATA_POS
(
pQuery
,
j
,
step
);
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
...
@@ -1271,7 +1254,7 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStat
...
@@ -1271,7 +1254,7 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStat
* pointsOffset is the maximum available space in result buffer update the actual forward step for query that
* pointsOffset is the maximum available space in result buffer update the actual forward step for query that
* requires checking buffer during loop
* requires checking buffer during loop
*/
*/
if
((
pQuery
->
checkBuffer
InLoop
==
1
)
&&
(
++
numOfRes
)
>=
pQuery
->
pointsOffset
)
{
if
((
pQuery
->
checkBuffer
==
1
)
&&
(
++
numOfRes
)
>=
pQuery
->
pointsOffset
)
{
pQuery
->
lastKey
=
lastKey
+
step
;
pQuery
->
lastKey
=
lastKey
+
step
;
assert
(
0
);
assert
(
0
);
// *forwardStep = j + 1;
// *forwardStep = j + 1;
...
@@ -1297,7 +1280,7 @@ static UNUSED_FUNC int32_t reviseForwardSteps(SQueryRuntimeEnv *pRuntimeEnv, int
...
@@ -1297,7 +1280,7 @@ static UNUSED_FUNC int32_t reviseForwardSteps(SQueryRuntimeEnv *pRuntimeEnv, int
/*
/*
* 1. If value filter exists, we try all data in current block, and do not set the QUERY_RESBUF_FULL flag.
* 1. If value filter exists, we try all data in current block, and do not set the QUERY_RESBUF_FULL flag.
*
*
* 2. In case of top/bottom/ts_comp query, the checkBuffer
InLoop
== 1 and pQuery->numOfFilterCols
* 2. In case of top/bottom/ts_comp query, the checkBuffer == 1 and pQuery->numOfFilterCols
* may be 0 or not. We do not check the capacity of output buffer, since the filter function will do it.
* may be 0 or not. We do not check the capacity of output buffer, since the filter function will do it.
*
*
* 3. In handling the query of secondary query of join, tsBuf servers as a ts filter.
* 3. In handling the query of secondary query of join, tsBuf servers as a ts filter.
...
@@ -1309,7 +1292,7 @@ static UNUSED_FUNC int32_t reviseForwardSteps(SQueryRuntimeEnv *pRuntimeEnv, int
...
@@ -1309,7 +1292,7 @@ static UNUSED_FUNC int32_t reviseForwardSteps(SQueryRuntimeEnv *pRuntimeEnv, int
}
}
// current buffer does not have enough space, try in the next loop
// current buffer does not have enough space, try in the next loop
if
((
pQuery
->
checkBuffer
InLoop
==
1
)
&&
(
pQuery
->
pointsOffset
<=
forwardStep
))
{
if
((
pQuery
->
checkBuffer
==
1
)
&&
(
pQuery
->
pointsOffset
<=
forwardStep
))
{
forwardStep
=
pQuery
->
pointsOffset
;
forwardStep
=
pQuery
->
pointsOffset
;
}
}
...
@@ -1317,17 +1300,17 @@ static UNUSED_FUNC int32_t reviseForwardSteps(SQueryRuntimeEnv *pRuntimeEnv, int
...
@@ -1317,17 +1300,17 @@ static UNUSED_FUNC int32_t reviseForwardSteps(SQueryRuntimeEnv *pRuntimeEnv, int
}
}
static
int32_t
tableApplyFunctionsOnBlock
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
static
int32_t
tableApplyFunctionsOnBlock
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
SDataStatis
*
pStatis
,
__block_search_fn_t
searchFn
,
int32_t
*
numOfRes
,
SDataStatis
*
pStatis
,
__block_search_fn_t
searchFn
,
SWindowResInfo
*
pWindowResInfo
,
SArray
*
pDataBlock
)
{
SWindowResInfo
*
pWindowResInfo
,
SArray
*
pDataBlock
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTSBuf
!=
NULL
||
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTSBuf
!=
NULL
||
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
*
numOfRes
=
rowwiseApplyAllFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
pDataBlock
);
/*numOfRes = */
rowwiseApplyAllFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
pDataBlock
);
}
else
{
}
else
{
*
numOfRes
=
blockwiseApplyAllFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
searchFn
,
pDataBlock
);
blockwiseApplyAllFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
searchFn
,
pDataBlock
);
}
}
TSKEY
lastKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
TSKEY
lastKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
pQuery
->
lastKey
=
lastKey
+
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
pQuery
->
lastKey
=
lastKey
+
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
doCheckQueryCompleted
(
pRuntimeEnv
,
lastKey
,
pWindowResInfo
);
doCheckQueryCompleted
(
pRuntimeEnv
,
lastKey
,
pWindowResInfo
);
...
@@ -1339,14 +1322,19 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
...
@@ -1339,14 +1322,19 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
}
}
assert
(
*
numOfRes
>=
0
);
int32_t
numOfRes
=
getNumOfResult
(
pRuntimeEnv
);
// check if buffer is large enough for accommodating all qualified points
// update the number of output result
if
(
*
numOfRes
>
0
&&
pQuery
->
checkBufferInLoop
==
1
&&
((
*
numOfRes
)
>=
pQuery
->
rec
.
threshold
))
{
if
(
numOfRes
>
0
&&
pQuery
->
checkBuffer
==
1
)
{
assert
(
numOfRes
>=
pQuery
->
rec
.
rows
);
pQuery
->
rec
.
rows
=
numOfRes
;
if
(
numOfRes
>=
pQuery
->
rec
.
threshold
)
{
setQueryStatus
(
pQuery
,
QUERY_RESBUF_FULL
);
setQueryStatus
(
pQuery
,
QUERY_RESBUF_FULL
);
}
}
}
return
0
;
return
numOfRes
;
}
}
void
setExecParams
(
SQuery
*
pQuery
,
SQLFunctionCtx
*
pCtx
,
void
*
inputData
,
TSKEY
*
tsCol
,
int32_t
size
,
void
setExecParams
(
SQuery
*
pQuery
,
SQLFunctionCtx
*
pCtx
,
void
*
inputData
,
TSKEY
*
tsCol
,
int32_t
size
,
...
@@ -1450,8 +1438,7 @@ static void setWindowResultInfo(SResultInfo *pResultInfo, SQuery *pQuery, bool i
...
@@ -1450,8 +1438,7 @@ static void setWindowResultInfo(SResultInfo *pResultInfo, SQuery *pQuery, bool i
}
}
}
}
static
int32_t
setupQueryRuntimeEnv
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SColumnModel
*
pTagsSchema
,
int16_t
order
,
static
int32_t
setupQueryRuntimeEnv
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SColumnModel
*
pTagsSchema
,
int16_t
order
)
{
bool
isSTableQuery
)
{
dTrace
(
"QInfo:%p setup runtime env"
,
GET_QINFO_ADDR
(
pRuntimeEnv
));
dTrace
(
"QInfo:%p setup runtime env"
,
GET_QINFO_ADDR
(
pRuntimeEnv
));
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
...
@@ -1465,7 +1452,6 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, SColumnModel
...
@@ -1465,7 +1452,6 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, SColumnModel
pRuntimeEnv
->
offset
[
0
]
=
0
;
pRuntimeEnv
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
SSqlFuncExprMsg
*
pSqlFuncMsg
=
&
pQuery
->
pSelectExpr
[
i
].
pBase
;
SSqlFuncExprMsg
*
pSqlFuncMsg
=
&
pQuery
->
pSelectExpr
[
i
].
pBase
;
// SColIndexEx * pColIndexEx = &pSqlFuncMsg->colInfo;
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
i
];
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
i
];
pCtx
->
inputType
=
GET_COLUMN_TYPE
(
pQuery
,
i
);
pCtx
->
inputType
=
GET_COLUMN_TYPE
(
pQuery
,
i
);
...
@@ -1511,10 +1497,10 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, SColumnModel
...
@@ -1511,10 +1497,10 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, SColumnModel
}
}
// set the intermediate result output buffer
// set the intermediate result output buffer
setWindowResultInfo
(
pRuntimeEnv
->
resultInfo
,
pQuery
,
isST
ableQuery
);
setWindowResultInfo
(
pRuntimeEnv
->
resultInfo
,
pQuery
,
pRuntimeEnv
->
st
ableQuery
);
// if it is group by normal column, do not set output buffer, the output buffer is pResult
// if it is group by normal column, do not set output buffer, the output buffer is pResult
if
(
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
&&
!
isST
ableQuery
)
{
if
(
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
&&
!
pRuntimeEnv
->
st
ableQuery
)
{
resetCtxOutputBuf
(
pRuntimeEnv
);
resetCtxOutputBuf
(
pRuntimeEnv
);
}
}
...
@@ -1606,7 +1592,7 @@ bool isFixedOutputQuery(SQuery *pQuery) {
...
@@ -1606,7 +1592,7 @@ bool isFixedOutputQuery(SQuery *pQuery) {
// ignore the ts_comp function
// ignore the ts_comp function
if
(
i
==
0
&&
pExprMsg
->
functionId
==
TSDB_FUNC_PRJ
&&
pExprMsg
->
numOfParams
==
1
&&
if
(
i
==
0
&&
pExprMsg
->
functionId
==
TSDB_FUNC_PRJ
&&
pExprMsg
->
numOfParams
==
1
&&
pExprMsg
->
colInfo
.
colI
d
x
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
pExprMsg
->
colInfo
.
colI
nde
x
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
continue
;
continue
;
}
}
...
@@ -1683,7 +1669,7 @@ static bool needReverseScan(SQuery *pQuery) {
...
@@ -1683,7 +1669,7 @@ static bool needReverseScan(SQuery *pQuery) {
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
void
doGetAlignedIntervalQueryRangeImpl
(
SQuery
*
pQuery
,
int64_t
key
,
int64_t
keyFirst
,
int64_t
keyLast
,
void
getAlignQueryTimeWindow
(
SQuery
*
pQuery
,
int64_t
key
,
int64_t
keyFirst
,
int64_t
keyLast
,
int64_t
*
realSkey
,
int64_t
*
realEkey
,
STimeWindow
*
win
)
{
int64_t
*
realSkey
,
int64_t
*
realEkey
,
STimeWindow
*
win
)
{
assert
(
key
>=
keyFirst
&&
key
<=
keyLast
&&
pQuery
->
slidingTime
<=
pQuery
->
intervalTime
);
assert
(
key
>=
keyFirst
&&
key
<=
keyLast
&&
pQuery
->
slidingTime
<=
pQuery
->
intervalTime
);
...
@@ -1835,9 +1821,9 @@ bool normalizeUnBoundLastRowQuery(SQInfo *pQInfo, SPointInterpoSupporter *pPoint
...
@@ -1835,9 +1821,9 @@ bool normalizeUnBoundLastRowQuery(SQInfo *pQInfo, SPointInterpoSupporter *pPoint
static
void
setScanLimitationByResultBuffer
(
SQuery
*
pQuery
)
{
static
void
setScanLimitationByResultBuffer
(
SQuery
*
pQuery
)
{
if
(
isTopBottomQuery
(
pQuery
))
{
if
(
isTopBottomQuery
(
pQuery
))
{
pQuery
->
checkBuffer
InLoop
=
0
;
pQuery
->
checkBuffer
=
0
;
}
else
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
}
else
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
pQuery
->
checkBuffer
InLoop
=
0
;
pQuery
->
checkBuffer
=
0
;
}
else
{
}
else
{
bool
hasMultioutput
=
false
;
bool
hasMultioutput
=
false
;
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
...
@@ -1852,7 +1838,7 @@ static void setScanLimitationByResultBuffer(SQuery *pQuery) {
...
@@ -1852,7 +1838,7 @@ static void setScanLimitationByResultBuffer(SQuery *pQuery) {
}
}
}
}
pQuery
->
checkBuffer
InLoop
=
hasMultioutput
?
1
:
0
;
pQuery
->
checkBuffer
=
hasMultioutput
?
1
:
0
;
}
}
}
}
...
@@ -1902,9 +1888,9 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) {
...
@@ -1902,9 +1888,9 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) {
// descending order query for last_row query
// descending order query for last_row query
if
(
isFirstLastRowQuery
(
pQuery
))
{
if
(
isFirstLastRowQuery
(
pQuery
))
{
dTrace
(
"QInfo:%p scan order changed for last_row query, old:%d, new:%d"
,
GET_QINFO_ADDR
(
pQuery
),
dTrace
(
"QInfo:%p scan order changed for last_row query, old:%d, new:%d"
,
GET_QINFO_ADDR
(
pQuery
),
pQuery
->
order
.
order
,
TS
QL_SO
_DESC
);
pQuery
->
order
.
order
,
TS
DB_ORDER
_DESC
);
pQuery
->
order
.
order
=
TS
QL_SO
_DESC
;
pQuery
->
order
.
order
=
TS
DB_ORDER
_DESC
;
int64_t
skey
=
MIN
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
);
int64_t
skey
=
MIN
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
);
int64_t
ekey
=
MAX
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
);
int64_t
ekey
=
MAX
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
);
...
@@ -1917,56 +1903,56 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) {
...
@@ -1917,56 +1903,56 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) {
if
(
isPointInterpoQuery
(
pQuery
)
&&
pQuery
->
intervalTime
==
0
)
{
if
(
isPointInterpoQuery
(
pQuery
)
&&
pQuery
->
intervalTime
==
0
)
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"interp"
,
pQuery
->
order
.
order
,
TS
QL_SO
_ASC
,
pQuery
->
window
.
skey
,
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"interp"
,
pQuery
->
order
.
order
,
TS
DB_ORDER
_ASC
,
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
}
pQuery
->
order
.
order
=
TS
QL_SO
_ASC
;
pQuery
->
order
.
order
=
TS
DB_ORDER
_ASC
;
return
;
return
;
}
}
if
(
pQuery
->
intervalTime
==
0
)
{
if
(
pQuery
->
intervalTime
==
0
)
{
if
(
onlyFirstQuery
(
pQuery
))
{
if
(
onlyFirstQuery
(
pQuery
))
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-first"
,
pQuery
->
order
.
order
,
TS
QL_SO
_ASC
,
pQuery
->
window
.
skey
,
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-first"
,
pQuery
->
order
.
order
,
TS
DB_ORDER
_ASC
,
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
}
pQuery
->
order
.
order
=
TS
QL_SO
_ASC
;
pQuery
->
order
.
order
=
TS
DB_ORDER
_ASC
;
}
else
if
(
onlyLastQuery
(
pQuery
))
{
}
else
if
(
onlyLastQuery
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-last"
,
pQuery
->
order
.
order
,
TS
QL_SO
_DESC
,
pQuery
->
window
.
skey
,
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-last"
,
pQuery
->
order
.
order
,
TS
DB_ORDER
_DESC
,
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
}
pQuery
->
order
.
order
=
TS
QL_SO
_DESC
;
pQuery
->
order
.
order
=
TS
DB_ORDER
_DESC
;
}
}
}
else
{
// interval query
}
else
{
// interval query
if
(
metricQuery
)
{
if
(
metricQuery
)
{
if
(
onlyFirstQuery
(
pQuery
))
{
if
(
onlyFirstQuery
(
pQuery
))
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-first stable"
,
pQuery
->
order
.
order
,
TS
QL_SO
_ASC
,
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-first stable"
,
pQuery
->
order
.
order
,
TS
DB_ORDER
_ASC
,
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
}
pQuery
->
order
.
order
=
TS
QL_SO
_ASC
;
pQuery
->
order
.
order
=
TS
DB_ORDER
_ASC
;
}
else
if
(
onlyLastQuery
(
pQuery
))
{
}
else
if
(
onlyLastQuery
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-last stable"
,
pQuery
->
order
.
order
,
TS
QL_SO
_DESC
,
dTrace
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"only-last stable"
,
pQuery
->
order
.
order
,
TS
DB_ORDER
_DESC
,
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
}
pQuery
->
order
.
order
=
TS
QL_SO
_DESC
;
pQuery
->
order
.
order
=
TS
DB_ORDER
_DESC
;
}
}
}
}
}
}
...
@@ -2104,8 +2090,7 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI
...
@@ -2104,8 +2090,7 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI
continue
;
continue
;
}
}
int32_t
colInBuf
=
pQuery
->
pSelectExpr
[
i
].
pBase
.
colInfo
.
colIdxInBuf
;
int32_t
colInBuf
=
0
;
//pQuery->pSelectExpr[i].pBase.colInfo.colIdxInBuf;
SInterpInfo
*
pInterpInfo
=
(
SInterpInfo
*
)
pRuntimeEnv
->
pCtx
[
i
].
aOutputBuf
;
SInterpInfo
*
pInterpInfo
=
(
SInterpInfo
*
)
pRuntimeEnv
->
pCtx
[
i
].
aOutputBuf
;
pInterpInfo
->
pInterpDetail
=
calloc
(
1
,
sizeof
(
SInterpInfoDetail
));
pInterpInfo
->
pInterpDetail
=
calloc
(
1
,
sizeof
(
SInterpInfoDetail
));
...
@@ -2276,12 +2261,12 @@ int32_t vnodeSTableQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) {
...
@@ -2276,12 +2261,12 @@ int32_t vnodeSTableQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) {
// set the ts-comp file traverse order
// set the ts-comp file traverse order
if
(
param
!=
NULL
)
{
if
(
param
!=
NULL
)
{
int16_t
order
=
(
pQuery
->
order
.
order
==
pRuntimeEnv
->
pTSBuf
->
tsOrder
)
?
TS
QL_SO_ASC
:
TSQL_SO
_DESC
;
int16_t
order
=
(
pQuery
->
order
.
order
==
pRuntimeEnv
->
pTSBuf
->
tsOrder
)
?
TS
DB_ORDER_ASC
:
TSDB_ORDER
_DESC
;
tsBufSetTraverseOrder
(
pRuntimeEnv
->
pTSBuf
,
order
);
tsBufSetTraverseOrder
(
pRuntimeEnv
->
pTSBuf
,
order
);
}
}
assert
(
0
);
assert
(
0
);
// int32_t ret = setupQueryRuntimeEnv(pMeter, pQuery, &pQInfo->runtimeEnv, pTagSchemaInfo, TS
QL_SO
_ASC, true);
// int32_t ret = setupQueryRuntimeEnv(pMeter, pQuery, &pQInfo->runtimeEnv, pTagSchemaInfo, TS
DB_ORDER
_ASC, true);
// if (ret != TSDB_CODE_SUCCESS) {
// if (ret != TSDB_CODE_SUCCESS) {
// return ret;
// return ret;
// }
// }
...
@@ -2403,7 +2388,7 @@ static bool needToLoadDataBlock(SQuery *pQuery, SDataStatis *pDataStatis, SQLFun
...
@@ -2403,7 +2388,7 @@ static bool needToLoadDataBlock(SQuery *pQuery, SDataStatis *pDataStatis, SQLFun
#if 0
#if 0
for (int32_t k = 0; k < pQuery->numOfFilterCols; ++k) {
for (int32_t k = 0; k < pQuery->numOfFilterCols; ++k) {
SSingleColumnFilterInfo *pFilterInfo = &pQuery->pFilterInfo[k];
SSingleColumnFilterInfo *pFilterInfo = &pQuery->pFilterInfo[k];
int32_t colIndex = pFilterInfo->info.colI
d
x;
int32_t colIndex = pFilterInfo->info.colI
nde
x;
// this column not valid in current data block
// this column not valid in current data block
if (colIndex < 0 || pDataStatis[colIndex].colId != pFilterInfo->info.data.colId) {
if (colIndex < 0 || pDataStatis[colIndex].colId != pFilterInfo->info.data.colId) {
...
@@ -2481,7 +2466,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl
...
@@ -2481,7 +2466,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl
if
(
r
==
BLK_DATA_NO_NEEDED
)
{
if
(
r
==
BLK_DATA_NO_NEEDED
)
{
qTrace
(
"QInfo:%p slot:%d, data block ignored, brange:%"
PRId64
"-%"
PRId64
", rows:%d"
,
qTrace
(
"QInfo:%p slot:%d, data block ignored, brange:%"
PRId64
"-%"
PRId64
", rows:%d"
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
pBlockInfo
->
window
.
skey
,
pBlockInfo
->
window
.
ekey
,
pBlockInfo
->
size
);
GET_QINFO_ADDR
(
pRuntimeEnv
),
pBlockInfo
->
window
.
skey
,
pBlockInfo
->
window
.
ekey
,
pBlockInfo
->
rows
);
}
else
if
(
r
==
BLK_DATA_FILEDS_NEEDED
)
{
}
else
if
(
r
==
BLK_DATA_FILEDS_NEEDED
)
{
if
(
tsdbRetrieveDataBlockStatisInfo
(
pRuntimeEnv
->
pQueryHandle
,
pStatis
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tsdbRetrieveDataBlockStatisInfo
(
pRuntimeEnv
->
pQueryHandle
,
pStatis
)
!=
TSDB_CODE_SUCCESS
)
{
// return DISK_DATA_LOAD_FAILED;
// return DISK_DATA_LOAD_FAILED;
...
@@ -2501,7 +2486,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl
...
@@ -2501,7 +2486,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl
* filter the data block according to the value filter condition.
* filter the data block according to the value filter condition.
* no need to load the data block, continue for next block
* no need to load the data block, continue for next block
*/
*/
if
(
!
needToLoadDataBlock
(
pQuery
,
*
pStatis
,
pRuntimeEnv
->
pCtx
,
pBlockInfo
->
size
))
{
if
(
!
needToLoadDataBlock
(
pQuery
,
*
pStatis
,
pRuntimeEnv
->
pCtx
,
pBlockInfo
->
rows
))
{
#if defined(_DEBUG_VIEW)
#if defined(_DEBUG_VIEW)
dTrace
(
"QInfo:%p fileId:%d, slot:%d, block discarded by per-filter"
,
GET_QINFO_ADDR
(
pQuery
),
pQuery
->
fileId
,
dTrace
(
"QInfo:%p fileId:%d, slot:%d, block discarded by per-filter"
,
GET_QINFO_ADDR
(
pQuery
),
pQuery
->
fileId
,
pQuery
->
slot
);
pQuery
->
slot
);
...
@@ -2577,8 +2562,6 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) {
...
@@ -2577,8 +2562,6 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) {
static
int64_t
doScanAllDataBlocks
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
static
int64_t
doScanAllDataBlocks
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int64_t
cnt
=
0
;
dTrace
(
"QInfo:%p query start, qrange:%"
PRId64
"-%"
PRId64
", lastkey:%"
PRId64
", order:%d"
,
dTrace
(
"QInfo:%p query start, qrange:%"
PRId64
"-%"
PRId64
", lastkey:%"
PRId64
", order:%d"
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
lastKey
,
pQuery
->
order
.
order
);
GET_QINFO_ADDR
(
pRuntimeEnv
),
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
lastKey
,
pQuery
->
order
.
order
);
...
@@ -2586,43 +2569,66 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -2586,43 +2569,66 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
while
(
tsdbNextDataBlock
(
pQueryHandle
))
{
// check if query is killed or not set the status of query to pass the status check
// check if query is killed or not set the status of query to pass the status check
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
return
cnt
;
return
0
;
}
}
SDataBlockInfo
blockInfo
=
tsdbRetrieveDataBlockInfo
(
pQueryHandle
);
SDataBlockInfo
blockInfo
=
tsdbRetrieveDataBlockInfo
(
pQueryHandle
);
// todo extract methods
if
(
isIntervalQuery
(
pQuery
)
&&
pRuntimeEnv
->
windowResInfo
.
prevSKey
==
0
)
{
if
(
isIntervalQuery
(
pQuery
)
&&
pRuntimeEnv
->
windowResInfo
.
prevSKey
==
0
)
{
TSKEY
skey1
,
ekey1
;
TSKEY
skey1
,
ekey1
;
STimeWindow
w
=
{
0
};
STimeWindow
w
=
{
0
};
SWindowResInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
SWindowResInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
doGetAlignedIntervalQueryRangeImpl
(
pQuery
,
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
skey
,
pQuery
->
window
.
ekey
,
getAlignQueryTimeWindow
(
pQuery
,
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
skey
,
pQuery
->
window
.
ekey
,
&
skey1
,
&
ekey1
,
&
w
);
&
skey1
,
&
ekey1
,
&
w
);
pWindowResInfo
->
startTime
=
w
.
skey
;
pWindowResInfo
->
startTime
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
}
else
{
}
else
{
// the start position of the first time window in the endpoint that spreads beyond the queried last timestamp
// the start position of the first time window in the endpoint that spreads beyond the queried last timestamp
TSKEY
winStart
=
blockInfo
.
window
.
ekey
-
pQuery
->
intervalTime
;
TSKEY
start
=
blockInfo
.
window
.
ekey
-
pQuery
->
intervalTime
;
doGetAlignedIntervalQueryRangeImpl
(
pQuery
,
winStart
,
pQuery
->
window
.
ekey
,
blockInfo
.
window
.
ekey
,
&
skey1
,
&
ekey1
,
getAlignQueryTimeWindow
(
pQuery
,
start
,
pQuery
->
window
.
ekey
,
blockInfo
.
window
.
ekey
,
&
skey1
,
&
ekey1
,
&
w
);
&
w
);
pWindowResInfo
->
startTime
=
pQuery
->
window
.
skey
;
pWindowResInfo
->
startTime
=
pQuery
->
window
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
}
}
}
}
int32_t
numOfRes
=
0
;
// in case of prj/diff query, ensure the output buffer is sufficient to accomodate the results of current block
if
(
!
isIntervalQuery
(
pQuery
)
&&
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
&&
!
isFixedOutputQuery
(
pQuery
))
{
SResultRec
*
pRec
=
&
pQuery
->
rec
;
if
(
pQuery
->
rec
.
capacity
-
pQuery
->
rec
.
rows
<
blockInfo
.
rows
)
{
int32_t
remain
=
pRec
->
capacity
-
pRec
->
rows
;
int32_t
newSize
=
pRec
->
capacity
+
(
blockInfo
.
rows
-
remain
);
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
int32_t
bytes
=
pQuery
->
pSelectExpr
[
i
].
resBytes
;
char
*
tmp
=
realloc
(
pQuery
->
sdata
[
i
],
bytes
*
newSize
+
sizeof
(
SData
));
if
(
tmp
==
NULL
)
{
// todo handle the oom
}
else
{
pQuery
->
sdata
[
i
]
=
(
SData
*
)
tmp
;
}
// set the pCtx output buffer position
pRuntimeEnv
->
pCtx
[
i
].
aOutputBuf
=
pQuery
->
sdata
[
i
]
->
data
+
pRec
->
rows
*
bytes
;
}
pRec
->
capacity
=
newSize
;
}
}
SDataStatis
*
pStatis
=
NULL
;
SDataStatis
*
pStatis
=
NULL
;
SArray
*
pDataBlock
=
loadDataBlockOnDemand
(
pRuntimeEnv
,
&
blockInfo
,
&
pStatis
);
SArray
*
pDataBlock
=
loadDataBlockOnDemand
(
pRuntimeEnv
,
&
blockInfo
,
&
pStatis
);
int32_t
forwardStep
=
tableApplyFunctionsOnBlock
(
pRuntimeEnv
,
&
blockInfo
,
pStatis
,
binarySearchForKey
,
&
numOfRes
,
int32_t
numOfRes
=
tableApplyFunctionsOnBlock
(
pRuntimeEnv
,
&
blockInfo
,
pStatis
,
binarySearchForKey
,
&
pRuntimeEnv
->
windowResInfo
,
pDataBlock
);
&
pRuntimeEnv
->
windowResInfo
,
pDataBlock
);
dTrace
(
"QInfo:%p check data block, brange:%"
PRId64
"-%"
PRId64
", rows:%d"
,
dTrace
(
"QInfo:%p check data block, brange:%"
PRId64
"-%"
PRId64
", rows:%d
, res:%d
"
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
ekey
,
blockInfo
.
size
);
GET_QINFO_ADDR
(
pRuntimeEnv
),
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
ekey
,
blockInfo
.
rows
,
numOfRes
);
// save last access position
// save last access position
cnt
+=
forwardStep
;
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_RESBUF_FULL
))
{
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_RESBUF_FULL
))
{
break
;
break
;
}
}
...
@@ -2645,7 +2651,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -2645,7 +2651,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
}
}
}
}
return
cnt
;
return
0
;
}
}
static
void
updatelastkey
(
SQuery
*
pQuery
,
STableQueryInfo
*
pTableQInfo
)
{
pTableQInfo
->
lastKey
=
pQuery
->
lastKey
;
}
static
void
updatelastkey
(
SQuery
*
pQuery
,
STableQueryInfo
*
pTableQInfo
)
{
pTableQInfo
->
lastKey
=
pQuery
->
lastKey
;
}
...
@@ -2683,19 +2689,19 @@ void vnodeSetTagValueInParam(tSidSet *pSidSet, SQueryRuntimeEnv *pRuntimeEnv, vo
...
@@ -2683,19 +2689,19 @@ void vnodeSetTagValueInParam(tSidSet *pSidSet, SQueryRuntimeEnv *pRuntimeEnv, vo
}
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
->
numOfOutputCols
;
++
idx
)
{
for
(
int32_t
idx
=
0
;
idx
<
pQuery
->
numOfOutputCols
;
++
idx
)
{
SColIndex
Ex
*
pColEx
=
&
pQuery
->
pSelectExpr
[
idx
].
pBase
.
colInfo
;
SColIndex
*
pColEx
=
&
pQuery
->
pSelectExpr
[
idx
].
pBase
.
colInfo
;
// ts_comp column required the tag value for join filter
// ts_comp column required the tag value for join filter
if
(
!
TSDB_COL_IS_TAG
(
pColEx
->
flag
))
{
if
(
!
TSDB_COL_IS_TAG
(
pColEx
->
flag
))
{
continue
;
continue
;
}
}
doSetTagValueInParam
(
pTagSchema
,
pColEx
->
colI
d
x
,
pMeterSidInfo
,
&
pRuntimeEnv
->
pCtx
[
idx
].
tag
);
doSetTagValueInParam
(
pTagSchema
,
pColEx
->
colI
nde
x
,
pMeterSidInfo
,
&
pRuntimeEnv
->
pCtx
[
idx
].
tag
);
}
}
// set the join tag for first column
// set the join tag for first column
SSqlFuncExprMsg
*
pFuncMsg
=
&
pQuery
->
pSelectExpr
[
0
].
pBase
;
SSqlFuncExprMsg
*
pFuncMsg
=
&
pQuery
->
pSelectExpr
[
0
].
pBase
;
if
(
pFuncMsg
->
functionId
==
TSDB_FUNC_TS
&&
pFuncMsg
->
colInfo
.
colI
d
x
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
&&
if
(
pFuncMsg
->
functionId
==
TSDB_FUNC_TS
&&
pFuncMsg
->
colInfo
.
colI
nde
x
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
&&
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
assert
(
pFuncMsg
->
numOfParams
==
1
);
assert
(
pFuncMsg
->
numOfParams
==
1
);
doSetTagValueInParam
(
pTagSchema
,
pFuncMsg
->
arg
->
argValue
.
i64
,
pMeterSidInfo
,
&
pRuntimeEnv
->
pCtx
[
0
].
tag
);
doSetTagValueInParam
(
pTagSchema
,
pFuncMsg
->
arg
->
argValue
.
i64
,
pMeterSidInfo
,
&
pRuntimeEnv
->
pCtx
[
0
].
tag
);
...
@@ -2822,13 +2828,13 @@ void UNUSED_FUNC displayInterResult(SData **pdata, SQuery *pQuery, int32_t numOf
...
@@ -2822,13 +2828,13 @@ void UNUSED_FUNC displayInterResult(SData **pdata, SQuery *pQuery, int32_t numOf
for (int32_t i = 0; i < numOfCols; ++i) {
for (int32_t i = 0; i < numOfCols; ++i) {
switch (pQuery->pSelectExpr[i].resType) {
switch (pQuery->pSelectExpr[i].resType) {
case TSDB_DATA_TYPE_BINARY: {
case TSDB_DATA_TYPE_BINARY: {
int32_t colI
dx = pQuery->pSelectExpr[i].pBase.colInfo.colId
x;
int32_t colI
ndex = pQuery->pSelectExpr[i].pBase.colInfo.colInde
x;
int32_t type = 0;
int32_t type = 0;
if (TSDB_COL_IS_TAG(pQuery->pSelectExpr[i].pBase.colInfo.flag)) {
if (TSDB_COL_IS_TAG(pQuery->pSelectExpr[i].pBase.colInfo.flag)) {
type = pQuery->pSelectExpr[i].resType;
type = pQuery->pSelectExpr[i].resType;
} else {
} else {
type = pMeterObj->schema[colI
d
x].type;
type = pMeterObj->schema[colI
nde
x].type;
}
}
printBinaryData(pQuery->pSelectExpr[i].pBase.functionId, pdata[i]->data + pQuery->pSelectExpr[i].resBytes * j,
printBinaryData(pQuery->pSelectExpr[i].pBase.functionId, pdata[i]->data + pQuery->pSelectExpr[i].resBytes * j,
type);
type);
...
@@ -2979,9 +2985,9 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) {
...
@@ -2979,9 +2985,9 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) {
offset
+=
pData
->
numOfElems
;
offset
+=
pData
->
numOfElems
;
}
}
assert
(
pQuery
->
rec
.
size
==
0
);
assert
(
pQuery
->
rec
.
rows
==
0
);
pQuery
->
rec
.
size
+=
rows
;
pQuery
->
rec
.
rows
+=
rows
;
pQInfo
->
offset
+=
1
;
pQInfo
->
offset
+=
1
;
}
}
...
@@ -3207,8 +3213,8 @@ static void doDisableFunctsForSupplementaryScan(SQuery *pQuery, SWindowResInfo *
...
@@ -3207,8 +3213,8 @@ static void doDisableFunctsForSupplementaryScan(SQuery *pQuery, SWindowResInfo *
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutputCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutputCols
;
++
j
)
{
int32_t
functId
=
pQuery
->
pSelectExpr
[
j
].
pBase
.
functionId
;
int32_t
functId
=
pQuery
->
pSelectExpr
[
j
].
pBase
.
functionId
;
if
(((
functId
==
TSDB_FUNC_FIRST
||
functId
==
TSDB_FUNC_FIRST_DST
)
&&
order
==
TS
QL_SO
_DESC
)
||
if
(((
functId
==
TSDB_FUNC_FIRST
||
functId
==
TSDB_FUNC_FIRST_DST
)
&&
order
==
TS
DB_ORDER
_DESC
)
||
((
functId
==
TSDB_FUNC_LAST
||
functId
==
TSDB_FUNC_LAST_DST
)
&&
order
==
TS
QL_SO
_ASC
))
{
((
functId
==
TSDB_FUNC_LAST
||
functId
==
TSDB_FUNC_LAST_DST
)
&&
order
==
TS
DB_ORDER
_ASC
))
{
buf
->
resultInfo
[
j
].
complete
=
false
;
buf
->
resultInfo
[
j
].
complete
=
false
;
}
else
if
(
functId
!=
TSDB_FUNC_TS
&&
functId
!=
TSDB_FUNC_TAG
)
{
}
else
if
(
functId
!=
TSDB_FUNC_TS
&&
functId
!=
TSDB_FUNC_TAG
)
{
buf
->
resultInfo
[
j
].
complete
=
true
;
buf
->
resultInfo
[
j
].
complete
=
true
;
...
@@ -3233,8 +3239,8 @@ void disableFunctForTableSuppleScan(SQueryRuntimeEnv *pRuntimeEnv, int32_t order
...
@@ -3233,8 +3239,8 @@ void disableFunctForTableSuppleScan(SQueryRuntimeEnv *pRuntimeEnv, int32_t order
int32_t
functId
=
pQuery
->
pSelectExpr
[
j
].
pBase
.
functionId
;
int32_t
functId
=
pQuery
->
pSelectExpr
[
j
].
pBase
.
functionId
;
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
j
];
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
j
];
if
(((
functId
==
TSDB_FUNC_FIRST
||
functId
==
TSDB_FUNC_FIRST_DST
)
&&
order
==
TS
QL_SO
_DESC
)
||
if
(((
functId
==
TSDB_FUNC_FIRST
||
functId
==
TSDB_FUNC_FIRST_DST
)
&&
order
==
TS
DB_ORDER
_DESC
)
||
((
functId
==
TSDB_FUNC_LAST
||
functId
==
TSDB_FUNC_LAST_DST
)
&&
order
==
TS
QL_SO
_ASC
))
{
((
functId
==
TSDB_FUNC_LAST
||
functId
==
TSDB_FUNC_LAST_DST
)
&&
order
==
TS
DB_ORDER
_ASC
))
{
pCtx
->
resultInfo
->
complete
=
false
;
pCtx
->
resultInfo
->
complete
=
false
;
}
else
if
(
functId
!=
TSDB_FUNC_TS
&&
functId
!=
TSDB_FUNC_TAG
)
{
}
else
if
(
functId
!=
TSDB_FUNC_TS
&&
functId
!=
TSDB_FUNC_TAG
)
{
pCtx
->
resultInfo
->
complete
=
true
;
pCtx
->
resultInfo
->
complete
=
true
;
...
@@ -3310,7 +3316,7 @@ void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3310,7 +3316,7 @@ void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) {
pCtx
->
ptsOutputBuf
=
pRuntimeEnv
->
pCtx
[
0
].
aOutputBuf
;
pCtx
->
ptsOutputBuf
=
pRuntimeEnv
->
pCtx
[
0
].
aOutputBuf
;
}
}
memset
(
pQuery
->
sdata
[
i
]
->
data
,
0
,
(
size_t
)
pQuery
->
pSelectExpr
[
i
].
resBytes
*
pQuery
->
rec
.
capacity
);
memset
(
pQuery
->
sdata
[
i
]
->
data
,
0
,
(
size_t
)
pQuery
->
pSelectExpr
[
i
].
resBytes
*
pQuery
->
rec
.
capacity
);
}
}
initCtxOutputBuf
(
pRuntimeEnv
);
initCtxOutputBuf
(
pRuntimeEnv
);
...
@@ -3349,22 +3355,22 @@ void initCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3349,22 +3355,22 @@ void initCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) {
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutputCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutputCols
;
++
j
)
{
int32_t
functionId
=
pQuery
->
pSelectExpr
[
j
].
pBase
.
functionId
;
int32_t
functionId
=
pQuery
->
pSelectExpr
[
j
].
pBase
.
functionId
;
pRuntimeEnv
->
pCtx
[
j
].
currentStage
=
0
;
pRuntimeEnv
->
pCtx
[
j
].
currentStage
=
0
;
aAggs
[
functionId
].
init
(
&
pRuntimeEnv
->
pCtx
[
j
]);
aAggs
[
functionId
].
init
(
&
pRuntimeEnv
->
pCtx
[
j
]);
}
}
}
}
void
doSkipResults
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
void
doSkipResults
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
(
pQuery
->
rec
.
size
==
0
||
pQuery
->
limit
.
offset
==
0
)
{
if
(
pQuery
->
rec
.
rows
==
0
||
pQuery
->
limit
.
offset
==
0
)
{
return
;
return
;
}
}
if
(
pQuery
->
rec
.
size
<=
pQuery
->
limit
.
offset
)
{
if
(
pQuery
->
rec
.
rows
<=
pQuery
->
limit
.
offset
)
{
pQuery
->
limit
.
offset
-=
pQuery
->
rec
.
size
;
pQuery
->
limit
.
offset
-=
pQuery
->
rec
.
rows
;
pQuery
->
rec
.
size
=
0
;
pQuery
->
rec
.
rows
=
0
;
// pQuery->pointsOffset = pQuery->rec.pointsToRead; // clear all data in result buffer
// pQuery->pointsOffset = pQuery->rec.pointsToRead; // clear all data in result buffer
resetCtxOutputBuf
(
pRuntimeEnv
);
resetCtxOutputBuf
(
pRuntimeEnv
);
...
@@ -3373,7 +3379,7 @@ void doSkipResults(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3373,7 +3379,7 @@ void doSkipResults(SQueryRuntimeEnv *pRuntimeEnv) {
pQuery
->
status
&=
(
~
QUERY_RESBUF_FULL
);
pQuery
->
status
&=
(
~
QUERY_RESBUF_FULL
);
}
else
{
}
else
{
int32_t
numOfSkip
=
(
int32_t
)
pQuery
->
limit
.
offset
;
int32_t
numOfSkip
=
(
int32_t
)
pQuery
->
limit
.
offset
;
pQuery
->
rec
.
size
-=
numOfSkip
;
pQuery
->
rec
.
rows
-=
numOfSkip
;
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
int32_t
functionId
=
pQuery
->
pSelectExpr
[
i
].
pBase
.
functionId
;
int32_t
functionId
=
pQuery
->
pSelectExpr
[
i
].
pBase
.
functionId
;
...
@@ -3528,6 +3534,7 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3528,6 +3534,7 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
doScanAllDataBlocks
(
pRuntimeEnv
);
doScanAllDataBlocks
(
pRuntimeEnv
);
if
(
!
needScanDataBlocksAgain
(
pRuntimeEnv
))
{
if
(
!
needScanDataBlocksAgain
(
pRuntimeEnv
))
{
// restore the status
// restore the status
if
(
pRuntimeEnv
->
scanFlag
==
REPEAT_SCAN
)
{
if
(
pRuntimeEnv
->
scanFlag
==
REPEAT_SCAN
)
{
pQuery
->
status
=
status
;
pQuery
->
status
=
status
;
...
@@ -3547,7 +3554,6 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3547,7 +3554,6 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
/* check if query is killed or not */
/* check if query is killed or not */
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
if
(
isQueryKilled
(
GET_QINFO_ADDR
(
pRuntimeEnv
)))
{
// setQueryStatus(pQuery, QUERY_NO_DATA_TO_CHECK);
return
;
return
;
}
}
}
}
...
@@ -3678,7 +3684,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *p
...
@@ -3678,7 +3684,7 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *p
/**
/**
* set output buffer for different group
* set output buffer for different group
* @param pRuntimeEnv
* @param pRuntimeEnv
* @param pDataBlockInfo
Ex
* @param pDataBlockInfo
*/
*/
void
setExecutionContext
(
SQInfo
*
pQInfo
,
STableQueryInfo
*
pTableQueryInfo
,
int32_t
meterIdx
,
int32_t
groupIdx
,
void
setExecutionContext
(
SQInfo
*
pQInfo
,
STableQueryInfo
*
pTableQueryInfo
,
int32_t
meterIdx
,
int32_t
groupIdx
,
TSKEY
nextKey
)
{
TSKEY
nextKey
)
{
...
@@ -3793,7 +3799,7 @@ void setIntervalQueryRange(STableQueryInfo *pTableQueryInfo, SQInfo *pQInfo, TSK
...
@@ -3793,7 +3799,7 @@ void setIntervalQueryRange(STableQueryInfo *pTableQueryInfo, SQInfo *pQInfo, TSK
STimeWindow
w
=
{
0
};
STimeWindow
w
=
{
0
};
SWindowResInfo
*
pWindowResInfo
=
&
pTableQueryInfo
->
windowResInfo
;
SWindowResInfo
*
pWindowResInfo
=
&
pTableQueryInfo
->
windowResInfo
;
doGetAlignedIntervalQueryRangeImpl
(
pQuery
,
win
.
skey
,
win
.
skey
,
win
.
ekey
,
&
skey1
,
&
ekey1
,
&
w
);
getAlignQueryTimeWindow
(
pQuery
,
win
.
skey
,
win
.
skey
,
win
.
ekey
,
&
skey1
,
&
ekey1
,
&
w
);
pWindowResInfo
->
startTime
=
pQuery
->
window
.
skey
;
// windowSKey may be 0 in case of 1970 timestamp
pWindowResInfo
->
startTime
=
pQuery
->
window
.
skey
;
// windowSKey may be 0 in case of 1970 timestamp
if
(
pWindowResInfo
->
prevSKey
==
0
)
{
if
(
pWindowResInfo
->
prevSKey
==
0
)
{
...
@@ -3863,7 +3869,7 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde
...
@@ -3863,7 +3869,7 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde
dTrace
(
"QInfo:%p start to copy data from windowResInfo to pQuery buf"
,
GET_QINFO_ADDR
(
pQuery
));
dTrace
(
"QInfo:%p start to copy data from windowResInfo to pQuery buf"
,
GET_QINFO_ADDR
(
pQuery
));
int32_t
totalSubset
=
getNumOfSubset
(
pQInfo
);
int32_t
totalSubset
=
getNumOfSubset
(
pQInfo
);
if
(
orderType
==
TS
QL_SO
_ASC
)
{
if
(
orderType
==
TS
DB_ORDER
_ASC
)
{
startIdx
=
pQInfo
->
subgroupIdx
;
startIdx
=
pQInfo
->
subgroupIdx
;
step
=
1
;
step
=
1
;
}
else
{
// desc order copy all data
}
else
{
// desc order copy all data
...
@@ -3929,12 +3935,12 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde
...
@@ -3929,12 +3935,12 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde
void
copyFromWindowResToSData
(
SQInfo
*
pQInfo
,
SWindowResult
*
result
)
{
void
copyFromWindowResToSData
(
SQInfo
*
pQInfo
,
SWindowResult
*
result
)
{
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
int32_t
orderType
=
(
pQuery
->
pGroupbyExpr
!=
NULL
)
?
pQuery
->
pGroupbyExpr
->
orderType
:
TS
QL_SO
_ASC
;
int32_t
orderType
=
(
pQuery
->
pGroupbyExpr
!=
NULL
)
?
pQuery
->
pGroupbyExpr
->
orderType
:
TS
DB_ORDER
_ASC
;
int32_t
numOfResult
=
doCopyToSData
(
pQInfo
,
result
,
orderType
);
int32_t
numOfResult
=
doCopyToSData
(
pQInfo
,
result
,
orderType
);
pQuery
->
rec
.
size
+=
numOfResult
;
pQuery
->
rec
.
rows
+=
numOfResult
;
assert
(
pQuery
->
rec
.
size
<=
pQuery
->
rec
.
capacity
);
assert
(
pQuery
->
rec
.
rows
<=
pQuery
->
rec
.
capacity
);
}
}
static
void
updateWindowResNumOfRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableDataInfo
*
pTableDataInfo
)
{
static
void
updateWindowResNumOfRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STableDataInfo
*
pTableDataInfo
)
{
...
@@ -3958,15 +3964,12 @@ void stableApplyFunctionsOnBlock(SQueryRuntimeEnv* pRuntimeEnv, STableDataInfo *
...
@@ -3958,15 +3964,12 @@ void stableApplyFunctionsOnBlock(SQueryRuntimeEnv* pRuntimeEnv, STableDataInfo *
STableQueryInfo
*
pTableQueryInfo
=
pTableDataInfo
->
pTableQInfo
;
STableQueryInfo
*
pTableQueryInfo
=
pTableDataInfo
->
pTableQInfo
;
SWindowResInfo
*
pWindowResInfo
=
&
pTableQueryInfo
->
windowResInfo
;
SWindowResInfo
*
pWindowResInfo
=
&
pTableQueryInfo
->
windowResInfo
;
int32_t
numOfRes
=
0
;
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
// numOfRes = rowwiseApplyAllFunctions(pRuntimeEnv, &forwardStep, pFields, pDataBlockInfo, pWindowResInfo);
// numOfRes = rowwiseApplyAllFunctions(pRuntimeEnv, &forwardStep, pFields, pDataBlockInfo, pWindowResInfo);
}
else
{
}
else
{
numOfRes
=
blockwiseApplyAllFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
searchFn
,
pDataBlock
);
blockwiseApplyAllFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
pWindowResInfo
,
searchFn
,
pDataBlock
);
}
}
assert
(
numOfRes
>=
0
);
updateWindowResNumOfRes
(
pRuntimeEnv
,
pTableDataInfo
);
updateWindowResNumOfRes
(
pRuntimeEnv
,
pTableDataInfo
);
updatelastkey
(
pQuery
,
pTableQueryInfo
);
updatelastkey
(
pQuery
,
pTableQueryInfo
);
}
}
...
@@ -3982,7 +3985,7 @@ bool vnodeHasRemainResults(void *handle) {
...
@@ -3982,7 +3985,7 @@ bool vnodeHasRemainResults(void *handle) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SInterpolationInfo
*
pInterpoInfo
=
&
pRuntimeEnv
->
interpoInfo
;
SInterpolationInfo
*
pInterpoInfo
=
&
pRuntimeEnv
->
interpoInfo
;
if
(
pQuery
->
limit
.
limit
>
0
&&
pQuery
->
rec
.
size
>=
pQuery
->
limit
.
limit
)
{
if
(
pQuery
->
limit
.
limit
>
0
&&
pQuery
->
rec
.
rows
>=
pQuery
->
limit
.
limit
)
{
return
false
;
return
false
;
}
}
...
@@ -4153,7 +4156,7 @@ void vnodePrintQueryStatistics(SQInfo *pQInfo) {
...
@@ -4153,7 +4156,7 @@ void vnodePrintQueryStatistics(SQInfo *pQInfo) {
#endif
#endif
}
}
int32_t
doInit
ialize
QInfo
(
SQInfo
*
pQInfo
,
void
*
param
,
void
*
tsdb
,
bool
isSTableQuery
)
{
int32_t
doInitQInfo
(
SQInfo
*
pQInfo
,
void
*
param
,
void
*
tsdb
,
bool
isSTableQuery
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
...
@@ -4182,13 +4185,15 @@ int32_t doInitializeQInfo(SQInfo *pQInfo, void *param, void* tsdb, bool isSTable
...
@@ -4182,13 +4185,15 @@ int32_t doInitializeQInfo(SQInfo *pQInfo, void *param, void* tsdb, bool isSTable
pRuntimeEnv
->
pQuery
=
pQuery
;
pRuntimeEnv
->
pQuery
=
pQuery
;
pRuntimeEnv
->
pTSBuf
=
param
;
pRuntimeEnv
->
pTSBuf
=
param
;
pRuntimeEnv
->
cur
.
vnodeIndex
=
-
1
;
pRuntimeEnv
->
cur
.
vnodeIndex
=
-
1
;
pRuntimeEnv
->
stableQuery
=
isSTableQuery
;
if
(
param
!=
NULL
)
{
if
(
param
!=
NULL
)
{
int16_t
order
=
(
pQuery
->
order
.
order
==
pRuntimeEnv
->
pTSBuf
->
tsOrder
)
?
TS
QL_SO_ASC
:
TSQL_SO
_DESC
;
int16_t
order
=
(
pQuery
->
order
.
order
==
pRuntimeEnv
->
pTSBuf
->
tsOrder
)
?
TS
DB_ORDER_ASC
:
TSDB_ORDER
_DESC
;
tsBufSetTraverseOrder
(
pRuntimeEnv
->
pTSBuf
,
order
);
tsBufSetTraverseOrder
(
pRuntimeEnv
->
pTSBuf
,
order
);
}
}
// create runtime environment
// create runtime environment
code
=
setupQueryRuntimeEnv
(
pRuntimeEnv
,
NULL
,
pQuery
->
order
.
order
,
isSTableQuery
);
code
=
setupQueryRuntimeEnv
(
pRuntimeEnv
,
NULL
,
pQuery
->
order
.
order
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
@@ -4271,8 +4276,6 @@ int32_t doInitializeQInfo(SQInfo *pQInfo, void *param, void* tsdb, bool isSTable
...
@@ -4271,8 +4276,6 @@ int32_t doInitializeQInfo(SQInfo *pQInfo, void *param, void* tsdb, bool isSTable
// the pQuery->window.skey is changed during normalizedFirstQueryRange, so set the newest lastkey value
// the pQuery->window.skey is changed during normalizedFirstQueryRange, so set the newest lastkey value
pQuery
->
lastKey
=
pQuery
->
window
.
skey
;
pQuery
->
lastKey
=
pQuery
->
window
.
skey
;
pRuntimeEnv
->
stableQuery
=
false
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -4282,7 +4285,7 @@ static UNUSED_FUNC bool isGroupbyEachTable(SSqlGroupbyExpr *pGroupbyExpr, tSidSe
...
@@ -4282,7 +4285,7 @@ static UNUSED_FUNC bool isGroupbyEachTable(SSqlGroupbyExpr *pGroupbyExpr, tSidSe
}
}
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
SColIndex
Ex
*
pColIndex
=
&
pGroupbyExpr
->
columnInfo
[
i
];
SColIndex
*
pColIndex
=
&
pGroupbyExpr
->
columnInfo
[
i
];
if
(
pColIndex
->
flag
==
TSDB_COL_TAG
)
{
if
(
pColIndex
->
flag
==
TSDB_COL_TAG
)
{
// assert(pSidset->numOfTables == pSidset->numOfSubSet);
// assert(pSidset->numOfTables == pSidset->numOfSubSet);
return
true
;
return
true
;
...
@@ -4455,7 +4458,7 @@ static UNUSED_FUNC int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, i
...
@@ -4455,7 +4458,7 @@ static UNUSED_FUNC int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, i
// accumulate the point interpolation result
// accumulate the point interpolation result
if
(
numOfRes
>
0
)
{
if
(
numOfRes
>
0
)
{
pQuery
->
rec
.
size
+=
numOfRes
;
pQuery
->
rec
.
rows
+=
numOfRes
;
forwardCtxOutputBuf
(
pRuntimeEnv
,
numOfRes
);
forwardCtxOutputBuf
(
pRuntimeEnv
,
numOfRes
);
}
}
...
@@ -4822,13 +4825,13 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
...
@@ -4822,13 +4825,13 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
}
}
pQuery
->
rec
.
size
+=
pQuery
->
rec
.
size
;
pQuery
->
rec
.
rows
+=
pQuery
->
rec
.
rows
;
if
(
pQuery
->
rec
.
size
==
0
)
{
if
(
pQuery
->
rec
.
rows
==
0
)
{
// vnodePrintQueryStatistics(pSupporter);
// vnodePrintQueryStatistics(pSupporter);
}
}
dTrace
(
"QInfo:%p current:%lldd, total:%lldd"
,
pQInfo
,
pQuery
->
rec
.
size
,
pQuery
->
rec
.
total
);
dTrace
(
"QInfo:%p current:%lldd, total:%lldd"
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
return
;
return
;
}
}
...
@@ -4885,7 +4888,7 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
...
@@ -4885,7 +4888,7 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
}
}
// handle the limitation of output buffer
// handle the limitation of output buffer
dTrace
(
"QInfo:%p points returned:%d, total:%d"
,
pQInfo
,
pQuery
->
rec
.
size
,
pQuery
->
rec
.
total
);
dTrace
(
"QInfo:%p points returned:%d, total:%d"
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
}
}
/*
/*
...
@@ -4906,7 +4909,7 @@ static void tableFixedOutputProcessor(SQInfo *pQInfo) {
...
@@ -4906,7 +4909,7 @@ static void tableFixedOutputProcessor(SQInfo *pQInfo) {
}
}
// since the numOfOutputElems must be identical for all sql functions that are allowed to be executed simutanelously.
// since the numOfOutputElems must be identical for all sql functions that are allowed to be executed simutanelously.
pQuery
->
rec
.
size
=
getNumOfResult
(
pRuntimeEnv
);
pQuery
->
rec
.
rows
=
getNumOfResult
(
pRuntimeEnv
);
// assert(pQuery->size <= pQuery->pointsToRead &&
// assert(pQuery->size <= pQuery->pointsToRead &&
// Q_STATUS_EQUAL(pQuery->over, QUERY_COMPLETED));
// Q_STATUS_EQUAL(pQuery->over, QUERY_COMPLETED));
...
@@ -4918,12 +4921,12 @@ static void tableFixedOutputProcessor(SQInfo *pQInfo) {
...
@@ -4918,12 +4921,12 @@ static void tableFixedOutputProcessor(SQInfo *pQInfo) {
doSkipResults
(
pRuntimeEnv
);
doSkipResults
(
pRuntimeEnv
);
doRevisedResultsByLimit
(
pQInfo
);
doRevisedResultsByLimit
(
pQInfo
);
pQuery
->
rec
.
size
=
pQuery
->
rec
.
size
;
pQuery
->
rec
.
rows
=
pQuery
->
rec
.
rows
;
}
}
static
void
tableMultiOutputProcess
or
(
SQInfo
*
pQInfo
)
{
static
void
tableMultiOutputProcess
(
SQInfo
*
pQInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
// for ts_comp query, re-initialized is not allowed
// for ts_comp query, re-initialized is not allowed
if
(
!
isTSCompQuery
(
pQuery
))
{
if
(
!
isTSCompQuery
(
pQuery
))
{
...
@@ -4938,8 +4941,8 @@ static void tableMultiOutputProcessor(SQInfo *pQInfo) {
...
@@ -4938,8 +4941,8 @@ static void tableMultiOutputProcessor(SQInfo *pQInfo) {
return
;
return
;
}
}
pQuery
->
rec
.
size
=
getNumOfResult
(
pRuntimeEnv
);
pQuery
->
rec
.
rows
=
getNumOfResult
(
pRuntimeEnv
);
if
(
pQuery
->
limit
.
offset
>
0
&&
pQuery
->
numOfFilterCols
>
0
&&
pQuery
->
rec
.
size
>
0
)
{
if
(
pQuery
->
limit
.
offset
>
0
&&
pQuery
->
numOfFilterCols
>
0
&&
pQuery
->
rec
.
rows
>
0
)
{
doSkipResults
(
pRuntimeEnv
);
doSkipResults
(
pRuntimeEnv
);
}
}
...
@@ -4947,7 +4950,7 @@ static void tableMultiOutputProcessor(SQInfo *pQInfo) {
...
@@ -4947,7 +4950,7 @@ static void tableMultiOutputProcessor(SQInfo *pQInfo) {
* 1. if pQuery->size == 0, pQuery->limit.offset >= 0, still need to check data
* 1. if pQuery->size == 0, pQuery->limit.offset >= 0, still need to check data
* 2. if pQuery->size > 0, pQuery->limit.offset must be 0
* 2. if pQuery->size > 0, pQuery->limit.offset must be 0
*/
*/
if
(
pQuery
->
rec
.
size
>
0
||
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
if
(
pQuery
->
rec
.
rows
>
0
||
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
break
;
break
;
}
}
...
@@ -4959,17 +4962,16 @@ static void tableMultiOutputProcessor(SQInfo *pQInfo) {
...
@@ -4959,17 +4962,16 @@ static void tableMultiOutputProcessor(SQInfo *pQInfo) {
doRevisedResultsByLimit
(
pQInfo
);
doRevisedResultsByLimit
(
pQInfo
);
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_RESBUF_FULL
))
{
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_RESBUF_FULL
))
{
dTrace
(
"QInfo:%p query paused due to
buffer
limitation, next qrange:%"
PRId64
"-%"
PRId64
,
dTrace
(
"QInfo:%p query paused due to
output
limitation, next qrange:%"
PRId64
"-%"
PRId64
,
pQInfo
,
pQuery
->
lastKey
,
pQuery
->
window
.
ekey
);
pQInfo
,
pQuery
->
lastKey
,
pQuery
->
window
.
ekey
);
}
}
// dTrace("QInfo:%p vid:%d sid:%d id:%s, %d points returned, totalRead:%d totalReturn:%d", pQInfo, pMeterObj->vnode,
// dTrace("QInfo:%p vid:%d sid:%d id:%s, %d points returned, totalRead:%d totalReturn:%d", pQInfo, pMeterObj->vnode,
// pMeterObj->sid, pMeterObj->meterId, pQuery->size, pQInfo->size, pQInfo->pointsReturned);
// pMeterObj->sid, pMeterObj->meterId, pQuery->size, pQInfo->size, pQInfo->pointsReturned);
// pQuery->pointsOffset = pQuery->pointsToRead; //restore the available buffer
if
(
!
isTSCompQuery
(
pQuery
))
{
// if (!isTSCompQuery(pQuery)) {
assert
(
pQuery
->
rec
.
rows
<=
pQuery
->
rec
.
capacity
);
// assert(pQuery->size <= pQuery->pointsToRead);
}
// }
}
}
static
void
tableIntervalProcessImpl
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
static
void
tableIntervalProcessImpl
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
...
@@ -5016,7 +5018,7 @@ static void tableIntervalProcessor(SQInfo *pQInfo) {
...
@@ -5016,7 +5018,7 @@ static void tableIntervalProcessor(SQInfo *pQInfo) {
if
(
isIntervalQuery
(
pQuery
))
{
if
(
isIntervalQuery
(
pQuery
))
{
pQInfo
->
subgroupIdx
=
0
;
// always start from 0
pQInfo
->
subgroupIdx
=
0
;
// always start from 0
pQuery
->
rec
.
size
=
0
;
pQuery
->
rec
.
rows
=
0
;
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
clearFirstNTimeWindow
(
pRuntimeEnv
,
pQInfo
->
subgroupIdx
);
clearFirstNTimeWindow
(
pRuntimeEnv
,
pQInfo
->
subgroupIdx
);
...
@@ -5027,37 +5029,37 @@ static void tableIntervalProcessor(SQInfo *pQInfo) {
...
@@ -5027,37 +5029,37 @@ static void tableIntervalProcessor(SQInfo *pQInfo) {
doRevisedResultsByLimit
(
pQInfo
);
doRevisedResultsByLimit
(
pQInfo
);
break
;
break
;
}
else
{
}
else
{
taosInterpoSetStartInfo
(
&
pRuntimeEnv
->
interpoInfo
,
pQuery
->
rec
.
size
,
pQuery
->
interpoType
);
taosInterpoSetStartInfo
(
&
pRuntimeEnv
->
interpoInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
interpoType
);
SData
**
pInterpoBuf
=
pRuntimeEnv
->
pInterpoBuf
;
SData
**
pInterpoBuf
=
pRuntimeEnv
->
pInterpoBuf
;
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutputCols
;
++
i
)
{
memcpy
(
pInterpoBuf
[
i
]
->
data
,
pQuery
->
sdata
[
i
]
->
data
,
pQuery
->
rec
.
size
*
pQuery
->
pSelectExpr
[
i
].
resBytes
);
memcpy
(
pInterpoBuf
[
i
]
->
data
,
pQuery
->
sdata
[
i
]
->
data
,
pQuery
->
rec
.
rows
*
pQuery
->
pSelectExpr
[
i
].
resBytes
);
}
}
numOfInterpo
=
0
;
numOfInterpo
=
0
;
pQuery
->
rec
.
size
=
vnodeQueryResultInterpolate
(
pQuery
->
rec
.
rows
=
vnodeQueryResultInterpolate
(
pQInfo
,
(
tFilePage
**
)
pQuery
->
sdata
,
(
tFilePage
**
)
pInterpoBuf
,
pQuery
->
rec
.
size
,
&
numOfInterpo
);
pQInfo
,
(
tFilePage
**
)
pQuery
->
sdata
,
(
tFilePage
**
)
pInterpoBuf
,
pQuery
->
rec
.
rows
,
&
numOfInterpo
);
dTrace
(
"QInfo: %p interpo completed, final:%d"
,
pQInfo
,
pQuery
->
rec
.
size
);
dTrace
(
"QInfo: %p interpo completed, final:%d"
,
pQInfo
,
pQuery
->
rec
.
rows
);
if
(
pQuery
->
rec
.
size
>
0
||
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
if
(
pQuery
->
rec
.
rows
>
0
||
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
doRevisedResultsByLimit
(
pQInfo
);
doRevisedResultsByLimit
(
pQInfo
);
break
;
break
;
}
}
// no result generated yet, continue retrieve data
// no result generated yet, continue retrieve data
pQuery
->
rec
.
size
=
0
;
pQuery
->
rec
.
rows
=
0
;
}
}
}
}
// all data scanned, the group by normal column can return
// all data scanned, the group by normal column can return
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
// todo refactor with merge interval time result
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
// todo refactor with merge interval time result
pQInfo
->
subgroupIdx
=
0
;
pQInfo
->
subgroupIdx
=
0
;
pQuery
->
rec
.
size
=
0
;
pQuery
->
rec
.
rows
=
0
;
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
clearFirstNTimeWindow
(
pRuntimeEnv
,
pQInfo
->
subgroupIdx
);
clearFirstNTimeWindow
(
pRuntimeEnv
,
pQInfo
->
subgroupIdx
);
}
}
pQuery
->
rec
.
size
+=
pQuery
->
rec
.
size
;
pQuery
->
rec
.
rows
+=
pQuery
->
rec
.
rows
;
pQInfo
->
pointsInterpo
+=
numOfInterpo
;
pQInfo
->
pointsInterpo
+=
numOfInterpo
;
// dTrace("%p vid:%d sid:%d id:%s, %d points returned %d points interpo, totalRead:%d totalInterpo:%d
// dTrace("%p vid:%d sid:%d id:%s, %d points returned %d points interpo, totalRead:%d totalInterpo:%d
...
@@ -5066,7 +5068,7 @@ static void tableIntervalProcessor(SQInfo *pQInfo) {
...
@@ -5066,7 +5068,7 @@ static void tableIntervalProcessor(SQInfo *pQInfo) {
// pQInfo->size - pQInfo->pointsInterpo, pQInfo->pointsInterpo, pQInfo->pointsReturned);
// pQInfo->size - pQInfo->pointsInterpo, pQInfo->pointsInterpo, pQInfo->pointsReturned);
}
}
static
void
singleT
ableQueryImpl
(
SQInfo
*
pQInfo
)
{
static
void
t
ableQueryImpl
(
SQInfo
*
pQInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
...
@@ -5077,15 +5079,15 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
...
@@ -5077,15 +5079,15 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
*/
*/
int32_t
numOfInterpo
=
0
;
int32_t
numOfInterpo
=
0
;
int32_t
remain
=
taosNumOfRemainPoints
(
&
pRuntimeEnv
->
interpoInfo
);
int32_t
remain
=
taosNumOfRemainPoints
(
&
pRuntimeEnv
->
interpoInfo
);
pQuery
->
rec
.
size
=
vnodeQueryResultInterpolate
(
pQInfo
,
(
tFilePage
**
)
pQuery
->
sdata
,
pQuery
->
rec
.
rows
=
vnodeQueryResultInterpolate
(
pQInfo
,
(
tFilePage
**
)
pQuery
->
sdata
,
(
tFilePage
**
)
pRuntimeEnv
->
pInterpoBuf
,
remain
,
&
numOfInterpo
);
(
tFilePage
**
)
pRuntimeEnv
->
pInterpoBuf
,
remain
,
&
numOfInterpo
);
doRevisedResultsByLimit
(
pQInfo
);
doRevisedResultsByLimit
(
pQInfo
);
pQInfo
->
pointsInterpo
+=
numOfInterpo
;
pQInfo
->
pointsInterpo
+=
numOfInterpo
;
pQuery
->
rec
.
size
+=
pQuery
->
rec
.
size
;
pQuery
->
rec
.
rows
+=
pQuery
->
rec
.
rows
;
dTrace
(
"QInfo:%p current:%d returned, total:%d"
,
pQInfo
,
pQuery
->
rec
.
size
,
pQuery
->
rec
.
total
);
dTrace
(
"QInfo:%p current:%d returned, total:%d"
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
sem_post
(
&
pQInfo
->
dataReady
);
sem_post
(
&
pQInfo
->
dataReady
);
return
;
return
;
}
}
...
@@ -5097,17 +5099,17 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
...
@@ -5097,17 +5099,17 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
((
isIntervalQuery
(
pQuery
)
&&
pQuery
->
rec
.
total
<
pQuery
->
limit
.
limit
)))
{
((
isIntervalQuery
(
pQuery
)
&&
pQuery
->
rec
.
total
<
pQuery
->
limit
.
limit
)))
{
// todo limit the output for interval query?
// todo limit the output for interval query?
pQuery
->
rec
.
size
=
0
;
pQuery
->
rec
.
rows
=
0
;
pQInfo
->
subgroupIdx
=
0
;
// always start from 0
pQInfo
->
subgroupIdx
=
0
;
// always start from 0
if
(
pRuntimeEnv
->
windowResInfo
.
size
>
0
)
{
if
(
pRuntimeEnv
->
windowResInfo
.
size
>
0
)
{
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
copyFromWindowResToSData
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
pQuery
->
rec
.
size
+=
pQuery
->
rec
.
size
;
pQuery
->
rec
.
rows
+=
pQuery
->
rec
.
rows
;
clearFirstNTimeWindow
(
pRuntimeEnv
,
pQInfo
->
subgroupIdx
);
clearFirstNTimeWindow
(
pRuntimeEnv
,
pQInfo
->
subgroupIdx
);
if
(
pQuery
->
rec
.
size
>
0
)
{
if
(
pQuery
->
rec
.
rows
>
0
)
{
dTrace
(
"QInfo:%p %d rows returned from group results, total:%d"
,
pQInfo
,
pQuery
->
rec
.
size
,
pQuery
->
rec
.
total
);
dTrace
(
"QInfo:%p %d rows returned from group results, total:%d"
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
sem_post
(
&
pQInfo
->
dataReady
);
sem_post
(
&
pQInfo
->
dataReady
);
return
;
return
;
}
}
...
@@ -5121,23 +5123,21 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
...
@@ -5121,23 +5123,21 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
}
}
// number of points returned during this query
// number of points returned during this query
pQuery
->
rec
.
size
=
0
;
pQuery
->
rec
.
rows
=
0
;
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
// 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)
tableIntervalProcessor
(
pQInfo
);
tableIntervalProcessor
(
pQInfo
);
}
else
{
}
else
if
(
isFixedOutputQuery
(
pQuery
))
{
if
(
isFixedOutputQuery
(
pQuery
))
{
assert
(
pQuery
->
checkBuffer
==
0
);
assert
(
pQuery
->
checkBufferInLoop
==
0
);
tableFixedOutputProcessor
(
pQInfo
);
tableFixedOutputProcessor
(
pQInfo
);
}
else
{
// diff/add/multiply/subtract/division
}
else
{
// diff/add/multiply/subtract/division
assert
(
pQuery
->
checkBufferInLoop
==
1
);
assert
(
pQuery
->
checkBuffer
==
1
);
tableMultiOutputProcessor
(
pQInfo
);
tableMultiOutputProcess
(
pQInfo
);
}
}
}
// record the total elapsed time
// record the total elapsed time
pQInfo
->
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
pQInfo
->
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
...
@@ -5145,16 +5145,16 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
...
@@ -5145,16 +5145,16 @@ static void singleTableQueryImpl(SQInfo* pQInfo) {
if
(
isQueryKilled
(
pQInfo
))
{
if
(
isQueryKilled
(
pQInfo
))
{
dTrace
(
"QInfo:%p query is killed"
,
pQInfo
);
dTrace
(
"QInfo:%p query is killed"
,
pQInfo
);
}
else
{
}
else
{
dTrace
(
"QInfo:%p query task completed, %"
PRId64
" rows will returned, total:%"
PRId64
" rows"
,
pQInfo
,
pQuery
->
rec
.
size
,
dTrace
(
"QInfo:%p query task completed, %"
PRId64
" rows will returned, total:%"
PRId64
" rows"
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
pQuery
->
rec
.
total
);
}
}
sem_post
(
&
pQInfo
->
dataReady
);
sem_post
(
&
pQInfo
->
dataReady
);
}
}
static
void
multiT
ableQueryImpl
(
SQInfo
*
pQInfo
)
{
static
void
st
ableQueryImpl
(
SQInfo
*
pQInfo
)
{
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
pQuery
->
rec
.
size
=
0
;
pQuery
->
rec
.
rows
=
0
;
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
...
@@ -5162,7 +5162,7 @@ static void multiTableQueryImpl(SQInfo* pQInfo) {
...
@@ -5162,7 +5162,7 @@ static void multiTableQueryImpl(SQInfo* pQInfo) {
(
isFixedOutputQuery
(
pQuery
)
&&
(
!
isPointInterpoQuery
(
pQuery
))
&&
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)))
{
(
isFixedOutputQuery
(
pQuery
)
&&
(
!
isPointInterpoQuery
(
pQuery
))
&&
!
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)))
{
multiTableQueryProcess
(
pQInfo
);
multiTableQueryProcess
(
pQInfo
);
}
else
{
}
else
{
assert
((
pQuery
->
checkBuffer
InLoop
==
1
&&
pQuery
->
intervalTime
==
0
)
||
isPointInterpoQuery
(
pQuery
)
||
assert
((
pQuery
->
checkBuffer
==
1
&&
pQuery
->
intervalTime
==
0
)
||
isPointInterpoQuery
(
pQuery
)
||
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
));
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
));
vnodeSTableSeqProcessor
(
pQInfo
);
vnodeSTableSeqProcessor
(
pQInfo
);
...
@@ -5172,7 +5172,7 @@ static void multiTableQueryImpl(SQInfo* pQInfo) {
...
@@ -5172,7 +5172,7 @@ static void multiTableQueryImpl(SQInfo* pQInfo) {
pQInfo
->
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
pQInfo
->
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
);
// taosInterpoSetStartInfo(&pQInfo->runtimeEnv.interpoInfo, pQuery->size, pQInfo->query.interpoType);
// taosInterpoSetStartInfo(&pQInfo->runtimeEnv.interpoInfo, pQuery->size, pQInfo->query.interpoType);
if
(
pQuery
->
rec
.
size
==
0
)
{
if
(
pQuery
->
rec
.
rows
==
0
)
{
int32_t
numOfTables
=
taosArrayGetSize
(
pQInfo
->
pTableIdList
);
int32_t
numOfTables
=
taosArrayGetSize
(
pQInfo
->
pTableIdList
);
dTrace
(
"QInfo:%p over, %d tables queried, %d points are returned"
,
pQInfo
,
numOfTables
,
pQuery
->
rec
.
total
);
dTrace
(
"QInfo:%p over, %d tables queried, %d points are returned"
,
pQInfo
,
numOfTables
,
pQuery
->
rec
.
total
);
// vnodePrintQueryStatistics(pSupporter);
// vnodePrintQueryStatistics(pSupporter);
...
@@ -5267,7 +5267,7 @@ static char* createTableIdList(SQueryTableMsg* pQueryMsg, char* pMsg, SArray** p
...
@@ -5267,7 +5267,7 @@ static char* createTableIdList(SQueryTableMsg* pQueryMsg, char* pMsg, SArray** p
* @return
* @return
*/
*/
static
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
SArray
**
pTableIdList
,
SSqlFuncExprMsg
***
pExpr
,
static
int32_t
convertQueryMsg
(
SQueryTableMsg
*
pQueryMsg
,
SArray
**
pTableIdList
,
SSqlFuncExprMsg
***
pExpr
,
wchar_t
**
tagCond
)
{
char
**
tagCond
)
{
pQueryMsg
->
numOfTables
=
htonl
(
pQueryMsg
->
numOfTables
);
pQueryMsg
->
numOfTables
=
htonl
(
pQueryMsg
->
numOfTables
);
pQueryMsg
->
window
.
skey
=
htobe64
(
pQueryMsg
->
window
.
skey
);
pQueryMsg
->
window
.
skey
=
htobe64
(
pQueryMsg
->
window
.
skey
);
...
@@ -5285,7 +5285,6 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
...
@@ -5285,7 +5285,6 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
pQueryMsg
->
numOfOutputCols
=
htons
(
pQueryMsg
->
numOfOutputCols
);
pQueryMsg
->
numOfOutputCols
=
htons
(
pQueryMsg
->
numOfOutputCols
);
pQueryMsg
->
numOfGroupCols
=
htons
(
pQueryMsg
->
numOfGroupCols
);
pQueryMsg
->
numOfGroupCols
=
htons
(
pQueryMsg
->
numOfGroupCols
);
pQueryMsg
->
tagCondLen
=
htons
(
pQueryMsg
->
tagCondLen
);
pQueryMsg
->
tagCondLen
=
htons
(
pQueryMsg
->
tagCondLen
);
pQueryMsg
->
nameCondLen
=
htons
(
pQueryMsg
->
nameCondLen
);
pQueryMsg
->
tsOffset
=
htonl
(
pQueryMsg
->
tsOffset
);
pQueryMsg
->
tsOffset
=
htonl
(
pQueryMsg
->
tsOffset
);
pQueryMsg
->
tsLen
=
htonl
(
pQueryMsg
->
tsLen
);
pQueryMsg
->
tsLen
=
htonl
(
pQueryMsg
->
tsLen
);
pQueryMsg
->
tsNumOfBlocks
=
htonl
(
pQueryMsg
->
tsNumOfBlocks
);
pQueryMsg
->
tsNumOfBlocks
=
htonl
(
pQueryMsg
->
tsNumOfBlocks
);
...
@@ -5345,7 +5344,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
...
@@ -5345,7 +5344,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
for
(
int32_t
i
=
0
;
i
<
pQueryMsg
->
numOfOutputCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryMsg
->
numOfOutputCols
;
++
i
)
{
(
*
pExpr
)[
i
]
=
pExprMsg
;
(
*
pExpr
)[
i
]
=
pExprMsg
;
pExprMsg
->
colInfo
.
colI
dx
=
htons
(
pExprMsg
->
colInfo
.
colId
x
);
pExprMsg
->
colInfo
.
colI
ndex
=
htons
(
pExprMsg
->
colInfo
.
colInde
x
);
pExprMsg
->
colInfo
.
colId
=
htons
(
pExprMsg
->
colInfo
.
colId
);
pExprMsg
->
colInfo
.
colId
=
htons
(
pExprMsg
->
colInfo
.
colId
);
pExprMsg
->
colInfo
.
flag
=
htons
(
pExprMsg
->
colInfo
.
flag
);
pExprMsg
->
colInfo
.
flag
=
htons
(
pExprMsg
->
colInfo
.
flag
);
pExprMsg
->
functionId
=
htons
(
pExprMsg
->
functionId
);
pExprMsg
->
functionId
=
htons
(
pExprMsg
->
functionId
);
...
@@ -5399,7 +5398,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
...
@@ -5399,7 +5398,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
pQueryMsg
->
orderByIdx
=
htons
(
pQueryMsg
->
orderByIdx
);
pQueryMsg
->
orderByIdx
=
htons
(
pQueryMsg
->
orderByIdx
);
pQueryMsg
->
orderType
=
htons
(
pQueryMsg
->
orderType
);
pQueryMsg
->
orderType
=
htons
(
pQueryMsg
->
orderType
);
pMsg
+=
sizeof
(
SColIndex
Ex
)
*
pQueryMsg
->
numOfGroupCols
;
pMsg
+=
sizeof
(
SColIndex
)
*
pQueryMsg
->
numOfGroupCols
;
}
else
{
}
else
{
pQueryMsg
->
groupbyTagIds
=
0
;
pQueryMsg
->
groupbyTagIds
=
0
;
}
}
...
@@ -5418,8 +5417,8 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
...
@@ -5418,8 +5417,8 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
// the tag query condition expression string is located at the end of query msg
// the tag query condition expression string is located at the end of query msg
if
(
pQueryMsg
->
tagCondLen
>
0
)
{
if
(
pQueryMsg
->
tagCondLen
>
0
)
{
*
tagCond
=
calloc
(
1
,
pQueryMsg
->
tagCondLen
*
TSDB_NCHAR_SIZE
);
*
tagCond
=
calloc
(
1
,
pQueryMsg
->
tagCondLen
);
memcpy
(
*
tagCond
,
pMsg
,
pQueryMsg
->
tagCondLen
*
TSDB_NCHAR_SIZE
);
memcpy
(
*
tagCond
,
pMsg
,
pQueryMsg
->
tagCondLen
);
}
}
dTrace
(
"qmsg:%p query on %d table(s), qrange:%"
PRId64
"-%"
PRId64
", numOfGroupbyTagCols:%d, ts order:%d, "
dTrace
(
"qmsg:%p query on %d table(s), qrange:%"
PRId64
"-%"
PRId64
", numOfGroupbyTagCols:%d, ts order:%d, "
...
@@ -5469,10 +5468,10 @@ static int32_t buildAirthmeticExprFromMsg(SSqlFunctionExpr *pExpr, SQueryTableMs
...
@@ -5469,10 +5468,10 @@ static int32_t buildAirthmeticExprFromMsg(SSqlFunctionExpr *pExpr, SQueryTableMs
// there may be duplicated referenced columns.
// there may be duplicated referenced columns.
num = i + 1;
num = i + 1;
pBinaryExprInfo->pReqColumns = malloc(sizeof(SColIndex
Ex
) * num);
pBinaryExprInfo->pReqColumns = malloc(sizeof(SColIndex) * num);
for (int32_t k = 0; k < num; ++k) {
for (int32_t k = 0; k < num; ++k) {
SColIndex
Ex
* pColIndex = &pBinaryExprInfo->pReqColumns[k];
SColIndex* pColIndex = &pBinaryExprInfo->pReqColumns[k];
pColIndex->colId = ids[k];
pColIndex->colId = ids[k];
}
}
...
@@ -5569,19 +5568,19 @@ static SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, int3
...
@@ -5569,19 +5568,19 @@ static SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, int3
// using group by tag columns
// using group by tag columns
SSqlGroupbyExpr
*
pGroupbyExpr
=
SSqlGroupbyExpr
*
pGroupbyExpr
=
(
SSqlGroupbyExpr
*
)
malloc
(
sizeof
(
SSqlGroupbyExpr
)
+
pQueryMsg
->
numOfGroupCols
*
sizeof
(
SColIndex
Ex
));
(
SSqlGroupbyExpr
*
)
malloc
(
sizeof
(
SSqlGroupbyExpr
)
+
pQueryMsg
->
numOfGroupCols
*
sizeof
(
SColIndex
));
if
(
pGroupbyExpr
==
NULL
)
{
if
(
pGroupbyExpr
==
NULL
)
{
*
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
*
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
SColIndex
Ex
*
pGroupbyColInfo
=
(
SColIndexE
x
*
)
pQueryMsg
->
groupbyTagIds
;
SColIndex
*
pGroupbyColInfo
=
(
SColInde
x
*
)
pQueryMsg
->
groupbyTagIds
;
pGroupbyExpr
->
numOfGroupCols
=
pQueryMsg
->
numOfGroupCols
;
pGroupbyExpr
->
numOfGroupCols
=
pQueryMsg
->
numOfGroupCols
;
pGroupbyExpr
->
orderType
=
pQueryMsg
->
orderType
;
pGroupbyExpr
->
orderType
=
pQueryMsg
->
orderType
;
pGroupbyExpr
->
orderIndex
=
pQueryMsg
->
orderByIdx
;
pGroupbyExpr
->
orderIndex
=
pQueryMsg
->
orderByIdx
;
memcpy
(
pGroupbyExpr
->
columnInfo
,
pGroupbyColInfo
,
sizeof
(
SColIndex
Ex
)
*
pGroupbyExpr
->
numOfGroupCols
);
memcpy
(
pGroupbyExpr
->
columnInfo
,
pGroupbyColInfo
,
sizeof
(
SColIndex
)
*
pGroupbyExpr
->
numOfGroupCols
);
return
pGroupbyExpr
;
return
pGroupbyExpr
;
}
}
...
@@ -5631,9 +5630,9 @@ static int32_t vnodeCreateFilterInfo(void *pQInfo, SQuery *pQuery) {
...
@@ -5631,9 +5630,9 @@ static int32_t vnodeCreateFilterInfo(void *pQInfo, SQuery *pQuery) {
return
TSDB_CODE_INVALID_QUERY_MSG
;
return
TSDB_CODE_INVALID_QUERY_MSG
;
}
}
if
((
lower
==
TSDB_RELATION_
LARGE_EQUAL
||
lower
==
TSDB_RELATION_LARGE
)
&&
if
((
lower
==
TSDB_RELATION_
GREATER_EQUAL
||
lower
==
TSDB_RELATION_GREATER
)
&&
(
upper
==
TSDB_RELATION_LESS_EQUAL
||
upper
==
TSDB_RELATION_LESS
))
{
(
upper
==
TSDB_RELATION_LESS_EQUAL
||
upper
==
TSDB_RELATION_LESS
))
{
if
(
lower
==
TSDB_RELATION_
LARGE
_EQUAL
)
{
if
(
lower
==
TSDB_RELATION_
GREATER
_EQUAL
)
{
if
(
upper
==
TSDB_RELATION_LESS_EQUAL
)
{
if
(
upper
==
TSDB_RELATION_LESS_EQUAL
)
{
pSingleColFilter
->
fp
=
rangeFilterArray
[
4
];
pSingleColFilter
->
fp
=
rangeFilterArray
[
4
];
}
else
{
}
else
{
...
@@ -5674,16 +5673,16 @@ static void doUpdateExprColumnIndex(SQuery* pQuery) {
...
@@ -5674,16 +5673,16 @@ static void doUpdateExprColumnIndex(SQuery* pQuery) {
// int32_t i = 0, j = 0;
// int32_t i = 0, j = 0;
// while (i < pQuery->numOfCols && j < pMeterObj->numOfColumns) {
// while (i < pQuery->numOfCols && j < pMeterObj->numOfColumns) {
// if (pQuery->colList[i].data.colId == pMeterObj->schema[j].colId) {
// if (pQuery->colList[i].data.colId == pMeterObj->schema[j].colId) {
// pQuery->colList[i++].colI
d
x = (int16_t)j++;
// pQuery->colList[i++].colI
nde
x = (int16_t)j++;
// } else if (pQuery->colList[i].data.colId < pMeterObj->schema[j].colId) {
// } else if (pQuery->colList[i].data.colId < pMeterObj->schema[j].colId) {
// pQuery->colList[i++].colI
d
x = -1;
// pQuery->colList[i++].colI
nde
x = -1;
// } else if (pQuery->colList[i].data.colId > pMeterObj->schema[j].colId) {
// } else if (pQuery->colList[i].data.colId > pMeterObj->schema[j].colId) {
// j++;
// j++;
// }
// }
// }
// }
// while (i < pQuery->numOfCols) {
// while (i < pQuery->numOfCols) {
// pQuery->colList[i++].colI
d
x = -1; // not such column in current meter
// pQuery->colList[i++].colI
nde
x = -1; // not such column in current meter
// }
// }
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
...
@@ -5692,10 +5691,10 @@ static void doUpdateExprColumnIndex(SQuery* pQuery) {
...
@@ -5692,10 +5691,10 @@ static void doUpdateExprColumnIndex(SQuery* pQuery) {
continue
;
continue
;
}
}
SColIndex
Ex
*
pColIndexEx
=
&
pSqlExprMsg
->
colInfo
;
SColIndex
*
pColIndexEx
=
&
pSqlExprMsg
->
colInfo
;
for
(
int32_t
f
=
0
;
f
<
pQuery
->
numOfCols
;
++
f
)
{
for
(
int32_t
f
=
0
;
f
<
pQuery
->
numOfCols
;
++
f
)
{
if
(
pColIndexEx
->
colId
==
pQuery
->
colList
[
f
].
info
.
colId
)
{
if
(
pColIndexEx
->
colId
==
pQuery
->
colList
[
f
].
info
.
colId
)
{
pColIndexEx
->
colI
d
x
=
f
;
pColIndexEx
->
colI
nde
x
=
f
;
break
;
break
;
}
}
}
}
...
@@ -5776,7 +5775,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
...
@@ -5776,7 +5775,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
// set the output buffer capacity
// set the output buffer capacity
pQuery
->
rec
.
capacity
=
4096
;
pQuery
->
rec
.
capacity
=
4096
;
pQuery
->
rec
.
threshold
=
2
;
pQuery
->
rec
.
threshold
=
4000
;
for
(
int32_t
col
=
0
;
col
<
pQuery
->
numOfOutputCols
;
++
col
)
{
for
(
int32_t
col
=
0
;
col
<
pQuery
->
numOfOutputCols
;
++
col
)
{
assert
(
pExprs
[
col
].
interResBytes
>=
pExprs
[
col
].
resBytes
);
assert
(
pExprs
[
col
].
interResBytes
>=
pExprs
[
col
].
resBytes
);
...
@@ -5855,7 +5854,7 @@ static bool isValidQInfo(void *param) {
...
@@ -5855,7 +5854,7 @@ static bool isValidQInfo(void *param) {
}
}
static
void
freeQInfo
(
SQInfo
*
pQInfo
);
static
void
freeQInfo
(
SQInfo
*
pQInfo
);
static
int32_t
init
ialize
QInfo
(
SQueryTableMsg
*
pQueryMsg
,
void
*
tsdb
,
SQInfo
*
pQInfo
,
bool
isSTable
)
{
static
int32_t
initQInfo
(
SQueryTableMsg
*
pQueryMsg
,
void
*
tsdb
,
SQInfo
*
pQInfo
,
bool
isSTable
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
...
@@ -5880,7 +5879,7 @@ static int32_t initializeQInfo(SQueryTableMsg *pQueryMsg, void* tsdb, SQInfo *pQ
...
@@ -5880,7 +5879,7 @@ static int32_t initializeQInfo(SQueryTableMsg *pQueryMsg, void* tsdb, SQInfo *pQ
}
}
// filter the qualified
// filter the qualified
if
((
code
=
doInit
ialize
QInfo
(
pQInfo
,
pTSBuf
,
tsdb
,
isSTable
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
doInitQInfo
(
pQInfo
,
pTSBuf
,
tsdb
,
isSTable
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
goto
_error
;
}
}
...
@@ -6004,11 +6003,11 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
...
@@ -6004,11 +6003,11 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
pQuery
->
sdata
[
0
]
->
data
,
strerror
(
errno
));
pQuery
->
sdata
[
0
]
->
data
,
strerror
(
errno
));
}
}
}
else
{
}
else
{
doCopyQueryResultToMsg
(
pQInfo
,
pQuery
->
rec
.
size
,
data
);
doCopyQueryResultToMsg
(
pQInfo
,
pQuery
->
rec
.
rows
,
data
);
}
}
pQuery
->
rec
.
total
+=
pQuery
->
rec
.
size
;
pQuery
->
rec
.
total
+=
pQuery
->
rec
.
rows
;
dTrace
(
"QInfo:%p current:%d, total:%d"
,
pQInfo
,
pQuery
->
rec
.
size
,
pQuery
->
rec
.
total
);
dTrace
(
"QInfo:%p current:%d, total:%d"
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -6020,9 +6019,9 @@ int32_t qCreateQueryInfo(void* tsdb, SQueryTableMsg *pQueryMsg, SQInfo **pQInfo)
...
@@ -6020,9 +6019,9 @@ int32_t qCreateQueryInfo(void* tsdb, SQueryTableMsg *pQueryMsg, SQInfo **pQInfo)
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
char
*
tagCond
=
NULL
;
SArray
*
pTableIdList
=
NULL
;
SArray
*
pTableIdList
=
NULL
;
SSqlFuncExprMsg
**
pExprMsg
=
NULL
;
SSqlFuncExprMsg
**
pExprMsg
=
NULL
;
wchar_t
*
tagCond
=
NULL
;
if
((
code
=
convertQueryMsg
(
pQueryMsg
,
&
pTableIdList
,
&
pExprMsg
,
&
tagCond
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
convertQueryMsg
(
pQueryMsg
,
&
pTableIdList
,
&
pExprMsg
,
&
tagCond
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
@@ -6050,21 +6049,23 @@ int32_t qCreateQueryInfo(void* tsdb, SQueryTableMsg *pQueryMsg, SQInfo **pQInfo)
...
@@ -6050,21 +6049,23 @@ int32_t qCreateQueryInfo(void* tsdb, SQueryTableMsg *pQueryMsg, SQInfo **pQInfo)
goto
_query_over
;
goto
_query_over
;
}
}
// super table query
SArray
*
res
=
NULL
;
bool
isSTableQuery
=
false
;
bool
isSTableQuery
=
false
;
SArray
*
res
=
NULL
;
if
((
pQueryMsg
->
queryType
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
!=
0
)
{
if
((
pQueryMsg
->
queryType
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
!=
0
)
{
isSTableQuery
=
true
;
isSTableQuery
=
true
;
STableId
*
id
=
taosArrayGet
(
pTableIdList
,
0
);
STableId
*
id
=
taosArrayGet
(
pTableIdList
,
0
);
id
->
uid
=
-
1
;
id
->
uid
=
-
1
;
res
=
tsdbQueryTableList
(
tsdb
,
id
->
uid
,
tagCond
,
pQueryMsg
->
tagCondLen
);
res
=
taosArrayInit
(
8
,
sizeof
(
STableId
));
/*int32_t ret =*/
tsdbQueryTags
(
tsdb
,
id
->
uid
,
tagCond
,
pQueryMsg
->
tagCondLen
,
res
);
if
(
taosArrayGetSize
(
res
)
==
0
)
{
// no qualified table in stable query in this vnode
if
(
taosArrayGetSize
(
res
)
==
0
)
{
// no qualified table in stable query in this vnode
code
=
TSDB_CODE_SUCCESS
;
code
=
TSDB_CODE_SUCCESS
;
goto
_query_over
;
goto
_query_over
;
}
}
}
else
{
}
else
{
assert
(
taosArrayGetSize
(
pTableIdList
)
==
1
);
res
=
pTableIdList
;
res
=
pTableIdList
;
}
}
...
@@ -6073,7 +6074,7 @@ int32_t qCreateQueryInfo(void* tsdb, SQueryTableMsg *pQueryMsg, SQInfo **pQInfo)
...
@@ -6073,7 +6074,7 @@ int32_t qCreateQueryInfo(void* tsdb, SQueryTableMsg *pQueryMsg, SQInfo **pQInfo)
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
}
code
=
init
ialize
QInfo
(
pQueryMsg
,
tsdb
,
*
pQInfo
,
isSTableQuery
);
code
=
initQInfo
(
pQueryMsg
,
tsdb
,
*
pQInfo
,
isSTableQuery
);
_query_over:
_query_over:
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -6116,11 +6117,10 @@ void qTableQuery(SQInfo *pQInfo) {
...
@@ -6116,11 +6117,10 @@ void qTableQuery(SQInfo *pQInfo) {
dTrace
(
"QInfo:%p query task is launched"
,
pQInfo
);
dTrace
(
"QInfo:%p query task is launched"
,
pQInfo
);
int32_t
numOfTables
=
taosArrayGetSize
(
pQInfo
->
pTableIdList
);
if
(
pQInfo
->
runtimeEnv
.
stableQuery
)
{
if
(
numOfTables
==
1
)
{
stableQueryImpl
(
pQInfo
);
singleTableQueryImpl
(
pQInfo
);
}
else
{
}
else
{
multiT
ableQueryImpl
(
pQInfo
);
t
ableQueryImpl
(
pQInfo
);
}
}
// vnodeDecRefCount(pQInfo);
// vnodeDecRefCount(pQInfo);
...
@@ -6138,7 +6138,7 @@ int32_t qRetrieveQueryResultInfo(SQInfo *pQInfo) {
...
@@ -6138,7 +6138,7 @@ int32_t qRetrieveQueryResultInfo(SQInfo *pQInfo) {
}
}
sem_wait
(
&
pQInfo
->
dataReady
);
sem_wait
(
&
pQInfo
->
dataReady
);
dTrace
(
"QInfo:%p retrieve result info, rowsize:%d, rows:%d, code:%d"
,
pQInfo
,
pQuery
->
rowSize
,
pQuery
->
rec
.
size
,
dTrace
(
"QInfo:%p retrieve result info, rowsize:%d, rows:%d, code:%d"
,
pQInfo
,
pQuery
->
rowSize
,
pQuery
->
rec
.
rows
,
pQInfo
->
code
);
pQInfo
->
code
);
return
pQInfo
->
code
;
return
pQInfo
->
code
;
...
@@ -6167,12 +6167,12 @@ int32_t qDumpRetrieveResult(SQInfo *pQInfo, SRetrieveTableRsp** pRsp, int32_t* c
...
@@ -6167,12 +6167,12 @@ int32_t qDumpRetrieveResult(SQInfo *pQInfo, SRetrieveTableRsp** pRsp, int32_t* c
}
}
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
size_t
size
=
getResultSize
(
pQInfo
,
&
pQuery
->
rec
.
size
);
size_t
size
=
getResultSize
(
pQInfo
,
&
pQuery
->
rec
.
rows
);
*
contLen
=
size
+
sizeof
(
SRetrieveTableRsp
);
*
contLen
=
size
+
sizeof
(
SRetrieveTableRsp
);
// todo handle failed to allocate memory
// todo handle failed to allocate memory
*
pRsp
=
(
SRetrieveTableRsp
*
)
rpcMallocCont
(
*
contLen
);
*
pRsp
=
(
SRetrieveTableRsp
*
)
rpcMallocCont
(
*
contLen
);
(
*
pRsp
)
->
numOfRows
=
htonl
(
pQuery
->
rec
.
size
);
(
*
pRsp
)
->
numOfRows
=
htonl
(
pQuery
->
rec
.
rows
);
int32_t
code
=
pQInfo
->
code
;
int32_t
code
=
pQInfo
->
code
;
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
code
==
TSDB_CODE_SUCCESS
)
{
...
@@ -6183,7 +6183,7 @@ int32_t qDumpRetrieveResult(SQInfo *pQInfo, SRetrieveTableRsp** pRsp, int32_t* c
...
@@ -6183,7 +6183,7 @@ int32_t qDumpRetrieveResult(SQInfo *pQInfo, SRetrieveTableRsp** pRsp, int32_t* c
(
*
pRsp
)
->
useconds
=
0
;
(
*
pRsp
)
->
useconds
=
0
;
}
}
if
(
pQuery
->
rec
.
size
>
0
&&
code
==
TSDB_CODE_SUCCESS
)
{
if
(
pQuery
->
rec
.
rows
>
0
&&
code
==
TSDB_CODE_SUCCESS
)
{
code
=
doDumpQueryResult
(
pQInfo
,
(
*
pRsp
)
->
data
);
code
=
doDumpQueryResult
(
pQInfo
,
(
*
pRsp
)
->
data
);
}
else
{
}
else
{
setQueryStatus
(
pQuery
,
QUERY_OVER
);
setQueryStatus
(
pQuery
,
QUERY_OVER
);
...
...
src/query/src/sql.c
浏览文件 @
3f9d5cca
...
@@ -2471,13 +2471,13 @@ static void yy_reduce(
...
@@ -2471,13 +2471,13 @@ static void yy_reduce(
yymsp
[
-
1
].
minor
.
yy380
=
yylhsminor
.
yy380
;
yymsp
[
-
1
].
minor
.
yy380
=
yylhsminor
.
yy380
;
break
;
break
;
case
152
:
/* sortorder ::= ASC */
case
152
:
/* sortorder ::= ASC */
{
yymsp
[
0
].
minor
.
yy250
=
TS
QL_SO
_ASC
;
}
{
yymsp
[
0
].
minor
.
yy250
=
TS
DB_ORDER
_ASC
;
}
break
;
break
;
case
153
:
/* sortorder ::= DESC */
case
153
:
/* sortorder ::= DESC */
{
yymsp
[
0
].
minor
.
yy250
=
TS
QL_SO
_DESC
;}
{
yymsp
[
0
].
minor
.
yy250
=
TS
DB_ORDER
_DESC
;}
break
;
break
;
case
154
:
/* sortorder ::= */
case
154
:
/* sortorder ::= */
{
yymsp
[
1
].
minor
.
yy250
=
TS
QL_SO
_ASC
;}
{
yymsp
[
1
].
minor
.
yy250
=
TS
DB_ORDER
_ASC
;}
break
;
break
;
case
157
:
/* grouplist ::= grouplist COMMA item */
case
157
:
/* grouplist ::= grouplist COMMA item */
{
{
...
...
src/util/inc/tcompare.h
0 → 100644
浏览文件 @
3f9d5cca
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_TCOMPARE_H
#define TDENGINE_TCOMPARE_H
#include "os.h"
int32_t
compareInt32Val
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt64Val
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt16Val
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8Val
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareIntDoubleVal
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareDoubleIntVal
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareDoubleVal
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrVal
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareWStrVal
(
const
void
*
pLeft
,
const
void
*
pRight
);
__compar_fn_t
getKeyComparFunc
(
int32_t
keyType
);
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
filterDataType
);
#endif // TDENGINE_TCOMPARE_H
src/util/src/tcompare.c
0 → 100644
浏览文件 @
3f9d5cca
#include "taosdef.h"
#include "tcompare.h"
int32_t
compareInt32Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
ret
=
GET_INT32_VAL
(
pLeft
)
-
GET_INT32_VAL
(
pRight
);
if
(
ret
==
0
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
int32_t
compareInt64Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
ret
=
GET_INT64_VAL
(
pLeft
)
-
GET_INT64_VAL
(
pRight
);
if
(
ret
==
0
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
int32_t
compareInt16Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
ret
=
GET_INT16_VAL
(
pLeft
)
-
GET_INT16_VAL
(
pRight
);
if
(
ret
==
0
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
int32_t
compareInt8Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
ret
=
GET_INT8_VAL
(
pLeft
)
-
GET_INT8_VAL
(
pRight
);
if
(
ret
==
0
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
int32_t
compareIntDoubleVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
// int64_t lhs = ((SSkipListKey *)pLeft)->i64Key;
// double rhs = ((SSkipListKey *)pRight)->dKey;
// if (fabs(lhs - rhs) < FLT_EPSILON) {
// return 0;
// } else {
// return (lhs > rhs) ? 1 : -1;
// }
return
0
;
}
int32_t
compareDoubleIntVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
// double lhs = ((SSkipListKey *)pLeft)->dKey;
// int64_t rhs = ((SSkipListKey *)pRight)->i64Key;
// if (fabs(lhs - rhs) < FLT_EPSILON) {
// return 0;
// } else {
// return (lhs > rhs) ? 1 : -1;
// }
return
0
;
}
int32_t
compareDoubleVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
double
ret
=
GET_DOUBLE_VAL
(
pLeft
)
-
GET_DOUBLE_VAL
(
pRight
);
if
(
fabs
(
ret
)
<
FLT_EPSILON
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
int32_t
compareStrVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
ret
=
strcmp
(
pLeft
,
pRight
);
if
(
ret
==
0
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
int32_t
compareWStrVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
// SSkipListKey *pL = (SSkipListKey *)pLeft;
// SSkipListKey *pR = (SSkipListKey *)pRight;
//
// if (pL->nLen == 0 && pR->nLen == 0) {
// return 0;
// }
//
// // handle only one-side bound compare situation, there is only lower bound or only upper bound
// if (pL->nLen == -1) {
// return 1; // no lower bound, lower bound is minimum, always return -1;
// } else if (pR->nLen == -1) {
// return -1; // no upper bound, upper bound is maximum situation, always return 1;
// }
//
// int32_t ret = wcscmp(((SSkipListKey *)pLeft)->wpz, ((SSkipListKey *)pRight)->wpz);
//
// if (ret == 0) {
// return 0;
// } else {
// return ret > 0 ? 1 : -1;
// }
return
0
;
}
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
filterDataType
)
{
__compar_fn_t
comparFn
=
NULL
;
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_BIGINT
:
{
if
(
filterDataType
==
TSDB_DATA_TYPE_BIGINT
)
{
comparFn
=
compareInt64Val
;
break
;
}
}
case
TSDB_DATA_TYPE_BOOL
:
{
if
(
filterDataType
>=
TSDB_DATA_TYPE_BOOL
&&
filterDataType
<=
TSDB_DATA_TYPE_BIGINT
)
{
comparFn
=
compareInt32Val
;
}
else
if
(
filterDataType
>=
TSDB_DATA_TYPE_FLOAT
&&
filterDataType
<=
TSDB_DATA_TYPE_DOUBLE
)
{
comparFn
=
compareIntDoubleVal
;
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
{
// if (filterDataType >= TSDB_DATA_TYPE_BOOL && filterDataType <= TSDB_DATA_TYPE_BIGINT) {
// comparFn = compareDoubleIntVal;
// } else if (filterDataType >= TSDB_DATA_TYPE_FLOAT && filterDataType <= TSDB_DATA_TYPE_DOUBLE) {
// comparFn = compareDoubleVal;
// }
if
(
filterDataType
==
TSDB_DATA_TYPE_DOUBLE
)
{
comparFn
=
compareDoubleVal
;
}
break
;
}
case
TSDB_DATA_TYPE_BINARY
:
comparFn
=
compareStrVal
;
break
;
case
TSDB_DATA_TYPE_NCHAR
:
comparFn
=
compareWStrVal
;
break
;
default:
comparFn
=
compareInt32Val
;
break
;
}
return
comparFn
;
}
__compar_fn_t
getKeyComparFunc
(
int32_t
keyType
)
{
__compar_fn_t
comparFn
=
NULL
;
switch
(
keyType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
comparFn
=
compareInt8Val
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
comparFn
=
compareInt16Val
;
break
;
case
TSDB_DATA_TYPE_INT
:
comparFn
=
compareInt32Val
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
comparFn
=
compareInt64Val
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
comparFn
=
compareInt32Val
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
comparFn
=
compareDoubleVal
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
comparFn
=
compareStrVal
;
break
;
case
TSDB_DATA_TYPE_NCHAR
:
comparFn
=
compareWStrVal
;
break
;
default:
comparFn
=
compareInt32Val
;
break
;
}
return
comparFn
;
}
src/vnode/tsdb/inc/tsdb.h
浏览文件 @
3f9d5cca
...
@@ -208,7 +208,7 @@ typedef struct SBlockInfo {
...
@@ -208,7 +208,7 @@ typedef struct SBlockInfo {
typedef
struct
SDataBlockInfo
{
typedef
struct
SDataBlockInfo
{
STimeWindow
window
;
STimeWindow
window
;
int32_t
size
;
int32_t
rows
;
int32_t
numOfCols
;
int32_t
numOfCols
;
int64_t
uid
;
int64_t
uid
;
int32_t
sid
;
int32_t
sid
;
...
@@ -335,7 +335,7 @@ SArray *tsdbGetTableList(tsdb_query_handle_t *pQueryHandle);
...
@@ -335,7 +335,7 @@ SArray *tsdbGetTableList(tsdb_query_handle_t *pQueryHandle);
* @param pTagCond. tag query condition
* @param pTagCond. tag query condition
*
*
*/
*/
SArray
*
tsdbQueryTableList
(
tsdb_repo_t
*
tsdb
,
int64_t
uid
,
const
wchar_t
*
pTagCond
,
size_t
len
);
int32_t
tsdbQueryTags
(
tsdb_repo_t
*
tsdb
,
int64_t
uid
,
const
char
*
pTagCond
,
size_t
len
,
SArray
*
list
);
/**
/**
* clean up the query handle
* clean up the query handle
...
...
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
3f9d5cca
...
@@ -6,9 +6,10 @@
...
@@ -6,9 +6,10 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <
sys/sendfile
.h>
#include <
tlog
.h>
#include <unistd.h>
#include <unistd.h>
// #include "taosdef.h"
// #include "taosdef.h"
...
@@ -738,6 +739,7 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlk *pBlock) {
...
@@ -738,6 +739,7 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlk *pBlock) {
STableId
tableId
=
{.
uid
=
pBlock
->
uid
,
.
tid
=
pBlock
->
tid
};
STableId
tableId
=
{.
uid
=
pBlock
->
uid
,
.
tid
=
pBlock
->
tid
};
STable
*
pTable
=
tsdbIsValidTableToInsert
(
pRepo
->
tsdbMeta
,
tableId
);
STable
*
pTable
=
tsdbIsValidTableToInsert
(
pRepo
->
tsdbMeta
,
tableId
);
if
(
pTable
==
NULL
)
{
if
(
pTable
==
NULL
)
{
dError
(
"failed to get table for insert, uid:%"
PRIu64
", tid:%d"
,
tableId
.
uid
,
tableId
.
tid
);
return
TSDB_CODE_INVALID_TABLE_ID
;
return
TSDB_CODE_INVALID_TABLE_ID
;
}
}
...
...
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
3f9d5cca
...
@@ -93,6 +93,11 @@ void tsdbFreeEncode(void *cont) {
...
@@ -93,6 +93,11 @@ void tsdbFreeEncode(void *cont) {
if
(
cont
!=
NULL
)
free
(
cont
);
if
(
cont
!=
NULL
)
free
(
cont
);
}
}
static
char
*
getTagIndexKey
(
const
void
*
pData
)
{
STable
*
table
=
*
(
STable
**
)
pData
;
return
getTupleKey
(
table
->
tagVal
);
}
int
tsdbRestoreTable
(
void
*
pHandle
,
void
*
cont
,
int
contLen
)
{
int
tsdbRestoreTable
(
void
*
pHandle
,
void
*
cont
,
int
contLen
)
{
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
pHandle
;
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
pHandle
;
...
@@ -101,7 +106,7 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
...
@@ -101,7 +106,7 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
pTable
->
pIndex
=
pTable
->
pIndex
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
1
,
0
,
0
,
getT
uple
Key
);
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
1
,
0
,
0
,
getT
agIndex
Key
);
}
}
tsdbAddTableToMeta
(
pMeta
,
pTable
,
false
);
tsdbAddTableToMeta
(
pMeta
,
pTable
,
false
);
...
@@ -218,7 +223,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
...
@@ -218,7 +223,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
super
->
tagSchema
=
tdDupSchema
(
pCfg
->
tagSchema
);
super
->
tagSchema
=
tdDupSchema
(
pCfg
->
tagSchema
);
super
->
tagVal
=
tdDataRowDup
(
pCfg
->
tagValues
);
super
->
tagVal
=
tdDataRowDup
(
pCfg
->
tagValues
);
super
->
pIndex
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
1
,
super
->
pIndex
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
1
,
0
,
0
,
getT
uple
Key
);
// Allow duplicate key, no lock
0
,
0
,
getT
agIndex
Key
);
// Allow duplicate key, no lock
if
(
super
->
pIndex
==
NULL
)
{
if
(
super
->
pIndex
==
NULL
)
{
tdFreeSchema
(
super
->
schema
);
tdFreeSchema
(
super
->
schema
);
...
@@ -403,8 +408,6 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) {
...
@@ -403,8 +408,6 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) {
pNode
->
level
=
level
;
pNode
->
level
=
level
;
SSkipList
*
list
=
pSTable
->
pIndex
;
SSkipList
*
list
=
pSTable
->
pIndex
;
memcpy
(
SL_GET_NODE_KEY
(
list
,
pNode
),
dataRowTuple
(
pTable
->
tagVal
),
colBytes
(
s
));
memcpy
(
SL_GET_NODE_DATA
(
pNode
),
&
pTable
,
POINTER_BYTES
);
memcpy
(
SL_GET_NODE_DATA
(
pNode
),
&
pTable
,
POINTER_BYTES
);
tSkipListPut
(
list
,
pNode
);
tSkipListPut
(
list
,
pNode
);
...
...
src/vnode/tsdb/src/tsdbRead.c
浏览文件 @
3f9d5cca
...
@@ -19,13 +19,14 @@
...
@@ -19,13 +19,14 @@
#include "tutil.h"
#include "tutil.h"
#include "../../../query/inc/qast.h"
#include "../../../query/inc/qast.h"
#include "../../../query/inc/tlosertree.h"
#include "../../../query/inc/tsqlfunction.h"
#include "../../../query/inc/tsqlfunction.h"
#include "tsdb.h"
#include "tsdb.h"
#include "tsdbMain.h"
#include "tsdbMain.h"
#define EXTRA_BYTES 2
#define EXTRA_BYTES 2
#define PRIMARY_TSCOL_REQUIRED(c) (((SColumnInfoEx
*)taosArrayGet(c, 0))->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)
#define PRIMARY_TSCOL_REQUIRED(c) (((SColumnInfoEx*)taosArrayGet(c, 0))->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)
#define QUERY_IS_ASC_QUERY(o) (o == TS
QL_SO
_ASC)
#define QUERY_IS_ASC_QUERY(o) (o == TS
DB_ORDER
_ASC)
#define QH_GET_NUM_OF_COLS(handle) (taosArrayGetSize((handle)->pColumns))
#define QH_GET_NUM_OF_COLS(handle) (taosArrayGetSize((handle)->pColumns))
enum
{
enum
{
...
@@ -48,7 +49,7 @@ typedef struct SDataBlockLoadInfo {
...
@@ -48,7 +49,7 @@ typedef struct SDataBlockLoadInfo {
SFileGroup
*
fileGroup
;
SFileGroup
*
fileGroup
;
int32_t
slot
;
int32_t
slot
;
int32_t
sid
;
int32_t
sid
;
SArray
*
pLoadedCols
;
SArray
*
pLoadedCols
;
}
SDataBlockLoadInfo
;
}
SDataBlockLoadInfo
;
typedef
struct
SLoadCompBlockInfo
{
typedef
struct
SLoadCompBlockInfo
{
...
@@ -57,52 +58,31 @@ typedef struct SLoadCompBlockInfo {
...
@@ -57,52 +58,31 @@ typedef struct SLoadCompBlockInfo {
int32_t
fileListIndex
;
int32_t
fileListIndex
;
}
SLoadCompBlockInfo
;
}
SLoadCompBlockInfo
;
typedef
struct
SQueryFilesInfo
{
SArray
*
pFileInfo
;
int32_t
current
;
// the memory mapped header file, NOTE: only one header file can be mmap.
int32_t
vnodeId
;
int32_t
headerFd
;
// header file fd
int64_t
headerFileSize
;
int32_t
dataFd
;
int32_t
lastFd
;
char
headerFilePath
[
PATH_MAX
];
// current opened header file name
char
dataFilePath
[
PATH_MAX
];
// current opened data file name
char
lastFilePath
[
PATH_MAX
];
// current opened last file path
char
dbFilePathPrefix
[
PATH_MAX
];
}
SQueryFilesInfo
;
typedef
struct
STableCheckInfo
{
typedef
struct
STableCheckInfo
{
STableId
tableId
;
STableId
tableId
;
TSKEY
lastKey
;
TSKEY
lastKey
;
STable
*
pTableObj
;
STable
*
pTableObj
;
int64_t
offsetInHeaderFile
;
int64_t
offsetInHeaderFile
;
// int32_t numOfBlocks;
int32_t
start
;
int32_t
start
;
bool
checkFirstFileBlock
;
bool
checkFirstFileBlock
;
SCompInfo
*
pCompInfo
;
SCompIdx
*
compIndex
;
int32_t
numOfBlocks
;
// number of qualified data blocks not the original blocks
SCompInfo
*
pCompInfo
;
SDataCols
*
pDataCols
;
SDataCols
*
pDataCols
;
SFileGroup
*
pFileGroup
;
SFileGroupIter
fileIter
;
SSkipListIterator
*
iter
;
SSkipListIterator
*
iter
;
}
STableCheckInfo
;
}
STableCheckInfo
;
typedef
struct
{
typedef
struct
{
SCompBlock
*
compBlock
;
SCompBlock
*
compBlock
;
SField
*
fields
;
SField
*
fields
;
}
SCompBlockFields
;
}
SCompBlockFields
;
typedef
struct
STable
DataBlockInfoEx
{
typedef
struct
STable
BlockInfo
{
SCompBlockFields
pBlock
;
SCompBlockFields
pBlock
;
STableCheckInfo
*
p
MeterData
Info
;
STableCheckInfo
*
p
TableCheck
Info
;
int32_t
blockIndex
;
int32_t
blockIndex
;
int32_t
groupIdx
;
/* number of group is less than the total number of
meter
s */
int32_t
groupIdx
;
/* number of group is less than the total number of
table
s */
}
STable
DataBlockInfoEx
;
}
STable
BlockInfo
;
enum
{
enum
{
SINGLE_TABLE_MODEL
=
1
,
SINGLE_TABLE_MODEL
=
1
,
...
@@ -114,13 +94,9 @@ typedef struct STsdbQueryHandle {
...
@@ -114,13 +94,9 @@ typedef struct STsdbQueryHandle {
int8_t
model
;
// access model, single table model or multi-table model
int8_t
model
;
// access model, single table model or multi-table model
SQueryFilePos
cur
;
// current position
SQueryFilePos
cur
;
// current position
SQueryFilePos
start
;
// the start position, used for secondary/third iteration
SQueryFilePos
start
;
// the start position, used for secondary/third iteration
int32_t
unzipBufSize
;
char
*
unzipBuffer
;
char
*
secondaryUnzipBuffer
;
SDataBlockLoadInfo
dataBlockLoadInfo
;
/* record current block load information */
SDataBlockLoadInfo
dataBlockLoadInfo
;
/* record current block load information */
SLoadCompBlockInfo
compBlockLoadInfo
;
/* record current compblock information in SQuery */
SLoadCompBlockInfo
compBlockLoadInfo
;
/* record current compblock information in SQuery */
SQueryFilesInfo
vnodeFileInfo
;
int16_t
numOfRowsPerPage
;
int16_t
numOfRowsPerPage
;
uint16_t
flag
;
// denotes reversed scan of data or not
uint16_t
flag
;
// denotes reversed scan of data or not
...
@@ -129,24 +105,29 @@ typedef struct STsdbQueryHandle {
...
@@ -129,24 +105,29 @@ typedef struct STsdbQueryHandle {
int32_t
blockBufferSize
;
int32_t
blockBufferSize
;
SCompBlock
*
pBlock
;
SCompBlock
*
pBlock
;
int32_t
numOfBlocks
;
int32_t
numOfBlocks
;
SField
**
pFields
;
SField
**
pFields
;
SArray
*
pColumns
;
// column list, SColumnInfoEx array list
SArray
*
pColumns
;
// column list, SColumnInfoEx array list
bool
locateStart
;
bool
locateStart
;
int32_t
realNumOfRows
;
int32_t
realNumOfRows
;
bool
loadDataAfterSeek
;
// load data after seek.
bool
loadDataAfterSeek
;
// load data after seek.
SArray
*
pTableCheckInfo
;
SArray
*
pTableCheckInfo
;
int32_t
activeIndex
;
int32_t
activeIndex
;
bool
checkFiles
;
// check file stage
int32_t
tableIndex
;
int32_t
tableIndex
;
bool
isFirstSlot
;
bool
isFirstSlot
;
void
*
qinfo
;
// query info handle, for debug purpose
void
*
qinfo
;
// query info handle, for debug purpose
STableBlockInfo
*
pDataBlockInfo
;
STableDataBlockInfoEx
*
pDataBlockInfoEx
;
SFileGroup
*
pFileGroup
;
SFileGroupIter
fileIter
;
SCompIdx
*
compIndex
;
}
STsdbQueryHandle
;
}
STsdbQueryHandle
;
int32_t
doAllocateBuf
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
rowsPerFileBlock
)
{
int32_t
doAllocateBuf
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
rowsPerFileBlock
)
{
// record the maximum column width among columns of this meter/metric
// record the maximum column width among columns of this meter/metric
SColumnInfoEx
*
pColumn
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
0
);
SColumnInfoEx
*
pColumn
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
0
);
int32_t
maxColWidth
=
pColumn
->
info
.
bytes
;
int32_t
maxColWidth
=
pColumn
->
info
.
bytes
;
for
(
int32_t
i
=
1
;
i
<
QH_GET_NUM_OF_COLS
(
pQueryHandle
);
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
QH_GET_NUM_OF_COLS
(
pQueryHandle
);
++
i
)
{
...
@@ -156,55 +137,31 @@ int32_t doAllocateBuf(STsdbQueryHandle *pQueryHandle, int32_t rowsPerFileBlock)
...
@@ -156,55 +137,31 @@ int32_t doAllocateBuf(STsdbQueryHandle *pQueryHandle, int32_t rowsPerFileBlock)
}
}
}
}
// only one unzip buffer required, since we can unzip each column one by one
pQueryHandle
->
unzipBufSize
=
(
size_t
)(
maxColWidth
*
rowsPerFileBlock
+
EXTRA_BYTES
);
// plus extra_bytes
pQueryHandle
->
unzipBuffer
=
(
char
*
)
calloc
(
1
,
pQueryHandle
->
unzipBufSize
);
pQueryHandle
->
secondaryUnzipBuffer
=
(
char
*
)
calloc
(
1
,
pQueryHandle
->
unzipBufSize
);
if
(
pQueryHandle
->
unzipBuffer
==
NULL
||
pQueryHandle
->
secondaryUnzipBuffer
==
NULL
)
{
goto
_error_clean
;
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_error_clean:
tfree
(
pQueryHandle
->
unzipBuffer
);
tfree
(
pQueryHandle
->
secondaryUnzipBuffer
);
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
}
static
void
initQueryFileInfoFD
(
SQueryFilesInfo
*
pVnodeFilesInfo
)
{
static
void
tsdbInitDataBlockLoadInfo
(
SDataBlockLoadInfo
*
pBlockLoadInfo
)
{
pVnodeFilesInfo
->
current
=
-
1
;
pVnodeFilesInfo
->
headerFileSize
=
-
1
;
pVnodeFilesInfo
->
headerFd
=
FD_INITIALIZER
;
// set the initial value
pVnodeFilesInfo
->
dataFd
=
FD_INITIALIZER
;
pVnodeFilesInfo
->
lastFd
=
FD_INITIALIZER
;
}
static
void
vnodeInitDataBlockLoadInfo
(
SDataBlockLoadInfo
*
pBlockLoadInfo
)
{
pBlockLoadInfo
->
slot
=
-
1
;
pBlockLoadInfo
->
slot
=
-
1
;
pBlockLoadInfo
->
sid
=
-
1
;
pBlockLoadInfo
->
sid
=
-
1
;
pBlockLoadInfo
->
fileGroup
=
NULL
;
pBlockLoadInfo
->
fileGroup
=
NULL
;
}
}
static
void
vnodeInitCompBlockLoadInfo
(
SLoadCompBlockInfo
*
pCompBlockLoadInfo
)
{
static
void
tsdbInitCompBlockLoadInfo
(
SLoadCompBlockInfo
*
pCompBlockLoadInfo
)
{
pCompBlockLoadInfo
->
sid
=
-
1
;
pCompBlockLoadInfo
->
sid
=
-
1
;
pCompBlockLoadInfo
->
fileId
=
-
1
;
pCompBlockLoadInfo
->
fileId
=
-
1
;
pCompBlockLoadInfo
->
fileListIndex
=
-
1
;
pCompBlockLoadInfo
->
fileListIndex
=
-
1
;
}
}
tsdb_query_handle_t
*
tsdbQueryByTableId
(
tsdb_repo_t
*
tsdb
,
STsdbQueryCond
*
pCond
,
SArray
*
idList
,
SArray
*
pColumnInfo
)
{
tsdb_query_handle_t
*
tsdbQueryByTableId
(
tsdb_repo_t
*
tsdb
,
STsdbQueryCond
*
pCond
,
SArray
*
idList
,
SArray
*
pColumnInfo
)
{
// todo 1. filter not exist table
// todo 1. filter not exist table
// todo 2. add the reference count for each table that is involved in query
// todo 2. add the reference count for each table that is involved in query
STsdbQueryHandle
*
pQueryHandle
=
calloc
(
1
,
sizeof
(
STsdbQueryHandle
));
STsdbQueryHandle
*
pQueryHandle
=
calloc
(
1
,
sizeof
(
STsdbQueryHandle
));
pQueryHandle
->
order
=
pCond
->
order
;
pQueryHandle
->
order
=
pCond
->
order
;
pQueryHandle
->
window
=
pCond
->
twindow
;
pQueryHandle
->
window
=
pCond
->
twindow
;
pQueryHandle
->
pTsdb
=
tsdb
;
pQueryHandle
->
pTsdb
=
tsdb
;
pQueryHandle
->
compIndex
=
calloc
(
10000
,
sizeof
(
SCompIdx
)),
pQueryHandle
->
loadDataAfterSeek
=
false
;
pQueryHandle
->
loadDataAfterSeek
=
false
;
pQueryHandle
->
isFirstSlot
=
true
;
pQueryHandle
->
isFirstSlot
=
true
;
...
@@ -213,14 +170,13 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
...
@@ -213,14 +170,13 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
assert
(
size
>=
1
);
assert
(
size
>=
1
);
pQueryHandle
->
pTableCheckInfo
=
taosArrayInit
(
size
,
sizeof
(
STableCheckInfo
));
pQueryHandle
->
pTableCheckInfo
=
taosArrayInit
(
size
,
sizeof
(
STableCheckInfo
));
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableId
id
=
*
(
STableId
*
)
taosArrayGet
(
idList
,
i
);
STableId
id
=
*
(
STableId
*
)
taosArrayGet
(
idList
,
i
);
STableCheckInfo
info
=
{
STableCheckInfo
info
=
{
.
lastKey
=
pQueryHandle
->
window
.
skey
,
.
lastKey
=
pQueryHandle
->
window
.
skey
,
.
tableId
=
id
,
.
tableId
=
id
,
.
pTableObj
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
id
.
uid
),
//todo this may be failed
.
pTableObj
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
id
.
uid
),
// todo this may be failed
.
compIndex
=
calloc
(
10000
,
sizeof
(
SCompIdx
)),
.
pCompInfo
=
calloc
(
1
,
1024
),
.
pCompInfo
=
calloc
(
1
,
1024
),
};
};
...
@@ -228,7 +184,8 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
...
@@ -228,7 +184,8 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
taosArrayPush
(
pQueryHandle
->
pTableCheckInfo
,
&
info
);
taosArrayPush
(
pQueryHandle
->
pTableCheckInfo
,
&
info
);
}
}
pQueryHandle
->
model
=
(
size
>
1
)
?
MULTI_TABLE_MODEL
:
SINGLE_TABLE_MODEL
;
pQueryHandle
->
model
=
(
size
>
1
)
?
MULTI_TABLE_MODEL
:
SINGLE_TABLE_MODEL
;
pQueryHandle
->
checkFiles
=
1
;
pQueryHandle
->
activeIndex
=
0
;
pQueryHandle
->
activeIndex
=
0
;
...
@@ -238,7 +195,7 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
...
@@ -238,7 +195,7 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
pQueryHandle
->
pColumns
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumnInfoEx
));
pQueryHandle
->
pColumns
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumnInfoEx
));
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoEx
*
pCol
=
taosArrayGet
(
pColumnInfo
,
i
);
SColumnInfoEx
*
pCol
=
taosArrayGet
(
pColumnInfo
,
i
);
SColumnInfoEx
pDest
=
{{
0
},
0
};
SColumnInfoEx
pDest
=
{{
0
},
0
};
pDest
.
pData
=
calloc
(
1
,
EXTRA_BYTES
+
bufferCapacity
*
pCol
->
info
.
bytes
);
pDest
.
pData
=
calloc
(
1
,
EXTRA_BYTES
+
bufferCapacity
*
pCol
->
info
.
bytes
);
...
@@ -250,19 +207,18 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
...
@@ -250,19 +207,18 @@ tsdb_query_handle_t *tsdbQueryByTableId(tsdb_repo_t* tsdb, STsdbQueryCond *pCond
return
NULL
;
return
NULL
;
}
}
initQueryFileInfoFD
(
&
pQueryHandle
->
vnodeFileInfo
);
tsdbInitDataBlockLoadInfo
(
&
pQueryHandle
->
dataBlockLoadInfo
);
vnodeInitDataBlockLoadInfo
(
&
pQueryHandle
->
dataBlockLoadInfo
);
tsdbInitCompBlockLoadInfo
(
&
pQueryHandle
->
compBlockLoadInfo
);
vnodeInitCompBlockLoadInfo
(
&
pQueryHandle
->
compBlockLoadInfo
);
return
(
tsdb_query_handle_t
)
pQueryHandle
;
return
(
tsdb_query_handle_t
)
pQueryHandle
;
}
}
static
bool
hasMoreDataInCache
ForSingleModel
(
STsdbQueryHandle
*
pHandle
)
{
static
bool
hasMoreDataInCache
(
STsdbQueryHandle
*
pHandle
)
{
assert
(
pHandle
->
activeIndex
==
0
&&
taosArrayGetSize
(
pHandle
->
pTableCheckInfo
)
==
1
);
assert
(
pHandle
->
activeIndex
==
0
&&
taosArrayGetSize
(
pHandle
->
pTableCheckInfo
)
==
1
);
STableCheckInfo
*
pTableCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
STableCheckInfo
*
pTableCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
STable
*
pTable
=
pTableCheckInfo
->
pTableObj
;
STable
*
pTable
=
pTableCheckInfo
->
pTableObj
;
assert
(
pTable
!=
NULL
);
assert
(
pTable
!=
NULL
);
// no data in cache, abort
// no data in cache, abort
...
@@ -283,25 +239,74 @@ static int32_t getFileIdFromKey(TSKEY key) {
...
@@ -283,25 +239,74 @@ static int32_t getFileIdFromKey(TSKEY key) {
return
(
int32_t
)(
key
/
10
);
// set the starting fileId
return
(
int32_t
)(
key
/
10
);
// set the starting fileId
}
}
static
int32_t
getFileCompInfo
(
STableCheckInfo
*
pCheckInfo
,
SFileGroup
*
fileGroup
)
{
static
int32_t
binarySearchForBlockImpl
(
SCompBlock
*
pBlock
,
int32_t
numOfBlocks
,
TSKEY
skey
,
int32_t
order
);
// check open file failed
static
int32_t
getFileCompInfo
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
*
numOfBlocks
,
int32_t
type
)
{
// todo check open file failed
SFileGroup
*
fileGroup
=
pQueryHandle
->
pFileGroup
;
if
(
fileGroup
->
files
[
TSDB_FILE_TYPE_HEAD
].
fd
==
FD_INITIALIZER
)
{
if
(
fileGroup
->
files
[
TSDB_FILE_TYPE_HEAD
].
fd
==
FD_INITIALIZER
)
{
fileGroup
->
files
[
TSDB_FILE_TYPE_HEAD
].
fd
=
open
(
fileGroup
->
files
[
TSDB_FILE_TYPE_HEAD
].
fname
,
O_RDONLY
);
fileGroup
->
files
[
TSDB_FILE_TYPE_HEAD
].
fd
=
open
(
fileGroup
->
files
[
TSDB_FILE_TYPE_HEAD
].
fname
,
O_RDONLY
);
}
}
tsdbLoadCompIdx
(
fileGroup
,
pCheckInfo
->
compIndex
,
10000
);
// todo set dynamic max tables
// load all the comp offset value for all tables in this file
SCompIdx
*
compIndex
=
&
pCheckInfo
->
compIndex
[
pCheckInfo
->
tableId
.
tid
];
tsdbLoadCompIdx
(
fileGroup
,
pQueryHandle
->
compIndex
,
10000
);
// todo set dynamic max tables
*
numOfBlocks
=
0
;
size_t
numOfTables
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfTables
;
++
i
)
{
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
SCompIdx
*
compIndex
=
&
pQueryHandle
->
compIndex
[
pCheckInfo
->
tableId
.
tid
];
if
(
compIndex
->
len
==
0
||
compIndex
->
numOfSuperBlocks
==
0
)
{
// no data block in this file, try next file
if
(
compIndex
->
len
==
0
||
compIndex
->
numOfSuperBlocks
==
0
)
{
// no data block in this file, try next file
}
else
{
}
else
{
tsdbLoadCompBlocks
(
fileGroup
,
compIndex
,
pCheckInfo
->
pCompInfo
);
tsdbLoadCompBlocks
(
fileGroup
,
compIndex
,
pCheckInfo
->
pCompInfo
);
int32_t
index
=
0
;
// discard the unqualified data block based on the query time window
int32_t
start
=
binarySearchForBlockImpl
(
pCheckInfo
->
pCompInfo
->
blocks
,
compIndex
->
numOfSuperBlocks
,
pQueryHandle
->
order
,
pCheckInfo
->
lastKey
);
if
(
type
==
QUERY_RANGE_GREATER_EQUAL
)
{
if
(
pCheckInfo
->
lastKey
<=
pCheckInfo
->
pCompInfo
->
blocks
[
start
].
keyLast
)
{
// break;
}
else
{
index
=
-
1
;
}
}
else
{
if
(
pCheckInfo
->
lastKey
>=
pCheckInfo
->
pCompInfo
->
blocks
[
start
].
keyFirst
)
{
// break;
}
else
{
index
=
-
1
;
}
}
// not found in data blocks in current file
if
(
index
==
-
1
)
{
continue
;
}
// todo speedup the procedure of locating end block
int32_t
e
=
start
;
while
(
e
<
compIndex
->
numOfSuperBlocks
&&
(
pCheckInfo
->
pCompInfo
->
blocks
[
e
].
keyFirst
<=
pQueryHandle
->
window
.
ekey
))
{
e
+=
1
;
}
if
(
start
>
0
)
{
memmove
(
pCheckInfo
->
pCompInfo
->
blocks
,
&
pCheckInfo
->
pCompInfo
->
blocks
[
start
],
(
e
-
start
)
*
sizeof
(
SCompBlock
));
}
pCheckInfo
->
numOfBlocks
=
(
e
-
start
);
(
*
numOfBlocks
)
+=
pCheckInfo
->
numOfBlocks
;
}
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
binarySearchForBlockImpl
(
SCompBlock
*
pBlock
,
int32_t
numOfBlocks
,
TSKEY
skey
,
int32_t
order
)
{
int32_t
binarySearchForBlockImpl
(
SCompBlock
*
pBlock
,
int32_t
numOfBlocks
,
TSKEY
skey
,
int32_t
order
)
{
int32_t
firstSlot
=
0
;
int32_t
firstSlot
=
0
;
int32_t
lastSlot
=
numOfBlocks
-
1
;
int32_t
lastSlot
=
numOfBlocks
-
1
;
...
@@ -315,10 +320,10 @@ static int32_t binarySearchForBlockImpl(SCompBlock *pBlock, int32_t numOfBlocks,
...
@@ -315,10 +320,10 @@ static int32_t binarySearchForBlockImpl(SCompBlock *pBlock, int32_t numOfBlocks,
if
(
skey
>
pBlock
[
midSlot
].
keyLast
)
{
if
(
skey
>
pBlock
[
midSlot
].
keyLast
)
{
if
(
numOfBlocks
==
2
)
break
;
if
(
numOfBlocks
==
2
)
break
;
if
((
order
==
TS
QL_SO
_DESC
)
&&
(
skey
<
pBlock
[
midSlot
+
1
].
keyFirst
))
break
;
if
((
order
==
TS
DB_ORDER
_DESC
)
&&
(
skey
<
pBlock
[
midSlot
+
1
].
keyFirst
))
break
;
firstSlot
=
midSlot
+
1
;
firstSlot
=
midSlot
+
1
;
}
else
if
(
skey
<
pBlock
[
midSlot
].
keyFirst
)
{
}
else
if
(
skey
<
pBlock
[
midSlot
].
keyFirst
)
{
if
((
order
==
TS
QL_SO
_ASC
)
&&
(
skey
>
pBlock
[
midSlot
-
1
].
keyLast
))
break
;
if
((
order
==
TS
DB_ORDER
_ASC
)
&&
(
skey
>
pBlock
[
midSlot
-
1
].
keyLast
))
break
;
lastSlot
=
midSlot
-
1
;
lastSlot
=
midSlot
-
1
;
}
else
{
}
else
{
break
;
// got the slot
break
;
// got the slot
...
@@ -328,13 +333,11 @@ static int32_t binarySearchForBlockImpl(SCompBlock *pBlock, int32_t numOfBlocks,
...
@@ -328,13 +333,11 @@ static int32_t binarySearchForBlockImpl(SCompBlock *pBlock, int32_t numOfBlocks,
return
midSlot
;
return
midSlot
;
}
}
static
SDataBlockInfo
getTrueDataBlockInfo
(
STsdbQueryHandle
*
pHandle
,
STableCheckInfo
*
pCheckInfo
)
{
static
SDataBlockInfo
getTrueDataBlockInfo
(
STableCheckInfo
*
pCheckInfo
,
SCompBlock
*
pBlock
)
{
SCompBlock
*
pDiskBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
pHandle
->
cur
.
slot
];
SDataBlockInfo
info
=
{
SDataBlockInfo
info
=
{
.
window
=
{.
skey
=
pDiskBlock
->
keyFirst
,
.
ekey
=
pDisk
Block
->
keyLast
},
.
window
=
{.
skey
=
pBlock
->
keyFirst
,
.
ekey
=
p
Block
->
keyLast
},
.
numOfCols
=
p
Disk
Block
->
numOfCols
,
.
numOfCols
=
pBlock
->
numOfCols
,
.
size
=
pDisk
Block
->
numOfPoints
,
.
rows
=
p
Block
->
numOfPoints
,
.
sid
=
pCheckInfo
->
tableId
.
tid
,
.
sid
=
pCheckInfo
->
tableId
.
tid
,
.
uid
=
pCheckInfo
->
tableId
.
uid
,
.
uid
=
pCheckInfo
->
tableId
.
uid
,
};
};
...
@@ -342,50 +345,76 @@ static SDataBlockInfo getTrueDataBlockInfo(STsdbQueryHandle* pHandle, STableChec
...
@@ -342,50 +345,76 @@ static SDataBlockInfo getTrueDataBlockInfo(STsdbQueryHandle* pHandle, STableChec
return
info
;
return
info
;
}
}
SArray
*
getDefaultLoadColumns
(
STsdbQueryHandle
*
pQueryHandle
,
bool
loadTS
);
SArray
*
getDefaultLoadColumns
(
STsdbQueryHandle
*
pQueryHandle
,
bool
loadTS
);
static
void
filterDataInDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
SDataCols
*
pCols
,
SArray
*
sa
);
static
void
filterDataInDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
STableCheckInfo
*
pCheckInfo
,
SCompBlock
*
pBlock
,
SArray
*
sa
);
static
bool
doLoadDataFromFileBlock
(
STsdbQueryHandle
*
pQueryHandle
)
{
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
pQueryHandle
->
activeIndex
);
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
SCompData
*
data
=
calloc
(
1
,
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pBlock
->
numOfCols
);
static
bool
doLoadFileDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
SCompBlock
*
pBlock
,
STableCheckInfo
*
pCheckInfo
)
{
SCompData
*
data
=
calloc
(
1
,
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pBlock
->
numOfCols
);
data
->
numOfCols
=
pBlock
->
numOfCols
;
data
->
numOfCols
=
pBlock
->
numOfCols
;
data
->
uid
=
pCheckInfo
->
pTableObj
->
tableId
.
uid
;
data
->
uid
=
pCheckInfo
->
pTableObj
->
tableId
.
uid
;
bool
blockLoaded
=
false
;
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
if
(
pCheckInfo
->
pDataCols
==
NULL
)
{
pCheckInfo
->
pDataCols
=
tdNewDataCols
(
1000
,
2
,
4096
);
pCheckInfo
->
pDataCols
=
tdNewDataCols
(
1000
,
2
,
4096
);
tdInitDataCols
(
pCheckInfo
->
pDataCols
,
pCheckInfo
->
pTableObj
->
schema
);
}
tdInitDataCols
(
pCheckInfo
->
pDataCols
,
tsdbGetTableSchema
(
tsdbGetMeta
(
pQueryHandle
->
pTsdb
),
pCheckInfo
->
pTableObj
));
SFile
*
pFile
=
&
p
CheckInfo
->
pFileGroup
->
files
[
TSDB_FILE_TYPE_DATA
];
SFile
*
pFile
=
&
p
QueryHandle
->
pFileGroup
->
files
[
TSDB_FILE_TYPE_DATA
];
if
(
pFile
->
fd
==
FD_INITIALIZER
)
{
if
(
pFile
->
fd
==
FD_INITIALIZER
)
{
pFile
->
fd
=
open
(
pFile
->
fname
,
O_RDONLY
);
pFile
->
fd
=
open
(
pFile
->
fname
,
O_RDONLY
);
}
}
tsdbLoadDataBlock
(
pFile
,
pBlock
,
1
,
pCheckInfo
->
pDataCols
,
data
);
if
(
tsdbLoadDataBlock
(
pFile
,
pBlock
,
1
,
pCheckInfo
->
pDataCols
,
data
)
==
0
)
{
return
true
;
SDataBlockLoadInfo
*
pBlockLoadInfo
=
&
pQueryHandle
->
dataBlockLoadInfo
;
}
static
bool
loadQualifiedDataFromFileBlock
(
STsdbQueryHandle
*
pQueryHandle
)
{
pBlockLoadInfo
->
fileGroup
=
pQueryHandle
->
pFileGroup
;
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
pBlockLoadInfo
->
slot
=
pQueryHandle
->
cur
.
slot
;
pBlockLoadInfo
->
sid
=
pCheckInfo
->
pTableObj
->
tableId
.
tid
;
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
pQueryHandle
->
activeIndex
);
blockLoaded
=
true
;
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
}
taosArrayDestroy
(
sa
);
tfree
(
data
);
TSKEY
*
d
=
(
TSKEY
*
)
pCheckInfo
->
pDataCols
->
cols
[
PRIMARYKEY_TIMESTAMP_COL_INDEX
].
pData
;
assert
(
d
[
0
]
==
pBlock
->
keyFirst
&&
d
[
pBlock
->
numOfPoints
-
1
]
==
pBlock
->
keyLast
);
return
blockLoaded
;
}
static
bool
loadFileDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
SCompBlock
*
pBlock
,
STableCheckInfo
*
pCheckInfo
)
{
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
))
{
// query ended in current block
// query ended in current block
if
(
pQueryHandle
->
window
.
ekey
<
pBlock
->
keyLast
)
{
if
(
pQueryHandle
->
window
.
ekey
<
pBlock
->
keyLast
)
{
doLoadDataFromFileBlock
(
pQueryHandle
);
if
(
!
doLoadFileDataBlock
(
pQueryHandle
,
pBlock
,
pCheckInfo
))
{
filterDataInDataBlock
(
pQueryHandle
,
pCheckInfo
->
pDataCols
,
sa
);
return
false
;
}
SDataCols
*
pDataCols
=
pCheckInfo
->
pDataCols
;
if
(
pCheckInfo
->
lastKey
>
pBlock
->
keyFirst
)
{
cur
->
pos
=
binarySearchForKey
(
pDataCols
->
cols
[
0
].
pData
,
pBlock
->
numOfPoints
,
pCheckInfo
->
lastKey
,
pQueryHandle
->
order
);
}
else
{
cur
->
pos
=
0
;
}
filterDataInDataBlock
(
pQueryHandle
,
pCheckInfo
,
pBlock
,
sa
);
}
else
{
// the whole block is loaded in to buffer
}
else
{
// the whole block is loaded in to buffer
pQueryHandle
->
realNumOfRows
=
pBlock
->
numOfPoints
;
pQueryHandle
->
realNumOfRows
=
pBlock
->
numOfPoints
;
}
}
}
else
{
// todo desc query
}
else
{
// todo desc query
if
(
pQueryHandle
->
window
.
ekey
>
pBlock
->
keyFirst
)
{
if
(
pQueryHandle
->
window
.
ekey
>
pBlock
->
keyFirst
)
{
//
}
}
}
}
...
@@ -393,8 +422,8 @@ static bool loadQualifiedDataFromFileBlock(STsdbQueryHandle *pQueryHandle) {
...
@@ -393,8 +422,8 @@ static bool loadQualifiedDataFromFileBlock(STsdbQueryHandle *pQueryHandle) {
return
pQueryHandle
->
realNumOfRows
>
0
;
return
pQueryHandle
->
realNumOfRows
>
0
;
}
}
bool
moveToNextBlock
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
step
)
{
bool
moveToNextBlock
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
step
)
{
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
if
(
pQueryHandle
->
cur
.
fid
>=
0
)
{
if
(
pQueryHandle
->
cur
.
fid
>=
0
)
{
/*
/*
...
@@ -405,61 +434,57 @@ bool moveToNextBlock(STsdbQueryHandle *pQueryHandle, int32_t step) {
...
@@ -405,61 +434,57 @@ bool moveToNextBlock(STsdbQueryHandle *pQueryHandle, int32_t step) {
int32_t
tid
=
pCheckInfo
->
tableId
.
tid
;
int32_t
tid
=
pCheckInfo
->
tableId
.
tid
;
if
((
step
==
QUERY_ASC_FORWARD_STEP
&&
if
((
step
==
QUERY_ASC_FORWARD_STEP
&&
(
pQueryHandle
->
cur
.
slot
==
p
CheckInfo
->
compIndex
[
tid
].
numOfSuperBlocks
-
1
))
||
(
pQueryHandle
->
cur
.
slot
==
p
QueryHandle
->
compIndex
[
tid
].
numOfSuperBlocks
-
1
))
||
(
step
==
QUERY_DESC_FORWARD_STEP
&&
(
pQueryHandle
->
cur
.
slot
==
0
)))
{
(
step
==
QUERY_DESC_FORWARD_STEP
&&
(
pQueryHandle
->
cur
.
slot
==
0
)))
{
// temporarily keep the position value, in case of no data qualified when move forwards(backwards)
// temporarily keep the position value, in case of no data qualified when move forwards(backwards)
// SQueryFilePos save = pQueryHandle->cur;
// SQueryFilePos save = pQueryHandle->cur;
SFileGroup
*
fgroup
=
tsdbGetFileGroupNext
(
&
pCheckInfo
->
fileIter
);
pQueryHandle
->
pFileGroup
=
tsdbGetFileGroupNext
(
&
pQueryHandle
->
fileIter
);
int32_t
fid
=
-
1
;
int32_t
fid
=
-
1
;
if
(
fgroup
!=
NULL
)
{
int32_t
numOfBlocks
=
0
;
if
((
fid
=
getFileCompInfo
(
pCheckInfo
,
fgroup
))
<
0
)
{
if
(
pQueryHandle
->
pFileGroup
!=
NULL
)
{
if
((
fid
=
getFileCompInfo
(
pQueryHandle
,
&
numOfBlocks
,
1
))
<
0
)
{
}
else
{
}
else
{
cur
->
slot
=
(
step
==
QUERY_ASC_FORWARD_STEP
)
?
0
:
pQueryHandle
->
numOfBlocks
-
1
;
cur
->
slot
=
(
step
==
QUERY_ASC_FORWARD_STEP
)
?
0
:
pQueryHandle
->
numOfBlocks
-
1
;
cur
->
pos
=
(
step
==
QUERY_ASC_FORWARD_STEP
)
?
0
:
pQueryHandle
->
pBlock
[
cur
->
slot
].
numOfPoints
-
1
;
cur
->
pos
=
(
step
==
QUERY_ASC_FORWARD_STEP
)
?
0
:
pQueryHandle
->
pBlock
[
cur
->
slot
].
numOfPoints
-
1
;
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
SCompData
*
data
=
calloc
(
1
,
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pBlock
->
numOfCols
);
cur
->
fid
=
pQueryHandle
->
pFileGroup
->
fileId
;
data
->
numOfCols
=
pBlock
->
numOfCols
;
data
->
uid
=
pCheckInfo
->
pTableObj
->
tableId
.
uid
;
cur
->
fid
=
fgroup
->
fileId
;
assert
(
cur
->
pos
>=
0
&&
cur
->
fid
>=
0
&&
cur
->
slot
>=
0
);
assert
(
cur
->
pos
>=
0
&&
cur
->
fid
>=
0
&&
cur
->
slot
>=
0
);
if
(
pBlock
->
keyFirst
>
pQueryHandle
->
window
.
ekey
)
{
// done
if
(
pBlock
->
keyFirst
>
pQueryHandle
->
window
.
ekey
)
{
// done
return
false
;
return
false
;
}
}
loadQualifiedDataFromFileBlock
(
pQueryHandle
);
return
loadFileDataBlock
(
pQueryHandle
,
pBlock
,
pCheckInfo
);
return
true
;
}
}
}
else
{
// check data in cache
}
else
{
// check data in cache
pQueryHandle
->
cur
.
fid
=
-
1
;
pQueryHandle
->
cur
.
fid
=
-
1
;
return
hasMoreDataInCache
ForSingleModel
(
pQueryHandle
);
return
hasMoreDataInCache
(
pQueryHandle
);
}
}
}
else
{
// next block in the same file
}
else
{
// next block in the same file
cur
->
slot
+=
step
;
cur
->
slot
+=
step
;
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
cur
->
pos
=
(
step
==
QUERY_ASC_FORWARD_STEP
)
?
0
:
pBlock
->
numOfPoints
-
1
;
cur
->
pos
=
(
step
==
QUERY_ASC_FORWARD_STEP
)
?
0
:
pBlock
->
numOfPoints
-
1
;
return
load
QualifiedDataFromFileBlock
(
pQueryHandle
);
return
load
FileDataBlock
(
pQueryHandle
,
pBlock
,
pCheckInfo
);
}
}
}
else
{
// data in cache
}
else
{
// data in cache
return
hasMoreDataInCache
ForSingleModel
(
pQueryHandle
);
return
hasMoreDataInCache
(
pQueryHandle
);
}
}
return
false
;
return
false
;
}
}
int
vnodeBinarySearchKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
)
{
int
vnodeBinarySearchKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
)
{
int
firstPos
,
lastPos
,
midPos
=
-
1
;
int
firstPos
,
lastPos
,
midPos
=
-
1
;
int
numOfPoints
;
int
numOfPoints
;
TSKEY
*
keyList
;
TSKEY
*
keyList
;
if
(
num
<=
0
)
return
-
1
;
if
(
num
<=
0
)
return
-
1
;
keyList
=
(
TSKEY
*
)
pValue
;
keyList
=
(
TSKEY
*
)
pValue
;
firstPos
=
0
;
firstPos
=
0
;
lastPos
=
num
-
1
;
lastPos
=
num
-
1
;
...
@@ -514,14 +539,16 @@ int vnodeBinarySearchKey(char *pValue, int num, TSKEY key, int order) {
...
@@ -514,14 +539,16 @@ int vnodeBinarySearchKey(char *pValue, int num, TSKEY key, int order) {
// only return the qualified data to client in terms of query time window, data rows in the same block but do not
// only return the qualified data to client in terms of query time window, data rows in the same block but do not
// be included in the query time window will be discarded
// be included in the query time window will be discarded
static
void
filterDataInDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
SDataCols
*
pCols
,
SArray
*
sa
)
{
static
void
filterDataInDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
STableCheckInfo
*
pCheckInfo
,
SCompBlock
*
pBlock
,
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
SArray
*
sa
)
{
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
pQueryHandle
->
activeIndex
);
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
SDataBlockInfo
blockInfo
=
getTrueDataBlockInfo
(
pQueryHandle
,
pCheckInfo
);
SDataBlockInfo
blockInfo
=
getTrueDataBlockInfo
(
pCheckInfo
,
pBlock
);
SDataCols
*
pCols
=
pCheckInfo
->
pDataCols
;
int32_t
endPos
=
cur
->
pos
;
int32_t
endPos
=
cur
->
pos
;
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
)
&&
pQueryHandle
->
window
.
ekey
>
blockInfo
.
window
.
ekey
)
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
)
&&
pQueryHandle
->
window
.
ekey
>
blockInfo
.
window
.
ekey
)
{
endPos
=
blockInfo
.
size
-
1
;
endPos
=
blockInfo
.
rows
-
1
;
pQueryHandle
->
realNumOfRows
=
endPos
-
cur
->
pos
+
1
;
pQueryHandle
->
realNumOfRows
=
endPos
-
cur
->
pos
+
1
;
pCheckInfo
->
lastKey
=
blockInfo
.
window
.
ekey
+
1
;
pCheckInfo
->
lastKey
=
blockInfo
.
window
.
ekey
+
1
;
}
else
if
(
!
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
)
&&
pQueryHandle
->
window
.
ekey
<
blockInfo
.
window
.
skey
)
{
}
else
if
(
!
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
)
&&
pQueryHandle
->
window
.
ekey
<
blockInfo
.
window
.
skey
)
{
...
@@ -529,7 +556,8 @@ static void filterDataInDataBlock(STsdbQueryHandle *pQueryHandle, SDataCols* pCo
...
@@ -529,7 +556,8 @@ static void filterDataInDataBlock(STsdbQueryHandle *pQueryHandle, SDataCols* pCo
pQueryHandle
->
realNumOfRows
=
cur
->
pos
+
1
;
pQueryHandle
->
realNumOfRows
=
cur
->
pos
+
1
;
pCheckInfo
->
lastKey
=
blockInfo
.
window
.
ekey
-
1
;
pCheckInfo
->
lastKey
=
blockInfo
.
window
.
ekey
-
1
;
}
else
{
}
else
{
endPos
=
vnodeBinarySearchKey
(
pCols
->
cols
[
0
].
pData
,
pCols
->
numOfPoints
,
pQueryHandle
->
window
.
ekey
,
pQueryHandle
->
order
);
endPos
=
vnodeBinarySearchKey
(
pCols
->
cols
[
0
].
pData
,
pCols
->
numOfPoints
,
pQueryHandle
->
window
.
ekey
,
pQueryHandle
->
order
);
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQueryHandle
->
order
))
{
if
(
endPos
<
cur
->
pos
)
{
if
(
endPos
<
cur
->
pos
)
{
...
@@ -558,41 +586,42 @@ static void filterDataInDataBlock(STsdbQueryHandle *pQueryHandle, SDataCols* pCo
...
@@ -558,41 +586,42 @@ static void filterDataInDataBlock(STsdbQueryHandle *pQueryHandle, SDataCols* pCo
int32_t
numOfCols
=
QH_GET_NUM_OF_COLS
(
pQueryHandle
);
int32_t
numOfCols
=
QH_GET_NUM_OF_COLS
(
pQueryHandle
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
sa
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
sa
);
++
i
)
{
int16_t
colId
=
*
(
int16_t
*
)
taosArrayGet
(
sa
,
i
);
int16_t
colId
=
*
(
int16_t
*
)
taosArrayGet
(
sa
,
i
);
for
(
int32_t
j
=
0
;
j
<
numOfCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
numOfCols
;
++
j
)
{
SColumnInfoEx
*
pCol
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
j
);
SColumnInfoEx
*
pCol
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
j
);
if
(
pCol
->
info
.
colId
==
colId
)
{
if
(
pCol
->
info
.
colId
==
colId
)
{
SDataCol
*
pDataCol
=
&
pCols
->
cols
[
i
];
SDataCol
*
pDataCol
=
&
pCols
->
cols
[
i
];
memmove
(
pCol
->
pData
,
pDataCol
->
pData
+
pCol
->
info
.
bytes
*
start
,
pQueryHandle
->
realNumOfRows
*
pCol
->
info
.
bytes
);
memmove
(
pCol
->
pData
,
pDataCol
->
pData
+
pCol
->
info
.
bytes
*
start
,
pQueryHandle
->
realNumOfRows
*
pCol
->
info
.
bytes
);
break
;
break
;
}
}
}
}
}
}
assert
(
pQueryHandle
->
realNumOfRows
<=
blockInfo
.
size
);
assert
(
pQueryHandle
->
realNumOfRows
<=
blockInfo
.
rows
);
// forward(backward) the position for cursor
// forward(backward) the position for cursor
cur
->
pos
=
endPos
;
cur
->
pos
=
endPos
;
}
}
static
SArray
*
getColumnIdList
(
STsdbQueryHandle
*
pQueryHandle
)
{
static
SArray
*
getColumnIdList
(
STsdbQueryHandle
*
pQueryHandle
)
{
int32_t
numOfCols
=
QH_GET_NUM_OF_COLS
(
pQueryHandle
);
int32_t
numOfCols
=
QH_GET_NUM_OF_COLS
(
pQueryHandle
);
SArray
*
pIdList
=
taosArrayInit
(
numOfCols
,
sizeof
(
int16_t
));
SArray
*
pIdList
=
taosArrayInit
(
numOfCols
,
sizeof
(
int16_t
));
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoEx
*
pCol
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
SColumnInfoEx
*
pCol
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
taosArrayPush
(
pIdList
,
&
pCol
->
info
.
colId
);
taosArrayPush
(
pIdList
,
&
pCol
->
info
.
colId
);
}
}
return
pIdList
;
return
pIdList
;
}
}
SArray
*
getDefaultLoadColumns
(
STsdbQueryHandle
*
pQueryHandle
,
bool
loadTS
)
{
SArray
*
getDefaultLoadColumns
(
STsdbQueryHandle
*
pQueryHandle
,
bool
loadTS
)
{
SArray
*
pLocalIdList
=
getColumnIdList
(
pQueryHandle
);
SArray
*
pLocalIdList
=
getColumnIdList
(
pQueryHandle
);
// check if the primary time stamp column needs to load
// check if the primary time stamp column needs to load
int16_t
colId
=
*
(
int16_t
*
)
taosArrayGet
(
pLocalIdList
,
0
);
int16_t
colId
=
*
(
int16_t
*
)
taosArrayGet
(
pLocalIdList
,
0
);
// the primary timestamp column does not be included in the the specified load column list, add it
// the primary timestamp column does not be included in the the specified load column list, add it
if
(
loadTS
&&
colId
!=
0
)
{
if
(
loadTS
&&
colId
!=
0
)
{
...
@@ -603,14 +632,14 @@ SArray *getDefaultLoadColumns(STsdbQueryHandle *pQueryHandle, bool loadTS) {
...
@@ -603,14 +632,14 @@ SArray *getDefaultLoadColumns(STsdbQueryHandle *pQueryHandle, bool loadTS) {
return
pLocalIdList
;
return
pLocalIdList
;
}
}
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
)
{
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
)
{
int
firstPos
,
lastPos
,
midPos
=
-
1
;
int
firstPos
,
lastPos
,
midPos
=
-
1
;
int
numOfPoints
;
int
numOfPoints
;
TSKEY
*
keyList
;
TSKEY
*
keyList
;
if
(
num
<=
0
)
return
-
1
;
if
(
num
<=
0
)
return
-
1
;
keyList
=
(
TSKEY
*
)
pValue
;
keyList
=
(
TSKEY
*
)
pValue
;
firstPos
=
0
;
firstPos
=
0
;
lastPos
=
num
-
1
;
lastPos
=
num
-
1
;
...
@@ -663,186 +692,368 @@ static int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) {
...
@@ -663,186 +692,368 @@ static int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) {
return
midPos
;
return
midPos
;
}
}
static
bool
getQualifiedDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
STableCheckInfo
*
pCheckInfo
,
int32_t
type
)
{
static
bool
getQualifiedDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
STableCheckInfo
*
pCheckInfo
,
int32_t
type
)
{
STsdbFileH
*
pFileHandle
=
tsdbGetFile
(
pQueryHandle
->
pTsdb
);
STsdbFileH
*
pFileHandle
=
tsdbGetFile
(
pQueryHandle
->
pTsdb
);
int32_t
fid
=
getFileIdFromKey
(
pCheckInfo
->
lastKey
);
int32_t
fid
=
getFileIdFromKey
(
pCheckInfo
->
lastKey
);
tsdbInitFileGroupIter
(
pFileHandle
,
&
p
CheckInfo
->
fileIter
,
TSDB_FGROUP_ITER_FORWARD
);
tsdbInitFileGroupIter
(
pFileHandle
,
&
p
QueryHandle
->
fileIter
,
TSDB_FGROUP_ITER_FORWARD
);
tsdbSeekFileGroupIter
(
&
p
CheckInfo
->
fileIter
,
fid
);
tsdbSeekFileGroupIter
(
&
p
QueryHandle
->
fileIter
,
fid
);
p
CheckInfo
->
pFileGroup
=
tsdbGetFileGroupNext
(
&
pCheckInfo
->
fileIter
);
p
QueryHandle
->
pFileGroup
=
tsdbGetFileGroupNext
(
&
pQueryHandle
->
fileIter
);
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
TSKEY
key
=
pCheckInfo
->
lastKey
;
int32_t
index
=
-
1
;
int32_t
tid
=
pCheckInfo
->
tableId
.
tid
;
int32_t
tid
=
pCheckInfo
->
tableId
.
tid
;
int32_t
numOfBlocks
=
0
;
while
(
p
CheckInfo
->
pFileGroup
!=
NULL
)
{
while
(
p
QueryHandle
->
pFileGroup
!=
NULL
)
{
if
(
getFileCompInfo
(
p
CheckInfo
,
pCheckInfo
->
pFileGroup
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
getFileCompInfo
(
p
QueryHandle
,
&
numOfBlocks
,
1
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
break
;
}
}
assert
(
pCheckInfo
->
numOfBlocks
>=
0
);
// no data block in current file, try next
// no data block in current file, try next
if
(
pCheckInfo
->
compIndex
[
tid
].
numOfSuperBlocks
==
0
)
{
if
(
pCheckInfo
->
numOfBlocks
>
0
)
{
dTrace
(
"QInfo:%p no data block in file, fid:%d, tid:%d, try next"
,
pQueryHandle
->
qinfo
,
cur
->
fid
=
pQueryHandle
->
pFileGroup
->
fileId
;
pCheckInfo
->
pFileGroup
->
fileId
,
tid
);
break
;
}
pCheckInfo
->
pFileGroup
=
tsdbGetFileGroupNext
(
&
pCheckInfo
->
fileIter
);
dTrace
(
"%p no data block in file, fid:%d, tid:%d, try next, %p"
,
pQueryHandle
,
pQueryHandle
->
pFileGroup
->
fileId
,
continue
;
tid
,
pQueryHandle
->
qinfo
);
pQueryHandle
->
pFileGroup
=
tsdbGetFileGroupNext
(
&
pQueryHandle
->
fileIter
);
}
}
index
=
binarySearchForBlockImpl
(
pCheckInfo
->
pCompInfo
->
blocks
,
pCheckInfo
->
compIndex
[
tid
].
numOfSuperBlocks
,
pQueryHandle
->
order
,
key
);
if
(
pCheckInfo
->
numOfBlocks
==
0
)
{
return
false
;
}
if
(
type
==
QUERY_RANGE_GREATER_EQUAL
)
{
cur
->
slot
=
0
;
// always start from the first slot
if
(
key
<=
pCheckInfo
->
pCompInfo
->
blocks
[
index
].
keyLast
)
{
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
break
;
return
loadFileDataBlock
(
pQueryHandle
,
pBlock
,
pCheckInfo
);
}
else
{
}
index
=
-
1
;
static
UNUSED_FUNC
bool
hasMoreDataForSingleTable
(
STsdbQueryHandle
*
pHandle
)
{
assert
(
pHandle
->
activeIndex
==
0
&&
taosArrayGetSize
(
pHandle
->
pTableCheckInfo
)
==
1
);
STsdbFileH
*
pFileHandle
=
tsdbGetFile
(
pHandle
->
pTsdb
);
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
if
(
!
pCheckInfo
->
checkFirstFileBlock
)
{
pCheckInfo
->
checkFirstFileBlock
=
true
;
if
(
pFileHandle
!=
NULL
)
{
bool
found
=
getQualifiedDataBlock
(
pHandle
,
pCheckInfo
,
1
);
if
(
found
)
{
return
true
;
}
}
}
else
{
if
(
key
>=
pCheckInfo
->
pCompInfo
->
blocks
[
index
].
keyFirst
)
{
break
;
}
else
{
index
=
-
1
;
}
}
// no data in file, try cache
pHandle
->
cur
.
fid
=
-
1
;
return
hasMoreDataInCache
(
pHandle
);
}
else
{
// move to next data block in file or in cache
return
moveToNextBlock
(
pHandle
,
1
);
}
}
}
typedef
struct
SBlockOrderSupporter
{
int32_t
numOfTables
;
STableBlockInfo
**
pDataBlockInfo
;
int32_t
*
blockIndexArray
;
int32_t
*
numOfBlocksPerMeter
;
}
SBlockOrderSupporter
;
void
cleanBlockOrderSupporter
(
SBlockOrderSupporter
*
pSupporter
,
int32_t
numOfTables
)
{
tfree
(
pSupporter
->
numOfBlocksPerMeter
);
tfree
(
pSupporter
->
blockIndexArray
);
for
(
int32_t
i
=
0
;
i
<
numOfTables
;
++
i
)
{
tfree
(
pSupporter
->
pDataBlockInfo
[
i
]);
}
}
// failed to find qualified point in file, abort
tfree
(
pSupporter
->
pDataBlockInfo
);
if
(
index
==
-
1
)
{
}
return
false
;
static
int32_t
dataBlockOrderCompar
(
const
void
*
pLeft
,
const
void
*
pRight
,
void
*
param
)
{
int32_t
leftTableIndex
=
*
(
int32_t
*
)
pLeft
;
int32_t
rightTableIndex
=
*
(
int32_t
*
)
pRight
;
SBlockOrderSupporter
*
pSupporter
=
(
SBlockOrderSupporter
*
)
param
;
int32_t
leftTableBlockIndex
=
pSupporter
->
blockIndexArray
[
leftTableIndex
];
int32_t
rightTableBlockIndex
=
pSupporter
->
blockIndexArray
[
rightTableIndex
];
if
(
leftTableBlockIndex
>
pSupporter
->
numOfBlocksPerMeter
[
leftTableIndex
])
{
/* left block is empty */
return
1
;
}
else
if
(
rightTableBlockIndex
>
pSupporter
->
numOfBlocksPerMeter
[
rightTableIndex
])
{
/* right block is empty */
return
-
1
;
}
}
assert
(
index
>=
0
&&
index
<
pCheckInfo
->
compIndex
[
tid
].
numOfSuperBlocks
);
STableBlockInfo
*
pLeftBlockInfoEx
=
&
pSupporter
->
pDataBlockInfo
[
leftTableIndex
][
leftTableBlockIndex
];
STableBlockInfo
*
pRightBlockInfoEx
=
&
pSupporter
->
pDataBlockInfo
[
rightTableIndex
][
rightTableBlockIndex
];
// load first data block into memory failed, caused by disk block error
// assert(pLeftBlockInfoEx->pBlock.compBlock->offset != pRightBlockInfoEx->pBlock.compBlock->offset);
bool
blockLoaded
=
false
;
if
(
pLeftBlockInfoEx
->
pBlock
.
compBlock
->
offset
==
pRightBlockInfoEx
->
pBlock
.
compBlock
->
offset
&&
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
pLeftBlockInfoEx
->
pBlock
.
compBlock
->
last
==
pRightBlockInfoEx
->
pBlock
.
compBlock
->
last
)
{
// todo add more information
dError
(
"error in header file, two block with same offset:%p"
,
pLeftBlockInfoEx
->
pBlock
.
compBlock
->
offset
);
}
// todo no need to loaded at all
return
pLeftBlockInfoEx
->
pBlock
.
compBlock
->
offset
>
pRightBlockInfoEx
->
pBlock
.
compBlock
->
offset
?
1
:
-
1
;
cur
->
slot
=
index
;
}
SCompBlock
*
pBlock
=
&
pCheckInfo
->
pCompInfo
->
blocks
[
cur
->
slot
];
int32_t
createDataBlocksInfo
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
numOfBlocks
,
int32_t
*
numOfAllocBlocks
)
{
SCompData
*
data
=
calloc
(
1
,
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pBlock
->
numOfCols
);
char
*
tmp
=
realloc
(
pQueryHandle
->
pDataBlockInfo
,
sizeof
(
STableBlockInfo
)
*
numOfBlocks
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
data
->
numOfCols
=
pBlock
->
numOfCols
;
pQueryHandle
->
pDataBlockInfo
=
(
STableBlockInfo
*
)
tmp
;
data
->
uid
=
pCheckInfo
->
pTableObj
->
tableId
.
uid
;
memset
(
pQueryHandle
->
pDataBlockInfo
,
0
,
sizeof
(
STableBlockInfo
)
*
numOfBlocks
);
*
numOfAllocBlocks
=
numOfBlocks
;
pCheckInfo
->
pDataCols
=
tdNewDataCols
(
1000
,
2
,
4096
);
int32_t
numOfTables
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
tdInitDataCols
(
pCheckInfo
->
pDataCols
,
pCheckInfo
->
pTableObj
->
schema
);
SFile
*
pFile
=
&
pCheckInfo
->
pFileGroup
->
files
[
TSDB_FILE_TYPE_DATA
];
SBlockOrderSupporter
sup
=
{
0
};
if
(
pFile
->
fd
==
FD_INITIALIZER
)
{
sup
.
numOfTables
=
numOfTables
;
pFile
->
fd
=
open
(
pFile
->
fname
,
O_RDONLY
);
sup
.
numOfBlocksPerMeter
=
calloc
(
1
,
sizeof
(
int32_t
)
*
numOfTables
);
sup
.
blockIndexArray
=
calloc
(
1
,
sizeof
(
int32_t
)
*
numOfTables
);
sup
.
pDataBlockInfo
=
calloc
(
1
,
POINTER_BYTES
*
numOfTables
);
if
(
sup
.
numOfBlocksPerMeter
==
NULL
||
sup
.
blockIndexArray
==
NULL
||
sup
.
pDataBlockInfo
==
NULL
)
{
cleanBlockOrderSupporter
(
&
sup
,
0
);
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
}
if
(
tsdbLoadDataBlock
(
pFile
,
pBlock
,
1
,
pCheckInfo
->
pDataCols
,
data
)
==
0
)
{
int32_t
cnt
=
0
;
SDataBlockLoadInfo
*
pBlockLoadInfo
=
&
pQueryHandle
->
dataBlockLoadInfo
;
int32_t
numOfQualMeters
=
0
;
pBlockLoadInfo
->
fileGroup
=
pCheckInfo
->
pFileGroup
;
for
(
int32_t
j
=
0
;
j
<
numOfTables
;
++
j
)
{
pBlockLoadInfo
->
slot
=
pQueryHandle
->
cur
.
slot
;
STableCheckInfo
*
pTableCheck
=
(
STableCheckInfo
*
)
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
j
);
pBlockLoadInfo
->
sid
=
pCheckInfo
->
pTableObj
->
tableId
.
tid
;
blockLoaded
=
true
;
SCompBlock
*
pBlock
=
pTableCheck
->
pCompInfo
->
blocks
;
sup
.
numOfBlocksPerMeter
[
numOfQualMeters
]
=
pTableCheck
->
numOfBlocks
;
char
*
buf
=
calloc
(
1
,
sizeof
(
STableBlockInfo
)
*
pTableCheck
->
numOfBlocks
);
if
(
buf
==
NULL
)
{
cleanBlockOrderSupporter
(
&
sup
,
numOfQualMeters
);
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
}
// dError("QInfo:%p fileId:%d total numOfBlks:%d blockId:%d load into memory failed due to error in disk files",
sup
.
pDataBlockInfo
[
numOfQualMeters
]
=
(
STableBlockInfo
*
)
buf
;
// GET_QINFO_ADDR(pQuery), pQuery->fileId, pQuery->numOfBlocks, blkIdx);
// failed to load data from disk, abort current query
for
(
int32_t
k
=
0
;
k
<
pTableCheck
->
numOfBlocks
;
++
k
)
{
if
(
blockLoaded
==
false
)
{
STableBlockInfo
*
pBlockInfoEx
=
&
sup
.
pDataBlockInfo
[
numOfQualMeters
][
k
];
taosArrayDestroy
(
sa
);
tfree
(
data
);
return
false
;
pBlockInfoEx
->
pBlock
.
compBlock
=
&
pBlock
[
k
];
pBlockInfoEx
->
pBlock
.
fields
=
NULL
;
pBlockInfoEx
->
pTableCheckInfo
=
pTableCheck
;
// pBlockInfoEx->groupIdx = pTableCheckInfo[j]->groupIdx; // set the group index
// pBlockInfoEx->blockIndex = pTableCheckInfo[j]->start + k; // set the block index in original meter
cnt
++
;
}
}
// todo search qualified points in blk, according to primary key (timestamp) column
numOfQualMeters
++
;
SDataCols
*
pDataCols
=
pCheckInfo
->
pDataCols
;
}
TSKEY
*
d
=
(
TSKEY
*
)
pDataCols
->
cols
[
PRIMARYKEY_TIMESTAMP_COL_INDEX
].
pData
;
dTrace
(
"%p create data blocks info struct completed"
,
pQueryHandle
);
assert
(
d
[
0
]
==
pBlock
->
keyFirst
&&
d
[
pBlock
->
numOfPoints
-
1
]
==
pBlock
->
keyLast
);
cur
->
pos
=
binarySearchForKey
(
pDataCols
->
cols
[
0
].
pData
,
pBlock
->
numOfPoints
,
key
,
pQueryHandle
->
order
);
assert
(
cnt
<=
numOfBlocks
&&
numOfQualMeters
<=
numOfTables
);
// the pMeterDataInfo[j]->numOfBlocks may be 0
sup
.
numOfTables
=
numOfQualMeters
;
SLoserTreeInfo
*
pTree
=
NULL
;
cur
->
fid
=
pCheckInfo
->
pFileGroup
->
fileId
;
uint8_t
ret
=
tLoserTreeCreate
(
&
pTree
,
sup
.
numOfTables
,
&
sup
,
dataBlockOrderCompar
);
assert
(
cur
->
pos
>=
0
&&
cur
->
fid
>=
0
&&
cur
->
slot
>=
0
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
cleanBlockOrderSupporter
(
&
sup
,
numOfTables
);
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
filterDataInDataBlock
(
pQueryHandle
,
pCheckInfo
->
pDataCols
,
sa
)
;
int32_t
numOfTotal
=
0
;
taosArrayDestroy
(
sa
);
while
(
numOfTotal
<
cnt
)
{
tfree
(
data
);
int32_t
pos
=
pTree
->
pNode
[
0
].
index
;
return
pQueryHandle
->
realNumOfRows
>
0
;
int32_t
index
=
sup
.
blockIndexArray
[
pos
]
++
;
STableBlockInfo
*
pBlocksInfoEx
=
sup
.
pDataBlockInfo
[
pos
];
pQueryHandle
->
pDataBlockInfo
[
numOfTotal
++
]
=
pBlocksInfoEx
[
index
];
// set data block index overflow, in order to disable the offset comparator
if
(
sup
.
blockIndexArray
[
pos
]
>=
sup
.
numOfBlocksPerMeter
[
pos
])
{
sup
.
blockIndexArray
[
pos
]
=
sup
.
numOfBlocksPerMeter
[
pos
]
+
1
;
}
tLoserTreeAdjust
(
pTree
,
pos
+
sup
.
numOfTables
);
}
/*
* available when no import exists
* for(int32_t i = 0; i < cnt - 1; ++i) {
* assert((*pDataBlockInfo)[i].pBlock.compBlock->offset < (*pDataBlockInfo)[i+1].pBlock.compBlock->offset);
* }
*/
dTrace
(
"%p %d data blocks sort completed"
,
pQueryHandle
,
cnt
);
cleanBlockOrderSupporter
(
&
sup
,
numOfTables
);
free
(
pTree
);
return
TSDB_CODE_SUCCESS
;
}
}
static
bool
hasMoreDataInFileForSingleTableModel
(
STsdbQueryHandle
*
pHandle
)
{
static
bool
getDataBlocksInFiles
(
STsdbQueryHandle
*
pQueryHandle
)
{
assert
(
pHandle
->
activeIndex
==
0
&&
taosArrayGetSize
(
pHandle
->
pTableCheckInfo
)
==
1
);
STsdbFileH
*
pFileHandle
=
tsdbGetFile
(
pQueryHandle
->
pTsdb
);
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
STsdbFileH
*
pFileHandle
=
tsdbGetFile
(
pHandle
->
pTsdb
);
// find the start data block in file
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
if
(
!
pQueryHandle
->
locateStart
)
{
pQueryHandle
->
locateStart
=
true
;
if
(
!
pCheckInfo
->
checkFirstFileBlock
)
{
int32_t
fid
=
getFileIdFromKey
(
pQueryHandle
->
window
.
skey
);
pCheckInfo
->
checkFirstFileBlock
=
true
;
if
(
pFileHandle
!=
NULL
)
{
tsdbInitFileGroupIter
(
pFileHandle
,
&
pQueryHandle
->
fileIter
,
TSDB_FGROUP_ITER_FORWARD
);
bool
found
=
getQualifiedDataBlock
(
pHandle
,
pCheckInfo
,
1
);
tsdbSeekFileGroupIter
(
&
pQueryHandle
->
fileIter
,
fid
);
if
(
found
)
{
return
true
;
int32_t
numOfBlocks
=
-
1
;
// todo opt for only one table case
pQueryHandle
->
numOfBlocks
=
0
;
int32_t
numOfTables
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
while
((
pQueryHandle
->
pFileGroup
=
tsdbGetFileGroupNext
(
&
pQueryHandle
->
fileIter
))
!=
NULL
)
{
if
(
getFileCompInfo
(
pQueryHandle
,
&
numOfBlocks
,
1
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
}
}
assert
(
numOfBlocks
>=
0
);
dTrace
(
"%p %d blocks found in file for %d table(s), fid:%d"
,
pQueryHandle
,
numOfBlocks
,
pQueryHandle
->
pFileGroup
->
fileId
,
numOfTables
);
// todo return error code to query engine
if
(
createDataBlocksInfo
(
pQueryHandle
,
numOfBlocks
,
&
pQueryHandle
->
numOfBlocks
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
}
}
// no data in file, try cache
assert
(
numOfBlocks
>=
pQueryHandle
->
numOfBlocks
);
pHandle
->
cur
.
fid
=
-
1
;
if
(
pQueryHandle
->
numOfBlocks
>
0
)
{
return
hasMoreDataInCacheForSingleModel
(
pHandle
);
break
;
}
else
{
// move to next data block in file or in cache
}
return
moveToNextBlock
(
pHandle
,
1
);
}
}
}
static
bool
hasMoreDataInCacheForMultiModel
(
STsdbQueryHandle
*
pHandle
)
{
// no data in file anymore
size_t
numOfTables
=
taosArrayGetSize
(
pHandle
->
pTableCheckInfo
);
if
(
pQueryHandle
->
numOfBlocks
<=
0
)
{
assert
(
numOfTables
>
0
);
assert
(
pQueryHandle
->
pFileGroup
==
NULL
);
cur
->
fid
=
-
1
;
while
(
pHandle
->
activeIndex
<
numOfTables
)
{
return
false
;
STableCheckInfo
*
pTableCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
}
STable
*
pTable
=
pTableCheckInfo
->
pTableObj
;
cur
->
slot
=
0
;
if
(
pTable
->
mem
==
NULL
&&
pTable
->
imem
==
NULL
)
{
cur
->
fid
=
pQueryHandle
->
pFileGroup
->
fileId
;
pHandle
->
activeIndex
+=
1
;
// try next table if exits
continue
;
STableBlockInfo
*
pBlockInfo
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
STableCheckInfo
*
pCheckInfo
=
pBlockInfo
->
pTableCheckInfo
;
SCompBlock
*
pBlock
=
pBlockInfo
->
pBlock
.
compBlock
;
return
loadFileDataBlock
(
pQueryHandle
,
pBlock
,
pCheckInfo
);
}
else
{
if
(
cur
->
slot
==
pQueryHandle
->
numOfBlocks
-
1
)
{
// all blocks
int32_t
numOfBlocks
=
-
1
;
int32_t
numOfTables
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
pQueryHandle
->
numOfBlocks
=
0
;
while
((
pQueryHandle
->
pFileGroup
=
tsdbGetFileGroupNext
(
&
pQueryHandle
->
fileIter
))
!=
NULL
)
{
if
(
getFileCompInfo
(
pQueryHandle
,
&
numOfBlocks
,
1
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
}
}
// all data in mem are checked already.
assert
(
numOfBlocks
>=
0
);
if
(
pTableCheckInfo
->
lastKey
>
pTable
->
mem
->
keyLast
)
{
dTrace
(
"%p %d blocks found in file for %d table(s), fid:%d"
,
pQueryHandle
,
numOfBlocks
,
numOfTables
,
pHandle
->
activeIndex
+=
1
;
// try next table if exits
pQueryHandle
->
pFileGroup
->
fileId
);
continue
;
// todo return error code to query engine
if
(
createDataBlocksInfo
(
pQueryHandle
,
numOfBlocks
,
&
pQueryHandle
->
numOfBlocks
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
}
}
return
true
;
assert
(
numOfBlocks
>=
pQueryHandle
->
numOfBlocks
);
if
(
pQueryHandle
->
numOfBlocks
>
0
)
{
break
;
}
}
}
// all tables has checked already
// no data in file anymore
if
(
pQueryHandle
->
numOfBlocks
<=
0
)
{
assert
(
pQueryHandle
->
pFileGroup
==
NULL
);
cur
->
fid
=
-
1
;
return
false
;
return
false
;
}
cur
->
slot
=
0
;
cur
->
fid
=
pQueryHandle
->
pFileGroup
->
fileId
;
STableBlockInfo
*
pBlockInfo
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
STableCheckInfo
*
pCheckInfo
=
pBlockInfo
->
pTableCheckInfo
;
SCompBlock
*
pBlock
=
pBlockInfo
->
pBlock
.
compBlock
;
return
loadFileDataBlock
(
pQueryHandle
,
pBlock
,
pCheckInfo
);
}
else
{
// next block of the same file
cur
->
slot
+=
1
;
cur
->
pos
=
0
;
STableBlockInfo
*
pBlockInfo
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
return
loadFileDataBlock
(
pQueryHandle
,
pBlockInfo
->
pBlock
.
compBlock
,
pBlockInfo
->
pTableCheckInfo
);
}
}
}
}
// handle data in cache situation
// handle data in cache situation
bool
tsdbNextDataBlock
(
tsdb_query_handle_t
*
pQueryHandle
)
{
bool
tsdbNextDataBlock
(
tsdb_query_handle_t
*
pQueryHandle
)
{
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
if
(
pHandle
->
model
==
SINGLE_TABLE_MODEL
)
{
return
hasMoreDataInFileForSingleTableModel
(
pHandle
);
size_t
numOfTables
=
taosArrayGetSize
(
pHandle
->
pTableCheckInfo
);
assert
(
numOfTables
>
0
);
if
(
pHandle
->
checkFiles
)
{
if
(
getDataBlocksInFiles
(
pHandle
))
{
return
true
;
}
pHandle
->
activeIndex
=
0
;
pHandle
->
checkFiles
=
0
;
while
(
pHandle
->
activeIndex
<
numOfTables
)
{
if
(
hasMoreDataInCache
(
pHandle
))
{
return
true
;
}
pHandle
->
activeIndex
+=
1
;
}
return
false
;
}
else
{
}
else
{
return
hasMoreDataInCacheForMultiModel
(
pHandle
);
while
(
pHandle
->
activeIndex
<
numOfTables
)
{
if
(
hasMoreDataInCache
(
pHandle
))
{
return
true
;
}
pHandle
->
activeIndex
+=
1
;
}
return
false
;
}
}
}
}
static
int
tsdbReadRowsFromCache
(
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
static
int
tsdbReadRowsFromCache
(
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
TSKEY
*
skey
,
TSKEY
*
ekey
,
TSKEY
*
skey
,
TSKEY
*
ekey
,
STsdbQueryHandle
*
pHandle
)
{
STsdbQueryHandle
*
pHandle
)
{
int
numOfRows
=
0
;
int
numOfRows
=
0
;
int32_t
numOfCols
=
taosArrayGetSize
(
pHandle
->
pColumns
);
int32_t
numOfCols
=
taosArrayGetSize
(
pHandle
->
pColumns
);
*
skey
=
INT64_MIN
;
*
skey
=
INT64_MIN
;
while
(
tSkipListIterNext
(
pIter
))
{
while
(
tSkipListIterNext
(
pIter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
);
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
);
if
(
node
==
NULL
)
break
;
if
(
node
==
NULL
)
break
;
SDataRow
row
=
SL_GET_NODE_DATA
(
node
);
SDataRow
row
=
SL_GET_NODE_DATA
(
node
);
...
@@ -855,9 +1066,9 @@ static int tsdbReadRowsFromCache(SSkipListIterator *pIter, TSKEY maxKey, int max
...
@@ -855,9 +1066,9 @@ static int tsdbReadRowsFromCache(SSkipListIterator *pIter, TSKEY maxKey, int max
*
ekey
=
dataRowKey
(
row
);
*
ekey
=
dataRowKey
(
row
);
int32_t
offset
=
0
;
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoEx
*
pColInfo
=
taosArrayGet
(
pHandle
->
pColumns
,
i
);
SColumnInfoEx
*
pColInfo
=
taosArrayGet
(
pHandle
->
pColumns
,
i
);
memcpy
(
pColInfo
->
pData
+
numOfRows
*
pColInfo
->
info
.
bytes
,
dataRowTuple
(
row
)
+
offset
,
pColInfo
->
info
.
bytes
);
memcpy
(
pColInfo
->
pData
+
numOfRows
*
pColInfo
->
info
.
bytes
,
dataRowTuple
(
row
)
+
offset
,
pColInfo
->
info
.
bytes
);
offset
+=
pColInfo
->
info
.
bytes
;
offset
+=
pColInfo
->
info
.
bytes
;
}
}
...
@@ -869,19 +1080,23 @@ static int tsdbReadRowsFromCache(SSkipListIterator *pIter, TSKEY maxKey, int max
...
@@ -869,19 +1080,23 @@ static int tsdbReadRowsFromCache(SSkipListIterator *pIter, TSKEY maxKey, int max
}
}
// copy data from cache into data block
// copy data from cache into data block
SDataBlockInfo
tsdbRetrieveDataBlockInfo
(
tsdb_query_handle_t
*
pQueryHandle
)
{
SDataBlockInfo
tsdbRetrieveDataBlockInfo
(
tsdb_query_handle_t
*
pQueryHandle
)
{
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
STable
*
pTable
=
NULL
;
STable
*
pTable
=
pCheckInfo
->
pTableObj
;
TSKEY
skey
=
0
,
ekey
=
0
;
TSKEY
skey
=
0
,
ekey
=
0
;
int32_t
rows
=
0
;
int32_t
rows
=
0
;
// data in file
// data in file
if
(
pHandle
->
cur
.
fid
>
0
)
{
if
(
pHandle
->
cur
.
fid
>=
0
)
{
SDataBlockInfo
binfo
=
getTrueDataBlockInfo
(
pHandle
,
pCheckInfo
);
STableBlockInfo
*
pBlockInfo
=
&
pHandle
->
pDataBlockInfo
[
pHandle
->
cur
.
slot
];
if
(
binfo
.
size
==
pHandle
->
realNumOfRows
)
{
pTable
=
pBlockInfo
->
pTableCheckInfo
->
pTableObj
;
SDataBlockInfo
binfo
=
getTrueDataBlockInfo
(
pBlockInfo
->
pTableCheckInfo
,
pBlockInfo
->
pBlock
.
compBlock
);
if
(
binfo
.
rows
==
pHandle
->
realNumOfRows
)
{
pBlockInfo
->
pTableCheckInfo
->
lastKey
=
pBlockInfo
->
pBlock
.
compBlock
->
keyLast
+
1
;
return
binfo
;
return
binfo
;
}
else
{
}
else
{
/* not a whole disk block, only the qualified rows, so this block is loaded in to buffer during the
/* not a whole disk block, only the qualified rows, so this block is loaded in to buffer during the
...
@@ -890,64 +1105,70 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(tsdb_query_handle_t *pQueryHandle) {
...
@@ -890,64 +1105,70 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(tsdb_query_handle_t *pQueryHandle) {
SColumnInfoEx
*
pColInfoEx
=
taosArrayGet
(
pHandle
->
pColumns
,
0
);
SColumnInfoEx
*
pColInfoEx
=
taosArrayGet
(
pHandle
->
pColumns
,
0
);
rows
=
pHandle
->
realNumOfRows
;
rows
=
pHandle
->
realNumOfRows
;
skey
=
*
(
TSKEY
*
)
pColInfoEx
->
pData
;
skey
=
*
(
TSKEY
*
)
pColInfoEx
->
pData
;
ekey
=
*
(
TSKEY
*
)
((
char
*
)
pColInfoEx
->
pData
+
TSDB_KEYSIZE
*
(
rows
-
1
));
ekey
=
*
(
TSKEY
*
)((
char
*
)
pColInfoEx
->
pData
+
TSDB_KEYSIZE
*
(
rows
-
1
));
// update the last key value
pBlockInfo
->
pTableCheckInfo
->
lastKey
=
ekey
+
1
;
}
}
}
else
{
}
else
{
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
pTable
=
pCheckInfo
->
pTableObj
;
if
(
pTable
->
mem
!=
NULL
)
{
if
(
pTable
->
mem
!=
NULL
)
{
// create mem table iterator if it is not created yet
// create mem table iterator if it is not created yet
if
(
pCheckInfo
->
iter
==
NULL
)
{
if
(
pCheckInfo
->
iter
==
NULL
)
{
pCheckInfo
->
iter
=
tSkipListCreateIter
(
pTable
->
mem
->
pData
);
pCheckInfo
->
iter
=
tSkipListCreateIter
(
pTable
->
mem
->
pData
);
}
}
rows
=
tsdbReadRowsFromCache
(
pCheckInfo
->
iter
,
INT64_MAX
,
2
,
&
skey
,
&
ekey
,
pHandle
);
rows
=
tsdbReadRowsFromCache
(
pCheckInfo
->
iter
,
INT64_MAX
,
2
,
&
skey
,
&
ekey
,
pHandle
);
// update the last key value
pCheckInfo
->
lastKey
=
ekey
+
1
;
}
}
}
}
SDataBlockInfo
blockInfo
=
{
SDataBlockInfo
blockInfo
=
{
.
uid
=
pTable
->
tableId
.
uid
,
.
uid
=
pTable
->
tableId
.
uid
,
.
sid
=
pTable
->
tableId
.
tid
,
.
rows
=
rows
,
.
window
=
{.
skey
=
skey
,
.
ekey
=
ekey
}};
.
sid
=
pTable
->
tableId
.
tid
,
.
size
=
rows
,
.
window
=
{.
skey
=
skey
,
.
ekey
=
ekey
}
};
// update the last key value
pCheckInfo
->
lastKey
=
ekey
+
1
;
return
blockInfo
;
return
blockInfo
;
}
}
// return null for data block in cache
// return null for data block in cache
int32_t
tsdbRetrieveDataBlockStatisInfo
(
tsdb_query_handle_t
*
pQueryHandle
,
SDataStatis
**
pBlockStatis
)
{
int32_t
tsdbRetrieveDataBlockStatisInfo
(
tsdb_query_handle_t
*
pQueryHandle
,
SDataStatis
**
pBlockStatis
)
{
*
pBlockStatis
=
NULL
;
*
pBlockStatis
=
NULL
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SArray
*
tsdbRetrieveDataBlock
(
tsdb_query_handle_t
*
pQueryHandle
,
SArray
*
pIdList
)
{
SArray
*
tsdbRetrieveDataBlock
(
tsdb_query_handle_t
*
pQueryHandle
,
SArray
*
pIdList
)
{
/**
/**
* In the following two cases, the data has been loaded to SColumnInfoEx.
* In the following two cases, the data has been loaded to SColumnInfoEx.
* 1. data is from cache, 2. data block is not completed qualified to query time range
* 1. data is from cache, 2. data block is not completed qualified to query time range
*/
*/
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
STsdbQueryHandle
*
pHandle
=
(
STsdbQueryHandle
*
)
pQueryHandle
;
if
(
pHandle
->
cur
.
fid
<
0
)
{
if
(
pHandle
->
cur
.
fid
<
0
)
{
return
pHandle
->
pColumns
;
return
pHandle
->
pColumns
;
}
else
{
}
else
{
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pHandle
->
pTableCheckInfo
,
pHandle
->
activeIndex
);
STableBlockInfo
*
pBlockInfoEx
=
&
pHandle
->
pDataBlockInfo
[
pHandle
->
cur
.
slot
];
STableCheckInfo
*
pCheckInfo
=
pBlockInfoEx
->
pTableCheckInfo
;
SDataBlockInfo
binfo
=
getTrueDataBlockInfo
(
p
Handle
,
pCheckInfo
);
SDataBlockInfo
binfo
=
getTrueDataBlockInfo
(
p
CheckInfo
,
pBlockInfoEx
->
pBlock
.
compBlock
);
assert
(
pHandle
->
realNumOfRows
<=
binfo
.
size
);
assert
(
pHandle
->
realNumOfRows
<=
binfo
.
rows
);
if
(
pHandle
->
realNumOfRows
<
binfo
.
size
)
{
if
(
pHandle
->
realNumOfRows
<
binfo
.
rows
)
{
return
pHandle
->
pColumns
;
return
pHandle
->
pColumns
;
}
else
{
}
else
{
SArray
*
sa
=
getDefaultLoadColumns
(
pHandle
,
true
);
// data block has been loaded, todo extract method
// data block has been loaded, todo extract method
SDataBlockLoadInfo
*
pBlockLoadInfo
=
&
pHandle
->
dataBlockLoadInfo
;
SDataBlockLoadInfo
*
pBlockLoadInfo
=
&
pHandle
->
dataBlockLoadInfo
;
if
(
pBlockLoadInfo
->
slot
==
pHandle
->
cur
.
slot
&&
pBlockLoadInfo
->
sid
==
pCheckInfo
->
pTableObj
->
tableId
.
tid
)
{
if
(
pBlockLoadInfo
->
slot
==
pHandle
->
cur
.
slot
&&
pBlockLoadInfo
->
sid
==
pCheckInfo
->
pTableObj
->
tableId
.
tid
)
{
return
pHandle
->
pColumns
;
return
pHandle
->
pColumns
;
}
else
{
}
else
{
doLoadDataFromFileBlock
(
pHandle
);
SCompBlock
*
pBlock
=
pBlockInfoEx
->
pBlock
.
compBlock
;
filterDataInDataBlock
(
pHandle
,
pCheckInfo
->
pDataCols
,
sa
);
doLoadFileDataBlock
(
pHandle
,
pBlock
,
pCheckInfo
);
SArray
*
sa
=
getDefaultLoadColumns
(
pHandle
,
true
);
filterDataInDataBlock
(
pHandle
,
pCheckInfo
,
pBlock
,
sa
);
taosArrayDestroy
(
sa
);
return
pHandle
->
pColumns
;
return
pHandle
->
pColumns
;
}
}
...
@@ -955,62 +1176,60 @@ SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList
...
@@ -955,62 +1176,60 @@ SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList
}
}
}
}
int32_t
tsdbResetQuery
(
tsdb_query_handle_t
*
pQueryHandle
,
STimeWindow
*
window
,
tsdbpos_t
position
,
int16_t
order
)
{
int32_t
tsdbResetQuery
(
tsdb_query_handle_t
*
pQueryHandle
,
STimeWindow
*
window
,
tsdbpos_t
position
,
int16_t
order
)
{
return
0
;
return
0
;
}
}
int32_t
tsdbDataBlockSeek
(
tsdb_query_handle_t
*
pQueryHandle
,
tsdbpos_t
pos
)
{
return
0
;
}
int32_t
tsdbDataBlockSeek
(
tsdb_query_handle_t
*
pQueryHandle
,
tsdbpos_t
pos
)
{
return
0
;
}
tsdbpos_t
tsdbDataBlockTell
(
tsdb_query_handle_t
*
pQueryHandle
)
{
return
NULL
;
}
tsdbpos_t
tsdbDataBlockTell
(
tsdb_query_handle_t
*
pQueryHandle
)
{
return
NULL
;
}
SArray
*
tsdbRetrieveDataRow
(
tsdb_query_handle_t
*
pQueryHandle
,
SArray
*
pIdList
,
SQueryRowCond
*
pCond
)
{
return
NULL
;
}
SArray
*
tsdbRetrieveDataRow
(
tsdb_query_handle_t
*
pQueryHandle
,
SArray
*
pIdList
,
SQueryRowCond
*
pCond
)
{
return
NULL
;
}
tsdb_query_handle_t
*
tsdbQueryFromTagConds
(
STsdbQueryCond
*
pCond
,
int16_t
stableId
,
const
char
*
pTagFilterStr
)
{
tsdb_query_handle_t
*
tsdbQueryFromTagConds
(
STsdbQueryCond
*
pCond
,
int16_t
stableId
,
const
char
*
pTagFilterStr
)
{
return
NULL
;
return
NULL
;
}
}
SArray
*
tsdbGetTableList
(
tsdb_query_handle_t
*
pQueryHandle
)
{
return
NULL
;
}
SArray
*
tsdbGetTableList
(
tsdb_query_handle_t
*
pQueryHandle
)
{
return
NULL
;
}
static
SArray
*
createTableIdArrayList
(
STsdbRepo
*
tsdb
,
int64_t
uid
)
{
static
int32_t
getAllTableIdList
(
STsdbRepo
*
tsdb
,
int64_t
uid
,
SArray
*
list
)
{
STable
*
pTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
STable
*
pTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
assert
(
pTable
!=
NULL
);
//assert pTable is a super table
assert
(
pTable
!=
NULL
);
// assert pTable is a super table
size_t
size
=
tSkipListGetSize
(
pTable
->
pIndex
);
SArray
*
pList
=
taosArrayInit
(
size
,
sizeof
(
STableId
));
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
pTable
->
pIndex
);
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
pTable
->
pIndex
);
while
(
tSkipListIterNext
(
iter
))
{
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
STable
*
t
=
*
(
STable
**
)
SL_GET_NODE_DATA
(
pNode
);
STable
*
t
=
*
(
STable
**
)
SL_GET_NODE_DATA
(
pNode
);
taosArrayPush
(
pL
ist
,
&
t
->
tableId
);
taosArrayPush
(
l
ist
,
&
t
->
tableId
);
}
}
return
pList
;
return
TSDB_CODE_SUCCESS
;
}
}
typedef
struct
S
SyntaxTreeFilter
Supporter
{
typedef
struct
S
ExprTree
Supporter
{
SSchema
*
pTagSchema
;
SSchema
*
pTagSchema
;
int32_t
numOfTags
;
int32_t
numOfTags
;
int32_t
optr
;
int32_t
optr
;
}
S
SyntaxTreeFilter
Supporter
;
}
S
ExprTree
Supporter
;
/**
/**
* convert the result pointer to
STabObj instead of tSkipListNode
* convert the result pointer to
table id instead of table object pointer
* @param pRes
* @param pRes
*/
*/
static
UNUSED_FUNC
void
tansformQueryResult
(
SArray
*
pRes
)
{
static
void
convertQueryResult
(
SArray
*
pRes
,
SArray
*
pTableList
)
{
if
(
p
Res
==
NULL
||
taosArrayGetSize
(
pRes
)
==
0
)
{
if
(
p
TableList
==
NULL
||
taosArrayGetSize
(
pTableList
)
==
0
)
{
return
;
return
;
}
}
size_t
size
=
taosArrayGetSize
(
p
Res
);
size_t
size
=
taosArrayGetSize
(
p
TableList
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
// pRes->pRes[i] = ((tSkipListNode*)(pRes->pRes[i]))->pData;
STable
*
pTable
=
taosArrayGetP
(
pTableList
,
i
);
taosArrayPush
(
pRes
,
&
pTable
->
tableId
);
}
}
}
}
void
tSQLListTraverseDestroyInfo
(
void
*
param
)
{
void
destroyHelper
(
void
*
param
)
{
if
(
param
==
NULL
)
{
if
(
param
==
NULL
)
{
return
;
return
;
}
}
...
@@ -1020,57 +1239,7 @@ void tSQLListTraverseDestroyInfo(void* param) {
...
@@ -1020,57 +1239,7 @@ void tSQLListTraverseDestroyInfo(void* param) {
free
(
param
);
free
(
param
);
}
}
static
char
*
convertTagQueryStr
(
const
wchar_t
*
str
,
size_t
len
)
{
static
UNUSED_FUNC
int32_t
compareStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
char
*
mbs
=
NULL
;
if
(
len
>
0
)
{
mbs
=
calloc
(
1
,
(
len
+
1
)
*
TSDB_NCHAR_SIZE
);
taosUcs4ToMbs
((
void
*
)
str
,
len
*
TSDB_NCHAR_SIZE
,
mbs
);
//todo add log
}
return
mbs
;
}
static
int32_t
compareStrVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
ret
=
strcmp
(
pLeft
,
pRight
);
if
(
ret
==
0
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
static
int32_t
compareWStrVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
ret
=
wcscmp
(
pLeft
,
pRight
);
if
(
ret
==
0
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
static
int32_t
compareIntVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
DEFAULT_COMP
(
GET_INT64_VAL
(
pLeft
),
GET_INT64_VAL
(
pRight
));
}
static
int32_t
compareIntDoubleVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
DEFAULT_COMP
(
GET_INT64_VAL
(
pLeft
),
GET_DOUBLE_VAL
(
pRight
));
}
static
int32_t
compareDoubleVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
DEFAULT_COMP
(
GET_DOUBLE_VAL
(
pLeft
),
GET_DOUBLE_VAL
(
pRight
));
}
static
int32_t
compareDoubleIntVal
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
double
ret
=
(
*
(
double
*
)
pLeft
)
-
(
*
(
int64_t
*
)
pRight
);
if
(
fabs
(
ret
)
<
DBL_EPSILON
)
{
return
0
;
}
else
{
return
ret
>
0
?
1
:
-
1
;
}
}
static
int32_t
compareStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
};
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
};
const
char
*
pattern
=
pRight
;
const
char
*
pattern
=
pRight
;
...
@@ -1081,7 +1250,7 @@ static int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
...
@@ -1081,7 +1250,7 @@ static int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
}
}
static
int32_t
compareWStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
static
UNUSED_FUNC
int32_t
compareWStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
};
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
};
const
wchar_t
*
pattern
=
pRight
;
const
wchar_t
*
pattern
=
pRight
;
...
@@ -1092,66 +1261,65 @@ static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) {
...
@@ -1092,66 +1261,65 @@ static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) {
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
}
}
static
__compar_fn_t
getFilterComparator
(
int32_t
type
,
int32_t
filterType
,
int32_t
optr
)
{
//
static __compar_fn_t getFilterComparator(int32_t type, int32_t filterType, int32_t optr) {
__compar_fn_t
comparator
=
NULL
;
//
__compar_fn_t comparator = NULL;
//
switch
(
type
)
{
//
switch (type) {
case
TSDB_DATA_TYPE_TINYINT
:
//
case TSDB_DATA_TYPE_TINYINT:
case
TSDB_DATA_TYPE_SMALLINT
:
//
case TSDB_DATA_TYPE_SMALLINT:
case
TSDB_DATA_TYPE_INT
:
//
case TSDB_DATA_TYPE_INT:
case
TSDB_DATA_TYPE_BIGINT
:
//
case TSDB_DATA_TYPE_BIGINT:
case
TSDB_DATA_TYPE_BOOL
:
{
//
case TSDB_DATA_TYPE_BOOL: {
if
(
filterType
>=
TSDB_DATA_TYPE_BOOL
&&
filterType
<=
TSDB_DATA_TYPE_BIGINT
)
{
//
if (filterType >= TSDB_DATA_TYPE_BOOL && filterType <= TSDB_DATA_TYPE_BIGINT) {
comparator
=
compareIntVal
;
//
comparator = compareIntVal;
}
else
if
(
filterType
>=
TSDB_DATA_TYPE_FLOAT
&&
filterType
<=
TSDB_DATA_TYPE_DOUBLE
)
{
//
} else if (filterType >= TSDB_DATA_TYPE_FLOAT && filterType <= TSDB_DATA_TYPE_DOUBLE) {
comparator
=
compareIntDoubleVal
;
//
comparator = compareIntDoubleVal;
}
//
}
break
;
//
break;
}
//
}
//
case
TSDB_DATA_TYPE_FLOAT
:
//
case TSDB_DATA_TYPE_FLOAT:
case
TSDB_DATA_TYPE_DOUBLE
:
{
//
case TSDB_DATA_TYPE_DOUBLE: {
if
(
filterType
>=
TSDB_DATA_TYPE_BOOL
&&
filterType
<=
TSDB_DATA_TYPE_BIGINT
)
{
//
if (filterType >= TSDB_DATA_TYPE_BOOL && filterType <= TSDB_DATA_TYPE_BIGINT) {
comparator
=
compareDoubleIntVal
;
//
comparator = compareDoubleIntVal;
}
else
if
(
filterType
>=
TSDB_DATA_TYPE_FLOAT
&&
filterType
<=
TSDB_DATA_TYPE_DOUBLE
)
{
//
} else if (filterType >= TSDB_DATA_TYPE_FLOAT && filterType <= TSDB_DATA_TYPE_DOUBLE) {
comparator
=
compareDoubleVal
;
//
comparator = compareDoubleVal;
}
//
}
break
;
//
break;
}
//
}
//
case
TSDB_DATA_TYPE_BINARY
:
{
//
case TSDB_DATA_TYPE_BINARY: {
assert
(
filterType
==
TSDB_DATA_TYPE_BINARY
);
//
assert(filterType == TSDB_DATA_TYPE_BINARY);
//
if
(
optr
==
TSDB_RELATION_LIKE
)
{
/* wildcard query using like operator */
//
if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
comparator
=
compareStrPatternComp
;
//
comparator = compareStrPatternComp;
}
else
{
/* normal relational comparator */
//
} else { /* normal relational comparator */
comparator
=
compareStrVal
;
//
comparator = compareStrVal;
}
//
}
//
break
;
//
break;
}
//
}
//
case
TSDB_DATA_TYPE_NCHAR
:
{
//
case TSDB_DATA_TYPE_NCHAR: {
assert
(
filterType
==
TSDB_DATA_TYPE_NCHAR
);
//
assert(filterType == TSDB_DATA_TYPE_NCHAR);
//
if
(
optr
==
TSDB_RELATION_LIKE
)
{
//
if (optr == TSDB_RELATION_LIKE) {
comparator
=
compareWStrPatternComp
;
//
comparator = compareWStrPatternComp;
}
else
{
//
} else {
comparator
=
compareWStrVal
;
//
comparator = compareWStrVal;
}
//
}
//
break
;
//
break;
}
//
}
default:
//
default:
comparator
=
compareIntVal
;
//
comparator = compareIntVal;
break
;
//
break;
}
//
}
//
return
comparator
;
//
return comparator;
}
//
}
static
void
getTagColumnInfo
(
SSyntaxTreeFilterSupporter
*
pSupporter
,
SSchema
*
pSchema
,
int32_t
*
index
,
static
void
getTagColumnInfo
(
SExprTreeSupporter
*
pSupporter
,
SSchema
*
pSchema
,
int32_t
*
index
,
int32_t
*
offset
)
{
int32_t
*
offset
)
{
*
index
=
0
;
*
index
=
0
;
*
offset
=
0
;
*
offset
=
0
;
...
@@ -1165,7 +1333,7 @@ static void getTagColumnInfo(SSyntaxTreeFilterSupporter* pSupporter, SSchema* pS
...
@@ -1165,7 +1333,7 @@ static void getTagColumnInfo(SSyntaxTreeFilterSupporter* pSupporter, SSchema* pS
while
((
*
index
)
<
pSupporter
->
numOfTags
)
{
while
((
*
index
)
<
pSupporter
->
numOfTags
)
{
if
(
pSupporter
->
pTagSchema
[
*
index
].
bytes
==
pSchema
->
bytes
&&
if
(
pSupporter
->
pTagSchema
[
*
index
].
bytes
==
pSchema
->
bytes
&&
pSupporter
->
pTagSchema
[
*
index
].
type
==
pSchema
->
type
&&
pSupporter
->
pTagSchema
[
*
index
].
type
==
pSchema
->
type
&&
strcmp
(
pSupporter
->
pTagSchema
[
*
index
].
name
,
pSchema
->
name
)
==
0
)
{
pSupporter
->
pTagSchema
[
*
index
].
colId
==
pSchema
->
colId
)
{
break
;
break
;
}
else
{
}
else
{
(
*
offset
)
+=
pSupporter
->
pTagSchema
[(
*
index
)
++
].
bytes
;
(
*
offset
)
+=
pSupporter
->
pTagSchema
[(
*
index
)
++
].
bytes
;
...
@@ -1174,7 +1342,7 @@ static void getTagColumnInfo(SSyntaxTreeFilterSupporter* pSupporter, SSchema* pS
...
@@ -1174,7 +1342,7 @@ static void getTagColumnInfo(SSyntaxTreeFilterSupporter* pSupporter, SSchema* pS
}
}
void
filterPrepare
(
void
*
expr
,
void
*
param
)
{
void
filterPrepare
(
void
*
expr
,
void
*
param
)
{
tExprNode
*
pExpr
=
(
tExprNode
*
)
expr
;
tExprNode
*
pExpr
=
(
tExprNode
*
)
expr
;
if
(
pExpr
->
_node
.
info
!=
NULL
)
{
if
(
pExpr
->
_node
.
info
!=
NULL
)
{
return
;
return
;
}
}
...
@@ -1184,7 +1352,7 @@ void filterPrepare(void* expr, void* param) {
...
@@ -1184,7 +1352,7 @@ void filterPrepare(void* expr, void* param) {
tQueryInfo
*
pInfo
=
pExpr
->
_node
.
info
;
tQueryInfo
*
pInfo
=
pExpr
->
_node
.
info
;
S
SyntaxTreeFilterSupporter
*
pSupporter
=
(
SSyntaxTreeFilter
Supporter
*
)
param
;
S
ExprTreeSupporter
*
pSupporter
=
(
SExprTree
Supporter
*
)
param
;
tVariant
*
pCond
=
pExpr
->
_node
.
pRight
->
pVal
;
tVariant
*
pCond
=
pExpr
->
_node
.
pRight
->
pVal
;
SSchema
*
pSchema
=
pExpr
->
_node
.
pLeft
->
pSchema
;
SSchema
*
pSchema
=
pExpr
->
_node
.
pLeft
->
pSchema
;
...
@@ -1194,10 +1362,10 @@ void filterPrepare(void* expr, void* param) {
...
@@ -1194,10 +1362,10 @@ void filterPrepare(void* expr, void* param) {
assert
((
offset
>=
0
&&
offset
<
TSDB_MAX_TAGS_LEN
)
||
(
offset
==
TSDB_TBNAME_COLUMN_INDEX
));
assert
((
offset
>=
0
&&
offset
<
TSDB_MAX_TAGS_LEN
)
||
(
offset
==
TSDB_TBNAME_COLUMN_INDEX
));
pInfo
->
sch
=
*
pSchema
;
pInfo
->
sch
=
*
pSchema
;
pInfo
->
colI
d
x
=
i
;
pInfo
->
colI
nde
x
=
i
;
pInfo
->
optr
=
pExpr
->
_node
.
optr
;
pInfo
->
optr
=
pExpr
->
_node
.
optr
;
pInfo
->
offset
=
offset
;
pInfo
->
offset
=
offset
;
pInfo
->
compare
=
getFilterComparator
(
pSchema
->
type
,
pCond
->
nType
,
pInfo
->
optr
);
// pInfo->compare
= getFilterComparator(pSchema->type, pCond->nType, pInfo->optr);
tVariantAssign
(
&
pInfo
->
q
,
pCond
);
tVariantAssign
(
&
pInfo
->
q
,
pCond
);
tVariantTypeSetType
(
&
pInfo
->
q
,
pInfo
->
sch
.
type
);
tVariantTypeSetType
(
&
pInfo
->
q
,
pInfo
->
sch
.
type
);
...
@@ -1216,7 +1384,7 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
...
@@ -1216,7 +1384,7 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
ret
=
pInfo
->
compare
(
val
,
pInfo
->
q
.
pz
);
ret
=
pInfo
->
compare
(
val
,
pInfo
->
q
.
pz
);
}
else
{
}
else
{
tVariant
t
=
{
0
};
tVariant
t
=
{
0
};
tVariantCreateFromBinary
(
&
t
,
val
,
(
uint32_t
)
pInfo
->
sch
.
bytes
,
type
);
tVariantCreateFromBinary
(
&
t
,
val
,
(
uint32_t
)
pInfo
->
sch
.
bytes
,
type
);
ret
=
pInfo
->
compare
(
&
t
.
i64Key
,
&
pInfo
->
q
.
i64Key
);
ret
=
pInfo
->
compare
(
&
t
.
i64Key
,
&
pInfo
->
q
.
i64Key
);
}
}
...
@@ -1228,10 +1396,10 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
...
@@ -1228,10 +1396,10 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
case
TSDB_RELATION_NOT_EQUAL
:
{
case
TSDB_RELATION_NOT_EQUAL
:
{
return
ret
!=
0
;
return
ret
!=
0
;
}
}
case
TSDB_RELATION_
LARGE
_EQUAL
:
{
case
TSDB_RELATION_
GREATER
_EQUAL
:
{
return
ret
>=
0
;
return
ret
>=
0
;
}
}
case
TSDB_RELATION_
LARGE
:
{
case
TSDB_RELATION_
GREATER
:
{
return
ret
>
0
;
return
ret
>
0
;
}
}
case
TSDB_RELATION_LESS_EQUAL
:
{
case
TSDB_RELATION_LESS_EQUAL
:
{
...
@@ -1250,59 +1418,55 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
...
@@ -1250,59 +1418,55 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
return
true
;
return
true
;
}
}
static
int32_t
doQueryTableList
(
STable
*
pSTable
,
SArray
*
pRes
,
const
char
*
pCond
)
{
static
int32_t
doQueryTableList
(
STable
*
pSTable
,
SArray
*
pRes
,
tExprNode
*
pExpr
)
{
// STColumn* stcol = schemaColAt(pSTable->tagSchema, 0);
// query according to the binary expression
STSchema
*
pSchema
=
pSTable
->
tagSchema
;
SSchema
*
schema
=
calloc
(
schemaNCols
(
pSchema
),
sizeof
(
SSchema
));
for
(
int32_t
i
=
0
;
i
<
schemaNCols
(
pSchema
);
++
i
)
{
schema
[
i
].
colId
=
schemaColAt
(
pSchema
,
i
)
->
colId
;
schema
[
i
].
type
=
schemaColAt
(
pSchema
,
i
)
->
type
;
schema
[
i
].
bytes
=
schemaColAt
(
pSchema
,
i
)
->
bytes
;
}
tExprNode
*
pExpr
=
NULL
;
SExprTreeSupporter
s
=
{.
pTagSchema
=
schema
,
.
numOfTags
=
schemaNCols
(
pSTable
->
tagSchema
)};
// tSQLBinaryExprFromString(&pExpr, stcol, schemaNCols(pSTable->tagSchema), (char*) pCond, strlen(pCond));
// failed to build expression, no result, return immediately
SBinaryFilterSupp
supp
=
{
if
(
pExpr
==
NULL
)
{
.
fp
=
(
__result_filter_fn_t
)
tSkipListNodeFilterCallback
,
.
setupInfoFn
=
filterPrepare
,
.
pExtInfo
=
&
s
};
mError
(
"table:%"
PRIu64
", no result returned, error in super table query expression:%s"
,
pSTable
->
tableId
.
uid
,
pCond
);
tfree
(
pCond
);
return
TSDB_CODE_OPS_NOT_SUPPORT
;
SArray
*
pTableList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
}
// query according to the binary expression
tExprTreeTraverse
(
pExpr
,
pSTable
->
pIndex
,
pTableList
,
&
supp
);
// SSyntaxTreeFilterSupporter s = {.pTagSchema = stcol, .numOfTags = schemaNCols(pSTable->tagSchema)};
tExprTreeDestroy
(
&
pExpr
,
destroyHelper
);
//
// SBinaryFilterSupp supp = {
// .fp = (__result_filter_fn_t)tSkipListNodeFilterCallback,
// .setupInfoFn = (__do_filter_suppl_fn_t)filterPrepare,
// .pExtInfo = &s
// };
//
// tSQLBinaryExprTraverse(pExpr, pSTable->pIndex, pRes, &supp);
// tExprTreeDestroy(&pExpr, tSQLListTraverseDestroyInfo);
//
// tansformQueryResult(pRes);
convertQueryResult
(
pRes
,
pTableList
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SArray
*
tsdbQueryTableList
(
tsdb_repo_t
*
tsdb
,
int64_t
uid
,
const
wchar_t
*
pTagCond
,
size_t
len
)
{
int32_t
tsdbQueryTags
(
tsdb_repo_t
*
tsdb
,
int64_t
uid
,
const
char
*
pTagCond
,
size_t
len
,
SArray
*
res
)
{
// no condition, all tables created according to the stable will involved in querying
if
(
pTagCond
==
NULL
||
len
==
0
)
{
// no condition, all tables created according to this stable are involved
SArray
*
result
=
taosArrayInit
(
8
,
POINTER_BYTES
);
return
getAllTableIdList
(
tsdb
,
uid
,
res
);
}
if
(
pTagCond
==
NULL
||
wcslen
(
pTagCond
)
==
0
)
{
return
createTableIdArrayList
(
tsdb
,
uid
);
}
else
{
char
*
str
=
convertTagQueryStr
(
pTagCond
,
len
);
STable
*
pSTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
STable
*
pSTable
=
tsdbGetTableByUid
(
tsdbGetMeta
(
tsdb
),
uid
);
assert
(
pSTable
!=
NULL
);
assert
(
pSTable
!=
NULL
);
doQueryTableList
(
pSTable
,
result
,
str
);
tExprNode
*
pExprNode
=
NULL
;
return
result
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
// failed to build expression, no result, return immediately
if
((
ret
=
exprTreeFromBinary
(
pTagCond
,
len
,
&
pExprNode
)
!=
TSDB_CODE_SUCCESS
)
||
(
pExprNode
==
NULL
))
{
dError
(
"stable:%"
PRIu64
", failed to deserialize expression tree, error exists"
,
uid
);
return
ret
;
}
}
return
doQueryTableList
(
pSTable
,
res
,
pExprNode
);
}
}
void
tsdbCleanupQueryHandle
(
tsdb_query_handle_t
queryHandle
)
{
void
tsdbCleanupQueryHandle
(
tsdb_query_handle_t
queryHandle
)
{
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
queryHandle
;
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
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
);
tSkipListDestroyIter
(
pTableCheckInfo
->
iter
);
...
@@ -1313,20 +1477,19 @@ void tsdbCleanupQueryHandle(tsdb_query_handle_t queryHandle) {
...
@@ -1313,20 +1477,19 @@ void tsdbCleanupQueryHandle(tsdb_query_handle_t queryHandle) {
tfree
(
pTableCheckInfo
->
pDataCols
);
tfree
(
pTableCheckInfo
->
pDataCols
);
tfree
(
pTableCheckInfo
->
pCompInfo
);
tfree
(
pTableCheckInfo
->
pCompInfo
);
tfree
(
pTableCheckInfo
->
compIndex
);
}
}
taosArrayDestroy
(
pQueryHandle
->
pTableCheckInfo
);
taosArrayDestroy
(
pQueryHandle
->
pTableCheckInfo
);
tfree
(
pQueryHandle
->
compIndex
);
size_t
cols
=
taosArrayGetSize
(
pQueryHandle
->
pColumns
);
size_t
cols
=
taosArrayGetSize
(
pQueryHandle
->
pColumns
);
for
(
int32_t
i
=
0
;
i
<
cols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
cols
;
++
i
)
{
SColumnInfoEx
*
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
SColumnInfoEx
*
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
tfree
(
pColInfo
->
pData
);
tfree
(
pColInfo
->
pData
);
}
}
taosArrayDestroy
(
pQueryHandle
->
pColumns
);
taosArrayDestroy
(
pQueryHandle
->
pColumns
);
tfree
(
pQueryHandle
->
unzipBuffer
);
tfree
(
pQueryHandle
->
pDataBlockInfo
);
tfree
(
pQueryHandle
->
secondaryUnzipBuffer
);
tfree
(
pQueryHandle
);
tfree
(
pQueryHandle
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录