shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

When the table is not sharding , in 5.0.0, SQL parsing is wrong, but it is correct before

Open lwtdev opened this issue 6 years ago • 7 comments

Bug Report

I have tested some SQL between older and newest version , and found some SQL parsing errors but work wells before.

Which version of ShardingSphere did you use?

  • Older version 5.0.0-RC1 ( 2020-10-26T16 master)

  • Newest version 5.0.0-RC1 ( 2020-10-30T15 master)

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

Expected behavior

parse correct

Actual behavior

parse error

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

  • Results in 5.0.0.RC1-older and 5.0.0.RC1-newest
ShardingProxy(5.0.0.RC1-older)No Sharding
deleteMultiTable[hasShardingKey:none];	 Support:true;	SQL: delete customer, customer_email from customer , customer_email where customer.status = 3;
ds_00|delete customer, customer_email from customer , customer_email where customer.status = 3|


ShardingProxy(5.0.0.RC1-newest)No Sharding
deleteMultiTable[hasShardingKey:none];	 Support:false;	SQL: delete customer, customer_email from customer , customer_email where customer.status = 3;
java.sql.SQLException: 2Unknown exception: [null]


ShardingProxy(5.0.0.RC1-older)No Sharding
selectIntoVarAfterFrom[hasShardingKey:none];	 Support:true;	SQL: select * from customer into @myvar;
ds_00|select * from customer into @myvar|

ShardingProxy(5.0.0.RC1-newest)No Sharding
selectIntoVarAfterFrom[hasShardingKey:none];	 Support:false;	SQL: select * from customer into @myvar;
java.sql.SQLException: 2Unknown exception: [org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue cannot be cast to org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement]

  • 5.0.0-RC1 config
schemaName: spsqltest_nosharding
#
dataSourceCommon:
  username: root
  password: root135
  connectionTimeoutMilliseconds: 30000
  idleTimeoutMilliseconds: 60000
  maxLifetimeMilliseconds: 1800000
  maxPoolSize: 50
  minPoolSize: 1
  maintenanceIntervalMilliseconds: 30000
#
dataSources:
  ds_00:
    url: jdbc:mysql://127.0.0.1:3306/spsqltest_nosharding?serverTimezone=UTC&useSSL=false

#
rules:
- !SHARDING
  defaultDatabaseStrategy:
    none:
  defaultTableStrategy:
    none:
  • SQL for creating tables create before shardingsphere start
-- @title:createTableCustomer
CREATE TABLE `customer` (
  `id` bigint(20) NOT NULL COMMENT 'primary key',
  `party_id` bigint(20) NOT NULL COMMENT 'user id',
   `status` smallint(6) DEFAULT NULL COMMENT 'status 1 enable 0 disable',
  PRIMARY KEY (`id`),
  KEY `party_id_index` (`party_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='customer';

-- @title:createTableCustomerEmail
CREATE TABLE customer_email (
  `id` bigint(20) NOT NULL COMMENT 'primary key',
  `party_id` bigint(20) NOT NULL COMMENT 'user id',
   `status` smallint(6) DEFAULT NULL COMMENT 'status 1 enable 0 disable',
  PRIMARY KEY (`id`),
  KEY `party_id_index` (`party_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='customer email';
  • SQL for testing
-- @title:deleteMultiTable,hasShardingKey:none
delete customer, customer_email from customer , customer_email where customer.status = 3;

-- @title:selectIntoVarAfterFrom,hasShardingKey:none
select * from customer into @myvar;

Example codes for reproduce this issue (such as a github link).

lwtdev avatar Oct 30 '20 08:10 lwtdev

SQL for testing

-- @title:deleteMultiTable,hasShardingKey:none
delete customer, customer_email from customer , customer_email where customer.status = 3;

-- @title:selectIntoVarAfterFrom,hasShardingKey:none
select * from customer into @myvar;

Thanks a lot @lwtdev . These cases are marked as UNSupported in docs.

There is no plan for these case. Can you make a pr for it?

kimmking avatar Oct 30 '20 09:10 kimmking

@kimmking In fact, these sql also works well in 4.11

ShardingProxy(4.1.1)No Sharding
deleteMultiTable[hasShardingKey:none];	 Support:true;	SQL: delete customer, customer_email from customer , customer_email where customer.status = 3;
ds_0|delete customer, customer_email from customer , customer_email where customer.status = 3|

ShardingProxy(4.1.1)No Sharding
selectIntoVarAfterFrom[hasShardingKey:all];	 Support:true;	SQL: select * from customer where id = 3 into @myvar;
ds_0|select * from customer where id = 3 into @myvar|

There is no plan for these case. Can you make a pr for it?

Maybe we can fix it at beta version ~

lwtdev avatar Oct 30 '20 10:10 lwtdev

@kimmking In fact, these sql also works well in 4.11

ShardingProxy(4.1.1)No Sharding
deleteMultiTable[hasShardingKey:none];	 Support:true;	SQL: delete customer, customer_email from customer , customer_email where customer.status = 3;
ds_0|delete customer, customer_email from customer , customer_email where customer.status = 3|

ShardingProxy(4.1.1)No Sharding
selectIntoVarAfterFrom[hasShardingKey:all];	 Support:true;	SQL: select * from customer where id = 3 into @myvar;
ds_0|select * from customer where id = 3 into @myvar|

There is no plan for these case. Can you make a pr for it?

Maybe we can fix it at beta version ~

@lwtdev , have you pushed a pull request to fix this bug?

SteNicholas avatar Nov 02 '20 02:11 SteNicholas

@SteNicholas no. I will try to fix it these days~

lwtdev avatar Nov 02 '20 02:11 lwtdev

@SteNicholas Hi, I just pushed the pull request.

lwtdev avatar Nov 08 '20 12:11 lwtdev

@lwtdev your code now is standing on your repo, not pr to this repo.

kimmking avatar Nov 13 '20 10:11 kimmking

@kimmking OK, I will repush it to master branch.

lwtdev avatar Nov 13 '20 11:11 lwtdev