Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b874090e
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看板
提交
b874090e
编写于
8月 12, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-255] cherry pick order support.
上级
7a0d2c10
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
46 deletion
+62
-46
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+48
-37
src/client/src/tscServer.c
src/client/src/tscServer.c
+3
-3
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+1
-1
src/query/src/qPlan.c
src/query/src/qPlan.c
+10
-5
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
b874090e
...
...
@@ -5482,14 +5482,19 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) {
pQueryInfo
->
order
.
order
=
TSDB_ORDER_ASC
;
if
(
isTopBottomQuery
(
pQueryInfo
))
{
pQueryInfo
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
}
else
{
// in case of select tbname from super_table, the def
ua
lt order column can not be the primary ts column
pQueryInfo
->
order
.
orderColId
=
INT32_MIN
;
}
else
{
// in case of select tbname from super_table, the def
au
lt order column can not be the primary ts column
pQueryInfo
->
order
.
orderColId
=
INT32_MIN
;
// todo define a macro
}
/* for super table query, set default ascending order for group output */
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
pQueryInfo
->
groupbyExpr
.
orderType
=
TSDB_ORDER_ASC
;
}
if
(
pQueryInfo
->
distinct
)
{
pQueryInfo
->
order
.
order
=
TSDB_ORDER_ASC
;
pQueryInfo
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
}
}
int32_t
validateOrderbyNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
,
SSchema
*
pSchema
)
{
...
...
@@ -5501,17 +5506,12 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
setDefaultOrderInfo
(
pQueryInfo
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
pQueryInfo
->
distinct
==
true
)
{
pQueryInfo
->
order
.
order
=
TSDB_ORDER_ASC
;
pQueryInfo
->
order
.
orderColId
=
0
;
return
TSDB_CODE_SUCCESS
;
}
if
(
pSqlNode
->
pSortOrder
==
NULL
)
{
if
(
pQueryInfo
->
distinct
||
pSqlNode
->
pSortOrder
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
SArray
*
pSortorder
=
pSqlNode
->
pSortOrder
;
char
*
pMsgBuf
=
tscGetErrorMsgPayload
(
pCmd
);
SArray
*
pSortOrder
=
pSqlNode
->
pSortOrder
;
/*
* for table query, there is only one or none order option is allowed, which is the
...
...
@@ -5519,19 +5519,19 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
*
* for super table query, the order option must be less than 3.
*/
size_t
size
=
taosArrayGetSize
(
pSort
o
rder
);
if
(
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
))
{
size_t
size
=
taosArrayGetSize
(
pSort
O
rder
);
if
(
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
)
||
UTIL_TABLE_IS_TMP_TABLE
(
pTableMetaInfo
)
)
{
if
(
size
>
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg0
);
return
invalidOperationMsg
(
pMsgBuf
,
msg0
);
}
}
else
{
if
(
size
>
2
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg3
);
return
invalidOperationMsg
(
pMsgBuf
,
msg3
);
}
}
// handle the first part of order by
tVariant
*
pVar
=
taosArrayGet
(
pSort
o
rder
,
0
);
tVariant
*
pVar
=
taosArrayGet
(
pSort
O
rder
,
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
)
{
...
...
@@ -5543,7 +5543,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
// super table query
if
(
getColumnIndexByName
(
&
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg1
);
return
invalidOperationMsg
(
pMsgBuf
,
msg1
);
}
bool
orderByTags
=
false
;
...
...
@@ -5555,7 +5555,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
// it is a tag column
if
(
pQueryInfo
->
groupbyExpr
.
columnInfo
==
NULL
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg2
);
return
invalidOperationMsg
(
pMsgBuf
,
msg2
);
}
SColIndex
*
pColIndex
=
taosArrayGet
(
pQueryInfo
->
groupbyExpr
.
columnInfo
,
0
);
if
(
relTagIndex
==
pColIndex
->
colIndex
)
{
...
...
@@ -5576,13 +5576,14 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
orderByGroupbyCol
=
true
;
}
}
if
(
!
(
orderByTags
||
orderByTS
||
orderByGroupbyCol
)
&&
!
isTopBottomQuery
(
pQueryInfo
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg3
);
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
(
pSort
o
rder
);
size_t
s
=
taosArrayGetSize
(
pSort
O
rder
);
if
(
s
==
1
)
{
if
(
orderByTags
)
{
pQueryInfo
->
groupbyExpr
.
orderIndex
=
index
.
columnIndex
-
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
...
...
@@ -5601,7 +5602,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
pExpr
=
tscExprGet
(
pQueryInfo
,
1
);
if
(
pExpr
->
base
.
colInfo
.
colIndex
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg2
);
return
invalidOperationMsg
(
pMsgBuf
,
msg2
);
}
tVariantListItem
*
p1
=
taosArrayGet
(
pSqlNode
->
pSortOrder
,
0
);
...
...
@@ -5619,9 +5620,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
addPrimaryTsColIntoResult
(
pQueryInfo
,
pCmd
);
}
}
}
if
(
s
==
2
)
{
}
else
{
tVariantListItem
*
pItem
=
taosArrayGet
(
pSqlNode
->
pSortOrder
,
0
);
if
(
orderByTags
)
{
pQueryInfo
->
groupbyExpr
.
orderIndex
=
index
.
columnIndex
-
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
...
...
@@ -5638,22 +5637,23 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
tVariant
*
pVar2
=
&
pItem
->
pVar
;
SStrToken
cname
=
{
pVar2
->
nLen
,
pVar2
->
nType
,
pVar2
->
pz
};
if
(
getColumnIndexByName
(
&
cname
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg1
);
return
invalidOperationMsg
(
pMsgBuf
,
msg1
);
}
if
(
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg2
);
return
invalidOperationMsg
(
pMsgBuf
,
msg2
);
}
else
{
tVariantListItem
*
p1
=
taosArrayGet
(
pSort
o
rder
,
1
);
tVariantListItem
*
p1
=
taosArrayGet
(
pSort
O
rder
,
1
);
pQueryInfo
->
order
.
order
=
p1
->
sortOrder
;
pQueryInfo
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
}
}
}
else
{
// meter query
if
(
getColumnIndexByName
(
&
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
)
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg1
);
}
else
if
(
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
)
||
UTIL_TABLE_IS_CHILD_TABLE
(
pTableMetaInfo
))
{
// check order by clause for normal table & temp table
if
(
getColumnIndexByName
(
&
columnName
,
pQueryInfo
,
&
index
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
pMsgBuf
,
msg1
);
}
if
(
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
&&
!
isTopBottomQuery
(
pQueryInfo
))
{
bool
validOrder
=
false
;
SArray
*
columnInfo
=
pQueryInfo
->
groupbyExpr
.
columnInfo
;
...
...
@@ -5661,13 +5661,14 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
SColIndex
*
pColIndex
=
taosArrayGet
(
columnInfo
,
0
);
validOrder
=
(
pColIndex
->
colIndex
==
index
.
columnIndex
);
}
if
(
!
validOrder
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg2
);
return
invalidOperationMsg
(
pMsgBuf
,
msg2
);
}
tVariantListItem
*
p1
=
taosArrayGet
(
pSqlNode
->
pSortOrder
,
0
);
pQueryInfo
->
groupbyExpr
.
orderIndex
=
pSchema
[
index
.
columnIndex
].
colId
;
pQueryInfo
->
groupbyExpr
.
orderType
=
p1
->
sortOrder
;
}
if
(
isTopBottomQuery
(
pQueryInfo
))
{
...
...
@@ -5683,13 +5684,14 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
pExpr
=
tscExprGet
(
pQueryInfo
,
1
);
if
(
pExpr
->
base
.
colInfo
.
colIndex
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg2
);
return
invalidOperationMsg
(
pMsgBuf
,
msg2
);
}
validOrder
=
true
;
}
if
(
!
validOrder
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg2
);
return
invalidOperationMsg
(
pMsgBuf
,
msg2
);
}
tVariantListItem
*
pItem
=
taosArrayGet
(
pSqlNode
->
pSortOrder
,
0
);
...
...
@@ -5699,6 +5701,18 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
return
TSDB_CODE_SUCCESS
;
}
tVariantListItem
*
pItem
=
taosArrayGet
(
pSqlNode
->
pSortOrder
,
0
);
pQueryInfo
->
order
.
order
=
pItem
->
sortOrder
;
pQueryInfo
->
order
.
orderColId
=
pSchema
[
index
.
columnIndex
].
colId
;
}
else
{
// handle the temp table order by clause. You can order by any single column in case of the temp table, created by
// inner subquery.
assert
(
UTIL_TABLE_IS_TMP_TABLE
(
pTableMetaInfo
)
&&
taosArrayGetSize
(
pSqlNode
->
pSortOrder
)
==
1
);
if
(
getColumnIndexByName
(
&
columnName
,
pQueryInfo
,
&
index
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
pMsgBuf
,
msg1
);
}
tVariantListItem
*
pItem
=
taosArrayGet
(
pSqlNode
->
pSortOrder
,
0
);
pQueryInfo
->
order
.
order
=
pItem
->
sortOrder
;
pQueryInfo
->
order
.
orderColId
=
pSchema
[
index
.
columnIndex
].
colId
;
...
...
@@ -8458,8 +8472,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
const
char
*
msg8
=
"condition missing for join query"
;
const
char
*
msg9
=
"not support 3 level select"
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
...
...
@@ -8754,8 +8767,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
pQueryInfo
->
simpleAgg
=
isSimpleAggregateRv
(
pQueryInfo
);
pQueryInfo
->
onlyTagQuery
=
onlyTagPrjFunction
(
pQueryInfo
);
pQueryInfo
->
groupbyColumn
=
tscGroupbyColumn
(
pQueryInfo
);
//pQueryInfo->globalMerge = tscIsTwoStageSTableQuery(pQueryInfo, 0);
pQueryInfo
->
arithmeticOnAgg
=
tsIsArithmeticQueryOnAggResult
(
pQueryInfo
);
pQueryInfo
->
orderProjectQuery
=
tscOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
);
...
...
src/client/src/tscServer.c
浏览文件 @
b874090e
...
...
@@ -880,16 +880,16 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfo
(
pCmd
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
SQueryAttr
query
=
{{
0
}};
tscCreateQueryFromQueryInfo
(
pQueryInfo
,
&
query
,
pSql
);
query
.
vgId
=
pTableMeta
->
vgId
;
SArray
*
tableScanOperator
=
createTableScanPlan
(
&
query
);
SArray
*
queryOperator
=
createExecOperatorPlan
(
&
query
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
SQueryTableMsg
*
pQueryMsg
=
(
SQueryTableMsg
*
)
pCmd
->
payload
;
tstrncpy
(
pQueryMsg
->
version
,
version
,
tListLen
(
pQueryMsg
->
version
));
...
...
src/query/inc/qExecutor.h
浏览文件 @
b874090e
...
...
@@ -417,7 +417,6 @@ typedef struct STableScanInfo {
int32_t
*
rowCellInfoOffset
;
SExprInfo
*
pExpr
;
SSDataBlock
block
;
bool
loadExternalRows
;
// load external rows (prev & next rows)
int32_t
numOfOutput
;
int64_t
elapsedTime
;
...
...
@@ -570,6 +569,7 @@ SOperatorInfo* createFilterOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
int32_t
numOfOutput
,
SColumnInfo
*
pCols
,
int32_t
numOfFilter
);
SOperatorInfo
*
createJoinOperatorInfo
(
SOperatorInfo
**
pUpstream
,
int32_t
numOfUpstream
,
SSchema
*
pSchema
,
int32_t
numOfOutput
);
SOperatorInfo
*
createOrderOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SSDataBlock
*
doGlobalAggregate
(
void
*
param
,
bool
*
newgroup
);
SSDataBlock
*
doMultiwayMergeSort
(
void
*
param
,
bool
*
newgroup
);
...
...
src/query/src/qPlan.c
浏览文件 @
b874090e
...
...
@@ -557,10 +557,9 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
int32_t
op
=
0
;
if
(
onlyQueryTags
(
pQueryAttr
))
{
// do nothing for tags query
if
(
onlyQueryTags
(
pQueryAttr
))
{
op
=
OP_TagScan
;
taosArrayPush
(
plan
,
&
op
);
}
op
=
OP_TagScan
;
taosArrayPush
(
plan
,
&
op
);
if
(
pQueryAttr
->
distinct
)
{
op
=
OP_Distinct
;
taosArrayPush
(
plan
,
&
op
);
...
...
@@ -651,8 +650,14 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
taosArrayPush
(
plan
,
&
op
);
}
}
// outer query order by support
int32_t
orderColId
=
pQueryAttr
->
order
.
orderColId
;
if
(
pQueryAttr
->
vgId
==
0
&&
orderColId
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
&&
orderColId
!=
INT32_MIN
)
{
op
=
OP_Order
;
taosArrayPush
(
plan
,
&
op
);
}
}
if
(
pQueryAttr
->
limit
.
limit
>
0
||
pQueryAttr
->
limit
.
offset
>
0
)
{
op
=
OP_Limit
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录