Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
b0b119
TDengine
提交
649465d7
TDengine
项目概览
b0b119
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
649465d7
编写于
4月 11, 2020
作者:
S
slguan
提交者:
GitHub
4月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1582 from taosdata/feature/query
Feature/query
上级
77cc326a
da40c925
变更
42
展开全部
隐藏空白更改
内联
并排
Showing
42 changed file
with
2087 addition
and
1655 deletion
+2087
-1655
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/dnode/src/dnodeWrite.c
src/dnode/src/dnodeWrite.c
+1
-1
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/query/tests/astTest.cpp
src/query/tests/astTest.cpp
+7
-5
src/query/tests/tsBufTest.cpp
src/query/tests/tsBufTest.cpp
+9
-9
src/util/inc/tarray.h
src/util/inc/tarray.h
+6
-0
src/util/inc/tcompare.h
src/util/inc/tcompare.h
+43
-0
src/util/inc/tskiplist.h
src/util/inc/tskiplist.h
+15
-9
src/util/inc/tutil.h
src/util/inc/tutil.h
+0
-6
src/util/src/tarray.c
src/util/src/tarray.c
+15
-0
src/util/src/tcompare.c
src/util/src/tcompare.c
+192
-0
src/util/src/tglobalcfg.c
src/util/src/tglobalcfg.c
+33
-27
src/util/src/tskiplist.c
src/util/src/tskiplist.c
+140
-257
src/util/src/tutil.c
src/util/src/tutil.c
+2
-2
src/util/tests/skiplistTest.cpp
src/util/tests/skiplistTest.cpp
+1
-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
浏览文件 @
649465d7
...
...
@@ -24,6 +24,7 @@ extern "C" {
* @date 2018/09/30
*/
#include "os.h"
#include "tbuffer.h"
#include "qextbuffer.h"
#include "taosdef.h"
#include "tscSecondaryMerge.h"
...
...
@@ -176,8 +177,8 @@ void tscIncStreamExecutionCount(void* pStream);
bool
tscValidateColumnId
(
STableMetaInfo
*
pTableMetaInfo
,
int32_t
colId
);
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
SCond
*
tsGetSTableQueryCond
Pos
(
STagCond
*
pCond
,
uint64_t
tableIndex
);
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
const
char
*
str
);
SCond
*
tsGetSTableQueryCond
(
STagCond
*
pCond
,
uint64_t
uid
);
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
*
pBuf
);
void
tscTagCondCopy
(
STagCond
*
dest
,
const
STagCond
*
src
);
void
tscTagCondRelease
(
STagCond
*
pCond
);
...
...
@@ -199,7 +200,7 @@ int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQuer
STableMetaInfo
*
tscGetMeterMetaInfoByUid
(
SQueryInfo
*
pQueryInfo
,
uint64_t
uid
,
int32_t
*
index
);
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
);
STableMetaInfo
*
tscAddEmptyMetaInfo
(
SQueryInfo
*
pQueryInfo
);
int32_t
tscAddSubqueryInfo
(
SSqlCmd
*
pCmd
);
...
...
src/client/inc/tsclient.h
浏览文件 @
649465d7
...
...
@@ -43,7 +43,7 @@ struct SSqlInfo;
typedef
struct
SSqlGroupbyExpr
{
int16_t
tableIndex
;
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
orderType
;
// order by type: asc/desc
}
SSqlGroupbyExpr
;
...
...
@@ -86,7 +86,7 @@ typedef struct STableMetaInfo {
/* the structure for sql function in select clause */
typedef
struct
SSqlExpr
{
char
aliasName
[
TSDB_COL_NAME_LEN
];
// as aliasName
SColIndex
Ex
colInfo
;
SColIndex
colInfo
;
int64_t
uid
;
// refactor use the pointer
int16_t
functionId
;
// function id in aAgg array
int16_t
resType
;
// return value type
...
...
@@ -141,6 +141,7 @@ struct SLocalReducer;
typedef
struct
SCond
{
uint64_t
uid
;
int32_t
len
;
// length of tag query condition data
char
*
cond
;
}
SCond
;
...
...
@@ -167,8 +168,7 @@ typedef struct STagCond {
SJoinInfo
joinInfo
;
// for different table, the query condition must be seperated
SCond
cond
[
TSDB_MAX_JOIN_TABLE_NUM
];
int16_t
numOfTagCond
;
SArray
*
pCond
;
}
STagCond
;
typedef
struct
SParamInfo
{
...
...
src/client/src/tscAsync.c
浏览文件 @
649465d7
...
...
@@ -464,13 +464,15 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
return
;
}
else
{
// normal async query continues
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
);
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
assert
(
code
==
TSDB_CODE_SUCCESS
);
if
(
pTableMetaInfo
->
pTableMeta
)
{
// todo update the submit message according to the new table meta
// 1. table uid, 2. ip address
code
=
tscSendMsgToServer
(
pSql
);
if
(
code
==
TSDB_CODE_SUCCESS
)
return
;
}
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
649465d7
...
...
@@ -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
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
;
}
...
...
@@ -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
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
BLK_DATA_NO_NEEDED
;
}
...
...
@@ -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
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
BLK_DATA_NO_NEEDED
;
}
...
...
@@ -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
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
BLK_DATA_NO_NEEDED
;
}
...
...
@@ -1483,7 +1483,7 @@ static bool first_last_function_setup(SQLFunctionCtx *pCtx) {
// todo opt for null block
static
void
first_function
(
SQLFunctionCtx
*
pCtx
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
;
}
...
...
@@ -1513,7 +1513,7 @@ static void first_function(SQLFunctionCtx *pCtx) {
}
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
;
}
...
...
@@ -1561,7 +1561,7 @@ static void first_dist_function(SQLFunctionCtx *pCtx) {
* 1. data block that are not loaded
* 2. scan data files in desc order
*/
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
;
}
...
...
@@ -1596,7 +1596,7 @@ static void first_dist_function_f(SQLFunctionCtx *pCtx, int32_t index) {
return
;
}
if
(
pCtx
->
order
==
TS
QL_SO
_DESC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_DESC
)
{
return
;
}
...
...
@@ -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)
*/
static
void
last_function
(
SQLFunctionCtx
*
pCtx
)
{
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
;
}
...
...
@@ -1683,7 +1683,7 @@ static void last_function(SQLFunctionCtx *pCtx) {
}
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
;
}
...
...
@@ -1730,7 +1730,7 @@ static void last_dist_function(SQLFunctionCtx *pCtx) {
* 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
*/
if
(
pCtx
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCtx
->
order
==
TS
DB_ORDER
_ASC
)
{
return
;
}
...
...
@@ -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
* 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
;
}
...
...
@@ -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
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
);
}
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
);
}
...
...
@@ -2449,7 +2449,7 @@ static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
int32_t
orderIdx
=
0
;
// 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
=
tMemBucketCreate
(
1024
,
MAX_AVAILABLE_BUFFER_SIZE
,
pCtx
->
inputBytes
,
pCtx
->
inputType
,
pDesc
);
...
...
@@ -2916,7 +2916,7 @@ static void col_project_function(SQLFunctionCtx *pCtx) {
INC_INIT_VAL
(
pCtx
,
pCtx
->
size
);
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
);
}
else
{
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
...
...
@@ -3011,7 +3011,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
int32_t
notNullElems
=
0
;
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
;
...
...
@@ -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
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
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
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
...
@@ -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
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
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
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
...
@@ -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
pCtx
->
param
[
1
].
dKey
=
pData
[
i
];
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
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
pOutput
+=
1
;
...
...
@@ -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
pCtx
->
param
[
1
].
dKey
=
pData
[
i
];
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
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
...
@@ -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
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
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
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
pOutput
+=
1
;
...
...
@@ -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
pCtx
->
param
[
1
].
i64Key
=
pData
[
i
];
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
;
*
pTimestamp
=
pCtx
->
ptsList
[
i
];
...
...
@@ -3298,17 +3298,17 @@ char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
SArithmeticSupport
*
pSupport
=
(
SArithmeticSupport
*
)
param
;
SSqlFunctionExpr
*
pExpr
=
pSupport
->
pExpr
;
int32_t
colIndex
InBuf
=
-
1
;
int32_t
colIndex
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pExpr
->
binExprInfo
.
numOfCols
;
++
i
)
{
if
(
colId
==
pExpr
->
binExprInfo
.
pReqColumns
[
i
].
colId
)
{
colIndex
InBuf
=
pExpr
->
binExprInfo
.
pReqColumns
[
i
].
colIdxInBuf
;
colIndex
=
pExpr
->
binExprInfo
.
pReqColumns
[
i
].
colIndex
;
break
;
}
}
assert
(
colIndex
InBuf
>=
0
&&
colId
>=
0
);
return
pSupport
->
data
[
colIndex
InBuf
]
+
pSupport
->
offset
*
pSupport
->
elemSize
[
colIndexInBuf
];
assert
(
colIndex
>=
0
&&
colId
>=
0
);
return
pSupport
->
data
[
colIndex
]
+
pSupport
->
offset
*
pSupport
->
elemSize
[
colIndex
];
}
static
void
arithmetic_function
(
SQLFunctionCtx
*
pCtx
)
{
...
...
@@ -4327,7 +4327,7 @@ static void ts_comp_function(SQLFunctionCtx *pCtx) {
const
char
*
input
=
GET_INPUT_CHAR
(
pCtx
);
// 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
);
}
else
{
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
...
...
src/client/src/tscLocal.c
浏览文件 @
649465d7
...
...
@@ -240,7 +240,7 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
pCmd
->
numOfCols
=
numOfCols
;
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
);
rowLen
+=
TSDB_COL_NAME_LEN
;
...
...
@@ -322,7 +322,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
STableIdInfo *pSidExt = tscGetMeterSidInfo(pSidList, j);
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;
assert((pColIndex->flag & TSDB_COL_TAG) != 0);
...
...
@@ -460,7 +460,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
pCmd
->
numOfCols
=
1
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
pQueryInfo
->
order
.
order
=
TS
QL_SO
_ASC
;
pQueryInfo
->
order
.
order
=
TS
DB_ORDER
_ASC
;
tscClearFieldInfo
(
&
pQueryInfo
->
fieldsInfo
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
649465d7
此差异已折叠。
点击以展开。
src/client/src/tscSecondaryMerge.c
浏览文件 @
649465d7
...
...
@@ -45,7 +45,7 @@ int32_t treeComparator(const void *pLeft, const void *pRight, void *param) {
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
,
pParam
->
numOfElems
,
pLocalData
[
pRightIdx
]
->
rowIdx
,
pLocalData
[
pRightIdx
]
->
filePage
.
data
);
}
else
{
...
...
@@ -652,7 +652,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
exprsInfo
.
numOfExprs
;
++
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
type
=
-
1
;
...
...
@@ -990,7 +990,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
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
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
int16_t
offset
=
getColumnModelOffset
(
pLocalReducer
->
resColModel
,
i
);
...
...
@@ -1168,7 +1168,7 @@ bool needToMerge(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer, tFilePage
}
else
{
tOrderDescriptor
*
pDesc
=
pLocalReducer
->
pDesc
;
if
(
pDesc
->
orderIdx
.
numOfCols
>
0
)
{
if
(
pDesc
->
tsOrder
==
TS
QL_SO
_ASC
)
{
// asc
if
(
pDesc
->
tsOrder
==
TS
DB_ORDER
_ASC
)
{
// asc
// todo refactor comparator
ret
=
compare_a
(
pLocalReducer
->
pDesc
,
1
,
0
,
pLocalReducer
->
prevRowOfInput
,
1
,
0
,
tmpBuffer
->
data
);
}
else
{
// desc
...
...
src/client/src/tscServer.c
浏览文件 @
649465d7
...
...
@@ -37,12 +37,25 @@ int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0};
int
(
*
tscProcessMsgRsp
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
);
void
tscProcessActivityTimer
(
void
*
handle
,
void
*
tmrId
);
int
tscKeepConn
[
TSDB_SQL_MAX
]
=
{
0
};
TSKEY
tscGetSubscriptionProgress
(
void
*
sub
,
int64_t
uid
);
void
tscUpdateSubscriptionProgress
(
void
*
sub
,
int64_t
uid
,
TSKEY
ts
);
void
tscSaveSubscriptionProgress
(
void
*
sub
);
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
()
{
if
(
tscMgmtIpList
.
numOfIps
<=
0
)
{
tscError
(
"invalid mgmt IP list:%d"
,
tscMgmtIpList
.
numOfIps
);
...
...
@@ -178,17 +191,6 @@ int tscSendMsgToServer(SSqlObj *pSql) {
}
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
);
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
+
tsRpcHeadSize
,
pSql
->
cmd
.
payloadLen
);
...
...
@@ -266,19 +268,18 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
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
if
(
++
pSql
->
retry
>
pSql
->
maxRetry
)
{
tscError
(
"%p max retry %d reached, "
,
pSql
,
pSql
->
retry
);
return
;
}
rpcMsg
->
code
=
tscRenewMeterMeta
(
pSql
,
pTableMetaInfo
->
name
);
if
(
pTableMetaInfo
->
pTableMeta
)
{
tscSendMsgToServer
(
pSql
);
if
(
pSql
->
retry
>
pSql
->
maxRetry
)
{
tscError
(
"%p max retry %d reached, give up"
,
pSql
,
pSql
->
maxRetry
);
}
else
{
rpcMsg
->
code
=
tscRenewMeterMeta
(
pSql
,
pTableMetaInfo
->
name
);
if
(
pTableMetaInfo
->
pTableMeta
)
{
tscSendMsgToServer
(
pSql
);
}
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
...
...
@@ -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
;
if
(
pRes
->
code
!=
TSDB_CODE_QUERY_CANCELLED
)
{
...
...
@@ -331,7 +336,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
pMsg
->
numOfFailedBlocks
=
htonl
(
pMsg
->
numOfFailedBlocks
);
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
);
}
else
{
tscTrace
(
"%p cmd:%d code:%s rsp len:%d"
,
pSql
,
pCmd
->
command
,
tstrerror
(
pRes
->
code
),
pRes
->
rspLen
);
...
...
@@ -551,8 +556,9 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
// pSql->cmd.payloadLen is set during copying data into payload
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
;
}
...
...
@@ -645,15 +651,22 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if
(
UTIL_TABLE_IS_NOMRAL_TABLE
(
pTableMetaInfo
))
{
numOfTables
=
1
;
tscSetDnodeIpList
(
pSql
,
pTableMeta
);
pQueryMsg
->
head
.
vgId
=
htonl
(
pTableMeta
->
vgId
);
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
)
{
tscError
(
"%p error vnodeIdx:%d"
,
pSql
,
pTableMetaInfo
->
vnodeIndex
);
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
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pTableMetaInfo->vnodeIndex);
...
...
@@ -666,12 +679,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
#endif
uint32_t
vnodeId
=
1
;
tscTrace
(
"%p query on vid:%d, number of tables:%d"
,
pSql
,
vnodeId
,
numOfTables
);
pQueryMsg
->
head
.
vgId
=
htonl
(
vnodeId
);
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
.
ekey
=
htobe64
(
pQueryInfo
->
etime
);
}
else
{
...
...
@@ -761,14 +775,14 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
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
);
return
-
1
;
}
pSqlFuncExpr
->
colInfo
.
colId
=
htons
(
pExpr
->
colInfo
.
colId
);
pSqlFuncExpr
->
colInfo
.
colI
dx
=
htons
(
pExpr
->
colInfo
.
colId
x
);
pSqlFuncExpr
->
colInfo
.
flag
=
htons
(
pExpr
->
colInfo
.
flag
);
pSqlFuncExpr
->
colInfo
.
colId
=
htons
(
pExpr
->
colInfo
.
colId
);
pSqlFuncExpr
->
colInfo
.
colI
ndex
=
htons
(
pExpr
->
colInfo
.
colInde
x
);
pSqlFuncExpr
->
colInfo
.
flag
=
htons
(
pExpr
->
colInfo
.
flag
);
pSqlFuncExpr
->
functionId
=
htons
(
pExpr
->
functionId
);
pSqlFuncExpr
->
numOfParams
=
htons
(
pExpr
->
numOfParams
);
...
...
@@ -816,16 +830,13 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
orderType
=
htons
(
pGroupbyExpr
->
orderType
);
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
;
pMsg
+=
sizeof
(
pCol
->
colId
);
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
colIdx
;
pMsg
+=
sizeof
(
pCol
->
colIdx
);
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
colIdxInBuf
;
pMsg
+=
sizeof
(
pCol
->
colIdxInBuf
);
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
colIndex
;
pMsg
+=
sizeof
(
pCol
->
colIndex
);
*
((
int16_t
*
)
pMsg
)
+=
pCol
->
flag
;
pMsg
+=
sizeof
(
pCol
->
flag
);
...
...
@@ -867,34 +878,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
// serialize tag column query condition
if
(
pQueryInfo
->
tagCond
.
numOfTagCond
>
0
)
{
if
(
pQueryInfo
->
tagCond
.
pCond
!=
NULL
&&
taosArrayGetSize
(
pQueryInfo
->
tagCond
.
pCond
)
>
0
)
{
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
SCond
*
pCond
=
tsGetSTableQueryCond
Pos
(
pTagCond
,
pTableMeta
->
uid
);
SCond
*
pCond
=
tsGetSTableQueryCond
(
pTagCond
,
pTableMeta
->
uid
);
if
(
pCond
!=
NULL
&&
pCond
->
cond
!=
NULL
)
{
size_t
condLen
=
strlen
(
pCond
->
cond
)
+
1
;
pQueryMsg
->
tagCondLen
=
htons
(
pCond
->
len
);
memcpy
(
pMsg
,
pCond
->
cond
,
pCond
->
len
);
bool
ret
=
taosMbsToUcs4
(
pCond
->
cond
,
condLen
,
pMsg
,
condLen
*
TSDB_NCHAR_SIZE
);
if
(
!
ret
)
{
tscError
(
"%p mbs to ucs4 failed:%d"
,
pSql
,
tsGetSTableQueryCondPos
(
pTagCond
,
pTableMeta
->
uid
));
return
0
;
}
pQueryMsg
->
tagCondLen
=
htons
(
condLen
);
pMsg
+=
condLen
*
TSDB_NCHAR_SIZE
;
pMsg
+=
pCond
->
len
;
}
}
// tbname in/like query expression should be sent to mgmt node
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
if
(
pTagCond
->
tbnameCond
.
cond
!=
NULL
)
{
size_t
s
=
strlen
(
pTagCond
->
tbnameCond
.
cond
);
memcpy
(
pMsg
,
pTagCond
->
tbnameCond
.
cond
,
s
);
pQueryMsg
->
nameCondLen
=
htons
(
s
);
pMsg
+=
s
;
}
msgLen
=
pMsg
-
pStart
;
tscTrace
(
"%p msg built success,len:%d bytes"
,
pSql
,
msgLen
);
...
...
@@ -1547,7 +1543,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
/**
* multi
meter
meta req pkg format:
* multi
table
meta req pkg format:
* | SMgmtHead | SCMMultiTableInfoMsg | tableId0 | tableId1 | tableId2 | ......
* no used 4B
**/
...
...
@@ -1592,8 +1588,10 @@ static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
int32_t
n
=
0
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
tagCond
.
numOfTagCond
;
++
i
)
{
n
+=
strlen
(
pQueryInfo
->
tagCond
.
cond
[
i
].
cond
);
size_t
size
=
taosArrayGetSize
(
pQueryInfo
->
tagCond
.
pCond
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
assert
(
0
);
// n += strlen(pQueryInfo->tagCond.cond[i].cond);
}
int32_t
tagLen
=
n
*
TSDB_NCHAR_SIZE
;
...
...
@@ -1604,7 +1602,7 @@ static UNUSED_FUNC int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
int32_t
joinCondLen
=
(
TSDB_TABLE_ID_LEN
+
sizeof
(
int16_t
))
*
2
;
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
;
...
...
@@ -1676,13 +1674,13 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
// convert to unicode before sending to mnode for metric query
int32_t condLen = 0;
if (pTagCond->numOfTagCond > 0) {
SCond *pCond = tsGetSTableQueryCond
Pos
(pTagCond, uid);
SCond *pCond = tsGetSTableQueryCond(pTagCond, uid);
if (pCond != NULL && pCond->cond != NULL) {
condLen = strlen(pCond->cond) + 1;
bool ret = taosMbsToUcs4(pCond->cond, condLen, pMsg, condLen * TSDB_NCHAR_SIZE);
if (!ret) {
tscError("%p mbs to ucs4 failed:%s", pSql, tsGetSTableQueryCond
Pos
(pTagCond, uid));
tscError("%p mbs to ucs4 failed:%s", pSql, tsGetSTableQueryCond(pTagCond, uid));
return 0;
}
}
...
...
@@ -1729,16 +1727,16 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pElem->groupbyTagColumnList = htonl(offset);
for (int32_t j = 0; j < pQueryInfo->groupbyExpr.numOfGroupCols; ++j) {
SColIndex
Ex
*pCol = &pQueryInfo->groupbyExpr.columnInfo[j];
SColIndex
Ex *pDestCol = (SColIndexE
x *)pMsg;
SColIndex *pCol = &pQueryInfo->groupbyExpr.columnInfo[j];
SColIndex
*pDestCol = (SColInde
x *)pMsg;
pDestCol->colIdxInBuf = 0;
pDestCol->colI
dx = htons(pCol->colId
x);
pDestCol->colI
ndex = htons(pCol->colInde
x);
pDestCol->colId = htons(pDestCol->colId);
pDestCol->flag = htons(pDestCol->flag);
strncpy(pDestCol->name, pCol->name, tListLen(pCol->name));
pMsg += sizeof(SColIndex
Ex
);
pMsg += sizeof(SColIndex);
}
}
}
...
...
@@ -1899,7 +1897,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
* |...... 1B 1B 4B
**/
...
...
@@ -2131,7 +2129,8 @@ _error_clean:
// todo opt performance
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
;
...
...
@@ -2369,7 +2368,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code);
static
int32_t
getTableMetaFromMgmt
(
SSqlObj
*
pSql
,
STableMetaInfo
*
pTableMetaInfo
)
{
SSqlObj
*
pNew
=
calloc
(
1
,
sizeof
(
SSqlObj
));
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
;
}
...
...
@@ -2384,7 +2383,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf
pNew
->
cmd
.
autoCreated
=
pSql
->
cmd
.
autoCreated
;
// create table if not exists
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
);
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
...
...
@@ -2466,9 +2465,10 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) {
* 2. if get metermeta failed, still get the metermeta
*/
if
(
pTableMetaInfo
->
pTableMeta
==
NULL
||
!
tscQueryOnMetric
(
pCmd
))
{
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
pTableMetaInfo
->
pTableMeta
)
{
tscTrace
(
"%p update
meter
meta, old: numOfTags:%d, numOfCols:%d, uid:%"
PRId64
", addr:%p"
,
pSql
,
pTableMetaInfo
->
numOfTags
,
pCmd
->
numOfCols
,
pTableMetaInfo
->
pTableMeta
->
uid
,
pTableMetaInfo
->
pTableMeta
);
tscTrace
(
"%p update
table
meta, old: numOfTags:%d, numOfCols:%d, uid:%"
PRId64
", addr:%p"
,
pSql
,
tscGetNumOfTags
(
pTableMeta
),
tscGetNumOfColumns
(
pTableMeta
),
pTableMeta
->
uid
,
pTableMeta
);
}
tscWaitingForCreateTable
(
pCmd
);
...
...
@@ -2497,7 +2497,6 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
}
#if 0
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
char tagstr[TSDB_MAX_TAGS_LEN + 1] = {0};
...
...
@@ -2536,7 +2535,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
STableMetaInfo
*
pMMInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
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
)
{
...
...
src/client/src/tscSql.c
浏览文件 @
649465d7
...
...
@@ -417,7 +417,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
*
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
)
{
...
...
@@ -512,14 +512,14 @@ static void **doSetResultRowData(SSqlObj *pSql) {
}
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
);
sas
->
elemSize
[
k
]
=
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
];
free
(
sas
);
//todo optimization
...
...
src/client/src/tscSubquery.c
浏览文件 @
649465d7
...
...
@@ -26,7 +26,7 @@ typedef struct SInsertSupporter {
static
void
freeSubqueryObj
(
SSqlObj
*
pSql
);
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
;
}
else
{
return
left
>
right
;
...
...
@@ -136,8 +136,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
* 2. only one element for each tag.
*/
if
(
output1
->
tsOrder
==
-
1
)
{
output1
->
tsOrder
=
TS
QL_SO
_ASC
;
output2
->
tsOrder
=
TS
QL_SO
_ASC
;
output1
->
tsOrder
=
TS
DB_ORDER
_ASC
;
output2
->
tsOrder
=
TS
DB_ORDER
_ASC
;
}
tsBufFlush
(
output1
);
...
...
@@ -1005,8 +1005,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
int32_t
numOfSubQuerie
s
=
taosArrayGetSize
(
pTableMetaInfo
->
vgroupIdList
);
assert
(
numOfSubQuerie
s
>
0
);
pSql
->
numOfSub
s
=
taosArrayGetSize
(
pTableMetaInfo
->
vgroupIdList
);
assert
(
pSql
->
numOfSub
s
>
0
);
int32_t
ret
=
tscLocalReducerEnvCreate
(
pSql
,
&
pMemoryBuf
,
&
pDesc
,
&
pModel
,
nBufferSize
);
if
(
ret
!=
0
)
{
...
...
@@ -1017,16 +1017,15 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
return
pRes
->
code
;
}
pSql
->
pSubs
=
calloc
(
numOfSubQueries
,
POINTER_BYTES
);
pSql
->
numOfSubs
=
numOfSubQueries
;
pSql
->
pSubs
=
calloc
(
pSql
->
numOfSubs
,
POINTER_BYTES
);
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
));
pState
->
numOfTotal
=
numOfSubQuerie
s
;
pState
->
numOfTotal
=
pSql
->
numOfSub
s
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
int32_t
i
=
0
;
for
(;
i
<
numOfSubQuerie
s
;
++
i
)
{
for
(;
i
<
pSql
->
numOfSub
s
;
++
i
)
{
SRetrieveSupport
*
trs
=
(
SRetrieveSupport
*
)
calloc
(
1
,
sizeof
(
SRetrieveSupport
));
if
(
trs
==
NULL
)
{
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) {
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
);
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
);
return
pRes
->
code
;
// free all allocated resource
}
if
(
pRes
->
code
==
TSDB_CODE_QUERY_CANCELLED
)
{
tscLocalReducerEnvDestroy
(
pMemoryBuf
,
pDesc
,
pModel
,
numOfSubQuerie
s
);
tscLocalReducerEnvDestroy
(
pMemoryBuf
,
pDesc
,
pModel
,
pSql
->
numOfSub
s
);
doCleanupSubqueries
(
pSql
,
i
,
pState
);
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
];
SRetrieveSupport
*
pSupport
=
pSub
->
param
;
...
...
@@ -1450,7 +1449,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
);
atomic_val_compare_exchange_32
(
&
pState
->
code
,
0
,
code
);
}
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
);
if
(
pNew
==
NULL
)
{
...
...
src/client/src/tscUtil.c
浏览文件 @
649465d7
...
...
@@ -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
SCond
*
cond
=
tsGetSTableQueryCond
Pos
(
pTagCond
,
uid
);
SCond
*
cond
=
tsGetSTableQueryCond
(
pTagCond
,
uid
);
char
join
[
512
]
=
{
0
};
if
(
pTagCond
->
joinInfo
.
hasJoin
)
{
...
...
@@ -92,28 +92,41 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
free
(
tmp
);
}
SCond
*
tsGetSTableQueryCondPos
(
STagCond
*
pTagCond
,
uint64_t
uid
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_MAX_JOIN_TABLE_NUM
;
++
i
)
{
if
(
uid
==
pTagCond
->
cond
[
i
].
uid
)
{
return
&
pTagCond
->
cond
[
i
];
SCond
*
tsGetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
)
{
if
(
pTagCond
->
pCond
==
NULL
)
{
return
NULL
;
}
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
;
}
// todo refactor by using SArray
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
const
char
*
str
)
{
size_t
len
=
strlen
(
str
);
if
(
len
==
0
)
{
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
*
pBuf
)
{
if
(
tbufTell
(
pBuf
)
==
0
)
{
return
;
}
SCond
*
pDest
=
&
pTagCond
->
cond
[
pTagCond
->
numOfTagCond
];
pDest
->
uid
=
uid
;
pDest
->
cond
=
strdup
(
str
);
pTagCond
->
numOfTagCond
+=
1
;
SCond
cond
=
{
.
uid
=
uid
,
.
len
=
tbufTell
(
pBuf
),
.
cond
=
NULL
,
};
cond
.
cond
=
tbufGetData
(
pBuf
,
true
);
if
(
pTagCond
->
pCond
==
NULL
)
{
pTagCond
->
pCond
=
taosArrayInit
(
3
,
sizeof
(
SCond
));
}
taosArrayPush
(
pTagCond
->
pCond
,
&
cond
);
}
bool
tscQueryOnMetric
(
SSqlCmd
*
pCmd
)
{
...
...
@@ -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
->
resBytes
=
size
;
pExpr
->
interResBytes
=
interSize
;
...
...
@@ -1207,7 +1220,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
pExpr
->
functionId
=
functionId
;
pExpr
->
colInfo
.
colI
d
x
=
srcColumnIndex
;
pExpr
->
colInfo
.
colI
nde
x
=
srcColumnIndex
;
pExpr
->
colInfo
.
colId
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
srcColumnIndex
)
->
colId
;
pExpr
->
resType
=
type
;
...
...
@@ -1642,26 +1655,46 @@ void tscTagCondCopy(STagCond* dest, const STagCond* src) {
dest
->
tbnameCond
.
uid
=
src
->
tbnameCond
.
uid
;
memcpy
(
&
dest
->
joinInfo
,
&
src
->
joinInfo
,
sizeof
(
SJoinInfo
));
for
(
int32_t
i
=
0
;
i
<
src
->
numOfTagCond
;
++
i
)
{
if
(
src
->
cond
[
i
].
cond
!=
NULL
)
{
dest
->
cond
[
i
].
cond
=
strdup
(
src
->
cond
[
i
].
cond
);
dest
->
relType
=
src
->
relType
;
if
(
src
->
pCond
==
NULL
)
{
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
)
{
free
(
pCond
->
tbnameCond
.
cond
);
for
(
int32_t
i
=
0
;
i
<
pCond
->
numOfTagCond
;
++
i
)
{
free
(
pCond
->
cond
[
i
].
cond
);
void
tscTagCondRelease
(
STagCond
*
pTagCond
)
{
free
(
pTagCond
->
tbnameCond
.
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
)
{
...
...
@@ -1674,11 +1707,11 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo) {
if
(
TSDB_COL_IS_TAG
(
pExpr
->
colInfo
.
flag
))
{
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
;
}
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) {
tfree
(
pCmd
->
pQueryInfo
);
}
STableMetaInfo
*
tscAdd
Meter
MetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
S
SuperTableMeta
*
pMetricMeta
,
int16_t
numOfTags
,
int16_t
*
tags
)
{
STableMetaInfo
*
tscAdd
Table
MetaInfo
(
SQueryInfo
*
pQueryInfo
,
const
char
*
name
,
STableMeta
*
pTableMeta
,
S
Array
*
vgroupList
,
int16_t
numOfTags
,
int16_t
*
tags
)
{
void
*
pAlloc
=
realloc
(
pQueryInfo
->
pTableMetaInfo
,
(
pQueryInfo
->
numOfTables
+
1
)
*
POINTER_BYTES
);
if
(
pAlloc
==
NULL
)
{
return
NULL
;
...
...
@@ -1900,6 +1933,10 @@ STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
pTableMetaInfo
->
pTableMeta
=
pTableMeta
;
pTableMetaInfo
->
numOfTags
=
numOfTags
;
if
(
vgroupList
!=
NULL
)
{
pTableMetaInfo
->
vgroupIdList
=
taosArrayClone
(
vgroupList
);
}
if
(
tags
!=
NULL
)
{
memcpy
(
pTableMetaInfo
->
tagColumnIndex
,
tags
,
sizeof
(
pTableMetaInfo
->
tagColumnIndex
[
0
])
*
numOfTags
);
...
...
@@ -1910,7 +1947,7 @@ STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST
}
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
)
{
...
...
@@ -1961,14 +1998,14 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
}
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
tableIndex
);
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
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
;
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
tableIndex
);
pNew
->
pTscObj
=
pSql
->
pTscObj
;
pNew
->
signature
=
pNew
;
...
...
@@ -2084,12 +2121,12 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
if
(
pPrevSql
==
NULL
)
{
STableMeta
*
pTableMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
name
);
SSuperTableMeta
*
pMetricMeta
=
NULL
;
if
(
cmd
==
TSDB_SQL_SELECT
)
{
pMetricMeta
=
taosCacheAcquireByName
(
tscCacheHandle
,
key
);
}
//
SSuperTableMeta* pMetricMeta = NULL;
//
if (cmd == TSDB_SQL_SELECT) {
//
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
);
}
else
{
// transfer the ownership of pTableMeta/pMetricMeta to the newly create sql object.
// STableMetaInfo* pPrevInfo = tscGetTableMetaInfoFromCmd(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0);
...
...
@@ -2097,7 +2134,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
// STableMeta* pPrevMeterMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pTableMeta);
// 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);
}
...
...
src/dnode/src/dnodeWrite.c
浏览文件 @
649465d7
...
...
@@ -218,7 +218,7 @@ static void dnodeHandleIdleWorker(SWriteWorker *pWorker) {
int32_t
num
=
taosGetQueueNumber
(
pWorker
->
qset
);
if
(
num
>
0
)
{
usleep
(
100
);
usleep
(
100
0
);
sched_yield
();
}
else
{
taosCloseQset
(
pWorker
->
qset
);
...
...
src/inc/taosdef.h
浏览文件 @
649465d7
...
...
@@ -147,10 +147,10 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
// TODO: check if below is necessary
#define TSDB_RELATION_INVALID 0
#define TSDB_RELATION_LESS 1
#define TSDB_RELATION_
LARGE
2
#define TSDB_RELATION_
GREATER
2
#define TSDB_RELATION_EQUAL 3
#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_LIKE 7
...
...
@@ -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_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
#define TS
QL_SO
_ASC 1
#define TS
QL_SO_DESC 0
#define TS
DB_ORDER
_ASC 1
#define TS
DB_ORDER_DESC 2
#define TSDB_SESSIONS_PER_VNODE (300)
#define TSDB_SESSIONS_PER_DNODE (TSDB_SESSIONS_PER_VNODE * TSDB_MAX_VNODES)
...
...
src/inc/taosmsg.h
浏览文件 @
649465d7
...
...
@@ -358,7 +358,7 @@ typedef struct {
int32_t
vgId
;
}
SMDDropVnodeMsg
;
typedef
struct
SColIndex
Ex
{
typedef
struct
SColIndex
{
int16_t
colId
;
/*
* colIdx is the index of column in latest schema of table
...
...
@@ -368,11 +368,10 @@ typedef struct SColIndexEx {
* 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.
*/
int16_t
colIdx
;
int16_t
colIdxInBuf
;
int16_t
colIndex
;
uint16_t
flag
;
// denote if it is a tag or not
char
name
[
TSDB_COL_NAME_LEN
];
}
SColIndex
Ex
;
}
SColIndex
;
/* sql function msg, to describe the message to vnode about sql function
* operations in select clause */
...
...
@@ -380,7 +379,7 @@ typedef struct SSqlFuncExprMsg {
int16_t
functionId
;
int16_t
numOfParams
;
SColIndex
Ex
colInfo
;
SColIndex
colInfo
;
struct
ArgElem
{
int16_t
argType
;
int16_t
argBytes
;
...
...
@@ -395,7 +394,7 @@ typedef struct SSqlFuncExprMsg {
typedef
struct
SSqlBinaryExprInfo
{
struct
tExprNode
*
pBinExpr
;
/* for binary expression */
int32_t
numOfCols
;
/* binary expression involves the readed number of columns*/
SColIndex
Ex
*
pReqColumns
;
/* source column list */
SColIndex
*
pReqColumns
;
/* source column list */
}
SSqlBinaryExprInfo
;
typedef
struct
SSqlFunctionExpr
{
...
...
@@ -467,7 +466,6 @@ typedef struct {
int64_t
slidingTime
;
// value for sliding window
char
slidingTimeUnit
;
// time interval type, for revisement of interval(1d)
uint16_t
tagCondLen
;
// tag length in current query
uint16_t
nameCondLen
;
// table name in/like query expression string length
int16_t
numOfGroupCols
;
// num of group by columns
int16_t
orderByIdx
;
int16_t
orderType
;
// used in group by xx order by xxx
...
...
@@ -669,7 +667,7 @@ typedef struct {
typedef
struct
STableMetaMsg
{
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
uint8_t
numOfTags
;
uint8_t
precision
;
...
...
src/query/inc/qast.h
浏览文件 @
649465d7
...
...
@@ -48,7 +48,7 @@ typedef void (*__do_filter_suppl_fn_t)(void *, void *);
*/
typedef
struct
tQueryInfo
{
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
SSchema
sch
;
// schema of tags
tVariant
q
;
// query condition value on the specific schema, filter expression
...
...
@@ -83,7 +83,7 @@ void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len);
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
,
char
*
(
*
cb
)(
void
*
,
char
*
,
int32_t
));
...
...
@@ -94,7 +94,7 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken);
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
}
...
...
src/query/inc/queryExecutor.h
浏览文件 @
649465d7
...
...
@@ -39,7 +39,7 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
typedef
struct
SSqlGroupbyExpr
{
int16_t
tableIndex
;
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
orderType
;
// order by type: asc/desc
}
SSqlGroupbyExpr
;
...
...
@@ -63,7 +63,7 @@ typedef struct SWindowResult {
typedef
struct
SResultRec
{
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
// 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 {
int8_t
precision
;
int16_t
numOfOutputCols
;
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
;
int32_t
rowSize
;
SSqlGroupbyExpr
*
pGroupbyExpr
;
...
...
src/query/inc/sql.y
浏览文件 @
649465d7
...
...
@@ -466,9 +466,9 @@ item(A) ::= ids(X) cpxName(Y). {
}
%type sortorder {int}
sortorder(A) ::= ASC. {A = TS
QL_SO
_ASC; }
sortorder(A) ::= DESC. {A = TS
QL_SO
_DESC;}
sortorder(A) ::= . {A = TS
QL_SO
_ASC;} //default is descend order
sortorder(A) ::= ASC. {A = TS
DB_ORDER
_ASC; }
sortorder(A) ::= DESC. {A = TS
DB_ORDER
_DESC;}
sortorder(A) ::= . {A = TS
DB_ORDER
_ASC;} //default is descend order
//group by clause
%type groupby_opt {tVariantList*}
...
...
src/query/inc/tsqlfunction.h
浏览文件 @
649465d7
...
...
@@ -102,7 +102,7 @@ extern "C" {
#define QUERY_ASC_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 TOP_BOTTOM_QUERY_LIMIT 100
...
...
src/query/src/qast.c
浏览文件 @
649465d7
...
...
@@ -18,6 +18,7 @@
#include "tutil.h"
#include "tbuffer.h"
#include "qast.h"
#include "tcompare.h"
#include "qsqlparser.h"
#include "qsyntaxtreefunction.h"
#include "taosdef.h"
...
...
@@ -79,22 +80,22 @@ static void reviseBinaryExprIfNecessary(tExprNode **pLeft, tExprNode **pRight, u
* switch left and left and right hand side in expr if possible
*/
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
*
);
}
switch
(
*
optr
)
{
case
TSDB_RELATION_
LARGE
:
case
TSDB_RELATION_
GREATER
:
(
*
optr
)
=
TSDB_RELATION_LESS
;
break
;
case
TSDB_RELATION_LESS
:
(
*
optr
)
=
TSDB_RELATION_
LARGE
;
(
*
optr
)
=
TSDB_RELATION_
GREATER
;
break
;
case
TSDB_RELATION_
LARGE
_EQUAL
:
case
TSDB_RELATION_
GREATER
_EQUAL
:
(
*
optr
)
=
TSDB_RELATION_LESS_EQUAL
;
break
;
case
TSDB_RELATION_LESS_EQUAL
:
(
*
optr
)
=
TSDB_RELATION_
LARGE
_EQUAL
;
(
*
optr
)
=
TSDB_RELATION_
GREATER
_EQUAL
;
break
;
default:
;
// for other type of operations, do nothing
...
...
@@ -163,9 +164,9 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken) {
case
TK_LE
:
return
TSDB_RELATION_LESS_EQUAL
;
case
TK_GT
:
return
TSDB_RELATION_
LARGE
;
return
TSDB_RELATION_
GREATER
;
case
TK_GE
:
return
TSDB_RELATION_
LARGE
_EQUAL
;
return
TSDB_RELATION_
GREATER
_EQUAL
;
case
TK_NE
:
return
TSDB_RELATION_NOT_EQUAL
;
case
TK_AND
:
...
...
@@ -376,12 +377,12 @@ static char *tSQLOptrToString(uint8_t optr, char *dst) {
dst
+=
1
;
break
;
}
case
TSDB_RELATION_
LARGE
:
{
case
TSDB_RELATION_
GREATER
:
{
*
dst
=
'>'
;
dst
+=
1
;
break
;
}
case
TSDB_RELATION_
LARGE
_EQUAL
:
{
case
TSDB_RELATION_
GREATER
_EQUAL
:
{
*
dst
=
'>'
;
*
(
dst
+
1
)
=
'='
;
dst
+=
2
;
...
...
@@ -466,8 +467,18 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
*
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) {
// q->lowerBndRelOptr = TSDB_RELATION_
LARGE
;
// q->lowerBndRelOptr = TSDB_RELATION_
GREATER
;
// q->upperBndRelOptr = TSDB_RELATION_LESS;
//
// switch (type) {
...
...
@@ -504,60 +515,100 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
// }
//}
//static void tSQLDoFilterInitialResult(tSkipList *pSkipList, bool (*fp)(), tQueryInfo *queryColInfo,
// tQueryResultset *result) {
// // primary key filter, search according to skiplist
// if (queryColInfo->colIdx == 0 && queryColInfo->optr != TSDB_RELATION_LIKE) {
// tSKipListQueryCond q;
// setInitialValueForRangeQueryCondition(&q, queryColInfo->q.nType);
//
// switch (queryColInfo->optr) {
// case TSDB_RELATION_EQUAL: {
// result->num =
// tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, INCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
// break;
// }
// case TSDB_RELATION_NOT_EQUAL: {
// result->num =
// tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, EXCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
// break;
// }
// case TSDB_RELATION_LESS_EQUAL: {
// tVariantAssign(&q.upperBnd, &queryColInfo->q);
// q.upperBndRelOptr = queryColInfo->optr;
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
// break;
// }
// case TSDB_RELATION_LESS: {
// tVariantAssign(&q.upperBnd, &queryColInfo->q);
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
// break;
// }
// case TSDB_RELATION_LARGE: {
// tVariantAssign(&q.lowerBnd, &queryColInfo->q);
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
// break;
// }
// case TSDB_RELATION_LARGE_EQUAL: {
// tVariantAssign(&q.lowerBnd, &queryColInfo->q);
// q.lowerBndRelOptr = queryColInfo->optr;
// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
// break;
// }
// default:
// pTrace("skiplist:%p, unsupport query operator:%d", pSkipList, queryColInfo->optr);
// }
//
// tSkipListDestroyKey(&q.upperBnd);
// tSkipListDestroyKey(&q.lowerBnd);
// } else {
// /*
// * Brutal force scan the whole skiplit to find the appropriate result,
// * since the filter is not applied to indexed column.
// */
// result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, queryColInfo);
// }
//}
// todo check for malloc failure
static
int32_t
setQueryCond
(
tQueryInfo
*
queryColInfo
,
SQueryCond
*
pCond
)
{
int32_t
optr
=
queryColInfo
->
optr
;
if
(
optr
==
TSDB_RELATION_GREATER
||
optr
==
TSDB_RELATION_GREATER_EQUAL
||
optr
==
TSDB_RELATION_EQUAL
||
optr
==
TSDB_RELATION_NOT_EQUAL
)
{
pCond
->
start
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariantAssign
(
&
pCond
->
start
->
v
,
&
queryColInfo
->
q
);
pCond
->
start
->
optr
=
queryColInfo
->
optr
;
}
else
if
(
optr
==
TSDB_RELATION_LESS
||
optr
==
TSDB_RELATION_LESS_EQUAL
)
{
pCond
->
end
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariantAssign
(
&
pCond
->
end
->
v
,
&
queryColInfo
->
q
);
pCond
->
end
->
optr
=
queryColInfo
->
optr
;
}
return
TSDB_CODE_SUCCESS
;
}
static
void
tQueryOnSkipList
(
SSkipList
*
pSkipList
,
SQueryCond
*
pCond
,
int32_t
type
,
SArray
*
result
)
{
SSkipListIterator
*
iter
=
NULL
;
if
(
pCond
->
start
!=
NULL
)
{
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
&
pCond
->
start
->
v
.
i64Key
,
type
,
TSDB_ORDER_ASC
);
}
else
{
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
&
pCond
->
end
->
v
.
i64Key
,
type
,
TSDB_ORDER_DESC
);
}
__compar_fn_t
func
=
getComparFunc
(
pSkipList
->
keyInfo
.
type
,
type
);
if
(
pCond
->
start
!=
NULL
)
{
int32_t
optr
=
pCond
->
start
->
optr
;
if
(
optr
==
TSDB_RELATION_EQUAL
)
{
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
int32_t
ret
=
func
(
SL_GET_NODE_KEY
(
pSkipList
,
pNode
),
&
pCond
->
start
->
v
.
i64Key
);
if
(
ret
==
0
)
{
taosArrayPush
(
result
,
SL_GET_NODE_DATA
(
pNode
));
}
else
{
break
;
}
}
}
else
if
(
optr
==
TSDB_RELATION_GREATER
||
optr
==
TSDB_RELATION_GREATER_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_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
...
...
@@ -670,9 +721,7 @@ static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *p
tExprNode
*
pLeft
=
pExpr
->
_node
.
pLeft
;
tExprNode
*
pRight
=
pExpr
->
_node
.
pRight
;
/*
* non-leaf nodes, recursively traverse the syntax tree in the post-root order
*/
//non-leaf nodes, recursively traverse the expression tree in the post-root order
if
(
pLeft
->
nodeType
==
TSQL_NODE_EXPR
&&
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_OR
)
{
// or
if
(
filterItem
(
pLeft
,
pItem
,
param
))
{
...
...
@@ -707,7 +756,7 @@ static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *p
* @param pSchema tag schemas
* @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
);
SArray
*
array
=
taosArrayInit
(
size
,
POINTER_BYTES
);
...
...
@@ -736,12 +785,12 @@ static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSki
}
// 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
)
{
return
;
}
tExprNode
*
pLeft
=
pExpr
->
_node
.
pLeft
;
tExprNode
*
pLeft
=
pExpr
->
_node
.
pLeft
;
tExprNode
*
pRight
=
pExpr
->
_node
.
pRight
;
// recursive traverse left child branch
...
...
@@ -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.
*/
tSQLBinaryTraverseOnResult
(
pExpr
,
result
,
param
);
exprTreeTraverseImpl
(
pExpr
,
result
,
param
);
}
else
if
(
weight
==
0
)
{
/**
* 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
SArray
*
rLeft
=
taosArrayInit
(
10
,
POINTER_BYTES
);
SArray
*
rRight
=
taosArrayInit
(
10
,
POINTER_BYTES
);
t
SQLBinaryExpr
Traverse
(
pLeft
,
pSkipList
,
rLeft
,
param
);
t
SQLBinaryExpr
Traverse
(
pRight
,
pSkipList
,
rRight
,
param
);
t
ExprTree
Traverse
(
pLeft
,
pSkipList
,
rLeft
,
param
);
t
ExprTree
Traverse
(
pRight
,
pSkipList
,
rRight
,
param
);
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION_AND
)
{
// CROSS
intersect
(
rLeft
,
rRight
,
result
);
...
...
@@ -801,13 +850,13 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
assert
(
pFirst
!=
pSecond
&&
pFirst
!=
NULL
&&
pSecond
!=
NULL
);
// 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,
* 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
assert
(
pLeft
->
nodeType
==
TSQL_NODE_COL
&&
pRight
->
nodeType
==
TSQL_NODE_VALUE
);
...
...
@@ -816,8 +865,19 @@ void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *resu
if
(
pSkipList
==
NULL
)
{
tSQLListTraverseOnResult
(
pExpr
,
param
->
fp
,
result
);
}
else
{
// assert(result->num == 0);
// tSQLDoFilterInitialResult(pSkipList, param->fp, pExpr->info, result);
tQueryInfo
*
pQueryInfo
=
pExpr
->
_node
.
info
;
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) {
*
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
};
/*int32_t code =*/
tbufBeginRead
(
&
rbuf
,
pBuf
,
size
);
tExprNode
*
pExprNode
=
NULL
;
exprTreeFromBinaryImpl
(
&
pExprNode
,
&
rbuf
);
return
pExprNode
;
}
\ No newline at end of file
exprTreeFromBinaryImpl
(
pExprNode
,
&
rbuf
);
return
TSDB_CODE_SUCCESS
;
}
src/query/src/qextbuffer.c
浏览文件 @
649465d7
...
...
@@ -345,7 +345,7 @@ static FORCE_INLINE int32_t primaryKeyComparator(int64_t f1, int64_t f2, int32_t
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
;
}
else
{
// asc
return
(
f1
<
f2
)
?
-
1
:
1
;
...
...
@@ -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
,
int32_t
orderType
)
{
// 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
)
{
tColDataInsertSort
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
compareFn
);
...
...
src/query/src/qinterpolation.c
浏览文件 @
649465d7
...
...
@@ -20,7 +20,7 @@
#include "taosmsg.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
)
{
if
(
timeRange
==
0
)
{
...
...
@@ -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
)
{
if
(
order
==
TS
QL_SO
_ASC
)
{
if
(
order
==
TS
DB_ORDER
_ASC
)
{
return
ekey
;
}
else
{
return
taosGetIntervalStartTimestamp
(
ekey
,
timeInterval
,
intervalTimeUnit
,
precision
);
...
...
src/query/src/qpercentile.c
浏览文件 @
649465d7
...
...
@@ -83,7 +83,7 @@ static tFilePage *loadIntoBucketFromDisk(tMemBucket *pMemBucket, int32_t segIdx,
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
return
buffer
;
...
...
src/query/src/qsyntaxtreefunction.c
浏览文件 @
649465d7
...
...
@@ -21,8 +21,8 @@
#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 step = ((_ord) == TS
QL_SO
_ASC) ? 1 : -1; \
int32_t i = ((_ord) == TS
DB_ORDER
_ASC) ? 0 : MAX(len1, len2) - 1; \
int32_t step = ((_ord) == TS
DB_ORDER
_ASC) ? 1 : -1; \
\
if ((len1) == (len2)) { \
for (; i < (len2) && i >= 0; i += step, (out) += 1) { \
...
...
@@ -53,8 +53,8 @@
#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 step = (_ord == TS
QL_SO
_ASC) ? 1 : -1; \
int32_t i = (_ord == TS
DB_ORDER
_ASC) ? 0 : MAX(len1, len2) - 1; \
int32_t step = (_ord == TS
DB_ORDER
_ASC) ? 1 : -1; \
\
if (len1 == (len2)) { \
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
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
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
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
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
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
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
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
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
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
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
double
*
pRight
=
(
double
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TS
QL_SO
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
QL_SO
_ASC
)
?
1
:
-
1
;
int32_t
i
=
(
order
==
TS
DB_ORDER
_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TS
DB_ORDER
_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
...
...
src/query/src/qtsbuf.c
浏览文件 @
649465d7
...
...
@@ -33,11 +33,11 @@ STSBuf* tsBufCreate(bool autoDelete) {
}
// 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
);
tsBufResetPos
(
pTSBuf
);
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
pTSBuf
->
autoDelete
=
autoDelete
;
pTSBuf
->
tsOrder
=
-
1
;
...
...
@@ -88,7 +88,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
// check the ts order
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);
tsBufDestory
(
pTSBuf
);
return
NULL
;
...
...
@@ -118,7 +118,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
tsBufResetPos
(
pTSBuf
);
// ascending by default
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
pTSBuf
->
autoDelete
=
autoDelete
;
...
...
@@ -274,7 +274,7 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
memset
(
pBlock
,
0
,
sizeof
(
STSBlock
));
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
* the end of each comp data block
...
...
@@ -303,7 +303,7 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) {
fread
(
&
pBlock
->
padding
,
sizeof
(
pBlock
->
padding
),
1
,
pTSBuf
->
f
);
// 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
);
int64_t
r
=
fseek
(
pTSBuf
->
f
,
-
offset
,
SEEK_CUR
);
UNUSED
(
r
);
...
...
@@ -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
);
if
(
lastKey
>
*
(
TSKEY
*
)
pData
)
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_DESC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_DESC
;
}
else
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_ASC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_ASC
;
}
}
else
if
(
len
>
TSDB_KEYSIZE
)
{
// 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) {
TSKEY
k2
=
*
(
TSKEY
*
)(
pData
+
TSDB_KEYSIZE
);
if
(
k1
<
k2
)
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_ASC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_ASC
;
}
else
if
(
k1
>
k2
)
{
pTSBuf
->
tsOrder
=
TS
QL_SO
_DESC
;
pTSBuf
->
tsOrder
=
TS
DB_ORDER
_DESC
;
}
else
{
// todo handle error
}
...
...
@@ -432,13 +432,13 @@ static int32_t tsBufFindBlock(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo, int
bool
decomp
=
false
;
while
((
i
++
)
<=
blockIndex
)
{
if
(
readDataFromDisk
(
pTSBuf
,
TS
QL_SO
_ASC
,
decomp
)
==
NULL
)
{
if
(
readDataFromDisk
(
pTSBuf
,
TS
DB_ORDER
_ASC
,
decomp
)
==
NULL
)
{
return
-
1
;
}
}
// 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
;
int32_t
compBlockSize
=
pBlock
->
compLen
+
sizeof
(
pBlock
->
compLen
)
*
2
+
sizeof
(
pBlock
->
numOfElem
)
+
sizeof
(
pBlock
->
tag
);
...
...
@@ -452,7 +452,7 @@ static int32_t tsBufFindBlockByTag(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo
bool
decomp
=
false
;
int64_t
offset
=
0
;
if
(
pTSBuf
->
cur
.
order
==
TS
QL_SO
_ASC
)
{
if
(
pTSBuf
->
cur
.
order
==
TS
DB_ORDER
_ASC
)
{
offset
=
pBlockInfo
->
offset
;
}
else
{
// reversed traverse starts from the end of block
offset
=
pBlockInfo
->
offset
+
pBlockInfo
->
compLen
;
...
...
@@ -482,8 +482,8 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
}
STSCursor
*
pCur
=
&
pTSBuf
->
cur
;
if
(
pCur
->
vnodeIndex
==
vnodeIndex
&&
((
pCur
->
blockIndex
<=
blockIndex
&&
pCur
->
order
==
TS
QL_SO
_ASC
)
||
(
pCur
->
blockIndex
>=
blockIndex
&&
pCur
->
order
==
TS
QL_SO
_DESC
)))
{
if
(
pCur
->
vnodeIndex
==
vnodeIndex
&&
((
pCur
->
blockIndex
<=
blockIndex
&&
pCur
->
order
==
TS
DB_ORDER
_ASC
)
||
(
pCur
->
blockIndex
>=
blockIndex
&&
pCur
->
order
==
TS
DB_ORDER
_DESC
)))
{
int32_t
i
=
0
;
bool
decomp
=
false
;
int32_t
step
=
abs
(
blockIndex
-
pCur
->
blockIndex
);
...
...
@@ -520,7 +520,7 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
pCur
->
vnodeIndex
=
vnodeIndex
;
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
)
{
...
...
@@ -555,7 +555,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
// get the first/last position according to traverse order
if
(
pCur
->
vnodeIndex
==
-
1
)
{
if
(
pCur
->
order
==
TS
QL_SO
_ASC
)
{
if
(
pCur
->
order
==
TS
DB_ORDER
_ASC
)
{
tsBufGetBlock
(
pTSBuf
,
0
,
0
);
if
(
pTSBuf
->
block
.
numOfElem
==
0
)
{
// the whole list is empty, return
...
...
@@ -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
)
{
assert
(
pTSBuf
->
tsData
.
len
==
pTSBuf
->
block
.
numOfElem
*
TSDB_KEYSIZE
);
if
((
pCur
->
order
==
TS
QL_SO
_ASC
&&
pCur
->
tsIndex
>=
pTSBuf
->
block
.
numOfElem
-
1
)
||
(
pCur
->
order
==
TS
QL_SO
_DESC
&&
pCur
->
tsIndex
<=
0
))
{
if
((
pCur
->
order
==
TS
DB_ORDER
_ASC
&&
pCur
->
tsIndex
>=
pTSBuf
->
block
.
numOfElem
-
1
)
||
(
pCur
->
order
==
TS
DB_ORDER
_DESC
&&
pCur
->
tsIndex
<=
0
))
{
int32_t
vnodeId
=
pTSBuf
->
pData
[
pCur
->
vnodeIndex
].
info
.
vnode
;
STSVnodeBlockInfo
*
pBlockInfo
=
tsBufGetVnodeBlockInfo
(
pTSBuf
,
vnodeId
);
if
(
pBlockInfo
==
NULL
||
(
pCur
->
blockIndex
>=
pBlockInfo
->
numOfBlocks
-
1
&&
pCur
->
order
==
TS
QL_SO
_ASC
)
||
(
pCur
->
blockIndex
<=
0
&&
pCur
->
order
==
TS
QL_SO
_DESC
))
{
if
((
pCur
->
vnodeIndex
>=
pTSBuf
->
numOfVnodes
-
1
&&
pCur
->
order
==
TS
QL_SO
_ASC
)
||
(
pCur
->
vnodeIndex
<=
0
&&
pCur
->
order
==
TS
QL_SO
_DESC
))
{
if
(
pBlockInfo
==
NULL
||
(
pCur
->
blockIndex
>=
pBlockInfo
->
numOfBlocks
-
1
&&
pCur
->
order
==
TS
DB_ORDER
_ASC
)
||
(
pCur
->
blockIndex
<=
0
&&
pCur
->
order
==
TS
DB_ORDER
_DESC
))
{
if
((
pCur
->
vnodeIndex
>=
pTSBuf
->
numOfVnodes
-
1
&&
pCur
->
order
==
TS
DB_ORDER
_ASC
)
||
(
pCur
->
vnodeIndex
<=
0
&&
pCur
->
order
==
TS
DB_ORDER
_DESC
))
{
pCur
->
vnodeIndex
=
-
1
;
return
false
;
}
...
...
@@ -609,7 +609,7 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
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
);
break
;
...
...
@@ -766,7 +766,7 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
pTSBuf
->
fileSize
+=
len
;
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
=
{
.
magic
=
TS_COMP_FILE_MAGIC
,
.
numOfVnode
=
pTSBuf
->
numOfVnodes
,
.
tsOrder
=
pTSBuf
->
tsOrder
};
...
...
@@ -850,7 +850,7 @@ void tsBufDisplay(STSBuf* pTSBuf) {
printf
(
"number of vnode:%d
\n
"
,
pTSBuf
->
numOfVnodes
);
int32_t
old
=
pTSBuf
->
cur
.
order
;
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
tsBufResetPos
(
pTSBuf
);
...
...
src/query/src/queryExecutor.c
浏览文件 @
649465d7
此差异已折叠。
点击以展开。
src/query/src/sql.c
浏览文件 @
649465d7
...
...
@@ -2471,13 +2471,13 @@ static void yy_reduce(
yymsp
[
-
1
].
minor
.
yy380
=
yylhsminor
.
yy380
;
break
;
case
152
:
/* sortorder ::= ASC */
{
yymsp
[
0
].
minor
.
yy250
=
TS
QL_SO
_ASC
;
}
{
yymsp
[
0
].
minor
.
yy250
=
TS
DB_ORDER
_ASC
;
}
break
;
case
153
:
/* sortorder ::= DESC */
{
yymsp
[
0
].
minor
.
yy250
=
TS
QL_SO
_DESC
;}
{
yymsp
[
0
].
minor
.
yy250
=
TS
DB_ORDER
_DESC
;}
break
;
case
154
:
/* sortorder ::= */
{
yymsp
[
1
].
minor
.
yy250
=
TS
QL_SO
_ASC
;}
{
yymsp
[
1
].
minor
.
yy250
=
TS
DB_ORDER
_ASC
;}
break
;
case
157
:
/* grouplist ::= grouplist COMMA item */
{
...
...
src/query/tests/astTest.cpp
浏览文件 @
649465d7
...
...
@@ -255,7 +255,7 @@ static void testQueryStr(SSchema *schema, int32_t numOfCols, char *sql, tSkipLis
printf
(
"expr is: %s
\n
"
,
str
);
SArray
*
result
=
NULL
;
// t
SQLBinaryExpr
Traverse(pExpr, pSkipList, result, tSkipListNodeFilterCallback, &result);
// t
ExprTree
Traverse(pExpr, pSkipList, result, tSkipListNodeFilterCallback, &result);
// printf("the result is:%lld\n", result.num);
//
// bool findResult = false;
...
...
@@ -533,7 +533,7 @@ tExprNode* createExpr2() {
auto
*
p2
=
(
tExprNode
*
)
calloc
(
1
,
sizeof
(
tExprNode
));
p2
->
nodeType
=
TSQL_NODE_EXPR
;
p2
->
_node
.
optr
=
TSDB_RELATION_
LARGE
_EQUAL
;
p2
->
_node
.
optr
=
TSDB_RELATION_
GREATER
_EQUAL
;
p2
->
_node
.
pLeft
=
pLeft1
;
p2
->
_node
.
pRight
=
pRight1
;
p2
->
_node
.
hasPK
=
false
;
...
...
@@ -556,7 +556,8 @@ void exprSerializeTest1() {
ASSERT_TRUE
(
size
>
0
);
char
*
b
=
tbufGetData
(
&
buf
,
false
);
tExprNode
*
p2
=
exprTreeFromBinary
(
b
,
size
);
tExprNode
*
p2
=
NULL
;
exprTreeFromBinary
(
b
,
size
,
&
p2
);
ASSERT_EQ
(
p1
->
nodeType
,
p2
->
nodeType
);
ASSERT_EQ
(
p2
->
_node
.
optr
,
p1
->
_node
.
optr
);
...
...
@@ -592,7 +593,8 @@ void exprSerializeTest2() {
ASSERT_TRUE
(
size
>
0
);
char
*
b
=
tbufGetData
(
&
buf
,
false
);
tExprNode
*
p2
=
exprTreeFromBinary
(
b
,
size
);
tExprNode
*
p2
=
NULL
;
exprTreeFromBinary
(
b
,
size
,
&
p2
);
ASSERT_EQ
(
p1
->
nodeType
,
p2
->
nodeType
);
ASSERT_EQ
(
p2
->
_node
.
optr
,
p1
->
_node
.
optr
);
...
...
@@ -617,7 +619,7 @@ void exprSerializeTest2() {
ASSERT_EQ
(
c1Right
->
nodeType
,
c2Right
->
nodeType
);
ASSERT_EQ
(
c2Right
->
nodeType
,
TSQL_NODE_EXPR
);
ASSERT_EQ
(
c2Right
->
_node
.
optr
,
TSDB_RELATION_
LARGE
_EQUAL
);
ASSERT_EQ
(
c2Right
->
_node
.
optr
,
TSDB_RELATION_
GREATER
_EQUAL
);
ASSERT_EQ
(
c2Right
->
_node
.
pRight
->
pVal
->
dKey
,
91.99
);
ASSERT_EQ
(
p2
->
_node
.
hasPK
,
true
);
...
...
src/query/tests/tsBufTest.cpp
浏览文件 @
649465d7
...
...
@@ -37,7 +37,7 @@ void simpleTest() {
int64_t
*
list
=
createTsList
(
10
,
10000000
,
30
);
tsBufAppend
(
pTSBuf
,
0
,
tag
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
QL_SO
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
DB_ORDER
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
sizeof
(
int64_t
)
*
num
);
EXPECT_EQ
(
pTSBuf
->
block
.
tag
,
tag
);
...
...
@@ -65,7 +65,7 @@ void largeTSTest() {
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
EXPECT_EQ
(
pTSBuf
->
block
.
tag
,
tag
);
EXPECT_EQ
(
pTSBuf
->
numOfVnodes
,
1
);
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
QL_SO
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
DB_ORDER
_ASC
);
tsBufFlush
(
pTSBuf
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
...
...
@@ -91,7 +91,7 @@ void multiTagsTest() {
start
+=
step
*
num
;
}
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
QL_SO
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
DB_ORDER
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
,
numOfTags
-
1
);
...
...
@@ -127,7 +127,7 @@ void multiVnodeTagsTest() {
EXPECT_EQ
(
pTSBuf
->
numOfVnodes
,
j
+
1
);
}
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
QL_SO
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
DB_ORDER
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
,
numOfTags
-
1
);
...
...
@@ -167,7 +167,7 @@ void loadDataTest() {
EXPECT_EQ
(
pTSBuf
->
numOfVnodes
,
j
+
1
);
}
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
QL_SO
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TS
DB_ORDER
_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
,
numOfTags
-
1
);
...
...
@@ -252,7 +252,7 @@ void TSTraverse() {
int64_t
s
=
taosGetTimestampUs
();
printf
(
"start:%"
PRIu64
"
\n
"
,
s
);
pTSBuf
->
cur
.
order
=
TS
QL_SO
_DESC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_DESC
;
// complete reverse traverse
int32_t
x
=
0
;
...
...
@@ -263,7 +263,7 @@ void TSTraverse() {
// specify the data block with vnode and tags value
tsBufResetPos
(
pTSBuf
);
pTSBuf
->
cur
.
order
=
TS
QL_SO
_DESC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_DESC
;
int32_t
startVnode
=
1
;
int32_t
startTag
=
2
;
...
...
@@ -297,7 +297,7 @@ void TSTraverse() {
/////////////////////////////////////////////////////////////////////////////////
// traverse
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
tsBufResetPos
(
pTSBuf
);
// complete forwards traverse
...
...
@@ -308,7 +308,7 @@ void TSTraverse() {
// specify the data block with vnode and tags value
tsBufResetPos
(
pTSBuf
);
pTSBuf
->
cur
.
order
=
TS
QL_SO
_ASC
;
pTSBuf
->
cur
.
order
=
TS
DB_ORDER
_ASC
;
startVnode
=
1
;
startTag
=
2
;
...
...
src/util/inc/tarray.h
浏览文件 @
649465d7
...
...
@@ -100,6 +100,12 @@ void taosArrayRemove(SArray* pArray, size_t index);
*/
void
taosArrayCopy
(
SArray
*
pDst
,
SArray
*
pSrc
);
/**
* clone a new array
* @param pSrc
*/
SArray
*
taosArrayClone
(
SArray
*
pSrc
);
/**
* destroy array list
* @param pArray
...
...
src/util/inc/tcompare.h
0 → 100644
浏览文件 @
649465d7
/*
* 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/inc/tskiplist.h
浏览文件 @
649465d7
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef T
BAS
E_TSKIPLIST_H
#define T
BAS
E_TSKIPLIST_H
#ifndef T
DENGIN
E_TSKIPLIST_H
#define T
DENGIN
E_TSKIPLIST_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -24,10 +24,6 @@ extern "C" {
#include "taosdef.h"
#include "tarray.h"
/*
* key of each node
* todo move to as the global structure in all search codes...
*/
#define MAX_SKIP_LIST_LEVEL 15
#define SKIP_LIST_RECORD_PERFORMANCE 0
...
...
@@ -35,11 +31,11 @@ typedef char *SSkipListKey;
typedef
char
*
(
*
__sl_key_fn_t
)(
const
void
*
);
/**
* the skip list node is located in a consecutive memory area,
* the format of skip list node is as follows:
* +------------+-----------------------+------------------------+-----+------+
* | node level | forward pointer array | backward pointer array | key | data |
* +------------+-----------------------+------------------------+-----+------+
* the skiplist node is located in a consecutive memory area, key will not be copy to skip list
*/
typedef
struct
SSkipListNode
{
uint8_t
level
;
...
...
@@ -136,7 +132,8 @@ typedef struct SSkipList {
typedef
struct
SSkipListIterator
{
SSkipList
*
pSkipList
;
SSkipListNode
*
cur
;
int64_t
num
;
int32_t
step
;
// the number of nodes that have been checked already
int32_t
order
;
// order of the iterator
}
SSkipListIterator
;
/**
...
...
@@ -205,6 +202,15 @@ void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel);
*/
SSkipListIterator
*
tSkipListCreateIter
(
SSkipList
*
pSkipList
);
/**
* create skip list iterator from the given node and specified the order
* @param pSkipList
* @param pNode start position, instead of the first node in skip list
* @param order traverse order of the iterator
* @return
*/
SSkipListIterator
*
tSkipListCreateIterFromVal
(
SSkipList
*
pSkipList
,
const
char
*
val
,
int32_t
type
,
int32_t
order
);
/**
* forward the skip list iterator
* @param iter
...
...
@@ -245,4 +251,4 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode);
}
#endif
#endif // T
BAS
E_TSKIPLIST_H
#endif // T
DENGIN
E_TSKIPLIST_H
src/util/inc/tutil.h
浏览文件 @
649465d7
...
...
@@ -121,10 +121,6 @@ int64_t strnatoi(char *num, int32_t len);
char
*
strreplace
(
const
char
*
str
,
const
char
*
pattern
,
const
char
*
rep
);
#define POW2(x) ((x) * (x))
int32_t
strdequote
(
char
*
src
);
char
*
paGetToken
(
char
*
src
,
char
**
token
,
int32_t
*
tokenLen
);
void
taosMsleep
(
int32_t
mseconds
);
...
...
@@ -133,8 +129,6 @@ int32_t taosByteArrayToHexStr(char bytes[], int32_t len, char hexstr[]);
int32_t
taosHexStrToByteArray
(
char
hexstr
[],
char
bytes
[]);
int64_t
str2int64
(
char
*
str
);
int32_t
taosFileRename
(
char
*
fullPath
,
char
*
suffix
,
char
delimiter
,
char
**
dstPath
);
/**
...
...
src/util/src/tarray.c
浏览文件 @
649465d7
...
...
@@ -160,6 +160,21 @@ void taosArrayCopy(SArray* pDst, SArray* pSrc) {
pDst
->
size
=
pSrc
->
size
;
}
SArray
*
taosArrayClone
(
SArray
*
pSrc
)
{
assert
(
pSrc
!=
NULL
);
if
(
pSrc
->
size
==
0
)
{
// empty array list
return
taosArrayInit
(
8
,
pSrc
->
elemSize
);
}
SArray
*
dst
=
taosArrayInit
(
pSrc
->
size
,
pSrc
->
elemSize
);
memcpy
(
dst
->
pData
,
pSrc
->
pData
,
pSrc
->
elemSize
*
pSrc
->
size
);
dst
->
size
=
pSrc
->
size
;
return
dst
;
}
void
taosArrayDestroy
(
SArray
*
pArray
)
{
if
(
pArray
==
NULL
)
{
return
;
...
...
src/util/src/tcompare.c
0 → 100644
浏览文件 @
649465d7
#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/util/src/tglobalcfg.c
浏览文件 @
649465d7
...
...
@@ -14,13 +14,12 @@
*/
#include "os.h"
#include <locale.h>
#include "taosdef.h"
#include "taoserror.h"
#include "tglobalcfg.h"
#include "tkey.h"
#include "tlog.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tsocket.h"
#include "tsystem.h"
#include "tutil.h"
...
...
@@ -840,9 +839,8 @@ void tsReadGlobalLogConfig() {
FILE
*
fp
;
char
*
line
,
*
option
,
*
value
;
size_t
len
;
int
olen
,
vlen
;
char
fileName
[
128
]
;
char
fileName
[
PATH_MAX
]
=
{
0
}
;
mdebugFlag
=
135
;
sdbDebugFlag
=
135
;
...
...
@@ -858,22 +856,26 @@ void tsReadGlobalLogConfig() {
wordfree
(
&
full_path
);
tsReadLogOption
(
"logDir"
,
logDir
);
sprintf
(
fileName
,
"%s/taos.cfg"
,
configDir
);
fp
=
fopen
(
fileName
,
"r"
);
if
(
fp
==
NULL
)
{
printf
(
"
\n
option file:%s not found, all options are set to system
default
\n
"
,
fileName
);
printf
(
"
\n
config file:%s not found, all variables are set to
default
\n
"
,
fileName
);
return
;
}
line
=
NULL
;
size_t
len
=
1024
;
line
=
calloc
(
1
,
len
);
while
(
!
feof
(
fp
))
{
tfree
(
line
);
line
=
option
=
value
=
NULL
;
len
=
olen
=
vlen
=
0
;
memset
(
line
,
0
,
len
);
option
=
value
=
NULL
;
olen
=
vlen
=
0
;
getline
(
&
line
,
&
len
,
fp
);
if
(
line
==
NULL
)
break
;
line
[
len
-
1
]
=
0
;
paGetToken
(
line
,
&
option
,
&
olen
);
if
(
olen
==
0
)
continue
;
option
[
olen
]
=
0
;
...
...
@@ -892,25 +894,26 @@ void tsReadGlobalLogConfig() {
bool
tsReadGlobalConfig
()
{
tsInitGlobalConfig
();
FILE
*
fp
;
char
*
line
,
*
option
,
*
value
,
*
value1
;
size_t
len
;
int
olen
,
vlen
,
vlen1
;
char
fileName
[
128
]
;
char
fileName
[
PATH_MAX
]
=
{
0
}
;
sprintf
(
fileName
,
"%s/taos.cfg"
,
configDir
);
fp
=
fopen
(
fileName
,
"r"
);
if
(
fp
==
NULL
)
{
}
else
{
line
=
NULL
;
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
size_t
len
=
1024
;
line
=
calloc
(
1
,
len
);
if
(
fp
!=
NULL
)
{
while
(
!
feof
(
fp
))
{
tfree
(
line
);
line
=
option
=
value
=
NULL
;
len
=
olen
=
vlen
=
0
;
memset
(
line
,
0
,
len
);
getline
(
&
line
,
&
len
,
fp
)
;
if
(
line
==
NULL
)
break
;
option
=
value
=
NULL
;
olen
=
vlen
=
0
;
getline
(
&
line
,
&
len
,
fp
);
line
[
len
-
1
]
=
0
;
paGetToken
(
line
,
&
option
,
&
olen
);
if
(
olen
==
0
)
continue
;
option
[
olen
]
=
0
;
...
...
@@ -922,14 +925,15 @@ bool tsReadGlobalConfig() {
// For dataDir, the format is:
// dataDir /mnt/disk1 0
paGetToken
(
value
+
vlen
+
1
,
&
value1
,
&
vlen1
);
tsReadConfigOption
(
option
,
value
);
}
tfree
(
line
);
fclose
(
fp
);
}
tfree
(
line
);
if
(
tsReadStorageConfig
)
{
tsReadStorageConfig
();
}
...
...
@@ -983,6 +987,7 @@ bool tsReadGlobalConfig() {
strcpy
(
tsLocalIp
,
tsPrivateIp
);
}
// todo refactor
tsVersion
=
0
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
if
(
version
[
i
]
>=
'0'
&&
version
[
i
]
<=
'9'
)
{
...
...
@@ -991,6 +996,7 @@ bool tsReadGlobalConfig() {
break
;
}
}
tsVersion
=
10
*
tsVersion
;
return
true
;
...
...
src/util/src/tskiplist.c
浏览文件 @
649465d7
...
...
@@ -17,6 +17,7 @@
#include "tlog.h"
#include "tskiplist.h"
#include "tutil.h"
#include "tcompare.h"
__attribute__
((
unused
))
static
FORCE_INLINE
void
recordNodeEachLevel
(
SSkipList
*
pSkipList
,
int32_t
level
)
{
// record link count in each level
#if SKIP_LIST_RECORD_PERFORMANCE
...
...
@@ -72,196 +73,54 @@ memset(pNode, 0, SL_NODE_HEADER_SIZE(_l));\
static
void
tSkipListDoInsert
(
SSkipList
*
pSkipList
,
SSkipListNode
**
forward
,
SSkipListNode
*
pNode
);
static
SSkipListNode
*
tSkipListDoAppend
(
SSkipList
*
pSkipList
,
SSkipListNode
*
pNode
);
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
;
}
static
__compar_fn_t
getKeyFilterComparator
(
SSkipList
*
pSkipList
,
int32_t
filterDataType
)
{
__compar_fn_t
comparFn
=
NULL
;
switch
(
pSkipList
->
keyInfo
.
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
:
{
static
SSkipListIterator
*
doCreateSkipListIterator
(
SSkipList
*
pSkipList
,
int32_t
order
);
//static __compar_fn_t getComparFunc(SSkipList *pSkipList, int32_t filterDataType) {
// __compar_fn_t comparFn = NULL;
//
// switch (pSkipList->keyInfo.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 = compare
DoubleInt
Val;
// comparFn = compare
Int32
Val;
// } 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;
// }
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
;
}
static
__compar_fn_t
getKeyComparator
(
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
;
}
// break;
// }
// case TSDB_DATA_TYPE_BINARY:
// comparFn = compareStrVal;
// break;
// case TSDB_DATA_TYPE_NCHAR:
// comparFn = compareWStrVal;
// break;
// default:
// comparFn = compareInt32Val;
// break;
// }
//
// return comparFn;
//}
static
bool
initForwardBackwardPtr
(
SSkipList
*
pSkipList
)
{
uint32_t
maxLevel
=
pSkipList
->
maxLevel
;
...
...
@@ -298,7 +157,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint8_t keyLen, ui
pSkipList
->
keyInfo
=
(
SSkipListKeyInfo
){.
type
=
keyType
,
.
len
=
keyLen
,
.
dupKey
=
dupKey
,
.
freeNode
=
freeNode
};
pSkipList
->
keyFn
=
fn
;
pSkipList
->
comparFn
=
getKeyCompar
ator
(
keyType
);
pSkipList
->
comparFn
=
getKeyCompar
Func
(
keyType
);
pSkipList
->
maxLevel
=
maxLevel
;
pSkipList
->
level
=
1
;
...
...
@@ -406,22 +265,18 @@ SSkipListNode *tSkipListPut(SSkipList *pSkipList, SSkipListNode *pNode) {
SSkipListNode
*
px
=
pSkipList
->
pHead
;
SSkipListNode
*
forward
[
MAX_SKIP_LIST_LEVEL
]
=
{
0
};
bool
identical
=
false
;
int32_t
ret
=
-
1
;
for
(
int32_t
i
=
pSkipList
->
level
-
1
;
i
>=
0
;
--
i
)
{
SSkipListNode
*
p
=
SL_GET_FORWARD_POINTER
(
px
,
i
);
while
(
p
!=
pSkipList
->
pTail
)
{
char
*
key
=
SL_GET_NODE_KEY
(
pSkipList
,
p
);
// if the forward element is less than the specified key, forward one step
int32_t
ret
=
pSkipList
->
comparFn
(
key
,
newDatakey
);
ret
=
pSkipList
->
comparFn
(
key
,
newDatakey
);
if
(
ret
<
0
)
{
px
=
p
;
p
=
SL_GET_FORWARD_POINTER
(
px
,
i
);
}
else
{
if
(
identical
==
false
)
{
identical
=
(
ret
==
0
);
}
break
;
}
}
...
...
@@ -430,7 +285,7 @@ SSkipListNode *tSkipListPut(SSkipList *pSkipList, SSkipListNode *pNode) {
}
// if the skip list does not allowed identical key inserted, the new data will be discarded.
if
(
pSkipList
->
keyInfo
.
dupKey
==
0
&&
identical
)
{
if
(
pSkipList
->
keyInfo
.
dupKey
==
0
&&
ret
==
0
)
{
if
(
pSkipList
->
lock
)
{
pthread_rwlock_unlock
(
pSkipList
->
lock
);
}
...
...
@@ -447,20 +302,13 @@ void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **forward, SSkipListN
for
(
int32_t
i
=
0
;
i
<
pNode
->
level
;
++
i
)
{
SSkipListNode
*
x
=
forward
[
i
];
// if (x != pSkipList->pTail) {
SL_GET_BACKWARD_POINTER
(
pNode
,
i
)
=
x
;
SL_GET_BACKWARD_POINTER
(
pNode
,
i
)
=
x
;
SSkipListNode
*
next
=
SL_GET_FORWARD_POINTER
(
x
,
i
);
// if (next) {
SL_GET_BACKWARD_POINTER
(
next
,
i
)
=
pNode
;
// }
SSkipListNode
*
next
=
SL_GET_FORWARD_POINTER
(
x
,
i
);
SL_GET_BACKWARD_POINTER
(
next
,
i
)
=
pNode
;
SL_GET_FORWARD_POINTER
(
pNode
,
i
)
=
next
;
SL_GET_FORWARD_POINTER
(
x
,
i
)
=
pNode
;
// } else {
// SL_GET_FORWARD_POINTER(pSkipList->pHead, i) = pNode;
// }
SL_GET_FORWARD_POINTER
(
pNode
,
i
)
=
next
;
SL_GET_FORWARD_POINTER
(
x
,
i
)
=
pNode
;
}
atomic_add_fetch_32
(
&
pSkipList
->
size
,
1
);
...
...
@@ -494,11 +342,9 @@ SSkipListNode* tSkipListDoAppend(SSkipList *pSkipList, SSkipListNode *pNode) {
SArray
*
tSkipListGet
(
SSkipList
*
pSkipList
,
SSkipListKey
pKey
,
int16_t
keyType
)
{
int32_t
sLevel
=
pSkipList
->
level
-
1
;
int32_t
ret
=
-
1
;
// result list
SArray
*
sa
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SSkipListNode
*
pNode
=
pSkipList
->
pHead
;
if
(
pSkipList
->
lock
)
{
...
...
@@ -509,15 +355,16 @@ SArray* tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey, int16_t keyType) {
pSkipList
->
state
.
queryCount
++
;
#endif
__compar_fn_t
filterComparFn
=
get
KeyFilterComparator
(
pSkipList
,
keyType
);
__compar_fn_t
filterComparFn
=
get
ComparFunc
(
pSkipList
->
keyInfo
.
type
,
keyType
);
int32_t
ret
=
-
1
;
for
(
int32_t
i
=
sLevel
;
i
>=
0
;
--
i
)
{
SSkipListNode
*
pNext
=
SL_GET_FORWARD_POINTER
(
pNode
,
i
);
while
(
pNext
!=
NULL
)
{
char
*
key
=
SL_GET_NODE_KEY
(
pSkipList
,
pNext
);
SSkipListNode
*
p
=
SL_GET_FORWARD_POINTER
(
pNode
,
i
);
while
(
p
!=
pSkipList
->
pTail
)
{
char
*
key
=
SL_GET_NODE_KEY
(
pSkipList
,
p
);
if
((
ret
=
filterComparFn
(
key
,
pKey
))
<
0
)
{
pNode
=
p
Next
;
p
Next
=
SL_GET_FORWARD_POINTER
(
pNext
,
i
);
pNode
=
p
;
p
=
SL_GET_FORWARD_POINTER
(
p
,
i
);
}
else
{
break
;
}
...
...
@@ -525,10 +372,6 @@ SArray* tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey, int16_t keyType) {
// find the qualified key
if
(
ret
==
0
)
{
if
(
pSkipList
->
lock
)
{
pthread_rwlock_unlock
(
pSkipList
->
lock
);
}
SSkipListNode
*
pResult
=
SL_GET_FORWARD_POINTER
(
pNode
,
i
);
taosArrayPush
(
sa
,
&
pResult
);
...
...
@@ -559,25 +402,57 @@ SSkipListIterator* tSkipListCreateIter(SSkipList *pSkipList) {
return
NULL
;
}
SSkipListIterator
*
iter
=
calloc
(
1
,
sizeof
(
SSkipListIterator
));
iter
->
pSkipList
=
pSkipList
;
if
(
pSkipList
->
lock
)
{
pthread_rwlock_rdlock
(
pSkipList
->
lock
);
return
doCreateSkipListIterator
(
pSkipList
,
TSDB_ORDER_ASC
);
}
SSkipListIterator
*
tSkipListCreateIterFromVal
(
SSkipList
*
pSkipList
,
const
char
*
val
,
int32_t
type
,
int32_t
order
)
{
if
(
pSkipList
==
NULL
)
{
return
NULL
;
}
iter
->
cur
=
NULL
;
iter
->
num
=
pSkipList
->
size
;
assert
(
order
==
TSDB_ORDER_ASC
||
order
==
TSDB_ORDER_DESC
);
if
(
pSkipList
->
lock
)
{
pthread_rwlock_unlock
(
pSkipList
->
lock
);
}
if
(
val
==
NULL
)
{
return
doCreateSkipListIterator
(
pSkipList
,
order
);
}
else
{
return
iter
;
SSkipListNode
*
forward
[
MAX_SKIP_LIST_LEVEL
]
=
{
0
};
int32_t
ret
=
-
1
;
__compar_fn_t
filterComparFn
=
getComparFunc
(
pSkipList
->
keyInfo
.
type
,
type
);
SSkipListNode
*
pNode
=
pSkipList
->
pHead
;
for
(
int32_t
i
=
pSkipList
->
level
-
1
;
i
>=
0
;
--
i
)
{
SSkipListNode
*
p
=
SL_GET_FORWARD_POINTER
(
pNode
,
i
);
while
(
p
!=
pSkipList
->
pTail
)
{
char
*
key
=
SL_GET_NODE_KEY
(
pSkipList
,
p
);
if
((
ret
=
filterComparFn
(
key
,
val
))
<
0
)
{
pNode
=
p
;
p
=
SL_GET_FORWARD_POINTER
(
p
,
i
);
}
else
{
break
;
}
}
forward
[
i
]
=
pNode
;
}
SSkipListIterator
*
iter
=
doCreateSkipListIterator
(
pSkipList
,
order
);
// set the initial position
if
(
order
==
TSDB_ORDER_ASC
)
{
iter
->
cur
=
forward
[
0
];
// greater equals than the value
}
else
{
iter
->
cur
=
SL_GET_FORWARD_POINTER
(
forward
[
0
],
0
);
}
return
iter
;
}
}
bool
tSkipListIterNext
(
SSkipListIterator
*
iter
)
{
if
(
iter
->
num
==
0
||
iter
->
pSkipList
==
NULL
)
{
if
(
iter
->
pSkipList
==
NULL
)
{
return
false
;
}
...
...
@@ -587,26 +462,35 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
pthread_rwlock_rdlock
(
pSkipList
->
lock
);
}
if
(
iter
->
cur
==
NULL
)
{
iter
->
cur
=
SL_GET_FORWARD_POINTER
(
pSkipList
->
pHead
,
0
);
}
else
{
iter
->
cur
=
SL_GET_FORWARD_POINTER
(
iter
->
cur
,
0
);
if
(
iter
->
order
==
TSDB_ORDER_ASC
)
{
// ascending order iterate
if
(
iter
->
cur
==
NULL
)
{
iter
->
cur
=
SL_GET_FORWARD_POINTER
(
pSkipList
->
pHead
,
0
);
}
else
{
iter
->
cur
=
SL_GET_FORWARD_POINTER
(
iter
->
cur
,
0
);
}
}
else
{
// descending order iterate
if
(
iter
->
cur
==
NULL
)
{
iter
->
cur
=
SL_GET_BACKWARD_POINTER
(
pSkipList
->
pTail
,
0
);
}
else
{
iter
->
cur
=
SL_GET_BACKWARD_POINTER
(
iter
->
cur
,
0
);
}
}
if
(
pSkipList
->
lock
)
{
pthread_rwlock_unlock
(
pSkipList
->
lock
);
}
return
iter
->
cur
!=
pSkipList
->
pTail
;
return
(
iter
->
order
==
TSDB_ORDER_ASC
)
?
(
iter
->
cur
!=
pSkipList
->
pTail
)
:
(
iter
->
cur
!=
pSkipList
->
pHead
)
;
}
SSkipListNode
*
tSkipListIterGet
(
SSkipListIterator
*
iter
)
{
if
(
iter
==
NULL
||
iter
->
cur
==
iter
->
pSkipList
->
pTail
)
{
if
(
iter
==
NULL
||
iter
->
cur
==
iter
->
pSkipList
->
pTail
||
iter
->
cur
==
iter
->
pSkipList
->
pHead
)
{
return
NULL
;
}
else
{
return
iter
->
cur
;
}
}
void
*
tSkipListDestroyIter
(
SSkipListIterator
*
iter
)
{
if
(
iter
==
NULL
)
{
return
NULL
;
...
...
@@ -622,7 +506,7 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) {
// SSkipListNode *p = pStartNode;
// int32_t numOfRes = 0;
//
// __compar_fn_t filterComparFn = get
KeyFilterComparator
(pSkipList, pEndKey->nType);
// __compar_fn_t filterComparFn = get
ComparFunc
(pSkipList, pEndKey->nType);
// while (p != NULL) {
// int32_t ret = filterComparFn(&p->key, pEndKey);
// if (ret > 0) {
...
...
@@ -663,7 +547,7 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) {
// return 0;
// }
//
// __compar_fn_t filterComparFn = get
KeyFilterComparator
(pSkipList, pKey->nType);
// __compar_fn_t filterComparFn = get
ComparFunc
(pSkipList, pKey->nType);
//
// // backward check if previous nodes are with the same value.
// SSkipListNode *pPrev = pNode->pBackward[0];
...
...
@@ -679,11 +563,11 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) {
// int32_t ret = -1;
//
// SSkipListNode *x = &pSkipList->pHead;
// __compar_fn_t filterComparFn = get
KeyFilterComparator
(pSkipList, pKey->nType);
// __compar_fn_t filterComparFn = get
ComparFunc
(pSkipList, pKey->nType);
//
// pthread_rwlock_rdlock(&pSkipList->lock);
//
// if (cond == TSDB_RELATION_
LARGE_EQUAL || cond == TSDB_RELATION_LARGE
) {
// if (cond == TSDB_RELATION_
GREATER_EQUAL || cond == TSDB_RELATION_GREATER
) {
// for (int32_t i = sLevel; i >= 0; --i) {
// while (x->pForward[i] != NULL && (ret = filterComparFn(&x->pForward[i]->key, pKey)) < 0) {
// x = x->pForward[i];
...
...
@@ -691,7 +575,7 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) {
// }
//
// // backward check if previous nodes are with the same value.
// if (cond == TSDB_RELATION_
LARGE
_EQUAL && ret == 0) {
// if (cond == TSDB_RELATION_
GREATER
_EQUAL && ret == 0) {
// SSkipListNode *pNode = x->pForward[0];
// while ((pNode->pBackward[0] != &pSkipList->pHead) && (filterComparFn(&pNode->pBackward[0]->key, pKey) == 0)) {
// pNode = pNode->pBackward[0];
...
...
@@ -700,10 +584,10 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) {
// return pNode;
// }
//
// if (ret > 0 || cond == TSDB_RELATION_
LARGE
_EQUAL) {
// if (ret > 0 || cond == TSDB_RELATION_
GREATER
_EQUAL) {
// pthread_rwlock_unlock(&pSkipList->lock);
// return x->pForward[0];
// } else { // cond == TSDB_RELATION_
LARGE
&& ret == 0
// } else { // cond == TSDB_RELATION_
GREATER
&& ret == 0
// SSkipListNode *pn = x->pForward[0];
// while (pn != NULL && filterComparFn(&pn->key, pKey) == 0) {
// pn = pn->pForward[0];
...
...
@@ -717,19 +601,9 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) {
// return NULL;
//}
//
// int32_t tSkipListRangeQuery(SSkipList *pSkipList, tSKipListQueryCond *pCond, SSkipListNode ***pRes) {
// pSkipList->state.queryCount++;
// SSkipListNode *pStart = tSkipListParQuery(pSkipList, &pCond->lowerBnd, pCond->lowerBndRelOptr);
// if (pStart == 0) {
// *pRes = NULL;
// return 0;
// }
//
// return tSkipListEndParQuery(pSkipList, pStart, &pCond->upperBnd, pCond->upperBndRelOptr, pRes);
//}
//
// static bool removeSupport(SSkipList *pSkipList, SSkipListNode **forward, SSkipListKey *pKey) {
// __compar_fn_t filterComparFn = get
KeyFilterComparator
(pSkipList, pKey->nType);
// __compar_fn_t filterComparFn = get
ComparFunc
(pSkipList, pKey->nType);
//
// if (filterComparFn(&forward[0]->pForward[0]->key, pKey) == 0) {
// SSkipListNode *p = forward[0]->pForward[0];
...
...
@@ -760,7 +634,7 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) {
//
// bool tSkipListRemove(SSkipList *pSkipList, SSkipListKey *pKey) {
// SSkipListNode *forward[MAX_SKIP_LIST_LEVEL] = {0};
// __compar_fn_t filterComparFn = get
KeyFilterComparator
(pSkipList, pKey->nType);
// __compar_fn_t filterComparFn = get
ComparFunc
(pSkipList, pKey->nType);
//
// pthread_rwlock_rdlock(&pSkipList->lock);
//
...
...
@@ -818,3 +692,12 @@ void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel) {
p
=
SL_GET_FORWARD_POINTER
(
p
,
nlevel
-
1
);
}
}
SSkipListIterator
*
doCreateSkipListIterator
(
SSkipList
*
pSkipList
,
int32_t
order
)
{
SSkipListIterator
*
iter
=
calloc
(
1
,
sizeof
(
SSkipListIterator
));
iter
->
pSkipList
=
pSkipList
;
iter
->
order
=
order
;
return
iter
;
}
src/util/src/tutil.c
浏览文件 @
649465d7
...
...
@@ -166,7 +166,7 @@ char* strtolower(char *dst, const char *src) {
char
*
paGetToken
(
char
*
string
,
char
**
token
,
int32_t
*
tokenLen
)
{
char
quote
=
0
;
while
(
*
string
!=
0
)
{
if
(
*
string
==
' '
||
*
string
==
'\t'
)
{
++
string
;
...
...
@@ -336,7 +336,7 @@ int32_t taosByteArrayToHexStr(char bytes[], int32_t len, char hexstr[]) {
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
for
(
i
=
0
;
i
<
len
;
i
++
)
{
hexstr
[
i
*
2
]
=
hexval
[((
bytes
[
i
]
>>
4
)
&
0xF
)];
hexstr
[
i
*
2
]
=
hexval
[((
bytes
[
i
]
>>
4
u
)
&
0xF
)];
hexstr
[(
i
*
2
)
+
1
]
=
hexval
[(
bytes
[
i
])
&
0x0F
];
}
...
...
src/util/tests/skiplistTest.cpp
浏览文件 @
649465d7
...
...
@@ -104,6 +104,7 @@ void randKeyTest() {
tSkipListDestroy
(
pSkipList
);
}
void
stringKeySkiplistTest
()
{
const
int32_t
max_key_size
=
12
;
...
...
src/vnode/tsdb/inc/tsdb.h
浏览文件 @
649465d7
...
...
@@ -208,7 +208,7 @@ typedef struct SBlockInfo {
typedef
struct
SDataBlockInfo
{
STimeWindow
window
;
int32_t
size
;
int32_t
rows
;
int32_t
numOfCols
;
int64_t
uid
;
int32_t
sid
;
...
...
@@ -335,7 +335,7 @@ SArray *tsdbGetTableList(tsdb_query_handle_t *pQueryHandle);
* @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
...
...
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
649465d7
...
...
@@ -6,9 +6,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <
sys/sendfile
.h>
#include <
tlog
.h>
#include <unistd.h>
// #include "taosdef.h"
...
...
@@ -741,6 +742,7 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlk *pBlock) {
STableId
tableId
=
{.
uid
=
pBlock
->
uid
,
.
tid
=
pBlock
->
tid
};
STable
*
pTable
=
tsdbIsValidTableToInsert
(
pRepo
->
tsdbMeta
,
tableId
);
if
(
pTable
==
NULL
)
{
dError
(
"failed to get table for insert, uid:%"
PRIu64
", tid:%d"
,
tableId
.
uid
,
tableId
.
tid
);
return
TSDB_CODE_INVALID_TABLE_ID
;
}
...
...
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
649465d7
...
...
@@ -93,6 +93,11 @@ void tsdbFreeEncode(void *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
)
{
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
pHandle
;
...
...
@@ -101,8 +106,8 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
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
);
...
...
@@ -218,7 +223,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
super
->
tagSchema
=
tdDupSchema
(
pCfg
->
tagSchema
);
super
->
tagVal
=
tdDataRowDup
(
pCfg
->
tagValues
);
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
)
{
tdFreeSchema
(
super
->
schema
);
...
...
@@ -414,8 +419,6 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) {
pNode
->
level
=
level
;
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
);
tSkipListPut
(
list
,
pNode
);
...
...
src/vnode/tsdb/src/tsdbRead.c
浏览文件 @
649465d7
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录