Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
caeabf38
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
caeabf38
编写于
12月 03, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-225] refactor codes.
上级
d59b8f18
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
68 deletion
+72
-68
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+4
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+3
-1
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-3
src/query/src/qUtil.c
src/query/src/qUtil.c
+63
-63
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
caeabf38
...
...
@@ -246,11 +246,14 @@ typedef struct SQueryInfo {
int16_t
fillType
;
// final result fill type
int16_t
numOfTables
;
STableMetaInfo
**
pTableMetaInfo
;
struct
STSBuf
*
tsBuf
;
struct
STSBuf
*
tsBuf
;
int64_t
*
fillVal
;
// default value for fill
char
*
msg
;
// pointer to the pCmd->payload to keep error message temporarily
int64_t
clauseLimit
;
// limit for current sub clause
int64_t
prjOffset
;
// offset value in the original sql expression, only applied at client side
int64_t
tableLimit
;
// table limit in case of super table projection query + global order + limit
int32_t
udColumnId
;
// current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
int16_t
resColumnId
;
// result column id
}
SQueryInfo
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
caeabf38
...
...
@@ -5307,7 +5307,8 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
// keep original limitation value in globalLimit
pQueryInfo
->
clauseLimit
=
pQueryInfo
->
limit
.
limit
;
pQueryInfo
->
prjOffset
=
pQueryInfo
->
limit
.
offset
;
pQueryInfo
->
prjOffset
=
pQueryInfo
->
limit
.
offset
;
pQueryInfo
->
tableLimit
=
-
1
;
if
(
tscOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
))
{
/*
...
...
@@ -5317,6 +5318,7 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
* than or equal to the value of limit.
*/
if
(
pQueryInfo
->
limit
.
limit
>
0
)
{
pQueryInfo
->
tableLimit
=
pQueryInfo
->
limit
.
limit
+
pQueryInfo
->
limit
.
offset
;
pQueryInfo
->
limit
.
limit
=
-
1
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
caeabf38
...
...
@@ -697,6 +697,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
tagNameRelType
=
htons
(
pQueryInfo
->
tagCond
.
relType
);
pQueryMsg
->
numOfTags
=
htonl
(
numOfTags
);
pQueryMsg
->
queryType
=
htonl
(
pQueryInfo
->
type
);
pQueryMsg
->
tableLimit
=
htobe64
(
pQueryInfo
->
tableLimit
);
size_t
numOfOutput
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
pQueryMsg
->
numOfOutput
=
htons
((
int16_t
)
numOfOutput
);
// this is the stage one output column number
...
...
src/query/src/qExecutor.c
浏览文件 @
caeabf38
...
...
@@ -6260,11 +6260,9 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
pQueryMsg
->
interval
.
interval
=
htobe64
(
pQueryMsg
->
interval
.
interval
);
pQueryMsg
->
interval
.
sliding
=
htobe64
(
pQueryMsg
->
interval
.
sliding
);
pQueryMsg
->
interval
.
offset
=
htobe64
(
pQueryMsg
->
interval
.
offset
);
// pQueryMsg->interval.intervalUnit = pQueryMsg->interval.intervalUnit;
// pQueryMsg->interval.slidingUnit = pQueryMsg->interval.slidingUnit;
// pQueryMsg->interval.offsetUnit = pQueryMsg->interval.offsetUnit;
pQueryMsg
->
limit
=
htobe64
(
pQueryMsg
->
limit
);
pQueryMsg
->
offset
=
htobe64
(
pQueryMsg
->
offset
);
pQueryMsg
->
tableLimit
=
htobe64
(
pQueryMsg
->
tableLimit
);
pQueryMsg
->
order
=
htons
(
pQueryMsg
->
order
);
pQueryMsg
->
orderColId
=
htons
(
pQueryMsg
->
orderColId
);
...
...
src/query/src/qUtil.c
浏览文件 @
caeabf38
...
...
@@ -43,48 +43,48 @@ int32_t getOutputInterResultBufSize(SQuery* pQuery) {
return
size
;
}
int32_t
initWindowResInfo
(
SResultRowInfo
*
p
WindowRes
Info
,
int32_t
size
,
int16_t
type
)
{
p
WindowRes
Info
->
capacity
=
size
;
int32_t
initWindowResInfo
(
SResultRowInfo
*
p
ResultRow
Info
,
int32_t
size
,
int16_t
type
)
{
p
ResultRow
Info
->
capacity
=
size
;
p
WindowRes
Info
->
type
=
type
;
p
WindowRes
Info
->
curIndex
=
-
1
;
p
WindowRes
Info
->
size
=
0
;
p
WindowRes
Info
->
prevSKey
=
TSKEY_INITIAL_VAL
;
p
ResultRow
Info
->
type
=
type
;
p
ResultRow
Info
->
curIndex
=
-
1
;
p
ResultRow
Info
->
size
=
0
;
p
ResultRow
Info
->
prevSKey
=
TSKEY_INITIAL_VAL
;
p
WindowResInfo
->
pResult
=
calloc
(
pWindowRes
Info
->
capacity
,
POINTER_BYTES
);
if
(
p
WindowRes
Info
->
pResult
==
NULL
)
{
p
ResultRowInfo
->
pResult
=
calloc
(
pResultRow
Info
->
capacity
,
POINTER_BYTES
);
if
(
p
ResultRow
Info
->
pResult
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
return
TSDB_CODE_SUCCESS
;
}
void
cleanupTimeWindowInfo
(
SResultRowInfo
*
p
WindowRes
Info
)
{
if
(
p
WindowRes
Info
==
NULL
)
{
void
cleanupTimeWindowInfo
(
SResultRowInfo
*
p
ResultRow
Info
)
{
if
(
p
ResultRow
Info
==
NULL
)
{
return
;
}
if
(
p
WindowRes
Info
->
capacity
==
0
)
{
assert
(
p
WindowRes
Info
->
pResult
==
NULL
);
if
(
p
ResultRow
Info
->
capacity
==
0
)
{
assert
(
p
ResultRow
Info
->
pResult
==
NULL
);
return
;
}
if
(
p
WindowResInfo
->
type
==
TSDB_DATA_TYPE_BINARY
||
pWindowRes
Info
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
for
(
int32_t
i
=
0
;
i
<
p
WindowRes
Info
->
size
;
++
i
)
{
tfree
(
p
WindowRes
Info
->
pResult
[
i
]
->
key
);
if
(
p
ResultRowInfo
->
type
==
TSDB_DATA_TYPE_BINARY
||
pResultRow
Info
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
for
(
int32_t
i
=
0
;
i
<
p
ResultRow
Info
->
size
;
++
i
)
{
tfree
(
p
ResultRow
Info
->
pResult
[
i
]
->
key
);
}
}
tfree
(
p
WindowRes
Info
->
pResult
);
tfree
(
p
ResultRow
Info
->
pResult
);
}
void
resetTimeWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
p
WindowRes
Info
)
{
if
(
p
WindowResInfo
==
NULL
||
pWindowRes
Info
->
capacity
==
0
)
{
void
resetTimeWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
p
ResultRow
Info
)
{
if
(
p
ResultRowInfo
==
NULL
||
pResultRow
Info
->
capacity
==
0
)
{
return
;
}
for
(
int32_t
i
=
0
;
i
<
p
WindowRes
Info
->
size
;
++
i
)
{
SResultRow
*
pWindowRes
=
p
WindowRes
Info
->
pResult
[
i
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
p
WindowRes
Info
->
type
);
for
(
int32_t
i
=
0
;
i
<
p
ResultRow
Info
->
size
;
++
i
)
{
SResultRow
*
pWindowRes
=
p
ResultRow
Info
->
pResult
[
i
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
p
ResultRow
Info
->
type
);
int32_t
groupIndex
=
0
;
int64_t
uid
=
0
;
...
...
@@ -93,30 +93,30 @@ void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pWindowR
taosHashRemove
(
pRuntimeEnv
->
pResultRowHashTable
,
(
const
char
*
)
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
sizeof
(
groupIndex
)));
}
p
WindowRes
Info
->
curIndex
=
-
1
;
p
WindowRes
Info
->
size
=
0
;
p
ResultRow
Info
->
curIndex
=
-
1
;
p
ResultRow
Info
->
size
=
0
;
p
WindowRes
Info
->
startTime
=
TSKEY_INITIAL_VAL
;
p
WindowRes
Info
->
prevSKey
=
TSKEY_INITIAL_VAL
;
p
ResultRow
Info
->
startTime
=
TSKEY_INITIAL_VAL
;
p
ResultRow
Info
->
prevSKey
=
TSKEY_INITIAL_VAL
;
}
void
clearFirstNWindowRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
num
)
{
SResultRowInfo
*
p
WindowRes
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
WindowResInfo
==
NULL
||
pWindowResInfo
->
capacity
==
0
||
pWindowRes
Info
->
size
==
0
||
num
==
0
)
{
SResultRowInfo
*
p
ResultRow
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
ResultRowInfo
==
NULL
||
pResultRowInfo
->
capacity
==
0
||
pResultRow
Info
->
size
==
0
||
num
==
0
)
{
return
;
}
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
WindowRes
Info
);
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
ResultRow
Info
);
assert
(
num
>=
0
&&
num
<=
numOfClosed
);
int16_t
type
=
p
WindowRes
Info
->
type
;
int16_t
type
=
p
ResultRow
Info
->
type
;
int64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
);
char
*
key
=
NULL
;
int16_t
bytes
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SResultRow
*
pResult
=
p
WindowRes
Info
->
pResult
[
i
];
SResultRow
*
pResult
=
p
ResultRow
Info
->
pResult
[
i
];
if
(
pResult
->
closed
)
{
// remove the window slot from hash table
getResultRowKeyInfo
(
pResult
,
type
,
&
key
,
&
bytes
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
...
...
@@ -126,23 +126,23 @@ void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
}
}
int32_t
remain
=
p
WindowRes
Info
->
size
-
num
;
int32_t
remain
=
p
ResultRow
Info
->
size
-
num
;
// clear all the closed windows from the window list
for
(
int32_t
k
=
0
;
k
<
remain
;
++
k
)
{
copyResultRow
(
pRuntimeEnv
,
p
WindowResInfo
->
pResult
[
k
],
pWindowRes
Info
->
pResult
[
num
+
k
],
type
);
copyResultRow
(
pRuntimeEnv
,
p
ResultRowInfo
->
pResult
[
k
],
pResultRow
Info
->
pResult
[
num
+
k
],
type
);
}
// move the unclosed window in the front of the window list
for
(
int32_t
k
=
remain
;
k
<
p
WindowRes
Info
->
size
;
++
k
)
{
SResultRow
*
pWindowRes
=
p
WindowRes
Info
->
pResult
[
k
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
p
WindowRes
Info
->
type
);
for
(
int32_t
k
=
remain
;
k
<
p
ResultRow
Info
->
size
;
++
k
)
{
SResultRow
*
pWindowRes
=
p
ResultRow
Info
->
pResult
[
k
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
p
ResultRow
Info
->
type
);
}
p
WindowRes
Info
->
size
=
remain
;
p
ResultRow
Info
->
size
=
remain
;
for
(
int32_t
k
=
0
;
k
<
p
WindowRes
Info
->
size
;
++
k
)
{
SResultRow
*
pResult
=
p
WindowRes
Info
->
pResult
[
k
];
for
(
int32_t
k
=
0
;
k
<
p
ResultRow
Info
->
size
;
++
k
)
{
SResultRow
*
pResult
=
p
ResultRow
Info
->
pResult
[
k
];
getResultRowKeyInfo
(
pResult
,
type
,
&
key
,
&
bytes
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
...
...
@@ -150,43 +150,43 @@ void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
assert
(
p
!=
NULL
);
int32_t
v
=
(
*
p
-
num
);
assert
(
v
>=
0
&&
v
<=
p
WindowRes
Info
->
size
);
assert
(
v
>=
0
&&
v
<=
p
ResultRow
Info
->
size
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
taosHashPut
(
pRuntimeEnv
->
pResultRowHashTable
,
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
),
(
char
*
)
&
v
,
sizeof
(
int32_t
));
}
p
WindowRes
Info
->
curIndex
=
-
1
;
p
ResultRow
Info
->
curIndex
=
-
1
;
}
void
clearClosedTimeWindow
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SResultRowInfo
*
p
WindowRes
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
WindowResInfo
==
NULL
||
pWindowResInfo
->
capacity
==
0
||
pWindowRes
Info
->
size
==
0
)
{
SResultRowInfo
*
p
ResultRow
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
ResultRowInfo
==
NULL
||
pResultRowInfo
->
capacity
==
0
||
pResultRow
Info
->
size
==
0
)
{
return
;
}
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
WindowRes
Info
);
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
ResultRow
Info
);
clearFirstNWindowRes
(
pRuntimeEnv
,
numOfClosed
);
}
int32_t
numOfClosedTimeWindow
(
SResultRowInfo
*
p
WindowRes
Info
)
{
int32_t
numOfClosedTimeWindow
(
SResultRowInfo
*
p
ResultRow
Info
)
{
int32_t
i
=
0
;
while
(
i
<
p
WindowResInfo
->
size
&&
pWindowRes
Info
->
pResult
[
i
]
->
closed
)
{
while
(
i
<
p
ResultRowInfo
->
size
&&
pResultRow
Info
->
pResult
[
i
]
->
closed
)
{
++
i
;
}
return
i
;
}
void
closeAllTimeWindow
(
SResultRowInfo
*
p
WindowRes
Info
)
{
assert
(
p
WindowResInfo
->
size
>=
0
&&
pWindowResInfo
->
capacity
>=
pWindowRes
Info
->
size
);
void
closeAllTimeWindow
(
SResultRowInfo
*
p
ResultRow
Info
)
{
assert
(
p
ResultRowInfo
->
size
>=
0
&&
pResultRowInfo
->
capacity
>=
pResultRow
Info
->
size
);
for
(
int32_t
i
=
0
;
i
<
p
WindowRes
Info
->
size
;
++
i
)
{
if
(
p
WindowRes
Info
->
pResult
[
i
]
->
closed
)
{
for
(
int32_t
i
=
0
;
i
<
p
ResultRow
Info
->
size
;
++
i
)
{
if
(
p
ResultRow
Info
->
pResult
[
i
]
->
closed
)
{
continue
;
}
p
WindowRes
Info
->
pResult
[
i
]
->
closed
=
true
;
p
ResultRow
Info
->
pResult
[
i
]
->
closed
=
true
;
}
}
...
...
@@ -195,41 +195,41 @@ void closeAllTimeWindow(SResultRowInfo *pWindowResInfo) {
* the last qualified time stamp in case of sliding query, which the sliding time is not equalled to the interval time.
* NOTE: remove redundant, only when the result set order equals to traverse order
*/
void
removeRedundantWindow
(
SResultRowInfo
*
p
WindowRes
Info
,
TSKEY
lastKey
,
int32_t
order
)
{
assert
(
p
WindowResInfo
->
size
>=
0
&&
pWindowResInfo
->
capacity
>=
pWindowRes
Info
->
size
);
if
(
p
WindowRes
Info
->
size
<=
1
)
{
void
removeRedundantWindow
(
SResultRowInfo
*
p
ResultRow
Info
,
TSKEY
lastKey
,
int32_t
order
)
{
assert
(
p
ResultRowInfo
->
size
>=
0
&&
pResultRowInfo
->
capacity
>=
pResultRow
Info
->
size
);
if
(
p
ResultRow
Info
->
size
<=
1
)
{
return
;
}
// get the result order
int32_t
resultOrder
=
(
p
WindowResInfo
->
pResult
[
0
]
->
win
.
skey
<
pWindowRes
Info
->
pResult
[
1
]
->
win
.
skey
)
?
1
:-
1
;
int32_t
resultOrder
=
(
p
ResultRowInfo
->
pResult
[
0
]
->
win
.
skey
<
pResultRow
Info
->
pResult
[
1
]
->
win
.
skey
)
?
1
:-
1
;
if
(
order
!=
resultOrder
)
{
return
;
}
int32_t
i
=
0
;
if
(
order
==
QUERY_ASC_FORWARD_STEP
)
{
TSKEY
ekey
=
p
WindowRes
Info
->
pResult
[
i
]
->
win
.
ekey
;
while
(
i
<
p
WindowRes
Info
->
size
&&
(
ekey
<
lastKey
))
{
TSKEY
ekey
=
p
ResultRow
Info
->
pResult
[
i
]
->
win
.
ekey
;
while
(
i
<
p
ResultRow
Info
->
size
&&
(
ekey
<
lastKey
))
{
++
i
;
}
}
else
if
(
order
==
QUERY_DESC_FORWARD_STEP
)
{
while
(
i
<
p
WindowResInfo
->
size
&&
(
pWindowRes
Info
->
pResult
[
i
]
->
win
.
skey
>
lastKey
))
{
while
(
i
<
p
ResultRowInfo
->
size
&&
(
pResultRow
Info
->
pResult
[
i
]
->
win
.
skey
>
lastKey
))
{
++
i
;
}
}
if
(
i
<
p
WindowRes
Info
->
size
)
{
p
WindowRes
Info
->
size
=
(
i
+
1
);
if
(
i
<
p
ResultRow
Info
->
size
)
{
p
ResultRow
Info
->
size
=
(
i
+
1
);
}
}
bool
isWindowResClosed
(
SResultRowInfo
*
p
WindowRes
Info
,
int32_t
slot
)
{
return
(
getResultRow
(
p
WindowRes
Info
,
slot
)
->
closed
==
true
);
bool
isWindowResClosed
(
SResultRowInfo
*
p
ResultRow
Info
,
int32_t
slot
)
{
return
(
getResultRow
(
p
ResultRow
Info
,
slot
)
->
closed
==
true
);
}
void
closeTimeWindow
(
SResultRowInfo
*
p
WindowRes
Info
,
int32_t
slot
)
{
getResultRow
(
p
WindowRes
Info
,
slot
)
->
closed
=
true
;
void
closeTimeWindow
(
SResultRowInfo
*
p
ResultRow
Info
,
int32_t
slot
)
{
getResultRow
(
p
ResultRow
Info
,
slot
)
->
closed
=
true
;
}
void
clearResultRow
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pWindowRes
,
int16_t
type
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录