Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f28c1a60
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看板
提交
f28c1a60
编写于
7月 13, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-5176]<enhance>: improve the twa query performance in case of interval query.
上级
99016d14
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
20 deletion
+48
-20
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+48
-20
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
f28c1a60
...
...
@@ -96,7 +96,7 @@ static int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrTo
static
int32_t
parseSlidingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SStrToken
*
pSliding
);
static
int32_t
validateStateWindowNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
,
bool
isStable
);
static
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExprItem
*
pItem
);
static
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExprItem
*
pItem
,
bool
outerQuery
);
static
int32_t
validateWhereNode
(
SQueryInfo
*
pQueryInfo
,
tSqlExpr
**
pExpr
,
SSqlObj
*
pSql
);
static
int32_t
validateFillNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
);
...
...
@@ -1809,8 +1809,8 @@ static bool hasNoneUserDefineExpr(SQueryInfo* pQueryInfo) {
return
false
;
}
int32_t
validateSelectNodeList
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelNodeList
,
bool
isSTable
,
bool
joinQuery
,
bool
timeWindowQuery
)
{
int32_t
validateSelectNodeList
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelNodeList
,
bool
joinQuery
,
bool
timeWindowQuery
,
bool
outerQuery
)
{
assert
(
pSelNodeList
!=
NULL
&&
pCmd
!=
NULL
);
const
char
*
msg1
=
"too many items in selection clause"
;
...
...
@@ -1852,7 +1852,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
}
else
if
(
type
==
SQL_NODE_TABLE_COLUMN
||
type
==
SQL_NODE_VALUE
)
{
// use the dynamic array list to decide if the function is valid or not
// select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2
if
(
addProjectionExprAndResultField
(
pCmd
,
pQueryInfo
,
pItem
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
addProjectionExprAndResultField
(
pCmd
,
pQueryInfo
,
pItem
,
outerQuery
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
else
if
(
type
==
SQL_NODE_EXPR
)
{
...
...
@@ -1988,14 +1988,15 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
return
numOfTotalColumns
;
}
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExprItem
*
pItem
)
{
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExprItem
*
pItem
,
bool
outerQuery
)
{
const
char
*
msg1
=
"tag for normal table query is not allowed"
;
const
char
*
msg2
=
"invalid column name"
;
const
char
*
msg3
=
"tbname not allowed in outer query"
;
int32_t
startPos
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
int32_t
optr
=
pItem
->
pNode
->
tokenId
;
int32_t
tokenId
=
pItem
->
pNode
->
tokenId
;
if
(
optr
==
TK_ALL
)
{
// project on all fields
if
(
tokenId
==
TK_ALL
)
{
// project on all fields
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_PROJECTION_QUERY
);
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
...
...
@@ -2019,7 +2020,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
if
(
pTableMeta
->
tableType
!=
TSDB_TEMP_TABLE
)
{
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pTableMeta
->
id
.
uid
);
}
}
else
if
(
optr
==
TK_STRING
||
optr
==
TK_INTEGER
||
optr
==
TK_FLOAT
)
{
// simple column projection query
}
else
if
(
tokenId
==
TK_STRING
||
tokenId
==
TK_INTEGER
||
tokenId
==
TK_FLOAT
)
{
// simple column projection query
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
// user-specified constant value as a new result column
...
...
@@ -2027,13 +2028,13 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
index
.
tableIndex
=
0
;
SSchema
colSchema
=
tGetUserSpecifiedColumnSchema
(
&
pItem
->
pNode
->
value
,
&
pItem
->
pNode
->
exprToken
,
pItem
->
aliasName
);
SExprInfo
*
pExpr
=
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_UDC
,
getNewResColId
(
pCmd
));
SExprInfo
*
pExpr
=
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_UDC
,
getNewResColId
(
pCmd
));
// NOTE: the first parameter is reserved for the tag column id during join query process.
pExpr
->
base
.
numOfParams
=
2
;
tVariantAssign
(
&
pExpr
->
base
.
param
[
1
],
&
pItem
->
pNode
->
value
);
}
else
if
(
optr
==
TK_ID
)
{
}
else
if
(
tokenId
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -2041,12 +2042,40 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
}
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
SSchema
colSchema
=
*
tGetTbnameColumnSchema
();
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
getColumnName
(
pItem
,
name
,
colSchema
.
name
,
sizeof
(
colSchema
.
name
)
-
1
);
if
(
outerQuery
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
bool
existed
=
false
;
SSchema
*
pSchema
=
pTableMetaInfo
->
pTableMeta
->
schema
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
if
(
strncasecmp
(
pSchema
[
i
].
name
,
TSQL_TBNAME_L
,
tListLen
(
pSchema
[
i
].
name
))
==
0
)
{
existed
=
true
;
index
.
columnIndex
=
i
;
break
;
}
}
if
(
!
existed
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
tstrncpy
(
colSchema
.
name
,
name
,
TSDB_COL_NAME_LEN
);
/*SExprInfo* pExpr = */
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_TAGPRJ
,
&
index
,
&
colSchema
,
TSDB_COL_TAG
,
getNewResColId
(
pCmd
));
SSchema
colSchema
=
pSchema
[
index
.
columnIndex
];
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
getColumnName
(
pItem
,
name
,
colSchema
.
name
,
sizeof
(
colSchema
.
name
)
-
1
);
tstrncpy
(
colSchema
.
name
,
name
,
TSDB_COL_NAME_LEN
);
/*SExprInfo* pExpr = */
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_NORMAL
,
getNewResColId
(
pCmd
));
}
else
{
SSchema
colSchema
=
*
tGetTbnameColumnSchema
();
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
getColumnName
(
pItem
,
name
,
colSchema
.
name
,
sizeof
(
colSchema
.
name
)
-
1
);
tstrncpy
(
colSchema
.
name
,
name
,
TSDB_COL_NAME_LEN
);
/*SExprInfo* pExpr = */
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_TAGPRJ
,
&
index
,
&
colSchema
,
TSDB_COL_TAG
,
getNewResColId
(
pCmd
));
}
}
else
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
...
...
@@ -7156,8 +7185,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return
code
;
}
bool
isSTable
=
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
);
if
(
validateSelectNodeList
(
&
pSql
->
cmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
isSTable
,
false
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateSelectNodeList
(
&
pSql
->
cmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
false
,
false
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -7945,7 +7973,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
validateSelectNodeList
(
pCmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
false
,
false
,
timeWindowQuery
)
!=
if
(
validateSelectNodeList
(
pCmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
false
,
timeWindowQuery
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -8085,7 +8113,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
int32_t
timeWindowQuery
=
(
TPARSER_HAS_TOKEN
(
pSqlNode
->
interval
.
interval
)
||
TPARSER_HAS_TOKEN
(
pSqlNode
->
sessionVal
.
gap
));
if
(
validateSelectNodeList
(
pCmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
isSTable
,
joinQuery
,
timeWindowQuery
)
!=
if
(
validateSelectNodeList
(
pCmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
joinQuery
,
timeWindowQuery
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录