Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL:针对无路由配置表的查询,经路由后,表名被替换为小写,未保留原SQL规范 #576

Closed
neo37927 opened this issue Jan 24, 2018 · 9 comments

Comments

@neo37927
Copy link

neo37927 commented Jan 24, 2018

Please answer these questions before submitting your issue. Thanks!

Which version of Sharding-Jdbc do you using?

2.0.2

Expected behavior

保留原始SQL中的表名的规范

Actual behavior

表名被转成了小写

Steps to reproduce the behavior

数据库为:mysql
数据库设置项中,并没有设置lower_case_table_names=1
即数据库表名区分大小写

Please provide the reproduce example codes (such as github link)

link:https://github.com/neo37927/sharding-jdbc-example.git
branch:reproduce-example-codes
说明:
1.首先,我在git code中,抓取了T_ORDER、T_ORDER_ITEM 的建删表SQL,并手动执行。注释掉demo中的相关建删表代码。(即//orderRepository.createIfNotExistsTable()等)
2.修改xml中表名为大写
3.运行Demo会将会看到报错

异常:[ERROR] 2018-01-24 16:24:24,818 --ShardingJDBC-2-- [com.google.common.util.concurrent.Futures$CombinedFuture] input future failed.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'platform_honor.t_order_1' doesn't exist
其中platform_honor 为我本地库名

@neo37927 neo37927 changed the title 原始SQL表名规范为:表名大写,没有配置TableRule,表名被重写为小写 原始SQL表名规范为:表名大写,SQL解析后表名被重写为小写 Jan 24, 2018
@neo37927
Copy link
Author

neo37927 commented Jan 24, 2018

DDL语句手动执行的原因:若通过程序自动执行,表名同样会被转为小写,无法再现本问题

@neo37927
Copy link
Author

neo37927 commented Jan 24, 2018

代码:
SQLRewriteEngine.class
private void appendTableToken(final SQLBuilder sqlBuilder, final TableToken tableToken, final int count, final List<SQLToken> sqlTokens) { sqlBuilder.appendTable(tableToken.getTableName().toLowerCase()); int beginPosition = tableToken.getBeginPosition() + tableToken.getOriginalLiterals().length(); appendRest(sqlBuilder, count, sqlTokens, beginPosition); }

sqlBuilder.appendTable(tableToken.getTableName().toLowerCase());
转为小写

@neo37927
Copy link
Author

#529
查阅了下,相关代码,应是由于修改此BUG时提交

@hwck
Copy link

hwck commented Jan 25, 2018

@neo37927 现在dev 分支应该是可以的吧,我没试过,我现在是用2.0.0版本暂时没有表名大小写的问题

@neo37927
Copy link
Author

@hwck 您在维护么?
可以看下这个再现demo
link:https://github.com/neo37927/sharding-jdbc-example.git
branch:reproduce-example-codes

@terrymanu
Copy link
Member

应该是之前改的一个issue并没有完全想清楚,这个bug下一版本会修复

@terrymanu
Copy link
Member

经过排查,这是使用方的问题。
上面的@neo37927 同学提出的代码和此issue没有关系。代码中的转为小写是供logic table判断使用,是让logic无论是大写还是小写,都能匹配到sharding rule。
关于此问题,由于使用方配置acutalDataNode使用的是小写,因此改写完的真实表名称为小写。如果将acutalDataNode配置为大写,那么改写完的真实表名称自然为大写。

@neo37927
Copy link
Author

neo37927 commented Mar 5, 2018

@terrymanu 本来想着,来找找新版本,却发现日志被取消了。。。做了简要说明,麻烦有时间确认下。

说明:
表名重写有两种可能

  1. 存在配置的表
  2. 缺省配置的表
    针对第一类,通过配置确实可以调整,这个我之前也是知道的,但对于项目来说并不是所有的表均需要添加分表的逻辑,那么处理第二类时,我验证过,存在表名被转为小写的情况

复现

linkhttps://github.com/neo37927/sharding-jdbc-example.git
branch:reproduce-example-codes
取消了对T_ORDER的路由配置。

部分报错日志

1.Insert--------------
[INFO ] 2018-03-05 11:36:00,710 --main-- [Sharding-JDBC-SQL] Logic SQL:
INSERT INTO T_ORDER (
user_id, status
)
VALUES (
?,
?
)
/省略部分/
[INFO ] 2018-03-05 11:36:00,713 --main-- [Sharding-JDBC-SQL] Actual SQL: ds_0 :::
INSERT INTO t_order (
user_id, status
)
VALUES (
?,
?
) ::: [51, INSERT_TEST]

@neo37927 neo37927 changed the title 原始SQL表名规范为:表名大写,SQL解析后表名被重写为小写 SQL:针对无路由配置表的查询,经路由后,表名被替换为小写,未保留原SQL规范 Mar 6, 2018
@terrymanu terrymanu reopened this Mar 6, 2018
@terrymanu
Copy link
Member

We should make clear with rule here.
If use default data source or use database sharding only, the actual data nodes can absent, the default value is all real data sources + low case real table names.
It is a problem if data base is case sensitive, the solution is configure the actual data nodes for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants