场景:
线上执行了一条大查询的SQL,出现报错:
ERROR 1104 (42000): The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay
排查:
查看SQL_BIG_SELECTS和MAX_JOIN_SIZE
mysql> show variables like 'max_join_size';
+---------------+----------------------+
| Variable_name | Value |
+---------------+----------------------+
| max_join_size | 6000000 |
+---------------+----------------------+
1 row in set (0.02 sec)
mysql> show variables like 'SQL_BIG_SELECTS';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| sql_big_selects | OFF |
+-----------------+-------+
1 row in set (0.00 sec)
发现MAX_JOIN_SIZE被调到了600000,同时也关闭了sql_big_selects,当查询优化器估算所检查的行数超过600000时,查询将被终止掉。
解决方法:
方法一、将sql_big_selects打开。
mysql> set global sql_big_selects=1;
Query OK, 0 rows affected (0.00 sec)
同时修改MySQL配置文件。
方法二、调大max_join_size
mysql> set global max_join_size=18446744073709551615;
Query OK, 0 rows affected (0.00 sec)
同时修改MySQL配置文件。
方法三、查询表添加索引,优化查询。