Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
3f9d5cca
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
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
此差异已折叠。
点击以展开。
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
);
if
(
pTableMetaInfo
->
pTableMeta
)
{
rpcMsg
->
code
=
tscRenewMeterMeta
(
pSql
,
pTableMetaInfo
->
name
);
tscSendMsgToServer
(
pSql
);
}
if
(
pTableMetaInfo
->
pTableMeta
)
{
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) {
}
}
}
}
pSql
->
retry
=
0
;
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
;
}
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,14 +774,14 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -760,14 +774,14 @@ 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
);
pSqlFuncExpr
->
numOfParams
=
htons
(
pExpr
->
numOfParams
);
pSqlFuncExpr
->
numOfParams
=
htons
(
pExpr
->
numOfParams
);
...
@@ -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
);
pMsg
+=
pCond
->
len
;
if
(
!
ret
)
{
tscError
(
"%p mbs to ucs4 failed:%d"
,
pSql
,
tsGetSTableQueryCondPos
(
pTagCond
,
pTableMeta
->
uid
));
return
0
;
}
pQueryMsg
->
tagCondLen
=
htons
(
condLen
);
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
,
pTagCond
->
numOfTagCond
+=
1
;
};
cond
.
cond
=
tbufGetData
(
pBuf
,
true
);
if
(
pTagCond
->
pCond
==
NULL
)
{
pTagCond
->
pCond
=
taosArrayInit
(
3
,
sizeof
(
SCond
));
}
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
->
cond
[
i
].
cond
!=
NULL
)
{
if
(
src
->
pCond
==
NULL
)
{
dest
->
cond
[
i
].
cond
=
strdup
(
src
->
cond
[
i
].
cond
);
return
;
}
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
->
cond
[
i
].
uid
=
src
->
cond
[
i
].
uid
;
taosArrayPush
(
dest
->
pCond
,
&
c
)
;
}
}
dest
->
relType
=
src
->
relType
;
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
;
...
@@ -1900,6 +1933,10 @@ STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
...
@@ -1900,6 +1933,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
)
{
...
@@ -1961,14 +1998,14 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
...
@@ -1961,14 +1998,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
...
@@ -670,7 +668,7 @@ typedef struct {
...
@@ -670,7 +668,7 @@ typedef struct {
typedef
struct
STableMetaMsg
{
typedef
struct
STableMetaMsg
{
int32_t
contLen
;
int32_t
contLen
;
char
tableId
[
TSDB_TABLE_ID_LEN
];
// table id
char
tableId
[
TSDB_TABLE_ID_LEN
];
// table id
char
stableId
[
TSDB_TABLE_ID_LEN
];
// stable name if it is created according to super table
char
stableId
[
TSDB_TABLE_ID_LEN
];
// stable name if it is created according to super table
uint8_t
numOfTags
;
uint8_t
numOfTags
;
uint8_t
precision
;
uint8_t
precision
;
...
...
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,12 +785,12 @@ static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSki
...
@@ -736,12 +785,12 @@ 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
;
}
}
tExprNode
*
pLeft
=
pExpr
->
_node
.
pLeft
;
tExprNode
*
pLeft
=
pExpr
->
_node
.
pLeft
;
tExprNode
*
pRight
=
pExpr
->
_node
.
pRight
;
tExprNode
*
pRight
=
pExpr
->
_node
.
pRight
;
// recursive traverse left child branch
// recursive traverse left child branch
...
@@ -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
;
}
\ No newline at end of file
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
此差异已折叠。
点击以展开。
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,8 +106,8 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
...
@@ -101,8 +106,8 @@ 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
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录