Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
47125c85
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
47125c85
编写于
11月 17, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
<fix>TD-11074 fix orderby tbname & optimize order by check logic
上级
7937d054
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
23 deletion
+33
-23
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+32
-23
tests/pytest/query/querySort.py
tests/pytest/query/querySort.py
+1
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
47125c85
...
...
@@ -5771,10 +5771,17 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
* for table query, there is only one or none order option is allowed, which is the
* ts or values(top/bottom) order is supported.
*
* for super table query, the order option must be less than 3.
* for super table query, the order option must be less than 3 and the second must be ts.
*
* order by has 5 situations
* 1. from stable group by tag1 order by tag1 [ts]
* 2. from stable group by tbname order by tbname [ts]
* 3. from stable/table group by column1 order by column1
* 4. from stable/table order by ts
* 5. select stable/table top(column2,1) ... order by column2
*/
size_t
size
=
taosArrayGetSize
(
pSortOrder
);
if
(
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
)
||
UTIL_TABLE_IS_TMP
_TABLE
(
pTableMetaInfo
))
{
if
(
!
UTIL_TABLE_IS_SUPER
_TABLE
(
pTableMetaInfo
))
{
if
(
size
>
1
)
{
return
invalidOperationMsg
(
pMsgBuf
,
msg0
);
}
...
...
@@ -5784,15 +5791,14 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
}
}
if
(
size
>
0
&&
pQueryInfo
->
distinct
)
{
return
invalidOperationMsg
(
pMsgBuf
,
msg10
);
return
invalidOperationMsg
(
pMsgBuf
,
msg10
);
}
// handle the first part of order by
tVariant
*
pVar
=
taosArrayGet
(
pSortOrder
,
0
);
// e.g., order by 1 asc, return directly with out further check.
if
(
pVar
->
nType
>=
TSDB_DATA_TYPE_TINYINT
&&
pVar
->
nType
<=
TSDB_DATA_TYPE_BIGINT
)
{
return
TSDB_CODE_SUCCESS
;
if
(
pVar
->
nType
!=
TSDB_DATA_TYPE_BINARY
){
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
SStrToken
columnName
=
{
pVar
->
nLen
,
pVar
->
nType
,
pVar
->
pz
};
...
...
@@ -5801,7 +5807,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
if
(
pQueryInfo
->
pUdfInfo
&&
taosArrayGetSize
(
pQueryInfo
->
pUdfInfo
)
>
0
)
{
int32_t
usize
=
(
int32_t
)
taosArrayGetSize
(
pQueryInfo
->
pUdfInfo
);
for
(
int32_t
i
=
0
;
i
<
usize
;
++
i
)
{
SUdfInfo
*
pUdfInfo
=
taosArrayGet
(
pQueryInfo
->
pUdfInfo
,
i
);
if
(
pUdfInfo
->
funcType
==
TSDB_UDF_TYPE_SCALAR
)
{
...
...
@@ -5820,9 +5826,9 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
bool
orderByTS
=
false
;
bool
orderByGroupbyCol
=
false
;
if
(
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
{
if
(
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
{
// order by tag1
int32_t
relTagIndex
=
index
.
columnIndex
-
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
// it is a tag column
if
(
pQueryInfo
->
groupbyExpr
.
columnInfo
==
NULL
)
{
return
invalidOperationMsg
(
pMsgBuf
,
msg4
);
...
...
@@ -5831,26 +5837,29 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
if
(
relTagIndex
==
pColIndex
->
colIndex
)
{
orderByTags
=
true
;
}
}
else
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
orderByTags
=
true
;
}
if
(
PRIMARYKEY_TIMESTAMP_COL_INDEX
==
index
.
columnIndex
)
{
}
else
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
// order by tbname
// it is a tag column
if
(
pQueryInfo
->
groupbyExpr
.
columnInfo
==
NULL
)
{
return
invalidOperationMsg
(
pMsgBuf
,
msg4
);
}
SColIndex
*
pColIndex
=
taosArrayGet
(
pQueryInfo
->
groupbyExpr
.
columnInfo
,
0
);
if
(
TSDB_TBNAME_COLUMN_INDEX
==
pColIndex
->
colIndex
)
{
orderByTags
=
true
;
}
}
else
if
(
index
.
columnIndex
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
// order by ts
orderByTS
=
true
;
}
SArray
*
columnInfo
=
pQueryInfo
->
groupbyExpr
.
columnInfo
;
if
(
columnInfo
!=
NULL
&&
taosArrayGetSize
(
columnInfo
)
>
0
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
columnInfo
,
0
);
if
(
PRIMARYKEY_TIMESTAMP_COL_INDEX
!=
index
.
columnIndex
&&
pColIndex
->
colIndex
==
index
.
columnIndex
)
{
orderByGroupbyCol
=
true
;
}
else
{
// order by normal column
SArray
*
columnInfo
=
pQueryInfo
->
groupbyExpr
.
columnInfo
;
if
(
columnInfo
!=
NULL
&&
taosArrayGetSize
(
columnInfo
)
>
0
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
columnInfo
,
0
);
if
(
pColIndex
->
colIndex
==
index
.
columnIndex
)
{
orderByGroupbyCol
=
true
;
}
}
}
if
(
!
(
orderByTags
||
orderByTS
||
orderByGroupbyCol
)
&&
!
isTopBottomQuery
(
pQueryInfo
))
{
return
invalidOperationMsg
(
pMsgBuf
,
msg3
);
}
else
{
// order by top/bottom result value column is not supported in case of interval query.
assert
(
!
(
orderByTags
&&
orderByTS
&&
orderByGroupbyCol
));
}
size_t
s
=
taosArrayGetSize
(
pSortOrder
);
...
...
tests/pytest/query/querySort.py
浏览文件 @
47125c85
...
...
@@ -122,6 +122,7 @@ class TDTestCase:
(
i
,
i
))
self
.
checkColumnSorted
(
1
,
"desc"
)
tdSql
.
error
(
"select tbcol1 from st order by 123"
)
tdSql
.
error
(
"select tbcol1 from st order by tbname"
)
tdSql
.
query
(
"select avg(tbcol1) from st group by tbname order by tbname"
)
tdSql
.
checkData
(
1
,
0
,
5.5
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录