Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
8137a287
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看板
提交
8137a287
编写于
9月 03, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225] fix last query bug and add some function definitions.
上级
455fd0f7
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
51 addition
and
55 deletion
+51
-55
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+6
-8
src/query/inc/tsqlfunction.h
src/query/inc/tsqlfunction.h
+9
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+36
-47
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
8137a287
...
...
@@ -221,20 +221,18 @@ typedef struct STableDataBlocks {
SParamInfo
*
params
;
}
STableDataBlocks
;
//typedef struct SDataBlockList { // todo remove
// uint32_t nSize;
// uint32_t nAlloc;
// STableDataBlocks **pData;
//} SDataBlockList;
typedef
struct
SQueryInfo
{
int16_t
command
;
// the command may be different for each subclause, so keep it seperately.
uint32_t
type
;
// query/insert type
// TODO refactor
char
intervalTimeUnit
;
char
slidingTimeUnit
;
uint32_t
type
;
// query/insert type
STimeWindow
window
;
// query time window
int64_t
intervalTime
;
// aggregation time
interval
int64_t
intervalTime
;
// aggregation time
window range
int64_t
slidingTime
;
// sliding window in mseconds
int64_t
intervalOffset
;
// start offset of each time window
int32_t
tz
;
// query client timezone
SSqlGroupbyExpr
groupbyExpr
;
// group by tags info
SArray
*
colList
;
// SArray<SColumn*>
SFieldInfo
fieldsInfo
;
...
...
src/query/inc/tsqlfunction.h
浏览文件 @
8137a287
...
...
@@ -69,6 +69,15 @@ extern "C" {
#define TSDB_FUNC_AVG_IRATE 33
#define TSDB_FUNC_TID_TAG 34
#define TSDB_FUNC_HISTOGRAM 35
#define TSDB_FUNC_HLL 36
#define TSDB_FUNC_MODE 37
#define TSDB_FUNC_SAMPLE 38
#define TSDB_FUNC_CEIL 39
#define TSDB_FUNC_FLOOR 40
#define TSDB_FUNC_ROUND 41
#define TSDB_FUNC_MAVG 42
#define TSDB_FUNC_CSUM 43
#define TSDB_FUNCSTATE_SO 0x1u // single output
#define TSDB_FUNCSTATE_MO 0x2u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM
...
...
src/query/src/qExecutor.c
浏览文件 @
8137a287
...
...
@@ -35,8 +35,6 @@
* forced to load primary column explicitly.
*/
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
#define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN)
...
...
@@ -1927,24 +1925,24 @@ static bool onlyFirstQuery(SQuery *pQuery) { return onlyOneQueryType(pQuery, TSD
static
bool
onlyLastQuery
(
SQuery
*
pQuery
)
{
return
onlyOneQueryType
(
pQuery
,
TSDB_FUNC_LAST
,
TSDB_FUNC_LAST_DST
);
}
// todo refactor, add iterator
static
void
doExchangeTimeWindow
(
SQInfo
*
pQInfo
)
{
size_t
t
=
GET_NUM_OF_TABLEGROUP
(
pQInfo
);
static
void
doExchangeTimeWindow
(
SQInfo
*
pQInfo
,
STimeWindow
*
win
)
{
size_t
t
=
taosArrayGetSize
(
pQInfo
->
tableGroupInfo
.
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
t
;
++
i
)
{
SArray
*
p1
=
GET_TABLEGROUP
(
pQInfo
,
i
);
SArray
*
p1
=
taosArrayGetP
(
pQInfo
->
tableGroupInfo
.
pGroupList
,
i
);
SArray
*
tableKeyGroup
=
taosArrayGetP
(
pQInfo
->
tableGroupInfo
.
pGroupList
,
i
);
size_t
len
=
taosArrayGetSize
(
p1
);
for
(
int32_t
j
=
0
;
j
<
len
;
++
j
)
{
STableQueryInfo
*
pTableQueryInfo
=
(
STableQueryInfo
*
)
taosArrayGetP
(
p1
,
j
);
SWAP
(
pTableQueryInfo
->
win
.
skey
,
pTableQueryInfo
->
win
.
ekey
,
TSKEY
);
STableKeyInfo
*
pInfo
=
taosArrayGet
(
p1
,
j
);
STableKeyInfo
*
pInfo
=
taosArrayGet
(
tableKeyGroup
,
j
);
pInfo
->
lastKey
=
pTableQueryInfo
->
win
.
skey
;
// update the new lastkey if it is equalled to the value of the old skey
if
(
pInfo
->
lastKey
==
win
->
ekey
)
{
pInfo
->
lastKey
=
win
->
skey
;
}
}
}
}
static
void
changeExecuteScanOrder
(
SQInfo
*
pQInfo
,
bool
stableQuery
)
{
static
void
changeExecuteScanOrder
(
SQInfo
*
pQInfo
,
SQueryTableMsg
*
pQueryMsg
,
bool
stableQuery
)
{
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
// in case of point-interpolation query, use asc order scan
...
...
@@ -1961,15 +1959,17 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, bool stableQuery) {
if
(
pQuery
->
window
.
skey
>
pQuery
->
window
.
ekey
)
{
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
return
;
}
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
&&
pQuery
->
order
.
order
==
TSDB_ORDER_DESC
)
{
pQuery
->
order
.
order
=
TSDB_ORDER_ASC
;
if
(
pQuery
->
window
.
skey
>
pQuery
->
window
.
ekey
)
{
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
return
;
}
...
...
@@ -1991,7 +1991,7 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, bool stableQuery) {
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
doExchangeTimeWindow
(
pQInfo
);
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
}
pQuery
->
order
.
order
=
TSDB_ORDER_ASC
;
...
...
@@ -2001,7 +2001,7 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, bool stableQuery) {
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
doExchangeTimeWindow
(
pQInfo
);
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
}
pQuery
->
order
.
order
=
TSDB_ORDER_DESC
;
...
...
@@ -2015,6 +2015,7 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, bool stableQuery) {
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
}
pQuery
->
order
.
order
=
TSDB_ORDER_ASC
;
...
...
@@ -2024,6 +2025,7 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, bool stableQuery) {
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
}
pQuery
->
order
.
order
=
TSDB_ORDER_DESC
;
...
...
@@ -4449,10 +4451,6 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
setScanLimitationByResultBuffer
(
pQuery
);
// NOTE: pTableCheckInfo need to update the query time range and the lastKey info
// TODO fixme
changeExecuteScanOrder
(
pQInfo
,
isSTableQuery
);
code
=
setupQueryHandle
(
tsdb
,
pQInfo
,
isSTableQuery
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
@@ -6022,14 +6020,6 @@ static void doUpdateExprColumnIndex(SQuery *pQuery) {
}
}
static
int
compareTableIdInfo
(
const
void
*
a
,
const
void
*
b
)
{
const
STableIdInfo
*
x
=
(
const
STableIdInfo
*
)
a
;
const
STableIdInfo
*
y
=
(
const
STableIdInfo
*
)
b
;
if
(
x
->
uid
>
y
->
uid
)
return
1
;
if
(
x
->
uid
<
y
->
uid
)
return
-
1
;
return
0
;
}
static
void
freeQInfo
(
SQInfo
*
pQInfo
);
static
void
calResultBufSize
(
SQuery
*
pQuery
)
{
...
...
@@ -6051,8 +6041,8 @@ static void calResultBufSize(SQuery* pQuery) {
}
}
static
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
S
Array
*
pTableIdList
,
S
SqlGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
STableGroupInfo
*
pTableGroupInfo
,
SColumnInfo
*
pTagCols
)
{
static
SQInfo
*
createQInfoImpl
(
SQueryTableMsg
*
pQueryMsg
,
SSqlGroupbyExpr
*
pGroupbyExpr
,
SExprInfo
*
pExprs
,
STableGroupInfo
*
pTableGroupInfo
,
SColumnInfo
*
pTagCols
,
bool
stableQuery
)
{
int16_t
numOfCols
=
pQueryMsg
->
numOfCols
;
int16_t
numOfOutput
=
pQueryMsg
->
numOfOutput
;
...
...
@@ -6151,8 +6141,6 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
}
int
tableIndex
=
0
;
STimeWindow
window
=
pQueryMsg
->
window
;
taosArraySort
(
pTableIdList
,
compareTableIdInfo
);
pQInfo
->
runtimeEnv
.
interBufSize
=
getOutputInterResultBufSize
(
pQuery
);
pQInfo
->
pBuf
=
calloc
(
pTableGroupInfo
->
numOfTables
,
sizeof
(
STableQueryInfo
));
...
...
@@ -6161,12 +6149,20 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
}
// NOTE: pTableCheckInfo need to update the query time range and the lastKey info
// changeExecuteScanOrder(pQInfo, stableQuery);
pQInfo
->
arrTableIdInfo
=
taosArrayInit
(
tableIndex
,
sizeof
(
STableIdInfo
));
pQInfo
->
dataReady
=
QUERY_RESULT_NOT_READY
;
pthread_mutex_init
(
&
pQInfo
->
lock
,
NULL
);
pQuery
->
pos
=
-
1
;
pQuery
->
window
=
pQueryMsg
->
window
;
changeExecuteScanOrder
(
pQInfo
,
pQueryMsg
,
stableQuery
);
STimeWindow
window
=
pQuery
->
window
;
int32_t
index
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
pa
=
taosArrayGetP
(
p
TableGroupInfo
->
pGroupList
,
i
);
SArray
*
pa
=
taosArrayGetP
(
p
QInfo
->
tableGroupInfo
.
pGroupList
,
i
);
size_t
s
=
taosArrayGetSize
(
pa
);
SArray
*
p1
=
taosArrayInit
(
s
,
POINTER_BYTES
);
...
...
@@ -6179,12 +6175,9 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
for
(
int32_t
j
=
0
;
j
<
s
;
++
j
)
{
STableKeyInfo
*
info
=
taosArrayGet
(
pa
,
j
);
STableId
*
id
=
TSDB_TABLEID
(
info
->
pTable
);
STableIdInfo
*
pTableId
=
taosArraySearch
(
pTableIdList
,
id
,
compareTableIdInfo
);
window
.
skey
=
(
pTableId
!=
NULL
)
?
pTableId
->
key
:
pQueryMsg
->
window
.
skey
;
void
*
buf
=
(
char
*
)
pQInfo
->
pBuf
+
index
*
sizeof
(
STableQueryInfo
);
window
.
skey
=
info
->
lastKey
;
STableQueryInfo
*
item
=
createTableQueryInfo
(
&
pQInfo
->
runtimeEnv
,
info
->
pTable
,
window
,
buf
);
if
(
item
==
NULL
)
{
goto
_cleanup
;
...
...
@@ -6192,17 +6185,13 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
item
->
groupIndex
=
i
;
taosArrayPush
(
p1
,
&
item
);
STableId
*
id
=
TSDB_TABLEID
(
info
->
pTable
);
taosHashPut
(
pQInfo
->
tableqinfoGroupInfo
.
map
,
&
id
->
tid
,
sizeof
(
id
->
tid
),
&
item
,
POINTER_BYTES
);
index
+=
1
;
}
}
pQInfo
->
arrTableIdInfo
=
taosArrayInit
(
tableIndex
,
sizeof
(
STableIdInfo
));
pQInfo
->
dataReady
=
QUERY_RESULT_NOT_READY
;
pthread_mutex_init
(
&
pQInfo
->
lock
,
NULL
);
pQuery
->
pos
=
-
1
;
pQuery
->
window
=
pQueryMsg
->
window
;
colIdCheck
(
pQuery
);
qDebug
(
"qmsg:%p QInfo:%p created"
,
pQueryMsg
,
pQInfo
);
...
...
@@ -6558,7 +6547,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
assert
(
0
);
}
(
*
pQInfo
)
=
createQInfoImpl
(
pQueryMsg
,
p
TableIdList
,
pGroupbyExpr
,
pExprs
,
&
tableGroupInfo
,
pTagColumnInfo
);
(
*
pQInfo
)
=
createQInfoImpl
(
pQueryMsg
,
p
GroupbyExpr
,
pExprs
,
&
tableGroupInfo
,
pTagColumnInfo
,
isSTableQuery
);
pExprs
=
NULL
;
pGroupbyExpr
=
NULL
;
pTagColumnInfo
=
NULL
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录