Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
2891d51a
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2891d51a
编写于
3月 11, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-2895] fix bug found by regression test.
上级
2b9e364f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
101 addition
and
59 deletion
+101
-59
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+26
-16
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+72
-43
tests/script/general/parser/testSuite.sim
tests/script/general/parser/testSuite.sim
+3
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
2891d51a
...
...
@@ -1536,6 +1536,7 @@ bool isValidDistinctSql(SQueryInfo* pQueryInfo) {
}
return
false
;
}
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
tSQLExprList
*
pSelection
,
bool
isSTable
,
bool
joinQuery
,
bool
intervalQuery
)
{
assert
(
pSelection
!=
NULL
&&
pCmd
!=
NULL
);
...
...
@@ -1871,6 +1872,26 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT
}
}
static
void
updateLastQueryInfoForGroupby
(
SQueryInfo
*
pQueryInfo
,
STableMeta
*
pTableMeta
,
int32_t
functionId
,
int32_t
index
)
{
if
(
functionId
!=
TSDB_FUNC_LAST
)
{
// todo refactor
return
;
}
SSqlGroupbyExpr
*
pGroupBy
=
&
pQueryInfo
->
groupbyExpr
;
if
(
pGroupBy
->
numOfGroupCols
>
0
)
{
for
(
int32_t
k
=
0
;
k
<
pGroupBy
->
numOfGroupCols
;
++
k
)
{
SColIndex
*
pIndex
=
taosArrayGet
(
pGroupBy
->
columnInfo
,
k
);
if
(
!
TSDB_COL_IS_TAG
(
pIndex
->
flag
)
&&
pIndex
->
colIndex
<
tscGetNumOfColumns
(
pTableMeta
))
{
// group by normal columns
SSqlExpr
*
pExpr
=
taosArrayGetP
(
pQueryInfo
->
exprList
,
index
);
pExpr
->
numOfParams
=
1
;
pExpr
->
param
->
i64
=
TSDB_ORDER_ASC
;
return
;
}
}
}
}
int32_t
addExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
colIndex
,
tSqlExprItem
*
pItem
,
bool
finalResult
)
{
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
int32_t
functionId
=
pItem
->
pNode
->
functionId
;
...
...
@@ -2135,6 +2156,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
&
pSchema
[
j
],
cvtFunc
,
name
,
colIndex
++
,
&
index
,
finalResult
)
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
updateLastQueryInfoForGroupby
(
pQueryInfo
,
pTableMetaInfo
->
pTableMeta
,
functionId
,
colIndex
-
1
);
}
}
else
{
...
...
@@ -2150,7 +2173,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
index
.
columnIndex
);
bool
multiColOutput
=
pItem
->
pNode
->
pParam
->
nExpr
>
1
;
...
...
@@ -2160,21 +2182,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
TSDB_CODE_TSC_INVALID_SQL
;
}
if
(
functionId
==
TSDB_FUNC_LAST
)
{
// todo refactor
SSqlGroupbyExpr
*
pGroupBy
=
&
pQueryInfo
->
groupbyExpr
;
if
(
pGroupBy
->
numOfGroupCols
>
0
)
{
for
(
int32_t
k
=
0
;
k
<
pGroupBy
->
numOfGroupCols
;
++
k
)
{
SColIndex
*
pIndex
=
taosArrayGet
(
pGroupBy
->
columnInfo
,
k
);
if
(
!
TSDB_COL_IS_TAG
(
pIndex
->
flag
)
&&
pIndex
->
colIndex
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
{
// group by normal columns
SSqlExpr
*
pExpr
=
taosArrayGetP
(
pQueryInfo
->
exprList
,
colIndex
+
i
);
pExpr
->
numOfParams
=
1
;
pExpr
->
param
->
i64
=
TSDB_ORDER_ASC
;
break
;
}
}
}
}
updateLastQueryInfoForGroupby
(
pQueryInfo
,
pTableMetaInfo
->
pTableMeta
,
functionId
,
colIndex
+
i
);
}
}
...
...
@@ -2202,6 +2210,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
TSDB_CODE_TSC_INVALID_SQL
;
}
updateLastQueryInfoForGroupby
(
pQueryInfo
,
pTableMetaInfo
->
pTableMeta
,
functionId
,
colIndex
);
colIndex
++
;
}
...
...
@@ -2211,6 +2220,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
TSDB_CODE_SUCCESS
;
}
}
case
TSDB_FUNC_TOP
:
case
TSDB_FUNC_BOTTOM
:
case
TSDB_FUNC_PERCT
:
...
...
src/query/src/qExecutor.c
浏览文件 @
2891d51a
...
...
@@ -35,6 +35,13 @@
#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC))
#define CHECK_IF_QUERY_KILLED(_q) \
do { \
if (isQueryKilled((_q)->qinfo)) { \
longjmp((_q)->env, TSDB_CODE_TSC_QUERY_CANCELLED); \
} \
} while (0)
#define SDATA_BLOCK_INITIALIZER (SDataBlockInfo) {{0}, 0}
#define TIME_WINDOW_COPY(_dst, _src) do {\
...
...
@@ -189,6 +196,9 @@ static bool isPointInterpoQuery(SQuery *pQuery);
static
void
setResultBufSize
(
SQuery
*
pQuery
,
SRspResultInfo
*
pResultInfo
);
static
void
setCtxTagForJoin
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
void
*
pTable
);
static
void
setParamForStableStddev
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
SExprInfo
*
pExpr
);
static
void
doSetTableGroupOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
groupIndex
);
// setup the output buffer for each operator
static
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
)
{
...
...
@@ -378,6 +388,32 @@ static bool hasNullRv(SColIndex* pColIndex, SDataStatis *pStatis) {
return
true
;
}
static
void
prepareResultListBuffer
(
SResultRowInfo
*
pResultRowInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
// more than the capacity, reallocate the resources
if
(
pResultRowInfo
->
size
<
pResultRowInfo
->
capacity
)
{
return
;
}
int64_t
newCapacity
=
0
;
if
(
pResultRowInfo
->
capacity
>
10000
)
{
newCapacity
=
(
int64_t
)(
pResultRowInfo
->
capacity
*
1
.
25
);
}
else
{
newCapacity
=
(
int64_t
)(
pResultRowInfo
->
capacity
*
1
.
5
);
}
char
*
t
=
realloc
(
pResultRowInfo
->
pResult
,
(
size_t
)(
newCapacity
*
POINTER_BYTES
));
if
(
t
==
NULL
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
pResultRowInfo
->
pResult
=
(
SResultRow
**
)
t
;
int32_t
inc
=
(
int32_t
)
newCapacity
-
pResultRowInfo
->
capacity
;
memset
(
&
pResultRowInfo
->
pResult
[
pResultRowInfo
->
capacity
],
0
,
POINTER_BYTES
*
inc
);
pResultRowInfo
->
capacity
=
(
int32_t
)
newCapacity
;
}
static
SResultRow
*
doPrepareResultRowFromKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
char
*
pData
,
int16_t
bytes
,
bool
masterscan
,
uint64_t
uid
)
{
bool
existed
=
false
;
...
...
@@ -408,28 +444,7 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes
}
if
(
!
existed
)
{
// TODO refactor
// more than the capacity, reallocate the resources
if
(
pResultRowInfo
->
size
>=
pResultRowInfo
->
capacity
)
{
int64_t
newCapacity
=
0
;
if
(
pResultRowInfo
->
capacity
>
10000
)
{
newCapacity
=
(
int64_t
)(
pResultRowInfo
->
capacity
*
1
.
25
);
}
else
{
newCapacity
=
(
int64_t
)(
pResultRowInfo
->
capacity
*
1
.
5
);
}
char
*
t
=
realloc
(
pResultRowInfo
->
pResult
,
(
size_t
)(
newCapacity
*
POINTER_BYTES
));
if
(
t
==
NULL
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
pResultRowInfo
->
pResult
=
(
SResultRow
**
)
t
;
int32_t
inc
=
(
int32_t
)
newCapacity
-
pResultRowInfo
->
capacity
;
memset
(
&
pResultRowInfo
->
pResult
[
pResultRowInfo
->
capacity
],
0
,
POINTER_BYTES
*
inc
);
pResultRowInfo
->
capacity
=
(
int32_t
)
newCapacity
;
}
prepareResultListBuffer
(
pResultRowInfo
,
pRuntimeEnv
);
SResultRow
*
pResult
=
NULL
;
...
...
@@ -2486,6 +2501,10 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
pTableScanInfo
->
rowCellInfoOffset
)
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
else
if
(
pQuery
->
stableQuery
)
{
// stable aggregate, not interval aggregate or normal column aggregate
doSetTableGroupOutputBuf
(
pRuntimeEnv
,
pTableScanInfo
->
pResultRowInfo
,
pTableScanInfo
->
pCtx
,
pTableScanInfo
->
rowCellInfoOffset
,
pTableScanInfo
->
numOfOutput
,
pQuery
->
current
->
groupIndex
);
}
(
*
status
)
=
doFilterByBlockTimeWindow
(
pTableScanInfo
,
pBlock
);
...
...
@@ -3101,7 +3120,9 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
int16_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
pCtx
[
i
].
resultInfo
=
getResultCell
(
pResult
,
i
,
rowCellInfoOffset
);
if
(
pCtx
->
resultInfo
->
initialized
&&
pCtx
->
resultInfo
->
complete
)
{
SResultRowCellInfo
*
pResInfo
=
pCtx
[
i
].
resultInfo
;
if
(
pResInfo
->
initialized
&&
pResInfo
->
complete
)
{
offset
+=
pCtx
[
i
].
outputBytes
;
continue
;
}
...
...
@@ -3114,25 +3135,17 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
0
].
pOutput
;
}
if
(
!
p
Ctx
[
i
].
result
Info
->
initialized
)
{
if
(
!
p
Res
Info
->
initialized
)
{
aAggs
[
functionId
].
init
(
&
pCtx
[
i
]);
}
}
}
void
setExecutionContext
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int32_t
numOfOutput
,
int32_t
groupIndex
,
TSKEY
nextKey
)
{
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
pQuery
->
current
;
// lastKey needs to be updated
pTableQueryInfo
->
lastKey
=
nextKey
;
if
(
pRuntimeEnv
->
prevGroupId
!=
INT32_MIN
&&
pRuntimeEnv
->
prevGroupId
==
groupIndex
)
{
return
;
}
void
doSetTableGroupOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
*
rowCellInfoOffset
,
int32_t
numOfOutput
,
int32_t
groupIndex
)
{
int64_t
uid
=
0
;
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pInfo
->
r
esultRowInfo
,
(
char
*
)
&
groupIndex
,
sizeof
(
groupIndex
),
true
,
uid
);
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pR
esultRowInfo
,
(
char
*
)
&
groupIndex
,
sizeof
(
groupIndex
),
true
,
uid
);
assert
(
pResultRow
!=
NULL
);
/*
...
...
@@ -3140,16 +3153,29 @@ void setExecutionContext(SQueryRuntimeEnv* pRuntimeEnv, SOptrBasicInfo* pInfo, i
* all group belong to one result set, and each group result has different group id so set the id to be one
*/
if
(
pResultRow
->
pageId
==
-
1
)
{
i
f
(
addNewWindowResultBuf
(
pResultRow
,
pRuntimeEnv
->
pResultBuf
,
groupIndex
,
pRuntimeEnv
->
pQuery
->
resultRowSize
)
!=
TSDB_CODE_SUCCESS
)
{
i
nt32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
pRuntimeEnv
->
pResultBuf
,
groupIndex
,
pRuntimeEnv
->
pQuery
->
resultRowSize
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
}
setResultRowOutputBufInitCtx
(
pRuntimeEnv
,
pResultRow
,
pCtx
,
numOfOutput
,
rowCellInfoOffset
);
}
void
setExecutionContext
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int32_t
numOfOutput
,
int32_t
groupIndex
,
TSKEY
nextKey
)
{
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
pQuery
->
current
;
// lastKey needs to be updated
pTableQueryInfo
->
lastKey
=
nextKey
;
if
(
pRuntimeEnv
->
prevGroupId
!=
INT32_MIN
&&
pRuntimeEnv
->
prevGroupId
==
groupIndex
)
{
return
;
}
doSetTableGroupOutputBuf
(
pRuntimeEnv
,
&
pInfo
->
resultRowInfo
,
pInfo
->
pCtx
,
pInfo
->
rowCellInfoOffset
,
numOfOutput
,
groupIndex
);
// record the current active group id
pRuntimeEnv
->
prevGroupId
=
groupIndex
;
setResultOutputBuf
(
pRuntimeEnv
,
pResultRow
,
pInfo
->
pCtx
,
numOfOutput
,
pInfo
->
rowCellInfoOffset
);
initCtxOutputBuffer
(
pInfo
->
pCtx
,
numOfOutput
);
}
void
setResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
,
SQLFunctionCtx
*
pCtx
,
...
...
@@ -3981,11 +4007,14 @@ static SSDataBlock* doTableScanImpl(void* param) {
STableGroupInfo
*
pTableGroupInfo
=
&
pOperator
->
pRuntimeEnv
->
tableqinfoGroupInfo
;
while
(
tsdbNextDataBlock
(
pTableScanInfo
->
pQueryHandle
))
{
pTableScanInfo
->
numOfBlocks
+=
1
;
if
(
isQueryKilled
(
pOperator
->
pRuntimeEnv
->
qinfo
))
{
longjmp
(
pOperator
->
pRuntimeEnv
->
env
,
TSDB_CODE_TSC_QUERY_CANCELLED
);
}
// todo check for query cancel
pTableScanInfo
->
numOfBlocks
+=
1
;
tsdbRetrieveDataBlockInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pBlock
->
info
);
// todo opt
if
(
pTableGroupInfo
->
numOfTables
>
1
||
(
pQuery
->
current
==
NULL
&&
pTableGroupInfo
->
numOfTables
==
1
))
{
STableQueryInfo
**
pTableQueryInfo
=
(
STableQueryInfo
**
)
taosHashGet
(
pTableGroupInfo
->
map
,
&
pBlock
->
info
.
tid
,
sizeof
(
pBlock
->
info
.
tid
));
...
...
@@ -4349,8 +4378,8 @@ static SSDataBlock* doSTableAggregate(void* param) {
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
);
TSKEY
k
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pBlock
->
info
.
window
.
ekey
+
1
:
pBlock
->
info
.
window
.
skey
-
1
;
setExecutionContext
(
pRuntimeEnv
,
pInfo
,
pOperator
->
numOfOutput
,
pQuery
->
current
->
groupIndex
,
k
);
TSKEY
k
ey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pBlock
->
info
.
window
.
ekey
+
1
:
pBlock
->
info
.
window
.
skey
-
1
;
setExecutionContext
(
pRuntimeEnv
,
pInfo
,
pOperator
->
numOfOutput
,
pQuery
->
current
->
groupIndex
,
k
ey
);
doAggregateImpl
(
pOperator
,
pQuery
->
window
.
skey
,
pInfo
->
pCtx
,
pBlock
);
}
...
...
tests/script/general/parser/testSuite.sim
浏览文件 @
2891d51a
...
...
@@ -107,3 +107,6 @@ sleep 100
run general/parser/function.sim
sleep 100
run general/parser/stableOp.sim
sleep 100
run general/parser/slimit_alter_tags.sim
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录