MySQL8.0のヒント句が便利になっていたので基本動作確認。
バッチ処理前にSETコマンドで動的に設定していたセッション変数を実行するクエリーにヒントとして追加する事が出来るようです。

WL#681: Hint to temporarily set session variable for current statement
https://dev.mysql.com/worklog/task/?id=681

Syntax of the SET_VAR hint is:


 /*+ SET_VAR( = ) */

大量のデータをOrder by, Group by等でソート処理していて、Sort_merge_passesが多発している場合にソートバッファーの不足をヒント句で回避してディスクI/Oの発生を抑える事が出来る。
大量データのソートが多いバッチ処理などに組み込んでおくと、処理が早く終わらせる事が出来る。
(例)


mysql> SELECT /*+ SET_VAR(sort_buffer_size = 4M) */ name FROM city ORDER BY name;


実際にデータを準備してsort_buffer_sizeヒント句を検証した結果
Duration: 12.71 sec → 6.45 sec
sort_merge_passes: 216 → 0


mysql> select count(*) from ( select v.name, count(*) from t_group g join tbnode n on g.groupid = n.groupid join t_virual v on n.nodeid = v.nodeid group by v.name with rollup) t;
+----------+
| count(*) |
+----------+
|     1001 |
+----------+
1 row in set (12.71 sec)

mysql> select * from sys.statement_analysis limit 1\G
*************************** 1. row ***************************
            query: SELECT COUNT ( * ) FROM ( SELE ... v` . `name` WITH ROLLUP ) `t` 
               db: PERF
        full_scan: *
       exec_count: 1
        err_count: 0
       warn_count: 0
    total_latency: 12.71 s
      max_latency: 12.71 s
      avg_latency: 12.71 s
     lock_latency: 1.47 ms
        rows_sent: 1
    rows_sent_avg: 1
    rows_examined: 3102001
rows_examined_avg: 3102001
    rows_affected: 0
rows_affected_avg: 0
       tmp_tables: 2
  tmp_disk_tables: 0
      rows_sorted: 1000000
sort_merge_passes: 216
           digest: 1e941ce49e8f810963a8468995dc2eaf
       first_seen: 2017-09-28 20:29:46.768069
        last_seen: 2017-09-28 20:29:46.768069
1 row in set (0.01 sec)

mysql> 


mysql> CALL sys.ps_truncate_all_tables(FALSE);
+---------------------+
| summary             |
+---------------------+
| Truncated 49 tables |
+---------------------+
1 row in set (0.17 sec)

Query OK, 0 rows affected (0.18 sec)

mysql> select  /*+ SET_VAR(sort_buffer_size = 16M) */ count(*) from (select v.name, count(*) from t_group g join tbnode n on g.groupid = n.groupid join t_virual v on n.nodeid = v.nodeid  group by v.name with rollup) t;
+----------+
| count(*) |
+----------+
|     1001 |
+----------+
1 row in set (6.45 sec)

mysql> select * from sys.statement_analysis limit 1\G
*************************** 1. row ***************************
            query: SELECT /*+ SET_VAR ( `sort_buf ... v` . `name` WITH ROLLUP ) `t` 
               db: PERF
        full_scan: *
       exec_count: 1
        err_count: 0
       warn_count: 0
    total_latency: 9.94 s
      max_latency: 9.94 s
      avg_latency: 9.94 s
     lock_latency: 406.00 us
        rows_sent: 1
    rows_sent_avg: 1
    rows_examined: 3102001
rows_examined_avg: 3102001
    rows_affected: 0
rows_affected_avg: 0
       tmp_tables: 2
  tmp_disk_tables: 0
      rows_sorted: 1000000
sort_merge_passes: 0
           digest: bdf5d04f4574930fef467d6c359c49bf
       first_seen: 2017-09-28 20:37:42.923895
        last_seen: 2017-09-28 20:37:42.923895
1 row in set (0.01 sec)

使いどころが難しいが、以下のようにauto_increment_increment等の値もヒント句で変更出来るようです。


mysql> CREATE TABLE `T_SET_VAR` (
    ->   `id` int(10) NOT NULL AUTO_INCREMENT,
    ->   `memo` varchar(100) DEFAULT NULL,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.18 sec)

mysql> insert into T_SET_VAR(memo) values('auto_increment_increment test');
Query OK, 1 row affected (0.08 sec)

mysql> insert into T_SET_VAR(memo) values('auto_increment_increment test2');
Query OK, 1 row affected (0.03 sec)

mysql> select * from T_SET_VAR;                                                                                                  
+----+--------------------------------+
| id | memo                           |
+----+--------------------------------+
|  1 | auto_increment_increment test  |
|  2 | auto_increment_increment test2 |
+----+--------------------------------+
2 rows in set (0.00 sec)

mysql> select * from T_SET_VAR;                                             
+----+--------------------------------+
| id | memo                           |
+----+--------------------------------+
|  1 | auto_increment_increment test  |
|  2 | auto_increment_increment test2 |
+----+--------------------------------+
2 rows in set (0.00 sec)

mysql> insert /*+ SET_VAR(auto_increment_increment = 10) */ into T_SET_VAR(memo) values('auto_increment_increment test3?');
Query OK, 1 row affected (0.03 sec)

mysql> select * from T_SET_VAR;                                                                                            
+----+---------------------------------+
| id | memo                            |
+----+---------------------------------+
|  1 | auto_increment_increment test   |
|  2 | auto_increment_increment test2  |
| 11 | auto_increment_increment test3? |
+----+---------------------------------+
3 rows in set (0.00 sec)

その他、Worklogによると以下のように、色々なセッション変数をSETコマンドを利用しないでヒント句で指定出来るようです。

List of settable variables:
———————————————————————————-
auto_increment_increment
auto_increment_offset
big_tables
bulk_insert_buffer_size
default_tmp_storage_engine
div_precision_increment
end_markers_in_json
eq_range_index_dive_limit
foreign_key_checks
group_concat_max_len
insert_id
internal_tmp_mem_storage_engine
join_buffer_size
lock_wait_timeout
max_error_count
max_execution_time
max_heap_table_size
max_join_size
max_length_for_sort_data
max_points_in_geometry
max_seeks_for_key
max_sort_length
optimizer_prune_level
optimizer_search_depth variables
optimizer_switch
range_alloc_block_size
range_optimizer_max_mem_size
read_buffer_size
read_rnd_buffer_size
sort_buffer_size
sql_auto_is_null
sql_big_selects
sql_buffer_result
sql_mode
sql_safe_updates
sql_select_limit
timestamp
tmp_table_size
updatable_views_with_limit
unique_checks
windowing_use_high_precision
———————————————————————————-

参照: The MySQL 8.0.3 Release Candidate is available