shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Request to add words RANK and FUNCTION as MySQL unreserved Word in mysql sql parser module

Open zhaopinglu opened this issue 6 years ago • 8 comments

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

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

SQL with column name RANK and FUNCTION can run without issue

Actual behavior

ss-proxy reports unsupported sql

Reason analyze (If you can)

The SQL contains column names like RANK and FUNCTION which were defined as reserved words in sql-parser-mysql module

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

Create a table with column name rank and function Then run sql over ss-proxy to query those columns

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

zhaopinglu avatar Sep 02 '20 08:09 zhaopinglu

Hi @zhaopinglu

  1. What if you use FUNCTION to execute SQL?
  2. Keyworkd of MySQL tell me FUNCTION (R) is reserved in 8.x

tristaZero avatar Sep 02 '20 10:09 tristaZero

Hi @tristaZero In my subquery case add '``' will report NPE.
select schema from (select * from table where id = 4) a It seems a bug cause column name not trim '``' image image

My version is the master version. Thx for investigating this

zero2hj avatar Sep 09 '20 08:09 zero2hj

@chana71 Thanks for your feedback.

  1. What your query SQL? The following one?

select schema from (select * from table where id = 4) a

  1. What if you do not use subquery? Could you give it a test?

tristaZero avatar Sep 10 '20 03:09 tristaZero

@tristaZero

  1. Complete SQL looks like this. Please check

SELECT SCHEMA_SIZE, A.CHECKTIME, A.`SCHEMA`
FROM (
SELECT SCHEMA_SIZE, CHECKTIME, `SCHEMA`
FROM MYSQL_SCHEMA_SIZE
WHERE DBID IN (1) AND `SCHEMA` IN ('test')) A
RIGHT JOIN (
SELECT MAX(CHECKTIME) CHECKTIME, `SCHEMA`
FROM MYSQL_SCHEMA_SIZE
WHERE DBID IN (1) AND `SCHEMA` IN ('test')
GROUP BY `SCHEMA`) B ON A.CHECKTIME = B.CHECKTIME AND A.`SCHEMA` = B.`SCHEMA`
  1. If not with a subquery,e.g. SELECT SCHEMA_SIZE, SCHEMA FROM SCHEMA_SIZE;, It works.

zero2hj avatar Sep 10 '20 09:09 zero2hj

@chana71 So could we conclude that the possible issue is subquery cannot support keyword of MySQL? Plus, what if there is no keyword in subquery?

@jingshanglu Could you check whether the SQL above is supported on our master branch?

tristaZero avatar Sep 11 '20 04:09 tristaZero

@chana71 So could we conclude that the possible issue is subquery cannot support keyword of MySQL? Plus, what if there is no keyword in subquery?

@jingshanglu Could you check whether the SQL above is supported on our master branch?

Statement is right, rewrite is wrong.

jingshanglu avatar Sep 12 '20 01:09 jingshanglu

@jingshanglu You mean we get the wrong rewritten SQL? Which part of the rewritten SQL is unexpected?

tristaZero avatar Sep 13 '20 02:09 tristaZero

@chana71 #7476 The pr maybe fix it, when it is merged, you can try the master branch.

jingshanglu avatar Sep 16 '20 06:09 jingshanglu