apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
19.96k stars 6.74k forks source link

ERROR 1054 (42S22): Unknown column 't_order.order_id' in 'field list' #5857

Closed mty2015 closed 4 years ago

mty2015 commented 4 years ago

Which version of ShardingSphere did you use? 4.1.0

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

Steps to reproduce the behavior

when executing the follow sql:

SELECT `t_order`.`user_id`, `t_order`.`order_id`, `t_order`.`name` FROM `t_order` ORDER BY `t_order`.`order_id` ASC  ;

the follow error is raised:

ERROR 1054 (42S22): Unknown column 't_order.order_id' in 'field list'

the actual sql is wrong:

SELECT `t_order_0`.`user_id`, `t_order_0`.`order_id`, `t_order_0`.`name` , `t_order`.`order_id` AS ORDER_BY_DERIVED_0 FROM `t_order_0` ORDER BY `t_order_0`.`order_id` ASC
yu199195 commented 4 years ago

please.show you sharding config, and you use db is mysql ,pgsql?

mty2015 commented 4 years ago

default configuration of the official release without any changes, and mysql

mty2015 commented 4 years ago

meanwhile, I found that shardingsphere is not good compatible with the sql style with schema prefix, for example:

DELETE FROM t_order WHERE order_id IN (1);

is ok, but

DELETE FROM `t_order` WHERE `t_order`.`order_id` IN (1);

is not work with the follow error:

org.apache.shardingsphere.underlying.common.exception.ShardingSphereException: Cannot support Multiple-Table for 'org.apache.shardingsphere.sql.parser.sql.statement.dml.DeleteStatement@3293c2dc'.
    at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route(ShardingStandardRoutingEngine.java:72)
    at org.apache.shardingsphere.sharding.route.engine.ShardingRouteDecorator.decorate(ShardingRouteDecorator.java:69)
    at org.apache.shardingsphere.sharding.route.engine.ShardingRouteDecorator.decorate(ShardingRouteDecorator.java:53)
    at org.apache.shardingsphere.underlying.route.DataNodeRouter.executeRoute(DataNodeRouter.java:91)
    at org.apache.shardingsphere.underlying.route.DataNodeRouter.route(DataNodeRouter.java:76)
    at org.apache.shardingsphere.underlying.pluggble.prepare.SimpleQueryPrepareEngine.route(SimpleQueryPrepareEngine.java:54)
    at org.apache.shardingsphere.underlying.pluggble.prepare.BasePrepareEngine.executeRoute(BasePrepareEngine.java:96)
    at org.apache.shardingsphere.underlying.pluggble.prepare.BasePrepareEngine.prepare(BasePrepareEngine.java:83)
    at org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.wrapper.StatementExecutorWrapper.doShardingRoute(StatementExecutorWrapper.java:80)
    at org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.wrapper.StatementExecutorWrapper.route(StatementExecutorWrapper.java:63)
    at org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:74)
    at org.apache.shardingsphere.shardingproxy.backend.text.query.QueryBackendHandler.execute(QueryBackendHandler.java:52)
    at org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:73)
    at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:93)
    at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:71)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
yu199195 commented 4 years ago

ok,we'll keep track of it and fix it in the near future, you can use unprefixed ones for the time being.

mty2015 commented 4 years ago

very unfortunately I use orm framework to access db, I can't completely control the style of sql. :(

yu199195 commented 4 years ago

very unfortunately I use orm framework to access db, I can't completely control the style of sql

you can use shrding-jdbc. sharding-proxy, I'm not sure I support that now.

mty2015 commented 4 years ago

the project is not based java.

kimmking commented 4 years ago

I reproduce it now. And will fix it in 4.1.1.

mty2015 commented 4 years ago

Great, thank you

kimmking commented 4 years ago

The root of this issue is derived projection is an expression projection, and expression will be generated as a string before rewriting, then it keep the original style to be a part of rewrited actual SQL.

Cases as we know:

we will try to fix case 1&2

kimmking commented 4 years ago

@hongfuli As an alternative choice, we suggest:

mty2015 commented 4 years ago

thanks for your suggestion. But I use the orm framework based python, the generated SQL is not under my control

kimmking commented 4 years ago

After make a deep investigation, it need to make more time to fix it, so we will pending it for the latest release version, and move to version 5.0.0.

mty2015 commented 4 years ago

ok, thanks

kimmking commented 4 years ago

@jingshanglu will track it.

jingshanglu commented 4 years ago

I'll track it.