V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
panjier0409
V2EX  ›  程序员

Java Sharding-JDBC 数据库分库分表问题

  •  
  •   panjier0409 · 2022-07-06 21:49:24 +08:00 · 1270 次点击
    这是一个创建于 652 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题,实际业务上关联的表的查询比较复杂,又不像 demo 一样 2 个绑定表( t_order, t_order_item )这样查询,sql 也没有那么理想化, 比如嵌套 SQL 例如

    select * from no_route_table where file1 in (select filed1 from route_table where route_key =1)
    
    

    这样的查询route_table并不会被解析并且重写,实际业务如何到底使用,还是说我的使用操作是有问题的

    3 条回复    2022-07-07 14:08:34 +08:00
    zhenjiachen
        1
    zhenjiachen  
       2022-07-06 22:35:07 +08:00 via iPhone
    做两次查询?第一次查询 route table 把结果放在内存,然后第二次去 in 查询 no route table
    chihiro2014
        2
    chihiro2014  
       2022-07-06 23:11:35 +08:00
    在代码中制定路由规则?
    shaohan0228
        3
    shaohan0228  
       2022-07-07 14:08:34 +08:00
    把查询 SQL 的逻辑写到代码中

    我看实验性支持里面好像添加子查询支持了 可以看看 https://shardingsphere.apache.org/document/current/cn/features/sharding/use-norms/sql/#%E5%AE%9E%E9%AA%8C%E6%80%A7%E6%94%AF%E6%8C%81
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1083 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:58 · PVG 02:58 · LAX 11:58 · JFK 14:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.