From 12dc638abd820d813066a137e52ef49cd673e9ac Mon Sep 17 00:00:00 2001 From: "serg@janus.mylan" <> Date: Tue, 1 Aug 2006 14:02:19 +0200 Subject: [PATCH 1/5] compile-time definition of intptr type --- config/ac-macros/misc.m4 | 30 ------------------------------ configure.in | 2 +- include/my_atomic.h | 8 +++++++- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/config/ac-macros/misc.m4 b/config/ac-macros/misc.m4 index 3ed64b5625b..fdce85aa136 100644 --- a/config/ac-macros/misc.m4 +++ b/config/ac-macros/misc.m4 @@ -1,35 +1,5 @@ # Local macros for automake & autoconf -# A local version of AC_CHECK_SIZEOF that includes sys/types.h -dnl MYSQL_CHECK_SIZEOF(TYPE [, CROSS-SIZE]) -AC_DEFUN([MYSQL_CHECK_SIZEOF], -[changequote(<<, >>)dnl -dnl The name to #define. -define(<>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl -dnl The cache variable name. -define(<>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl -changequote([, ])dnl -AC_MSG_CHECKING(size of $1) -AC_CACHE_VAL(AC_CV_NAME, -[AC_TRY_RUN([#include -#include -#if STDC_HEADERS -#include -#include -#endif -main() -{ - FILE *f=fopen("conftestval", "w"); - if (!f) exit(1); - fprintf(f, "%d\n", sizeof($1)); - exit(0); -}], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, ifelse([$2], , , AC_CV_NAME=$2))])dnl -AC_MSG_RESULT($AC_CV_NAME) -AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [ ]) -undefine([AC_TYPE_NAME])dnl -undefine([AC_CV_NAME])dnl -]) - #---START: Used in for client configure AC_DEFUN([MYSQL_TYPE_ACCEPT], [ac_save_CXXFLAGS="$CXXFLAGS" diff --git a/configure.in b/configure.in index 1306a3cc74d..49da91797fc 100644 --- a/configure.in +++ b/configure.in @@ -1687,7 +1687,7 @@ then AC_MSG_ERROR("MySQL needs a long long type.") fi # off_t is not a builtin type -MYSQL_CHECK_SIZEOF(off_t, 4) +AC_CHECK_SIZEOF(off_t, 4) if test "$ac_cv_sizeof_off_t" -eq 0 then AC_MSG_ERROR("MySQL needs a off_t type.") diff --git a/include/my_atomic.h b/include/my_atomic.h index c916026c0e0..9a319f84451 100644 --- a/include/my_atomic.h +++ b/include/my_atomic.h @@ -135,7 +135,13 @@ make_atomic_swap(ptr) #undef _atomic_h_cleanup_ #endif -typedef int32 intptr; /* TODO configure check */ +#if SIZEOF_CHARP == SIZEOF_INT +typedef int intptr; +#elif SIZEOF_CHARP == SIZEOF_LONG +typedef long intptr; +#else +#error +#endif #define MY_ATOMIC_OK 0 #define MY_ATOMIC_NOT_1CPU 1 From 9c59cfe4d7fd6047212eb4e84aa2d657aea2134c Mon Sep 17 00:00:00 2001 From: "andrey@lmy004." <> Date: Fri, 4 Aug 2006 12:50:49 +0200 Subject: [PATCH 2/5] Fix for bug#21416 SP: Recursion level higher than zero needed for non-recursive call The following procedure was not possible if max_sp_recursion_depth is 0 create procedure show_proc() show create procedure show_proc; Actually there is no recursive call but the limit is checked. Solved by temporarily increasing the thread's limit just before the fetch from cache and decreasing after that. --- mysql-test/r/sp.result | 7 +++++++ mysql-test/t/sp.test | 10 ++++++++++ sql/sp.cc | 21 +++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index db72d190441..3ef1066ecda 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5051,4 +5051,11 @@ concat('data was: /', var1, '/') data was: /1/ drop table t3| drop procedure bug15217| +drop procedure if exists bug21416| +create procedure bug21416() show create procedure bug21416| +call bug21416()| +Procedure sql_mode Create Procedure +bug21416 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug21416`() +show create procedure bug21416 +drop procedure bug21416| drop table t1,t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 99f3bbbbd14..fcf179d3e8f 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5950,6 +5950,16 @@ call bug15217()| drop table t3| drop procedure bug15217| +# +# BUG#21416: SP: Recursion level higher than zero needed for non-recursive call +# +--disable_warnings +drop procedure if exists bug21416| +--enable_warnings +create procedure bug21416() show create procedure bug21416| +call bug21416()| +drop procedure bug21416| + # # BUG#NNNN: New bug synopsis # diff --git a/sql/sp.cc b/sql/sp.cc index e794a461402..bea4eb12836 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -992,6 +992,12 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, } DBUG_RETURN(sp->m_first_free_instance); } + /* + Actually depth could be +1 than the actual value in case a SP calls + SHOW CREATE PROCEDURE. Hence, the linked list could hold up to one more + instance. + */ + level= sp->m_last_cached_sp->m_recursion_level + 1; if (level > depth) { @@ -1161,19 +1167,22 @@ sp_update_procedure(THD *thd, sp_name *name, st_sp_chistics *chistics) int sp_show_create_procedure(THD *thd, sp_name *name) { + int ret= SP_KEY_NOT_FOUND; sp_head *sp; DBUG_ENTER("sp_show_create_procedure"); DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str)); + /* + Increase the recursion limit for this statement. SHOW CREATE PROCEDURE + does not do actual recursion. + */ + thd->variables.max_sp_recursion_depth++; if ((sp= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name, &thd->sp_proc_cache, FALSE))) - { - int ret= sp->show_create_procedure(thd); + ret= sp->show_create_procedure(thd); - DBUG_RETURN(ret); - } - - DBUG_RETURN(SP_KEY_NOT_FOUND); + thd->variables.max_sp_recursion_depth--; + DBUG_RETURN(ret); } From 76ff7fb78f7369bdb807b0bd8ad9e9a45a8e75ea Mon Sep 17 00:00:00 2001 From: "andrey@lmy004." <> Date: Wed, 9 Aug 2006 17:07:59 +0200 Subject: [PATCH 3/5] Fix for bug#20701 BINARY keyword should be forbidden in stored routines create function func() returns char(10) binary ... is no more possible. This will be reenabled when bug 2676 "DECLARE can't have COLLATE clause in stored procedure" is fixed. Fix after 2nd review --- mysql-test/r/sp-error.result | 5 +++++ mysql-test/r/sp.result | 14 ++++++++++---- mysql-test/t/sp-error.test | 18 ++++++++++++++++++ mysql-test/t/sp.test | 19 +++++++++++++++---- sql/sql_yacc.yy | 11 +++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index bf36b4796b9..63401845f23 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1181,3 +1181,8 @@ show authors; return 42; end| ERROR 0A000: Not allowed to return a result set from a function +drop function if exists bug20701| +create function bug20701() returns varchar(25) binary return "test"| +ERROR 42000: This version of MySQL doesn't yet support 'return value collation' +create function bug20701() returns varchar(25) return "test"| +drop function bug20701| diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 3ef1066ecda..e51ebaa4e94 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -3620,12 +3620,18 @@ call bug11333(10)| drop procedure bug11333| drop table t3| drop function if exists bug9048| -create function bug9048(f1 char binary) returns char binary +create function bug9048(f1 char binary) returns char begin set f1= concat( 'hello', f1 ); return f1; end| drop function bug9048| +create function bug9048(f1 char binary) returns char binary +begin +set f1= concat( 'hello', f1 ); +return f1; +end| +ERROR 42000: This version of MySQL doesn't yet support 'return value collation' drop procedure if exists bug12849_1| create procedure bug12849_1(inout x char) select x into x| set @var='a'| @@ -4074,7 +4080,7 @@ select res; end| create table t3 (a int)| insert into t3 values (0)| -create view v1 as select a from t3; +create view v1 as select a from t3| create procedure bug10100pt(level int, lim int) begin if level < lim then @@ -4095,7 +4101,7 @@ else select * from v1; end if; end| -prepare stmt2 from "select * from t3;"; +prepare stmt2 from "select * from t3;"| create procedure bug10100pd(level int, lim int) begin if level < lim then @@ -4465,7 +4471,7 @@ Error 1347 'test.v1' is not BASE TABLE Error 1347 'test.v1' is not BASE TABLE Error 1347 'test.v1' is not BASE TABLE drop procedure bug13012| -drop view v1; +drop view v1| select * from t1 order by data| id data aa 0 diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index d370cb3037c..73a64b6feeb 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1728,10 +1728,28 @@ begin return 42; end| +# +# BUG#20701: BINARY keyword should be forbidden in stored routines +# +--disable_warnings +drop function if exists bug20701| +--enable_warnings +# +# This was disabled in 5.1.12. See bug #20701 +# When collation support in SP is implemented, then this test should +# be removed. +# +--error ER_NOT_SUPPORTED_YET +create function bug20701() returns varchar(25) binary return "test"| +create function bug20701() returns varchar(25) return "test"| +drop function bug20701| + # # BUG#NNNN: New bug synopsis # #--disable_warnings #drop procedure if exists bugNNNN| +#drop function if exists bugNNNN| #--enable_warnings #create procedure bugNNNN... +#create function bugNNNN... diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index fcf179d3e8f..6ae7319e433 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -4381,12 +4381,23 @@ drop table t3| --disable_warnings drop function if exists bug9048| --enable_warnings -create function bug9048(f1 char binary) returns char binary +create function bug9048(f1 char binary) returns char begin set f1= concat( 'hello', f1 ); return f1; end| drop function bug9048| +# +# This was disabled in 5.1.12. See bug #20701 +# When collation support in SP is implemented, then this test should +# be removed. +# +--error ER_NOT_SUPPORTED_YET +create function bug9048(f1 char binary) returns char binary +begin + set f1= concat( 'hello', f1 ); + return f1; +end| # Bug #12849 Stored Procedure: Crash on procedure call with CHAR type # 'INOUT' parameter @@ -4940,7 +4951,7 @@ end| # a procedure which use tables and recursion create table t3 (a int)| insert into t3 values (0)| -create view v1 as select a from t3; +create view v1 as select a from t3| create procedure bug10100pt(level int, lim int) begin if level < lim then @@ -4963,7 +4974,7 @@ begin end if; end| # dynamic sql & recursion -prepare stmt2 from "select * from t3;"; +prepare stmt2 from "select * from t3;"| create procedure bug10100pd(level int, lim int) begin if level < lim then @@ -5258,7 +5269,7 @@ call bug13012()| call bug13012()| call bug13012()| drop procedure bug13012| -drop view v1; +drop view v1| select * from t1 order by data| # diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ff422c4418c..d94281ed9cc 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1672,6 +1672,17 @@ create_function_tail: { LEX *lex= Lex; sp_head *sp= lex->sphead; + /* + This was disabled in 5.1.12. See bug #20701 + When collation support in SP is implemented, then this test + should be removed. + */ + if (($8 == FIELD_TYPE_STRING || $8 == MYSQL_TYPE_VARCHAR) + && (lex->type & BINCMP_FLAG)) + { + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "return value collation"); + YYABORT; + } if (sp->fill_field_definition(YYTHD, lex, (enum enum_field_types) $8, From eba9109225b2bebda9a78be47fbc8de71b47f991 Mon Sep 17 00:00:00 2001 From: "andrey@example.com" <> Date: Thu, 10 Aug 2006 11:52:34 +0200 Subject: [PATCH 4/5] after merge update --- mysql-test/r/mysqldump.result | 2 +- mysql-test/r/sp.result | 7 +++++++ mysql-test/t/mysqldump.test | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index f01d8f6160e..153ddb7ca2b 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -2279,7 +2279,7 @@ INSERT INTO t1 VALUES(1), (2), (3), (4), (5); CREATE FUNCTION `bug9056_func1`(a INT, b INT) RETURNS int(11) RETURN a+b // CREATE PROCEDURE `bug9056_proc1`(IN a INT, IN b INT, OUT c INT) BEGIN SELECT a+b INTO c; end // -create function bug9056_func2(f1 char binary) returns char binary +create function bug9056_func2(f1 char binary) returns char begin set f1= concat( 'hello', f1 ); return f1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index ec4065fbc1d..8ff180044df 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -3620,11 +3620,18 @@ call bug11333(10)| drop procedure bug11333| drop table t3| drop function if exists bug9048| +create function bug9048(f1 char binary) returns char +begin +set f1= concat( 'hello', f1 ); +return f1; +end| +drop function bug9048| create function bug9048(f1 char binary) returns char binary begin set f1= concat( 'hello', f1 ); return f1; end| +ERROR 42000: This version of MySQL doesn't yet support 'return value collation' drop procedure if exists bug12849_1| create procedure bug12849_1(inout x char) select x into x| set @var='a'| diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 8acc29fcc50..c40a21e0ca0 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -951,7 +951,7 @@ CREATE FUNCTION `bug9056_func1`(a INT, b INT) RETURNS int(11) RETURN a+b // CREATE PROCEDURE `bug9056_proc1`(IN a INT, IN b INT, OUT c INT) BEGIN SELECT a+b INTO c; end // -create function bug9056_func2(f1 char binary) returns char binary +create function bug9056_func2(f1 char binary) returns char begin set f1= concat( 'hello', f1 ); return f1; From 81efea724ed497f602051bad3aad0bd57d2e4223 Mon Sep 17 00:00:00 2001 From: "andrey@example.com" <> Date: Thu, 10 Aug 2006 12:26:43 +0200 Subject: [PATCH 5/5] revert part of the code how did it get in?!? (it's only in local csets so no other tree is affected) --- sql/sp.cc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/sql/sp.cc b/sql/sp.cc index d8bbd97f601..f60a167e39a 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -992,11 +992,6 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, } DBUG_RETURN(sp->m_first_free_instance); } - /* - Actually depth could be +1 than the actual value in case a SP calls - SHOW CREATE PROCEDURE. Hence, the linked list could hold up to one more - instance. - */ level= sp->m_last_cached_sp->m_recursion_level + 1; if (level > depth) @@ -1172,16 +1167,10 @@ sp_show_create_procedure(THD *thd, sp_name *name) DBUG_ENTER("sp_show_create_procedure"); DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str)); - /* - Increase the recursion limit for this statement. SHOW CREATE PROCEDURE - does not do actual recursion. - */ - thd->variables.max_sp_recursion_depth++; if ((sp= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name, &thd->sp_proc_cache, FALSE))) ret= sp->show_create_procedure(thd); - thd->variables.max_sp_recursion_depth--; DBUG_RETURN(ret); }