方便更快捷的说明问题,可以按需填写(可删除)
使用环境:
SpringBoot 2.7
Mybatis 3.5.10
Shardingsphere-jdbc-core-spring-boot-starter 5.2.1
场景、问题:
按年月进行分片,正常进行订单之间的绑定
e_ticket_order_main_202404 这张表也都是存在的
yarm 配置
shardingsphere: # 分布式数据库中间件
datasource:
names: master # 定义数据源的名称
master:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/e-ticket-shardingsphere?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
username: root
password: 123456
max-pool-size: 100
min-idle: 20
connection-timeout: 6000
rules:
sharding:
tables:
e_ticket_order_main:
logic-table: e_ticket_order_main
actual-data-nodes: master.e_ticket_order_main_$->{202403..202408}
table-strategy:
standard:
sharding-column: create_time
sharding-algorithm-name: date-precise-sharding-algorithm
e_ticket_order_detail:
logic-table: e_ticket_order_detail
actual-data-nodes: master.e_ticket_order_detail_$->{202403..202408}
table-strategy:
standard:
sharding-column: create_time
sharding-algorithm-name: date-precise-sharding-algorithm
sharding-algorithms:
date-precise-sharding-algorithm:
type: CLASS_BASED_COMPLEX_TABLE
props:
strategy: STANDARD
algorithmClassName: com.xxx.xxx.common.shardingsphere.algorithm.DatePreciseShardingAlgorithm
binding-tables:
- e_ticket_order_main,e_ticket_order_detail
props:
sql-show: true
已进行操作:
单表查询,没有任何问题 ,联表的情况出错
现状:
分片的组装结果
2024-06-27 22:08:22.890 INFO 53272 --- [ XNIO-1 task-2] c.a.e.c.s.a.DatePreciseShardingAlgorithm : >>>>>>>>>> 默认范围: 下限:Fri Mar 01 00:00:00 CST 2024,上限:Thu Aug 01 00:00:00 CST 2024
2024-06-27 22:08:22.890 INFO 53272 --- [ XNIO-1 task-2] c.a.e.c.s.a.DatePreciseShardingAlgorithm : >>>>>>>>>> 条件范围: 下限:2024-04-23 00:00:00.0,上限:2024-04-24 23:59:59.0
2024-06-27 22:08:22.891 INFO 53272 --- [ XNIO-1 task-2] c.a.e.c.s.a.DatePreciseShardingAlgorithm : >>>>>>>>>> 分片组装结果:[e_ticket_order_main_202404]
错误
### Cause: java.sql.SQLException: Actual table `master.e_ticket_order_main_202404` is not in table rule configuration.
; Actual table `master.e_ticket_order_main_202404` is not in table rule configuration.; nested exception is java.sql.SQLException: Actual table `master.e_ticket_order_main_202404` is not in table rule configuration.