apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.79k stars 6.7k forks source link

select x.* with join with error:No such column; nested exception is java.sql.SQLException: No such column #24584

Closed irwinai closed 2 months ago

irwinai commented 1 year ago

Bug Report

Which version of ShardingSphere did you use?

5.1.1

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

ShardingSphere-JDBC

Expected behavior

query success

Actual behavior

query with exception

Reason analyze (If you can)

I dont know

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

make query like this select xx.* with join

  select t.*
        from t_order t
        join (select * from t_order) t2 on t.user_id=t2.user_id

then you can get the query with exception

Caused by: java.sql.SQLException: No such column
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getSqlException(ExceptionMapper.java:277)
    at org.mariadb.jdbc.MariaDbResultSetMetaData.getColumnInformation(MariaDbResultSetMetaData.java:389)
    at org.mariadb.jdbc.MariaDbResultSetMetaData.getColumnLabel(MariaDbResultSetMetaData.java:186)
    at org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetMetaData.getColumnLabel(ShardingSphereResultSetMetaData.java:106)
    at org.apache.ibatis.executor.resultset.ResultSetWrapper.<init>(ResultSetWrapper.java:60)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getFirstResultSet(DefaultResultSetHandler.java:251)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:188)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
    at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:108)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
    at com.sun.proxy.$Proxy243.query(Unknown Source)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
    ... 38 more

The table in the query condition of this question has nothing to do with whether it is divided into tables. This problem exists regardless of whether it is a single table or a divided table. The core of the main problem is that as long as a subquery is joined, and then x.* is included in the select condition, an error will be reported.

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

 select t.*
        from t_order t
        join (select * from t_order) t2 on t.user_id=t2.user_id
strongduanmu commented 1 year ago

Hi @irwinai, can you provide your configuration?

irwinai commented 1 year ago

Hi @irwinai, can you provide your configuration?

what configuration??

irwinai commented 1 year ago

Hi @irwinai, can you provide your configuration?

updated

terrymanu commented 2 months ago

The SQL parser is improved in each version, please test the latest version.