apache / shardingsphere

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

sharding-proxy到底有没有人用?为什么这么多bug? #8051

Closed qifengzhang007 closed 4 years ago

qifengzhang007 commented 4 years ago

问题描述:两个表连接查询结果不正确!

当前软件以及版本 sharding-proxy 4.1.1

主要配置参数

shardingRule:
  tables:
    # 表名: t_order
    tb_order:
      actualDataNodes: ds_${0..1}.tb_order_${0..1}
      # table 表的行内规则
      tableStrategy:
        inline:
          #分表字段,开发者生成
          shardingColumn: order_id
          #算法, order_id 是偶数,就存入  t_order_0 表
          algorithmExpression: tb_order_${order_id % 2}
      #主键生成规则:雪花算法+该表(t_order)的主键:id   ,id 字段会自动生成
      keyGenerator:
        type: SNOWFLAKE
        column: id
    tb_order_item:
      actualDataNodes: ds_${0..1}.tb_order_item_${0..3}
      tableStrategy:
        inline:
          # t_order_item 表的数据就是t_order表的明细数据,两个表的关联键是  order_id
          shardingColumn: order_id
          algorithmExpression: tb_order_item_${order_id % 4}
      #主键生成规则:雪花算法+该表(t_order_item)的主键:id ,字段会自动生成
      keyGenerator:
        type: SNOWFLAKE
        column: id
  #设置哪些表需要分库分表
  bindingTables:
    - tb_order,tb_order_item
  #数据源配置策略  
  defaultDatabaseStrategy:
    inline:
      #一般来说,订单表中数据的产生和操作员(用户id)user_id 绑定,如果用户id时偶数,就寻找 ds_0 数据源对应的数据库
      shardingColumn: id
      algorithmExpression: ds_${id % 2}
  defaultTableStrategy:
    none:

问题复现步骤

SELECT  *  FROM  tb_order  WHERE   order_id=20201106001 ;
-- 查询结果会有1条数据
"id"    "order_id"  "order_name"    "status"    "remark"    "created_at"    "updated_at"
"531493101638778884"    "20201106001"   "双11订单测试001"    "1" "订单主表001"   "2020-11-06 15:23:50"   "2020-11-06 15:23:50"

SELECT  *  FROM  tb_order_item   WHERE   order_id=20201106001;
-- 查询结果会有2条数据
"id"    "order_id"  "item_name" "price" "num"   "total_price"   "status"    "remark"    "created_at"    "updated_at"
"531498964927643648"    "20201106001"   "小米手10" "2.00"  "4999"  "9998.00"   "1" "小米手机白色版"   "2020-11-06 15:47:08"   "2020-11-06 15:47:08"
"531499009353711617"    "20201106001"   "小米手10 至尊版" "2.00"  "4999"  "9998.00"   "1" "小米手机至尊版"   "2020-11-06 15:47:18"   "2020-11-06 15:47:18"

sql表关联查询之后,只有一条数据,而且还是字段被合并在一行了?什么奇葩问题?
SELECT  *  FROM    tb_order  a  LEFT  JOIN   tb_order_item  b  ON  a.order_id=b.order_id   WHERE   a.order_id=20201106001
#查询结果错误,被合并成了一行,而且只有一条数据!
"id"    "order_id"  "order_name"    "status"    "remark"    "created_at"    "updated_at"    "id"    "order_id"  "item_name" "price" "num"   "total_price"   "status"    "remark"    "created_at"    "updated_at"
"531493101638778884"    "20201106001"   "双11订单测试001"    "1" "订单主表001"   "2020-11-06 15:23:50"   "2020-11-06 15:23:50"   "531498964927643648"    "20201106001"   "小米手10" "2.00"  "4999"  "9998.00"   "1" "小米手机白色版"   "2020-11-06 15:47:08"   "2020-11-06 15:47:08"
terrymanu commented 4 years ago

For English only, other languages will not accept.

kimmking commented 4 years ago

@qifengzhang007 binding tables MUST BE the same sharding rule!

thicv commented 4 years ago

@qifengzhang007 根本不看规矩啊,首先必须是英文回复,这不是 shardingsphere 或者国内的规矩,这是 Apache 的规矩,其次 shardingsphere 是付费软件吗?那么多人日以继夜的新增功能改 bug,你给了一分钱,拿来就用就得拿来就喷?opensource 就得让你这么说话?最后你要是行,你就改了提 PR 啊。小屁孩你爸妈没有教你怎么跟别人说话吗,是不是缺少社会的毒打?