shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

execute 'insert into select', shardingsphere insert the same record into each sub-tables.

Open congzhou2603 opened this issue 3 years ago • 0 comments

Bug Report

Table 'cmdb_user' is configured with three databases, and each database is configured with three sub-tables.

When I execute insert into cmdb_user (user_id, id1, id2 )values(2,1,1);, it insert one records correctly.

When I execute insert into cmdb_user (user_id, id1, id2 )values(2,1,1);, it insert a records into each of the sub-tables of three databases, insert 9 records totally.

Which version of ShardingSphere did you use?

tag:5.2.0, commitid:8dee990098fd2cb000079ce1a933c530e8d0a704

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

ShardingSphere-Proxy

Expected behavior

executeinsert into cmdb_user insert into cmdb_user (user_id, id1, id2 ) select 3, 3, 3; can insert one record based databaseStrategy and tableStrategy, which is similar to insert into cmdb_user (user_id, id1, id2 )values(2,1,1);.

Actual behavior

It insert the same record into each table, insert 9 records totally.

Reason analyze (If you can)

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

image-20220921155619430 image-20220921153808493

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

rules:
  - !AUTHORITY
    users:
      - root@%:root
      - sharding@:sharding
    provider:
      type: ALL_PRIVILEGES_PERMITTED
  - !TRANSACTION
    defaultType: XA
    providerType: Atomikos
props:
  max-connections-size-per-query: 1
  executor-size: 16  # Infinite by default.
  sql-show: true
  proxy-frontend-flush-threshold: 128  # The default value is 128.
  proxy.transaction.type: XA
databaseName: sharding_db
dataSources:
  ds_0:
    url: jdbc:opengauss://XXX:XXX/tpccdb?serverTimezone=UTC&useSSL=false&connectTimeout=10&batchMode=on&loggerLevel=OFF
    username: XXX
    password: Huawei@123
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
  ds_1:
    url: jdbc:opengauss://XXX:XXX/tpccdb?serverTimezone=UTC&useSSL=false&connectTimeout=10&batchMode=on&loggerLevel=OFF
    username: XXX
    password: Huawei@123
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
  ds_2:
    url: jdbc:opengauss://XXX:XXX/tpccdb?serverTimezone=UTC&useSSL=false&connectTimeout=10&batchMode=on&loggerLevel=OFF
    username: XXX
    password: Huawei@123
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50

rules:
  - !SHARDING
    tables:
      cmdb_user:
        actualDataNodes: ds_${0..2}.cmdb_user_${0..2}
        databaseStrategy:
          standard:
            shardingAlgorithmName: ds_user_alg
            shardingColumn: user_id
        tableStrategy:
          standard:
            shardingAlgorithmName: ts_user_alg
            shardingColumn: user_id
      t_order:
        actualDataNodes: ds_${0..1}.t_order_${0..1}
        tableStrategy:
          standard:
            shardingColumn: order_id
            shardingAlgorithmName: t-order-inline
        keyGenerateStrategy:
          column: order_id
          keyGeneratorName: snowflake
      t_order_item:
        actualDataNodes: ds_${0..1}.t_order_item_${0..1}
        tableStrategy:
          standard:
            shardingColumn: order_id
            shardingAlgorithmName: t_order-item-inline
        keyGenerateStrategy:
          column: order_item_id
          keyGeneratorName: snowflake
      t_account:
        actualDataNodes: ds_${0..1}.t_account_${0..1}
        tableStrategy:
          standard:
            shardingAlgorithmName: t-account-inline
        keyGenerateStrategy:
          column: account_id
          keyGeneratorName: snowflake
    defaultShardingColumn: account_id
    bindingTables:
      - t_order,t_order_item
      - cmdb_user
    broadcastTables:
      - t_address
    defaultDatabaseStrategy:
      standard:
        shardingColumn: user_id
        shardingAlgorithmName: database-inline
    defaultTableStrategy:
      none:

    shardingAlgorithms:
      ds_user_alg:
        props:
          algorithm-expression: ds_${user_id % 3}
        type: INLINE
      ts_user_alg:
        props:
          algorithm-expression: cmdb_user_${user_id % 3}
        type: INLINE
      database-inline:
        type: INLINE
        props:
          algorithm-expression: ds_${user_id % 2}
      t-order-inline:
        type: INLINE
        props:
          algorithm-expression: t_order_${order_id % 2}
      t_order-item-inline:
        type: INLINE
        props:
          algorithm-expression: t_order_item_${order_id % 2}
      t-account-inline:
        type: INLINE
        props:
          algorithm-expression: t_account_${account_id % 2}
    keyGenerators:
      snowflake:
        type: SNOWFLAKE

congzhou2603 avatar Sep 21 '22 07:09 congzhou2603