1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Fixed bug in SQL_SELECT_LIMIT

We where comparing costs when we should be comparing number of rows
that will be examined
This commit is contained in:
Monty
2021-10-06 12:34:54 +03:00
committed by Sergei Petrunia
parent fc0c157aaa
commit 7d0bef6cd7
5 changed files with 8 additions and 10 deletions

View File

@@ -39,19 +39,19 @@ id name id name
connect test_con1, localhost, root,,; connect test_con1, localhost, root,,;
connection test_con1; connection test_con1;
## Setting value of max_join_size ## ## 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 ## ## 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; 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 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-------------------------#' '#--------------------FN_DYNVARS_079_03-------------------------#'
## Setting global value of variable ## ## Setting global value of variable ##
SET @@global.max_join_size=8; SET @@global.max_join_size=4;
connect test_con2, localhost, root,,; connect test_con2, localhost, root,,;
connection test_con2; connection test_con2;
## Verifying value of max_join_size ## ## Verifying value of max_join_size ##
SELECT @@global.max_join_size; SELECT @@global.max_join_size;
@@global.max_join_size @@global.max_join_size
8 4
## Since total joins are more than max_join_size value so error will occur ## ## 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; 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 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

View File

@@ -3,7 +3,7 @@
SET @session_sql_big_selects = @@SESSION.sql_big_selects; SET @session_sql_big_selects = @@SESSION.sql_big_selects;
SET @session_max_join_size = @@SESSION.max_join_size; SET @session_max_join_size = @@SESSION.max_join_size;
SET @global_max_join_size = @@GLOBAL.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 t1(a varchar(20) not null, b varchar(20));
CREATE TEMPORARY TABLE t2(a varchar(20) null, b varchar(20)); CREATE TEMPORARY TABLE t2(a varchar(20) null, b varchar(20));
INSERT INTO t1 VALUES('aa','bb'); INSERT INTO t1 VALUES('aa','bb');

View File

@@ -84,7 +84,7 @@ connect (test_con1, localhost, root,,);
connection test_con1; connection test_con1;
--echo ## Setting value of max_join_size ## --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 ## --echo ## Since total joins are more than max_join_size value so error will occur ##
--Error ER_TOO_BIG_SELECT --Error ER_TOO_BIG_SELECT
@@ -97,7 +97,7 @@ SELECT * FROM t1 INNER JOIN t2 ON t1.id = t2.id;
########################################################## ##########################################################
--echo ## Setting global value of variable ## --echo ## Setting global value of variable ##
SET @@global.max_join_size=8; SET @@global.max_join_size=4;
connect (test_con2, localhost, root,,); connect (test_con2, localhost, root,,);
connection test_con2; connection test_con2;

View File

@@ -28,7 +28,7 @@
SET @session_sql_big_selects = @@SESSION.sql_big_selects; SET @session_sql_big_selects = @@SESSION.sql_big_selects;
SET @session_max_join_size = @@SESSION.max_join_size; SET @session_max_join_size = @@SESSION.max_join_size;
SET @global_max_join_size = @@GLOBAL.max_join_size; SET @global_max_join_size = @@GLOBAL.max_join_size;
SET MAX_JOIN_SIZE=9; SET MAX_JOIN_SIZE=21;
# #
# Create tables # Create tables
@@ -115,8 +115,6 @@ disconnect con_int2;
# #
# Cleanup # Cleanup
# #
SET @@SESSION.sql_big_selects = @session_sql_big_selects; SET @@SESSION.sql_big_selects = @session_sql_big_selects;
SET @@SESSION.max_join_size = @session_max_join_size; SET @@SESSION.max_join_size = @session_max_join_size;
SET @@GLOBAL.max_join_size = @global_max_join_size; SET @@GLOBAL.max_join_size = @global_max_join_size;

View File

@@ -2621,7 +2621,7 @@ int JOIN::optimize_stage2()
goto setup_subq_exit; goto setup_subq_exit;
} }
if (!(thd->variables.option_bits & OPTION_BIG_SELECTS) && 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)) !(select_options & SELECT_DESCRIBE))
{ /* purecov: inspected */ { /* purecov: inspected */
my_message(ER_TOO_BIG_SELECT, ER_THD(thd, ER_TOO_BIG_SELECT), MYF(0)); my_message(ER_TOO_BIG_SELECT, ER_THD(thd, ER_TOO_BIG_SELECT), MYF(0));