Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ecb757b1
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ecb757b1
编写于
9月 03, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
9月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3362 from taosdata/feature/query
[td-1317]
上级
07410285
4db1086e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
132 addition
and
55 deletion
+132
-55
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+61
-43
src/query/src/qPercentile.c
src/query/src/qPercentile.c
+7
-2
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+24
-5
tests/script/general/parser/lastrow_query.sim
tests/script/general/parser/lastrow_query.sim
+18
-0
tests/script/general/parser/timestamp.sim
tests/script/general/parser/timestamp.sim
+1
-1
tests/script/general/parser/timestamp_query.sim
tests/script/general/parser/timestamp_query.sim
+21
-4
未找到文件。
src/query/src/qExecutor.c
浏览文件 @
ecb757b1
...
...
@@ -1951,36 +1951,36 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bo
// todo handle the case the the order irrelevant query type mixed up with order critical query type
// descending order query for last_row query
if
(
isFirstLastRowQuery
(
pQuery
))
{
if
(
isFirstLastRowQuery
(
pQuery
)
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
)
)
{
qDebug
(
"QInfo:%p scan order changed for last_row query, old:%d, new:%d"
,
GET_QINFO_ADDR
(
pQuery
),
pQuery
->
order
.
order
,
TSDB_ORDER_ASC
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
pQuery
->
order
.
order
=
TSDB_ORDER_ASC
;
if
(
pQuery
->
window
.
skey
>
pQuery
->
window
.
ekey
)
{
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
assert
(
pQuery
->
window
.
skey
<=
pQuery
->
window
.
ekey
);
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
return
;
}
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
&&
pQuery
->
order
.
order
==
TSDB_ORDER_DESC
)
{
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
)
)
{
pQuery
->
order
.
order
=
TSDB_ORDER_ASC
;
if
(
pQuery
->
window
.
skey
>
pQuery
->
window
.
ekey
)
{
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
assert
(
pQuery
->
window
.
skey
<=
pQuery
->
window
.
ekey
);
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
return
;
}
if
(
isPointInterpoQuery
(
pQuery
)
&&
pQuery
->
intervalTime
==
0
)
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
qDebug
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"interp"
,
pQuery
->
order
.
order
,
TSDB_ORDER_ASC
,
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
}
if
(
isPointInterpoQuery
(
pQuery
)
&&
(
pQuery
->
intervalTime
==
0
)
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
qDebug
(
msg
,
GET_QINFO_ADDR
(
pQuery
),
"interp"
,
pQuery
->
order
.
order
,
TSDB_ORDER_ASC
,
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pQuery
->
window
.
skey
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
pQuery
->
order
.
order
=
TSDB_ORDER_ASC
;
assert
(
pQuery
->
window
.
skey
<=
pQuery
->
window
.
ekey
);
doExchangeTimeWindow
(
pQInfo
,
&
pQuery
->
window
);
return
;
}
...
...
@@ -4354,6 +4354,32 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) {
return
true
;
}
static
void
freeTableQueryInfo
(
STableGroupInfo
*
pTableGroupInfo
)
{
if
(
pTableGroupInfo
->
pGroupList
==
NULL
)
{
assert
(
pTableGroupInfo
->
numOfTables
==
0
);
}
else
{
size_t
numOfGroups
=
taosArrayGetSize
(
pTableGroupInfo
->
pGroupList
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
p
=
taosArrayGetP
(
pTableGroupInfo
->
pGroupList
,
i
);
size_t
num
=
taosArrayGetSize
(
p
);
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
STableQueryInfo
*
item
=
taosArrayGetP
(
p
,
j
);
destroyTableQueryInfo
(
item
);
}
taosArrayDestroy
(
p
);
}
taosArrayDestroy
(
pTableGroupInfo
->
pGroupList
);
pTableGroupInfo
->
pGroupList
=
NULL
;
pTableGroupInfo
->
numOfTables
=
0
;
}
taosHashCleanup
(
pTableGroupInfo
->
map
);
pTableGroupInfo
->
map
=
NULL
;
}
static
int32_t
setupQueryHandle
(
void
*
tsdb
,
SQInfo
*
pQInfo
,
bool
isSTableQuery
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
...
...
@@ -4389,20 +4415,22 @@ static int32_t setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery)
terrno
=
TSDB_CODE_SUCCESS
;
if
(
isFirstLastRowQuery
(
pQuery
))
{
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryLastRow
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
if
(
pRuntimeEnv
->
pQueryHandle
==
NULL
)
{
// no data in current stable, clear all
freeTableQueryInfo
(
&
pQInfo
->
tableqinfoGroupInfo
);
}
else
{
// update the query time window
pQuery
->
window
=
cond
.
twindow
;
// update the query time window
pQuery
->
window
=
cond
.
twindow
;
size_t
numOfGroups
=
GET_NUM_OF_TABLEGROUP
(
pQInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
group
=
GET_TABLEGROUP
(
pQInfo
,
i
);
size_t
numOfGroups
=
GET_NUM_OF_TABLEGROUP
(
pQInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
group
=
GET_TABLEGROUP
(
pQInfo
,
i
);
size_t
t
=
taosArrayGetSize
(
group
);
for
(
int32_t
j
=
0
;
j
<
t
;
++
j
)
{
STableQueryInfo
*
pCheckInfo
=
taosArrayGetP
(
group
,
j
);
size_t
t
=
taosArrayGetSize
(
group
);
for
(
int32_t
j
=
0
;
j
<
t
;
++
j
)
{
STableQueryInfo
*
pCheckInfo
=
taosArrayGetP
(
group
,
j
);
pCheckInfo
->
win
=
pQuery
->
window
;
pCheckInfo
->
lastKey
=
pCheckInfo
->
win
.
skey
;
pCheckInfo
->
win
=
pQuery
->
window
;
pCheckInfo
->
lastKey
=
pCheckInfo
->
win
.
skey
;
}
}
}
}
else
if
(
isPointInterpoQuery
(
pQuery
))
{
...
...
@@ -4456,6 +4484,12 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
return
code
;
}
if
(
pQInfo
->
tableqinfoGroupInfo
.
numOfTables
==
0
)
{
qDebug
(
"QInfo:%p no table qualified for tag filter, abort query"
,
pQInfo
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
return
TSDB_CODE_SUCCESS
;
}
pQInfo
->
tsdb
=
tsdb
;
pQInfo
->
vgId
=
vgId
;
...
...
@@ -6349,29 +6383,13 @@ static void freeQInfo(SQInfo *pQInfo) {
taosTFree
(
pQuery
);
}
// todo refactor, extract method to destroytableDataInfo
if
(
pQInfo
->
tableqinfoGroupInfo
.
pGroupList
!=
NULL
)
{
int32_t
numOfGroups
=
(
int32_t
)(
GET_NUM_OF_TABLEGROUP
(
pQInfo
));
for
(
int32_t
i
=
0
;
i
<
numOfGroups
;
++
i
)
{
SArray
*
p
=
GET_TABLEGROUP
(
pQInfo
,
i
);
size_t
num
=
taosArrayGetSize
(
p
);
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
STableQueryInfo
*
item
=
taosArrayGetP
(
p
,
j
);
destroyTableQueryInfo
(
item
);
}
taosArrayDestroy
(
p
);
}
}
freeTableQueryInfo
(
&
pQInfo
->
tableqinfoGroupInfo
);
taosTFree
(
pQInfo
->
pBuf
);
taosArrayDestroy
(
pQInfo
->
tableqinfoGroupInfo
.
pGroupList
);
taosHashCleanup
(
pQInfo
->
tableqinfoGroupInfo
.
map
);
tsdbDestroyTableGroup
(
&
pQInfo
->
tableGroupInfo
);
taosArrayDestroy
(
pQInfo
->
arrTableIdInfo
);
pQInfo
->
signature
=
0
;
qDebug
(
"QInfo:%p QInfo is freed"
,
pQInfo
);
...
...
src/query/src/qPercentile.c
浏览文件 @
ecb757b1
...
...
@@ -154,9 +154,14 @@ int32_t tBucketBigIntHash(tMemBucket *pBucket, const void *value) {
// todo refactor to more generic
int32_t
tBucketIntHash
(
tMemBucket
*
pBucket
,
const
void
*
value
)
{
int32_t
v
=
*
(
int32_t
*
)
value
;
int32_t
index
=
-
1
;
int32_t
v
=
0
;
switch
(
pBucket
->
type
)
{
case
TSDB_DATA_TYPE_SMALLINT
:
v
=
*
(
int16_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
v
=
*
(
int8_t
*
)
value
;
break
;
default:
v
=
*
(
int32_t
*
)
value
;
break
;
}
int32_t
index
=
-
1
;
if
(
pBucket
->
range
.
iMaxVal
==
INT32_MIN
)
{
/*
* taking negative integer into consideration,
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
ecb757b1
...
...
@@ -295,9 +295,16 @@ out_of_memory:
}
TsdbQueryHandleT
tsdbQueryLastRow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
)
{
pCond
->
order
=
TSDB_ORDER_ASC
;
pCond
->
twindow
=
changeTableGroupByLastrow
(
groupList
);
// no qualified table
if
(
groupList
->
numOfTables
==
0
)
{
return
NULL
;
}
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
tsdbQueryTables
(
tsdb
,
pCond
,
groupList
,
qinfo
);
assert
(
pCond
->
order
==
TSDB_ORDER_ASC
&&
pCond
->
twindow
.
skey
<=
pCond
->
twindow
.
ekey
);
return
pQueryHandle
;
}
...
...
@@ -1981,8 +1988,9 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
STimeWindow
changeTableGroupByLastrow
(
STableGroupInfo
*
groupList
)
{
STimeWindow
window
=
{
INT64_MAX
,
INT64_MIN
};
int32_t
totalNumOfTable
=
0
;
// NOTE: starts from the buffer in case of descending timestamp order check data blocks
// todo consider the query time window, current last_row does not apply the query time window
size_t
numOfGroups
=
taosArrayGetSize
(
groupList
->
pGroupList
);
for
(
int32_t
j
=
0
;
j
<
numOfGroups
;
++
j
)
{
SArray
*
pGroup
=
taosArrayGetP
(
groupList
->
pGroupList
,
j
);
...
...
@@ -1993,8 +2001,9 @@ STimeWindow changeTableGroupByLastrow(STableGroupInfo *groupList) {
size_t
numOfTables
=
taosArrayGetSize
(
pGroup
);
for
(
int32_t
i
=
0
;
i
<
numOfTables
;
++
i
)
{
STableKeyInfo
*
pKeyInfo
=
(
STableKeyInfo
*
)
taosArrayGet
(
pGroup
,
i
);
TSKEY
lastKey
=
((
STable
*
)(
pKeyInfo
->
pTable
))
->
lastKey
;
// if the lastKey equals to INT64_MIN, there is no data in this table
TSKEY
lastKey
=
((
STable
*
)(
pKeyInfo
->
pTable
))
->
lastKey
;
if
(
key
<
lastKey
)
{
key
=
lastKey
;
...
...
@@ -2012,13 +2021,23 @@ STimeWindow changeTableGroupByLastrow(STableGroupInfo *groupList) {
}
}
// clear current group
taosArrayClear
(
pGroup
);
// more than one table in each group, only one table left for each group
if
(
numOfTables
>
1
)
{
t
aosArrayClear
(
pGroup
)
;
if
(
keyInfo
.
pTable
!=
NULL
)
{
t
otalNumOfTable
++
;
taosArrayPush
(
pGroup
,
&
keyInfo
);
}
}
// window does not being updated, so set the original
if
(
window
.
skey
==
INT64_MAX
&&
window
.
ekey
==
INT64_MIN
)
{
window
=
TSWINDOW_INITIALIZER
;
assert
(
totalNumOfTable
==
0
);
}
groupList
->
numOfTables
=
totalNumOfTable
;
return
window
;
}
...
...
tests/script/general/parser/lastrow_query.sim
浏览文件 @
ecb757b1
...
...
@@ -153,4 +153,22 @@ if $rows != 46 then
return -1
endi
print ========>td-1317, empty table last_row query crashed
sql create table m1(ts timestamp, k int) tags (a int);
sql create table t1 using m1 tags(1);
sql create table t2 using m1 tags(2);
sql select last_row(*) from t1
if $rows != 0 then
return -1
endi
sql select last_row(*) from m1
if $rows != 0 then
return -1
endi
sql select last_row(*) from m1 where tbname in ('t1')
if $rows != 0 then
return -1
endi
tests/script/general/parser/timestamp.sim
浏览文件 @
ecb757b1
...
...
@@ -20,7 +20,7 @@ $db = $dbPrefix . $i
$stb = $stbPrefix . $i
sql drop database if exists $db
sql create database $db maxrows 200
cache 1024 tblocks 200
maxTables 4
sql create database $db maxrows 200 maxTables 4
print ====== create tables
sql use $db
sql create table $stb (ts timestamp, c1 timestamp, c2 int) tags(t1 binary(20))
...
...
tests/script/general/parser/timestamp_query.sim
浏览文件 @
ecb757b1
...
...
@@ -22,12 +22,29 @@ $tsu = $tsu - $delta
$tsu = $tsu + $ts0
##### select from supertable
$tb = $tbPrefix . 0
sql select first(c1), last(c1) from $tb where ts >= $ts0 and ts < $tsu interval(5m) fill(value, -1)
sql select first(c1), last(c1)
, (1537325400 - 1537146000)/(5*60) v
from $tb where ts >= $ts0 and ts < $tsu interval(5m) fill(value, -1)
$res = $rowNum * 2
$res = $res - 1
if $rows != $res then
$n = $res - 2
print ============>$n
if $rows != $n then
print expect $n, actual $rows
return -1
endi
if $data03 != 598.000000000 then
print expect 598.000000000, actual $data03
return -1
endi
if $data13 != 598.000000000 then
print expect 598.000000000, actual $data03
return -1
endi
sql select first(c1), last(c1), (1537325400 - 1537146000)/(5*60) v from $tb where ts >= $ts0 and ts < $tsu interval(5m) fill(value, NULL)
if $data13 != 598.000000000 then
print expect 598.000000000, actual $data03
return -1
endi
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录