shardingsphere
shardingsphere copied to clipboard
SQL executed incorrectly when create table has enum field
Bug Report
SQL executed incorrectly when create table has enum field
Which version of ShardingSphere did you use?
5.0.0-RC1
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy
Expected behavior
In 4.1.1
ShardingProxy(4.1.1)2DB2Table
createTableWhenEnumFieldHasCharacterSet[hasShardingKey:none]; Support:true; SQL: CREATE TABLE customer_email ( id bigint(20) NOT NULL COMMENT 'primary key', t_em enum('a', 'b') character set utf8, PRIMARY KEY (`id`) );
ds_00|CREATE TABLE customer_email_0000 (
id bigint(20) NOT NULL COMMENT 'primary key',
t_em enum('a', 'b') character set utf8,
PRIMARY KEY (`id`)
)|
ds_00|CREATE TABLE customer_email_0001 (
id bigint(20) NOT NULL COMMENT 'primary key',
t_em enum('a', 'b') character set utf8,
PRIMARY KEY (`id`)
)|
ds_01|CREATE TABLE customer_email_0002 (
id bigint(20) NOT NULL COMMENT 'primary key',
t_em enum('a', 'b') character set utf8,
PRIMARY KEY (`id`)
)|
ds_01|CREATE TABLE customer_email_0003 (
id bigint(20) NOT NULL COMMENT 'primary key',
t_em enum('a', 'b') character set utf8,
PRIMARY KEY (`id`)
)
Actual behavior
In 5.0.0-RC1
ShardingProxy(5.0.0.RC1)2DB2Table
createTableWhenEnumFieldHasCharacterSet[hasShardingKey:none]; Support:false; SQL: CREATE TABLE customer_email ( id bigint(20) NOT NULL COMMENT 'primary key', t_em enum('a', 'b') character set utf8, PRIMARY KEY (`id`) );
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: This version of ShardingProxy doesn't yet support this SQL. 'Unsupported SQL of `CREATE TABLE customer_email (
id bigint(20) NOT NULL COMMENT 'primary key',
t_em enum('a', 'b') character set utf8,
PRIMARY KEY (`id`)
)`'
Reason analyze (If you can)
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
- Test sqls
Use
sctl:explainrun these sqls:
-- @title:createTableWhenEnumFieldHasCharacterSet
CREATE TABLE customer_email (
id bigint(20) NOT NULL COMMENT 'primary key',
t_em enum('a', 'b') character set utf8,
PRIMARY KEY (`id`)
);
- Sharding config in 4.1.1
shardingRule:
tables:
customer:
actualDataNodes: ds_00.customer_000${0..1},ds_01.customer_000${2..3}
databaseStrategy:
inline:
shardingColumn: id
algorithmExpression: ds_0${(id % 4 ).intdiv(2)}
tableStrategy:
inline:
shardingColumn: id
algorithmExpression: customer_000${id % 4}
keyGenerator:
type: SNOWFLAKE
column: id
customer_email:
actualDataNodes: ds_00.customer_email_000${0..1},ds_01.customer_email_000${2..3}
databaseStrategy:
inline:
shardingColumn: id
algorithmExpression: ds_0${(id % 4 ).intdiv(2)}
tableStrategy:
inline:
shardingColumn: id
algorithmExpression: customer_email_000${id % 4}
keyGenerator:
type: SNOWFLAKE
column: id
full_table:
actualDataNodes: ds_00.full_table_000${0..1},ds_01.full_table_000${2..3}
databaseStrategy:
inline:
shardingColumn: id
algorithmExpression: ds_0${(id % 4 ).intdiv(2)}
tableStrategy:
inline:
shardingColumn: id
algorithmExpression: full_table_000${id % 4}
keyGenerator:
type: SNOWFLAKE
column: id
bindingTables:
- customer,customer_email,full_table
defaultDataSourceName: ds_00
defaultDatabaseStrategy:
none:
defaultTableStrategy:
none:
- Sharding config in 5.0.0-RC1
#
rules:
- !SHARDING
tables:
customer:
actualDataNodes: ds_00.customer_000${0..1},ds_01.customer_000${2..3}
databaseStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: database_inline
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: customer_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
customer_email:
actualDataNodes: ds_00.customer_email_000${0..1},ds_01.customer_email_000${2..3}
databaseStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: database_inline
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: customer_email_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
full_table:
actualDataNodes: ds_00.full_table_000${0..1},ds_01.full_table_000${2..3}
databaseStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: database_inline
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: full_table_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
bindingTables:
- customer,customer_email,full_table
defaultDatabaseStrategy:
none:
defaultTableStrategy:
none:
shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: ds_0${(id % 4 ).intdiv(2)}
customer_inline:
type: INLINE
props:
algorithm-expression: customer_000${id % 4}
customer_email_inline:
type: INLINE
props:
algorithm-expression: customer_email_000${id % 4}
full_table_inline:
type: INLINE
props:
algorithm-expression: full_table_000${id % 4}
Example codes for reproduce this issue (such as a github link).
@lwtdev Thank you very much for your feedback. I have tested this problem and found that it's a CHARACTER SET parsing bug. I will fix this bug.