Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
ae9eecf1
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
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看板
未验证
提交
ae9eecf1
编写于
7月 14, 2021
作者:
H
Haojun Liao
提交者:
GitHub
7月 14, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6849 from taosdata/feature/query
[td-5153]<fix>: fix the tbname query bug in outer query.
上级
6dc159f8
d95f27ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
23 deletion
+51
-23
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+48
-20
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+3
-3
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
ae9eecf1
...
@@ -96,7 +96,7 @@ static int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrTo
...
@@ -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
parseSlidingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SStrToken
*
pSliding
);
static
int32_t
validateStateWindowNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
,
bool
isStable
);
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
validateWhereNode
(
SQueryInfo
*
pQueryInfo
,
tSqlExpr
**
pExpr
,
SSqlObj
*
pSql
);
static
int32_t
validateFillNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
);
static
int32_t
validateFillNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
);
...
@@ -1809,8 +1809,8 @@ static bool hasNoneUserDefineExpr(SQueryInfo* pQueryInfo) {
...
@@ -1809,8 +1809,8 @@ static bool hasNoneUserDefineExpr(SQueryInfo* pQueryInfo) {
return
false
;
return
false
;
}
}
int32_t
validateSelectNodeList
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelNodeList
,
bool
isSTable
,
bool
joinQuery
,
int32_t
validateSelectNodeList
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelNodeList
,
bool
joinQuery
,
bool
timeWindowQuery
)
{
bool
timeWindowQuery
,
bool
outerQuery
)
{
assert
(
pSelNodeList
!=
NULL
&&
pCmd
!=
NULL
);
assert
(
pSelNodeList
!=
NULL
&&
pCmd
!=
NULL
);
const
char
*
msg1
=
"too many items in selection clause"
;
const
char
*
msg1
=
"too many items in selection clause"
;
...
@@ -1852,7 +1852,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
...
@@ -1852,7 +1852,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
}
else
if
(
type
==
SQL_NODE_TABLE_COLUMN
||
type
==
SQL_NODE_VALUE
)
{
}
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
// 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
// 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
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
else
if
(
type
==
SQL_NODE_EXPR
)
{
}
else
if
(
type
==
SQL_NODE_EXPR
)
{
...
@@ -1988,14 +1988,15 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
...
@@ -1988,14 +1988,15 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
return
numOfTotalColumns
;
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
*
msg1
=
"tag for normal table query is not allowed"
;
const
char
*
msg2
=
"invalid column name"
;
const
char
*
msg2
=
"invalid column name"
;
const
char
*
msg3
=
"tbname not allowed in outer query"
;
int32_t
startPos
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
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
);
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_PROJECTION_QUERY
);
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
...
@@ -2019,7 +2020,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
...
@@ -2019,7 +2020,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
if
(
pTableMeta
->
tableType
!=
TSDB_TEMP_TABLE
)
{
if
(
pTableMeta
->
tableType
!=
TSDB_TEMP_TABLE
)
{
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pTableMeta
->
id
.
uid
);
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
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
// user-specified constant value as a new result column
// user-specified constant value as a new result column
...
@@ -2027,13 +2028,13 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
...
@@ -2027,13 +2028,13 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
index
.
tableIndex
=
0
;
index
.
tableIndex
=
0
;
SSchema
colSchema
=
tGetUserSpecifiedColumnSchema
(
&
pItem
->
pNode
->
value
,
&
pItem
->
pNode
->
exprToken
,
pItem
->
aliasName
);
SSchema
colSchema
=
tGetUserSpecifiedColumnSchema
(
&
pItem
->
pNode
->
value
,
&
pItem
->
pNode
->
exprToken
,
pItem
->
aliasName
);
SExprInfo
*
pExpr
=
SExprInfo
*
pExpr
=
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_UDC
,
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_UDC
,
getNewResColId
(
pCmd
));
getNewResColId
(
pCmd
));
// NOTE: the first parameter is reserved for the tag column id during join query process.
// NOTE: the first parameter is reserved for the tag column id during join query process.
pExpr
->
base
.
numOfParams
=
2
;
pExpr
->
base
.
numOfParams
=
2
;
tVariantAssign
(
&
pExpr
->
base
.
param
[
1
],
&
pItem
->
pNode
->
value
);
tVariantAssign
(
&
pExpr
->
base
.
param
[
1
],
&
pItem
->
pNode
->
value
);
}
else
if
(
optr
==
TK_ID
)
{
}
else
if
(
tokenId
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -2041,12 +2042,40 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
...
@@ -2041,12 +2042,40 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
}
}
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
SSchema
colSchema
=
*
tGetTbnameColumnSchema
();
if
(
outerQuery
)
{
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
getColumnName
(
pItem
,
name
,
colSchema
.
name
,
sizeof
(
colSchema
.
name
)
-
1
);
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
);
SSchema
colSchema
=
pSchema
[
index
.
columnIndex
];
/*SExprInfo* pExpr = */
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_TAGPRJ
,
&
index
,
&
colSchema
,
TSDB_COL_TAG
,
getNewResColId
(
pCmd
));
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
{
}
else
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
...
@@ -7156,8 +7185,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
...
@@ -7156,8 +7185,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return
code
;
return
code
;
}
}
bool
isSTable
=
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
);
if
(
validateSelectNodeList
(
&
pSql
->
cmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
false
,
false
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateSelectNodeList
(
&
pSql
->
cmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
isSTable
,
false
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
...
@@ -7945,7 +7973,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
...
@@ -7945,7 +7973,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
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
)
{
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
...
@@ -8085,7 +8113,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
...
@@ -8085,7 +8113,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
int32_t
timeWindowQuery
=
int32_t
timeWindowQuery
=
(
TPARSER_HAS_TOKEN
(
pSqlNode
->
interval
.
interval
)
||
TPARSER_HAS_TOKEN
(
pSqlNode
->
sessionVal
.
gap
));
(
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
)
{
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
...
...
src/client/src/tscSubquery.c
浏览文件 @
ae9eecf1
...
@@ -2542,7 +2542,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
...
@@ -2542,7 +2542,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
SSqlObj
*
pSub
=
pSql
->
pSubs
[
j
];
SSqlObj
*
pSub
=
pSql
->
pSubs
[
j
];
SRetrieveSupport
*
pSupport
=
pSub
->
param
;
SRetrieveSupport
*
pSupport
=
pSub
->
param
;
tscDebug
(
"0x%"
PRIx64
" sub:
%p launch subquery, orderOfSub:%d."
,
pSql
->
self
,
pSub
,
pSupport
->
subqueryIndex
);
tscDebug
(
"0x%"
PRIx64
" sub:
0x%"
PRIx64
" launch subquery, orderOfSub:%d."
,
pSql
->
self
,
pSub
->
self
,
pSupport
->
subqueryIndex
);
tscBuildAndSendRequest
(
pSub
,
NULL
);
tscBuildAndSendRequest
(
pSub
,
NULL
);
}
}
...
@@ -2861,8 +2861,8 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
...
@@ -2861,8 +2861,8 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
assert
(
pRes
->
numOfRows
==
numOfRows
);
assert
(
pRes
->
numOfRows
==
numOfRows
);
int64_t
num
=
atomic_add_fetch_64
(
&
pState
->
numOfRetrievedRows
,
numOfRows
);
int64_t
num
=
atomic_add_fetch_64
(
&
pState
->
numOfRetrievedRows
,
numOfRows
);
tscDebug
(
"0x%"
PRIx64
" sub:
%p
retrieve numOfRows:%d totalNumOfRows:%"
PRIu64
" from ep:%s, orderOfSub:%d"
,
tscDebug
(
"0x%"
PRIx64
" sub:
0x%"
PRIx64
"
retrieve numOfRows:%d totalNumOfRows:%"
PRIu64
" from ep:%s, orderOfSub:%d"
,
pParentSql
->
self
,
pSql
,
pRes
->
numOfRows
,
pState
->
numOfRetrievedRows
,
pSql
->
epSet
.
fqdn
[
pSql
->
epSet
.
inUse
],
idx
);
pParentSql
->
self
,
pSql
->
self
,
pRes
->
numOfRows
,
pState
->
numOfRetrievedRows
,
pSql
->
epSet
.
fqdn
[
pSql
->
epSet
.
inUse
],
idx
);
if
(
num
>
tsMaxNumOfOrderedResults
&&
tscIsProjectionQueryOnSTable
(
pQueryInfo
,
0
)
&&
!
(
tscGetQueryInfo
(
&
pParentSql
->
cmd
)
->
distinctTag
))
{
if
(
num
>
tsMaxNumOfOrderedResults
&&
tscIsProjectionQueryOnSTable
(
pQueryInfo
,
0
)
&&
!
(
tscGetQueryInfo
(
&
pParentSql
->
cmd
)
->
distinctTag
))
{
tscError
(
"0x%"
PRIx64
" sub:0x%"
PRIx64
" num of OrderedRes is too many, max allowed:%"
PRId32
" , current:%"
PRId64
,
tscError
(
"0x%"
PRIx64
" sub:0x%"
PRIx64
" num of OrderedRes is too many, max allowed:%"
PRId32
" , current:%"
PRId64
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录