diff options
author | unknown <gshchepa/uchum@gleb.loc> | 2007-08-03 01:58:21 +0500 |
---|---|---|
committer | unknown <gshchepa/uchum@gleb.loc> | 2007-08-03 01:58:21 +0500 |
commit | a53510f0be0bfdbaff6e60366d5e8cfc1d2d197f (patch) | |
tree | 47296516b38e3c9b2c7c5042a7374083dfbb1207 | |
parent | 465c3ef06085c5f8ec6d5de8ad66a4d0ef560f2b (diff) | |
download | mariadb-git-a53510f0be0bfdbaff6e60366d5e8cfc1d2d197f.tar.gz |
Fixed bug #27352.
The SELECT query with more than 31 nested dependent SELECT queries returned
wrong result.
New error message has been added: ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT.
It will be reported as: "Too high level of nesting for select".
sql/sql_parse.cc:
Fixed bug #27352.
The Item_sum::register_sum_func method has been modified to return
TRUE on exceeding of allowed level of SELECT nesting and to report
corresponding error message.
sql/unireg.h:
Fixed bug #27352.
Constant definition has been added: maximal allowed level of SELECT nesting.
mysql-test/t/select.test:
Updated test case for bug #27352.
mysql-test/r/select.result:
Updated test case for bug #27352.
sql/share/errmsg.txt:
Fixed bug #27352.
New error message has been added: ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT.
-rw-r--r-- | mysql-test/r/select.result | 10 | ||||
-rw-r--r-- | mysql-test/t/select.test | 30 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 2 | ||||
-rw-r--r-- | sql/sql_parse.cc | 5 | ||||
-rw-r--r-- | sql/unireg.h | 2 |
5 files changed, 49 insertions, 0 deletions
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index bfe0b9d19df..5930c36029f 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -3995,4 +3995,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index 1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index DROP TABLE t1; +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (1,11), (2,22), (2,22); +EXPLAIN SELECT c1 FROM t1 WHERE (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT COUNT(c2)))))))))))))))))))))))))))))))) > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +31 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +32 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +EXPLAIN SELECT c1 FROM t1 WHERE (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT COUNT(c2))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) > 0; +ERROR HY000: Too high level of nesting for select +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 56b2f1b02b8..8bfa12539fa 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -3370,4 +3370,34 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2 WHERE 1 AND f1.b NOT IN (100,2232,3343,51111); DROP TABLE t1; +# +# Bug #27352: Incorrect result of nested selects instead of error reporting +# + +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (1,11), (2,22), (2,22); + +let $n= 31; +let $q= COUNT(c2); +while ($n) +{ + let $q= (SELECT $q); + dec $n; +} +--disable_warnings +eval EXPLAIN SELECT c1 FROM t1 WHERE $q > 0; +--enable_warnings + +let $n= 64; +let $q= COUNT(c2); +while ($n) +{ + let $q= (SELECT $q); + dec $n; +} +--error ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT +eval EXPLAIN SELECT c1 FROM t1 WHERE $q > 0; + +DROP TABLE t1; + --echo End of 5.0 tests diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index a52ffa8216c..6d4ca33ccc7 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5635,3 +5635,5 @@ ER_NON_INSERTABLE_TABLE eng "The target table %-.100s of the %s is not insertable-into" ER_ADMIN_WRONG_MRG_TABLE eng "Table '%-.64s' is differently defined or of non-MyISAM type or doesn't exist" +ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT + eng "Too high level of nesting for select" diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index ae3bc0f5597..78b3904a207 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5889,6 +5889,11 @@ mysql_new_select(LEX *lex, bool move_down) select_lex->init_query(); select_lex->init_select(); lex->nest_level++; + if (lex->nest_level > (int) MAX_SELECT_NESTING) + { + my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING); + DBUG_RETURN(1); + } select_lex->nest_level= lex->nest_level; /* Don't evaluate this subquery during statement prepare even if diff --git a/sql/unireg.h b/sql/unireg.h index 81ca18c1d32..d8301060cc4 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -81,6 +81,8 @@ RAND_TABLE_BIT) #define MAX_FIELDS 4096 /* Limit in the .frm file */ +#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1) + #define MAX_SORT_MEMORY (2048*1024-MALLOC_OVERHEAD) #define MIN_SORT_MEMORY (32*1024-MALLOC_OVERHEAD) |