shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Some SQL was executed incorrectly in 5.0.0-RC1, but executed successfully in 4.1.1

Open lwtdev opened this issue 6 years ago • 5 comments

Bug Report

Some SQL was executed incorrectly in 5.0.0-RC1, but executed successfully in 4.1.1

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
insertValueWithExpr[hasShardingKey:All];	 Support:true;	SQL: insert into customer (id, name, party_id) values (3, 'a', id + 1);
ds_01|insert into customer_0003 (id, name, party_id) values (3, 'a', id+1)|


ShardingProxy(4.1.1)2DB2Table
createTableWithOnUpdate[hasShardingKey:none];	 Support:true;	SQL: CREATE TABLE customer_email (   id bigint(20) NOT NULL COMMENT 'primary key',   `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,   `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,   PRIMARY KEY (`id`) );
ds_00|CREATE TABLE customer_email_0000 (
  id bigint(20) NOT NULL COMMENT 'primary key',
  `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
)|
ds_00|CREATE TABLE customer_email_0001 (
  id bigint(20) NOT NULL COMMENT 'primary key',
  `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
)|
ds_01|CREATE TABLE customer_email_0002 (
  id bigint(20) NOT NULL COMMENT 'primary key',
  `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
)|
ds_01|CREATE TABLE customer_email_0003 (
  id bigint(20) NOT NULL COMMENT 'primary key',
  `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
)|


ShardingProxy(4.1.1)2DB2Table
createTableWithMiddleInt[hasShardingKey:none];	 Support:true;	SQL: CREATE TABLE full_table (  id bigint(15) not null primary key comment 'prmary key',     t_mi middleint(10)  );
ds_00|CREATE TABLE full_table_0000
(
	id bigint(15) not null primary key comment 'prmary key',
    t_mi middleint(10)
 )|
ds_00|CREATE TABLE full_table_0001
(
	id bigint(15) not null primary key comment 'prmary key',
    t_mi middleint(10)
 )|
ds_01|CREATE TABLE full_table_0002
(
	id bigint(15) not null primary key comment 'prmary key',
    t_mi middleint(10)
 )|
ds_01|CREATE TABLE full_table_0003
(
	id bigint(15) not null primary key comment 'prmary key',
    t_mi middleint(10)
 )|

Actual behavior

In 5.0.0-RC1

ShardingProxy(5.0.0.RC1)2DB2Table
insertValueWithExpr[hasShardingKey:All];	 Support:false;	SQL: insert into customer (id, name, party_id) values (3, 'a', id + 1);
java.sql.SQLException: 2Unknown exception: [org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression cannot be cast to org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.ComplexExpressionSegment]

ShardingProxy(5.0.0.RC1)2DB2Table
createTableWithOnUpdate[hasShardingKey:none];	 Support:false;	SQL: CREATE TABLE customer_email (   id bigint(20) NOT NULL COMMENT 'primary key',   `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,   `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,   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',
  `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
)`'

ShardingProxy(5.0.0.RC1)2DB2Table
createTableWithMiddleInt[hasShardingKey:none];	 Support:false;	SQL: CREATE TABLE full_table (  id bigint(15) not null primary key comment 'prmary key',     t_mi middleint(10)  );
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: This version of ShardingProxy doesn't yet support this SQL. 'Unsupported SQL of `CREATE TABLE full_table
(
	id bigint(15) not null primary key comment 'prmary key',
    t_mi middleint(10)
 )`'

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:explain run these sqls:
-- @title:insertValueWithExpr,hasShardingKey:All
insert into customer (id, name, party_id) values (3, 'a', id + 1);

-- @title:createTableWithOnUpdate
CREATE TABLE customer_email (
  id bigint(20) NOT NULL COMMENT 'primary key',
  `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
);

-- @title:createTableWithMiddleInt
CREATE TABLE full_table
(
	id bigint(15) not null primary key comment 'prmary key',
    t_mi middleint(10)
 );
  • 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 avatar Sep 29 '20 11:09 lwtdev

@lwtdev It seems to be a parse error, I will investigate and fix this problem as soon as possible.

strongduanmu avatar Sep 29 '20 12:09 strongduanmu

@lwtdev Thanks to your continued feedback and testing. :) @strongduanmu Initiative!

tristaZero avatar Sep 30 '20 03:09 tristaZero

Hi @lwtdev @strongduanmu has fixed this issue with the efficiency, and welcome your verification test. Happy mooncake day, everyone!

tristaZero avatar Oct 01 '20 10:10 tristaZero

Hi @tristaZero I just ran the test and everything was executed successfully.

lwtdev avatar Oct 04 '20 07:10 lwtdev

@lwtdev So great, my QA engineer!

tristaZero avatar Oct 08 '20 04:10 tristaZero