You can route statements to elastic compute nodes (ECNs) by adding SQL hints to workload classes.
Using Hints With Workload Classes
To avoid the need to modify SQL queries you can apply hints for routing and asynchronous replication as workload class properties and map queries to the class. The workload class then applies the hint when the query is executed.
Note
You can only create the workload class once the ECN has been provisioned. Also, to avoid the situation where a workload class is routing queries to an ECN that has been deprovisoned, you should remove the routing location from the workload class before deprovisioning the ECN. The correct sequence of actions is:
Provisioning: provision ECN – adapt workload class (add existing routing location hint).
Deprovisioning: adapt workload class (remove routing location) – deprovision ECN.
Setting a Hint as a Property of a Workload Class
Two workload class properties are available to add routing hints to workload classes. Use either or both of these properties as necessary to apply a routing hint and avoid the need to modify SQL statements – the hint is applied to all statements executed by this class. Hints can be removed from the class by using UNSET.
The ROUTING LOCATION HINT property can be set to the value of a table placement location (as defined in the monitoring view M_TABLE_PLACEMENT_LOCATIONS). This has the same effect as applying the ROUTE_TO hint on the SQL command line. The following example routes queries mapped to this class to the group of tables 'ecn_group1'.
Use the RESULT LAG HINT property with the value 'HANA_ATR' to route queries to an asynchronous replica. This has the same effect as applying the RESULT LAG ('hana_atr') hint on the SQL command line:
1CREATE WORKLOAD CLASS "MyWLC" SET 'ROUTING LOCATION HINT' = 'ecn_group1', 'RESULT LAG HINT' = 'HANA_ATR';
A configuration parameter is available that you can use to control routing in the event that the ECN cannot be reached for some reason. Automatic rerouting back to the coordinator is prevented by default by the force_reroute parameter in the distribution section of the global.ini file. The parameter is set to TRUE by default, which applies the routing defined in the ROUTING LOCATION HINT property, and in the case of failure simply returns an error message rather than routing back to the coordinator (see Options for Handling Rerouting in the previous topic).
Mapping Options
You can map queries to this workload class in a number of ways (see topic 'Properties for Workload Class Mappings' for full details).
This first example is based on a named user (ECN_USER) so that the workload class settings of MyWLC are applied to all queries submitted by this user:
1CREATE WORKLOAD MAPPING "MyWLCMapping1" WORKLOAD CLASS "MyWLC" SET 'USER NAME' = 'ECN_USER';
In this example, a session variable is used so that the workload class settings of MyWLC are applied to all queries with an application component name (session variable value) of 'My_APP':
1CREATE WORKLOAD MAPPING "MyWLCMapping2" WORKLOAD CLASS "MyWLC" SET 'APPLICATION COMPONENT NAME' = 'My_APP';
Location-Specific Workload Class Limits
You may need to apply different workload class limits to the ECN other than the limits that apply to the coordinator. This is possible using the SET AT LOCATION syntax. The following example applies a statement thread limit at three different targets. The first limit applies generally; the other limits apply to named locations:
1234CREATE WORKLOAD CLASS MyChildWc PARENT MyParentWc
SET 'STATEMENT THREAD LIMIT' = '11'
SET AT LOCATION 'coordinator' 'STATEMENT THREAD LIMIT' = '22'
SET AT LOCATION 'ECN_4' 'STATEMENT THREAD LIMIT' = '44';
Verification of Workload Classes
Refer to the system views WORKLOAD_CLASSES andWORKLOAD_MAPPINGS for details of the properties of workload classes.
The monitoring view M_PREPARED_STATEMENTS includes the WORKLOAD_CLASS_NAME of the workload class that was applied to the execution of a statement.
The monitoring view M_WORKLOAD shows workload values over time expressed as rates where data is collected every minute.
Verification of Routing
The query execution plan EXPLAIN_PLAN_TABLE System View has schema and table name.
Execution information in the monitoring view M_SQL_PLAN_CACHE is helpful to verify the details of the data being read by each statement string. This view shows statement compile and execution information such as accessed table names, execution count, execution count by routing, execution location, and so on.
Column | Description |
---|---|
ACCESSED_TABLE_NAMES, ACCESSED_OBJECTS, ACCESSED_OBJECT_NAMES | You can use the information in these columns to see which tables were accessed by a statement either source or replica tables |
EXECUTION_COUNT | Indicates the accumulated number of times the plan was executed. |
EXECUTION_COUNT_BY_ROUTING | Shows how many times the statement is executed in the routed connection. |
TABLE_LOCATIONS | Displays locations for both original and replicated tables including host, port, database ID, and volume ID. |
Summary
You can route SQL statements to ECNs by applying SQL hints through workload classes, avoiding direct SQL query modifications. Add hints as workload class properties, which apply when queries are executed. Ensure workload classes are removed from ECNs before deprovisioning to avoid routing issues. Verify workload classes and routing through system views like `WORKLOAD_CLASSES`, `WORKLOAD_MAPPINGS`, `M_PREPARED_STATEMENTS`, `M_WORKLOAD`, `EXPLAIN_PLAN_TABLE`, and `M_SQL_PLAN_CACHE`.
Related Information
For more information about routing workload to ECNs, see: