Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c9933fd3
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
c9933fd3
编写于
7月 09, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225]
上级
79454952
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
86 addition
and
66 deletion
+86
-66
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+5
-3
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+1
-2
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+38
-59
src/query/src/qUtil.c
src/query/src/qUtil.c
+2
-2
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+40
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
c9933fd3
...
...
@@ -7802,13 +7802,15 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
}
static
STableMeta
*
extractTempTableMetaFromSubquery
(
SQueryInfo
*
pUpstream
)
{
int32_t
numOfColumns
=
pUpstream
->
fieldsInfo
.
numOfOutput
;
STableMetaInfo
*
pUpstreamTableMetaInfo
=
tscGetMetaInfo
(
pUpstream
,
0
)
;
STableMeta
*
meta
=
calloc
(
1
,
sizeof
(
STableMeta
)
+
sizeof
(
SSchema
)
*
numOfColumns
);
int32_t
numOfColumns
=
pUpstream
->
fieldsInfo
.
numOfOutput
;
STableMeta
*
meta
=
calloc
(
1
,
sizeof
(
STableMeta
)
+
sizeof
(
SSchema
)
*
numOfColumns
);
meta
->
tableType
=
TSDB_TEMP_TABLE
;
STableComInfo
*
info
=
&
meta
->
tableInfo
;
info
->
numOfColumns
=
numOfColumns
;
info
->
precision
=
pUpstreamTableMetaInfo
->
pTableMeta
->
tableInfo
.
precision
;
info
->
numOfTags
=
0
;
int32_t
n
=
0
;
...
...
src/query/inc/qExecutor.h
浏览文件 @
c9933fd3
...
...
@@ -105,8 +105,7 @@ typedef struct SResultRowInfo {
int16_t
type
:
8
;
// data type for hash key
int32_t
size
:
24
;
// number of result set
int32_t
capacity
;
// max capacity
SResultRow
*
current
;
// current start active index
int64_t
prevSKey
;
// previous (not completed) sliding window start key
SResultRow
*
current
;
// current active result row
}
SResultRowInfo
;
typedef
struct
SColumnFilterElem
{
...
...
src/query/src/qExecutor.c
浏览文件 @
c9933fd3
...
...
@@ -242,6 +242,7 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeE
if
(
size
<=
0
)
{
return
;
}
int32_t
orderId
=
pRuntimeEnv
->
pQueryAttr
->
order
.
orderColId
;
if
(
orderId
<=
0
)
{
return
;
...
...
@@ -410,21 +411,6 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, SQueryRuntim
pResultRowInfo
->
capacity
=
(
int32_t
)
newCapacity
;
}
//static int32_t ascResultRowCompareFn(const void* p1, const void* p2) {
// SResultRow* pRow1 = *(SResultRow**)p1;
// SResultRow* pRow2 = *(SResultRow**)p2;
//
// if (pRow1 == pRow2) {
// return 0;
// } else {
// return pRow1->win.skey < pRow2->win.skey? -1:1;
// }
//}
//static int32_t descResultRowCompareFn(const void* p1, const void* p2) {
// return -ascResultRowCompareFn(p1, p2);
//}
static
SResultRow
*
doPrepareResultRowFromKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
int64_t
tid
,
char
*
pData
,
int16_t
bytes
,
bool
masterscan
,
uint64_t
tableGroupId
)
{
bool
existed
=
false
;
...
...
@@ -450,11 +436,6 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
pData
,
bytes
,
tid
);
void
*
ptr
=
taosHashGet
(
pRuntimeEnv
->
pResultRowListSet
,
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
));
existed
=
(
ptr
!=
NULL
);
// __compar_fn_t fn = QUERY_IS_ASC_QUERY(pRuntimeEnv->pQueryAttr)? ascResultRowCompareFn:descResultRowCompareFn;
// void* ptr = taosbsearch(p1, pResultRowInfo->pResult, pResultRowInfo->size, POINTER_BYTES, fn, TD_EQ);
// if (ptr != NULL) {
// existed = true;
// }
}
}
}
else
{
...
...
@@ -526,12 +507,12 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t
STimeWindow
w
=
{
0
};
if
(
pResultRowInfo
->
current
==
NULL
)
{
// the first window, from the previous stored value
if
(
pResultRowInfo
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
//
if (pResultRowInfo->prevSKey == TSKEY_INITIAL_VAL) {
getInitialStartTimeWindow
(
pQueryAttr
,
ts
,
&
w
);
pResultRowInfo
->
prevSKey
=
w
.
skey
;
}
else
{
w
.
skey
=
pResultRowInfo
->
prevSKey
;
}
//
pResultRowInfo->prevSKey = w.skey;
//
} else {
//
w.skey = pResultRowInfo->prevSKey;
//
}
if
(
pQueryAttr
->
interval
.
intervalUnit
==
'n'
||
pQueryAttr
->
interval
.
intervalUnit
==
'y'
)
{
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pQueryAttr
->
interval
.
interval
,
pQueryAttr
->
interval
.
intervalUnit
,
pQueryAttr
->
precision
)
-
1
;
...
...
@@ -539,10 +520,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t
w
.
ekey
=
w
.
skey
+
pQueryAttr
->
interval
.
interval
-
1
;
}
}
else
{
// int32_t slot = curTimeWindowIndex(pResultRowInfo);
// SResultRow* pWindowRes = getResultRow(pResultRowInfo, slot);
SResultRow
*
pWindowRes
=
pResultRowInfo
->
current
;
w
=
pWindowRes
->
win
;
w
=
pResultRowInfo
->
current
->
win
;
}
if
(
w
.
skey
>
ts
||
w
.
ekey
<
ts
)
{
...
...
@@ -747,8 +725,6 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey,
}
else
{
pResultRowInfo
->
current
=
pResultRowInfo
->
pResult
[
i
+
1
];
// current not closed result object
}
pResultRowInfo
->
prevSKey
=
pResultRowInfo
->
current
->
win
.
skey
;
}
}
...
...
@@ -1266,7 +1242,6 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
SResultRow
*
prevRow
=
pResultRowInfo
->
current
;
// int32_t prevIndex = curTimeWindowIndex(pResultRowInfo);
TSKEY
*
tsCols
=
NULL
;
if
(
pSDataBlock
->
pDataBlock
!=
NULL
)
{
...
...
@@ -1313,16 +1288,16 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
}
STimeWindow
w
=
pRes
->
win
;
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pResultRowInfo
,
pSDataBlock
->
info
.
tid
,
&
w
,
masterScan
,
&
pResult
,
tableGroupId
,
pInfo
->
pCtx
,
numOfOutput
,
pInfo
->
rowCellInfoOffset
);
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pResultRowInfo
,
pSDataBlock
->
info
.
tid
,
&
w
,
masterScan
,
&
pResult
,
tableGroupId
,
pInfo
->
pCtx
,
numOfOutput
,
pInfo
->
rowCellInfoOffset
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
assert
(
!
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
));
doTimeWindowInterpolation
(
pOperatorInfo
,
pInfo
,
pSDataBlock
->
pDataBlock
,
*
(
TSKEY
*
)
pRuntimeEnv
->
prevRow
[
0
]
,
-
1
,
tsCols
[
startPos
],
startPos
,
w
.
ekey
,
RESULT_ROW_END_INTERP
);
doTimeWindowInterpolation
(
pOperatorInfo
,
pInfo
,
pSDataBlock
->
pDataBlock
,
*
(
TSKEY
*
)
pRuntimeEnv
->
prevRow
[
0
],
-
1
,
tsCols
[
startPos
],
startPos
,
w
.
ekey
,
RESULT_ROW_END_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
setNotInterpoWindowKey
(
pInfo
->
pCtx
,
pQueryAttr
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
...
...
@@ -3703,12 +3678,16 @@ void setParamForStableStddevByColData(SQueryRuntimeEnv* pRuntimeEnv, SQLFunction
void
setIntervalQueryRange
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
TSKEY
key
)
{
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
SResultRowInfo
*
p
WindowRes
Info
=
&
pTableQueryInfo
->
resInfo
;
SResultRowInfo
*
p
ResultRow
Info
=
&
pTableQueryInfo
->
resInfo
;
if
(
p
WindowResInfo
->
prevSKey
!=
TSKEY_INITIAL_VA
L
)
{
if
(
p
ResultRowInfo
->
current
!=
NUL
L
)
{
return
;
}
// if (pWindowResInfo->prevSKey != TSKEY_INITIAL_VAL) {
// return;
// }
pTableQueryInfo
->
win
.
skey
=
key
;
STimeWindow
win
=
{.
skey
=
key
,
.
ekey
=
pQueryAttr
->
window
.
ekey
};
...
...
@@ -3724,13 +3703,13 @@ void setIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key) {
TSKEY
ek
=
MAX
(
win
.
skey
,
win
.
ekey
);
getAlignQueryTimeWindow
(
pQueryAttr
,
win
.
skey
,
sk
,
ek
,
&
w
);
if
(
pWindowRes
Info
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQueryAttr
))
{
assert
(
win
.
ekey
==
pQueryAttr
->
window
.
ekey
);
}
pWindowRes
Info
->
prevSKey
=
w
.
skey
;
}
// if (pResultRow
Info->prevSKey == TSKEY_INITIAL_VAL) {
//
if (!QUERY_IS_ASC_QUERY(pQueryAttr)) {
//
assert(win.ekey == pQueryAttr->window.ekey);
//
}
//
// pResultRow
Info->prevSKey = w.skey;
//
}
pTableQueryInfo
->
lastKey
=
pTableQueryInfo
->
win
.
skey
;
}
...
...
@@ -4631,7 +4610,7 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) {
if
(
pResultRowInfo
->
size
>
0
)
{
pResultRowInfo
->
current
=
pResultRowInfo
->
pResult
[
0
];
pResultRowInfo
->
prevSKey
=
pResultRowInfo
->
pResult
[
0
]
->
win
.
skey
;
//
pResultRowInfo->prevSKey = pResultRowInfo->pResult[0]->win.skey;
}
qDebug
(
"QInfo:0x%"
PRIx64
" start to repeat scan data blocks due to query func required, qrange:%"
PRId64
"-%"
PRId64
,
...
...
@@ -4657,7 +4636,7 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) {
if
(
pResultRowInfo
->
size
>
0
)
{
pResultRowInfo
->
current
=
pResultRowInfo
->
pResult
[
pResultRowInfo
->
size
-
1
];
pResultRowInfo
->
prevSKey
=
pResultRowInfo
->
current
->
win
.
skey
;
//
pResultRowInfo->prevSKey = pResultRowInfo->current->win.skey;
}
p
=
doTableScanImpl
(
pOperator
,
newgroup
);
...
...
src/query/src/qUtil.c
浏览文件 @
c9933fd3
...
...
@@ -44,7 +44,7 @@ int32_t getOutputInterResultBufSize(SQueryAttr* pQueryAttr) {
int32_t
initResultRowInfo
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
size
,
int16_t
type
)
{
pResultRowInfo
->
type
=
type
;
pResultRowInfo
->
size
=
0
;
pResultRowInfo
->
prevSKey
=
TSKEY_INITIAL_VAL
;
//
pResultRowInfo->prevSKey = TSKEY_INITIAL_VAL;
pResultRowInfo
->
current
=
NULL
;
pResultRowInfo
->
capacity
=
size
;
...
...
@@ -93,7 +93,7 @@ void resetResultRowInfo(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRo
pResultRowInfo
->
size
=
0
;
pResultRowInfo
->
current
=
NULL
;
pResultRowInfo
->
prevSKey
=
TSKEY_INITIAL_VAL
;
//
pResultRowInfo->prevSKey = TSKEY_INITIAL_VAL;
}
int32_t
numOfClosedResultRows
(
SResultRowInfo
*
pResultRowInfo
)
{
...
...
tests/script/general/parser/nestquery.sim
浏览文件 @
c9933fd3
...
...
@@ -450,4 +450,44 @@ if $data11 != 1 then
return -1
endi
print =====================>TD-5157
sql select twa(c1) from nest_tb1 interval(19a);
if $rows != 10000 then
return -1
endi
if $data00 != @20-09-14 23:59:59.992@ then
return -1
endi
if $data01 != 0.000083333 then
return -1
endi
print =================>us database interval query, TD-5039
sql create database test precision 'us';
sql use test;
sql create table t1(ts timestamp, k int);
sql insert into t1 values('2020-01-01 01:01:01.000', 1) ('2020-01-01 01:02:00.000', 2);
sql select avg(k) from (select avg(k) k from t1 interval(1s)) interval(1m);
if $rows != 2 then
return -1
endi
if $data00 != @20-01-01 01:01:00.000000@ then
return -1
endi
if $data01 != 1.000000000 then
return -1
endi
if $data10 != @20-01-01 01:02:00.000000@ then
return -1
endi
if $data11 != 2.000000000 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录