Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
404674b5
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看板
提交
404674b5
编写于
1月 20, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/develop' into feature/os
上级
fffe8658
c20d5741
变更
14
展开全部
显示空白变更内容
内联
并排
Showing
14 changed file
with
1983 addition
and
1355 deletion
+1983
-1355
src/client/inc/tscSubquery.h
src/client/inc/tscSubquery.h
+0
-1
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+2
-1
src/client/src/tscLocalMerge.c
src/client/src/tscLocalMerge.c
+4
-0
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+18
-0
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+201
-53
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+6
-0
src/inc/ttokendef.h
src/inc/ttokendef.h
+142
-139
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+4
-2
src/query/inc/sql.y
src/query/inc/sql.y
+65
-9
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+4
-2
src/query/src/sql.c
src/query/src/sql.c
+1533
-1146
tests/script/general/http/restful_full.sim
tests/script/general/http/restful_full.sim
+1
-0
tests/script/general/parser/join.sim
tests/script/general/parser/join.sim
+2
-1
未找到文件。
src/client/inc/tscSubquery.h
浏览文件 @
404674b5
...
...
@@ -47,7 +47,6 @@ void tscLockByThread(int64_t *lockedBy);
void
tscUnlockByThread
(
int64_t
*
lockedBy
);
#ifdef __cplusplus
}
#endif
...
...
src/client/inc/tsclient.h
浏览文件 @
404674b5
...
...
@@ -317,7 +317,8 @@ typedef struct STscObj {
}
STscObj
;
typedef
struct
SSubqueryState
{
int32_t
numOfRemain
;
// the number of remain unfinished subquery
pthread_mutex_t
mutex
;
int8_t
*
states
;
int32_t
numOfSub
;
// the number of total sub-queries
uint64_t
numOfRetrievedRows
;
// total number of points in this query
}
SSubqueryState
;
...
...
src/client/src/tscLocalMerge.c
浏览文件 @
404674b5
...
...
@@ -1427,6 +1427,10 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
tscResetForNextRetrieve
(
pRes
);
if
(
pSql
->
signature
!=
pSql
||
pRes
==
NULL
||
pRes
->
pLocalReducer
==
NULL
)
{
// all data has been processed
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
)
{
return
pRes
->
code
;
}
tscError
(
"%p local merge abort due to error occurs, code:%s"
,
pSql
,
tstrerror
(
pRes
->
code
));
return
pRes
->
code
;
}
...
...
src/client/src/tscSQLParser.c
浏览文件 @
404674b5
...
...
@@ -264,6 +264,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case
TSDB_SQL_DROP_DB
:
{
const
char
*
msg2
=
"invalid name"
;
const
char
*
msg3
=
"param name too long"
;
const
char
*
msg4
=
"table is not super table"
;
SStrToken
*
pzName
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
if
((
pInfo
->
type
!=
TSDB_SQL_DROP_DNODE
)
&&
(
tscValidateName
(
pzName
)
!=
TSDB_CODE_SUCCESS
))
{
...
...
@@ -285,6 +286,18 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
(
pInfo
->
pDCLInfo
->
tableType
==
TSDB_SUPER_TABLE
)
{
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
}
}
else
if
(
pInfo
->
type
==
TSDB_SQL_DROP_DNODE
)
{
pzName
->
n
=
strdequote
(
pzName
->
z
);
strncpy
(
pTableMetaInfo
->
name
,
pzName
->
z
,
pzName
->
n
);
...
...
@@ -4794,6 +4807,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg17
=
"invalid column name"
;
const
char
*
msg18
=
"primary timestamp column cannot be dropped"
;
const
char
*
msg19
=
"invalid new tag name"
;
const
char
*
msg20
=
"table is not super table"
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -4819,6 +4833,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
pAlterSQL
->
tableType
==
TSDB_SUPER_TABLE
&&
!
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
)))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg20
);
}
if
(
pAlterSQL
->
type
==
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
||
pAlterSQL
->
type
==
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
||
pAlterSQL
->
type
==
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
)
{
if
(
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
))
{
...
...
src/client/src/tscServer.c
浏览文件 @
404674b5
...
...
@@ -2193,7 +2193,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
tscDebug
(
"%p remove table meta after drop table:%s, numOfRemain:%d"
,
pSql
,
pTableMetaInfo
->
name
,
(
int32_t
)
taosHashGetSize
(
tscTableMetaInfo
));
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
)
;
pTableMetaInfo
->
pTableMeta
=
NULL
;
return
0
;
}
...
...
src/client/src/tscSubquery.c
浏览文件 @
404674b5
...
...
@@ -55,6 +55,58 @@ static void skipRemainValue(STSBuf* pTSBuf, tVariant* tag1) {
}
}
static
void
subquerySetState
(
SSqlObj
*
pSql
,
SSubqueryState
*
subState
,
int
idx
,
int8_t
state
)
{
assert
(
idx
<
subState
->
numOfSub
);
assert
(
subState
->
states
);
pthread_mutex_lock
(
&
subState
->
mutex
);
tscDebug
(
"subquery:%p,%d state set to %d"
,
pSql
,
idx
,
state
);
subState
->
states
[
idx
]
=
state
;
pthread_mutex_unlock
(
&
subState
->
mutex
);
}
static
bool
allSubqueryDone
(
SSqlObj
*
pParentSql
)
{
bool
done
=
true
;
SSubqueryState
*
subState
=
&
pParentSql
->
subState
;
//lock in caller
for
(
int
i
=
0
;
i
<
subState
->
numOfSub
;
i
++
)
{
if
(
0
==
subState
->
states
[
i
])
{
tscDebug
(
"%p subquery:%p,%d is NOT finished, total:%d"
,
pParentSql
,
pParentSql
->
pSubs
[
i
],
i
,
subState
->
numOfSub
);
done
=
false
;
break
;
}
else
{
tscDebug
(
"%p subquery:%p,%d is finished, total:%d"
,
pParentSql
,
pParentSql
->
pSubs
[
i
],
i
,
subState
->
numOfSub
);
}
}
return
done
;
}
static
bool
subAndCheckDone
(
SSqlObj
*
pSql
,
SSqlObj
*
pParentSql
,
int
idx
)
{
SSubqueryState
*
subState
=
&
pParentSql
->
subState
;
assert
(
idx
<
subState
->
numOfSub
);
pthread_mutex_lock
(
&
subState
->
mutex
);
tscDebug
(
"%p subquery:%p,%d state set to 1"
,
pParentSql
,
pSql
,
idx
);
subState
->
states
[
idx
]
=
1
;
bool
done
=
allSubqueryDone
(
pParentSql
);
pthread_mutex_unlock
(
&
subState
->
mutex
);
return
done
;
}
static
int64_t
doTSBlockIntersect
(
SSqlObj
*
pSql
,
SJoinSupporter
*
pSupporter1
,
SJoinSupporter
*
pSupporter2
,
STimeWindow
*
win
)
{
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
);
...
...
@@ -367,10 +419,6 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
// scan all subquery, if one sub query has only ts, ignore it
tscDebug
(
"%p start to launch secondary subqueries, %d out of %d needs to query"
,
pSql
,
numOfSub
,
pSql
->
subState
.
numOfSub
);
//the subqueries that do not actually launch the secondary query to virtual node is set as completed.
SSubqueryState
*
pState
=
&
pSql
->
subState
;
pState
->
numOfRemain
=
numOfSub
;
bool
success
=
true
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
...
...
@@ -404,6 +452,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
break
;
}
tscClearSubqueryInfo
(
&
pNew
->
cmd
);
pSql
->
pSubs
[
i
]
=
pNew
;
...
...
@@ -480,6 +529,8 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
}
}
subquerySetState
(
pPrevSub
,
&
pSql
->
subState
,
i
,
0
);
size_t
numOfCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
tscDebug
(
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%"
PRIzu
", colList:%"
PRIzu
", fieldsInfo:%d, name:%s"
,
pSql
,
pNew
,
0
,
pTableMetaInfo
->
vgroupIndex
,
pQueryInfo
->
type
,
taosArrayGetSize
(
pQueryInfo
->
exprList
),
...
...
@@ -517,20 +568,25 @@ void freeJoinSubqueryObj(SSqlObj* pSql) {
SJoinSupporter
*
p
=
pSub
->
param
;
tscDestroyJoinSupporter
(
p
);
if
(
pSub
->
res
.
code
==
TSDB_CODE_SUCCESS
)
{
taos_free_result
(
pSub
);
pSql
->
pSubs
[
i
]
=
NULL
;
}
if
(
pSql
->
subState
.
states
)
{
pthread_mutex_destroy
(
&
pSql
->
subState
.
mutex
);
}
tfree
(
pSql
->
subState
.
states
);
pSql
->
subState
.
numOfSub
=
0
;
}
static
void
quitAllSubquery
(
SSqlObj
*
pSqlObj
,
SJoinSupporter
*
pSupporter
)
{
assert
(
pSqlObj
->
subState
.
numOfRemain
>
0
);
if
(
atomic_sub_fetch_32
(
&
pSqlObj
->
subState
.
numOfRemain
,
1
)
<=
0
)
{
static
void
quitAllSubquery
(
SSqlObj
*
pSqlSub
,
SSqlObj
*
pSqlObj
,
SJoinSupporter
*
pSupporter
)
{
if
(
subAndCheckDone
(
pSqlSub
,
pSqlObj
,
pSupporter
->
subqueryIndex
))
{
tscError
(
"%p all subquery return and query failed, global code:%s"
,
pSqlObj
,
tstrerror
(
pSqlObj
->
res
.
code
));
freeJoinSubqueryObj
(
pSqlObj
);
return
;
}
//tscDestroyJoinSupporter(pSupporter);
...
...
@@ -777,6 +833,15 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
assert
(
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
));
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
}
// check for the error code firstly
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
// todo retry if other subqueries are not failed
...
...
@@ -785,7 +850,7 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
tscError
(
"%p sub query failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
pParentSql
->
res
.
code
=
numOfRows
;
quitAllSubquery
(
pParentSql
,
pSupporter
);
quitAllSubquery
(
p
Sql
,
p
ParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -802,7 +867,7 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
tscError
(
"%p failed to malloc memory"
,
pSql
);
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
quitAllSubquery
(
p
Sql
,
p
ParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -844,7 +909,8 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
// no data exists in next vnode, mark the <tid, tags> query completed
// only when there is no subquery exits any more, proceeds to get the intersect of the <tid, tags> tuple sets.
if
(
atomic_sub_fetch_32
(
&
pParentSql
->
subState
.
numOfRemain
,
1
)
>
0
)
{
if
(
!
subAndCheckDone
(
pSql
,
pParentSql
,
pSupporter
->
subqueryIndex
))
{
tscDebug
(
"%p tagRetrieve:%p,%d completed, total:%d"
,
pParentSql
,
tres
,
pSupporter
->
subqueryIndex
,
pParentSql
->
subState
.
numOfSub
);
return
;
}
...
...
@@ -891,7 +957,9 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
((
SJoinSupporter
*
)
psub2
->
param
)
->
pVgroupTables
=
tscVgroupTableInfoClone
(
pTableMetaInfo2
->
pVgroupTables
);
pParentSql
->
subState
.
numOfSub
=
2
;
pParentSql
->
subState
.
numOfRemain
=
pParentSql
->
subState
.
numOfSub
;
memset
(
pParentSql
->
subState
.
states
,
0
,
sizeof
(
pParentSql
->
subState
.
states
[
0
])
*
pParentSql
->
subState
.
numOfSub
);
tscDebug
(
"%p reset all sub states to 0"
,
pParentSql
);
for
(
int32_t
m
=
0
;
m
<
pParentSql
->
subState
.
numOfSub
;
++
m
)
{
SSqlObj
*
sub
=
pParentSql
->
pSubs
[
m
];
...
...
@@ -915,6 +983,15 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
assert
(
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
));
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
}
// check for the error code firstly
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
// todo retry if other subqueries are not failed yet
...
...
@@ -922,7 +999,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
tscError
(
"%p sub query failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
pParentSql
->
res
.
code
=
numOfRows
;
quitAllSubquery
(
pParentSql
,
pSupporter
);
quitAllSubquery
(
p
Sql
,
p
ParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -937,7 +1014,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
quitAllSubquery
(
p
Sql
,
p
ParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
...
...
@@ -955,7 +1032,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
quitAllSubquery
(
p
Sql
,
p
ParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
...
...
@@ -1009,7 +1086,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
return
;
}
if
(
atomic_sub_fetch_32
(
&
pParentSql
->
subState
.
numOfRemain
,
1
)
>
0
)
{
if
(
!
subAndCheckDone
(
pSql
,
pParentSql
,
pSupporter
->
subqueryIndex
)
)
{
return
;
}
...
...
@@ -1049,6 +1126,17 @@ static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfR
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
}
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
assert
(
numOfRows
==
taos_errno
(
pSql
));
...
...
@@ -1088,9 +1176,8 @@ static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfR
}
}
assert
(
pState
->
numOfRemain
>
0
);
if
(
atomic_sub_fetch_32
(
&
pState
->
numOfRemain
,
1
)
>
0
)
{
tscDebug
(
"%p sub:%p completed, remain:%d, total:%d"
,
pParentSql
,
tres
,
pState
->
numOfRemain
,
pState
->
numOfSub
);
if
(
!
subAndCheckDone
(
pSql
,
pParentSql
,
pSupporter
->
subqueryIndex
))
{
tscDebug
(
"%p sub:%p,%d completed, total:%d"
,
pParentSql
,
tres
,
pSupporter
->
subqueryIndex
,
pState
->
numOfSub
);
return
;
}
...
...
@@ -1205,16 +1292,17 @@ void tscFetchDatablockForSubquery(SSqlObj* pSql) {
}
}
// get the number of subquery that need to retrieve the next vnode.
if
(
orderedPrjQuery
)
{
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
SSqlObj
*
pSub
=
pSql
->
pSubs
[
i
];
if
(
pSub
!=
NULL
&&
pSub
->
res
.
row
>=
pSub
->
res
.
numOfRows
&&
pSub
->
res
.
completed
)
{
pSql
->
subState
.
numOfRemain
++
;
subquerySetState
(
pSub
,
&
pSql
->
subState
,
i
,
0
)
;
}
}
}
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
SSqlObj
*
pSub
=
pSql
->
pSubs
[
i
];
if
(
pSub
==
NULL
)
{
...
...
@@ -1270,7 +1358,19 @@ void tscFetchDatablockForSubquery(SSqlObj* pSql) {
// retrieve data from current vnode.
tscDebug
(
"%p retrieve data from %d subqueries"
,
pSql
,
numOfFetch
);
SJoinSupporter
*
pSupporter
=
NULL
;
pSql
->
subState
.
numOfRemain
=
numOfFetch
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
SSqlObj
*
pSql1
=
pSql
->
pSubs
[
i
];
if
(
pSql1
==
NULL
)
{
continue
;
}
SSqlRes
*
pRes1
=
&
pSql1
->
res
;
if
(
pRes1
->
row
>=
pRes1
->
numOfRows
)
{
subquerySetState
(
pSql1
,
&
pSql
->
subState
,
i
,
0
);
}
}
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
SSqlObj
*
pSql1
=
pSql
->
pSubs
[
i
];
...
...
@@ -1372,7 +1472,8 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
// retrieve actual query results from vnode during the second stage join subquery
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
code
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -1384,7 +1485,8 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
tscError
(
"%p abort query, code:%s, global code:%s"
,
pSql
,
tstrerror
(
code
),
tstrerror
(
pParentSql
->
res
.
code
));
pParentSql
->
res
.
code
=
code
;
quitAllSubquery
(
pParentSql
,
pSupporter
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -1408,7 +1510,7 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
// In case of consequence query from other vnode, do not wait for other query response here.
if
(
!
(
pTableMetaInfo
->
vgroupIndex
>
0
&&
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
)))
{
if
(
atomic_sub_fetch_32
(
&
pParentSql
->
subState
.
numOfRemain
,
1
)
>
0
)
{
if
(
!
subAndCheckDone
(
pSql
,
pParentSql
,
pSupporter
->
subqueryIndex
)
)
{
return
;
}
}
...
...
@@ -1422,6 +1524,7 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
if
(
pTableMetaInfo
->
vgroupIndex
>
0
&&
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
))
{
pSql
->
fp
=
joinRetrieveFinalResCallback
;
// continue retrieve data
pSql
->
cmd
.
command
=
TSDB_SQL_FETCH
;
tscProcessSql
(
pSql
);
}
else
{
// first retrieve from vnode during the secondary stage sub-query
// set the command flag must be after the semaphore been correctly set.
...
...
@@ -1457,8 +1560,7 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
pSql
->
pSubs
[
pSql
->
subState
.
numOfRemain
++
]
=
pNew
;
assert
(
pSql
->
subState
.
numOfRemain
<=
pSql
->
subState
.
numOfSub
);
pSql
->
pSubs
[
tableIndex
]
=
pNew
;
if
(
QUERY_IS_JOIN_QUERY
(
pQueryInfo
->
type
))
{
addGroupInfoForSubquery
(
pSql
,
pNew
,
0
,
tableIndex
);
...
...
@@ -1590,6 +1692,19 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) {
int32_t
code
=
TSDB_CODE_SUCCESS
;
pSql
->
subState
.
numOfSub
=
pQueryInfo
->
numOfTables
;
if
(
pSql
->
subState
.
states
==
NULL
)
{
pSql
->
subState
.
states
=
calloc
(
pSql
->
subState
.
numOfSub
,
sizeof
(
*
pSql
->
subState
.
states
));
if
(
pSql
->
subState
.
states
==
NULL
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
_error
;
}
pthread_mutex_init
(
&
pSql
->
subState
.
mutex
,
NULL
);
}
memset
(
pSql
->
subState
.
states
,
0
,
sizeof
(
*
pSql
->
subState
.
states
)
*
pSql
->
subState
.
numOfSub
);
tscDebug
(
"%p reset all sub states to 0"
,
pSql
);
bool
hasEmptySub
=
false
;
tscDebug
(
"%p start subquery, total:%d"
,
pSql
,
pQueryInfo
->
numOfTables
);
...
...
@@ -1622,14 +1737,25 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) {
pSql
->
cmd
.
command
=
TSDB_SQL_RETRIEVE_EMPTY_RESULT
;
(
*
pSql
->
fp
)(
pSql
->
param
,
pSql
,
0
);
}
else
{
int
fail
=
0
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
SSqlObj
*
pSub
=
pSql
->
pSubs
[
i
];
if
(
fail
)
{
(
*
pSub
->
fp
)(
pSub
->
param
,
pSub
,
0
);
continue
;
}
if
((
code
=
tscProcessSql
(
pSub
))
!=
TSDB_CODE_SUCCESS
)
{
pSql
->
subState
.
numOfRemain
=
i
-
1
;
// the already sent request will continue and do not go to the error process routine
break
;
pRes
->
code
=
code
;
(
*
pSub
->
fp
)(
pSub
->
param
,
pSub
,
0
);
fail
=
1
;
}
}
if
(
fail
)
{
return
;
}
pSql
->
cmd
.
command
=
TSDB_SQL_TABLE_JOIN_RETRIEVE
;
}
...
...
@@ -1728,7 +1854,21 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
return
ret
;
}
pState
->
numOfRemain
=
pState
->
numOfSub
;
if
(
pState
->
states
==
NULL
)
{
pState
->
states
=
calloc
(
pState
->
numOfSub
,
sizeof
(
*
pState
->
states
));
if
(
pState
->
states
==
NULL
)
{
pRes
->
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
tscAsyncResultOnError
(
pSql
);
tfree
(
pMemoryBuf
);
return
ret
;
}
pthread_mutex_init
(
&
pState
->
mutex
,
NULL
);
}
memset
(
pState
->
states
,
0
,
sizeof
(
*
pState
->
states
)
*
pState
->
numOfSub
);
tscDebug
(
"%p reset all sub states to 0"
,
pSql
);
pRes
->
code
=
TSDB_CODE_SUCCESS
;
int32_t
i
=
0
;
...
...
@@ -1877,7 +2017,6 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
assert
(
pSql
!=
NULL
);
SSubqueryState
*
pState
=
&
pParentSql
->
subState
;
assert
(
pState
->
numOfRemain
<=
pState
->
numOfSub
&&
pState
->
numOfRemain
>=
0
);
// retrieved in subquery failed. OR query cancelled in retrieve phase.
if
(
taos_errno
(
pSql
)
==
TSDB_CODE_SUCCESS
&&
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -1908,10 +2047,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
}
}
int32_t
remain
=
-
1
;
if
((
remain
=
atomic_sub_fetch_32
(
&
pState
->
numOfRemain
,
1
))
>
0
)
{
tscDebug
(
"%p sub:%p orderOfSub:%d freed, finished subqueries:%d"
,
pParentSql
,
pSql
,
trsupport
->
subqueryIndex
,
pState
->
numOfSub
-
remain
);
if
(
!
subAndCheckDone
(
pSql
,
pParentSql
,
subqueryIndex
))
{
tscDebug
(
"%p sub:%p,%d freed, not finished, total:%d"
,
pParentSql
,
pSql
,
trsupport
->
subqueryIndex
,
pState
->
numOfSub
);
tscFreeRetrieveSup
(
pSql
);
return
;
...
...
@@ -1980,10 +2117,8 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
return
;
}
int32_t
remain
=
-
1
;
if
((
remain
=
atomic_sub_fetch_32
(
&
pParentSql
->
subState
.
numOfRemain
,
1
))
>
0
)
{
tscDebug
(
"%p sub:%p orderOfSub:%d freed, finished subqueries:%d"
,
pParentSql
,
pSql
,
trsupport
->
subqueryIndex
,
pState
->
numOfSub
-
remain
);
if
(
!
subAndCheckDone
(
pSql
,
pParentSql
,
idx
))
{
tscDebug
(
"%p sub:%p orderOfSub:%d freed, not finished"
,
pParentSql
,
pSql
,
trsupport
->
subqueryIndex
);
tscFreeRetrieveSup
(
pSql
);
return
;
...
...
@@ -2033,7 +2168,6 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
SSqlObj
*
pParentSql
=
trsupport
->
pParentSql
;
SSubqueryState
*
pState
=
&
pParentSql
->
subState
;
assert
(
pState
->
numOfRemain
<=
pState
->
numOfSub
&&
pState
->
numOfRemain
>=
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
SVgroupInfo
*
pVgroup
=
&
pTableMetaInfo
->
vgroupList
->
vgroups
[
0
];
...
...
@@ -2254,7 +2388,8 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
}
}
if
(
atomic_sub_fetch_32
(
&
pParentObj
->
subState
.
numOfRemain
,
1
)
>
0
)
{
if
(
!
subAndCheckDone
(
tres
,
pParentObj
,
pSupporter
->
index
))
{
tscDebug
(
"%p insert:%p,%d completed, total:%d"
,
pParentObj
,
tres
,
pSupporter
->
index
,
pParentObj
->
subState
.
numOfSub
);
return
;
}
...
...
@@ -2288,6 +2423,8 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
STableMetaInfo
*
pMasterTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pParentObj
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
0
);
tscAddTableMetaInfo
(
pQueryInfo
,
pMasterTableMetaInfo
->
name
,
NULL
,
NULL
,
NULL
,
NULL
);
subquerySetState
(
pSql
,
&
pParentObj
->
subState
,
i
,
0
);
tscDebug
(
"%p, failed sub:%d, %p"
,
pParentObj
,
i
,
pSql
);
}
}
...
...
@@ -2302,7 +2439,6 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
}
pParentObj
->
cmd
.
parseFinished
=
false
;
pParentObj
->
subState
.
numOfRemain
=
numOfFailed
;
tscResetSqlCmdObj
(
&
pParentObj
->
cmd
);
...
...
@@ -2378,7 +2514,19 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
// the number of already initialized subqueries
int32_t
numOfSub
=
0
;
pSql
->
subState
.
numOfRemain
=
pSql
->
subState
.
numOfSub
;
if
(
pSql
->
subState
.
states
==
NULL
)
{
pSql
->
subState
.
states
=
calloc
(
pSql
->
subState
.
numOfSub
,
sizeof
(
*
pSql
->
subState
.
states
));
if
(
pSql
->
subState
.
states
==
NULL
)
{
pRes
->
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
_error
;
}
pthread_mutex_init
(
&
pSql
->
subState
.
mutex
,
NULL
);
}
memset
(
pSql
->
subState
.
states
,
0
,
sizeof
(
*
pSql
->
subState
.
states
)
*
pSql
->
subState
.
numOfSub
);
tscDebug
(
"%p reset all sub states to 0"
,
pSql
);
pSql
->
pSubs
=
calloc
(
pSql
->
subState
.
numOfSub
,
POINTER_BYTES
);
if
(
pSql
->
pSubs
==
NULL
)
{
goto
_error
;
...
...
src/client/src/tscUtil.c
浏览文件 @
404674b5
...
...
@@ -441,6 +441,12 @@ static void tscFreeSubobj(SSqlObj* pSql) {
pSql
->
pSubs
[
i
]
=
NULL
;
}
if
(
pSql
->
subState
.
states
)
{
pthread_mutex_destroy
(
&
pSql
->
subState
.
mutex
);
}
tfree
(
pSql
->
subState
.
states
);
pSql
->
subState
.
numOfSub
=
0
;
}
...
...
src/inc/ttokendef.h
浏览文件 @
404674b5
...
...
@@ -82,151 +82,154 @@
#define TK_STABLES 64
#define TK_VGROUPS 65
#define TK_DROP 66
#define TK_
DNODE
67
#define TK_
USER
68
#define TK_
ACCOUNT
69
#define TK_
USE
70
#define TK_
DESCRIBE
71
#define TK_
ALTER
72
#define TK_
PASS
73
#define TK_P
RIVILEGE
74
#define TK_
LOCAL
75
#define TK_
IF
76
#define TK_
EXISTS
77
#define TK_
PPS
78
#define TK_
TSERIES
79
#define TK_
DBS
80
#define TK_
STORAGE
81
#define TK_
QTIME
82
#define TK_
CONNS
83
#define TK_
STATE
84
#define TK_
KEEP
85
#define TK_
CACHE
86
#define TK_
REPLICA
87
#define TK_
QUORUM
88
#define TK_
DAYS
89
#define TK_
MINROWS
90
#define TK_M
AX
ROWS 91
#define TK_
BLOCKS
92
#define TK_
CTIME
93
#define TK_
WAL
94
#define TK_
FSYNC
95
#define TK_
COMP
96
#define TK_
PRECISION
97
#define TK_
UPDATE
98
#define TK_
CACHELAST
99
#define TK_
LP
100
#define TK_
R
P 101
#define TK_
UNSIGNED
102
#define TK_
TAGS
103
#define TK_
USING
104
#define TK_
AS
105
#define TK_
COMMA
106
#define TK_
NULL
107
#define TK_
SELECT
108
#define TK_
UNION
109
#define TK_
ALL
110
#define TK_
FROM
111
#define TK_
VARIABLE
112
#define TK_
INTERVAL
113
#define TK_
FILL
114
#define TK_
SLIDING
115
#define TK_
ORDER
116
#define TK_
BY
117
#define TK_
ASC
118
#define TK_
DESC
119
#define TK_
GROUP
120
#define TK_
HAVING
121
#define TK_
LIMIT
122
#define TK_
OFFSET
123
#define TK_
SLIMI
T 124
#define TK_S
OFFSET
125
#define TK_
WHERE
126
#define TK_
NOW
127
#define TK_
RESET
128
#define TK_
QUERY
129
#define TK_
ADD
130
#define TK_
COLUMN
131
#define TK_
TAG
132
#define TK_
CHANGE
133
#define TK_
SET
134
#define TK_
KILL
135
#define TK_
CONNECTION
136
#define TK_
STREAM
137
#define TK_
COLON
138
#define TK_
ABORT
139
#define TK_A
FTER
140
#define TK_A
TTACH
141
#define TK_
BEFORE
142
#define TK_BE
GIN
143
#define TK_
CASCADE
144
#define TK_C
LUSTER
145
#define TK_C
ONFLICT
146
#define TK_CO
PY
147
#define TK_
DEFERRED
148
#define TK_DE
LIMITERS
149
#define TK_DE
TACH
150
#define TK_
EACH
151
#define TK_E
ND
152
#define TK_E
XPLAIN
153
#define TK_
FAIL
154
#define TK_F
OR
155
#define TK_
IGNORE
156
#define TK_I
MMEDIATE
157
#define TK_I
NITIALLY
158
#define TK_IN
STEAD
159
#define TK_
MATCH
160
#define TK_
KEY
161
#define TK_
OF
162
#define TK_
RAISE
163
#define TK_R
EPLACE
164
#define TK_RE
STRICT
165
#define TK_R
OW
166
#define TK_
STATEMENT
167
#define TK_
TRIGGER
168
#define TK_
VIEW
169
#define TK_
COUNT
170
#define TK_
SUM
171
#define TK_
AVG
172
#define TK_
MIN
173
#define TK_M
AX
174
#define TK_
FIRST
175
#define TK_
LAST
176
#define TK_
TOP
177
#define TK_
BOTTOM
178
#define TK_
STDDEV
179
#define TK_
PERCENTILE
180
#define TK_
APERCENTILE
181
#define TK_
LEASTSQUARES
182
#define TK_
HISTOGRAM
183
#define TK_
DIFF
184
#define TK_
SPREAD
185
#define TK_
TWA
186
#define TK_
INTERP
187
#define TK_
LAST_ROW
188
#define TK_
RATE
189
#define TK_
IRATE
190
#define TK_
SUM_RATE
191
#define TK_SUM_
IRATE
192
#define TK_
AVG_RATE
193
#define TK_AVG_
IRATE
194
#define TK_
TBID
195
#define TK_
SEMI
196
#define TK_
NONE
197
#define TK_
PREV
198
#define TK_
LINEAR
199
#define TK_
IMPORT
200
#define TK_
METRIC
201
#define TK_
TBNAME
202
#define TK_
JOIN
203
#define TK_
METRICS
204
#define TK_
STABLE
205
#define TK_
STABLE
67
#define TK_
DNODE
68
#define TK_
USER
69
#define TK_
ACCOUNT
70
#define TK_
USE
71
#define TK_
DESCRIBE
72
#define TK_
ALTER
73
#define TK_P
ASS
74
#define TK_
PRIVILEGE
75
#define TK_
LOCAL
76
#define TK_
IF
77
#define TK_
EXISTS
78
#define TK_
PPS
79
#define TK_
TSERIES
80
#define TK_
DBS
81
#define TK_
STORAGE
82
#define TK_
QTIME
83
#define TK_
CONNS
84
#define TK_
STATE
85
#define TK_
KEEP
86
#define TK_
CACHE
87
#define TK_
REPLICA
88
#define TK_
QUORUM
89
#define TK_
DAYS
90
#define TK_M
IN
ROWS 91
#define TK_
MAXROWS
92
#define TK_
BLOCKS
93
#define TK_
CTIME
94
#define TK_
WAL
95
#define TK_
FSYNC
96
#define TK_
COMP
97
#define TK_
PRECISION
98
#define TK_
UPDATE
99
#define TK_
CACHELAST
100
#define TK_
L
P 101
#define TK_
RP
102
#define TK_
UNSIGNED
103
#define TK_
TAGS
104
#define TK_
USING
105
#define TK_
AS
106
#define TK_
COMMA
107
#define TK_
NULL
108
#define TK_
SELECT
109
#define TK_
UNION
110
#define TK_
ALL
111
#define TK_
FROM
112
#define TK_
VARIABLE
113
#define TK_
INTERVAL
114
#define TK_
FILL
115
#define TK_
SLIDING
116
#define TK_
ORDER
117
#define TK_
BY
118
#define TK_
ASC
119
#define TK_
DESC
120
#define TK_
GROUP
121
#define TK_
HAVING
122
#define TK_
LIMIT
123
#define TK_
OFFSE
T 124
#define TK_S
LIMIT
125
#define TK_
SOFFSET
126
#define TK_
WHERE
127
#define TK_
NOW
128
#define TK_
RESET
129
#define TK_
QUERY
130
#define TK_
ADD
131
#define TK_
COLUMN
132
#define TK_
TAG
133
#define TK_
CHANGE
134
#define TK_
SET
135
#define TK_
KILL
136
#define TK_
CONNECTION
137
#define TK_
STREAM
138
#define TK_
COLON
139
#define TK_A
BORT
140
#define TK_A
FTER
141
#define TK_
ATTACH
142
#define TK_BE
FORE
143
#define TK_
BEGIN
144
#define TK_C
ASCADE
145
#define TK_C
LUSTER
146
#define TK_CO
NFLICT
147
#define TK_
COPY
148
#define TK_DE
FERRED
149
#define TK_DE
LIMITERS
150
#define TK_
DETACH
151
#define TK_E
ACH
152
#define TK_E
ND
153
#define TK_
EXPLAIN
154
#define TK_F
AIL
155
#define TK_
FOR
156
#define TK_I
GNORE
157
#define TK_I
MMEDIATE
158
#define TK_IN
ITIALLY
159
#define TK_
INSTEAD
160
#define TK_
MATCH
161
#define TK_
KEY
162
#define TK_
OF
163
#define TK_R
AISE
164
#define TK_RE
PLACE
165
#define TK_R
ESTRICT
166
#define TK_
ROW
167
#define TK_
STATEMENT
168
#define TK_
TRIGGER
169
#define TK_
VIEW
170
#define TK_
COUNT
171
#define TK_
SUM
172
#define TK_
AVG
173
#define TK_M
IN
174
#define TK_
MAX
175
#define TK_
FIRST
176
#define TK_
LAST
177
#define TK_
TOP
178
#define TK_
BOTTOM
179
#define TK_
STDDEV
180
#define TK_
PERCENTILE
181
#define TK_
APERCENTILE
182
#define TK_
LEASTSQUARES
183
#define TK_
HISTOGRAM
184
#define TK_
DIFF
185
#define TK_
SPREAD
186
#define TK_
TWA
187
#define TK_
INTERP
188
#define TK_
LAST_ROW
189
#define TK_
RATE
190
#define TK_
IRATE
191
#define TK_SUM_
RATE
192
#define TK_
SUM_IRATE
193
#define TK_AVG_
RATE
194
#define TK_
AVG_IRATE
195
#define TK_
TBID
196
#define TK_
SEMI
197
#define TK_
NONE
198
#define TK_
PREV
199
#define TK_
LINEAR
200
#define TK_
IMPORT
201
#define TK_
METRIC
202
#define TK_
TBNAME
203
#define TK_
JOIN
204
#define TK_
METRICS
205
#define TK_INSERT 206
#define TK_INTO 207
#define TK_VALUES 208
#define TK_SPACE 300
#define TK_COMMENT 301
#define TK_ILLEGAL 302
...
...
src/query/inc/qSqlparser.h
浏览文件 @
404674b5
...
...
@@ -98,6 +98,7 @@ typedef struct SCreateTableSQL {
typedef
struct
SAlterTableSQL
{
SStrToken
name
;
int16_t
tableType
;
int16_t
type
;
STagData
tagData
;
SArray
*
pAddColumns
;
// SArray<TAOS_FIELD>
...
...
@@ -156,6 +157,7 @@ typedef struct tDCLSQL {
int32_t
nAlloc
;
/* Number of entries allocated below */
SStrToken
*
a
;
/* one entry for element */
bool
existsCheck
;
int16_t
tableType
;
union
{
SCreateDBInfo
dbOpt
;
...
...
@@ -250,7 +252,7 @@ SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSe
void
tSqlExprNodeDestroy
(
tSQLExpr
*
pExpr
);
SAlterTableSQL
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
);
SAlterTableSQL
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableTable
);
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTagVals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
);
void
destroyAllSelectClause
(
SSubclauseInfo
*
pSql
);
...
...
@@ -267,7 +269,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
void
SqlInfoDestroy
(
SSqlInfo
*
pInfo
);
void
setDCLSQLElems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParams
,
...);
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
);
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
,
int16_t
tableType
);
void
setShowOptions
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
prefix
,
SStrToken
*
pPatterns
);
tDCLSQL
*
tTokenListAppend
(
tDCLSQL
*
pTokenList
,
SStrToken
*
pToken
);
...
...
src/query/inc/sql.y
浏览文件 @
404674b5
...
...
@@ -131,10 +131,16 @@ cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). {
//drop configure for tables
cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n;
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y);
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y
, -1
);
}
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y); }
//drop stable
cmd ::= DROP STABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n;
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, TSDB_SUPER_TABLE);
}
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, -1); }
cmd ::= DROP DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); }
cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); }
cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
...
...
@@ -305,6 +311,8 @@ signed(A) ::= MINUS INTEGER(X). { A = -strtol(X.z, NULL, 10);}
////////////////////////////////// The CREATE TABLE statement ///////////////////////////////
cmd ::= CREATE TABLE create_table_args. {}
cmd ::= CREATE TABLE create_stable_args. {}
cmd ::= CREATE STABLE create_stable_args. {}
cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;}
%type create_table_list{SCreateTableSQL*}
...
...
@@ -333,7 +341,8 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
}
// create super table
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
%type create_stable_args{SCreateTableSQL*}
create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
A = tSetCreateSqlElems(X, Y, NULL, TSQL_CREATE_STABLE);
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
...
...
@@ -683,7 +692,7 @@ cmd ::= RESET QUERY CACHE. { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
///////////////////////////////////ALTER TABLE statement//////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN
, -1
);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
@@ -693,14 +702,14 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
toTSDBType(A.type);
SArray* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN
, -1
);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
X.n += Y.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN
, -1
);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
...
...
@@ -709,7 +718,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN
, -1
);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
@@ -722,7 +731,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
, -1
);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
@@ -733,7 +742,54 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
A = tVariantListAppend(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
///////////////////////////////////ALTER STABLE statement//////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n;
toTSDBType(A.type);
SArray* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
X.n += Y.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
X.n += Z.n;
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
X.n += F.n;
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
src/query/src/qParserImpl.c
浏览文件 @
404674b5
...
...
@@ -585,11 +585,12 @@ SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagVal
return
info
;
}
SAlterTableSQL
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
)
{
SAlterTableSQL
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableType
)
{
SAlterTableSQL
*
pAlterTable
=
calloc
(
1
,
sizeof
(
SAlterTableSQL
));
pAlterTable
->
name
=
*
pTableName
;
pAlterTable
->
type
=
type
;
pAlterTable
->
tableType
=
tableType
;
if
(
type
==
TSDB_ALTER_TABLE_ADD_COLUMN
||
type
==
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
)
{
pAlterTable
->
pAddColumns
=
pCols
;
...
...
@@ -733,9 +734,10 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
va_end
(
va
);
}
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
)
{
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
,
int16_t
tableType
)
{
pInfo
->
type
=
type
;
pInfo
->
pDCLInfo
=
tTokenListAppend
(
pInfo
->
pDCLInfo
,
pToken
);
pInfo
->
pDCLInfo
->
tableType
=
tableType
;
pInfo
->
pDCLInfo
->
existsCheck
=
(
existsCheck
->
n
==
1
);
}
...
...
src/query/src/sql.c
浏览文件 @
404674b5
此差异已折叠。
点击以展开。
tests/script/general/http/restful_full.sim
浏览文件 @
404674b5
...
...
@@ -15,6 +15,7 @@ print =============== step1 - login
system_content curl 127.0.0.1:7111/rest/
print 1-> $system_content
if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then
print $system_content
return -1
endi
...
...
tests/script/general/parser/join.sim
浏览文件 @
404674b5
...
...
@@ -415,6 +415,7 @@ sql select count(join_mt0.c1), sum(join_mt1.c2), first(join_mt0.c5), last(join_m
$val = 100
if $rows != $val then
print $rows
return -1
endi
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录