当前使用版本(必填,否则不予处理)
出现版本:
该问题是如何引起的?(确定最新版也有问题再提!!!)
select * from ( select id from test ) as a GROUP BY a.id 这个语句会报错
但是如果是这个语句就不会了: select * from ( select id from test ) as a GROUP BY id
后面发现这个出现在使用 这个数据库框架的时候: shardingsphere
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-namespace</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>4.1.0</version>
</dependency>
shardingsphere读写分离配置: shardingsphere: datasource: names: master,slave0 master: type: com.thit.web.config.MyDruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver #配置基本属性 url: jdbc:mysql://127.0.0.1:33016/inter_server_pro?serverTimezone=GMT%2B8&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull username: admin password: admin slave0: type: com.thit.web.config.MyDruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver #配置基本属性 url: jdbc:mysql://127.0.0.1:33016/inter_server_pro?serverTimezone=GMT%2B8&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull username: admin password: admin masterslave: name: ms master-data-source-name: master slave-data-source-names: master,slave0 props: sql: show: true
重现步骤(如果有就写完整)
报错信息
Caused by: org.apache.ibatis.executor.ExecutorException: Error preparing statement. Cause: java.lang.IllegalStateException: Can not find owner from table. at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:97) at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59) at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) at com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor.intercept(PaginationInterceptor.java:156) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy388.prepare(Unknown Source) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) at sun.reflect.GeneratedMethodAccessor141.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ... 82 common frames omitted
Comment From: chenziwucodeing
如果不使用 shardingsphere框架是不会的。但是个人认为是 mybatis-plus 问题。
Comment From: miemieYaho
你认为是mp的问题,那你应该找出到底是什么问题才对,talk is cheap show me the code
Comment From: chenziwucodeing
。。。
------------------ 原始邮件 ------------------ 发件人: "miemieYaho"<notifications@github.com>; 发送时间: 2020年6月9日(星期二) 下午3:12 收件人: "baomidou/mybatis-plus"<mybatis-plus@noreply.github.com>; 抄送: "小马过河"<359572187@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [baomidou/mybatis-plus] 出现 Can not find owner from table报错。和shardingsphere一起使用的时候。 (#2585)
你认为是mp的问题,那你应该找出到底是什么问题才对,talk is cheap show me the code
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Comment From: chenziwucodeing
我也不是没有解决方案。我就觉得你们的框架不错。给你们提的问题。报错信息给你们了。我认为你们是能重现的。
------------------ 原始邮件 ------------------ 发件人: "miemieYaho"<notifications@github.com>; 发送时间: 2020年6月9日(星期二) 下午3:12 收件人: "baomidou/mybatis-plus"<mybatis-plus@noreply.github.com>; 抄送: "小马过河"<359572187@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [baomidou/mybatis-plus] 出现 Can not find owner from table报错。和shardingsphere一起使用的时候。 (#2585)
你认为是mp的问题,那你应该找出到底是什么问题才对,talk is cheap show me the code
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Comment From: miemieYaho
那你写个demo看看
Comment From: chenziwucodeing
好吧
Comment From: AnswerNo2
同样出现了和你一样的问题
Comment From: steveNash12
我也出现同样的问题了,麻烦问下楼主是怎么解决的
Comment From: chaoge555
同问,什么原因导致的。
Comment From: visoeclipse
同问,什么原因导致的。
shardingsphere的bug,去掉shardingsphere
Comment From: liuanxin
这个看起来是的确是 shardingsphere 内部使用的 sql 解析器有问题, 异常是由org.apache.shardingsphere.sql.parser.binder.segment.select.projection.engine.ProjectionsContextEngine.java:197 find 方法中抛出的, 问题的关键在于 org.apache.shardingsphere.sql.parser.SQLParserEngine.java:57 parse 方法中对 sql 的解析是有问题的. 相关的 issue
Comment From: yunmengmeng
同样出现了一样的问题,这个应该是shardingsphere的问题,因为单独用是没有问题的
Comment From: sokeung
同上 Cause: java.lang.IllegalStateException: Can not find owner from table.
Comment From: luckey-ke
我也不是没有解决方案。我就觉得你们的框架。给你们提的问题。报错信息给你们了。我认为你们是能重现的。 … ------------------ 原始邮件 ------------------ 发件人: "miemieYaho"<notifications@github.com>; 发送时间: 2020年6月9日(星期二) 下午3:12 收件人: "baomidou/mybatis-plus"<mybatis-plus@noreply.github.com>; 抄送: "小马过河"<359572187@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [baomidou/mybatis-plus] 出现 Can not find owner from table报错。和shardingsphere一起使用的时候。 (#2585) 你认为是mp的问题,那你应该找出到底是什么问题才对,talk is cheap show me the code — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
大哥如何解决这个问题的是
Comment From: steveNash12
我也出现同样的问题了,麻烦问下楼主是怎么解决的 有网友给出了解决方案,希望对大家有帮助 https://blog.csdn.net/wcy1900353090/article/details/106442091/
Comment From: wenzhisheng
select * from ( select id from test ) as a GROUP BY id 这个查询确实不会报错,但是得到的结果集是0,navicat查询有数据的
Comment From: 18672675036
这个看起来是的确是 shardingsphere 内部使用的 sql 解析器有问题, 异常是由
org.apache.shardingsphere.sql.parser.binder.segment.select.projection.engine.ProjectionsContextEngine.java:197find 方法中抛出的, 问题的关键在于org.apache.shardingsphere.sql.parser.SQLParserEngine.java:57parse 方法中对 sql 的解析是有问题的. 相关的 issue
那如何解决呢?
Comment From: wkq361138880
同问,如何解决的
Comment From: luckey-ke
不好意思,才看到,我应该是解决的了,不过时间太久忘记了,可以描述下你是在什么情况下报的这个错误吗发自我的 iPhone在 2022年11月25日,21:16,wkq @.***> 写道: 如何解决的
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
Comment From: lushenbo321
同问解决方案是什么
Comment From: wa114d
问题还是没有解决啊
Comment From: xccer
解决了吗?
Comment From: BiuBiuBooom
// 重点是外层SQL不要出现 * ,不要使用别名,需要的字段都写清楚(内外层sql都要写清楚),才可以查出数据,不然要么是数据为空,要么是报错 Can not find owner from table.
// 正常工作 select resId,resType from ( select id as resId, type as resType from test ) res where resId > 0 GROUP BY resType
// 没有数据 select * from ( select id as resId, type as resType from test ) res where resId > 0 GROUP BY resType
// 没有数据 select * from ( select * from test )res where id > 0 GROUP BY res.type
// IllegalStateException : Can not find owner from table. select * from ( select * from test ) res where res.id > 0 GROUP BY res.type
Comment From: serendipity-pink
// 重点是外层SQL不要出现 * ,不要使用别名,需要的字段都写清楚(内外层sql都要写清楚),才可以查出数据,不然要么是数据为空,要么是报错 Can not find owner from table.
// 正常工作 select resId,resType from ( select id as resId, type as resType from test ) res where resId > 0 GROUP BY resType
// 没有数据 select * from ( select id as resId, type as resType from test ) res where resId > 0 GROUP BY resType
// 没有数据 select * from ( select * from test )res where id > 0 GROUP BY res.type
// IllegalStateException : Can not find owner from table. select * from ( select * from test ) res where res.id > 0 GROUP BY res.type
刚好遇到这个问题了,非常感谢!