Mixed Rules

The overlay between rule items in a mixed configuration is associated by the data source name and the table name.

If the previous rule is aggregation-oriented, the next rule needs to use the aggregated logical data source name configured by the previous rule when configuring the data source. Similarly, if the previous rule is table aggregation-oriented, the next rule needs to use the aggregated logical table name configured by the previous rule when configuring the table.

Configuration Item Explanation

  1. dataSources: # Configure the real data source name.
  2. write_ds:
  3. # ...Omit specific configuration.
  4. read_ds_0:
  5. # ...Omit specific configuration.
  6. read_ds_1:
  7. # ...Omit specific configuration.
  8. rules:
  9. - !SHARDING # Configure data sharding rules.
  10. tables:
  11. t_user:
  12. actualDataNodes: ds.t_user_${0..1} # Data source name 'ds' uses the logical data source name of the readwrite-splitting configuration.
  13. tableStrategy:
  14. standard:
  15. shardingColumn: user_id
  16. shardingAlgorithmName: t_user_inline
  17. shardingAlgorithms:
  18. t_user_inline:
  19. type: INLINE
  20. props:
  21. algorithm-expression: t_user_${user_id % 2}
  22. - !ENCRYPT # Configure data encryption rules.
  23. tables:
  24. t_user: # Table `t_user` is the name of the logical table that uses the data sharding configuration.
  25. columns:
  26. pwd:
  27. plainColumn: plain_pwd
  28. cipherColumn: cipher_pwd
  29. encryptorName: encryptor_aes
  30. encryptors:
  31. encryptor_aes:
  32. type: aes
  33. props:
  34. aes-key-value: 123456abc
  35. - !READWRITE_SPLITTING # Configure readwrite-splitting rules.
  36. dataSources:
  37. ds: # The logical data source name 'ds' for readwrite-splitting is used in data sharding.
  38. writeDataSourceName: write_ds # Use the real data source name 'write_ds'.
  39. readDataSourceNames:
  40. - read_ds_0 # Use the real data source name 'read_ds_0'.
  41. - read_ds_1 # Use the real data source name 'read_ds_1'.
  42. loadBalancerName: roundRobin
  43. loadBalancers:
  44. roundRobin:
  45. type: ROUND_ROBIN
  46. props:
  47. sql-show: true