Skip to content

Commit

Permalink
Fixed bug in SQL_SELECT_LIMIT
Browse files Browse the repository at this point in the history
We where comparing costs when we should be comparing number of rows
that will be examined
  • Loading branch information
montywi authored and spetrunia committed Jan 30, 2023
1 parent fc0c157 commit 7d0bef6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions mysql-test/suite/sys_vars/r/max_join_size_func.result
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ id name id name
connect test_con1, localhost, root,,;
connection test_con1;
## Setting value of max_join_size ##
SET @@session.max_join_size=8;
SET @@session.max_join_size=4;
## Since total joins are more than max_join_size value so error will occur ##
SELECT * FROM t1 INNER JOIN t2 ON t1.id = t2.id;
ERROR 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
'#--------------------FN_DYNVARS_079_03-------------------------#'
## Setting global value of variable ##
SET @@global.max_join_size=8;
SET @@global.max_join_size=4;
connect test_con2, localhost, root,,;
connection test_con2;
## Verifying value of max_join_size ##
SELECT @@global.max_join_size;
@@global.max_join_size
8
4
## Since total joins are more than max_join_size value so error will occur ##
SELECT * FROM t1 INNER JOIN t2 ON t1.id = t2.id;
ERROR 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
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/sys_vars/r/sql_big_selects_func.result
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SET @session_sql_big_selects = @@SESSION.sql_big_selects;
SET @session_max_join_size = @@SESSION.max_join_size;
SET @global_max_join_size = @@GLOBAL.max_join_size;
SET MAX_JOIN_SIZE=9;
SET MAX_JOIN_SIZE=21;
CREATE TEMPORARY TABLE t1(a varchar(20) not null, b varchar(20));
CREATE TEMPORARY TABLE t2(a varchar(20) null, b varchar(20));
INSERT INTO t1 VALUES('aa','bb');
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/sys_vars/t/max_join_size_func.test
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ connect (test_con1, localhost, root,,);
connection test_con1;

--echo ## Setting value of max_join_size ##
SET @@session.max_join_size=8;
SET @@session.max_join_size=4;

--echo ## Since total joins are more than max_join_size value so error will occur ##
--Error ER_TOO_BIG_SELECT
Expand All @@ -97,7 +97,7 @@ SELECT * FROM t1 INNER JOIN t2 ON t1.id = t2.id;
##########################################################

--echo ## Setting global value of variable ##
SET @@global.max_join_size=8;
SET @@global.max_join_size=4;

connect (test_con2, localhost, root,,);
connection test_con2;
Expand Down
4 changes: 1 addition & 3 deletions mysql-test/suite/sys_vars/t/sql_big_selects_func.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
SET @session_sql_big_selects = @@SESSION.sql_big_selects;
SET @session_max_join_size = @@SESSION.max_join_size;
SET @global_max_join_size = @@GLOBAL.max_join_size;
SET MAX_JOIN_SIZE=9;
SET MAX_JOIN_SIZE=21;

#
# Create tables
Expand Down Expand Up @@ -115,8 +115,6 @@ disconnect con_int2;
#
# Cleanup
#


SET @@SESSION.sql_big_selects = @session_sql_big_selects;
SET @@SESSION.max_join_size = @session_max_join_size;
SET @@GLOBAL.max_join_size = @global_max_join_size;
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,7 @@ int JOIN::optimize_stage2()
goto setup_subq_exit;
}
if (!(thd->variables.option_bits & OPTION_BIG_SELECTS) &&
best_read > (double) thd->variables.max_join_size &&
join_record_count > (double) thd->variables.max_join_size &&
!(select_options & SELECT_DESCRIBE))
{ /* purecov: inspected */
my_message(ER_TOO_BIG_SELECT, ER_THD(thd, ER_TOO_BIG_SELECT), MYF(0));
Expand Down

0 comments on commit 7d0bef6

Please sign in to comment.