Bug #105261 system variable max_join_size acts differently when table size is different
Submitted: 19 Oct 2021 8:24 Modified: 19 Oct 2021 11:40
Reporter: Cheng Zhou Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:8.0/5.7 OS:Any
Assigned to: CPU Architecture:Any

[19 Oct 2021 8:24] Cheng Zhou
Description:
The document says "Do not permit statements that probably need to examine more than max_join_size rows (for single-table statements) or row combinations (for multiple-table statements) or that are likely to do more than max_join_size disk seeks". But max_join_size acts differently for different table size.

How to repeat:
1. create table t1(a int primary key, b int);
2. set max_join_size = 5;
3. insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
4. 
mysql> select * from t1 limit 2;
+---+------+
| a | b    |
+---+------+
| 1 |    1 |
| 2 |    2 |
+---+------+
2 rows in set (0.00 sec)

5. 
delimiter //
create procedure sp1(a int, b int)
begin
declare var int;
set var =a;
while var<b do
insert into t1 values(var,var);
set var = var+1;
end while;
end //
delimiter ;
6.  call sp1(10,100);
7. mysql> select * from t1 limit 2;
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

Suggested fix:
Its behavior should be consistent for different table size.
[19 Oct 2021 11:40] MySQL Verification Team
Thank you for the bug report.