Logo
Hint

Hint #

DBPlusEngine supports using Hint to influence the routing of the intermediate layer, in order to achieve the flexible usage of DBPlusEngine.

DBPlusEngine’s Hint is different from the native database’s Hint feature and can be regarded as a unique way of using DBPlusEngine.

Recommendation #

  1. At the time when the sharding field does not exist in the SQL and database table structure but exists in the external business logic, Hint can be used to force routing.
  2. In scenarios where there are certain business requirements that need operations to be performed only on the primary database, Hint can be used to ensure strong data consistency.

Example #

  • Example of using read/write splitting Hint:

users can set the primary database routing flag by calling HintManager.setWriteRouteOnly(), or using SQL Hint to achieve forced primary database routing in read/write splitting scenarios.

SQL Hint requires the user to enable parsing comments in advance by setting sqlCommentParseEnabled to true. The comment format currently only supports /* */, and the content needs to start with ShardingSphere hint: and the attribute name is WRITE_ROUTE_ONLY.

/* SHARDINGSPHERE_HINT: WRITE_ROUTE_ONLY=true */
SELECT * FROM t_order;

Then execute the SQL statement to achieve forced primary database routing.