Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0a28d69b
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看板
提交
0a28d69b
编写于
5月 22, 2020
作者:
B
Bomin Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
create & alter table: send actual tag data only
上级
99d44db9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
38 addition
and
25 deletion
+38
-25
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+3
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+4
-2
src/client/src/tscServer.c
src/client/src/tscServer.c
+11
-5
src/inc/taosmsg.h
src/inc/taosmsg.h
+5
-2
src/mnode/src/mgmtTable.c
src/mnode/src/mgmtTable.c
+15
-15
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
0a28d69b
...
...
@@ -928,10 +928,12 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
}
// 3. calculate the actual data size of STagData
pCmd
->
payloadLen
=
sizeof
(
pTag
->
name
);
pCmd
->
payloadLen
=
sizeof
(
pTag
->
name
)
+
sizeof
(
pTag
->
dataLen
)
;
for
(
int32_t
t
=
0
;
t
<
numOfTags
;
++
t
)
{
pTag
->
dataLen
+=
pTagSchema
[
t
].
bytes
;
pCmd
->
payloadLen
+=
pTagSchema
[
t
].
bytes
;
}
pTag
->
dataLen
=
htonl
(
pTag
->
dataLen
);
if
(
tscValidateName
(
&
tableToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid table name"
,
*
sqlstr
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
0a28d69b
...
...
@@ -4416,6 +4416,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg13
);
}
pAlterSQL
->
tagData
.
dataLen
=
pTagsSchema
->
bytes
;
// validate the length of binary
if
((
pTagsSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pTagsSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
...
...
@@ -5550,11 +5551,11 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
// too long tag values will return invalid sql, not be truncated automatically
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pStableMeterMetaInfo
->
pTableMeta
);
char
*
tagVal
=
pCreateTable
->
usingInfo
.
tagdata
.
data
;
STagData
*
pTag
=
&
pCreateTable
->
usingInfo
.
tagdata
;
char
*
tagVal
=
pTag
->
data
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
for
(
int32_t
i
=
0
;
i
<
pList
->
nExpr
;
++
i
)
{
if
(
pTagSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
||
pTagSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
// validate the length of binary
if
(
pList
->
a
[
i
].
pVar
.
nLen
+
VARSTR_HEADER_SIZE
>
pTagSchema
[
i
].
bytes
)
{
...
...
@@ -5593,6 +5594,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return
ret
;
}
pTag
->
dataLen
=
tagVal
-
pTag
->
data
;
return
TSDB_CODE_SUCCESS
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
0a28d69b
...
...
@@ -1213,8 +1213,13 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int8_t
type
=
pInfo
->
pCreateTableInfo
->
type
;
if
(
type
==
TSQL_CREATE_TABLE_FROM_STABLE
)
{
// create by using super table, tags value
memcpy
(
pMsg
,
&
pInfo
->
pCreateTableInfo
->
usingInfo
.
tagdata
,
sizeof
(
STagData
));
pMsg
+=
sizeof
(
STagData
);
STagData
*
pTag
=
&
pInfo
->
pCreateTableInfo
->
usingInfo
.
tagdata
;
*
(
int32_t
*
)
pMsg
=
htonl
(
pTag
->
dataLen
);
pMsg
+=
sizeof
(
int32_t
);
memcpy
(
pMsg
,
pTag
->
name
,
sizeof
(
pTag
->
name
));
pMsg
+=
sizeof
(
pTag
->
name
);
memcpy
(
pMsg
,
pTag
->
data
,
pTag
->
dataLen
);
pMsg
+=
pTag
->
dataLen
;
}
else
{
// create (super) table
pSchema
=
(
SSchema
*
)
pCreateTableMsg
->
schema
;
...
...
@@ -1281,9 +1286,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
strcpy
(
pAlterTableMsg
->
tableId
,
pTableMetaInfo
->
name
);
pAlterTableMsg
->
type
=
htons
(
pAlterInfo
->
type
);
pAlterTableMsg
->
numOfCols
=
tscNumOfFields
(
pQueryInfo
);
memcpy
(
pAlterTableMsg
->
tagVal
,
pAlterInfo
->
tagData
.
data
,
TSDB_MAX_TAGS_LEN
);
pAlterTableMsg
->
numOfCols
=
htons
(
tscNumOfFields
(
pQueryInfo
));
SSchema
*
pSchema
=
pAlterTableMsg
->
schema
;
for
(
int
i
=
0
;
i
<
pAlterTableMsg
->
numOfCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
i
);
...
...
@@ -1295,6 +1298,9 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
pMsg
=
(
char
*
)
pSchema
;
pAlterTableMsg
->
tagValLen
=
htonl
(
pAlterInfo
->
tagData
.
dataLen
);
memcpy
(
pMsg
,
pAlterInfo
->
tagData
.
data
,
pAlterInfo
->
tagData
.
dataLen
);
pMsg
+=
pAlterInfo
->
tagData
.
dataLen
;
msgLen
=
pMsg
-
(
char
*
)
pAlterTableMsg
;
pCmd
->
payloadLen
=
msgLen
;
...
...
src/inc/taosmsg.h
浏览文件 @
0a28d69b
...
...
@@ -269,9 +269,11 @@ typedef struct {
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
char
db
[
TSDB_DB_NAME_LEN
+
1
];
int16_t
type
;
/* operation type */
char
tagVal
[
TSDB_MAX_BYTES_PER_ROW
];
int
8_t
numOfCols
;
/* number of schema */
int16_t
numOfCols
;
/* number of schema */
int
32_t
tagValLen
;
SSchema
schema
[];
// tagVal is padded after schema
// char tagVal[];
}
SCMAlterTableMsg
;
typedef
struct
{
...
...
@@ -647,6 +649,7 @@ typedef struct SMultiTableMeta {
}
SMultiTableMeta
;
typedef
struct
{
int32_t
dataLen
;
char
name
[
TSDB_TABLE_ID_LEN
+
1
];
char
data
[
TSDB_MAX_TAGS_LEN
];
}
STagData
;
...
...
src/mnode/src/mgmtTable.c
浏览文件 @
0a28d69b
...
...
@@ -1334,13 +1334,13 @@ static void mgmtProcessDropSuperTableRsp(SRpcMsg *rpcMsg) {
}
static
void
*
mgmtBuildCreateChildTableMsg
(
SCMCreateTableMsg
*
pMsg
,
SChildTableObj
*
pTable
)
{
char
*
pTagData
=
NULL
;
STagData
*
pTagData
=
NULL
;
int32_t
tagDataLen
=
0
;
int32_t
totalCols
=
0
;
int32_t
contLen
=
0
;
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
&&
pMsg
!=
NULL
)
{
pTagData
=
pMsg
->
schema
+
TSDB_TABLE_ID_LEN
+
1
;
tagDataLen
=
htonl
(
pMsg
->
contLen
)
-
sizeof
(
SCMCreateTableMsg
)
-
TSDB_TABLE_ID_LEN
-
1
;
pTagData
=
(
STagData
*
)
pMsg
->
schema
;
tagDataLen
=
ntohl
(
pTagData
->
dataLen
)
;
totalCols
=
pTable
->
superTable
->
numOfColumns
+
pTable
->
superTable
->
numOfTags
;
contLen
=
sizeof
(
SMDCreateTableMsg
)
+
totalCols
*
sizeof
(
SSchema
)
+
tagDataLen
+
pTable
->
sqlLen
;
}
else
{
...
...
@@ -1393,7 +1393,7 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb
}
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
&&
pMsg
!=
NULL
)
{
memcpy
(
pCreate
->
data
+
totalCols
*
sizeof
(
SSchema
),
pTagData
,
tagDataLen
);
memcpy
(
pCreate
->
data
+
totalCols
*
sizeof
(
SSchema
),
pTagData
->
data
,
tagDataLen
);
memcpy
(
pCreate
->
data
+
totalCols
*
sizeof
(
SSchema
)
+
tagDataLen
,
pTable
->
sql
,
pTable
->
sqlLen
);
}
...
...
@@ -1420,10 +1420,10 @@ static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj
pTable
->
vgId
=
pVgroup
->
vgId
;
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
char
*
pTagData
=
(
char
*
)
pCreate
->
schema
;
// it is a tag key
SSuperTableObj
*
pSuperTable
=
mgmtGetSuperTable
(
pTagData
);
STagData
*
pTagData
=
(
STagData
*
)
pCreate
->
schema
;
// it is a tag key
SSuperTableObj
*
pSuperTable
=
mgmtGetSuperTable
(
pTagData
->
name
);
if
(
pSuperTable
==
NULL
)
{
mError
(
"table:%s, corresponding super table:%s does not exist"
,
pCreate
->
tableId
,
pTagData
);
mError
(
"table:%s, corresponding super table:%s does not exist"
,
pCreate
->
tableId
,
pTagData
->
name
);
free
(
pTable
);
terrno
=
TSDB_CODE_INVALID_TABLE
;
return
NULL
;
...
...
@@ -1742,7 +1742,9 @@ static int32_t mgmtDoGetChildTableMeta(SQueuedMsg *pMsg, STableMetaMsg *pMeta) {
static
void
mgmtAutoCreateChildTable
(
SQueuedMsg
*
pMsg
)
{
SCMTableInfoMsg
*
pInfo
=
pMsg
->
pCont
;
int32_t
contLen
=
sizeof
(
SCMCreateTableMsg
)
+
sizeof
(
STagData
);
STagData
*
pTag
=
(
STagData
*
)
pInfo
->
tags
;
int32_t
contLen
=
sizeof
(
SCMCreateTableMsg
)
+
offsetof
(
STagData
,
data
)
+
ntohl
(
pTag
->
dataLen
);
SCMCreateTableMsg
*
pCreateMsg
=
rpcMallocCont
(
contLen
);
if
(
pCreateMsg
==
NULL
)
{
mError
(
"table:%s, failed to create table while get meta info, no enough memory"
,
pInfo
->
tableId
);
...
...
@@ -1756,14 +1758,9 @@ static void mgmtAutoCreateChildTable(SQueuedMsg *pMsg) {
pCreateMsg
->
getMeta
=
1
;
pCreateMsg
->
contLen
=
htonl
(
contLen
);
contLen
=
sizeof
(
STagData
);
if
(
contLen
>
pMsg
->
contLen
-
sizeof
(
SCMTableInfoMsg
))
{
contLen
=
pMsg
->
contLen
-
sizeof
(
SCMTableInfoMsg
);
}
memcpy
(
pCreateMsg
->
schema
,
pInfo
->
tags
,
contLen
);
memcpy
(
pCreateMsg
->
schema
,
pInfo
->
tags
,
contLen
-
sizeof
(
SCMCreateTableMsg
));
SQueuedMsg
*
newMsg
=
mgmtCloneQueuedMsg
(
pMsg
);
pMsg
->
pCont
=
newMsg
->
pCont
;
newMsg
->
msgType
=
TSDB_MSG_TYPE_CM_CREATE_TABLE
;
newMsg
->
pCont
=
pCreateMsg
;
...
...
@@ -2201,6 +2198,8 @@ static void mgmtProcessAlterTableMsg(SQueuedMsg *pMsg) {
}
pAlter
->
type
=
htons
(
pAlter
->
type
);
pAlter
->
numOfCols
=
htons
(
pAlter
->
numOfCols
);
pAlter
->
tagValLen
=
htonl
(
pAlter
->
tagValLen
);
if
(
pAlter
->
numOfCols
>
2
)
{
mError
(
"table:%s, error numOfCols:%d in alter table"
,
pAlter
->
tableId
,
pAlter
->
numOfCols
);
...
...
@@ -2232,7 +2231,8 @@ static void mgmtProcessAlterTableMsg(SQueuedMsg *pMsg) {
mTrace
(
"table:%s, start to alter ctable"
,
pAlter
->
tableId
);
SChildTableObj
*
pTable
=
(
SChildTableObj
*
)
pMsg
->
pTable
;
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
)
{
code
=
mgmtModifyChildTableTagValue
(
pTable
,
pAlter
->
schema
[
0
].
name
,
pAlter
->
tagVal
);
char
*
tagVal
=
(
char
*
)(
pAlter
->
schema
+
pAlter
->
numOfCols
);
code
=
mgmtModifyChildTableTagValue
(
pTable
,
pAlter
->
schema
[
0
].
name
,
tagVal
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_COLUMN
)
{
code
=
mgmtAddNormalTableColumn
(
pMsg
->
pDb
,
pTable
,
pAlter
->
schema
,
1
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_DROP_COLUMN
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录