Hint

    Main application scenarios for Hint:

    • The sharding fields do not exist in the SQL and database table structure but in the external business logic.
    • Certain data operations are forced to be performed in given databases.
    1. Use HintManager.addDatabaseShardingValue, HintManager.addTableShardingValue to set the sharding key value.
    2. Execute SQL statements to complete routing and execution.
    3. Call HintManager.close to clean up the contents of ThreadLocal.

    Hint Configuration

    Hint algorithms require users to implement the interface of . Apache ShardingSphere will acquire sharding values from HintManager to route.

    Get HintManager

    Add Sharding Value

    • Use hintManager.addDatabaseShardingValue to add sharding key value of data source.
    • Use hintManager.addTableShardingValue to add sharding key value of table.

    Clean Hint Values

    Sharding values are saved in ThreadLocal, so it is necessary to use hintManager.close() to clean .

    Codes:

    Use special SQL comments

    Terms of Use

    To use SQL Hint function, users need to set sqlCommentParseEnabled to true. The comment format only supports for now. The content needs to start with SHARDINGSPHERE_HINT:, and optional attributes include:

    • {table}.SHARDING_DATABASE_VALUE: used to add the data source sharding value corresponding to {table} table, multiple attributes are separated by commas;
    • {table}.SHARDING_TABLE_VALUE: used to add the table sharding value corresponding to {table} table, multiple attributes are separated by commas.

    Users can use to set sharding value in hint route to some certain sharding database without sharding tables.

    Codes: