Bug #101198 SET_VAR optimizer hint doesn't recognize value that has decimal point
Submitted: 15 Oct 2020 20:22 Modified: 17 Oct 2020 16:17
Reporter: Shu Lin Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[15 Oct 2020 20:22] Shu Lin
Description:
SET_VAR optimizer hint doesn't recognize decimal point in <value>, as shown in the example below.

I use SET_VAR on secondary_engine_cost_threshold. If the value is "3", it works. If the value is "3.0" or "3.3", optimizer hint doesn't work. And the warning message seem to complain about the decimal point. The decimal point value works in a plain "set" command.

mysql> explain select /*+ SET_VAR(secondary_engine_cost_threshold=3) */ count(*) from t3;
--------------
explain select /*+ SET_VAR(secondary_engine_cost_threshold=3) */ count(*) from t3
--------------

+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
|  1 | SIMPLE      | t3    | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    3 |   100.00 | NULL  |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
--------------
show warnings
--------------

+-------+------+-----------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                         |
+-------+------+-----------------------------------------------------------------------------------------------------------------+
| Note  | 1003 | /* select#1 */ select /*+ SET_VAR(secondary_engine_cost_threshold=3) */ count(0) AS `count(*)` from `oltp`.`t3` |
+-------+------+-----------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>  explain select /*+ SET_VAR(secondary_engine_cost_threshold=3.0) */ count(*) from t3;
--------------
explain select /*+ SET_VAR(secondary_engine_cost_threshold=3.0) */ count(*) from t3
--------------

+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
|  1 | SIMPLE      | t3    | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    3 |   100.00 | NULL  |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
1 row in set, 2 warnings (0.00 sec)

mysql> show warnings;
--------------
show warnings
--------------

+---------+------+----------------------------------------------------------------------+
| Level   | Code | Message                                                              |
+---------+------+----------------------------------------------------------------------+
| Warning | 1064 | Optimizer hint syntax error near '.0) */ count(*) from t3' at line 1 |
| Note    | 1003 | /* select#1 */ select count(0) AS `count(*)` from `oltp`.`t3`        |
+---------+------+----------------------------------------------------------------------+
2 rows in set (0.01 sec)

mysql> explain select /*+ SET_VAR(secondary_engine_cost_threshold=3.3) */ count(*) from t3;
--------------
explain select /*+ SET_VAR(secondary_engine_cost_threshold=3.3) */ count(*) from t3
--------------

+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
|  1 | SIMPLE      | t3    | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    3 |   100.00 | NULL  |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
1 row in set, 2 warnings (0.00 sec)

mysql>  show warnings;
--------------
show warnings
--------------

+---------+------+----------------------------------------------------------------------+
| Level   | Code | Message                                                              |
+---------+------+----------------------------------------------------------------------+
| Warning | 1064 | Optimizer hint syntax error near '.3) */ count(*) from t3' at line 1 |
| Note    | 1003 | /* select#1 */ select count(0) AS `count(*)` from `oltp`.`t3`        |
+---------+------+----------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> set secondary_engine_cost_threshold=3.3;
--------------
set secondary_engine_cost_threshold=3.3
--------------

Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'secondary_engine_cost_threshold';
--------------
show variables like 'secondary_engine_cost_threshold'
--------------

+---------------------------------+----------+
| Variable_name                   | Value    |
+---------------------------------+----------+
| secondary_engine_cost_threshold | 3.300000 |
+---------------------------------+----------+
1 row in set (0.03 sec)

How to repeat:
See description. You can use any table to replace "t3" in my query. It doesn't matter.
[16 Oct 2020 11:42] MySQL Verification Team
Hi Mr. Lin,

Thank you for your bug report.

We have checked our source and, indeed, this variable is of the type `double`. Hence, it should accept a decimal point.

Verified as reported.
[17 Oct 2020 16:17] Gleb Shchepa
Thank you for your bug report. This issue has been committed to the source repository of the product and will be incorporated into the next release.

Thank you for your interest in MySQL.