From 0770db04507975fc85530fbf86bbc721def20413 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 3 Jul 2006 14:54:09 +0500 Subject: bug 20317 (test fails in embedded for different number of threads is running) I decided to make ps_1general test independent from actual number of threads running mysql-test/r/ps_1general.result: result fixed mysql-test/t/ps_1general.test: as i think we don't really care about the number of threads running i just replace the number with '#' --- mysql-test/r/ps_1general.result | 2 +- mysql-test/t/ps_1general.test | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index 49e858eca56..67b6c0d1b0b 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -282,7 +282,7 @@ t9 MyISAM 9 Dynamic 2 220 440 4294967295 2048 0 NULL # # # latin1_swedish_ci NUL prepare stmt4 from ' show status like ''Threads_running'' '; execute stmt4; Variable_name Value -Threads_running 1 +Threads_running # prepare stmt4 from ' show variables like ''sql_mode'' '; execute stmt4; Variable_name Value diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test index 5752e6b0b66..6f15ba8f673 100644 --- a/mysql-test/t/ps_1general.test +++ b/mysql-test/t/ps_1general.test @@ -305,6 +305,7 @@ prepare stmt4 from ' show table status from test like ''t9%'' '; --replace_result 2147483647 4294967295 # Bug#4288 execute stmt4; +--replace_column 2 # prepare stmt4 from ' show status like ''Threads_running'' '; execute stmt4; prepare stmt4 from ' show variables like ''sql_mode'' '; -- cgit v1.2.1 From 7733615d8d843e850dfe336e3d77d7901f84b772 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 7 Jul 2006 21:24:54 +0400 Subject: Bug#19207: Final parenthesis omitted for CREATE INDEX in Stored Procedure Wrong criteria was used to distinguish the case when there was no lookahead performed in the parser. Bug affected only statements ending in one-character token without any optional tail, like CREATE INDEX and CALL. mysql-test/r/sp-code.result: Add result for bug#19207: Final parenthesis omitted for CREATE INDEX in Stored Procedure mysql-test/t/sp-code.test: Add test case for bug#19207: Final parenthesis omitted for CREATE INDEX in Stored Procedure sql/sql_yacc.yy: Use (yychar == YYEMPTY) as the criteria of whether lookahead was not performed. --- mysql-test/r/sp-code.result | 11 +++++++++-- mysql-test/t/sp-code.test | 22 ++++++++++++++++++++++ sql/sql_yacc.yy | 16 ++++++++++++---- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/sp-code.result b/mysql-test/r/sp-code.result index 8bdb9a724d7..4ae38861d29 100644 --- a/mysql-test/r/sp-code.result +++ b/mysql-test/r/sp-code.result @@ -155,11 +155,11 @@ Pos Instruction 0 stmt 9 "drop temporary table if exists sudoku..." 1 stmt 1 "create temporary table sudoku_work ( ..." 2 stmt 1 "create temporary table sudoku_schedul..." -3 stmt 95 "call sudoku_init(" +3 stmt 95 "call sudoku_init()" 4 jump_if_not 7(8) p_naive@0 5 stmt 4 "update sudoku_work set cnt = 0 where ..." 6 jump 8 -7 stmt 95 "call sudoku_count(" +7 stmt 95 "call sudoku_count()" 8 stmt 6 "insert into sudoku_schedule (row,col)..." 9 set v_scounter@2 0 10 set v_i@3 1 @@ -199,3 +199,10 @@ Pos Instruction 44 jump 14 45 stmt 9 "drop temporary table sudoku_work, sud..." drop procedure sudoku_solve; +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1() CREATE INDEX idx ON t1 (c1); +SHOW PROCEDURE CODE p1; +Pos Instruction +0 stmt 2 "CREATE INDEX idx ON t1 (c1)" +DROP PROCEDURE p1; +End of 5.0 tests. diff --git a/mysql-test/t/sp-code.test b/mysql-test/t/sp-code.test index 0a26ea644f6..72efa831059 100644 --- a/mysql-test/t/sp-code.test +++ b/mysql-test/t/sp-code.test @@ -190,3 +190,25 @@ delimiter ;// show procedure code sudoku_solve; drop procedure sudoku_solve; + + +# +# Bug#19207: Final parenthesis omitted for CREATE INDEX in Stored +# Procedure +# +# Wrong criteria was used to distinguish the case when there was no +# lookahead performed in the parser. Bug affected only statements +# ending in one-character token without any optional tail, like CREATE +# INDEX and CALL. +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +CREATE PROCEDURE p1() CREATE INDEX idx ON t1 (c1); +SHOW PROCEDURE CODE p1; + +DROP PROCEDURE p1; + + +--echo End of 5.0 tests. diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 952a8eb44ea..ae41f90b3e8 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1911,9 +1911,12 @@ sp_proc_stmt: sp_instr_stmt *i=new sp_instr_stmt(sp->instructions(), lex->spcont, lex); - /* Extract the query statement from the tokenizer: - The end is either lex->tok_end or tok->ptr. */ - if (lex->ptr - lex->tok_end > 1) + /* + Extract the query statement from the tokenizer. The + end is either lex->ptr, if there was no lookahead, + lex->tok_end otherwise. + */ + if (yychar == YYEMPTY) i->m_query.length= lex->ptr - sp->m_tmp_query; else i->m_query.length= lex->tok_end - sp->m_tmp_query; @@ -7841,7 +7844,12 @@ option_type_value: lex))) YYABORT; - if (lex->ptr - lex->tok_end > 1) + /* + Extract the query statement from the tokenizer. The + end is either lex->ptr, if there was no lookahead, + lex->tok_end otherwise. + */ + if (yychar == YYEMPTY) qbuff.length= lex->ptr - sp->m_tmp_query; else qbuff.length= lex->tok_end - sp->m_tmp_query; -- cgit v1.2.1 From 3ff08ab8cbb0963a881a93e317d29cae506f545f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 Jul 2006 23:39:51 +0400 Subject: Post-merge fixes for Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating tables" mysql-test/r/ps.result: A post-merge fix. mysql-test/t/ps.test: A post-merge fix: all 5.0 tests should go after 4.1 tests. sql/sql_lex.cc: auxilliary -> auxiliary sql/sql_prepare.cc: auxilliary -> auxiliary sql/table.cc: Update st_table_list::reinit_before_use in 5.0 to include 5.0-specific cleanups. sql/table.h: st_table_list::reinit_before_use is public. --- mysql-test/r/ps.result | 267 ++++++++++++++++++++++++++----------------------- mysql-test/t/ps.test | 28 +++--- sql/sql_lex.cc | 2 +- sql/sql_prepare.cc | 4 +- sql/table.cc | 17 +++- sql/table.h | 2 +- 6 files changed, 173 insertions(+), 147 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 3ce2f5169e2..68602f7b053 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -485,11 +485,6 @@ execute stmt; pnum deallocate prepare stmt; drop table t1, t2; -create table t1 (a varchar(20)); -insert into t1 values ('foo'); -prepare stmt FROM 'SELECT char_length (a) FROM t1'; -ERROR 42000: FUNCTION test.char_length does not exist -drop table t1; prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0"; execute stmt; foo @@ -502,77 +497,6 @@ SELECT FOUND_ROWS(); FOUND_ROWS() 2 deallocate prepare stmt; -create table t1 (a char(3) not null, b char(3) not null, -c char(3) not null, primary key (a, b, c)); -create table t2 like t1; -prepare stmt from -"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) - where t1.a=1"; -execute stmt; -a -execute stmt; -a -execute stmt; -a -prepare stmt from -"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from -(t1 left outer join t2 on t2.a=? and t1.b=t2.b) -left outer join t2 t3 on t3.a=? where t1.a=?"; -set @a:=1, @b:=1, @c:=1; -execute stmt using @a, @b, @c; -a b c a b c -execute stmt using @a, @b, @c; -a b c a b c -execute stmt using @a, @b, @c; -a b c a b c -deallocate prepare stmt; -drop table t1,t2; -SET @aux= "SELECT COUNT(*) - FROM INFORMATION_SCHEMA.COLUMNS A, - INFORMATION_SCHEMA.COLUMNS B - WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA - AND A.TABLE_NAME = B.TABLE_NAME - AND A.COLUMN_NAME = B.COLUMN_NAME AND - A.TABLE_NAME = 'user'"; -prepare my_stmt from @aux; -execute my_stmt; -COUNT(*) -37 -execute my_stmt; -COUNT(*) -37 -execute my_stmt; -COUNT(*) -37 -deallocate prepare my_stmt; -drop procedure if exists p1| -drop table if exists t1| -create table t1 (id int)| -insert into t1 values(1)| -create procedure p1(a int, b int) -begin -declare c int; -select max(id)+1 into c from t1; -insert into t1 select a+b; -insert into t1 select a-b; -insert into t1 select a-c; -end| -set @a= 3, @b= 4| -prepare stmt from "call p1(?, ?)"| -execute stmt using @a, @b| -execute stmt using @a, @b| -select * from t1| -id -1 -7 --1 -1 -7 --1 --5 -deallocate prepare stmt| -drop procedure p1| -drop table t1| drop table if exists t1; Warnings: Note 1051 Unknown table 't1' @@ -636,47 +560,6 @@ id 3 deallocate prepare stmt; drop table t1, t2; -create table t1 (a int); -insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); -prepare stmt from "select * from t1 limit ?, ?"; -set @offset=0, @limit=1; -execute stmt using @offset, @limit; -a -1 -select * from t1 limit 0, 1; -a -1 -set @offset=3, @limit=2; -execute stmt using @offset, @limit; -a -4 -5 -select * from t1 limit 3, 2; -a -4 -5 -prepare stmt from "select * from t1 limit ?"; -execute stmt using @limit; -a -1 -2 -prepare stmt from "select * from t1 where a in (select a from t1 limit ?)"; -ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' -prepare stmt from "select * from t1 union all select * from t1 limit ?, ?"; -set @offset=9; -set @limit=2; -execute stmt using @offset, @limit; -a -10 -1 -prepare stmt from "(select * from t1 limit ?, ?) union all - (select * from t1 limit ?, ?) order by a limit ?"; -execute stmt using @offset, @limit, @offset, @limit, @limit; -a -10 -10 -drop table t1; -deallocate prepare stmt; create table t1 (id int); prepare stmt from "insert into t1 (id) select id from t1 union select id from t1"; execute stmt; @@ -777,15 +660,6 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp select ? from t1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1 drop table t1; -CREATE TABLE b12651_T1(a int) ENGINE=MYISAM; -CREATE TABLE b12651_T2(b int) ENGINE=MYISAM; -CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2; -PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)'; -EXECUTE b12651; -1 -DROP VIEW b12651_V1; -DROP TABLE b12651_T1, b12651_T2; -DEALLOCATE PREPARE b12651; prepare stmt from "select @@time_zone"; execute stmt; @@time_zone @@ -1002,6 +876,147 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count; @@max_prepared_stmt_count @@prepared_stmt_count 3 0 set global max_prepared_stmt_count= @old_max_prepared_stmt_count; +drop table if exists t1; +create temporary table if not exists t1 (a1 int); +prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1"; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +deallocate prepare stmt; +End of 4.1 tests +create table t1 (a varchar(20)); +insert into t1 values ('foo'); +prepare stmt FROM 'SELECT char_length (a) FROM t1'; +ERROR 42000: FUNCTION test.char_length does not exist +drop table t1; +create table t1 (a char(3) not null, b char(3) not null, +c char(3) not null, primary key (a, b, c)); +create table t2 like t1; +prepare stmt from +"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) + where t1.a=1"; +execute stmt; +a +execute stmt; +a +execute stmt; +a +prepare stmt from +"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from +(t1 left outer join t2 on t2.a=? and t1.b=t2.b) +left outer join t2 t3 on t3.a=? where t1.a=?"; +set @a:=1, @b:=1, @c:=1; +execute stmt using @a, @b, @c; +a b c a b c +execute stmt using @a, @b, @c; +a b c a b c +execute stmt using @a, @b, @c; +a b c a b c +deallocate prepare stmt; +drop table t1,t2; +SET @aux= "SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS A, + INFORMATION_SCHEMA.COLUMNS B + WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA + AND A.TABLE_NAME = B.TABLE_NAME + AND A.COLUMN_NAME = B.COLUMN_NAME AND + A.TABLE_NAME = 'user'"; +prepare my_stmt from @aux; +execute my_stmt; +COUNT(*) +37 +execute my_stmt; +COUNT(*) +37 +execute my_stmt; +COUNT(*) +37 +deallocate prepare my_stmt; +drop procedure if exists p1| +drop table if exists t1| +create table t1 (id int)| +insert into t1 values(1)| +create procedure p1(a int, b int) +begin +declare c int; +select max(id)+1 into c from t1; +insert into t1 select a+b; +insert into t1 select a-b; +insert into t1 select a-c; +end| +set @a= 3, @b= 4| +prepare stmt from "call p1(?, ?)"| +execute stmt using @a, @b| +execute stmt using @a, @b| +select * from t1| +id +1 +7 +-1 +1 +7 +-1 +-5 +deallocate prepare stmt| +drop procedure p1| +drop table t1| +create table t1 (a int); +insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +prepare stmt from "select * from t1 limit ?, ?"; +set @offset=0, @limit=1; +execute stmt using @offset, @limit; +a +1 +select * from t1 limit 0, 1; +a +1 +set @offset=3, @limit=2; +execute stmt using @offset, @limit; +a +4 +5 +select * from t1 limit 3, 2; +a +4 +5 +prepare stmt from "select * from t1 limit ?"; +execute stmt using @limit; +a +1 +2 +prepare stmt from "select * from t1 where a in (select a from t1 limit ?)"; +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +prepare stmt from "select * from t1 union all select * from t1 limit ?, ?"; +set @offset=9; +set @limit=2; +execute stmt using @offset, @limit; +a +10 +1 +prepare stmt from "(select * from t1 limit ?, ?) union all + (select * from t1 limit ?, ?) order by a limit ?"; +execute stmt using @offset, @limit, @offset, @limit, @limit; +a +10 +10 +drop table t1; +deallocate prepare stmt; +CREATE TABLE b12651_T1(a int) ENGINE=MYISAM; +CREATE TABLE b12651_T2(b int) ENGINE=MYISAM; +CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2; +PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)'; +EXECUTE b12651; +1 +DROP VIEW b12651_V1; +DROP TABLE b12651_T1, b12651_T2; +DEALLOCATE PREPARE b12651; create table t1 (id int); prepare ins_call from "insert into t1 (id) values (1)"; execute ins_call; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 85987b69574..c9357481e6c 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -527,6 +527,7 @@ set @a=200887, @b=860; # this query did not return all matching rows execute stmt using @a, @b; deallocate prepare stmt; + drop table t1; # @@ -586,7 +587,6 @@ execute stmt; execute stmt; deallocate prepare stmt; drop table t1; - # # Bug#11458 "Prepared statement with subselects return random data": # drop PARAM_TABLE_BIT from the list of tables used by a subquery @@ -655,7 +655,6 @@ execute stmt using @user_id, @id; execute stmt using @user_id, @id; deallocate prepare stmt; drop table t1, t2, t3, t4; - # # Bug#9379: make sure that Item::collation is reset when one sets # a parameter marker from a string variable. @@ -770,7 +769,6 @@ execute stmt using @like; deallocate prepare stmt; drop table t1; - # # Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is # recreated with PS/SP" @@ -841,17 +839,17 @@ set global max_prepared_stmt_count=10000000000000000; select @@max_prepared_stmt_count; set global max_prepared_stmt_count=default; select @@max_prepared_stmt_count; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_GLOBAL_VARIABLE set @@max_prepared_stmt_count=1; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_GLOBAL_VARIABLE set max_prepared_stmt_count=1; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_GLOBAL_VARIABLE set local max_prepared_stmt_count=1; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_INCORRECT_GLOBAL_LOCAL_VAR set local prepared_stmt_count=0; ---error 1229 # ER_GLOBAL_VARIABLE +--error ER_INCORRECT_GLOBAL_LOCAL_VAR set @@prepared_stmt_count=0; ---error 1232 # ER_WRONG_TYPE_FOR_VAR +--error ER_INCORRECT_GLOBAL_LOCAL_VAR set global prepared_stmt_count=1; # set to a reasonable limit works set global max_prepared_stmt_count=1; @@ -861,13 +859,13 @@ select @@max_prepared_stmt_count; # set global max_prepared_stmt_count=0; select @@max_prepared_stmt_count, @@prepared_stmt_count; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt from "select 1"; select @@prepared_stmt_count; set global max_prepared_stmt_count=1; prepare stmt from "select 1"; select @@prepared_stmt_count; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt1 from "select 1"; select @@prepared_stmt_count; deallocate prepare stmt; @@ -886,13 +884,13 @@ select @@prepared_stmt_count; # select @@prepared_stmt_count, @@max_prepared_stmt_count; set global max_prepared_stmt_count=0; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt from "select 1"; # Result: the old statement is deallocated, the new is not created. --error 1243 # ER_UNKNOWN_STMT_HANDLER execute stmt; select @@prepared_stmt_count; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt from "select 1"; select @@prepared_stmt_count; # @@ -906,10 +904,10 @@ connect (con1,localhost,root,,); connection con1; prepare stmt from "select 2"; prepare stmt1 from "select 3"; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt2 from "select 4"; connection default; ---error 1105 # ER_UNKNOWN_ERROR +--error ER_MAX_PREPARED_STMT_COUNT_REACHED prepare stmt2 from "select 4"; select @@max_prepared_stmt_count, @@prepared_stmt_count; disconnect con1; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 16925348cce..efbf29cf207 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -126,7 +126,7 @@ void lex_start(THD *thd, uchar *buf,uint length) lex->param_list.empty(); lex->view_list.empty(); lex->prepared_stmt_params.empty(); - lex->auxilliary_table_list.empty(); + lex->auxiliary_table_list.empty(); lex->unit.next= lex->unit.master= lex->unit.link_next= lex->unit.return_to= 0; lex->unit.prev= lex->unit.link_prev= 0; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 37a5e2f0af0..a2f73ac9989 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2138,9 +2138,9 @@ void reinit_stmt_before_use(THD *thd, LEX *lex) (multi-delete). We do a full clean up, although at the moment all we need to clean in the tables of MULTI-DELETE list is 'table' member. */ - for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxilliary_table_list.first; + for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxiliary_table_list.first; tables; - tables= tables->next) + tables= tables->next_global) { tables->reinit_before_use(thd); } diff --git a/sql/table.cc b/sql/table.cc index 55e1575b9a3..b4c08729a79 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2992,14 +2992,27 @@ Field_iterator_table_ref::get_natural_column_ref() st_table_list::reinit_before_use() */ -void st_table_list::reinit_before_use(THD * /* thd */) +void st_table_list::reinit_before_use(THD *thd) { /* Reset old pointers to TABLEs: they are not valid since the tables were closed in the end of previous prepare or execute call. */ table= 0; - table_list= 0; + /* Reset is_schema_table_processed value(needed for I_S tables */ + is_schema_table_processed= FALSE; + + TABLE_LIST *embedded; /* The table at the current level of nesting. */ + TABLE_LIST *embedding= this; /* The parent nested table reference. */ + do + { + embedded= embedding; + if (embedded->prep_on_expr) + embedded->on_expr= embedded->prep_on_expr->copy_andor_structure(thd); + embedding= embedded->embedding; + } + while (embedding && + embedding->nested_join->join_list.head() == embedded); } diff --git a/sql/table.h b/sql/table.h index 88a1482907c..44ec3dc5c06 100644 --- a/sql/table.h +++ b/sql/table.h @@ -668,6 +668,7 @@ typedef struct st_table_list Security_context *find_view_security_context(THD *thd); bool prepare_view_securety_context(THD *thd); #endif + void reinit_before_use(THD *thd); private: bool prep_check_option(THD *thd, uint8 check_opt_type); @@ -676,7 +677,6 @@ private: Cleanup for re-execution in a prepared statement or a stored procedure. */ - void reinit_before_use(THD *thd); } TABLE_LIST; class Item; -- cgit v1.2.1 From 06bf59ad3381522f4f5ba272a478271c741f0049 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 13 Jul 2006 17:12:31 +0400 Subject: Bug#18630: Arguments of suid routine calculated in wrong security context. Routine arguments were evaluated in the security context of the routine itself, not in the caller's context. The bug is fixed the following way: - Item_func_sp::find_and_check_access() has been split into two functions: Item_func_sp::find_and_check_access() itself only finds the function and check that the caller have EXECUTE privilege on it. New function set_routine_security_ctx() changes security context for SUID routines and checks that definer have EXECUTE privilege too. - new function sp_head::execute_trigger() is called from Table_triggers_list::process_triggers() instead of sp_head::execute_function(), and is effectively just as the sp_head::execute_function() is, with all non-trigger related code removed, and added trigger-specific security context switch. - call to Item_func_sp::find_and_check_access() stays outside of sp_head::execute_function(), and there is a code in sql_parse.cc before the call to sp_head::execute_procedure() that checks that the caller have EXECUTE privilege, but both sp_head::execute_function() and sp_head::execute_procedure() call set_routine_security_ctx() after evaluating their parameters, and restore the context after the body is executed. mysql-test/r/sp-security.result: Add test case for bug#18630: Arguments of suid routine calculated in wrong security context. mysql-test/t/sp-security.test: Add result for bug#18630: Arguments of suid routine calculated in wrong security context. sql/item_func.cc: Do not change security context before executing the function, as it will be changed after argument evaluation. Do not change security context in Item_func_sp::find_and_check_access(). sql/item_func.h: Change prototype for Item_func_sp::find_and_check_access(). sql/sp_head.cc: Add set_routine_security_ctx() function. Add sp_head::execute_trigger() method. Change security context in sp_head::execute_trigger(), and in sp_head::execute_function() and sp_head::execute_procedure() after argument evaluation. Move pop_all_cursors() call to sp_head::execute(). sql/sp_head.h: Add declaration for sp_head::execute_trigger() and set_routine_security_ctx(). sql/sql_parse.cc: Do not change security context before executing the procedure, as it will be changed after argument evaluation. sql/sql_trigger.cc: Call new sp_head::execute_trigger() instead of sp_head::execute_function(), which is responsible to switch security context. --- mysql-test/r/sp-security.result | 52 +++++++++++ mysql-test/t/sp-security.test | 78 ++++++++++++++++- sql/item_func.cc | 84 ++++++------------ sql/item_func.h | 3 +- sql/sp_head.cc | 190 +++++++++++++++++++++++++++++++++++++++- sql/sp_head.h | 8 ++ sql/sql_parse.cc | 18 +--- sql/sql_trigger.cc | 35 +------- 8 files changed, 356 insertions(+), 112 deletions(-) diff --git a/mysql-test/r/sp-security.result b/mysql-test/r/sp-security.result index a53b4c4d246..1198efc4f3b 100644 --- a/mysql-test/r/sp-security.result +++ b/mysql-test/r/sp-security.result @@ -451,3 +451,55 @@ SELECT Host,User,Password FROM mysql.user WHERE User='user19857'; Host User Password localhost user19857 *82DC221D557298F6CE9961037DB1C90604792F5C DROP USER user19857@localhost; +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; +DROP FUNCTION IF EXISTS f_suid; +DROP PROCEDURE IF EXISTS p_suid; +DROP FUNCTION IF EXISTS f_evil; +DELETE FROM mysql.user WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.db WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.tables_priv WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.columns_priv WHERE user LIKE 'mysqltest\_%'; +FLUSH PRIVILEGES; +CREATE TABLE t1 (i INT); +CREATE FUNCTION f_suid(i INT) RETURNS INT SQL SECURITY DEFINER RETURN 0; +CREATE PROCEDURE p_suid(IN i INT) SQL SECURITY DEFINER SET @c:= 0; +CREATE USER mysqltest_u1@localhost; +GRANT EXECUTE ON test.* TO mysqltest_u1@localhost; +CREATE DEFINER=mysqltest_u1@localhost FUNCTION f_evil () RETURNS INT +SQL SECURITY INVOKER +BEGIN +SET @a:= CURRENT_USER(); +SET @b:= (SELECT COUNT(*) FROM t1); +RETURN @b; +END| +CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT f_evil(); +SELECT COUNT(*) FROM t1; +ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1' +SELECT f_evil(); +ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1' +SELECT @a, @b; +@a @b +mysqltest_u1@localhost NULL +SELECT f_suid(f_evil()); +ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1' +SELECT @a, @b; +@a @b +mysqltest_u1@localhost NULL +CALL p_suid(f_evil()); +ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1' +SELECT @a, @b; +@a @b +mysqltest_u1@localhost NULL +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 'v1' +SELECT @a, @b; +@a @b +mysqltest_u1@localhost NULL +DROP VIEW v1; +DROP FUNCTION f_evil; +DROP USER mysqltest_u1@localhost; +DROP PROCEDURE p_suid; +DROP FUNCTION f_suid; +DROP TABLE t1; +End of 5.0 tests. diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test index d323b180216..a5d509f29b7 100644 --- a/mysql-test/t/sp-security.test +++ b/mysql-test/t/sp-security.test @@ -790,4 +790,80 @@ SELECT Host,User,Password FROM mysql.user WHERE User='user19857'; DROP USER user19857@localhost; -# End of 5.0 bugs. +--disconnect con1root +--connection default + + +# +# BUG#18630: Arguments of suid routine calculated in wrong security +# context +# +# Arguments of suid routines were calculated in definer's security +# context instead of caller's context thus creating security hole. +# +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; +DROP FUNCTION IF EXISTS f_suid; +DROP PROCEDURE IF EXISTS p_suid; +DROP FUNCTION IF EXISTS f_evil; +--enable_warnings +DELETE FROM mysql.user WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.db WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.tables_priv WHERE user LIKE 'mysqltest\_%'; +DELETE FROM mysql.columns_priv WHERE user LIKE 'mysqltest\_%'; +FLUSH PRIVILEGES; + +CREATE TABLE t1 (i INT); +CREATE FUNCTION f_suid(i INT) RETURNS INT SQL SECURITY DEFINER RETURN 0; +CREATE PROCEDURE p_suid(IN i INT) SQL SECURITY DEFINER SET @c:= 0; + +CREATE USER mysqltest_u1@localhost; +# Thanks to this grant statement privileges of anonymous users on +# 'test' database are not applicable for mysqltest_u1@localhost. +GRANT EXECUTE ON test.* TO mysqltest_u1@localhost; + +delimiter |; +CREATE DEFINER=mysqltest_u1@localhost FUNCTION f_evil () RETURNS INT + SQL SECURITY INVOKER +BEGIN + SET @a:= CURRENT_USER(); + SET @b:= (SELECT COUNT(*) FROM t1); + RETURN @b; +END| +delimiter ;| + +CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT f_evil(); + +connect (conn1, localhost, mysqltest_u1,,); + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT COUNT(*) FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT f_evil(); +SELECT @a, @b; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT f_suid(f_evil()); +SELECT @a, @b; + +--error ER_TABLEACCESS_DENIED_ERROR +CALL p_suid(f_evil()); +SELECT @a, @b; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +SELECT @a, @b; + +disconnect conn1; +connection default; + +DROP VIEW v1; +DROP FUNCTION f_evil; +DROP USER mysqltest_u1@localhost; +DROP PROCEDURE p_suid; +DROP FUNCTION f_suid; +DROP TABLE t1; + +--echo End of 5.0 tests. diff --git a/sql/item_func.cc b/sql/item_func.cc index 194d62b1183..57d3b0ac5f3 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4832,7 +4832,9 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld) { bool err_status= TRUE; Sub_statement_state statement_state; - Security_context *save_security_ctx= thd->security_ctx, *save_ctx_func; +#ifndef NO_EMBEDDED_ACCESS_CHECKS + Security_context *save_security_ctx= thd->security_ctx; +#endif DBUG_ENTER("Item_func_sp::execute_impl"); @@ -4843,7 +4845,7 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld) thd->security_ctx= context->security_ctx; } #endif - if (find_and_check_access(thd, EXECUTE_ACL, &save_ctx_func)) + if (find_and_check_access(thd)) goto error; /* @@ -4855,13 +4857,11 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld) err_status= m_sp->execute_function(thd, args, arg_count, return_value_fld); thd->restore_sub_statement_state(&statement_state); -#ifndef NO_EMBEDDED_ACCESS_CHECKS - sp_restore_security_context(thd, save_ctx_func); error: +#ifndef NO_EMBEDDED_ACCESS_CHECKS thd->security_ctx= save_security_ctx; -#else -error: #endif + DBUG_RETURN(err_status); } @@ -4978,70 +4978,38 @@ Item_func_sp::tmp_table_field(TABLE *t_arg) SYNOPSIS find_and_check_access() thd thread handler - want_access requested access - save backup of security context RETURN FALSE Access granted TRUE Requested access can't be granted or function doesn't exists - In this case security context is not changed and *save = 0 NOTES Checks if requested access to function can be granted to user. If function isn't found yet, it searches function first. If function can't be found or user don't have requested access error is raised. - If security context sp_ctx is provided and access can be granted then - switch back to previous context isn't performed. - In case of access error or if context is not provided then - find_and_check_access() switches back to previous security context. */ bool -Item_func_sp::find_and_check_access(THD *thd, ulong want_access, - Security_context **save) +Item_func_sp::find_and_check_access(THD *thd) { - bool res= TRUE; - - *save= 0; // Safety if error if (! m_sp && ! (m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name, &thd->sp_func_cache, TRUE))) { my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str); - goto error; + return TRUE; } #ifndef NO_EMBEDDED_ACCESS_CHECKS - if (check_routine_access(thd, want_access, - m_sp->m_db.str, m_sp->m_name.str, 0, FALSE)) - goto error; - - sp_change_security_context(thd, m_sp, save); - /* - If we changed context to run as another user, we need to check the - access right for the new context again as someone may have deleted - this person the right to use the procedure - - TODO: - Cache if the definer has the right to use the object on the first - usage and only reset the cache if someone does a GRANT statement - that 'may' affect this. - */ - if (*save && - check_routine_access(thd, want_access, + if (check_routine_access(thd, EXECUTE_ACL, m_sp->m_db.str, m_sp->m_name.str, 0, FALSE)) - { - sp_restore_security_context(thd, *save); - *save= 0; // Safety - goto error; - } + return TRUE; #endif - res= FALSE; // no error -error: - return res; + return FALSE; } + bool Item_func_sp::fix_fields(THD *thd, Item **ref) { @@ -5052,19 +5020,23 @@ Item_func_sp::fix_fields(THD *thd, Item **ref) { /* Here we check privileges of the stored routine only during view - creation, in order to validate the view. A runtime check is perfomed - in Item_func_sp::execute(), and this method is not called during - context analysis. We do not need to restore the security context - changed in find_and_check_access because all view structures created - in CREATE VIEW are not used for execution. Notice, that during view - creation we do not infer into stored routine bodies and do not check - privileges of its statements, which would probably be a good idea - especially if the view has SQL SECURITY DEFINER and the used stored - procedure has SQL SECURITY DEFINER + creation, in order to validate the view. A runtime check is + perfomed in Item_func_sp::execute(), and this method is not + called during context analysis. Notice, that during view + creation we do not infer into stored routine bodies and do not + check privileges of its statements, which would probably be a + good idea especially if the view has SQL SECURITY DEFINER and + the used stored procedure has SQL SECURITY DEFINER. */ - Security_context *save_ctx; - if (!(res= find_and_check_access(thd, EXECUTE_ACL, &save_ctx))) - sp_restore_security_context(thd, save_ctx); + res= find_and_check_access(thd); +#ifndef NO_EMBEDDED_ACCESS_CHECKS + Security_context *save_secutiry_ctx; + if (!res && !(res= set_routine_security_ctx(thd, m_sp, false, + &save_secutiry_ctx))) + { + sp_restore_security_context(thd, save_secutiry_ctx); + } +#endif /* ! NO_EMBEDDED_ACCESS_CHECKS */ } return res; } diff --git a/sql/item_func.h b/sql/item_func.h index 1d8a1bd5e22..f70becb79fc 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1465,8 +1465,7 @@ public: { context= (Name_resolution_context *)cntx; return FALSE; } void fix_length_and_dec(); - bool find_and_check_access(THD * thd, ulong want_access, - Security_context **backup); + bool find_and_check_access(THD * thd); virtual enum Functype functype() const { return FUNC_SP; } bool fix_fields(THD *thd, Item **ref); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 9965c48935a..e39efd78d7e 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1097,6 +1097,7 @@ sp_head::execute(THD *thd) thd->restore_active_arena(&execute_arena, &backup_arena); + thd->spcont->pop_all_cursors(); // To avoid memory leaks after an error /* Restore all saved */ old_packet.swap(thd->packet); @@ -1158,6 +1159,161 @@ sp_head::execute(THD *thd) m_first_instance->m_first_free_instance->m_recursion_level == m_recursion_level + 1)); m_first_instance->m_first_free_instance= this; + + DBUG_RETURN(err_status); +} + + +#ifndef NO_EMBEDDED_ACCESS_CHECKS +/* + set_routine_security_ctx() changes routine security context, and + checks if there is an EXECUTE privilege in new context. If there is + no EXECUTE privilege, it changes the context back and returns a + error. + + SYNOPSIS + set_routine_security_ctx() + thd thread handle + sp stored routine to change the context for + is_proc TRUE is procedure, FALSE if function + save_ctx pointer to an old security context + + RETURN + TRUE if there was a error, and the context wasn't changed. + FALSE if the context was changed. +*/ + +bool +set_routine_security_ctx(THD *thd, sp_head *sp, bool is_proc, + Security_context **save_ctx) +{ + *save_ctx= 0; + if (sp_change_security_context(thd, sp, save_ctx)) + return TRUE; + + /* + If we changed context to run as another user, we need to check the + access right for the new context again as someone may have revoked + the right to use the procedure from this user. + + TODO: + Cache if the definer has the right to use the object on the + first usage and only reset the cache if someone does a GRANT + statement that 'may' affect this. + */ + if (*save_ctx && + check_routine_access(thd, EXECUTE_ACL, + sp->m_db.str, sp->m_name.str, is_proc, FALSE)) + { + sp_restore_security_context(thd, *save_ctx); + *save_ctx= 0; + return TRUE; + } + + return FALSE; +} +#endif // ! NO_EMBEDDED_ACCESS_CHECKS + + +/* + Execute a trigger: + - changes security context for triggers + - switch to new memroot + - call sp_head::execute + - restore old memroot + - restores security context + + SYNOPSIS + sp_head::execute_trigger() + thd Thread handle + db database name + table table name + grant_info GRANT_INFO structure to be filled with + information about definer's privileges + on subject table + + RETURN + FALSE on success + TRUE on error +*/ + +bool +sp_head::execute_trigger(THD *thd, const char *db, const char *table, + GRANT_INFO *grant_info) +{ + sp_rcontext *octx = thd->spcont; + sp_rcontext *nctx = NULL; + bool err_status= FALSE; + MEM_ROOT call_mem_root; + Query_arena call_arena(&call_mem_root, Query_arena::INITIALIZED_FOR_SP); + Query_arena backup_arena; + + DBUG_ENTER("sp_head::execute_trigger"); + DBUG_PRINT("info", ("trigger %s", m_name.str)); + +#ifndef NO_EMBEDDED_ACCESS_CHECKS + Security_context *save_ctx; + if (sp_change_security_context(thd, this, &save_ctx)) + DBUG_RETURN(TRUE); + + /* + NOTE: TRIGGER_ACL should be used here. + */ + if (check_global_access(thd, SUPER_ACL)) + { + sp_restore_security_context(thd, save_ctx); + DBUG_RETURN(TRUE); + } + + /* + Fetch information about table-level privileges to GRANT_INFO + structure for subject table. Check of privileges that will use it + and information about column-level privileges will happen in + Item_trigger_field::fix_fields(). + */ + fill_effective_table_privileges(thd, grant_info, db, table); +#endif // NO_EMBEDDED_ACCESS_CHECKS + + /* + Prepare arena and memroot for objects which lifetime is whole + duration of trigger call (sp_rcontext, it's tables and items, + sp_cursor and Item_cache holders for case expressions). We can't + use caller's arena/memroot for those objects because in this case + some fixed amount of memory will be consumed for each trigger + invocation and so statements which involve lot of them will hog + memory. + + TODO: we should create sp_rcontext once per command and reuse it + on subsequent executions of a trigger. + */ + init_sql_alloc(&call_mem_root, MEM_ROOT_BLOCK_SIZE, 0); + thd->set_n_backup_active_arena(&call_arena, &backup_arena); + + if (!(nctx= new sp_rcontext(m_pcont, 0, octx)) || + nctx->init(thd)) + { + err_status= TRUE; + goto err_with_cleanup; + } + +#ifndef DBUG_OFF + nctx->sp= this; +#endif + + thd->spcont= nctx; + + err_status= execute(thd); + +err_with_cleanup: + thd->restore_active_arena(&call_arena, &backup_arena); +#ifndef NO_EMBEDDED_ACCESS_CHECKS + sp_restore_security_context(thd, save_ctx); +#endif // NO_EMBEDDED_ACCESS_CHECKS + delete nctx; + call_arena.free_items(); + free_root(&call_mem_root, MYF(0)); + thd->spcont= octx; + DBUG_RETURN(err_status); } @@ -1165,8 +1321,12 @@ sp_head::execute(THD *thd) /* Execute a function: - evaluate parameters + - changes security context for SUID routines + - switch to new memroot - call sp_head::execute + - restore old memroot - evaluate the return value + - restores security context SYNOPSIS sp_head::execute_function() @@ -1293,6 +1453,15 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, } thd->spcont= nctx; +#ifndef NO_EMBEDDED_ACCESS_CHECKS + Security_context *save_security_ctx; + if (set_routine_security_ctx(thd, this, FALSE, &save_security_ctx)) + { + err_status= TRUE; + goto err_with_cleanup; + } +#endif + binlog_save_options= thd->options; if (need_binlog_call) { @@ -1333,7 +1502,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, reset_dynamic(&thd->user_var_events); } - if (m_type == TYPE_ENUM_FUNCTION && !err_status) + if (!err_status) { /* We need result only in function but not in trigger */ @@ -1344,8 +1513,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, } } - - nctx->pop_all_cursors(); // To avoid memory leaks after an error +#ifndef NO_EMBEDDED_ACCESS_CHECKS + sp_restore_security_context(thd, save_security_ctx); +#endif err_with_cleanup: delete nctx; @@ -1368,8 +1538,10 @@ err_with_cleanup: The function does the following steps: - Set all parameters + - changes security context for SUID routines - call sp_head::execute - copy back values of INOUT and OUT parameters + - restores security context RETURN FALSE on success @@ -1490,6 +1662,12 @@ sp_head::execute_procedure(THD *thd, List *args) thd->spcont= nctx; +#ifndef NO_EMBEDDED_ACCESS_CHECKS + Security_context *save_security_ctx= 0; + if (!err_status) + err_status= set_routine_security_ctx(thd, this, TRUE, &save_security_ctx); +#endif + if (!err_status) err_status= execute(thd); @@ -1534,10 +1712,14 @@ sp_head::execute_procedure(THD *thd, List *args) } } +#ifndef NO_EMBEDDED_ACCESS_CHECKS + if (save_security_ctx) + sp_restore_security_context(thd, save_security_ctx); +#endif + if (!save_spcont) delete octx; - nctx->pop_all_cursors(); // To avoid memory leaks after an error delete nctx; thd->spcont= save_spcont; diff --git a/sql/sp_head.h b/sql/sp_head.h index 073cca2cd12..36747716bdc 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -206,6 +206,10 @@ public: void destroy(); + bool + execute_trigger(THD *thd, const char *db, const char *table, + GRANT_INFO *grant_onfo); + bool execute_function(THD *thd, Item **args, uint argcount, Field *return_fld); @@ -1149,6 +1153,10 @@ sp_change_security_context(THD *thd, sp_head *sp, Security_context **backup); void sp_restore_security_context(THD *thd, Security_context *backup); + +bool +set_routine_security_ctx(THD *thd, sp_head *sp, bool is_proc, + Security_context **save_ctx); #endif /* NO_EMBEDDED_ACCESS_CHECKS */ TABLE_LIST * diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index cd57c280950..9a3b1e1234e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4383,9 +4383,6 @@ end_with_restore_list: } else { -#ifndef NO_EMBEDDED_ACCESS_CHECKS - Security_context *save_ctx; -#endif ha_rows select_limit; /* bits that should be cleared in thd->server_status */ uint bits_to_be_cleared= 0; @@ -4427,21 +4424,11 @@ end_with_restore_list: #ifndef NO_EMBEDDED_ACCESS_CHECKS if (check_routine_access(thd, EXECUTE_ACL, - sp->m_db.str, sp->m_name.str, TRUE, 0) || - sp_change_security_context(thd, sp, &save_ctx)) + sp->m_db.str, sp->m_name.str, TRUE, FALSE)) { thd->net.no_send_ok= nsok; goto error; } - if (save_ctx && - check_routine_access(thd, EXECUTE_ACL, - sp->m_db.str, sp->m_name.str, TRUE, 0)) - { - thd->net.no_send_ok= nsok; - sp_restore_security_context(thd, save_ctx); - goto error; - } - #endif select_limit= thd->variables.select_limit; thd->variables.select_limit= HA_POS_ERROR; @@ -4465,9 +4452,6 @@ end_with_restore_list: thd->total_warn_count= 0; thd->variables.select_limit= select_limit; -#ifndef NO_EMBEDDED_ACCESS_CHECKS - sp_restore_security_context(thd, save_ctx); -#endif thd->net.no_send_ok= nsok; thd->server_status&= ~bits_to_be_cleared; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 28d7dc0bb9d..6effa6e0644 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1495,40 +1495,11 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event, old_field= table->field; } -#ifndef NO_EMBEDDED_ACCESS_CHECKS - Security_context *save_ctx; - - if (sp_change_security_context(thd, sp_trigger, &save_ctx)) - return TRUE; - - /* - NOTE: TRIGGER_ACL should be used below. - */ - - if (check_global_access(thd, SUPER_ACL)) - { - sp_restore_security_context(thd, save_ctx); - return TRUE; - } - - /* - Fetch information about table-level privileges to GRANT_INFO structure for - subject table. Check of privileges that will use it and information about - column-level privileges will happen in Item_trigger_field::fix_fields(). - */ - - fill_effective_table_privileges(thd, - &subject_table_grants[event][time_type], - table->s->db, table->s->table_name); -#endif // NO_EMBEDDED_ACCESS_CHECKS - thd->reset_sub_statement_state(&statement_state, SUB_STMT_TRIGGER); - err_status= sp_trigger->execute_function(thd, 0, 0, 0); + err_status= sp_trigger->execute_trigger + (thd, table->s->db, table->s->table_name, + &subject_table_grants[event][time_type]); thd->restore_sub_statement_state(&statement_state); - -#ifndef NO_EMBEDDED_ACCESS_CHECKS - sp_restore_security_context(thd, save_ctx); -#endif // NO_EMBEDDED_ACCESS_CHECKS } return err_status; -- cgit v1.2.1 From ca00a985a1e3df3e2fe71e0eec125fdcfa09f1a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 17 Jul 2006 14:48:40 +0400 Subject: Bug#21013: Performance Degrades when importing data that uses Trigger and Stored Procedure The essence of the bug was that for every re-execution of stored routine or prepared statement new items for character set conversions were created, thus increasing the number of items and the time of their processing, and creating memory leak. No test case is provided since current test suite can't cover such type of bugs. mysql-test/r/sp.result: Add result for bug#21013: Performance Degrades when importing data that uses Trigger and Stored Procedure. mysql-test/t/sp.test: Add test case for bug#21013: Performance Degrades when importing data that uses Trigger and Stored Procedure. sql/item.cc: Switch arena only when in statement prepare mode. Subsequent executions will use cached item tree. --- mysql-test/r/sp.result | 12 ++++++++++++ mysql-test/t/sp.test | 27 +++++++++++++++++++++++++++ sql/item.cc | 5 +++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 96bf2f01f86..10556bf31a2 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5057,4 +5057,16 @@ concat('data was: /', var1, '/') data was: /1/ drop table t3| drop procedure bug15217| +DROP PROCEDURE IF EXISTS bug21013 | +CREATE PROCEDURE bug21013(IN lim INT) +BEGIN +DECLARE i INT DEFAULT 0; +WHILE (i < lim) DO +SET @b = LOCATE(_latin1'b', @a, 1); +SET i = i + 1; +END WHILE; +END | +SET @a = _latin2"aaaaaaaaaa" | +CALL bug21013(10) | +DROP PROCEDURE bug21013 | drop table t1,t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 25c96042e6f..41da4eb9222 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5962,6 +5962,33 @@ call bug15217()| drop table t3| drop procedure bug15217| + +# +# BUG#21013: Performance Degrades when importing data that uses +# Trigger and Stored Procedure +# +# This is a performance and memory leak test. Run with large number +# passed to bug21013() procedure. +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug21013 | +--enable_warnings + +CREATE PROCEDURE bug21013(IN lim INT) +BEGIN + DECLARE i INT DEFAULT 0; + WHILE (i < lim) DO + SET @b = LOCATE(_latin1'b', @a, 1); + SET i = i + 1; + END WHILE; +END | + +SET @a = _latin2"aaaaaaaaaa" | +CALL bug21013(10) | + +DROP PROCEDURE bug21013 | + + # # BUG#NNNN: New bug synopsis # diff --git a/sql/item.cc b/sql/item.cc index 511ea1ffb44..db8a2985cca 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1418,7 +1418,8 @@ bool agg_item_charsets(DTCollation &coll, const char *fname, In case we're in statement prepare, create conversion item in its memory: it will be reused on each execute. */ - arena= thd->activate_stmt_arena_if_needed(&backup); + arena= thd->is_stmt_prepare() ? thd->activate_stmt_arena_if_needed(&backup) + : NULL; for (i= 0, arg= args; i < nargs; i++, arg+= item_sep) { @@ -1453,7 +1454,7 @@ bool agg_item_charsets(DTCollation &coll, const char *fname, been created in prepare. In this case register the change for rollback. */ - if (arena && arena->is_conventional()) + if (arena) *arg= conv; else thd->change_item_tree(arg, conv); -- cgit v1.2.1 From 6ec7976df97d5c9ced3f2e50339c74f19cda32fd Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Jul 2006 12:36:55 -0700 Subject: Fixed bug #17526: incorrect print method for class Item_func_trim. For 4.1 it caused wrong output for EXPLAIN EXTENDED commands if expressions with the TRIM function of two arguments were used. For 5.0 it caused an error message when trying to select from a view with the TRIM function of two arguments. This unexpected error message was due to the fact that the print method for the class Item_func_trim was inherited from the class Item_func. Yet the TRIM function does not take a list of its arguments. Rather it takes the arguments in the form: [{BOTH | LEADING | TRAILING} [remstr] FROM] str) | [remstr FROM] str mysql-test/r/func_str.result: Added a test case for bug #17526: uncorrect print method for class Item_func_trim. mysql-test/t/func_str.test: Added a test case for bug #17526: incorrect print method for class Item_func_trim. sql/item_strfunc.cc: Fixed bug #17526: incorrect print method for class Item_func_trim. Added an implementation for the virtual function print in the class Item_func_trim. The implementation takes into account the fact the TRIM function takes the arguments in the following forms: [{BOTH | LEADING | TRAILING} [remstr] FROM] str) | [remstr FROM] str sql/item_strfunc.h: Fixed bug #17526: incorrect print method for class Item_func_trim. Added an implementation for the virtual function print in the class Item_func_trim. Declared a virtual method to return the mode of the TRIM function: LEADING, TRAILING or BOTH. Added implementations of this method for Item_func_trim and its descendants Item_func_ltrim and Item_func_rtrim. --- mysql-test/r/func_str.result | 28 ++++++++++++++++++++++++++++ mysql-test/t/func_str.test | 15 +++++++++++++++ sql/item_strfunc.cc | 17 +++++++++++++++++ sql/item_strfunc.h | 4 ++++ 4 files changed, 64 insertions(+) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 61a77c211d7..2c15e5581e8 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -1036,4 +1036,32 @@ a c abc abc abc xyz xyz xyz DROP TABLE t1; +CREATE TABLE t1 (s varchar(10)); +INSERT INTO t1 VALUES ('yadda'), ('yaddy'); +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(s) > 'ab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +Warnings: +Note 1003 select test.t1.s AS `s` from test.t1 where (trim(test.t1.s) > _latin1'ab') +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM('y' FROM s) > 'ab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +Warnings: +Note 1003 select test.t1.s AS `s` from test.t1 where (trim(both _latin1'y' from test.t1.s) > _latin1'ab') +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(LEADING 'y' FROM s) > 'ab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +Warnings: +Note 1003 select test.t1.s AS `s` from test.t1 where (trim(leading _latin1'y' from test.t1.s) > _latin1'ab') +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(TRAILING 'y' FROM s) > 'ab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +Warnings: +Note 1003 select test.t1.s AS `s` from test.t1 where (trim(trailing _latin1'y' from test.t1.s) > _latin1'ab') +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +Warnings: +Note 1003 select test.t1.s AS `s` from test.t1 where (trim(both _latin1'y' from test.t1.s) > _latin1'ab') +DROP TABLE t1; End of 4.1 tests diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 9a1c75a8dc0..3c855a32eed 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -697,5 +697,20 @@ SELECT a, CONCAT(a,' ',a) AS c FROM t1 INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a; DROP TABLE t1; + +# +# Bug#17526: WRONG PRINT for TRIM FUNCTION with two arguments +# + +CREATE TABLE t1 (s varchar(10)); +INSERT INTO t1 VALUES ('yadda'), ('yaddy'); + +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(s) > 'ab'; +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM('y' FROM s) > 'ab'; +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(LEADING 'y' FROM s) > 'ab'; +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(TRAILING 'y' FROM s) > 'ab'; +EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab'; + +DROP TABLE t1; --echo End of 4.1 tests diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 7bc7956283b..1c5b947cb2b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1444,6 +1444,23 @@ void Item_func_trim::fix_length_and_dec() } } +void Item_func_trim::print(String *str) +{ + if (arg_count == 1) + { + Item_func::print(str); + return; + } + str->append(Item_func_trim::func_name()); + str->append('('); + str->append(mode_name()); + str->append(' '); + args[1]->print(str); + str->append(" from ",6); + args[0]->print(str); + str->append(')'); +} + /* Item_func_password */ diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index f800c17182b..880a19242ca 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -218,6 +218,8 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "trim"; } + void print(String *str); + virtual const char *mode_name() const { return "both"; } }; @@ -228,6 +230,7 @@ public: Item_func_ltrim(Item *a) :Item_func_trim(a) {} String *val_str(String *); const char *func_name() const { return "ltrim"; } + const char *mode_name() const { return "leading"; } }; @@ -238,6 +241,7 @@ public: Item_func_rtrim(Item *a) :Item_func_trim(a) {} String *val_str(String *); const char *func_name() const { return "rtrim"; } + const char *mode_name() const { return "trailing"; } }; -- cgit v1.2.1 From f8dda7bfb928c0eaee550db57f5288e0575ea378 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Jul 2006 16:42:19 -0700 Subject: Added a test case with views for bug #17526. mysql-test/r/func_str.result: Adjusted results for the test case of bug 17526. sql/item_strfunc.cc: Post-merge modification --- mysql-test/r/func_str.result | 10 +++++----- mysql-test/r/view.result | 33 +++++++++++++++++++++++++++++++++ mysql-test/t/view.test | 24 ++++++++++++++++++++++++ sql/item_strfunc.cc | 2 +- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index ae62010f118..a857f5055a2 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -1059,27 +1059,27 @@ EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(s) > 'ab'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where Warnings: -Note 1003 select test.t1.s AS `s` from test.t1 where (trim(test.t1.s) > _latin1'ab') +Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(`test`.`t1`.`s`) > _latin1'ab') EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM('y' FROM s) > 'ab'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where Warnings: -Note 1003 select test.t1.s AS `s` from test.t1 where (trim(both _latin1'y' from test.t1.s) > _latin1'ab') +Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(both _latin1'y' from `test`.`t1`.`s`) > _latin1'ab') EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(LEADING 'y' FROM s) > 'ab'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where Warnings: -Note 1003 select test.t1.s AS `s` from test.t1 where (trim(leading _latin1'y' from test.t1.s) > _latin1'ab') +Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(leading _latin1'y' from `test`.`t1`.`s`) > _latin1'ab') EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(TRAILING 'y' FROM s) > 'ab'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where Warnings: -Note 1003 select test.t1.s AS `s` from test.t1 where (trim(trailing _latin1'y' from test.t1.s) > _latin1'ab') +Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(trailing _latin1'y' from `test`.`t1`.`s`) > _latin1'ab') EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where Warnings: -Note 1003 select test.t1.s AS `s` from test.t1 where (trim(both _latin1'y' from test.t1.s) > _latin1'ab') +Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(both _latin1'y' from `test`.`t1`.`s`) > _latin1'ab') DROP TABLE t1; End of 4.1 tests create table t1 (d decimal default null); diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 7d2ab63ca77..c8a673e2209 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2774,3 +2774,36 @@ Field Type Null Key Default Extra COALESCE(i,j) int(11) YES NULL DROP VIEW v1; DROP TABLE t1,t2; +CREATE TABLE t1 (s varchar(10)); +INSERT INTO t1 VALUES ('yadda'), ('yady'); +SELECT TRIM(BOTH 'y' FROM s) FROM t1; +TRIM(BOTH 'y' FROM s) +adda +ad +CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1; +SELECT * FROM v1; +TRIM(BOTH 'y' FROM s) +adda +ad +DROP VIEW v1; +SELECT TRIM(LEADING 'y' FROM s) FROM t1; +TRIM(LEADING 'y' FROM s) +adda +ady +CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1; +SELECT * FROM v1; +TRIM(LEADING 'y' FROM s) +adda +ady +DROP VIEW v1; +SELECT TRIM(TRAILING 'y' FROM s) FROM t1; +TRIM(TRAILING 'y' FROM s) +yadda +yad +CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1; +SELECT * FROM v1; +TRIM(TRAILING 'y' FROM s) +yadda +yad +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 88a4d489039..6399cef9086 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2643,3 +2643,27 @@ DESCRIBE t2; DROP VIEW v1; DROP TABLE t1,t2; + +# +# Bug #17526: views with TRIM functions +# + +CREATE TABLE t1 (s varchar(10)); +INSERT INTO t1 VALUES ('yadda'), ('yady'); + +SELECT TRIM(BOTH 'y' FROM s) FROM t1; +CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1; +SELECT * FROM v1; +DROP VIEW v1; + +SELECT TRIM(LEADING 'y' FROM s) FROM t1; +CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1; +SELECT * FROM v1; +DROP VIEW v1; + +SELECT TRIM(TRAILING 'y' FROM s) FROM t1; +CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1; +SELECT * FROM v1; +DROP VIEW v1; + +DROP TABLE t1; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 7289c17f996..58ddb331b2e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1515,7 +1515,7 @@ void Item_func_trim::print(String *str) str->append(mode_name()); str->append(' '); args[1]->print(str); - str->append(" from ",6); + str->append(STRING_WITH_LEN(" from ")); args[0]->print(str); str->append(')'); } -- cgit v1.2.1 From d8180d44b81519ee1d1db8fe79caa2a6d1d6a5eb Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 20 Jul 2006 13:24:12 +0400 Subject: Fix for BUG#20716: SHOW INSTANCES statement causes races in IM tests. Fix for the bug in mysql-test-run.pl which prevents other tests succeed after IM-test failure. The idea of the fix of BUG#20716 is to: 1. Check each SHOW INSTANCES statement, add necessary "sleep" instruction before; 2. Move all environment checkings into the one file and include it everywhere. mysql-test/mysql-test-run.pl: Fix bug in mysql-test-run.pl -- kill leftovers if some guarded mysqld-instance is still alive after IM shutdown. mysql-test/r/im_daemon_life_cycle.result: Updated result file. mysql-test/r/im_life_cycle.result: Updated result file. mysql-test/r/im_options_set.result: Updated result file. mysql-test/r/im_options_unset.result: Updated result file. mysql-test/r/im_utils.result: Updated result file. mysql-test/t/im_daemon_life_cycle.imtest: Include im_check_env.inc for the checking of environment. mysql-test/t/im_life_cycle.imtest: Include im_check_env.inc for the checking of environment. mysql-test/t/im_options_set.imtest: Include im_check_env.inc for the checking of environment. mysql-test/t/im_options_unset.imtest: Include im_check_env.inc for the checking of environment. mysql-test/t/im_utils.imtest: Include im_check_env.inc for the checking of environment. mysql-test/include/im_check_env.inc: A new file to be included in each IM-test. The statements in the file ensure that starting conditions (environment) are as expected. --- mysql-test/include/im_check_env.inc | 27 +++++++++++++ mysql-test/mysql-test-run.pl | 22 +++++++++++ mysql-test/r/im_daemon_life_cycle.result | 3 ++ mysql-test/r/im_life_cycle.result | 11 ++---- mysql-test/r/im_options_set.result | 7 +++- mysql-test/r/im_options_unset.result | 7 +++- mysql-test/r/im_utils.result | 3 ++ mysql-test/t/im_daemon_life_cycle.imtest | 16 +------- mysql-test/t/im_life_cycle.imtest | 66 ++++++++++---------------------- mysql-test/t/im_options_set.imtest | 27 +------------ mysql-test/t/im_options_unset.imtest | 27 +------------ mysql-test/t/im_utils.imtest | 31 +++------------ 12 files changed, 98 insertions(+), 149 deletions(-) create mode 100644 mysql-test/include/im_check_env.inc diff --git a/mysql-test/include/im_check_env.inc b/mysql-test/include/im_check_env.inc new file mode 100644 index 00000000000..169edbac6b3 --- /dev/null +++ b/mysql-test/include/im_check_env.inc @@ -0,0 +1,27 @@ +# This file is intended to be used in each IM-test. It contains stamements, +# that ensure that starting conditions (environment) for the IM-test are as +# expected. + +# Wait for mysqld1 (guarded instance) to start. + +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started + +# Check the running instances. + +--connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) + +--connection mysql1_con + +SHOW VARIABLES LIKE 'server_id'; + +--connection default + +# Let IM detect that mysqld1 is online. This delay should be longer than +# monitoring interval. + +--sleep 2 + +# Check that IM understands that mysqld1 is online, while mysqld2 is +# offline. + +SHOW INSTANCES; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 14bd9b198a2..5a7609a55fb 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2898,12 +2898,16 @@ sub im_stop($) { while (1) { + # Check that IM-main died. + if (kill (0, $instance_manager->{'pid'})) { mtr_debug("IM-main is still alive."); last; } + # Check that IM-angel died. + if (defined $instance_manager->{'angel_pid'} && kill (0, $instance_manager->{'angel_pid'})) { @@ -2911,21 +2915,39 @@ sub im_stop($) { last; } + # Check that all guarded mysqld-instances died. + + my $guarded_mysqlds_dead= 1; + foreach my $pid (@mysqld_pids) { if (kill (0, $pid)) { mtr_debug("Guarded mysqld ($pid) is still alive."); + $guarded_mysqlds_dead= 0; last; } } + last unless $guarded_mysqlds_dead; + + # Ok, all necessary processes are dead. + $clean_shutdown= 1; last; } # Kill leftovers (the order is important). + if ($clean_shutdown) + { + mtr_debug("IM-shutdown was clean -- all processed died."); + } + else + { + mtr_debug("IM failed to shutdown gracefully. We have to clean the mess..."); + } + unless ($clean_shutdown) { diff --git a/mysql-test/r/im_daemon_life_cycle.result b/mysql-test/r/im_daemon_life_cycle.result index ea27fcb6db1..4f7dd77a88f 100644 --- a/mysql-test/r/im_daemon_life_cycle.result +++ b/mysql-test/r/im_daemon_life_cycle.result @@ -1,4 +1,7 @@ Success: the process has been started. +SHOW VARIABLES LIKE 'server_id'; +Variable_name Value +server_id 1 SHOW INSTANCES; instance_name status mysqld1 online diff --git a/mysql-test/r/im_life_cycle.result b/mysql-test/r/im_life_cycle.result index a9f78aea7d3..8394ec491e5 100644 --- a/mysql-test/r/im_life_cycle.result +++ b/mysql-test/r/im_life_cycle.result @@ -1,8 +1,7 @@ - --------------------------------------------------------------------- --- 1.1.1. --------------------------------------------------------------------- Success: the process has been started. +SHOW VARIABLES LIKE 'server_id'; +Variable_name Value +server_id 1 SHOW INSTANCES; instance_name status mysqld1 online @@ -40,10 +39,6 @@ ERROR HY000: Bad instance name. Check that the instance with such a name exists -------------------------------------------------------------------- -- 1.1.6. -------------------------------------------------------------------- -SHOW INSTANCES; -instance_name status -mysqld1 online -mysqld2 offline Killing the process... Sleeping... Success: the process was restarted. diff --git a/mysql-test/r/im_options_set.result b/mysql-test/r/im_options_set.result index 5e6c740624e..c3035079b39 100644 --- a/mysql-test/r/im_options_set.result +++ b/mysql-test/r/im_options_set.result @@ -1,8 +1,11 @@ -server_id = 1 -server_id = 2 +Success: the process has been started. SHOW VARIABLES LIKE 'server_id'; Variable_name Value server_id 1 +SHOW INSTANCES; +instance_name status +mysqld1 online +mysqld2 offline SET mysqld1.server_id = 11; server_id =11 server_id = 2 diff --git a/mysql-test/r/im_options_unset.result b/mysql-test/r/im_options_unset.result index bf54025edb7..ba468c78a5b 100644 --- a/mysql-test/r/im_options_unset.result +++ b/mysql-test/r/im_options_unset.result @@ -1,8 +1,11 @@ -server_id = 1 -server_id = 2 +Success: the process has been started. SHOW VARIABLES LIKE 'server_id'; Variable_name Value server_id 1 +SHOW INSTANCES; +instance_name status +mysqld1 online +mysqld2 offline UNSET mysqld1.server_id; server_id = 2 SHOW VARIABLES LIKE 'server_id'; diff --git a/mysql-test/r/im_utils.result b/mysql-test/r/im_utils.result index e6a5e007ed4..be696921812 100644 --- a/mysql-test/r/im_utils.result +++ b/mysql-test/r/im_utils.result @@ -1,4 +1,7 @@ Success: the process has been started. +SHOW VARIABLES LIKE 'server_id'; +Variable_name Value +server_id 1 SHOW INSTANCES; instance_name status mysqld1 online diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest index 3afc36935f8..fe2345a9987 100644 --- a/mysql-test/t/im_daemon_life_cycle.imtest +++ b/mysql-test/t/im_daemon_life_cycle.imtest @@ -7,21 +7,7 @@ ########################################################################### --source include/im_check_os.inc - -########################################################################### - -# Wait for mysqld1 (guarded instance) to start. - ---exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started - -# Let IM detect that mysqld1 is online. This delay should be longer than -# monitoring interval. - ---sleep 3 - -# Check that start conditions are as expected. - -SHOW INSTANCES; +--source include/im_check_env.inc ########################################################################### diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest index 2cbe53a7b28..35258396415 100644 --- a/mysql-test/t/im_life_cycle.imtest +++ b/mysql-test/t/im_life_cycle.imtest @@ -7,33 +7,7 @@ ########################################################################### --source include/im_check_os.inc - -########################################################################### -# -# 1.1.1. Check that Instance Manager is able: -# - to read definitions of two mysqld-instances; -# - to start the first instance; -# - to understand 'nonguarded' option and keep the second instance down; -# -########################################################################### - ---echo ---echo -------------------------------------------------------------------- ---echo -- 1.1.1. ---echo -------------------------------------------------------------------- - -# Wait for mysqld1 (guarded instance) to start. - ---exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started - -# Let IM detect that mysqld1 is online. This delay should be longer than -# monitoring interval. - ---sleep 3 - -# Check that start conditions are as expected. - -SHOW INSTANCES; +--source include/im_check_env.inc ########################################################################### # @@ -54,9 +28,10 @@ START INSTANCE mysqld2; # FIXME: START INSTANCE should be synchronous. --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started -# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is -# synchronous. Even waiting for mysqld to start by looking at its pid file is -# not enough, because IM may not detect that mysqld has started. +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. # SHOW INSTANCES; --connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK) @@ -86,9 +61,10 @@ STOP INSTANCE mysqld2; # FIXME: STOP INSTANCE should be synchronous. --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped -# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is -# synchronous. Even waiting for mysqld to start by looking at its pid file is -# not enough, because IM may not detect that mysqld has started. +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. # SHOW INSTANCES; ########################################################################### @@ -114,8 +90,8 @@ START INSTANCE mysqld1; ########################################################################### # -# 1.1.5. Check that Instance Manager reports correct errors for 'STOP INSTANCE' -# command: +# 1.1.5. Check that Instance Manager reports correct errors for +# 'STOP INSTANCE' command: # - if the client tries to start unregistered instance; # - if the client tries to start already stopped instance; # - if the client submits invalid arguments; @@ -146,12 +122,10 @@ STOP INSTANCE mysqld3; --echo -- 1.1.6. --echo -------------------------------------------------------------------- -SHOW INSTANCES; - --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30 -# Give some time to IM to detect that mysqld was restarted. It should be longer -# than monitoring interval. +# Give some time to IM to detect that mysqld was restarted. It should be +# longer than monitoring interval. --sleep 3 @@ -172,16 +146,18 @@ START INSTANCE mysqld2; # FIXME: START INSTANCE should be synchronous. --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started -# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is -# synchronous. Even waiting for mysqld to start by looking at its pid file is -# not enough, because IM may not detect that mysqld has started. +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. # SHOW INSTANCES; --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10 -# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is -# synchronous. Even waiting for mysqld to start by looking at its pid file is -# not enough, because IM may not detect that mysqld has started. +# FIXME: Result of SHOW INSTANCES here is not deterministic unless START +# INSTANCE is synchronous. Even waiting for mysqld to start by looking at +# its pid file is not enough, because it is unknown when IM detects that +# mysqld has started. # SHOW INSTANCES; ########################################################################### diff --git a/mysql-test/t/im_options_set.imtest b/mysql-test/t/im_options_set.imtest index a9b64861f99..76e209b6a66 100644 --- a/mysql-test/t/im_options_set.imtest +++ b/mysql-test/t/im_options_set.imtest @@ -39,32 +39,7 @@ ########################################################################### --source include/im_check_os.inc - -########################################################################### -# -# 0. Check starting conditions. -# -########################################################################### - -# - check the configuration file; - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - check the running instances. - ---connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check the internal cache. -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; -# SHOW INSTANCE OPTIONS mysqld2; +--source include/im_check_env.inc ########################################################################### # diff --git a/mysql-test/t/im_options_unset.imtest b/mysql-test/t/im_options_unset.imtest index 40629805d45..06f59e79ffe 100644 --- a/mysql-test/t/im_options_unset.imtest +++ b/mysql-test/t/im_options_unset.imtest @@ -46,32 +46,7 @@ ########################################################################### --source include/im_check_os.inc - -########################################################################### -# -# 0. Check starting conditions. -# -########################################################################### - -# - check the configuration file; - ---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ; - -# - check the running instances. - ---connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) - ---connection mysql1_con - -SHOW VARIABLES LIKE 'server_id'; - ---connection default - -# - check the internal cache. -# TODO: we should check only server_id option here. - -# SHOW INSTANCE OPTIONS mysqld1; -# SHOW INSTANCE OPTIONS mysqld2; +--source include/im_check_env.inc ########################################################################### # diff --git a/mysql-test/t/im_utils.imtest b/mysql-test/t/im_utils.imtest index 47902eeba52..4c05b342af5 100644 --- a/mysql-test/t/im_utils.imtest +++ b/mysql-test/t/im_utils.imtest @@ -7,36 +7,17 @@ ########################################################################### --source include/im_check_os.inc +--source include/im_check_env.inc ########################################################################### # -# Check starting conditions. This test case assumes that: -# - two mysqld-instances are registered; -# - the first instance is online; -# - the second instance is offline; +# Check 'SHOW INSTANCE OPTIONS' command. # - -# Wait for mysqld1 (guarded instance) to start. - ---exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started - -# Let IM detect that mysqld1 is online. This delay should be longer than -# monitoring interval. - ---sleep 3 - -# Check that start conditions are as expected. - -SHOW INSTANCES; - -# -# Check 'SHOW INSTANCE OPTIONS' command: -# - check that options of both offline and online instances are accessible; -# - since configuration of an mysqld-instance contains directories, we should -# completely ignore the second column (values) in order to make the test -# case produce the same results on different installations; -# TODO: ignore values of only directory-specific options. +# Since configuration of an mysqld-instance contains directories, we should +# completely ignore the second column (values) in order to make the test +# case produce the same results on different installations; +# TODO: ignore values of only directory-specific options. # --replace_column 2 VALUE -- cgit v1.2.1 From 68698c04abfbcbee1b67b5daca6695ada679ac4f Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Jul 2006 03:04:04 +0400 Subject: BUG#20975: Incorrect query result for NOT (subquery): Add implementations of Item_func_{nop,not}_all::neg_transformer mysql-test/r/subselect.result: BUG#20975: testcase mysql-test/t/subselect.test: BUG#20975: testcase sql/mysql_priv.h: Make chooser_compare_func_creator visible in item.h --- mysql-test/r/subselect.result | 26 ++++++++++++++++++++++++++ mysql-test/t/subselect.test | 16 ++++++++++++++++ sql/item_cmpfunc.cc | 22 ++++++++++++++++++++++ sql/item_cmpfunc.h | 2 ++ sql/item_subselect.cc | 6 +++--- sql/item_subselect.h | 9 ++++----- sql/mysql_priv.h | 3 ++- sql/sql_parse.cc | 2 +- 8 files changed, 76 insertions(+), 10 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index c78f0951469..595d80f1218 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -2868,3 +2868,29 @@ select 1 from dual where 1 < any (select 2 from dual); select 1 from dual where 1 < all (select 2 from dual where 1!=1); 1 1 +create table t1 (s1 char); +insert into t1 values (1),(2); +select * from t1 where (s1 < any (select s1 from t1)); +s1 +1 +select * from t1 where not (s1 < any (select s1 from t1)); +s1 +2 +select * from t1 where (s1 < ALL (select s1+1 from t1)); +s1 +1 +select * from t1 where not(s1 < ALL (select s1+1 from t1)); +s1 +2 +select * from t1 where (s1+1 = ANY (select s1 from t1)); +s1 +1 +select * from t1 where NOT(s1+1 = ANY (select s1 from t1)); +s1 +2 +select * from t1 where (s1 = ALL (select s1/s1 from t1)); +s1 +1 +select * from t1 where NOT(s1 = ALL (select s1/s1 from t1)); +s1 +2 diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index e01310bba45..1bcd37dd7d7 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1844,4 +1844,20 @@ select 1 from dual where 2 > any (select 1); select 1 from dual where 2 > all (select 1); select 1 from dual where 1 < any (select 2 from dual); select 1 from dual where 1 < all (select 2 from dual where 1!=1); + +# BUG#20975 Wrong query results for subqueries within NOT +create table t1 (s1 char); +insert into t1 values (1),(2); + +select * from t1 where (s1 < any (select s1 from t1)); +select * from t1 where not (s1 < any (select s1 from t1)); + +select * from t1 where (s1 < ALL (select s1+1 from t1)); +select * from t1 where not(s1 < ALL (select s1+1 from t1)); + +select * from t1 where (s1+1 = ANY (select s1 from t1)); +select * from t1 where NOT(s1+1 = ANY (select s1 from t1)); + +select * from t1 where (s1 = ALL (select s1/s1 from t1)); +select * from t1 where NOT(s1 = ALL (select s1/s1 from t1)); # End of 4.1 tests diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index f14efc7187b..a32bd0a7337 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -3099,6 +3099,28 @@ Item *Item_cond_or::neg_transformer(THD *thd) /* NOT(a OR b OR ...) -> */ } +Item *Item_func_nop_all::neg_transformer(THD *thd) +{ + /* "NOT (e $cmp$ ANY (SELECT ...)) -> e $rev_cmp$" ALL (SELECT ...) */ + Item_func_not_all *new_item= new Item_func_not_all(args[0]); + Item_allany_subselect *allany= (Item_allany_subselect*)args[0]; + allany->func= allany->func_creator(FALSE); + allany->all= !allany->all; + allany->upper_item= new_item; + return new_item; +} + +Item *Item_func_not_all::neg_transformer(THD *thd) +{ + /* "NOT (e $cmp$ ALL (SELECT ...)) -> e $rev_cmp$" ANY (SELECT ...) */ + Item_func_nop_all *new_item= new Item_func_nop_all(args[0]); + Item_allany_subselect *allany= (Item_allany_subselect*)args[0]; + allany->all= !allany->all; + allany->func= allany->func_creator(TRUE); + allany->upper_item= new_item; + return new_item; +} + Item *Item_func_eq::negated_item() /* a = b -> a != b */ { return new Item_func_ne(args[0], args[1]); diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 73abe208d9e..0e157fd412c 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -268,6 +268,7 @@ public: void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; }; void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; }; bool empty_underlying_subquery(); + Item *neg_transformer(THD *thd); }; @@ -278,6 +279,7 @@ public: Item_func_nop_all(Item *a) :Item_func_not_all(a) {} longlong val_int(); const char *func_name() const { return ""; } + Item *neg_transformer(THD *thd); }; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index f6f8eec9af5..c95a91de13e 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -542,14 +542,14 @@ Item_in_subselect::Item_in_subselect(Item * left_exp, } Item_allany_subselect::Item_allany_subselect(Item * left_exp, - Comp_creator *fn, + chooser_compare_func_creator fc, st_select_lex *select_lex, bool all_arg) - :Item_in_subselect(), all(all_arg) + :Item_in_subselect(), all(all_arg), func_creator(fc) { DBUG_ENTER("Item_in_subselect::Item_in_subselect"); left_expr= left_exp; - func= fn; + func= func_creator(all_arg); init(select_lex, new select_exists_subselect(this)); max_columns= 1; abort_on_null= 0; diff --git a/sql/item_subselect.h b/sql/item_subselect.h index dec32398a80..93171ad64a1 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -251,14 +251,13 @@ public: /* ALL/ANY/SOME subselect */ class Item_allany_subselect :public Item_in_subselect { -protected: - Comp_creator *func; - public: + chooser_compare_func_creator func_creator; + Comp_creator *func; bool all; - Item_allany_subselect(Item * left_expr, Comp_creator *f, - st_select_lex *select_lex, bool all); + Item_allany_subselect(Item * left_expr, chooser_compare_func_creator fc, + st_select_lex *select_lex, bool all); // only ALL subquery has upper not subs_type substype() { return all?ALL_SUBS:ANY_SUBS; } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index d231942bb7a..d03c6acac7c 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -387,8 +387,9 @@ enum enum_var_type OPT_DEFAULT, OPT_SESSION, OPT_GLOBAL }; class sys_var; -#include "item.h" +class Comp_creator; typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); +#include "item.h" /* sql_parse.cc */ void free_items(Item *item); void cleanup_items(Item *item); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index fbe36bfdc4a..660c77e81e4 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5436,7 +5436,7 @@ Item * all_any_subquery_creator(Item *left_expr, return new Item_func_not(new Item_in_subselect(left_expr, select_lex)); Item_allany_subselect *it= - new Item_allany_subselect(left_expr, (*cmp)(all), select_lex, all); + new Item_allany_subselect(left_expr, cmp, select_lex, all); if (all) return it->upper_item= new Item_func_not_all(it); /* ALL */ -- cgit v1.2.1 From 4e59d30dc9ef76c79c8e8c92bfad9b394d4d5c9b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Jul 2006 11:59:46 +0300 Subject: Fix for BUG#21007. The problem was that store_top_level_join_columns() incorrectly assumed that the left/right neighbor of a nested join table reference can be only at the same level in the join tree. The fix checks if the current nested join table reference has no immediate left/right neighbor, and if so chooses the left/right neighbors of the nearest upper level, where these references are != NULL. mysql-test/r/group_min_max.result: Test for BUG#21007. mysql-test/t/group_min_max.test: Test for BUG#21007. sql/sql_base.cc: After computing and materializing the columns of all NATURAL joins in a FROM clause, the procedure store_top_level_join_columns() has to change the current natural join into a leaf table reference for name resolution. For this it needs to make the left neighbor point to the natural join table reference, and the natural join itself point to its left neighbor. This fix correctly determines the left/right neighbors of a table reference, even if the neghbors are at higher levels in the nested join tree. The rule is that if a table reference has no immediate left/right neighbors, we recursively pick the left/right neighbor of the level(s) above. --- mysql-test/r/group_min_max.result | 43 +++++++++++++++++++++++++++++++++++ mysql-test/t/group_min_max.test | 48 +++++++++++++++++++++++++++++++++++++++ sql/sql_base.cc | 38 ++++++++++++++++++++----------- 3 files changed, 116 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result index d62586dba85..fe6f7c4ca55 100644 --- a/mysql-test/r/group_min_max.result +++ b/mysql-test/r/group_min_max.result @@ -2099,3 +2099,46 @@ SOUTH EAST SOUTH EAST SOUTH WEST SOUTH WEST WESTERN WESTERN DROP TABLE t1; +CREATE TABLE t1 (id1 INT, id2 INT); +CREATE TABLE t2 (id2 INT, id3 INT, id5 INT); +CREATE TABLE t3 (id3 INT, id4 INT); +CREATE TABLE t4 (id4 INT); +CREATE TABLE t5 (id5 INT, id6 INT); +CREATE TABLE t6 (id6 INT); +INSERT INTO t1 VALUES(1,1); +INSERT INTO t2 VALUES(1,1,1); +INSERT INTO t3 VALUES(1,1); +INSERT INTO t4 VALUES(1); +INSERT INTO t5 VALUES(1,1); +INSERT INTO t6 VALUES(1); +SELECT * FROM +t1 +NATURAL JOIN +(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6) +ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)); +id2 id1 id3 id5 id4 id3 id6 id5 +1 1 1 1 1 1 1 1 +SELECT * FROM +t1 +NATURAL JOIN +(((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6) on t3.id4 = t5.id5) JOIN t2 +ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)); +id2 id1 id4 id3 id6 id5 id3 id5 +1 1 1 1 1 1 1 1 +SELECT * FROM t1 NATURAL JOIN ((t3 join (t5 NATURAL JOIN t6)) JOIN t2); +id2 id1 id3 id4 id6 id5 id3 id5 +1 1 1 1 1 1 1 1 +SELECT * FROM +(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6) +ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)) +NATURAL JOIN +t1; +id2 id3 id5 id4 id3 id6 id5 id1 +1 1 1 1 1 1 1 1 +SELECT * FROM +(t2 JOIN ((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6))) +NATURAL JOIN +t1; +id2 id3 id5 id4 id3 id6 id5 id1 +1 1 1 1 1 1 1 1 +DROP TABLE t1,t2,t3,t4,t5,t6; diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test index 874f3cd1a80..5427727a8f4 100644 --- a/mysql-test/t/group_min_max.test +++ b/mysql-test/t/group_min_max.test @@ -746,3 +746,51 @@ EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a; SELECT DISTINCT a,a FROM t1 ORDER BY a; DROP TABLE t1; + +# +# Bug #21007: NATURAL JOIN (any JOIN (2 x NATURAL JOIN)) crashes the server +# + +CREATE TABLE t1 (id1 INT, id2 INT); +CREATE TABLE t2 (id2 INT, id3 INT, id5 INT); +CREATE TABLE t3 (id3 INT, id4 INT); +CREATE TABLE t4 (id4 INT); +CREATE TABLE t5 (id5 INT, id6 INT); +CREATE TABLE t6 (id6 INT); + +INSERT INTO t1 VALUES(1,1); +INSERT INTO t2 VALUES(1,1,1); +INSERT INTO t3 VALUES(1,1); +INSERT INTO t4 VALUES(1); +INSERT INTO t5 VALUES(1,1); +INSERT INTO t6 VALUES(1); + +-- original bug query +SELECT * FROM +t1 + NATURAL JOIN +(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6) + ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)); + +-- inner join swapped +SELECT * FROM +t1 + NATURAL JOIN +(((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6) on t3.id4 = t5.id5) JOIN t2 + ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)); + +-- one join less, no ON cond +SELECT * FROM t1 NATURAL JOIN ((t3 join (t5 NATURAL JOIN t6)) JOIN t2); + +-- wrong error message: 'id2' - ambiguous column +SELECT * FROM +(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6) + ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5)) + NATURAL JOIN +t1; +SELECT * FROM +(t2 JOIN ((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6))) + NATURAL JOIN +t1; + +DROP TABLE t1,t2,t3,t4,t5,t6; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 5383bb52aaa..7f9076bb46e 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4041,36 +4041,48 @@ store_top_level_join_columns(THD *thd, TABLE_LIST *table_ref, if (table_ref->nested_join) { List_iterator_fast nested_it(table_ref->nested_join->join_list); - TABLE_LIST *cur_left_neighbor= nested_it++; - TABLE_LIST *cur_right_neighbor= NULL; + TABLE_LIST *same_level_left_neighbor= nested_it++; + TABLE_LIST *same_level_right_neighbor= NULL; + /* Left/right-most neighbors, possibly at higher levels in the join tree. */ + TABLE_LIST *real_left_neighbor, *real_right_neighbor; - while (cur_left_neighbor) + while (same_level_left_neighbor) { - TABLE_LIST *cur_table_ref= cur_left_neighbor; - cur_left_neighbor= nested_it++; + TABLE_LIST *cur_table_ref= same_level_left_neighbor; + same_level_left_neighbor= nested_it++; /* The order of RIGHT JOIN operands is reversed in 'join list' to transform it into a LEFT JOIN. However, in this procedure we need the join operands in their lexical order, so below we reverse the - join operands. Notice that this happens only in the first loop, and - not in the second one, as in the second loop cur_left_neighbor == NULL. - This is the correct behavior, because the second loop - sets cur_table_ref reference correctly after the join operands are + join operands. Notice that this happens only in the first loop, + and not in the second one, as in the second loop + same_level_left_neighbor == NULL. + This is the correct behavior, because the second loop sets + cur_table_ref reference correctly after the join operands are swapped in the first loop. */ - if (cur_left_neighbor && + if (same_level_left_neighbor && cur_table_ref->outer_join & JOIN_TYPE_RIGHT) { /* This can happen only for JOIN ... ON. */ DBUG_ASSERT(table_ref->nested_join->join_list.elements == 2); - swap_variables(TABLE_LIST*, cur_left_neighbor, cur_table_ref); + swap_variables(TABLE_LIST*, same_level_left_neighbor, cur_table_ref); } + /* + Pick the parent's left and right neighbors if there are no immediate + neighbors at the same level. + */ + real_left_neighbor= (same_level_left_neighbor) ? + same_level_left_neighbor : left_neighbor; + real_right_neighbor= (same_level_right_neighbor) ? + same_level_right_neighbor : right_neighbor; + if (cur_table_ref->nested_join && store_top_level_join_columns(thd, cur_table_ref, - cur_left_neighbor, cur_right_neighbor)) + real_left_neighbor, real_right_neighbor)) goto err; - cur_right_neighbor= cur_table_ref; + same_level_right_neighbor= cur_table_ref; } } -- cgit v1.2.1 From 8024aabb76ffa8d1ea6105ca071b2109766ea2cb Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Jul 2006 17:59:52 +0300 Subject: Bug #20868: Client connection is broken on SQL query error An aggregate function reference was resolved incorrectly and caused a crash in count_field_types. Must use real_item() to get to the real Item instance through the reference mysql-test/r/func_group.result: Bug #20868: Client connection is broken on SQL query error * test case for the bug mysql-test/t/func_group.test: Bug #20868: Client connection is broken on SQL query error * test case for the bug sql/sql_select.cc: Bug #20868: Client connection is broken on SQL query error * correctly resolve aggregate function references. --- mysql-test/r/func_group.result | 11 +++++++++++ mysql-test/t/func_group.test | 15 +++++++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index f693c6190d5..896b79297f8 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -988,3 +988,14 @@ SUM(a) 6 DROP TABLE t1; set div_precision_increment= @sav_dpi; +CREATE TABLE t1 (a INT PRIMARY KEY, b INT); +INSERT INTO t1 VALUES (1,1), (2,2); +CREATE TABLE t2 (a INT PRIMARY KEY, b INT); +INSERT INTO t2 VALUES (1,1), (3,3); +SELECT SQL_NO_CACHE +(SELECT SUM(c.a) FROM t1 ttt, t2 ccc +WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid +FROM t1 t, t2 c WHERE t.a = c.b; +minid +NULL +DROP TABLE t1,t2; diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index e8c5fa18a25..f28ce234b73 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -660,3 +660,18 @@ SELECT SUM(a) FROM t1 GROUP BY b/c; DROP TABLE t1; set div_precision_increment= @sav_dpi; +# +# Bug #20868: Client connection is broken on SQL query error +# +CREATE TABLE t1 (a INT PRIMARY KEY, b INT); +INSERT INTO t1 VALUES (1,1), (2,2); + +CREATE TABLE t2 (a INT PRIMARY KEY, b INT); +INSERT INTO t2 VALUES (1,1), (3,3); + +SELECT SQL_NO_CACHE + (SELECT SUM(c.a) FROM t1 ttt, t2 ccc + WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid +FROM t1 t, t2 c WHERE t.a = c.b; + +DROP TABLE t1,t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a7158960ed0..c31d9d9902b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12806,7 +12806,7 @@ count_field_types(TMP_TABLE_PARAM *param, List &fields, { if (! field->const_item()) { - Item_sum *sum_item=(Item_sum*) field; + Item_sum *sum_item=(Item_sum*) field->real_item(); if (!sum_item->quick_group) param->quick_group=0; // UDF SUM function param->sum_func_count++; -- cgit v1.2.1 From 7118c2523c2b8d127ae0e3f2a08f28ee11c1c712 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Jul 2006 20:44:35 +0300 Subject: Bug #20466: a view is mixing data when there's a trigger on the table When making a place to store field values at the start of each group the real item (not the reference) must be used when deciding which column to copy. mysql-test/r/group_by.result: Bug #20466: a view is mixing data when there's a trigger on the table - test suite for the bug mysql-test/t/group_by.test: Bug #20466: a view is mixing data when there's a trigger on the table - test suite for the bug sql/sql_select.cc: Bug #20466: a view is mixing data when there's a trigger on the table - deal correctly with references --- mysql-test/r/group_by.result | 25 +++++++++++++++++++++++++ mysql-test/t/group_by.test | 23 +++++++++++++++++++++++ sql/sql_select.cc | 16 +++++++++------- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 7bc886022cc..e5c177503fa 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -796,3 +796,28 @@ aaa show warnings; Level Code Message drop table t1, t2; +CREATE TABLE t1 (a tinyint(3), b varchar(255), PRIMARY KEY (a)); +INSERT INTO t1 VALUES (1,'-----'), (6,'Allemagne'), (17,'Autriche'), +(25,'Belgique'), (54,'Danemark'), (62,'Espagne'), (68,'France'); +CREATE TABLE t2 (a tinyint(3), b tinyint(3), PRIMARY KEY (a), KEY b (b)); +INSERT INTO t2 VALUES (1,1), (2,1), (6,6), (18,17), (15,25), (16,25), +(17,25), (10,54), (5,62),(3,68); +CREATE VIEW v1 AS select t1.a, concat(t1.b,'') AS b, t1.b as real_b from t1; +explain +SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1 +where t2.b=v1.a GROUP BY t2.b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 index b b 2 NULL 10 Using index +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 1 test.t2.b 1 +SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1 +where t2.b=v1.a GROUP BY t2.b; +a b real_b +1 ----- ----- +6 Allemagne Allemagne +17 Autriche Autriche +25 Belgique Belgique +54 Danemark Danemark +62 Espagne Espagne +68 France France +DROP VIEW v1; +DROP TABLE t1,t2; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index fb9835c5d7f..ce1e4e59600 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -632,3 +632,26 @@ group by t1.c1; show warnings; drop table t1, t2; +# +# Bug #20466: a view is mixing data when there's a trigger on the table +# +CREATE TABLE t1 (a tinyint(3), b varchar(255), PRIMARY KEY (a)); + +INSERT INTO t1 VALUES (1,'-----'), (6,'Allemagne'), (17,'Autriche'), + (25,'Belgique'), (54,'Danemark'), (62,'Espagne'), (68,'France'); + +CREATE TABLE t2 (a tinyint(3), b tinyint(3), PRIMARY KEY (a), KEY b (b)); + +INSERT INTO t2 VALUES (1,1), (2,1), (6,6), (18,17), (15,25), (16,25), + (17,25), (10,54), (5,62),(3,68); + +CREATE VIEW v1 AS select t1.a, concat(t1.b,'') AS b, t1.b as real_b from t1; + +explain +SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1 +where t2.b=v1.a GROUP BY t2.b; +SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1 +where t2.b=v1.a GROUP BY t2.b; + +DROP VIEW v1; +DROP TABLE t1,t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a7158960ed0..39f5b43b05e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13066,10 +13066,11 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, param->copy_funcs.empty(); for (i= 0; (pos= li++); i++) { - if (pos->real_item()->type() == Item::FIELD_ITEM) + Item *real_pos= pos->real_item(); + if (real_pos->type() == Item::FIELD_ITEM) { Item_field *item; - pos= pos->real_item(); + pos= real_pos; if (!(item= new Item_field(thd, ((Item_field*) pos)))) goto err; pos= item; @@ -13108,12 +13109,13 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, } } } - else if ((pos->type() == Item::FUNC_ITEM || - pos->type() == Item::SUBSELECT_ITEM || - pos->type() == Item::CACHE_ITEM || - pos->type() == Item::COND_ITEM) && - !pos->with_sum_func) + else if ((real_pos->type() == Item::FUNC_ITEM || + real_pos->type() == Item::SUBSELECT_ITEM || + real_pos->type() == Item::CACHE_ITEM || + real_pos->type() == Item::COND_ITEM) && + !real_pos->with_sum_func) { // Save for send fields + pos= real_pos; /* TODO: In most cases this result will be sent to the user. This should be changed to use copy_int or copy_real depending -- cgit v1.2.1 From 35209c68eab3137bf40ca1657a2404006c2aa392 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 22 Jul 2006 02:08:00 +0400 Subject: Fixed bug#12185: Data type aggregation may produce wrong result The Item::tmp_table_field_from_field_type() function creates Field_datetime object instead of Field_timestamp object for timestamp field thus always changing data type is a tmp table is used. The Field_blob object constructor which is used in the Item::tmp_table_field_from_field_type() is always setting packlength field of newly created blob to 4. This leads to changing fields data type for example from the blob to the longblob if a temporary table is used. The Item::make_string_field() function always converts Field_string objects to Field_varstring objects. This leads to changing data type from the char/binary to varchar/varbinary. Added appropriate Field_timestamp object constructor for using in the Item::tmp_table_field_from_field_type() function. Added Field_blob object constructor which sets pack length according to max_length argument. The Item::tmp_table_field_from_field_type() function now creates Field_timestamp object for a timestamp field. The Item_type_holder::display_length() now returns correct NULL length NULL length. The Item::make_string_field() function now doesn't change Field_string to Field_varstring in the case of Item_type_holder. The Item::tmp_table_field_from_field_type() function now uses the Field_blob constructor which sets packlength according to max_length. mysql-test/t/union.test: Added test case for bug#12185: Data type aggregation may produce wrong result Corrected test case after fix for bug#12185 mysql-test/t/innodb.test: Corrected test case after fix for bug#12185 mysql-test/r/union.result: Added test case for bug#12185: Data type aggregation may produce wrong result Corrected test case after fix for bug#12185 mysql-test/r/innodb.result: Corrected test case after fix for bug#12185 mysql-test/r/create.result: Corrected the test case after fixing bug#12185 sql/field.h: Fixed bug#12185: Data type aggregation may produce wrong result Added Field_blob object constructor which sets packlength according to max_length argument. sql/item.cc: Fixed bug#12185: Data type aggregation may produce wrong result The Item::make_string_field() function now doesn't change Field_string to Field_varstring in the case of Item_type_holder. The Item::tmp_table_field_from_field_type() function now creates Field_timestamp object for a timestamp field. The Item::tmp_table_field_from_field_type() function now uses the Field_blob constructor which sets packlength according to max_length. The Item_type_holder::display_length() now returns correct NULL length NULL length. sql/field.cc: Fixed bug#12185: Data type aggregation may produce wrong result Added appropriate Field_timestamp object constructor for using in the Item::tmp_table_field_from_field_type() function. --- mysql-test/r/create.result | 2 +- mysql-test/r/innodb.result | 4 ++-- mysql-test/r/union.result | 31 +++++++++++++++++++++++-------- mysql-test/t/innodb.test | 2 +- mysql-test/t/union.test | 12 ++++++++++-- sql/field.cc | 18 ++++++++++++++++++ sql/field.h | 17 +++++++++++++++++ sql/item.cc | 13 ++++++++++--- 8 files changed, 82 insertions(+), 17 deletions(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 27a6c8a9d03..0bc5ec32086 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -452,7 +452,7 @@ t2 CREATE TABLE `t2` ( `ifnull(h,h)` decimal(5,4) default NULL, `ifnull(i,i)` year(4) default NULL, `ifnull(j,j)` date default NULL, - `ifnull(k,k)` datetime NOT NULL default '0000-00-00 00:00:00', + `ifnull(k,k)` timestamp NOT NULL default '0000-00-00 00:00:00', `ifnull(l,l)` datetime default NULL, `ifnull(m,m)` varchar(1) default NULL, `ifnull(n,n)` varchar(3) default NULL, diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 77046cc1fd1..1d1f26e4b01 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -1473,8 +1473,8 @@ Error 1146 Table 'test.t4' doesn't exist drop table t1,t2,t3; create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb; insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt'); -select name2 from t1 union all select name from t1 union all select id from t1; -name2 +select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1; +trim(name2) fff sss ttt diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index eb9e10aa58d..6ef5363d90f 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -691,9 +691,9 @@ t1 CREATE TABLE `t1` ( `da` datetime default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; -create table t1 SELECT dt from t2 UNION select sc from t2; -select * from t1; -dt +create table t1 SELECT dt from t2 UNION select trim(sc) from t2; +select trim(dt) from t1; +trim(dt) 1972-10-22 11:50:00 testc show create table t1; @@ -732,7 +732,7 @@ tetetetetest show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `dt` longblob + `dt` blob ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 SELECT sv from t2 UNION select b from t2; @@ -743,7 +743,7 @@ tetetetetest show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `sv` longblob + `sv` blob ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 SELECT i from t2 UNION select d from t2 UNION select b from t2; @@ -755,7 +755,7 @@ tetetetetest show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `i` longblob + `i` blob ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 SELECT sv from t2 UNION select tx from t2; @@ -766,7 +766,7 @@ teeeeeeeeeeeest show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `sv` longtext + `sv` text ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 SELECT b from t2 UNION select tx from t2; @@ -777,7 +777,7 @@ teeeeeeeeeeeest show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `b` longblob + `b` blob ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1,t2; create table t1 select 1 union select -1; @@ -1306,3 +1306,18 @@ id 5 99 drop table t1; +create table t1(f1 char(1), f2 char(5), f3 binary(1), f4 binary(5), f5 timestamp, f6 varchar(1) character set utf8 collate utf8_general_ci, f7 text); +create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f1` char(1) default NULL, + `f2` char(5) default NULL, + `f3` binary(1) default NULL, + `f4` binary(5) default NULL, + `f5` timestamp NOT NULL default '0000-00-00 00:00:00', + `f6` varchar(1) character set utf8 default NULL, + `f7` text, + `f8` text character set utf8 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1, t2; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index e4c8bf89cca..4ebfef3504e 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -1079,7 +1079,7 @@ drop table t1,t2,t3; # create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb; insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt'); -select name2 from t1 union all select name from t1 union all select id from t1; +select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1; drop table t1; # diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index 692f1f509fa..516bc6d4818 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -390,8 +390,8 @@ create table t1 SELECT da from t2 UNION select dt from t2; select * from t1; show create table t1; drop table t1; -create table t1 SELECT dt from t2 UNION select sc from t2; -select * from t1; +create table t1 SELECT dt from t2 UNION select trim(sc) from t2; +select trim(dt) from t1; show create table t1; drop table t1; create table t1 SELECT dt from t2 UNION select sv from t2; @@ -793,3 +793,11 @@ select id from t1 union all select 99 order by 1; drop table t1; # End of 4.1 tests + +# +# Bug#12185: Data type aggregation may produce wrong result +# +create table t1(f1 char(1), f2 char(5), f3 binary(1), f4 binary(5), f5 timestamp, f6 varchar(1) character set utf8 collate utf8_general_ci, f7 text); +create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1; +show create table t2; +drop table t1, t2; diff --git a/sql/field.cc b/sql/field.cc index a920d6d91b1..163822fe712 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4484,6 +4484,24 @@ Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg, } +Field_timestamp::Field_timestamp(bool maybe_null_arg, + const char *field_name_arg, + struct st_table *table_arg, CHARSET_INFO *cs) + :Field_str((char*) 0, 19, maybe_null_arg ? (uchar*) "": 0, 0, + NONE, field_name_arg, table_arg, cs) +{ + /* For 4.0 MYD and 4.0 InnoDB compatibility */ + flags|= ZEROFILL_FLAG | UNSIGNED_FLAG; + if (table && !table->timestamp_field && + unireg_check != NONE) + { + /* This timestamp has auto-update */ + table->timestamp_field= this; + flags|=TIMESTAMP_FLAG; + } +} + + /* Get auto-set type for TIMESTAMP field. diff --git a/sql/field.h b/sql/field.h index f4d27e46877..3aeb5e03259 100644 --- a/sql/field.h +++ b/sql/field.h @@ -781,6 +781,8 @@ public: enum utype unireg_check_arg, const char *field_name_arg, struct st_table *table_arg, CHARSET_INFO *cs); + Field_timestamp(bool maybe_null_arg, const char *field_name_arg, + struct st_table *table_arg, CHARSET_INFO *cs); enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } enum Item_result cmp_type () const { return INT_RESULT; } @@ -1129,6 +1131,21 @@ public: { flags|= BLOB_FLAG; } + Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, + struct st_table *table_arg, CHARSET_INFO *cs, bool set_packlength) + :Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, + NONE, field_name_arg, table_arg, cs) + { + flags|= BLOB_FLAG; + packlength= 4; + if (set_packlength) + { + uint32 char_lengt= len_arg/cs->mbmaxlen; + packlength= char_length <= 255 ? 1 : + char_length <= 65535 ? 2 : + char_length <= 16777215 ? 3 : 4; + } + } enum_field_types type() const { return FIELD_TYPE_BLOB;} enum ha_base_keytype key_type() const { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; } diff --git a/sql/item.cc b/sql/item.cc index 24efc1f106f..c7208a3af64 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3874,7 +3874,9 @@ Field *Item::make_string_field(TABLE *table) if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB) return new Field_blob(max_length, maybe_null, name, table, collation.collation); - if (max_length > 0) + /* Item_type_holder holds the exact type, do not change it */ + if (max_length > 0 && + (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING)) return new Field_varstring(max_length, maybe_null, name, table, collation.collation); return new Field_string(max_length, maybe_null, name, table, @@ -3938,6 +3940,7 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table) case MYSQL_TYPE_TIME: return new Field_time(maybe_null, name, table, &my_charset_bin); case MYSQL_TYPE_TIMESTAMP: + return new Field_timestamp(maybe_null, name, table, &my_charset_bin); case MYSQL_TYPE_DATETIME: return new Field_datetime(maybe_null, name, table, &my_charset_bin); case MYSQL_TYPE_YEAR: @@ -3961,7 +3964,11 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table) case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_GEOMETRY: - return new Field_blob(max_length, maybe_null, name, table, + if (this->type() == Item::TYPE_HOLDER) + return new Field_blob(max_length, maybe_null, name, table, + collation.collation, 1); + else + return new Field_blob(max_length, maybe_null, name, table, collation.collation); break; // Blob handled outside of case } @@ -6117,7 +6124,7 @@ uint32 Item_type_holder::display_length(Item *item) case MYSQL_TYPE_DOUBLE: return 53; case MYSQL_TYPE_NULL: - return 4; + return 0; case MYSQL_TYPE_LONGLONG: return 20; case MYSQL_TYPE_INT24: -- cgit v1.2.1 From 9d432f0dae740bcaa89b61a9b8fced23030d5a13 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 22 Jul 2006 02:36:17 +0400 Subject: Add missing "DROP TABLE" clause --- mysql-test/r/subselect.result | 1 + mysql-test/t/subselect.test | 1 + 2 files changed, 2 insertions(+) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 595d80f1218..a2a88be8c42 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -2894,3 +2894,4 @@ s1 select * from t1 where NOT(s1 = ALL (select s1/s1 from t1)); s1 2 +drop table t1; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 1bcd37dd7d7..fc97d22cbb1 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1860,4 +1860,5 @@ select * from t1 where NOT(s1+1 = ANY (select s1 from t1)); select * from t1 where (s1 = ALL (select s1/s1 from t1)); select * from t1 where NOT(s1 = ALL (select s1/s1 from t1)); +drop table t1; # End of 4.1 tests -- cgit v1.2.1 From 5a3a1c98a42fbb045303f766f53bfdd033ed795c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 22 Jul 2006 05:52:37 +0400 Subject: field.h: Fixed typo. sql/field.h: Fixed typo. --- sql/field.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/field.h b/sql/field.h index 0bbcd1099a0..d89d8bb3965 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1141,7 +1141,7 @@ public: packlength= 4; if (set_packlength) { - uint32 char_lengt= len_arg/cs->mbmaxlen; + uint32 char_length= len_arg/cs->mbmaxlen; packlength= char_length <= 255 ? 1 : char_length <= 65535 ? 2 : char_length <= 16777215 ? 3 : 4; -- cgit v1.2.1 From 0f5797f57697750a6177e4dbe3c04a4fefcdae41 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 22 Jul 2006 16:18:28 +0400 Subject: Post-merge fixes --- sql/item_subselect.cc | 2 +- sql/mysql_priv.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 3c279d827b2..6675c9e7b25 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -575,7 +575,7 @@ Item_allany_subselect::Item_allany_subselect(Item * left_exp, chooser_compare_func_creator fc, st_select_lex *select_lex, bool all_arg) - :Item_in_subselect(), all(all_arg), func_creator(fc) + :Item_in_subselect(), func_creator(fc), all(all_arg) { DBUG_ENTER("Item_in_subselect::Item_in_subselect"); left_expr= left_exp; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 619755fc6ff..3298b4e6c8e 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -523,6 +523,8 @@ class sys_var; class Comp_creator; typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); #include "item.h" +extern my_decimal decimal_zero; + /* sql_parse.cc */ void free_items(Item *item); void cleanup_items(Item *item); -- cgit v1.2.1 From 43df9fd34c2d2b05a29b17e39920ab270f82d483 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 22 Jul 2006 12:44:54 -0700 Subject: Fixed bug #18925: wrong results for queries with subqueries on information schema that use MIN/MAX aggregation. Execution of some correlated subqueries may set the value of null_row to 1 for tables used in the subquery. If the the subquery is on information schema it causes rejection of any row for the following executions of the subquery in the case when an optimization filtering by some condition is applied. The fix restores the value of the null_row flag for each execution of a subquery on information schema. mysql-test/r/information_schema.result: Added a test case for bug #18925. mysql-test/t/information_schema.test: Added a test case for bug #18925. sql/sql_show.cc: Fixed bug #18925. Execution of some correlated subqueries may set the value of null_row to 1 for tables used in the subquery. If the the subquery is on information schema it causes rejection of any row for the following execitions of the subquery in the case when an optimization filtering by some condition is applied. The fix restores the value of the null_row flag for each execution of a subquery on information schema. --- mysql-test/r/information_schema.result | 62 ++++++++++++++++++++++++++++++++++ mysql-test/t/information_schema.test | 33 ++++++++++++++++++ sql/sql_show.cc | 1 + 3 files changed, 96 insertions(+) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index a2feba7ad5d..3b3669119d5 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1170,3 +1170,65 @@ f1() DROP FUNCTION f1; DROP PROCEDURE p1; DROP USER mysql_bug20230@localhost; +SELECT t.table_name, c1.column_name +FROM information_schema.tables t +INNER JOIN +information_schema.columns c1 +ON t.table_schema = c1.table_schema AND +t.table_name = c1.table_name +WHERE t.table_schema = 'information_schema' AND +c1.ordinal_position = +( SELECT COALESCE(MIN(c2.ordinal_position),1) +FROM information_schema.columns c2 +WHERE c2.table_schema = t.table_schema AND +c2.table_name = t.table_name AND +c2.column_name LIKE '%SCHEMA%' + ); +table_name column_name +CHARACTER_SETS CHARACTER_SET_NAME +COLLATIONS COLLATION_NAME +COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME +COLUMNS TABLE_SCHEMA +COLUMN_PRIVILEGES TABLE_SCHEMA +KEY_COLUMN_USAGE CONSTRAINT_SCHEMA +ROUTINES ROUTINE_SCHEMA +SCHEMATA SCHEMA_NAME +SCHEMA_PRIVILEGES TABLE_SCHEMA +STATISTICS TABLE_SCHEMA +TABLES TABLE_SCHEMA +TABLE_CONSTRAINTS CONSTRAINT_SCHEMA +TABLE_PRIVILEGES TABLE_SCHEMA +TRIGGERS TRIGGER_SCHEMA +USER_PRIVILEGES GRANTEE +VIEWS TABLE_SCHEMA +SELECT t.table_name, c1.column_name +FROM information_schema.tables t +INNER JOIN +information_schema.columns c1 +ON t.table_schema = c1.table_schema AND +t.table_name = c1.table_name +WHERE t.table_schema = 'information_schema' AND +c1.ordinal_position = +( SELECT COALESCE(MIN(c2.ordinal_position),1) +FROM information_schema.columns c2 +WHERE c2.table_schema = 'information_schema' AND +c2.table_name = t.table_name AND +c2.column_name LIKE '%SCHEMA%' + ); +table_name column_name +CHARACTER_SETS CHARACTER_SET_NAME +COLLATIONS COLLATION_NAME +COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME +COLUMNS TABLE_SCHEMA +COLUMN_PRIVILEGES TABLE_SCHEMA +KEY_COLUMN_USAGE CONSTRAINT_SCHEMA +ROUTINES ROUTINE_SCHEMA +SCHEMATA SCHEMA_NAME +SCHEMA_PRIVILEGES TABLE_SCHEMA +STATISTICS TABLE_SCHEMA +TABLES TABLE_SCHEMA +TABLE_CONSTRAINTS CONSTRAINT_SCHEMA +TABLE_PRIVILEGES TABLE_SCHEMA +TRIGGERS TRIGGER_SCHEMA +USER_PRIVILEGES GRANTEE +VIEWS TABLE_SCHEMA diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index a2e19112cf9..b49ec9e2f31 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -887,4 +887,37 @@ DROP FUNCTION f1; DROP PROCEDURE p1; DROP USER mysql_bug20230@localhost; +# +# Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA +# + +SELECT t.table_name, c1.column_name + FROM information_schema.tables t + INNER JOIN + information_schema.columns c1 + ON t.table_schema = c1.table_schema AND + t.table_name = c1.table_name + WHERE t.table_schema = 'information_schema' AND + c1.ordinal_position = + ( SELECT COALESCE(MIN(c2.ordinal_position),1) + FROM information_schema.columns c2 + WHERE c2.table_schema = t.table_schema AND + c2.table_name = t.table_name AND + c2.column_name LIKE '%SCHEMA%' + ); +SELECT t.table_name, c1.column_name + FROM information_schema.tables t + INNER JOIN + information_schema.columns c1 + ON t.table_schema = c1.table_schema AND + t.table_name = c1.table_name + WHERE t.table_schema = 'information_schema' AND + c1.ordinal_position = + ( SELECT COALESCE(MIN(c2.ordinal_position),1) + FROM information_schema.columns c2 + WHERE c2.table_schema = 'information_schema' AND + c2.table_name = t.table_name AND + c2.column_name LIKE '%SCHEMA%' + ); + # End of 5.0 tests. diff --git a/sql/sql_show.cc b/sql/sql_show.cc index cabb04c5f16..e2adefb0ca9 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3963,6 +3963,7 @@ bool get_schema_tables_result(JOIN *join) table_list->table->file->delete_all_rows(); free_io_cache(table_list->table); filesort_free_buffers(table_list->table); + table_list->table->null_row= 0; } else table_list->table->file->records= 0; -- cgit v1.2.1 From 36510232aa5ab3788de36d17202254e3789441f4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 14:56:53 +0400 Subject: A fix and a test case for Bug#15752 "Lost connection to MySQL server when calling a SP from C API" The bug was caused by lack of checks for misuse in mysql_real_query. A stored procedure always returns at least one result, which is the status of execution of the procedure itself. This result, or so-called OK packet, is similar to a result returned by INSERT/UPDATE/CREATE operations: it contains the overall status of execution, the number of affected rows and the number of warnings. The client test program attached to the bug did not read this result and ivnoked the next query. In turn, libmysql had no check for such scenario and mysql_real_query was simply trying to send that query without reading the pending response, thus messing up the communication protocol. The fix is to return an error from mysql_real_query when it's called prior to retrieval of all pending results. client/mysqlbinlog.cc: net_safe_read -> cli_safe_read include/mysql.h: Remove a private function from the public header. include/mysql_com.h: Remove a define that is never used. include/sql_common.h: Add a declaration for cli_safe_read - a function that reads one packet from the server. libmysql/libmysql.c: net_safe_read -> cli_safe_read Return CR_COMMANDS_OUT_OF_SYNC on attempt to execute a statement using a connection which has pending result sets. sql-common/client.c: Actual fix for Bug#15752: if the server has pending result sets for the client, return CR_COMMANDS_OUT_OF_SYNC on attempt to execute another query. Similarly to the behaviour of mysql_use_result(), multiple result sets block the connection and must be fetched before it can be used for another query. This uncovered an error in the protocol: the server doesn't drop SERVER_MORE_RESULTS_EXISTS status flag upon an error, so in case of a multi-query like SELECT 1; SELECT syntax_error; SELECT 2; the client has no way to know that the server won't ever come to execution of the third query and won't return any result sets for it. For now, fix it in cli_safe_read, as a proper fix requires extension of the client-server protocol. sql/protocol.cc: Remove a name that is never used. sql/slave.cc: net_safe_read -> cli_safe_read tests/mysql_client_test.c: Make 'query' a local variable to avoid name clash. Add a test case for Bug#15752 "Lost connection to MySQL server when calling an SP from C API" --- client/mysqlbinlog.cc | 3 +- include/mysql.h | 1 - include/mysql_com.h | 1 - include/sql_common.h | 2 +- libmysql/libmysql.c | 16 ++++---- sql-common/client.c | 69 +++++++++++++++++++-------------- sql/protocol.cc | 2 +- sql/slave.cc | 2 +- tests/mysql_client_test.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++- 9 files changed, 150 insertions(+), 44 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 518ab7cf832..9cecdb4eafc 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -36,6 +36,7 @@ /* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */ #include "mysql_priv.h" #include "log_event.h" +#include "sql_common.h" #define BIN_LOG_HEADER_SIZE 4 #define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4) @@ -1077,7 +1078,7 @@ could be out of memory"); const char *error_msg; Log_event *ev; - len = net_safe_read(mysql); + len= cli_safe_read(mysql); if (len == packet_error) { fprintf(stderr, "Got error reading packet from server: %s\n", diff --git a/include/mysql.h b/include/mysql.h index 3a71e47f414..ae5cf670ec9 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -837,7 +837,6 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); #define simple_command(mysql, command, arg, length, skip_check) \ (*(mysql)->methods->advanced_command)(mysql, command, \ NullS, 0, arg, length, skip_check) -unsigned long net_safe_read(MYSQL* mysql); #ifdef __NETWARE__ #pragma pack(pop) /* restore alignment */ diff --git a/include/mysql_com.h b/include/mysql_com.h index ec1c133799f..60e726396cb 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -140,7 +140,6 @@ enum enum_server_command #define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */ #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ -#define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */ #define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */ #define SERVER_QUERY_NO_GOOD_INDEX_USED 16 #define SERVER_QUERY_NO_INDEX_USED 32 diff --git a/include/sql_common.h b/include/sql_common.h index 9fc8d4f457b..c77a905aeb1 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -35,7 +35,7 @@ my_bool cli_advanced_command(MYSQL *mysql, enum enum_server_command command, const char *header, ulong header_length, const char *arg, ulong arg_length, my_bool skip_check); - +unsigned long cli_safe_read(MYSQL *mysql); void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode, const char *sqlstate); void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate); diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index a851d62b108..884c0b3a4db 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -645,7 +645,7 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd) NET *net= &mysql->net; ulong pkt_length; - pkt_length= net_safe_read(mysql); + pkt_length= cli_safe_read(mysql); if (pkt_length == packet_error) return 1; @@ -666,7 +666,7 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd) return 1; } /* Read what server thinks about out new auth message report */ - if (net_safe_read(mysql) == packet_error) + if (cli_safe_read(mysql) == packet_error) return 1; } return 0; @@ -1887,7 +1887,7 @@ my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) DBUG_ENTER("cli_read_prepare_result"); mysql= mysql->last_used_con; - if ((packet_length= net_safe_read(mysql)) == packet_error) + if ((packet_length= cli_safe_read(mysql)) == packet_error) DBUG_RETURN(1); mysql->warning_count= 0; @@ -2505,7 +2505,8 @@ int cli_stmt_execute(MYSQL_STMT *stmt) if (stmt->param_count) { - NET *net= &stmt->mysql->net; + MYSQL *mysql= stmt->mysql; + NET *net= &mysql->net; MYSQL_BIND *param, *param_end; char *param_data; ulong length; @@ -2517,7 +2518,8 @@ int cli_stmt_execute(MYSQL_STMT *stmt) set_stmt_error(stmt, CR_PARAMS_NOT_BOUND, unknown_sqlstate); DBUG_RETURN(1); } - if (stmt->mysql->status != MYSQL_STATUS_READY) + if (mysql->status != MYSQL_STATUS_READY || + mysql->server_status & SERVER_MORE_RESULTS_EXISTS) { set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); DBUG_RETURN(1); @@ -4531,7 +4533,7 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row) int cli_unbuffered_fetch(MYSQL *mysql, char **row) { - if (packet_error == net_safe_read(mysql)) + if (packet_error == cli_safe_read(mysql)) return 1; *row= ((mysql->net.read_pos[0] == 254) ? NULL : @@ -4640,7 +4642,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt) mysql= mysql->last_used_con; - while ((pkt_len= net_safe_read(mysql)) != packet_error) + while ((pkt_len= cli_safe_read(mysql)) != packet_error) { cp= net->read_pos; if (cp[0] != 254 || pkt_len >= 8) diff --git a/sql-common/client.c b/sql-common/client.c index 31e85475f08..7c5460dd859 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -584,7 +584,7 @@ err: *****************************************************************************/ ulong -net_safe_read(MYSQL *mysql) +cli_safe_read(MYSQL *mysql) { NET *net= &mysql->net; ulong len=0; @@ -627,6 +627,16 @@ net_safe_read(MYSQL *mysql) } else set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate); + /* + Cover a protocol design error: error packet does not + contain the server status. Therefore, the client has no way + to find out whether there are more result sets of + a multiple-result-set statement pending. Luckily, in 5.0 an + error always aborts execution of a statement, wherever it is + a multi-statement or a stored procedure, so it should be + safe to unconditionally turn off the flag here. + */ + mysql->server_status&= ~SERVER_MORE_RESULTS_EXISTS; DBUG_PRINT("error",("Got error: %d/%s (%s)", net->last_errno, net->sqlstate, net->last_error)); @@ -652,7 +662,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, NET *net= &mysql->net; my_bool result= 1; init_sigpipe_variables - DBUG_ENTER("cli_advanced_command"); + DBUG_ENTER("cli_advanced_command"); /* Don't give sigpipe errors if the client doesn't want them */ set_sigpipe(mysql); @@ -662,7 +672,8 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, if (mysql_reconnect(mysql)) DBUG_RETURN(1); } - if (mysql->status != MYSQL_STATUS_READY) + if (mysql->status != MYSQL_STATUS_READY || + mysql->server_status & SERVER_MORE_RESULTS_EXISTS) { DBUG_PRINT("error",("state: %d", mysql->status)); set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); @@ -701,7 +712,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, } result=0; if (!skip_check) - result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ? + result= ((mysql->packet_length=cli_safe_read(mysql)) == packet_error ? 1 : 0); end: reset_sigpipe(mysql); @@ -753,7 +764,7 @@ static void cli_flush_use_result(MYSQL *mysql) for (;;) { ulong pkt_len; - if ((pkt_len=net_safe_read(mysql)) == packet_error) + if ((pkt_len=cli_safe_read(mysql)) == packet_error) break; if (pkt_len <= 8 && mysql->net.read_pos[0] == 254) { @@ -1275,7 +1286,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, NET *net = &mysql->net; DBUG_ENTER("cli_read_rows"); - if ((pkt_len= net_safe_read(mysql)) == packet_error) + if ((pkt_len= cli_safe_read(mysql)) == packet_error) DBUG_RETURN(0); if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), MYF(MY_WME | MY_ZEROFILL)))) @@ -1340,7 +1351,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, } } cur->data[field]=to; /* End of last field */ - if ((pkt_len=net_safe_read(mysql)) == packet_error) + if ((pkt_len=cli_safe_read(mysql)) == packet_error) { free_rows(result); DBUG_RETURN(0); @@ -1372,7 +1383,7 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) uchar *pos, *prev_pos, *end_pos; NET *net= &mysql->net; - if ((pkt_len=net_safe_read(mysql)) == packet_error) + if ((pkt_len=cli_safe_read(mysql)) == packet_error) return -1; if (pkt_len <= 8 && net->read_pos[0] == 254) { @@ -1649,23 +1660,23 @@ static MYSQL_RES *cli_use_result(MYSQL *mysql); static MYSQL_METHODS client_methods= { - cli_read_query_result, - cli_advanced_command, - cli_read_rows, - cli_use_result, - cli_fetch_lengths, - cli_flush_use_result + cli_read_query_result, /* read_query_result */ + cli_advanced_command, /* advanced_command */ + cli_read_rows, /* read_rows */ + cli_use_result, /* use_result */ + cli_fetch_lengths, /* fetch_lengths */ + cli_flush_use_result /* flush_use_result */ #ifndef MYSQL_SERVER - ,cli_list_fields, - cli_read_prepare_result, - cli_stmt_execute, - cli_read_binary_rows, - cli_unbuffered_fetch, - NULL, - cli_read_statistics, - cli_read_query_result, - cli_read_change_user_result, - cli_read_binary_rows + ,cli_list_fields, /* list_fields */ + cli_read_prepare_result, /* read_prepare_result */ + cli_stmt_execute, /* stmt_execute */ + cli_read_binary_rows, /* read_binary_rows */ + cli_unbuffered_fetch, /* unbuffered_fetch */ + NULL, /* free_embedded_thd */ + cli_read_statistics, /* read_statistics */ + cli_read_query_result, /* next_result */ + cli_read_change_user_result, /* read_change_user_result */ + cli_read_binary_rows /* read_rows_from_cursor */ #endif }; @@ -1999,7 +2010,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, Part 1: Connection established, read and parse first packet */ - if ((pkt_length=net_safe_read(mysql)) == packet_error) + if ((pkt_length=cli_safe_read(mysql)) == packet_error) goto error; /* Check if version of protocol matches current one */ @@ -2223,7 +2234,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, OK-packet, or re-request scrambled password. */ - if ((pkt_length=net_safe_read(mysql)) == packet_error) + if ((pkt_length=cli_safe_read(mysql)) == packet_error) goto error; if (pkt_length == 1 && net->read_pos[0] == 254 && @@ -2240,7 +2251,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, goto error; } /* Read what server thinks about out new auth message report */ - if (net_safe_read(mysql) == packet_error) + if (cli_safe_read(mysql) == packet_error) goto error; } @@ -2564,7 +2575,7 @@ static my_bool cli_read_query_result(MYSQL *mysql) */ mysql = mysql->last_used_con; - if ((length = net_safe_read(mysql)) == packet_error) + if ((length = cli_safe_read(mysql)) == packet_error) DBUG_RETURN(1); free_old_query(mysql); /* Free old result */ #ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/ @@ -2599,7 +2610,7 @@ get_info: if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ { int error=handle_local_infile(mysql,(char*) pos); - if ((length=net_safe_read(mysql)) == packet_error || error) + if ((length= cli_safe_read(mysql)) == packet_error || error) DBUG_RETURN(1); goto get_info; /* Get info packet */ } diff --git a/sql/protocol.cc b/sql/protocol.cc index 650bd8fc58f..f4efb8004ee 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -322,7 +322,7 @@ static char eof_buff[1]= { (char) 254 }; /* Marker for end of fields */ 254 Marker (1 byte) warning_count Stored in 2 bytes; New in 4.1 protocol status_flag Stored in 2 bytes; - For flags like SERVER_STATUS_MORE_RESULTS + For flags like SERVER_MORE_RESULTS_EXISTS Note that the warning count will not be sent if 'no_flush' is set as we don't want to report the warning count until all data is sent to the diff --git a/sql/slave.cc b/sql/slave.cc index b284f4a6a16..eb578f69cb0 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3051,7 +3051,7 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings) return packet_error; #endif - len = net_safe_read(mysql); + len = cli_safe_read(mysql); if (len == packet_error || (long) len < 1) { if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 7ad902afb6c..def67e22f00 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -50,7 +50,6 @@ static unsigned int opt_port; static my_bool tty_password= 0, opt_silent= 0; static MYSQL *mysql= 0; -static char query[MAX_TEST_QUERY_LENGTH]; static char current_db[]= "client_test_db"; static unsigned int test_count= 0; static unsigned int opt_count= 0; @@ -269,6 +268,7 @@ mysql_simple_prepare(MYSQL *mysql, const char *query) static void client_connect(ulong flag) { int rc; + static char query[MAX_TEST_QUERY_LENGTH]; myheader_r("client_connect"); if (!opt_silent) @@ -326,6 +326,8 @@ static void client_connect(ulong flag) static void client_disconnect() { + static char query[MAX_TEST_QUERY_LENGTH]; + myheader_r("client_disconnect"); if (mysql) @@ -657,6 +659,7 @@ int my_stmt_result(const char *buff) static void verify_col_data(const char *table, const char *col, const char *exp_data) { + static char query[MAX_TEST_QUERY_LENGTH]; MYSQL_RES *result; MYSQL_ROW row; int rc, field= 1; @@ -1362,6 +1365,7 @@ static void test_prepare_insert_update() for (cur_query= testcase; *cur_query; cur_query++) { + char query[MAX_TEST_QUERY_LENGTH]; printf("\nRunning query: %s", *cur_query); strmov(query, *cur_query); stmt= mysql_simple_prepare(mysql, query); @@ -1396,6 +1400,7 @@ static void test_prepare_simple() { MYSQL_STMT *stmt; int rc; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare_simple"); @@ -1466,6 +1471,7 @@ static void test_prepare_field_result() MYSQL_STMT *stmt; MYSQL_RES *result; int rc; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare_field_result"); @@ -1517,6 +1523,7 @@ static void test_prepare_syntax() { MYSQL_STMT *stmt; int rc; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare_syntax"); @@ -1558,6 +1565,7 @@ static void test_prepare() my_bool is_null[7]; char llbuf[22]; MYSQL_BIND bind[7]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare"); @@ -1731,6 +1739,7 @@ static void test_double_compare() MYSQL_RES *result; MYSQL_BIND bind[3]; ulong length[3]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_double_compare"); @@ -1813,6 +1822,7 @@ static void test_null() uint nData; MYSQL_BIND bind[2]; my_bool is_null[2]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_null"); @@ -1959,6 +1969,7 @@ static void test_ps_null_param() /* Execute several queries, all returning NULL in result. */ for(cur_query= queries; *cur_query; cur_query++) { + char query[MAX_TEST_QUERY_LENGTH]; strmov(query, *cur_query); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -1990,6 +2001,7 @@ static void test_fetch_null() MYSQL_BIND bind[11]; ulong length[11]; my_bool is_null[11]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_fetch_null"); @@ -2218,6 +2230,7 @@ static void test_select() int nData= 1; MYSQL_BIND bind[2]; ulong length[2]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_select"); @@ -2289,6 +2302,7 @@ static void test_ps_conj_select() int32 int_data; char str_data[32]; unsigned long str_length; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_ps_conj_select"); rc= mysql_query(mysql, "drop table if exists t1"); @@ -2346,6 +2360,7 @@ static void test_bug1115() MYSQL_BIND bind[1]; ulong length[1]; char szData[11]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_bug1115"); @@ -2457,6 +2472,7 @@ static void test_bug1180() MYSQL_BIND bind[1]; ulong length[1]; char szData[11]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_select_bug"); @@ -2547,6 +2563,7 @@ static void test_bug1644() int num; my_bool isnull; int rc, i; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_bug1644"); @@ -2646,6 +2663,7 @@ static void test_select_show() { MYSQL_STMT *stmt; int rc; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_select_show"); @@ -2714,6 +2732,7 @@ static void test_simple_update() MYSQL_RES *result; MYSQL_BIND bind[2]; ulong length[2]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_simple_update"); @@ -2791,6 +2810,7 @@ static void test_long_data() char *data= NullS; MYSQL_RES *result; MYSQL_BIND bind[3]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_long_data"); @@ -2877,6 +2897,7 @@ static void test_long_data_str() MYSQL_RES *result; MYSQL_BIND bind[2]; my_bool is_null[2]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_long_data_str"); @@ -2969,6 +2990,7 @@ static void test_long_data_str1() MYSQL_RES *result; MYSQL_BIND bind[2]; MYSQL_FIELD *field; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_long_data_str1"); @@ -3124,6 +3146,7 @@ static void test_long_data_bin() long length; MYSQL_RES *result; MYSQL_BIND bind[2]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_long_data_bin"); @@ -3203,6 +3226,7 @@ static void test_simple_delete() MYSQL_RES *result; MYSQL_BIND bind[2]; ulong length[2]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_simple_delete"); @@ -3285,6 +3309,7 @@ static void test_update() MYSQL_RES *result; MYSQL_BIND bind[2]; ulong length[2]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_update"); @@ -3381,6 +3406,7 @@ static void test_prepare_noparam() MYSQL_STMT *stmt; int rc; MYSQL_RES *result; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare_noparam"); @@ -4237,6 +4263,7 @@ static void test_prepare_ext() short sData= 10; longlong bData= 20; MYSQL_BIND bind[6]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare_ext"); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext"); @@ -4624,6 +4651,7 @@ static void test_stmt_close() MYSQL_RES *result; unsigned int count; int rc; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_stmt_close"); @@ -5270,6 +5298,7 @@ static void test_manual_sample() ulonglong affected_rows; MYSQL_BIND bind[3]; my_bool is_null; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_manual_sample"); @@ -5624,6 +5653,7 @@ static void test_prepare_multi_statements() { MYSQL *mysql_local; MYSQL_STMT *stmt; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare_multi_statements"); if (!(mysql_local= mysql_init(NULL))) @@ -5841,6 +5871,7 @@ static void test_store_result2() int nData; ulong length; MYSQL_BIND bind[1]; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_store_result2"); @@ -7120,6 +7151,7 @@ static void test_set_option() static void test_prepare_grant() { int rc; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_prepare_grant"); @@ -8592,6 +8624,7 @@ static void test_sqlmode() MYSQL_BIND bind[2]; char c1[5], c2[5]; int rc; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_sqlmode"); @@ -8735,6 +8768,7 @@ static void test_ts() ulong length; int rc, field_count; char name; + char query[MAX_TEST_QUERY_LENGTH]; myheader("test_ts"); @@ -15019,6 +15053,65 @@ static void test_bug20152() } } +/* Bug#15752 "Lost connection to MySQL server when calling a SP from C API" */ + +static void test_bug15752() +{ + MYSQL mysql_local; + int rc, i; + const int ITERATION_COUNT= 100; + char *query= "CALL p1()"; + + myheader("test_bug15752"); + + rc= mysql_query(mysql, "drop procedure if exists p1"); + myquery(rc); + rc= mysql_query(mysql, "create procedure p1() select 1"); + myquery(rc); + + mysql_init(&mysql_local); + if (! mysql_real_connect(&mysql_local, opt_host, opt_user, + opt_password, current_db, opt_port, + opt_unix_socket, + CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS)) + { + printf("Unable connect to MySQL server: %s\n", mysql_error(&mysql_local)); + DIE_UNLESS(0); + } + rc= mysql_real_query(&mysql_local, query, strlen(query)); + myquery(rc); + mysql_free_result(mysql_store_result(&mysql_local)); + + rc= mysql_real_query(&mysql_local, query, strlen(query)); + DIE_UNLESS(rc && mysql_errno(&mysql_local) == CR_COMMANDS_OUT_OF_SYNC); + + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(&mysql_local)); + + /* Check some other commands too */ + + DIE_UNLESS(mysql_next_result(&mysql_local) == 0); + mysql_free_result(mysql_store_result(&mysql_local)); + DIE_UNLESS(mysql_next_result(&mysql_local) == -1); + + /* The second problem is not reproducible: add the test case */ + for (i = 0; i < ITERATION_COUNT; i++) + { + if (mysql_real_query(&mysql_local, query, strlen(query))) + { + printf("\ni=%d %s failed: %s\n", i, query, mysql_error(&mysql_local)); + break; + } + mysql_free_result(mysql_store_result(&mysql_local)); + DIE_UNLESS(mysql_next_result(&mysql_local) == 0); + mysql_free_result(mysql_store_result(&mysql_local)); + DIE_UNLESS(mysql_next_result(&mysql_local) == -1); + + } + mysql_close(&mysql_local); + rc= mysql_query(mysql, "drop procedure p1"); + myquery(rc); +} /* Read and parse arguments and MySQL options from my.cnf @@ -15287,7 +15380,8 @@ static struct my_tests_st my_tests[]= { { "test_bug20152", test_bug20152 }, { "test_bug14169", test_bug14169 }, { "test_bug17667", test_bug17667 }, - { "test_bug19671", test_bug19671}, + { "test_bug19671", test_bug19671 }, + { "test_bug15752", test_bug15752 }, { 0, 0 } }; -- cgit v1.2.1 From 3037459ad50cd06c6b8c04b942f505d0f00a9634 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 15:10:50 +0400 Subject: BUG#14702: misleading error message when syntax error in CREATE PROCEDURE The bug was fixed already. This changeset adds a test case. mysql-test/r/sp-error.result: Add result for bug#14702: misleading error message when syntax error in CREATE PROCEDURE. mysql-test/t/sp-error.test: Add test case for bug#14702: misleading error message when syntax error in CREATE PROCEDURE. --- mysql-test/r/sp-error.result | 13 +++++++++++++ mysql-test/t/sp-error.test | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 924963017eb..da1fc58db57 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1174,3 +1174,16 @@ drop procedure bug15091; drop function if exists bug16896; create aggregate function bug16896() returns int return 1; ERROR 42000: AGGREGATE is not supported for stored functions +DROP PROCEDURE IF EXISTS bug14702; +CREATE IF NOT EXISTS PROCEDURE bug14702() +BEGIN +END; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS PROCEDURE bug14702() +BEGIN +END' at line 1 +CREATE PROCEDURE IF NOT EXISTS bug14702() +BEGIN +END; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS bug14702() +BEGIN +END' at line 1 diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index a4ab5d98922..2abb923efbb 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1706,6 +1706,28 @@ drop function if exists bug16896; create aggregate function bug16896() returns int return 1; +# +# BUG#14702: misleading error message when syntax error in CREATE +# PROCEDURE +# +# Misleading error message was given when IF NOT EXISTS was used in +# CREATE PROCEDURE. +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug14702; +--enable_warnings + +--error ER_PARSE_ERROR +CREATE IF NOT EXISTS PROCEDURE bug14702() +BEGIN +END; + +--error ER_PARSE_ERROR +CREATE PROCEDURE IF NOT EXISTS bug14702() +BEGIN +END; + + # # BUG#NNNN: New bug synopsis # -- cgit v1.2.1 From 568b49fb7dad0a08a4d57925fd5083f184169cdf Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 14:31:37 +0200 Subject: Bug#21125 mysqldump: Problem with non-standard table names - The mysql-test/std_data/bug15328.cnf file was not copied to install or dist dir. mysql-test/Makefile.am: Add std_data/*.cnf files to dist_hook and install-data-local scripts/make_win_src_distribution.sh: Copy *.cnf files as well. --- mysql-test/Makefile.am | 2 ++ scripts/make_win_src_distribution.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index 7c2415dd6b6..cd939417e64 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -60,6 +60,7 @@ dist-hook: $(INSTALL_DATA) $(srcdir)/std_data/*.dat $(srcdir)/std_data/*.000001 $(distdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(distdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/*.pem $(distdir)/std_data + $(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(distdir)/std_data $(INSTALL_DATA) $(srcdir)/lib/init_db.sql $(distdir)/lib $(INSTALL_DATA) $(srcdir)/lib/*.pl $(distdir)/lib @@ -83,6 +84,7 @@ install-data-local: $(INSTALL_DATA) $(srcdir)/include/*.inc $(DESTDIR)$(testdir)/include $(INSTALL_DATA) $(srcdir)/std_data/*.dat $(DESTDIR)$(testdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/*.*001 $(DESTDIR)$(testdir)/std_data + $(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(DESTDIR)$(testdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(DESTDIR)$(testdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/*.pem $(DESTDIR)$(testdir)/std_data diff --git a/scripts/make_win_src_distribution.sh b/scripts/make_win_src_distribution.sh index 4e5cc2ada46..742f6b9e994 100644 --- a/scripts/make_win_src_distribution.sh +++ b/scripts/make_win_src_distribution.sh @@ -206,7 +206,7 @@ copy_dir_files() for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def *.hpp *.yy \ README INSTALL* LICENSE AUTHORS NEWS ChangeLog \ *.inc *.test *.result *.pem Moscow_leap des_key_file \ - *.vcproj *.sln *.dat *.000001 *.require *.opt + *.vcproj *.sln *.dat *.000001 *.require *.opt *.cnf do if [ -f $i ] then -- cgit v1.2.1 From d64f605e48d42bc9a8fa33e206e427eab69b1a24 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 19:05:46 -0700 Subject: Fixed bug #21231: wrong results for a simple query with a a non-correlated single-row subquery over information schema. The function get_all_tables filling all information schema tables reset lex->sql_command to SQLCOM_SHOW_FIELDS. After this the function could evaluate partial conditions related to some columns. If these conditions contained a subquery over information schema it led to a wrong evaluation and a wrong result set. This bug was already fixed in 5.1. This patch follows the way how it was done in 5.1 where the value of lex->sql_command is set to SQLCOM_SHOW_FIELDS in get_all_tables only for the calls of the function open_normal_and_derived_tables and is restored after these calls. mysql-test/r/information_schema.result: Added a test case for bug #21231. mysql-test/t/information_schema.test: Added a test case for bug #21231. --- mysql-test/r/information_schema.result | 8 ++++++++ mysql-test/t/information_schema.test | 10 ++++++++++ sql/sql_show.cc | 16 ++++++++++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 3b3669119d5..652af1c8387 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1232,3 +1232,11 @@ TABLE_PRIVILEGES TABLE_SCHEMA TRIGGERS TRIGGER_SCHEMA USER_PRIVILEGES GRANTEE VIEWS TABLE_SCHEMA +SELECT MAX(table_name) FROM information_schema.tables; +MAX(table_name) +VIEWS +SELECT table_name from information_schema.tables +WHERE table_name=(SELECT MAX(table_name) +FROM information_schema.tables); +table_name +VIEWS diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index b49ec9e2f31..9e5dac8b853 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -920,4 +920,14 @@ SELECT t.table_name, c1.column_name c2.column_name LIKE '%SCHEMA%' ); +# +# Bug#21231: query with a simple non-correlated subquery over +# INFORMARTION_SCHEMA.TABLES +# + +SELECT MAX(table_name) FROM information_schema.tables; +SELECT table_name from information_schema.tables + WHERE table_name=(SELECT MAX(table_name) + FROM information_schema.tables); + # End of 5.0 tests. diff --git a/sql/sql_show.cc b/sql/sql_show.cc index e2adefb0ca9..e22873dad9a 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2116,12 +2116,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) LINT_INIT(end); LINT_INIT(len); - /* - Let us set fake sql_command so views won't try to merge - themselves into main statement. - */ - lex->sql_command= SQLCOM_SHOW_FIELDS; - lex->reset_n_backup_query_tables_list(&query_tables_list_backup); /* @@ -2144,8 +2138,16 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) I_S tables will be done. */ thd->temporary_tables= open_tables_state_backup.temporary_tables; + /* + Let us set fake sql_command so views won't try to merge + themselves into main statement. If we don't do this, + SELECT * from information_schema.xxxx will cause problems. + SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()' + */ + lex->sql_command= SQLCOM_SHOW_FIELDS; res= open_normal_and_derived_tables(thd, show_table_list, MYSQL_LOCK_IGNORE_FLUSH); + lex->sql_command= save_sql_command; /* get_all_tables() returns 1 on failure and 0 on success thus return only these and not the result code of ::process_table() @@ -2267,8 +2269,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first; lex->all_selects_list= &sel; lex->derived_tables= 0; + lex->sql_command= SQLCOM_SHOW_FIELDS; res= open_normal_and_derived_tables(thd, show_table_list, MYSQL_LOCK_IGNORE_FLUSH); + lex->sql_command= save_sql_command; /* We should use show_table_list->alias instead of show_table_list->table_name because table_name -- cgit v1.2.1 From 4e7121c07b0cfb5ed39e25edd9022ba1811d65fa Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Jul 2006 11:45:10 +0300 Subject: Bug#16712: group_concat returns odd srting insead of intended result when calculating GROUP_CONCAT all blob fields are transformed to varchar when making the temp table. However a varchar has at max 2 bytes for length. This fix makes the conversion only for blobs whose max length is below that limit. Otherwise blob field is created by make_string_field() call. mysql-test/r/func_gconcat.result: Bug#16712: group_concat returns odd srting insead of intended result * testsuite for the bug mysql-test/t/func_gconcat.test: Bug#16712: group_concat returns odd srting insead of intended result * testsuite for the bug sql/item_sum.cc: Bug#16712: group_concat returns odd srting insead of intended result * force blob->varchar conversion for small enough blobs only sql/sql_select.cc: Bug#16712: group_concat returns odd srting insead of intended result * force blob->varchar conversion for small enough blobs only --- mysql-test/r/func_gconcat.result | 13 +++++++++++++ mysql-test/t/func_gconcat.test | 14 ++++++++++++++ sql/item_sum.cc | 8 +++++++- sql/sql_select.cc | 14 ++++++++++++-- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result index d8a539da3fe..dc09a68682c 100644 --- a/mysql-test/r/func_gconcat.result +++ b/mysql-test/r/func_gconcat.result @@ -641,3 +641,16 @@ select charset(group_concat(c1 order by c2)) from t1; charset(group_concat(c1 order by c2)) latin1 drop table t1; +CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a)); +SET GROUP_CONCAT_MAX_LEN = 20000000; +INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000)); +INSERT INTO t1 SELECT a + 1, b FROM t1; +SELECT a, CHAR_LENGTH(b) FROM t1; +a CHAR_LENGTH(b) +1 120000 +2 120000 +SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1; +CHAR_LENGTH( GROUP_CONCAT(b) ) +240001 +SET GROUP_CONCAT_MAX_LEN = 1024; +DROP TABLE t1; diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index fbfdfa3b5d0..98c21986aa9 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -433,3 +433,17 @@ create table t1 (c1 varchar(10), c2 int); select charset(group_concat(c1 order by c2)) from t1; drop table t1; +# +# Bug #16712: group_concat returns odd string instead of intended result +# +CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a)); + +SET GROUP_CONCAT_MAX_LEN = 20000000; + +INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000)); +INSERT INTO t1 SELECT a + 1, b FROM t1; + +SELECT a, CHAR_LENGTH(b) FROM t1; +SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1; +SET GROUP_CONCAT_MAX_LEN = 1024; +DROP TABLE t1; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 877eb908d27..69b93909b3c 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -377,7 +377,13 @@ Field *Item_sum::create_tmp_field(bool group, TABLE *table, case INT_RESULT: return new Field_longlong(max_length,maybe_null,name,table,unsigned_flag); case STRING_RESULT: - if (max_length/collation.collation->mbmaxlen > 255 && convert_blob_length) + /* + Make sure that the blob fits into a Field_varstring which has + 2-byte lenght. + */ + if (max_length/collation.collation->mbmaxlen > 255 && + max_length/collation.collation->mbmaxlen < UINT_MAX16 && + convert_blob_length) return new Field_varstring(convert_blob_length, maybe_null, name, table, collation.collation); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 41ff9185cfb..6f3e6d8868d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8011,7 +8011,12 @@ Field* create_tmp_field_from_field(THD *thd, Field* org_field, { Field *new_field; - if (convert_blob_length && (org_field->flags & BLOB_FLAG)) + /* + Make sure that the blob fits into a Field_varstring which has + 2-byte lenght. + */ + if (convert_blob_length && convert_blob_length < UINT_MAX16 && + (org_field->flags & BLOB_FLAG)) new_field= new Field_varstring(convert_blob_length, org_field->maybe_null(), org_field->field_name, table, @@ -8087,8 +8092,13 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table, if ((type= item->field_type()) == MYSQL_TYPE_DATETIME || type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE) new_field= item->tmp_table_field_from_field_type(table); + /* + Make sure that the blob fits into a Field_varstring which has + 2-byte lenght. + */ else if (item->max_length/item->collation.collation->mbmaxlen > 255 && - convert_blob_length) + item->max_length/item->collation.collation->mbmaxlen < UINT_MAX16 + && convert_blob_length) new_field= new Field_varstring(convert_blob_length, maybe_null, item->name, table, item->collation.collation); -- cgit v1.2.1 From 1b3cdb6085c944e1c371779d4d4b6473ebcd116d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Jul 2006 18:42:49 +0300 Subject: Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE clause is called When executing INSERT over a view with calculated columns it was assuming all elements of the fields collection are actually Item_field instances. This may not be true when inserting into a view and that view has columns that are such expressions that allow updating (like setting a collation for example). Corrected to access field information through the filed_for_view_update() function and retrieve correctly the field info even for "update-friendly" non-Item_field items. mysql-test/r/view.result: Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE clause is called - test suite mysql-test/t/view.test: Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE clause is called - test suite sql/item_strfunc.h: Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE clause is called - obvious typo fixed sql/sql_base.cc: Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE clause is called - must access field information through the filed_for_view_update() function to retrieve correctly the field info even for "update-friendly" non-Item_field items. --- mysql-test/r/view.result | 13 +++++++++++++ mysql-test/t/view.test | 19 +++++++++++++++++++ sql/item_strfunc.h | 2 +- sql/sql_base.cc | 9 +++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index c8a673e2209..b2c65423b59 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2807,3 +2807,16 @@ yadda yad DROP VIEW v1; DROP TABLE t1; +CREATE TABLE t1 (s1 char); +INSERT INTO t1 VALUES ('Z'); +CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1; +CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1; +INSERT INTO v1 (col) VALUES ('b'); +INSERT INTO v2 (col) VALUES ('c'); +SELECT s1 FROM t1; +s1 +Z +b +c +DROP VIEW v1, v2; +DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 6399cef9086..1b930353ca4 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2667,3 +2667,22 @@ SELECT * FROM v1; DROP VIEW v1; DROP TABLE t1; + +# +# Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE +# clause is called +# +CREATE TABLE t1 (s1 char); +INSERT INTO t1 VALUES ('Z'); + +CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1; + +CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1; + +# either of these statements will cause crash +INSERT INTO v1 (col) VALUES ('b'); +INSERT INTO v2 (col) VALUES ('c'); + +SELECT s1 FROM t1; +DROP VIEW v1, v2; +DROP TABLE t1; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index a72182abcf7..488dc20b063 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -728,7 +728,7 @@ public: void fix_length_and_dec(); bool eq(const Item *item, bool binary_cmp) const; const char *func_name() const { return "collate"; } - enum Functype func_type() const { return COLLATE_FUNC; } + enum Functype functype() const { return COLLATE_FUNC; } void print(String *str); Item_field *filed_for_view_update() { diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 7f9076bb46e..28edee5c729 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4959,12 +4959,17 @@ fill_record(THD * thd, List &fields, List &values, bool ignore_errors) { List_iterator_fast f(fields),v(values); - Item *value; + Item *value, *fld; Item_field *field; DBUG_ENTER("fill_record"); - while ((field=(Item_field*) f++)) + while ((fld= f++)) { + if (!(field= fld->filed_for_view_update())) + { + my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name); + DBUG_RETURN(TRUE); + } value=v++; Field *rfield= field->field; TABLE *table= rfield->table; -- cgit v1.2.1 From 9a63adc8fd18489aa3a75c7715abaea0dcd16349 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 00:31:29 +0400 Subject: Fixed bug#19862: Sort with filesort by function evaluates function twice When there is no index defined filesort is used to sort the result of a query. If there is a function in the select list and the result set should be ordered by it's value then this function will be evaluated twice. First time to get the value of the sort key and second time to send its value to a user. This happens because filesort when sorts a table remembers only values of its fields but not values of functions. All functions are affected. But taking into account that SP and UDF functions can be both expensive and non-deterministic a temporary table should be used to store their results and then sort it to avoid twice SP evaluation and to get a correct result. If an expression referenced in an ORDER clause contains a SP or UDF function, force the use of a temporary table. A new Item_processor function called func_type_checker_processor is added to check whether the expression contains a function of a particular type. mysql-test/t/udf.test: Added test case for bug#19862: Sort with filesort by function evaluates function twice mysql-test/t/sp.test: Added test case for bug#19862: Sort with filesort by function evaluates function twice mysql-test/r/sp.result: Added test case for bug#19862: Sort with filesort by function evaluates function twice mysql-test/r/udf.result: Added test case for bug#19862: Sort with filesort by function evaluates function twice sql/sql_select.cc: Fixed bug#19862: Sort with filesort by function evaluates function twice If an expression referenced in an ORDER clause contains a SP or UDF function, force the use of a temporary table. sql/item_func.h: Fixed bug#19862: Sort with filesort by function evaluates function twice A new Item_processor function called func_type_checker_processor is added to check whether the expression contains a function of a particular type. sql/item.h: Fixed bug#19862: Sort with filesort by function evaluates function twice A new Item_processor function called func_type_checker_processor is added to check whether the expression contains a function of a particular type. sql/item_func.cc: Fixed bug#19862: Sort with filesort by function evaluates function twice A new Item_processor function called func_type_checker_processor is added to check whether the expression contains a function of a particular type. --- mysql-test/r/sp.result | 19 +++++++++++++++++++ mysql-test/r/udf.result | 6 ++++++ mysql-test/t/sp.test | 18 ++++++++++++++++++ mysql-test/t/udf.test | 7 +++++++ sql/item.h | 1 + sql/item_func.cc | 7 +++++++ sql/item_func.h | 4 +++- sql/sql_select.cc | 20 ++++++++++++++++++++ 8 files changed, 81 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 50913fb1b90..f04b5b2c635 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5057,4 +5057,23 @@ concat('data was: /', var1, '/') data was: /1/ drop table t3| drop procedure bug15217| +drop procedure if exists bug19862| +CREATE TABLE t11 (a INT)| +CREATE TABLE t12 (a INT)| +CREATE FUNCTION bug19862(x INT) RETURNS INT +BEGIN +INSERT INTO t11 VALUES (x); +RETURN x+1; +END| +INSERT INTO t12 VALUES (1), (2)| +SELECT bug19862(a) FROM t12 ORDER BY 1| +bug19862(a) +2 +3 +SELECT * FROM t11| +a +1 +2 +DROP TABLE t11, t12| +DROP FUNCTION bug19862| drop table t1,t2; diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result index 484c42c41bf..b44dce14230 100644 --- a/mysql-test/r/udf.result +++ b/mysql-test/r/udf.result @@ -93,6 +93,12 @@ NULL 0R FR DROP TABLE bug19904; +create table t1(f1 int); +insert into t1 values(1),(2); +explain select myfunc_int(f1) from t1 order by 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +drop table t1; End of 5.0 tests. DROP FUNCTION metaphon; DROP FUNCTION myfunc_double; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 25c96042e6f..cb9972fb800 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5962,6 +5962,24 @@ call bug15217()| drop table t3| drop procedure bug15217| +# +# BUG#19862: Sort with filesort by function evaluates function twice +# +--disable_warnings +drop procedure if exists bug19862| +--enable_warnings +CREATE TABLE t11 (a INT)| +CREATE TABLE t12 (a INT)| +CREATE FUNCTION bug19862(x INT) RETURNS INT + BEGIN + INSERT INTO t11 VALUES (x); + RETURN x+1; + END| +INSERT INTO t12 VALUES (1), (2)| +SELECT bug19862(a) FROM t12 ORDER BY 1| +SELECT * FROM t11| +DROP TABLE t11, t12| +DROP FUNCTION bug19862| # # BUG#NNNN: New bug synopsis # diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index f3be08c8537..560ec88eb10 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -109,6 +109,13 @@ SELECT myfunc_double(n) AS f FROM bug19904; SELECT metaphon(v) AS f FROM bug19904; DROP TABLE bug19904; +# +# Bug#19862: Sort with filesort by function evaluates function twice +# +create table t1(f1 int); +insert into t1 values(1),(2); +explain select myfunc_int(f1) from t1 order by 1; +drop table t1; --echo End of 5.0 tests. # diff --git a/sql/item.h b/sql/item.h index 0f49145082f..c59d84aaeaa 100644 --- a/sql/item.h +++ b/sql/item.h @@ -752,6 +752,7 @@ public: virtual bool find_item_in_field_list_processor(byte *arg) { return 0; } virtual bool change_context_processor(byte *context) { return 0; } virtual bool reset_query_id_processor(byte *query_id) { return 0; } + virtual bool func_type_checker_processor(byte *arg) { return 0; } virtual Item *equal_fields_propagator(byte * arg) { return this; } virtual Item *set_no_const_sub(byte *arg) { return this; } diff --git a/sql/item_func.cc b/sql/item_func.cc index 1d906b300b6..c31ac2bf047 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -398,6 +398,13 @@ Field *Item_func::tmp_table_field(TABLE *t_arg) return res; } + +bool Item_func::func_type_checker_processor(byte *arg) +{ + return *((Functype*)arg) == functype(); +} + + my_decimal *Item_func::val_decimal(my_decimal *decimal_value) { DBUG_ASSERT(fixed); diff --git a/sql/item_func.h b/sql/item_func.h index 2ca4be9f3f2..88a52d7f46e 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -55,7 +55,7 @@ public: NOT_FUNC, NOT_ALL_FUNC, NOW_FUNC, TRIG_COND_FUNC, GUSERVAR_FUNC, COLLATE_FUNC, - EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP }; + EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC }; enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL, OPTIMIZE_EQUAL }; enum Type type() const { return FUNC_ITEM; } @@ -186,6 +186,7 @@ public: Item *transform(Item_transformer transformer, byte *arg); void traverse_cond(Cond_traverser traverser, void * arg, traverse_order order); + bool func_type_checker_processor(byte *arg); }; @@ -930,6 +931,7 @@ public: Item_udf_func(udf_func *udf_arg, List &list) :Item_func(list), udf(udf_arg) {} const char *func_name() const { return udf.name(); } + enum Functype functype() const { return UDF_FUNC; } bool fix_fields(THD *thd, Item **ref) { DBUG_ASSERT(fixed == 0); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a7158960ed0..14389a57465 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1064,6 +1064,26 @@ JOIN::optimize() { need_tmp=1; simple_order=simple_group=0; // Force tmp table without sort } + if (order) + { + /* + Force using of tmp table if sorting by a SP or UDF function due to + their expensive and probably non-deterministic nature. + */ + for (ORDER *tmp_order= order; tmp_order ; tmp_order=tmp_order->next) + { + Item *item= *tmp_order->item; + Item_func::Functype type=Item_func::FUNC_SP; + Item_func::Functype type1=Item_func::UDF_FUNC; + if (item->walk(&Item::func_type_checker_processor,(byte*)&type) || + item->walk(&Item::func_type_checker_processor,(byte*)&type1)) + { + /* Force tmp table without sort */ + need_tmp=1; simple_order=simple_group=0; + break; + } + } + } } tmp_having= having; -- cgit v1.2.1 From 585b5bbc922f9b8a972f7b8d54c93c5eb3683b22 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 01:11:19 +0300 Subject: Fix for BUG#20954: avg(keyval) retuns 0.38 but max(keyval) returns an empty set The problem was in that opt_sum_query() replaced MIN/MAX functions with the corresponding constant found in a key, but due to imprecise representation of float numbers, when evaluating the where clause, this comparison failed. When MIN/MAX optimization detects that all tables can be removed, also remove all conjuncts in a where clause that refer to these tables. As a result of this fix, these conditions are not evaluated twice, and in the case of float number comparisons we do not discard result rows due to imprecise float representation. As a side-effect this fix also corrects an unnoticed problem in bug 12882. mysql-test/r/func_group.result: BUG#20954 - test result adjustment. Adjusted the test result of bug 12882 which was not preperly fixed. The current patch corrects the problem that was fully corrected by the patch for 12882. The problem was that opt_sum_query() indicated that the optimizer may remove all tables because all MIN/MAX/COUNT functions are constants, but this lead to an empty result instead of NULL because the WHERE clause was still evaluated. The current fix removes all conjuncts in the where clause that reference the removed tables, and thus corrects the problem. mysql-test/r/select.result: BUG#20954 - added test mysql-test/r/subselect.result: BUG#20954 - test result adjustment. The fix removes those conditions in a where clause that refer to tables optimized away by MIN/MAX optimization (opt_sum_query()). mysql-test/t/select.test: BUG#20954 - added test sql/sql_select.cc: Fix for BUG#20954: avg(keyval) retuns 0.38 but max(keyval) returns an empty set When MIN/MAX optimization detects that all tables can be removed, also remove all conjuncts in a where clause that refer to these tables. As a result of this fix, these conditions are not evaluated twice, and in the case of float number comparisons we do not discard result rows due to imprecise float representation. As a side-effect this fix also corrects an unnoticed problem in bug 12882. --- mysql-test/r/func_group.result | 2 ++ mysql-test/r/select.result | 49 ++++++++++++++++++++++++++++++++++++++++++ mysql-test/r/subselect.result | 2 +- mysql-test/t/select.test | 30 ++++++++++++++++++++++++++ sql/sql_select.cc | 18 ++++++++++++++++ 5 files changed, 100 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index ffa68f279f3..932ef133087 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -824,6 +824,7 @@ select 1, min(a) from t1m where 1=99; 1 NULL select 1, min(1) from t1m where a=99; 1 min(1) +1 NULL select 1, min(1) from t1m where 1=99; 1 min(1) 1 NULL @@ -835,6 +836,7 @@ select 1, max(a) from t1m where 1=99; 1 NULL select 1, max(1) from t1m where a=99; 1 max(1) +1 NULL select 1, max(1) from t1m where 1=99; 1 max(1) 1 NULL diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index c7df11ab018..d7c01fa5a57 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2744,3 +2744,52 @@ SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1; i='1e+01' i=1e+01 i in (1e+01) i in ('1e+01') 0 1 1 1 DROP TABLE t1; +CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1)); +CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2)); +INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941); +INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941); +explain select max(key1) from t1 where key1 <= 0.6158; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select max(key2) from t2 where key2 <= 1.6158; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select min(key1) from t1 where key1 >= 0.3762; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select min(key2) from t2 where key2 >= 1.3762; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select max(key1), min(key2) from t1, t2 +where key1 <= 0.6158 and key2 >= 1.3762; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +select max(key1) from t1 where key1 <= 0.6158; +max(key1) +0.61580002307892 +select max(key2) from t2 where key2 <= 1.6158; +max(key2) +1.6158000230789 +select min(key1) from t1 where key1 >= 0.3762; +min(key1) +0.37619999051094 +select min(key2) from t2 where key2 >= 1.3762; +min(key2) +1.3761999607086 +select max(key1), min(key2) from t1, t2 +where key1 <= 0.6158 and key2 >= 1.3762; +max(key1) min(key2) +0.61580002307892 1.3761999607086 +select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; +max(key1) +0.61580002307892 +select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; +min(key1) +0.37619999051094 +DROP TABLE t1,t2; diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 595d80f1218..dc921f747ee 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -539,7 +539,7 @@ EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away Warnings: -Note 1003 select max(test.t1.numreponse) AS `MAX(numreponse)` from test.t1 where (test.t1.numeropost = _latin1'1') +Note 1003 select max(test.t1.numreponse) AS `MAX(numreponse)` from test.t1 EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 Using index diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 4cdfc220350..acf9fd77c1b 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2297,4 +2297,34 @@ INSERT INTO t1 VALUES (10); SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1; DROP TABLE t1; +# +# Bug #20954 "avg(keyval) retuns 0.38 but max(keyval) returns an empty set" +# +--disable_ps_protocol +CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1)); +CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2)); +INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941); +INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941); + +explain select max(key1) from t1 where key1 <= 0.6158; +explain select max(key2) from t2 where key2 <= 1.6158; +explain select min(key1) from t1 where key1 >= 0.3762; +explain select min(key2) from t2 where key2 >= 1.3762; +explain select max(key1), min(key2) from t1, t2 +where key1 <= 0.6158 and key2 >= 1.3762; +explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; +explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; + +select max(key1) from t1 where key1 <= 0.6158; +select max(key2) from t2 where key2 <= 1.6158; +select min(key1) from t1 where key1 >= 0.3762; +select min(key2) from t2 where key2 >= 1.3762; +select max(key1), min(key2) from t1, t2 +where key1 <= 0.6158 and key2 >= 1.3762; +select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; +select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; + +DROP TABLE t1,t2; +--enable_ps_protocol + # End of 4.1 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index fd8a5149edd..96ac98cfb88 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -547,6 +547,24 @@ JOIN::optimize() } zero_result_cause= "Select tables optimized away"; tables_list= 0; // All tables resolved + /* + Extract all table-independent conditions and replace the WHERE + clause with them. All other conditions were computed by opt_sum_query + and the MIN/MAX/COUNT function(s) have been replaced by constants, + so there is no need to compute the whole WHERE clause again. + Notice that make_cond_for_table() will always succeed to remove all + computed conditions, because opt_sum_query() is applicable only to + conjunctions. + */ + if (conds) + { + COND *table_independent_conds= + make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0); + DBUG_EXECUTE("where", + print_where(table_independent_conds, + "where after opt_sum_query()");); + conds= table_independent_conds; + } } } if (!tables_list) -- cgit v1.2.1 From 03637f493e21efc5681d6cb141a484ea0bbe838c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 07:47:29 +0400 Subject: Applied innodb-4.1-ss32 snapshot. innobase/ibuf/ibuf0ibuf.c: Applied innodb-4.1-ss32 snapshot. ibuf_fixed_addr_page(): Add parameter space. As the insert buffer B-tree is only located in the system tablespace (space 0), IBUF_TREE_ROOT_PAGE_NO is only special in space 0. --- innobase/ibuf/ibuf0ibuf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c index 2191cdc0ee6..a0011629427 100644 --- a/innobase/ibuf/ibuf0ibuf.c +++ b/innobase/ibuf/ibuf0ibuf.c @@ -945,14 +945,11 @@ ibool ibuf_fixed_addr_page( /*=================*/ /* out: TRUE if a fixed address ibuf i/o page */ + ulint space, /* in: space id */ ulint page_no)/* in: page number */ { - if ((ibuf_bitmap_page(page_no)) - || (page_no == IBUF_TREE_ROOT_PAGE_NO)) { - return(TRUE); - } - - return(FALSE); + return((space == 0 && page_no == IBUF_TREE_ROOT_PAGE_NO) + || ibuf_bitmap_page(page_no)); } /*************************************************************************** @@ -976,7 +973,7 @@ ibuf_page( return(FALSE); } - if (ibuf_fixed_addr_page(page_no)) { + if (ibuf_fixed_addr_page(space, page_no)) { return(TRUE); } @@ -1024,7 +1021,7 @@ ibuf_page_low( return(FALSE); } #endif - if (ibuf_fixed_addr_page(page_no)) { + if (ibuf_fixed_addr_page(space, page_no)) { return(TRUE); } @@ -2931,7 +2928,7 @@ ibuf_merge_or_delete_for_page( return; } #endif - if (ibuf_fixed_addr_page(page_no) || fsp_descr_page(page_no) + if (ibuf_fixed_addr_page(space, page_no) || fsp_descr_page(page_no) || trx_sys_hdr_page(space, page_no)) { return; } -- cgit v1.2.1 From 820840a02682dd12de5090db608ff669a7455008 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 08:26:07 +0400 Subject: Applied innodb-5.0-ss660 snapshot. innobase/btr/btr0cur.c: Applied innodb-5.0-ss660 snapshot. btr_cur_search_to_nth_level(): Reacquire btr_search_latch after inserting to the insert buffer. This was noticed while analyzing Bug#19081 but this shold not fix this bug since according to Heikki, btr_search_latch is not reserved during an insert. innobase/ibuf/ibuf0ibuf.c: Applied innodb-5.0-ss660 snapshot. ibuf_fixed_addr_page(): Add parameter space. As the insert buffer B-tree is only located in the system tablespace (space 0), IBUF_TREE_ROOT_PAGE_NO is only special in space 0. innobase/include/sync0rw.ic: Applied innodb-5.0-ss660 snapshot. rw_lock_s_unlock_func(): Change a debug assertion to a production assertion in order to track down Bug#19081. --- innobase/btr/btr0cur.c | 3 ++- innobase/ibuf/ibuf0ibuf.c | 15 ++++++--------- innobase/include/sync0rw.ic | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/innobase/btr/btr0cur.c b/innobase/btr/btr0cur.c index 3d7b6fffb52..d51a090be75 100644 --- a/innobase/btr/btr0cur.c +++ b/innobase/btr/btr0cur.c @@ -439,7 +439,7 @@ retry_page_get: if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } - return; + goto func_exit; } /* Insert to the insert buffer did not succeed: @@ -555,6 +555,7 @@ retry_page_get: || mode != PAGE_CUR_LE); } +func_exit: if (has_search_latch) { rw_lock_s_lock(&btr_search_latch); diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c index e4694ed52ae..b95f0a1832b 100644 --- a/innobase/ibuf/ibuf0ibuf.c +++ b/innobase/ibuf/ibuf0ibuf.c @@ -950,14 +950,11 @@ ibool ibuf_fixed_addr_page( /*=================*/ /* out: TRUE if a fixed address ibuf i/o page */ + ulint space, /* in: space id */ ulint page_no)/* in: page number */ { - if ((ibuf_bitmap_page(page_no)) - || (page_no == IBUF_TREE_ROOT_PAGE_NO)) { - return(TRUE); - } - - return(FALSE); + return((space == 0 && page_no == IBUF_TREE_ROOT_PAGE_NO) + || ibuf_bitmap_page(page_no)); } /*************************************************************************** @@ -981,7 +978,7 @@ ibuf_page( return(FALSE); } - if (ibuf_fixed_addr_page(page_no)) { + if (ibuf_fixed_addr_page(space, page_no)) { return(TRUE); } @@ -1029,7 +1026,7 @@ ibuf_page_low( return(FALSE); } #endif - if (ibuf_fixed_addr_page(page_no)) { + if (ibuf_fixed_addr_page(space, page_no)) { return(TRUE); } @@ -3052,7 +3049,7 @@ ibuf_merge_or_delete_for_page( return; } #endif - if (ibuf_fixed_addr_page(page_no) || fsp_descr_page(page_no) + if (ibuf_fixed_addr_page(space, page_no) || fsp_descr_page(page_no) || trx_sys_hdr_page(space, page_no)) { return; } diff --git a/innobase/include/sync0rw.ic b/innobase/include/sync0rw.ic index b1ae636010a..9e15475ae53 100644 --- a/innobase/include/sync0rw.ic +++ b/innobase/include/sync0rw.ic @@ -362,7 +362,7 @@ rw_lock_s_unlock_func( /* Reset the shared lock by decrementing the reader count */ - ut_ad(lock->reader_count > 0); + ut_a(lock->reader_count > 0); lock->reader_count--; #ifdef UNIV_SYNC_DEBUG -- cgit v1.2.1 From 5ca1ee5eea4d08491772388f39a664e21df32b9b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 13:32:28 +0300 Subject: Bug #21019: First result of SELECT COUNT(*) different than consecutive runs When optimizing conditions like 'a = OR a IS NULL' so that they're united into a single condition on the key and checked together the server must check which value is the NULL value in a correct way : not only using ->is_null but also check if the expression doesn't depend on any tables referenced in the current statement. This additional check must be performed because that optimization takes place before the actual execution of the statement, so if the field was initialized to NULL from a previous statement the optimization would be applied incorrectly. mysql-test/r/select.result: Bug #21019: First result of SELECT COUNT(*) different than consecutive runs - test case mysql-test/t/select.test: Bug #21019: First result of SELECT COUNT(*) different than consecutive runs - test case. Note that ALTER TABLE is important here : it happens to leave the Field instance for t1.b set to NULL, witch is vital for demonstrating the problem fixed by this changeset. sql/sql_select.cc: Bug #21019: First result of SELECT COUNT(*) different than consecutive runs - check whether a value is null taking into account its table dependency. --- mysql-test/r/select.result | 26 ++++++++++++++++++++++++++ mysql-test/t/select.test | 15 +++++++++++++++ sql/sql_select.cc | 7 +++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index c7df11ab018..d415c336715 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2744,3 +2744,29 @@ SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1; i='1e+01' i=1e+01 i in (1e+01) i in ('1e+01') 0 1 1 1 DROP TABLE t1; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1,1), (2,1), (4,10); +CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b)); +INSERT INTO t2 VALUES (1,NULL), (2,10); +ALTER TABLE t1 ENABLE KEYS; +EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index b b 5 NULL 2 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +a b a b +1 NULL 1 1 +1 NULL 2 1 +1 NULL 4 10 +2 10 4 10 +EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index b b 5 NULL 2 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +a b a b +1 NULL 1 1 +1 NULL 2 1 +1 NULL 4 10 +2 10 4 10 +DROP TABLE IF EXISTS t1,t2; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 4cdfc220350..23fc09b5e39 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2297,4 +2297,19 @@ INSERT INTO t1 VALUES (10); SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1; DROP TABLE t1; +# +# Bug #21019: First result of SELECT COUNT(*) different than consecutive runs +# +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1,1), (2,1), (4,10); + +CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b)); +INSERT INTO t2 VALUES (1,NULL), (2,10); +ALTER TABLE t1 ENABLE KEYS; + +EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +DROP TABLE IF EXISTS t1,t2; # End of 4.1 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index fd8a5149edd..77ad0b8b163 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2143,8 +2143,11 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end, /* field = expression OR field IS NULL */ old->level= and_level; old->optimize= KEY_OPTIMIZE_REF_OR_NULL; - /* Remember the NOT NULL value */ - if (old->val->is_null()) + /* + Remember the NOT NULL value unless the value does not depend + on other tables. + */ + if (!old->val->used_tables() && old->val->is_null()) old->val= new_fields->val; /* The referred expression can be NULL: */ old->null_rejecting= 0; -- cgit v1.2.1 From 8c92143b4bf715abd307b69a7f3637feec7df2ba Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 18:18:34 +0300 Subject: Bug #21019: First result of SELECT COUNT(*) different than consecutive runs Correct merge --- mysql-test/r/select.result | 52 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 69228d2ff44..32c9fabb19e 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2736,6 +2736,32 @@ SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1; i='1e+01' i=1e+01 i in (1e+01,1e+01) i in ('1e+01','1e+01') 0 1 1 1 DROP TABLE t1; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1,1), (2,1), (4,10); +CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b)); +INSERT INTO t2 VALUES (1,NULL), (2,10); +ALTER TABLE t1 ENABLE KEYS; +EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index b b 5 NULL 2 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +a b a b +1 NULL 1 1 +1 NULL 2 1 +1 NULL 4 10 +2 10 4 10 +EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index b b 5 NULL 2 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; +a b a b +1 NULL 1 1 +1 NULL 2 1 +1 NULL 4 10 +2 10 4 10 +DROP TABLE IF EXISTS t1,t2; CREATE TABLE t1 ( K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', @@ -3125,32 +3151,6 @@ select count(*) from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id; count(*) 6 -CREATE TABLE t1 (a int, b int); -INSERT INTO t1 VALUES (1,1), (2,1), (4,10); -CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b)); -INSERT INTO t2 VALUES (1,NULL), (2,10); -ALTER TABLE t1 ENABLE KEYS; -EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index b b 5 NULL 2 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where -SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -a b a b -1 NULL 1 1 -1 NULL 2 1 -1 NULL 4 10 -2 10 4 10 -EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index b b 5 NULL 2 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where -SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -a b a b -1 NULL 1 1 -1 NULL 2 1 -1 NULL 4 10 -2 10 4 10 -DROP TABLE IF EXISTS t1,t2; drop table t1,t2,t3; create table t1 (a int); create table t2 (b int); -- cgit v1.2.1 From 6b75e24b73828316dd1715ab32811a614ce74314 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 19:19:30 +0300 Subject: * Bug #20792: Incorrect results from aggregate subquery When processing aggregate functions all tables values are reset to NULLs at the end of each group. When doing that if there are no rows found for a group the const tables must not be reset as they are not recalculated by do_select()/sub_select() for each group. mysql-test/r/subselect2.result: * Bug #20792: Incorrect results from aggregate subquery - test suite for the bug. This is dependent on InnoDB despite the fact that the bug and the fix are not InnoDB specific. This is because of the table flag HA_NOT_EXACT_COUNT. When this flag is off (as in MyISAM) both t2 and t3 become of join type 'system' as they are estimated to have 1 record and and this statistics can be trusted (according to the absence of HA_NOT_EXACT_COUNT). mysql-test/t/subselect2.test: * Bug #20792: Incorrect results from aggregate subquery - test suite for the bug sql/sql_select.cc: * Bug #20792: Incorrect results from aggregate subquery - when clearing results if there are not rows found for group the const tables must not be reset as they are not recalculated for each group. --- mysql-test/r/subselect2.result | 12 ++++++++++++ mysql-test/t/subselect2.test | 18 ++++++++++++++++++ sql/sql_select.cc | 10 ++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/subselect2.result b/mysql-test/r/subselect2.result index 8fcfa06a8ae..db1848105f8 100644 --- a/mysql-test/r/subselect2.result +++ b/mysql-test/r/subselect2.result @@ -130,3 +130,15 @@ id select_type table type possible_keys key key_len ref rows Extra 5 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where 6 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 32 func 1 Using index; Using where drop table t1, t2, t3, t4; +CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t2 VALUES (1); +CREATE TABLE t3 (a int(10), b int(10), c int(10), +PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t3 VALUES (1,2,1); +SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a +and t2.a='1' AND t1.a=t3.b) > 0; +a +2 +DROP TABLE t1,t2,t3; diff --git a/mysql-test/t/subselect2.test b/mysql-test/t/subselect2.test index b21eda176b6..162bdd0d90a 100644 --- a/mysql-test/t/subselect2.test +++ b/mysql-test/t/subselect2.test @@ -150,3 +150,21 @@ EXPLAIN SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JO drop table t1, t2, t3, t4; # End of 4.1 tests + +# +# Bug #20792: Incorrect results from aggregate subquery +# +CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t2 VALUES (1); + +CREATE TABLE t3 (a int(10), b int(10), c int(10), + PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t3 VALUES (1,2,1); + +SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a + and t2.a='1' AND t1.a=t3.b) > 0; + +DROP TABLE t1,t2,t3; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index fd8a5149edd..ce573136faf 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4452,10 +4452,16 @@ return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables, DBUG_RETURN(0); } - +/* + used only in JOIN::clear +*/ static void clear_tables(JOIN *join) { - for (uint i=0 ; i < join->tables ; i++) + /* + must clear only the non-const tables, as const tables + are not re-calculated. + */ + for (uint i=join->const_tables ; i < join->tables ; i++) mark_as_null_row(join->table[i]); // All fields are NULL } -- cgit v1.2.1 From 1150869c4a6418b9dbcbe6b9b2f6036e1c5379f1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Jul 2006 21:36:03 +0400 Subject: item_func.h, item_func.cc, sql_select.cc, item.h: Post review changes for bug#19862. sql/sql_select.cc: Post review changes for bug#19862. sql/item_func.h: Post review changes for bug#19862. sql/item_func.cc: Post review changes for bug#19862. sql/item.h: Post review changes for bug#19862. --- sql/item.h | 2 +- sql/item_func.cc | 4 ++-- sql/item_func.h | 5 ++++- sql/sql_select.cc | 5 +---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sql/item.h b/sql/item.h index c59d84aaeaa..514c31c2d74 100644 --- a/sql/item.h +++ b/sql/item.h @@ -752,7 +752,7 @@ public: virtual bool find_item_in_field_list_processor(byte *arg) { return 0; } virtual bool change_context_processor(byte *context) { return 0; } virtual bool reset_query_id_processor(byte *query_id) { return 0; } - virtual bool func_type_checker_processor(byte *arg) { return 0; } + virtual bool is_expensive_processor(byte *arg) { return 0; } virtual Item *equal_fields_propagator(byte * arg) { return this; } virtual Item *set_no_const_sub(byte *arg) { return this; } diff --git a/sql/item_func.cc b/sql/item_func.cc index c31ac2bf047..cbab9a4de1b 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -399,9 +399,9 @@ Field *Item_func::tmp_table_field(TABLE *t_arg) } -bool Item_func::func_type_checker_processor(byte *arg) +bool Item_func::is_expensive_processor(byte *arg) { - return *((Functype*)arg) == functype(); + return is_expensive(); } diff --git a/sql/item_func.h b/sql/item_func.h index bac4a186867..b33dae092ac 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -189,7 +189,8 @@ public: Item *transform(Item_transformer transformer, byte *arg); void traverse_cond(Cond_traverser traverser, void * arg, traverse_order order); - bool func_type_checker_processor(byte *arg); + bool is_expensive_processor(byte *arg); + virtual bool is_expensive() { return 0; } }; @@ -947,6 +948,7 @@ public: void cleanup(); Item_result result_type () const { return udf.result_type(); } table_map not_null_tables() const { return 0; } + bool is_expensive() { return 1; } }; @@ -1475,6 +1477,7 @@ public: virtual enum Functype functype() const { return FUNC_SP; } bool fix_fields(THD *thd, Item **ref); + bool is_expensive() { return 1; } }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 36962a233b8..20945117da1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1073,10 +1073,7 @@ JOIN::optimize() for (ORDER *tmp_order= order; tmp_order ; tmp_order=tmp_order->next) { Item *item= *tmp_order->item; - Item_func::Functype type=Item_func::FUNC_SP; - Item_func::Functype type1=Item_func::UDF_FUNC; - if (item->walk(&Item::func_type_checker_processor,(byte*)&type) || - item->walk(&Item::func_type_checker_processor,(byte*)&type1)) + if (item->walk(&Item::is_expensive_processor,(byte*)0)) { /* Force tmp table without sort */ need_tmp=1; simple_order=simple_group=0; -- cgit v1.2.1 From 49d721d7cff6f613ab3a87fe3065edf16b7288ea Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Jul 2006 15:19:13 +0400 Subject: Don't complain in the error log about IM shutdown unless BUG#20761 is fixed. --- mysql-test/mysql-test-run.pl | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 5a7609a55fb..8b832c390f8 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2968,17 +2968,24 @@ sub im_stop($) { mtr_kill_processes(\@mysqld_pids); # Complain in error log so that a warning will be shown. - - my $errlog= "$opt_vardir/log/mysql-test-run.pl.err"; - - open (ERRLOG, ">>$errlog") || - mtr_error("Can not open error log ($errlog)"); + # + # TODO: unless BUG#20761 is fixed, we will print the warning + # to stdout, so that it can be seen on console and does not + # produce pushbuild error. + + # my $errlog= "$opt_vardir/log/mysql-test-run.pl.err"; + # + # open (ERRLOG, ">>$errlog") || + # mtr_error("Can not open error log ($errlog)"); + # + # my $ts= localtime(); + # print ERRLOG + # "Warning: [$ts] Instance Manager did not shutdown gracefully.\n"; + # + # close ERRLOG; my $ts= localtime(); - print ERRLOG - "Warning: [$ts] Instance Manager did not shutdown gracefully.\n"; - - close ERRLOG; + print "Warning: [$ts] Instance Manager did not shutdown gracefully.\n"; } # That's all. -- cgit v1.2.1 From 3c108584740ca89fb77c7f002c67982abb86651c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Jul 2006 17:57:43 +0400 Subject: Fix for BUG#16211: Stored function return type for strings is ignored. Fix for BUG#16676: Database CHARSET not used for stored procedures The problem in BUG#16211 is that CHARSET-clause of the return type for stored functions is just ignored. The problem in BUG#16676 is that if character set is not explicitly specified for sp-variable, the server character set is used instead of the database one. The fix has two parts: - always store CHARSET-clause of the return type along with the type definition in mysql.proc.returns column. "Always" means that CHARSET-clause is appended even if it has not been explicitly specified in CREATE FUNCTION statement (this affects BUG#16211 only). Storing CHARSET-clause if it is not specified is essential to avoid changing character set if the database character set is altered in the future. NOTE: this change is not backward compatible with the previous releases. - use database default character set if CHARSET-clause is not explicitly specified (this affects both BUG#16211 and BUG#16676). NOTE: this also breaks backward compatibility. mysql-test/r/mysqldump.result: Updated result file. mysql-test/r/sp.result: Updated result file. mysql-test/t/sp.test: Provided test cases for BUG#16211, BUG#16676. sql/mysql_priv.h: Added two convenient functions for work with databases. sql/sp.cc: 1. Add CHARSET-clause to CREATE-statement if it has been explicitly specified. 2. Polishing -- provided some comments. sql/sp_head.cc: Use database charset as default charset of sp-variable. sql/sp_head.h: Move init_sp_name() out of init_strings(). sql/sql_db.cc: Two new functions created: - load_db_opt_by_name(); - check_db_dir_existence(); sql/sql_show.cc: Eliminate duplicated code by using check_db_dir_existence() and load_db_opt_by_name() sql/sql_table.cc: Eliminate duplicated code by using check_db_dir_existence() and load_db_opt_by_name() sql/sql_yacc.yy: Call sp_head::init_sp_name() to initialize stored routine name. --- mysql-test/r/mysqldump.result | 2 +- mysql-test/r/sp.result | 153 ++++++++++++++++++++++++++++++++++++++++ mysql-test/t/sp.test | 158 ++++++++++++++++++++++++++++++++++++++++++ sql/mysql_priv.h | 3 + sql/sp.cc | 12 ++++ sql/sp_head.cc | 53 +++++++++----- sql/sp_head.h | 6 +- sql/sql_db.cc | 94 ++++++++++++++++++++++--- sql/sql_show.cc | 40 +++-------- sql/sql_table.cc | 7 +- sql/sql_yacc.yy | 13 ++-- 11 files changed, 472 insertions(+), 69 deletions(-) diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index f9714e067e6..24ccc2c5fee 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -2248,7 +2248,7 @@ RETURN a+b */;; /*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;; /*!50003 DROP FUNCTION IF EXISTS `bug9056_func2` */;; /*!50003 SET SESSION SQL_MODE=""*/;; -/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`localhost`*/ /*!50003 FUNCTION `bug9056_func2`(f1 char binary) RETURNS char(1) +/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`localhost`*/ /*!50003 FUNCTION `bug9056_func2`(f1 char binary) RETURNS char(1) CHARSET latin1 begin set f1= concat( 'hello', f1 ); return f1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 10556bf31a2..70d8a99c7c2 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5069,4 +5069,157 @@ END | SET @a = _latin2"aaaaaaaaaa" | CALL bug21013(10) | DROP PROCEDURE bug21013 | +DROP DATABASE IF EXISTS mysqltest1| +DROP DATABASE IF EXISTS mysqltest2| +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| +CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8| +use mysqltest1| +CREATE FUNCTION bug16211_f1() RETURNS CHAR(10) +RETURN ""| +CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r +RETURN ""| +CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10) +RETURN ""| +CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r +RETURN ""| +SHOW CREATE FUNCTION bug16211_f1| +Function sql_mode Create Function +bug16211_f1 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f1`() RETURNS char(10) CHARSET utf8 +RETURN "" +SHOW CREATE FUNCTION bug16211_f2| +Function sql_mode Create Function +bug16211_f2 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f2`() RETURNS char(10) CHARSET koi8r +RETURN "" +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +Function sql_mode Create Function +bug16211_f3 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f3`() RETURNS char(10) CHARSET utf8 +RETURN "" +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| +Function sql_mode Create Function +bug16211_f4 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f4`() RETURNS char(10) CHARSET koi8r +RETURN "" +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| +dtd_identifier +char(10) CHARSET utf8 +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| +dtd_identifier +char(10) CHARSET koi8r +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| +dtd_identifier +char(10) CHARSET utf8 +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| +dtd_identifier +char(10) CHARSET koi8r +SELECT CHARSET(bug16211_f1())| +CHARSET(bug16211_f1()) +utf8 +SELECT CHARSET(bug16211_f2())| +CHARSET(bug16211_f2()) +koi8r +SELECT CHARSET(mysqltest2.bug16211_f3())| +CHARSET(mysqltest2.bug16211_f3()) +utf8 +SELECT CHARSET(mysqltest2.bug16211_f4())| +CHARSET(mysqltest2.bug16211_f4()) +koi8r +ALTER DATABASE mysqltest1 CHARACTER SET cp1251| +ALTER DATABASE mysqltest2 CHARACTER SET cp1251| +SHOW CREATE FUNCTION bug16211_f1| +Function sql_mode Create Function +bug16211_f1 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f1`() RETURNS char(10) CHARSET utf8 +RETURN "" +SHOW CREATE FUNCTION bug16211_f2| +Function sql_mode Create Function +bug16211_f2 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f2`() RETURNS char(10) CHARSET koi8r +RETURN "" +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +Function sql_mode Create Function +bug16211_f3 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f3`() RETURNS char(10) CHARSET utf8 +RETURN "" +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| +Function sql_mode Create Function +bug16211_f4 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f4`() RETURNS char(10) CHARSET koi8r +RETURN "" +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| +dtd_identifier +char(10) CHARSET utf8 +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| +dtd_identifier +char(10) CHARSET koi8r +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| +dtd_identifier +char(10) CHARSET utf8 +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| +dtd_identifier +char(10) CHARSET koi8r +SELECT CHARSET(bug16211_f1())| +CHARSET(bug16211_f1()) +utf8 +SELECT CHARSET(bug16211_f2())| +CHARSET(bug16211_f2()) +koi8r +SELECT CHARSET(mysqltest2.bug16211_f3())| +CHARSET(mysqltest2.bug16211_f3()) +utf8 +SELECT CHARSET(mysqltest2.bug16211_f4())| +CHARSET(mysqltest2.bug16211_f4()) +koi8r +use test| +DROP DATABASE mysqltest1| +DROP DATABASE mysqltest2| +DROP DATABASE IF EXISTS mysqltest1| +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| +use mysqltest1| +CREATE PROCEDURE bug16676_p1( +IN p1 CHAR(10), +INOUT p2 CHAR(10), +OUT p3 CHAR(10)) +BEGIN +SELECT CHARSET(p1), COLLATION(p1); +SELECT CHARSET(p2), COLLATION(p2); +SELECT CHARSET(p3), COLLATION(p3); +END| +CREATE PROCEDURE bug16676_p2( +IN p1 CHAR(10) CHARSET koi8r, +INOUT p2 CHAR(10) CHARSET cp1251, +OUT p3 CHAR(10) CHARSET greek) +BEGIN +SELECT CHARSET(p1), COLLATION(p1); +SELECT CHARSET(p2), COLLATION(p2); +SELECT CHARSET(p3), COLLATION(p3); +END| +SET @v2 = 'b'| +SET @v3 = 'c'| +CALL bug16676_p1('a', @v2, @v3)| +CHARSET(p1) COLLATION(p1) +utf8 utf8_general_ci +CHARSET(p2) COLLATION(p2) +utf8 utf8_general_ci +CHARSET(p3) COLLATION(p3) +utf8 utf8_general_ci +CALL bug16676_p2('a', @v2, @v3)| +CHARSET(p1) COLLATION(p1) +koi8r koi8r_general_ci +CHARSET(p2) COLLATION(p2) +cp1251 cp1251_general_ci +CHARSET(p3) COLLATION(p3) +greek greek_general_ci +use test| +DROP DATABASE mysqltest1| drop table t1,t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 41da4eb9222..3f051f77954 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5989,6 +5989,164 @@ CALL bug21013(10) | DROP PROCEDURE bug21013 | +# +# BUG#16211: Stored function return type for strings is ignored +# + +# Prepare: create database with fixed, pre-defined character set. + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest1| +DROP DATABASE IF EXISTS mysqltest2| +--enable_warnings + +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| +CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8| + +# Test case: + +use mysqltest1| + +# - Create two stored functions -- with and without explicit CHARSET-clause +# for return value; + +CREATE FUNCTION bug16211_f1() RETURNS CHAR(10) + RETURN ""| + +CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r + RETURN ""| + +CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10) + RETURN ""| + +CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r + RETURN ""| + +# - Check that CHARSET-clause is specified for the second function; + +SHOW CREATE FUNCTION bug16211_f1| +SHOW CREATE FUNCTION bug16211_f2| + +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| + +SELECT CHARSET(bug16211_f1())| +SELECT CHARSET(bug16211_f2())| + +SELECT CHARSET(mysqltest2.bug16211_f3())| +SELECT CHARSET(mysqltest2.bug16211_f4())| + +# - Alter database character set. + +ALTER DATABASE mysqltest1 CHARACTER SET cp1251| +ALTER DATABASE mysqltest2 CHARACTER SET cp1251| + +# - Check that CHARSET-clause has not changed. + +SHOW CREATE FUNCTION bug16211_f1| +SHOW CREATE FUNCTION bug16211_f2| + +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| + +SELECT CHARSET(bug16211_f1())| +SELECT CHARSET(bug16211_f2())| + +SELECT CHARSET(mysqltest2.bug16211_f3())| +SELECT CHARSET(mysqltest2.bug16211_f4())| + +# Cleanup. + +use test| + +DROP DATABASE mysqltest1| +DROP DATABASE mysqltest2| + + +# +# BUG#16676: Database CHARSET not used for stored procedures +# + +# Prepare: create database with fixed, pre-defined character set. + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest1| +--enable_warnings + +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| + +# Test case: + +use mysqltest1| + +# - Create two stored procedures -- with and without explicit CHARSET-clause; + +CREATE PROCEDURE bug16676_p1( + IN p1 CHAR(10), + INOUT p2 CHAR(10), + OUT p3 CHAR(10)) +BEGIN + SELECT CHARSET(p1), COLLATION(p1); + SELECT CHARSET(p2), COLLATION(p2); + SELECT CHARSET(p3), COLLATION(p3); +END| + +CREATE PROCEDURE bug16676_p2( + IN p1 CHAR(10) CHARSET koi8r, + INOUT p2 CHAR(10) CHARSET cp1251, + OUT p3 CHAR(10) CHARSET greek) +BEGIN + SELECT CHARSET(p1), COLLATION(p1); + SELECT CHARSET(p2), COLLATION(p2); + SELECT CHARSET(p3), COLLATION(p3); +END| + +# - Call procedures. + +SET @v2 = 'b'| +SET @v3 = 'c'| + +CALL bug16676_p1('a', @v2, @v3)| +CALL bug16676_p2('a', @v2, @v3)| + +# Cleanup. + +use test| + +DROP DATABASE mysqltest1| + # # BUG#NNNN: New bug synopsis # diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index c9ae743addd..51ce7224684 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1138,7 +1138,10 @@ uint check_word(TYPELIB *lib, const char *val, const char *end, bool is_keyword(const char *name, uint len); #define MY_DB_OPT_FILE "db.opt" +bool check_db_dir_existence(const char *db_name); bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create); +bool load_db_opt_by_name(THD *thd, const char *db_name, + HA_CREATE_INFO *db_create_info); bool my_dbopt_init(void); void my_dbopt_cleanup(void); void my_dbopt_free(void); diff --git a/sql/sp.cc b/sql/sp.cc index 553465ebff8..b5a4f8bad8f 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -495,6 +495,13 @@ sp_returns_type(THD *thd, String &result, sp_head *sp) table.s = &table.share_not_to_be_used; field= sp->create_result_field(0, 0, &table); field->sql_type(result); + + if (field->has_charset()) + { + result.append(STRING_WITH_LEN(" CHARSET ")); + result.append(field->charset()->csname); + } + delete field; } @@ -974,6 +981,11 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, sp_head *new_sp; const char *returns= ""; char definer[USER_HOST_BUFF_SIZE]; + + /* + String buffer for RETURNS data type must have system charset; + 64 -- size of "returns" column of mysql.proc. + */ String retstr(64); DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp)); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index e39efd78d7e..7bcadde2760 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -470,7 +470,7 @@ sp_head::init(LEX *lex) lex->trg_table_fields.empty(); my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8); m_param_begin= m_param_end= m_body_begin= 0; - m_qname.str= m_db.str= m_name.str= m_params.str= + m_qname.str= m_db.str= m_name.str= m_params.str= m_body.str= m_defstr.str= 0; m_qname.length= m_db.length= m_name.length= m_params.length= m_body.length= m_defstr.length= 0; @@ -478,29 +478,42 @@ sp_head::init(LEX *lex) DBUG_VOID_RETURN; } + void -sp_head::init_strings(THD *thd, LEX *lex, sp_name *name) +sp_head::init_sp_name(THD *thd, sp_name *spname) +{ + DBUG_ENTER("sp_head::init_sp_name"); + + /* Must be initialized in the parser. */ + + DBUG_ASSERT(spname && spname->m_db.str && spname->m_db.length); + + /* We have to copy strings to get them into the right memroot. */ + + m_db.length= spname->m_db.length; + m_db.str= strmake_root(thd->mem_root, spname->m_db.str, spname->m_db.length); + + m_name.length= spname->m_name.length; + m_name.str= strmake_root(thd->mem_root, spname->m_name.str, + spname->m_name.length); + + if (spname->m_qname.length == 0) + spname->init_qname(thd); + + m_qname.length= spname->m_qname.length; + m_qname.str= strmake_root(thd->mem_root, spname->m_qname.str, + m_qname.length); +} + + +void +sp_head::init_strings(THD *thd, LEX *lex) { DBUG_ENTER("sp_head::init_strings"); uchar *endp; /* Used to trim the end */ /* During parsing, we must use thd->mem_root */ MEM_ROOT *root= thd->mem_root; - DBUG_ASSERT(name); - /* Must be initialized in the parser */ - DBUG_ASSERT(name->m_db.str && name->m_db.length); - - /* We have to copy strings to get them into the right memroot */ - m_db.length= name->m_db.length; - m_db.str= strmake_root(root, name->m_db.str, name->m_db.length); - m_name.length= name->m_name.length; - m_name.str= strmake_root(root, name->m_name.str, name->m_name.length); - - if (name->m_qname.length == 0) - name->init_qname(thd); - m_qname.length= name->m_qname.length; - m_qname.str= strmake_root(root, name->m_qname.str, m_qname.length); - if (m_param_begin && m_param_end) { m_params.length= m_param_end - m_param_begin; @@ -1856,14 +1869,18 @@ sp_head::fill_field_definition(THD *thd, LEX *lex, enum enum_field_types field_type, create_field *field_def) { + HA_CREATE_INFO sp_db_info; LEX_STRING cmt = { 0, 0 }; uint unused1= 0; int unused2= 0; + load_db_opt_by_name(thd, m_db.str, &sp_db_info); + if (field_def->init(thd, (char*) "", field_type, lex->length, lex->dec, lex->type, (Item*) 0, (Item*) 0, &cmt, 0, &lex->interval_list, - (lex->charset ? lex->charset : default_charset_info), + (lex->charset ? lex->charset : + sp_db_info.default_table_charset), lex->uint_geom_type)) return TRUE; diff --git a/sql/sp_head.h b/sql/sp_head.h index 36747716bdc..4cd34bc9e20 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -193,9 +193,13 @@ public: void init(LEX *lex); + /* Copy sp name from parser. */ + void + init_sp_name(THD *thd, sp_name *spname); + // Initialize strings after parsing header void - init_strings(THD *thd, LEX *lex, sp_name *name); + init_strings(THD *thd, LEX *lex); int create(THD *thd); diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 902539dfdec..81508e4e9be 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -295,7 +295,6 @@ static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create) create Where to store the read options DESCRIPTION - For now, only default-character-set is read. RETURN VALUES 0 File found @@ -383,6 +382,50 @@ err1: } +/* + Retrieve database options by name. Load database options file or fetch from + cache. + + SYNOPSIS + load_db_opt_by_name() + db_name Database name + db_create_info Where to store the database options + + DESCRIPTION + load_db_opt_by_name() is a shortcut for load_db_opt(). + + NOTE + Although load_db_opt_by_name() (and load_db_opt()) returns status of + the operation, it is useless usually and should be ignored. The problem + is that there are 1) system databases ("mysql") and 2) virtual + databases ("information_schema"), which do not contain options file. + So, load_db_opt[_by_name]() returns FALSE for these databases, but this + is not an error. + + load_db_opt[_by_name]() clears db_create_info structure in any case, so + even on failure it contains valid data. So, common use case is just + call load_db_opt[_by_name]() without checking return value and use + db_create_info right after that. + + RETURN VALUES (read NOTE!) + FALSE Success + TRUE Failed to retrieve options +*/ + +bool load_db_opt_by_name(THD *thd, const char *db_name, + HA_CREATE_INFO *db_create_info) +{ + char db_opt_path[FN_REFLEN]; + + strxnmov(db_opt_path, sizeof (db_opt_path) - 1, mysql_data_home, "/", + db_name, "/", MY_DB_OPT_FILE, NullS); + + unpack_filename(db_opt_path, db_opt_path); + + return load_db_opt(thd, db_opt_path, db_create_info); +} + + /* Create a database @@ -1126,8 +1169,6 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check) { int path_length, db_length; char *db_name; - char path[FN_REFLEN]; - HA_CREATE_INFO create; bool system_db= 0; #ifndef NO_EMBEDDED_ACCESS_CHECKS ulong db_access; @@ -1196,16 +1237,14 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check) } } #endif - (void) sprintf(path,"%s/%s", mysql_data_home, db_name); - path_length= unpack_dirname(path, path); // Convert if not UNIX - if (path_length && path[path_length-1] == FN_LIBCHAR) - path[path_length-1]= '\0'; // remove ending '\' - if (my_access(path,F_OK)) + + if (check_db_dir_existence(db_name)) { my_error(ER_BAD_DB_ERROR, MYF(0), db_name); my_free(db_name, MYF(0)); DBUG_RETURN(1); } + end: x_free(thd->db); DBUG_ASSERT(db_name == NULL || db_name[0] != '\0'); @@ -1221,8 +1260,10 @@ end: } else { - strmov(path+unpack_dirname(path,path), MY_DB_OPT_FILE); - load_db_opt(thd, path, &create); + HA_CREATE_INFO create; + + load_db_opt_by_name(thd, db_name, &create); + thd->db_charset= create.default_table_charset ? create.default_table_charset : thd->variables.collation_server; @@ -1230,3 +1271,36 @@ end: } DBUG_RETURN(0); } + + +/* + Check if there is directory for the database name. + + SYNOPSIS + check_db_dir_existence() + db_name database name + + RETURN VALUES + FALSE There is directory for the specified database name. + TRUE The directory does not exist. +*/ + +bool check_db_dir_existence(const char *db_name) +{ + char db_dir_path[FN_REFLEN]; + uint db_dir_path_len; + + strxnmov(db_dir_path, sizeof (db_dir_path) - 1, mysql_data_home, "/", + db_name, NullS); + + db_dir_path_len= unpack_dirname(db_dir_path, db_dir_path); + + /* Remove trailing '/' or '\' if exists. */ + + if (db_dir_path_len && db_dir_path[db_dir_path_len - 1] == FN_LIBCHAR) + db_dir_path[db_dir_path_len - 1]= 0; + + /* Check access. */ + + return my_access(db_dir_path, F_OK); +} diff --git a/sql/sql_show.cc b/sql/sql_show.cc index cabb04c5f16..1a42ef81487 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -439,13 +439,11 @@ bool mysqld_show_create_db(THD *thd, char *dbname, { Security_context *sctx= thd->security_ctx; int length; - char path[FN_REFLEN]; char buff[2048]; String buffer(buff, sizeof(buff), system_charset_info); #ifndef NO_EMBEDDED_ACCESS_CHECKS uint db_access; #endif - bool found_libchar; HA_CREATE_INFO create; uint create_options = create_info ? create_info->options : 0; Protocol *protocol=thd->protocol; @@ -480,23 +478,13 @@ bool mysqld_show_create_db(THD *thd, char *dbname, } else { - (void) sprintf(path,"%s/%s",mysql_data_home, dbname); - length=unpack_dirname(path,path); // Convert if not unix - found_libchar= 0; - if (length && path[length-1] == FN_LIBCHAR) - { - found_libchar= 1; - path[length-1]=0; // remove ending '\' - } - if (access(path,F_OK)) + if (check_db_dir_existence(dbname)) { my_error(ER_BAD_DB_ERROR, MYF(0), dbname); DBUG_RETURN(TRUE); } - if (found_libchar) - path[length-1]= FN_LIBCHAR; - strmov(path+length, MY_DB_OPT_FILE); - load_db_opt(thd, path, &create); + + load_db_opt_by_name(thd, dbname, &create); } List field_list; field_list.push_back(new Item_empty_string("Database",NAME_LEN)); @@ -2319,8 +2307,11 @@ bool store_schema_shemata(THD* thd, TABLE *table, const char *db_name, int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) { - char path[FN_REFLEN]; - bool found_libchar; + /* + TODO: fill_schema_shemata() is called when new client is connected. + Returning error status in this case leads to client hangup. + */ + INDEX_FIELD_VALUES idx_field_vals; List files; char *file_name; @@ -2352,20 +2343,9 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) (grant_option && !check_grant_db(thd, file_name))) #endif { - strxmov(path, mysql_data_home, "/", file_name, NullS); - length=unpack_dirname(path,path); // Convert if not unix - found_libchar= 0; - if (length && path[length-1] == FN_LIBCHAR) - { - found_libchar= 1; - path[length-1]=0; // remove ending '\' - } + load_db_opt_by_name(thd, file_name, &create); - if (found_libchar) - path[length-1]= FN_LIBCHAR; - strmov(path+length, MY_DB_OPT_FILE); - load_db_opt(thd, path, &create); - if (store_schema_shemata(thd, table, file_name, + if (store_schema_shemata(thd, table, file_name, create.default_table_charset)) DBUG_RETURN(1); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 4772d64ad0a..e065a32c2e8 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1631,10 +1631,9 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, if (!create_info->default_table_charset) { HA_CREATE_INFO db_info; - char path[FN_REFLEN]; - /* Abuse build_table_path() to build the path to the db.opt file */ - build_table_path(path, sizeof(path), db, MY_DB_OPT_FILE, ""); - load_db_opt(thd, path, &db_info); + + load_db_opt_by_name(thd, db, &db_info); + create_info->default_table_charset= db_info.default_table_charset; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 75bb8d108f0..a92d19ee58d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1285,6 +1285,7 @@ create_function_tail: sp= new sp_head(); sp->reset_thd_mem_root(YYTHD); sp->init(lex); + sp->init_sp_name(YYTHD, lex->spname); sp->m_type= TYPE_ENUM_FUNCTION; lex->sphead= sp; @@ -1339,7 +1340,7 @@ create_function_tail: YYABORT; lex->sql_command= SQLCOM_CREATE_SPFUNCTION; - sp->init_strings(YYTHD, lex, lex->spname); + sp->init_strings(YYTHD, lex); if (!(sp->m_flags & sp_head::HAS_RETURN)) { my_error(ER_SP_NORETURN, MYF(0), sp->m_qname.str); @@ -9100,6 +9101,7 @@ trigger_tail: YYABORT; sp->reset_thd_mem_root(YYTHD); sp->init(lex); + sp->init_sp_name(YYTHD, $3); lex->stmt_definition_begin= $2; lex->ident.str= $7; @@ -9128,7 +9130,7 @@ trigger_tail: sp_head *sp= lex->sphead; lex->sql_command= SQLCOM_CREATE_TRIGGER; - sp->init_strings(YYTHD, lex, $3); + sp->init_strings(YYTHD, lex); /* Restore flag if it was cleared above */ if (sp->m_old_cmq) YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES; @@ -9176,13 +9178,14 @@ sp_tail: my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "PROCEDURE"); YYABORT; } - + lex->stmt_definition_begin= $2; - + /* Order is important here: new - reset - init */ sp= new sp_head(); sp->reset_thd_mem_root(YYTHD); sp->init(lex); + sp->init_sp_name(YYTHD, $3); sp->m_type= TYPE_ENUM_PROCEDURE; lex->sphead= sp; @@ -9220,7 +9223,7 @@ sp_tail: LEX *lex= Lex; sp_head *sp= lex->sphead; - sp->init_strings(YYTHD, lex, $3); + sp->init_strings(YYTHD, lex); lex->sql_command= SQLCOM_CREATE_PROCEDURE; /* Restore flag if it was cleared above */ if (sp->m_old_cmq) -- cgit v1.2.1 From d36f57813094135cf4cf7f4ab3ca275714b9c44c Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Jul 2006 02:49:18 +0400 Subject: Fix for BUG#20438: CREATE statements for views, stored routines and triggers can be not replicable. Now CREATE statements for writing in the binlog are created as follows: - the beginning of the statement is re-created; - the rest of the statement is copied from the original query. The problem appears when there is a version-specific comment (produced by mysqldump), started in the re-created part of the statement and closed in the copied part -- there is closing comment-parenthesis, but there is no opening one. The proper fix could be to re-create original statement, but we can not implement it in 5.0. So, for 5.0 the fix is just to cut closing comment-parenthesis. This technique is also used for SHOW CREATE PROCEDURE statement (so we are able to reuse existing code). mysql-test/r/rpl_sp.result: Updated result file. mysql-test/r/rpl_trigger.result: Updated result file. mysql-test/r/rpl_view.result: Updated result file. mysql-test/t/rpl_sp.test: Added test case for BUG#20438. mysql-test/t/rpl_trigger.test: Added test case for BUG#20438. mysql-test/t/rpl_view.test: Added test case for BUG#20438. sql/sp.cc: Trim comments at the end. sql/sp_head.cc: Moved this code to the separate function to be re-used. sql/sql_lex.cc: Added a new function. sql/sql_lex.h: Added a new function. sql/sql_trigger.cc: Trim comments at the end. sql/sql_view.cc: Trim comments at the end. --- mysql-test/r/rpl_sp.result | 44 ++++++++++++++++++++ mysql-test/r/rpl_trigger.result | 47 +++++++++++++++++++++ mysql-test/r/rpl_view.result | 37 +++++++++++++++++ mysql-test/t/rpl_sp.test | 80 +++++++++++++++++++++++++++++++++++ mysql-test/t/rpl_trigger.test | 92 +++++++++++++++++++++++++++++++++++++++++ mysql-test/t/rpl_view.test | 84 +++++++++++++++++++++++++++++++++++++ sql/sp.cc | 5 ++- sql/sp_head.cc | 5 +-- sql/sql_lex.cc | 24 +++++++++++ sql/sql_lex.h | 2 +- sql/sql_trigger.cc | 5 ++- sql/sql_view.cc | 6 ++- 12 files changed, 422 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/rpl_sp.result b/mysql-test/r/rpl_sp.result index 5dfda16c763..7b096b27733 100644 --- a/mysql-test/r/rpl_sp.result +++ b/mysql-test/r/rpl_sp.result @@ -420,4 +420,48 @@ SELECT * FROM t1; col test DROP PROCEDURE p1; + +---> Test for BUG#20438 + +---> Preparing environment... +---> connection: master +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; + +---> Synchronizing slave with master... + +---> connection: master + +---> Creating procedure... +/*!50003 CREATE PROCEDURE p1() SET @a = 1 */; +/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */; + +---> Checking on master... +SHOW CREATE PROCEDURE p1; +Procedure sql_mode Create Procedure +p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`() +SET @a = 1 +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function +f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11) +RETURN 0 + +---> Synchronizing slave with master... +---> connection: master + +---> Checking on slave... +SHOW CREATE PROCEDURE p1; +Procedure sql_mode Create Procedure +p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`() +SET @a = 1 +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function +f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11) +RETURN 0 + +---> connection: master + +---> Cleaning up... +DROP PROCEDURE p1; +DROP FUNCTION f1; drop table t1; diff --git a/mysql-test/r/rpl_trigger.result b/mysql-test/r/rpl_trigger.result index 3e4a3349e13..49f0f5c4c44 100644 --- a/mysql-test/r/rpl_trigger.result +++ b/mysql-test/r/rpl_trigger.result @@ -896,3 +896,50 @@ Tables_in_test (t_) SHOW TRIGGERS; Trigger Event Table Statement Timing Created sql_mode Definer RESET MASTER; +START SLAVE; + +---> Test for BUG#20438 + +---> Preparing environment... +---> connection: master +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; + +---> Synchronizing slave with master... + +---> connection: master + +---> Creating objects... +CREATE TABLE t1(c INT); +CREATE TABLE t2(c INT); +/*!50003 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 +FOR EACH ROW +INSERT INTO t2 VALUES(NEW.c * 10) */; + +---> Inserting value... +INSERT INTO t1 VALUES(1); + +---> Checking on master... +SELECT * FROM t1; +c +1 +SELECT * FROM t2; +c +10 + +---> Synchronizing slave with master... +---> connection: master + +---> Checking on slave... +SELECT * FROM t1; +c +1 +SELECT * FROM t2; +c +10 + +---> connection: master + +---> Cleaning up... +DROP TABLE t1; +DROP TABLE t2; diff --git a/mysql-test/r/rpl_view.result b/mysql-test/r/rpl_view.result index cf4c161b296..5a101defe38 100644 --- a/mysql-test/r/rpl_view.result +++ b/mysql-test/r/rpl_view.result @@ -54,3 +54,40 @@ slave-bin.000001 # Query 1 # use `test`; delete from v1 where a=2 slave-bin.000001 # Query 1 # use `test`; ALTER ALGORITHM=UNDEFINED DEFINER=root@localhost SQL SECURITY DEFINER VIEW v1 AS select a as b from t1 slave-bin.000001 # Query 1 # use `test`; drop view v1 slave-bin.000001 # Query 1 # use `test`; drop table t1 + +---> Test for BUG#20438 + +---> Preparing environment... +---> connection: master +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; + +---> Synchronizing slave with master... + +---> connection: master + +---> Creating objects... +CREATE TABLE t1(c INT); +/*!50003 CREATE VIEW v1 AS SELECT * FROM t1 */; + +---> Inserting value... +INSERT INTO t1 VALUES(1); + +---> Checking on master... +SELECT * FROM t1; +c +1 + +---> Synchronizing slave with master... +---> connection: master + +---> Checking on slave... +SELECT * FROM t1; +c +1 + +---> connection: master + +---> Cleaning up... +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/rpl_sp.test b/mysql-test/t/rpl_sp.test index 8be17be3822..7479794eded 100644 --- a/mysql-test/t/rpl_sp.test +++ b/mysql-test/t/rpl_sp.test @@ -435,6 +435,86 @@ connection master; DROP PROCEDURE p1; + +# +# BUG#20438: CREATE statements for views, stored routines and triggers can be +# not replicable. +# + +--echo +--echo ---> Test for BUG#20438 + +# Prepare environment. + +--echo +--echo ---> Preparing environment... +--echo ---> connection: master +--connection master + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo +--echo ---> connection: master +--connection master + +# Test. + +--echo +--echo ---> Creating procedure... + +/*!50003 CREATE PROCEDURE p1() SET @a = 1 */; + +/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */; + +--echo +--echo ---> Checking on master... + +SHOW CREATE PROCEDURE p1; +SHOW CREATE FUNCTION f1; + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo ---> connection: master + +--echo +--echo ---> Checking on slave... + +SHOW CREATE PROCEDURE p1; +SHOW CREATE FUNCTION f1; + +# Cleanup. + +--echo +--echo ---> connection: master +--connection master + +--echo +--echo ---> Cleaning up... + +DROP PROCEDURE p1; +DROP FUNCTION f1; + +--save_master_pos +--connection slave +--sync_with_master +--connection master + + # cleanup connection master; drop table t1; diff --git a/mysql-test/t/rpl_trigger.test b/mysql-test/t/rpl_trigger.test index 35f0a0b0a4b..3c8cbb97b31 100644 --- a/mysql-test/t/rpl_trigger.test +++ b/mysql-test/t/rpl_trigger.test @@ -331,6 +331,98 @@ SHOW TRIGGERS; RESET MASTER; +# Restart slave. + +connection slave; +START SLAVE; + + +# +# BUG#20438: CREATE statements for views, stored routines and triggers can be +# not replicable. +# + +--echo +--echo ---> Test for BUG#20438 + +# Prepare environment. + +--echo +--echo ---> Preparing environment... +--echo ---> connection: master +--connection master + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo +--echo ---> connection: master +--connection master + +# Test. + +--echo +--echo ---> Creating objects... + +CREATE TABLE t1(c INT); +CREATE TABLE t2(c INT); + +/*!50003 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 + FOR EACH ROW + INSERT INTO t2 VALUES(NEW.c * 10) */; + +--echo +--echo ---> Inserting value... + +INSERT INTO t1 VALUES(1); + +--echo +--echo ---> Checking on master... + +SELECT * FROM t1; +SELECT * FROM t2; + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo ---> connection: master + +--echo +--echo ---> Checking on slave... + +SELECT * FROM t1; +SELECT * FROM t2; + +# Cleanup. + +--echo +--echo ---> connection: master +--connection master + +--echo +--echo ---> Cleaning up... + +DROP TABLE t1; +DROP TABLE t2; + +--save_master_pos +--connection slave +--sync_with_master +--connection master + # # End of tests diff --git a/mysql-test/t/rpl_view.test b/mysql-test/t/rpl_view.test index 0a0c6a6dddb..d0990b4fbee 100644 --- a/mysql-test/t/rpl_view.test +++ b/mysql-test/t/rpl_view.test @@ -45,3 +45,87 @@ drop table t1; sync_slave_with_master; --replace_column 2 # 5 # show binlog events limit 1,100; + + + +# +# BUG#20438: CREATE statements for views, stored routines and triggers can be +# not replicable. +# + +--echo +--echo ---> Test for BUG#20438 + +# Prepare environment. + +--echo +--echo ---> Preparing environment... +--echo ---> connection: master +--connection master + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; +--enable_warnings + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo +--echo ---> connection: master +--connection master + +# Test. + +--echo +--echo ---> Creating objects... + +CREATE TABLE t1(c INT); + +/*!50003 CREATE VIEW v1 AS SELECT * FROM t1 */; + +--echo +--echo ---> Inserting value... + +INSERT INTO t1 VALUES(1); + +--echo +--echo ---> Checking on master... + +SELECT * FROM t1; + +--echo +--echo ---> Synchronizing slave with master... + +--save_master_pos +--connection slave +--sync_with_master + +--echo ---> connection: master + +--echo +--echo ---> Checking on slave... + +SELECT * FROM t1; + +# Cleanup. + +--echo +--echo ---> connection: master +--connection master + +--echo +--echo ---> Cleaning up... + +DROP VIEW v1; +DROP TABLE t1; + +--save_master_pos +--connection slave +--sync_with_master +--connection master + diff --git a/sql/sp.cc b/sql/sp.cc index b5a4f8bad8f..e8d36e15fa2 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -633,7 +633,10 @@ db_create_routine(THD *thd, int type, sp_head *sp) log_query.append(STRING_WITH_LEN("CREATE ")); append_definer(thd, &log_query, &thd->lex->definer->user, &thd->lex->definer->host); - log_query.append(thd->lex->stmt_definition_begin); + log_query.append(thd->lex->stmt_definition_begin, + (char *)sp->m_body_begin - + thd->lex->stmt_definition_begin + + sp->m_body.length); /* Such a statement can always go directly to binlog, no trans cache */ Query_log_event qinfo(thd, log_query.c_ptr(), log_query.length(), 0, diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 7bcadde2760..eec6e0fc3cd 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -527,10 +527,7 @@ sp_head::init_strings(THD *thd, LEX *lex) Trim "garbage" at the end. This is sometimes needed with the "/ * ! VERSION... * /" wrapper in dump files. */ - while (m_body_begin < endp && - (endp[-1] <= ' ' || endp[-1] == '*' || - endp[-1] == '/' || endp[-1] == ';')) - endp-= 1; + endp= skip_rear_comments(m_body_begin, endp); m_body.length= endp - m_body_begin; m_body.str= strmake_root(root, (char *)m_body_begin, m_body.length); diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index efbf29cf207..bb66fde79fe 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1054,6 +1054,30 @@ int MYSQLlex(void *arg, void *yythd) } } + +/* + Skip comment in the end of statement. + + SYNOPSIS + skip_rear_comments() + begin pointer to the beginning of statement + end pointer to the end of statement + + DESCRIPTION + The function is intended to trim comments at the end of the statement. + + RETURN + Pointer to the last non-comment symbol of the statement. +*/ + +uchar *skip_rear_comments(uchar *begin, uchar *end) +{ + while (begin < end && (end[-1] <= ' ' || end[-1] == '*' || + end[-1] == '/' || end[-1] == ';')) + end-= 1; + return end; +} + /* st_select_lex structures initialisations */ diff --git a/sql/sql_lex.h b/sql/sql_lex.h index e5b087fc72a..d7438a37d7e 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1115,4 +1115,4 @@ extern void lex_free(void); extern void lex_start(THD *thd, uchar *buf,uint length); extern void lex_end(LEX *lex); extern int MYSQLlex(void *arg, void *yythd); - +extern uchar *skip_rear_comments(uchar *begin, uchar *end); diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index f46c7414fa4..e806dd4a3f3 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -295,7 +295,10 @@ end: append_definer(thd, &log_query, &definer_user, &definer_host); } - log_query.append(thd->lex->stmt_definition_begin); + log_query.append(thd->lex->stmt_definition_begin, + (char *)thd->lex->sphead->m_body_begin - + thd->lex->stmt_definition_begin + + thd->lex->sphead->m_body.length); } /* Such a statement can always go directly to binlog, no trans cache. */ diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 1561ade78af..80cb8970049 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -671,8 +671,10 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, view->query.str= (char*)str.ptr(); view->query.length= str.length()-1; // we do not need last \0 view->source.str= thd->query + thd->lex->create_view_select_start; - view->source.length= (thd->query_length - - thd->lex->create_view_select_start); + view->source.length= (char *)skip_rear_comments((uchar *)view->source.str, + (uchar *)thd->query + + thd->query_length) - + view->source.str; view->file_version= 1; view->calc_md5(md5); view->md5.str= md5; -- cgit v1.2.1 From 798ffbd8ee438009febdc1e55215e0aa25929c19 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Jul 2006 03:32:39 +0400 Subject: Temporary changes just to check some points (will be restored). --- extra/yassl/src/ssl.cpp | 2 +- mysql-test/t/rpl_openssl.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index 07f5e9859b2..3ec8e74b258 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -158,7 +158,7 @@ SSL* SSL_new(SSL_CTX* ctx) void SSL_free(SSL* ssl) { - ysDelete(ssl); +// ysDelete(ssl); } diff --git a/mysql-test/t/rpl_openssl.test b/mysql-test/t/rpl_openssl.test index af70a1a9453..e18ddce9c92 100644 --- a/mysql-test/t/rpl_openssl.test +++ b/mysql-test/t/rpl_openssl.test @@ -1,6 +1,6 @@ # TODO: THIS TEST DOES NOT WORK ON WINDOWS # This should be fixed. ---source include/not_windows.inc +#--source include/not_windows.inc source include/have_openssl.inc; source include/master-slave.inc; -- cgit v1.2.1 From 78e24656ed1da3a770bcb02d13e139269cc3232a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Jul 2006 05:34:59 +0400 Subject: Removing temporary changes. --- extra/yassl/src/ssl.cpp | 2 +- mysql-test/t/rpl_openssl.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index 3ec8e74b258..07f5e9859b2 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -158,7 +158,7 @@ SSL* SSL_new(SSL_CTX* ctx) void SSL_free(SSL* ssl) { -// ysDelete(ssl); + ysDelete(ssl); } diff --git a/mysql-test/t/rpl_openssl.test b/mysql-test/t/rpl_openssl.test index e18ddce9c92..af70a1a9453 100644 --- a/mysql-test/t/rpl_openssl.test +++ b/mysql-test/t/rpl_openssl.test @@ -1,6 +1,6 @@ # TODO: THIS TEST DOES NOT WORK ON WINDOWS # This should be fixed. -#--source include/not_windows.inc +--source include/not_windows.inc source include/have_openssl.inc; source include/master-slave.inc; -- cgit v1.2.1 From 0abc107cd23978e95dc9e2b927f65d1c2b41e887 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Jul 2006 15:06:23 +0400 Subject: Bug#16581: deadlock: server and client both read from connection in 'conc_sys' test Concurrent execution of SELECT involing at least two INFORMATION_SCHEMA tables, DROP DATABASE statement and DROP TABLE statement could have resulted in stalled connection for this SELECT statement. The problem was that for the first query of a join there was a race between select from I_S.TABLES and DROP DATABASE, and the error (no such database) was prepared to be send to the client, but the join processing was continued. On second query to I_S.COLUMNS there was a race with DROP TABLE, but this error (no such table) was downgraded to warning, and thd->net.report_error was reset. And so neither result nor error was sent to the client. The solution is to stop join processing once it is clear we are going to report a error, and also to downgrade to warnings file system errors like 'no such database' (unless we are in the 'SHOW' command), because I_S is designed not to use locks and the query to I_S should not abort if something is dropped in the middle. No test case is provided since this bug is a result of a race, and is timing dependant. But we test that plain SHOW TABLES and SHOW COLUMNS give a error if there is no such database or a table respectively. mysql-test/r/show_check.result: Add result for the test that SHOW TABLES and SHOW COLUMNS give a error if there is no such database or a table respectively. mysql-test/t/show_check.test: Add test case that SHOW TABLES and SHOW COLUMNS give a error if there is no such database or a table respectively. sql/mysql_priv.h: Remove prototype of mysql_find_files(), which is made static under find_files() name. sql/sql_show.cc: Rename mysql_find_files() to find_files() and make it static. Return FIND_FILES_OK for success, FIND_FILES_OOM for out of memory, and FIND_FILES_DIR for directory reading error. Downgrade error to warning in get_all_tables() if it is a FIND_FILES_DIR error, and we are not in the 'SHOW' command. Once 'result' is set to 1 in get_schema_tables_result(), there's no need in continuing iterations, as we are about to return a error. --- mysql-test/r/show_check.result | 4 +++ mysql-test/t/show_check.test | 11 ++++++ sql/mysql_priv.h | 2 -- sql/sql_show.cc | 81 ++++++++++++++++++++++++++++++++++-------- 4 files changed, 81 insertions(+), 17 deletions(-) diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 994501767ba..7bdfa78066c 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -625,3 +625,7 @@ View Create View v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select sql_cache 1 AS `1` DROP PROCEDURE p1; DROP VIEW v1; +SHOW TABLES FROM no_such_database; +ERROR 42000: Unknown database 'no_such_database' +SHOW COLUMNS FROM no_such_table; +ERROR 42S02: Table 'test.no_such_table' doesn't exist diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index 6937cbe949d..65a81545c87 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -495,4 +495,15 @@ SHOW CREATE VIEW v1; DROP PROCEDURE p1; DROP VIEW v1; + +# +# Check that SHOW TABLES and SHOW COLUMNS give a error if there is no +# referenced database and table respectively. +# +--error ER_BAD_DB_ERROR +SHOW TABLES FROM no_such_database; +--error ER_NO_SUCH_TABLE +SHOW COLUMNS FROM no_such_table; + + # End of 5.0 tests. diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index c9ae743addd..0d1db7db977 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -865,8 +865,6 @@ bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create); void mysqld_list_processes(THD *thd,const char *user,bool verbose); int mysqld_show_status(THD *thd); int mysqld_show_variables(THD *thd,const char *wild); -int mysql_find_files(THD *thd,List *files, const char *db, - const char *path, const char *wild, bool dir); bool mysqld_show_storage_engines(THD *thd); bool mysqld_show_privileges(THD *thd); bool mysqld_show_column_types(THD *thd); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index cabb04c5f16..fe15e2b5d5d 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -250,9 +250,35 @@ bool mysqld_show_column_types(THD *thd) } -int -mysql_find_files(THD *thd,List *files, const char *db,const char *path, - const char *wild, bool dir) +/* + find_files() - find files in a given directory. + + SYNOPSIS + find_files() + thd thread handler + files put found files in this list + db database name to set in TABLE_LIST structure + path path to database + wild filter for found files + dir read databases in path if TRUE, read .frm files in + database otherwise + + RETURN + FIND_FILES_OK success + FIND_FILES_OOM out of memory error + FIND_FILES_DIR no such directory, or directory can't be read +*/ + +enum find_files_result { + FIND_FILES_OK, + FIND_FILES_OOM, + FIND_FILES_DIR +}; + +static +find_files_result +find_files(THD *thd, List *files, const char *db, + const char *path, const char *wild, bool dir) { uint i; char *ext; @@ -262,7 +288,7 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, uint col_access=thd->col_access; #endif TABLE_LIST table_list; - DBUG_ENTER("mysql_find_files"); + DBUG_ENTER("find_files"); if (wild && !wild[0]) wild=0; @@ -275,7 +301,7 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db); else my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno); - DBUG_RETURN(-1); + DBUG_RETURN(FIND_FILES_DIR); } for (i=0 ; i < (uint) dirp->number_off_files ; i++) @@ -337,7 +363,7 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, if (files->push_back(thd->strdup(file->name))) { my_dirend(dirp); - DBUG_RETURN(-1); + DBUG_RETURN(FIND_FILES_OOM); } } DBUG_PRINT("info",("found: %d files", files->elements)); @@ -345,7 +371,7 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, VOID(ha_find_files(thd,db,path,wild,dir,files)); - DBUG_RETURN(0); + DBUG_RETURN(FIND_FILES_OK); } @@ -2000,8 +2026,8 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table) wild string otherwise it's db name; RETURN - 1 error - 0 success + zero success + non-zero error */ int make_db_list(THD *thd, List *files, @@ -2027,8 +2053,8 @@ int make_db_list(THD *thd, List *files, if (files->push_back(thd->strdup(information_schema_name.str))) return 1; } - return mysql_find_files(thd, files, NullS, mysql_data_home, - idx_field_vals->db_value, 1); + return (find_files(thd, files, NullS, mysql_data_home, + idx_field_vals->db_value, 1) != FIND_FILES_OK); } /* @@ -2055,7 +2081,8 @@ int make_db_list(THD *thd, List *files, if (files->push_back(thd->strdup(information_schema_name.str))) return 1; *with_i_schema= 1; - return mysql_find_files(thd, files, NullS, mysql_data_home, NullS, 1); + return (find_files(thd, files, NullS, + mysql_data_home, NullS, 1) != FIND_FILES_OK); } @@ -2204,9 +2231,28 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) strxmov(path, mysql_data_home, "/", base_name, NullS); end= path + (len= unpack_dirname(path,path)); len= FN_LEN - len; - if (mysql_find_files(thd, &files, base_name, - path, idx_field_vals.table_value, 0)) - goto err; + find_files_result res= find_files(thd, &files, base_name, + path, idx_field_vals.table_value, 0); + if (res != FIND_FILES_OK) + { + /* + Downgrade errors about problems with database directory to + warnings if this is not a 'SHOW' command. Another thread + may have dropped database, and we may still have a name + for that directory. + */ + if (res == FIND_FILES_DIR && lex->orig_sql_command == SQLCOM_END) + { + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + thd->net.last_errno, thd->net.last_error); + thd->clear_error(); + continue; + } + else + { + goto err; + } + } if (lower_case_table_names) orig_base_name= thd->strdup(base_name); } @@ -3969,7 +4015,12 @@ bool get_schema_tables_result(JOIN *join) if (table_list->schema_table->fill_table(thd, table_list, tab->select_cond)) + { result= 1; + join->error= 1; + table_list->is_schema_table_processed= TRUE; + break; + } table_list->is_schema_table_processed= TRUE; } } -- cgit v1.2.1 From 83c87624fa1395c7ce36d869b1cd97fcc8425a84 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 30 Jul 2006 19:30:20 +0200 Subject: BUG#21217 "mysqltest" client is inconsistent when to log a line number - Init start_lineno to 0 client/mysqltest.c: Init start_lineno to 0 and set it back to zero before comparing result file. --- client/mysqltest.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 3f2e7d8edb6..ad0f9f857bb 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -147,7 +147,7 @@ const char *user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./"; static int port = 0; static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0; static my_bool tty_password= 0, ps_protocol= 0, ps_protocol_enabled= 0; -static uint start_lineno, *lineno; +static uint start_lineno= 0, *lineno; const char *manager_user="root",*manager_host=0; char *manager_pass=0; int manager_port=MYSQL_MANAGER_PORT; @@ -580,7 +580,7 @@ static void die(const char *fmt, ...) if (cur_file && cur_file != file_stack) fprintf(stderr, "In included file \"%s\": ", cur_file->file_name); - if (start_lineno != 0) + if (start_lineno > 0) fprintf(stderr, "At line %u: ", start_lineno); vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); @@ -4072,6 +4072,8 @@ int main(int argc, char **argv) parser.current_line += current_line_inc; } + start_lineno= 0; + if (!query_executed && result_file && my_stat(result_file, &res_info, 0)) { /* -- cgit v1.2.1 From c8673b09b871f5c6d55ce69e8302dbf0e5b2c348 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Jul 2006 17:33:37 +0300 Subject: Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM When executing ALTER TABLE all the attributes of the view were overwritten. This is contrary to the user's expectations. So some of the view attributes are preserved now : namely security and algorithm. This means that if they are not specified in ALTER VIEW their values are preserved from CREATE VIEW instead of being defaulted. mysql-test/r/view.result: Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM - test suite mysql-test/t/view.test: Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM - test suite sql/sql_lex.h: Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM - must make create_view_suid a tristate : on/off/unspecified sql/sql_view.cc: Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM - open the view to get it's attributes and put then as defaults for ALTER VIEW sql/sql_yacc.yy: Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM - must make create_view_suid a tristate : on/off/unspecified sql/table.h: Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM - must make create_view_suid a tristate : on/off/unspecified --- mysql-test/r/view.result | 11 ++++++++++ mysql-test/t/view.test | 13 +++++++++++ sql/sql_lex.h | 2 +- sql/sql_view.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ sql/sql_yacc.yy | 6 +++--- sql/table.h | 4 ++++ 6 files changed, 88 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index c8a673e2209..62bf5b30503 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2807,3 +2807,14 @@ yadda yad DROP VIEW v1; DROP TABLE t1; +CREATE TABLE t1 (x INT, y INT); +CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select `t1`.`x` AS `x` from `t1` +ALTER VIEW v1 AS SELECT x, y FROM t1; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select `t1`.`x` AS `x`,`t1`.`y` AS `y` from `t1` +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 6399cef9086..5db9030eece 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2667,3 +2667,16 @@ SELECT * FROM v1; DROP VIEW v1; DROP TABLE t1; + +# +#Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM +# +CREATE TABLE t1 (x INT, y INT); +CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1; +SHOW CREATE VIEW v1; + +ALTER VIEW v1 AS SELECT x, y FROM t1; +SHOW CREATE VIEW v1; + +DROP VIEW v1; +DROP TABLE t1; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index e5b087fc72a..897f6c25190 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -978,7 +978,7 @@ typedef struct st_lex : public Query_tables_list /* view created to be run from definer (standard behaviour) */ - bool create_view_suid; + uint8 create_view_suid; /* Characterstics of trigger being created */ st_trg_chistics trg_chistics; /* diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 1561ade78af..8aa93a7bbeb 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -155,6 +155,54 @@ err: DBUG_RETURN(TRUE); } +/* + Fill defined view parts + + SYNOPSIS + fill_defined_view_parts() + thd current thread. + view view to operate on + + DESCRIPTION + This function will initialize the parts of the view + definition that are not specified in ALTER VIEW + to their values from CREATE VIEW. + The view must be opened to get its definition. + We use a copy of the view when opening because we want + to preserve the original view instance. + + RETURN VALUE + TRUE can't open table + FALSE success +*/ +static bool +fill_defined_view_parts (THD *thd, TABLE_LIST *view) +{ + LEX *lex= thd->lex; + bool not_used; + TABLE_LIST decoy; + + memcpy (&decoy, view, sizeof (TABLE_LIST)); + if (!open_table(thd, &decoy, thd->mem_root, ¬_used, 0) && + !decoy.view) + { + return TRUE; + } + if (!lex->definer) + { + view->definer.host= decoy.definer.host; + view->definer.user= decoy.definer.user; + lex->definer= &view->definer; + } + if (lex->create_view_algorithm == VIEW_ALGORITHM_UNDEFINED) + lex->create_view_algorithm= decoy.algorithm; + if (lex->create_view_suid == VIEW_SUID_DEFAULT) + lex->create_view_suid= decoy.view_suid ? + VIEW_SUID_DEFINER : VIEW_SUID_INVOKER; + + return FALSE; +} + /* Creating/altering VIEW procedure @@ -207,7 +255,15 @@ bool mysql_create_view(THD *thd, } if (mode != VIEW_CREATE_NEW) + { + if (mode == VIEW_ALTER && + fill_defined_view_parts(thd, view)) + { + res= TRUE; + goto err; + } sp_cache_invalidate(); + } if (!lex->definer) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 425945f525e..677c327be3e 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -8997,11 +8997,11 @@ view_algorithm_opt: view_suid: /* empty */ - { Lex->create_view_suid= TRUE; } + { Lex->create_view_suid= VIEW_SUID_DEFAULT; } | SQL_SYM SECURITY_SYM DEFINER_SYM - { Lex->create_view_suid= TRUE; } + { Lex->create_view_suid= VIEW_SUID_DEFINER; } | SQL_SYM SECURITY_SYM INVOKER_SYM - { Lex->create_view_suid= FALSE; } + { Lex->create_view_suid= VIEW_SUID_INVOKER; } ; view_tail: diff --git a/sql/table.h b/sql/table.h index eb34867c390..675439e3662 100644 --- a/sql/table.h +++ b/sql/table.h @@ -360,6 +360,10 @@ typedef struct st_schema_table #define VIEW_ALGORITHM_TMPTABLE 1 #define VIEW_ALGORITHM_MERGE 2 +#define VIEW_SUID_INVOKER 0 +#define VIEW_SUID_DEFINER 1 +#define VIEW_SUID_DEFAULT 2 + /* view WITH CHECK OPTION parameter options */ #define VIEW_CHECK_NONE 0 #define VIEW_CHECK_LOCAL 1 -- cgit v1.2.1 From b74cb62348c2815c63452dd4d6c50c2510302a6e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Jul 2006 20:56:06 +0300 Subject: Bug #11551: Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE made DROP VIEW to continue on error and report an aggregated error at its end. This makes it similar to DROP TABLE. mysql-test/r/view.result: Bug #11551: Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE - test case - changed error message mysql-test/t/view.test: Bug #11551: Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE - test case sql/sql_view.cc: Bug #11551: Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE - made DROP VIEW to continue on error and report an aggregated error --- mysql-test/r/view.result | 21 +++++++++++++++++++- mysql-test/t/view.test | 21 ++++++++++++++++++++ sql/sql_view.cc | 51 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 79 insertions(+), 14 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index b2c65423b59..2cb2588428f 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -193,7 +193,7 @@ c d 2 5 3 10 drop view v100; -ERROR 42S02: Unknown table 'test.v100' +ERROR 42S02: Unknown table 'v100' drop view t1; ERROR HY000: 'test.t1' is not VIEW drop table v1; @@ -2820,3 +2820,22 @@ b c DROP VIEW v1, v2; DROP TABLE t1; +CREATE TABLE t1 (id INT); +CREATE VIEW v1 AS SELECT id FROM t1; +SHOW TABLES; +Tables_in_test +t1 +v1 +DROP VIEW v2,v1; +ERROR 42S02: Unknown table 'v2' +SHOW TABLES; +Tables_in_test +t1 +CREATE VIEW v1 AS SELECT id FROM t1; +DROP VIEW t1,v1; +ERROR HY000: 'test.t1' is not VIEW +SHOW TABLES; +Tables_in_test +t1 +DROP TABLE t1; +DROP VIEW IF EXISTS v1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 1b930353ca4..599b00f3fd1 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2686,3 +2686,24 @@ INSERT INTO v2 (col) VALUES ('c'); SELECT s1 FROM t1; DROP VIEW v1, v2; DROP TABLE t1; + +# +# Bug #11551: Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE +# +CREATE TABLE t1 (id INT); +CREATE VIEW v1 AS SELECT id FROM t1; +SHOW TABLES; + +--error 1051 +DROP VIEW v2,v1; +SHOW TABLES; + +CREATE VIEW v1 AS SELECT id FROM t1; +--error 1347 +DROP VIEW t1,v1; +SHOW TABLES; + +DROP TABLE t1; +--disable_warnings +DROP VIEW IF EXISTS v1; +--enable_warnings diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 1561ade78af..3c3d50605aa 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1226,8 +1226,11 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) DBUG_ENTER("mysql_drop_view"); char path[FN_REFLEN]; TABLE_LIST *view; - bool type= 0; + frm_type_enum type; db_type not_used; + String non_existant_views; + char *wrong_object_db= NULL, *wrong_object_name= NULL; + bool error= FALSE; for (view= views; view; view= view->next_local) { @@ -1235,8 +1238,9 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) view->table_name, reg_ext, NullS); (void) unpack_filename(path, path); VOID(pthread_mutex_lock(&LOCK_open)); - if (access(path, F_OK) || - (type= (mysql_frm_type(thd, path, ¬_used) != FRMTYPE_VIEW))) + type= FRMTYPE_ERROR; + if (access(path, F_OK) || + FRMTYPE_VIEW != (type= mysql_frm_type(thd, path, ¬_used))) { char name[FN_REFLEN]; my_snprintf(name, sizeof(name), "%s.%s", view->db, view->table_name); @@ -1248,25 +1252,46 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) VOID(pthread_mutex_unlock(&LOCK_open)); continue; } - if (type) - my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->table_name, "VIEW"); + if (type == FRMTYPE_TABLE) + { + if (!wrong_object_name) + { + wrong_object_db= view->db; + wrong_object_name= view->table_name; + } + } else - my_error(ER_BAD_TABLE_ERROR, MYF(0), name); - goto err; + { + if (non_existant_views.length()) + non_existant_views.append(','); + non_existant_views.append(String(view->table_name,system_charset_info)); + } + VOID(pthread_mutex_unlock(&LOCK_open)); + continue; } if (my_delete(path, MYF(MY_WME))) - goto err; + error= TRUE; query_cache_invalidate3(thd, view, 0); sp_cache_invalidate(); VOID(pthread_mutex_unlock(&LOCK_open)); } + if (error) + { + DBUG_RETURN(TRUE); + } + if (wrong_object_name) + { + my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name, + "VIEW"); + DBUG_RETURN(TRUE); + } + if (non_existant_views.length()) + { + my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr()); + DBUG_RETURN(TRUE); + } send_ok(thd); DBUG_RETURN(FALSE); - -err: - VOID(pthread_mutex_unlock(&LOCK_open)); - DBUG_RETURN(TRUE); - } -- cgit v1.2.1 From d251e9be4315a3bf92a0e997daf5c2c2f42588f3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Jul 2006 12:01:43 -0700 Subject: Bug#21269 (DEFINER-clause is allowed for UDF-functions) The problem was that the grammar allows to create a function with an optional definer clause, and define it as a UDF with the SONAME keyword. Such combination should be reported as an error. The solution is to not change the grammar itself, and to introduce a specific check in the yacc actions in 'create_function_tail' for UDF, that now reports ER_WRONG_USAGE when using both DEFINER and SONAME. mysql-test/r/udf.result: Added tests for Bug#21269 (DEFINER-clause is allowed for UDF-functions) mysql-test/t/udf.test: Added tests for Bug#21269 (DEFINER-clause is allowed for UDF-functions) sql/sql_yacc.yy: Creating a UDF function with a DEFINER clause is now a syntax error. --- mysql-test/r/udf.result | 6 ++++++ mysql-test/t/udf.test | 12 ++++++++++++ sql/sql_yacc.yy | 11 +++++++++++ 3 files changed, 29 insertions(+) diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result index 484c42c41bf..d71e7ef2ce7 100644 --- a/mysql-test/r/udf.result +++ b/mysql-test/r/udf.result @@ -93,6 +93,12 @@ NULL 0R FR DROP TABLE bug19904; +CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse +RETURNS STRING SONAME "should_not_parse.so"; +ERROR HY000: Incorrect usage of SONAME and DEFINER +CREATE DEFINER=someone@somewhere FUNCTION should_not_parse +RETURNS STRING SONAME "should_not_parse.so"; +ERROR HY000: Incorrect usage of SONAME and DEFINER End of 5.0 tests. DROP FUNCTION metaphon; DROP FUNCTION myfunc_double; diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index f3be08c8537..9d295d32831 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -109,6 +109,18 @@ SELECT myfunc_double(n) AS f FROM bug19904; SELECT metaphon(v) AS f FROM bug19904; DROP TABLE bug19904; +# +# Bug#21269: DEFINER-clause is allowed for UDF-functions +# + +--error ER_WRONG_USAGE +CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse +RETURNS STRING SONAME "should_not_parse.so"; + +--error ER_WRONG_USAGE +CREATE DEFINER=someone@somewhere FUNCTION should_not_parse +RETURNS STRING SONAME "should_not_parse.so"; + --echo End of 5.0 tests. # diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index a92d19ee58d..d497678cec3 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1256,6 +1256,17 @@ create_function_tail: RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys { LEX *lex=Lex; + if (lex->definer != NULL) + { + /* + DEFINER is a concept meaningful when interpreting SQL code. + UDF functions are compiled. + Using DEFINER with UDF has therefore no semantic, + and is considered a parsing error. + */ + my_error(ER_WRONG_USAGE, MYF(0), "SONAME", "DEFINER"); + YYABORT; + } lex->sql_command = SQLCOM_CREATE_FUNCTION; lex->udf.name = lex->spname->m_name; lex->udf.returns=(Item_result) $2; -- cgit v1.2.1 From 45871dbfd907cd0f0e68d4c73bbb1e96b4d0eb22 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Jul 2006 23:05:54 +0400 Subject: select.result, func_group.result, sql_select.cc: After merge fix mysql-test/r/select.result: After merge fix mysql-test/r/func_group.result: After merge fix sql/sql_select.cc: After merge fix --- mysql-test/r/func_group.result | 138 ----------------------------------------- mysql-test/r/select.result | 98 ++++++++++++++--------------- sql/sql_select.cc | 3 +- 3 files changed, 51 insertions(+), 188 deletions(-) diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index f0fd489867d..896b79297f8 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -821,144 +821,6 @@ SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6; MAX(id) NULL DROP TABLE t1; -create table t1m (a int) engine=myisam; -create table t1i (a int) engine=innodb; -create table t2m (a int) engine=myisam; -create table t2i (a int) engine=innodb; -insert into t2m values (5); -insert into t2i values (5); -select min(a) from t1m; -min(a) -NULL -select min(7) from t1m; -min(7) -NULL -select min(7) from DUAL; -min(7) -NULL -explain select min(7) from t2m join t1m; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -select min(7) from t2m join t1m; -min(7) -NULL -select max(a) from t1m; -max(a) -NULL -select max(7) from t1m; -max(7) -NULL -select max(7) from DUAL; -max(7) -NULL -explain select max(7) from t2m join t1m; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -select max(7) from t2m join t1m; -max(7) -NULL -select 1, min(a) from t1m where a=99; -1 min(a) -1 NULL -select 1, min(a) from t1m where 1=99; -1 min(a) -1 NULL -select 1, min(1) from t1m where a=99; -1 min(1) -1 NULL -select 1, min(1) from t1m where 1=99; -1 min(1) -1 NULL -select 1, max(a) from t1m where a=99; -1 max(a) -1 NULL -select 1, max(a) from t1m where 1=99; -1 max(a) -1 NULL -select 1, max(1) from t1m where a=99; -1 max(1) -1 NULL -select 1, max(1) from t1m where 1=99; -1 max(1) -1 NULL -select min(a) from t1i; -min(a) -NULL -select min(7) from t1i; -min(7) -NULL -select min(7) from DUAL; -min(7) -NULL -explain select min(7) from t2i join t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2i ALL NULL NULL NULL NULL 1 -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select min(7) from t2i join t1i; -min(7) -NULL -select max(a) from t1i; -max(a) -NULL -select max(7) from t1i; -max(7) -NULL -select max(7) from DUAL; -max(7) -NULL -explain select max(7) from t2i join t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2i ALL NULL NULL NULL NULL 1 -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select max(7) from t2i join t1i; -max(7) -NULL -select 1, min(a) from t1i where a=99; -1 min(a) -1 NULL -select 1, min(a) from t1i where 1=99; -1 min(a) -1 NULL -select 1, min(1) from t1i where a=99; -1 min(1) -1 NULL -select 1, min(1) from t1i where 1=99; -1 min(1) -1 NULL -select 1, max(a) from t1i where a=99; -1 max(a) -1 NULL -select 1, max(a) from t1i where 1=99; -1 max(a) -1 NULL -select 1, max(1) from t1i where a=99; -1 max(1) -1 NULL -select 1, max(1) from t1i where 1=99; -1 max(1) -1 NULL -explain select count(*), min(7), max(7) from t1m, t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select count(*), min(7), max(7) from t1m, t1i; -count(*) min(7) max(7) -0 NULL NULL -explain select count(*), min(7), max(7) from t1m, t2i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found -1 SIMPLE t2i ALL NULL NULL NULL NULL 1 -select count(*), min(7), max(7) from t1m, t2i; -count(*) min(7) max(7) -0 NULL NULL -explain select count(*), min(7), max(7) from t2m, t1i; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2m system NULL NULL NULL NULL 1 -1 SIMPLE t1i ALL NULL NULL NULL NULL 1 -select count(*), min(7), max(7) from t2m, t1i; -count(*) min(7) max(7) -0 NULL NULL -drop table t1m, t1i, t2m, t2i; CREATE TABLE t1 (id int PRIMARY KEY, b char(3), INDEX(b)); INSERT INTO t1 VALUES (1,'xx'), (2,'aa'); SELECT * FROM t1; diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 3df4f3f78ec..b5d059be4c5 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2762,6 +2762,55 @@ a b a b 1 NULL 4 10 2 10 4 10 DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1)); +CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2)); +INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941); +INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941); +explain select max(key1) from t1 where key1 <= 0.6158; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select max(key2) from t2 where key2 <= 1.6158; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select min(key1) from t1 where key1 >= 0.3762; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select min(key2) from t2 where key2 >= 1.3762; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select max(key1), min(key2) from t1, t2 +where key1 <= 0.6158 and key2 >= 1.3762; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +select max(key1) from t1 where key1 <= 0.6158; +max(key1) +0.61580002307892 +select max(key2) from t2 where key2 <= 1.6158; +max(key2) +1.6158000230789 +select min(key1) from t1 where key1 >= 0.3762; +min(key1) +0.37619999051094 +select min(key2) from t2 where key2 >= 1.3762; +min(key2) +1.3761999607086 +select max(key1), min(key2) from t1, t2 +where key1 <= 0.6158 and key2 >= 1.3762; +max(key1) min(key2) +0.61580002307892 1.3761999607086 +select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; +max(key1) +0.61580002307892 +select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; +min(key1) +0.37619999051094 +DROP TABLE t1,t2; CREATE TABLE t1 ( K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', @@ -3151,55 +3200,6 @@ select count(*) from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id; count(*) 6 -CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1)); -CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2)); -INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941); -INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941); -explain select max(key1) from t1 where key1 <= 0.6158; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key2) from t2 where key2 <= 1.6158; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key1) from t1 where key1 >= 0.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key2) from t2 where key2 >= 1.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key1), min(key2) from t1, t2 -where key1 <= 0.6158 and key2 >= 1.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -select max(key1) from t1 where key1 <= 0.6158; -max(key1) -0.61580002307892 -select max(key2) from t2 where key2 <= 1.6158; -max(key2) -1.6158000230789 -select min(key1) from t1 where key1 >= 0.3762; -min(key1) -0.37619999051094 -select min(key2) from t2 where key2 >= 1.3762; -min(key2) -1.3761999607086 -select max(key1), min(key2) from t1, t2 -where key1 <= 0.6158 and key2 >= 1.3762; -max(key1) min(key2) -0.61580002307892 1.3761999607086 -select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; -max(key1) -0.61580002307892 -select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; -min(key1) -0.37619999051094 -DROP TABLE t1,t2; drop table t1,t2,t3; create table t1 (a int); create table t2 (b int); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f6f45aea41e..412dbb529b6 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -687,8 +687,9 @@ JOIN::optimize() Notice that make_cond_for_table() will always succeed to remove all computed conditions, because opt_sum_query() is applicable only to conjunctions. + Preserve conditions for EXPLAIN. */ - if (conds) + if (conds && !(thd->lex->describe & DESCRIBE_EXTENDED)) { COND *table_independent_conds= make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0); -- cgit v1.2.1 From ec95bf782f0fd304756d974667893e0f696dbb64 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 1 Aug 2006 11:05:54 +0300 Subject: Bug #20103: Escaping with backslash does not work - make the client to respect the server-side no_backslash_escapes option and disable the special meaning of backslash also at client side. mysql-test/r/mysql_client.result: Bug #20103: Escaping with backslash does not work - test case mysql-test/t/mysql_client.test: Bug #20103: Escaping with backslash does not work - test case --- client/mysql.cc | 3 ++- mysql-test/r/mysql_client.result | 4 ++++ mysql-test/t/mysql_client.test | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/client/mysql.cc b/client/mysql.cc index 94b43d030e8..0b7284426c5 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1221,7 +1221,8 @@ static bool add_line(String &buffer,char *line,char *in_string, continue; } #endif - if (!*ml_comment && inchar == '\\') + if (!*ml_comment && inchar == '\\' && + !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)) { // Found possbile one character command like \c diff --git a/mysql-test/r/mysql_client.result b/mysql-test/r/mysql_client.result index 87d09428ff6..a20bd60aaf3 100644 --- a/mysql-test/r/mysql_client.result +++ b/mysql-test/r/mysql_client.result @@ -2,3 +2,7 @@ 1 ERROR 1064 (42000) at line 3: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 ERROR at line 1: USE must be followed by a database name +\ +\\ +'; +'; diff --git a/mysql-test/t/mysql_client.test b/mysql-test/t/mysql_client.test index e4b6658b631..003a086212e 100644 --- a/mysql-test/t/mysql_client.test +++ b/mysql-test/t/mysql_client.test @@ -27,3 +27,14 @@ # client comment recognized, but parameter missing => error --exec echo "use" > $MYSQLTEST_VARDIR/tmp/bug20432.sql --exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1 + +# +# Bug #20103: Escaping with backslash does not work +# +--exec echo "SET SQL_MODE = 'NO_BACKSLASH_ESCAPES';" > $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec echo "SELECT '\';" >> $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20103.sql 2>&1 + +--exec echo "SET SQL_MODE = '';" > $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec echo "SELECT '\';';" >> $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20103.sql 2>&1 -- cgit v1.2.1 From 75e40b161b5cbbea28eca2641e6dfadaf09267a1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 1 Aug 2006 21:59:58 +0200 Subject: Applied innodb-5.0-ss677 snapshot. Fixes: - bug #19834: Using cursors when running in READ-COMMITTED can cause InnoDB to crash - bug #21112: InnoDB slow with > 100,000 .ibd files - bug #21113: Duplicate printout in SHOW INNODB STATUS innobase/fil/fil0fil.c: Applied innodb-5.0-ss677 snapshot. Make the tablespace cache hash size 100 or 1000 times bigger. Fixes bug #21112. innobase/ibuf/ibuf0ibuf.c: Applied innodb-5.0-ss677 snapshot. ibuf_print(): Don't print redundant information. Fixes bug #21113. sql/ha_innodb.cc: Applied innodb-5.0-ss677 snapshot. ha_innobase::start_stmt(): patch from Heikki: Do not call read_view_close_for_mysql(). (Bug #19834) --- innobase/fil/fil0fil.c | 15 +++++++++------ innobase/ibuf/ibuf0ibuf.c | 16 ++-------------- sql/ha_innodb.cc | 26 +++++++++----------------- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/innobase/fil/fil0fil.c b/innobase/fil/fil0fil.c index cfd9813101d..2272f7cd8b3 100644 --- a/innobase/fil/fil0fil.c +++ b/innobase/fil/fil0fil.c @@ -251,9 +251,6 @@ struct fil_system_struct { initialized. */ fil_system_t* fil_system = NULL; -/* The tablespace memory cache hash table size */ -#define FIL_SYSTEM_HASH_SIZE 50 /* TODO: make bigger! */ - /************************************************************************ NOTE: you must call fil_mutex_enter_and_prepare_for_io() first! @@ -1324,11 +1321,17 @@ fil_init( /*=====*/ ulint max_n_open) /* in: max number of open files */ { + ulint hash_size; + ut_a(fil_system == NULL); - /*printf("Initializing the tablespace cache with max %lu open files\n", - max_n_open); */ - fil_system = fil_system_create(FIL_SYSTEM_HASH_SIZE, max_n_open); + if (srv_file_per_table) { + hash_size = 50000; + } else { + hash_size = 5000; + } + + fil_system = fil_system_create(hash_size, max_n_open); } /*********************************************************************** diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c index b95f0a1832b..9c7d9c5c3da 100644 --- a/innobase/ibuf/ibuf0ibuf.c +++ b/innobase/ibuf/ibuf0ibuf.c @@ -3499,21 +3499,9 @@ ibuf_print( data = UT_LIST_GET_FIRST(ibuf->data_list); while (data) { - fprintf(file, - "Ibuf for space %lu: size %lu, free list len %lu, seg size %lu,", - (ulong) data->space, (ulong) data->size, - (ulong) data->free_list_len, - (ulong) data->seg_size); - - if (data->empty) { - fputs(" is empty\n", file); - } else { - fputs(" is not empty\n", file); - } fprintf(file, - "Ibuf for space %lu: size %lu, free list len %lu, seg size %lu,\n" - "%lu inserts, %lu merged recs, %lu merges\n", - (ulong) data->space, + "Ibuf: size %lu, free list len %lu, seg size %lu,\n" + "%lu inserts, %lu merged recs, %lu merges\n", (ulong) data->size, (ulong) data->free_list_len, (ulong) data->seg_size, diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 6aadce0191a..472506f9903 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -5943,14 +5943,6 @@ ha_innobase::start_stmt( innobase_release_stat_resources(trx); - if (trx->isolation_level <= TRX_ISO_READ_COMMITTED - && trx->global_read_view) { - /* At low transaction isolation levels we let - each consistent read set its own snapshot */ - - read_view_close_for_mysql(trx); - } - prebuilt->sql_stat_start = TRUE; prebuilt->hint_need_to_fetch_extra_cols = 0; prebuilt->read_just_key = 0; @@ -6684,17 +6676,17 @@ ha_innobase::store_lock( && !thd->tablespace_op && thd->lex->sql_command != SQLCOM_TRUNCATE && thd->lex->sql_command != SQLCOM_OPTIMIZE + #ifdef __WIN__ - /* - for alter table on win32 for succesfull operation - completion it is used TL_WRITE(=10) lock instead of - TL_WRITE_ALLOW_READ(=6), however here in innodb handler - TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes - race condition when several clients do alter table - simultaneously (bug #17264). This fix avoids the problem. - */ - && thd->lex->sql_command != SQLCOM_ALTER_TABLE + /* For alter table on win32 for succesful operation + completion it is used TL_WRITE(=10) lock instead of + TL_WRITE_ALLOW_READ(=6), however here in innodb handler + TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes + race condition when several clients do alter table + simultaneously (bug #17264). This fix avoids the problem. */ + && thd->lex->sql_command != SQLCOM_ALTER_TABLE #endif + && thd->lex->sql_command != SQLCOM_CREATE_TABLE) { lock_type = TL_WRITE_ALLOW_WRITE; -- cgit v1.2.1 From 53cc83fef234277af1b3d2362d070f737c854390 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Aug 2006 02:21:36 +0200 Subject: .del-sp.test.orig: Delete: mysql-test/t/sp.test.orig BitKeeper/deleted/.del-sp.test.orig: Delete: mysql-test/t/sp.test.orig --- mysql-test/t/sp.test.orig | 5716 --------------------------------------------- 1 file changed, 5716 deletions(-) delete mode 100644 mysql-test/t/sp.test.orig diff --git a/mysql-test/t/sp.test.orig b/mysql-test/t/sp.test.orig deleted file mode 100644 index a4b99620344..00000000000 --- a/mysql-test/t/sp.test.orig +++ /dev/null @@ -1,5716 +0,0 @@ -# -# Basic stored PROCEDURE tests -# -# Please keep this file free of --error cases and other -# things that will not run in a single debugged mysqld -# process (e.g. master-slave things). -# -# Test cases for bugs are added at the end. See template there. -# -# Tests that require --error go into sp-error.test -# Tests that require inndb go into sp_trans.test -# Tests that check privilege and security issues go to sp-security.test. -# Tests that require multiple connections, except security/privilege tests, -# go to sp-thread. -# Tests that uses 'goto' to into sp-goto.test (currently disabled) -# Tests that destroys system tables (e.g. mysql.proc) for error testing -# go to sp-destruct. - -use test; - -# Test tables -# -# t1 and t2 are reused throughout the file, and dropped at the end. -# t3 and up are created and dropped when needed. -# ---disable_warnings -drop table if exists t1,t2,t3,t4; ---enable_warnings -create table t1 ( - id char(16) not null default '', - data int not null -); -create table t2 ( - s char(16), - i int, - d double -); - - -# Single statement, no params. ---disable_warnings -drop procedure if exists foo42; ---enable_warnings -create procedure foo42() - insert into test.t1 values ("foo", 42); - -call foo42(); -select * from t1; -delete from t1; -drop procedure foo42; - - -# Single statement, two IN params. ---disable_warnings -drop procedure if exists bar; ---enable_warnings -create procedure bar(x char(16), y int) - insert into test.t1 values (x, y); - -call bar("bar", 666); -select * from t1; -delete from t1; -# Don't drop procedure yet... - - -# Now for multiple statements... -delimiter |; - -# Empty statement ---disable_warnings -drop procedure if exists empty| ---enable_warnings -create procedure empty() -begin -end| - -call empty()| -drop procedure empty| - -# Scope test. This is legal (warnings might be possible in the future, -# but for the time being, we just accept it). ---disable_warnings -drop procedure if exists scope| ---enable_warnings -create procedure scope(a int, b float) -begin - declare b int; - declare c float; - - begin - declare c int; - end; -end| - -drop procedure scope| - -# Two statements. ---disable_warnings -drop procedure if exists two| ---enable_warnings -create procedure two(x1 char(16), x2 char(16), y int) -begin - insert into test.t1 values (x1, y); - insert into test.t1 values (x2, y); -end| - -call two("one", "two", 3)| -select * from t1| -delete from t1| -drop procedure two| - - -# Simple test of local variables and SET. ---disable_warnings -drop procedure if exists locset| ---enable_warnings -create procedure locset(x char(16), y int) -begin - declare z1, z2 int; - set z1 = y; - set z2 = z1+2; - insert into test.t1 values (x, z2); -end| - -call locset("locset", 19)| -select * from t1| -delete from t1| -drop procedure locset| - - -# In some contexts local variables are not recognized -# (and in some, you have to qualify the identifier). ---disable_warnings -drop procedure if exists setcontext| ---enable_warnings -create procedure setcontext() -begin - declare data int default 2; - - insert into t1 (id, data) values ("foo", 1); - replace t1 set data = data, id = "bar"; - update t1 set id = "kaka", data = 3 where t1.data = data; -end| - -call setcontext()| -select * from t1| -delete from t1| -drop procedure setcontext| - - -# Set things to null -create table t3 ( d date, i int, f double, s varchar(32) )| - ---disable_warnings -drop procedure if exists nullset| ---enable_warnings -create procedure nullset() -begin - declare ld date; - declare li int; - declare lf double; - declare ls varchar(32); - - set ld = null, li = null, lf = null, ls = null; - insert into t3 values (ld, li, lf, ls); - - insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"), - ((li is null), 1, "li is null"), - ((li = 0), null, "li = 0"), - ((lf is null), 1, "lf is null"), - ((lf = 0), null, "lf = 0"), - ((ls is null), 1, "ls is null"); -end| - -call nullset()| -select * from t3| -drop table t3| -drop procedure nullset| - - -# The peculiar (non-standard) mixture of variables types in SET. ---disable_warnings -drop procedure if exists mixset| ---enable_warnings -create procedure mixset(x char(16), y int) -begin - declare z int; - - set @z = y, z = 666, max_join_size = 100; - insert into test.t1 values (x, z); -end| - -call mixset("mixset", 19)| -show variables like 'max_join_size'| -select id,data,@z from t1| -delete from t1| -drop procedure mixset| - - -# Multiple CALL statements, one with OUT parameter. ---disable_warnings -drop procedure if exists zip| ---enable_warnings -create procedure zip(x char(16), y int) -begin - declare z int; - call zap(y, z); - call bar(x, z); -end| - -# SET local variables and OUT parameter. ---disable_warnings -drop procedure if exists zap| ---enable_warnings -create procedure zap(x int, out y int) -begin - declare z int; - set z = x+1, y = z; -end| - -call zip("zip", 99)| -select * from t1| -delete from t1| -drop procedure zip| -drop procedure bar| - -# Top-level OUT parameter -call zap(7, @zap)| -select @zap| - -drop procedure zap| - - -# "Deep" calls... ---disable_warnings -drop procedure if exists c1| ---enable_warnings -create procedure c1(x int) - call c2("c", x)| ---disable_warnings -drop procedure if exists c2| ---enable_warnings -create procedure c2(s char(16), x int) - call c3(x, s)| ---disable_warnings -drop procedure if exists c3| ---enable_warnings -create procedure c3(x int, s char(16)) - call c4("level", x, s)| ---disable_warnings -drop procedure if exists c4| ---enable_warnings -create procedure c4(l char(8), x int, s char(16)) - insert into t1 values (concat(l,s), x)| - -call c1(42)| -select * from t1| -delete from t1| -drop procedure c1| -drop procedure c2| -drop procedure c3| -drop procedure c4| - -# INOUT test ---disable_warnings -drop procedure if exists iotest| ---enable_warnings -create procedure iotest(x1 char(16), x2 char(16), y int) -begin - call inc2(x2, y); - insert into test.t1 values (x1, y); -end| - ---disable_warnings -drop procedure if exists inc2| ---enable_warnings -create procedure inc2(x char(16), y int) -begin - call inc(y); - insert into test.t1 values (x, y); -end| - ---disable_warnings -drop procedure if exists inc| ---enable_warnings -create procedure inc(inout io int) - set io = io + 1| - -call iotest("io1", "io2", 1)| -select * from t1| -delete from t1| -drop procedure iotest| -drop procedure inc2| - -# Propagating top-level @-vars ---disable_warnings -drop procedure if exists incr| ---enable_warnings -create procedure incr(inout x int) - call inc(x)| - -# Before -select @zap| -call incr(@zap)| -# After -select @zap| - -drop procedure inc| -drop procedure incr| - -# Call-by-value test -# The expected result is: -# ("cbv2", 4) -# ("cbv1", 4711) ---disable_warnings -drop procedure if exists cbv1| ---enable_warnings -create procedure cbv1() -begin - declare y int default 3; - - call cbv2(y+1, y); - insert into test.t1 values ("cbv1", y); -end| - ---disable_warnings -drop procedure if exists cbv2| ---enable_warnings -create procedure cbv2(y1 int, inout y2 int) -begin - set y2 = 4711; - insert into test.t1 values ("cbv2", y1); -end| - -call cbv1()| -select * from t1| -delete from t1| -drop procedure cbv1| -drop procedure cbv2| - - -# Subselect arguments - -insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)| - ---disable_warnings -drop procedure if exists sub1| ---enable_warnings -create procedure sub1(id char(16), x int) - insert into test.t1 values (id, x)| - ---disable_warnings -drop procedure if exists sub2| ---enable_warnings -create procedure sub2(id char(16)) -begin - declare x int; - set x = (select sum(t.i) from test.t2 t); - insert into test.t1 values (id, x); -end| - ---disable_warnings -drop procedure if exists sub3| ---enable_warnings -create function sub3(i int) returns int - return i+1| - -call sub1("sub1a", (select 7))| -call sub1("sub1b", (select max(i) from t2))| ---error ER_OPERAND_COLUMNS -call sub1("sub1c", (select i,d from t2 limit 1))| -call sub1("sub1d", (select 1 from (select 1) a))| -call sub2("sub2")| -select * from t1| -select sub3((select max(i) from t2))| -drop procedure sub1| -drop procedure sub2| -drop function sub3| -delete from t1| -delete from t2| - -# Basic tests of the flow control constructs - -# Just test on 'x'... ---disable_warnings -drop procedure if exists a0| ---enable_warnings -create procedure a0(x int) -while x do - set x = x-1; - insert into test.t1 values ("a0", x); -end while| - -call a0(3)| -select * from t1| -delete from t1| -drop procedure a0| - - -# The same, but with a more traditional test. ---disable_warnings -drop procedure if exists a| ---enable_warnings -create procedure a(x int) -while x > 0 do - set x = x-1; - insert into test.t1 values ("a", x); -end while| - -call a(3)| -select * from t1| -delete from t1| -drop procedure a| - - -# REPEAT ---disable_warnings -drop procedure if exists b| ---enable_warnings -create procedure b(x int) -repeat - insert into test.t1 values (repeat("b",3), x); - set x = x-1; -until x = 0 end repeat| - -call b(3)| -select * from t1| -delete from t1| -drop procedure b| - - -# Check that repeat isn't parsed the wrong way ---disable_warnings -drop procedure if exists b2| ---enable_warnings -create procedure b2(x int) -repeat(select 1 into outfile 'b2'); - insert into test.t1 values (repeat("b2",3), x); - set x = x-1; -until x = 0 end repeat| - -# We don't actually want to call it. -drop procedure b2| - - -# Labelled WHILE with ITERATE (pointless really) ---disable_warnings -drop procedure if exists c| ---enable_warnings -create procedure c(x int) -hmm: while x > 0 do - insert into test.t1 values ("c", x); - set x = x-1; - iterate hmm; - insert into test.t1 values ("x", x); -end while hmm| - -call c(3)| -select * from t1| -delete from t1| -drop procedure c| - - -# Labelled WHILE with LEAVE ---disable_warnings -drop procedure if exists d| ---enable_warnings -create procedure d(x int) -hmm: while x > 0 do - insert into test.t1 values ("d", x); - set x = x-1; - leave hmm; - insert into test.t1 values ("x", x); -end while| - -call d(3)| -select * from t1| -delete from t1| -drop procedure d| - - -# LOOP, with simple IF statement ---disable_warnings -drop procedure if exists e| ---enable_warnings -create procedure e(x int) -foo: loop - if x = 0 then - leave foo; - end if; - insert into test.t1 values ("e", x); - set x = x-1; -end loop foo| - -call e(3)| -select * from t1| -delete from t1| -drop procedure e| - - -# A full IF statement ---disable_warnings -drop procedure if exists f| ---enable_warnings -create procedure f(x int) -if x < 0 then - insert into test.t1 values ("f", 0); -elseif x = 0 then - insert into test.t1 values ("f", 1); -else - insert into test.t1 values ("f", 2); -end if| - -call f(-2)| -call f(0)| -call f(4)| -select * from t1| -delete from t1| -drop procedure f| - - -# This form of CASE is really just syntactic sugar for IF-ELSEIF-... ---disable_warnings -drop procedure if exists g| ---enable_warnings -create procedure g(x int) -case -when x < 0 then - insert into test.t1 values ("g", 0); -when x = 0 then - insert into test.t1 values ("g", 1); -else - insert into test.t1 values ("g", 2); -end case| - -call g(-42)| -call g(0)| -call g(1)| -select * from t1| -delete from t1| -drop procedure g| - - -# The "simple CASE" ---disable_warnings -drop procedure if exists h| ---enable_warnings -create procedure h(x int) -case x -when 0 then - insert into test.t1 values ("h0", x); -when 1 then - insert into test.t1 values ("h1", x); -else - insert into test.t1 values ("h?", x); -end case| - -call h(0)| -call h(1)| -call h(17)| -select * from t1| -delete from t1| -drop procedure h| - - -# It's actually possible to LEAVE a BEGIN-END block ---disable_warnings -drop procedure if exists i| ---enable_warnings -create procedure i(x int) -foo: -begin - if x = 0 then - leave foo; - end if; - insert into test.t1 values ("i", x); -end foo| - -call i(0)| -call i(3)| -select * from t1| -delete from t1| -drop procedure i| - - -# SELECT with one of more result set sent back to the clinet -insert into t1 values ("foo", 3), ("bar", 19)| -insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)| - ---disable_warnings -drop procedure if exists sel1| ---enable_warnings -create procedure sel1() -begin - select * from t1; -end| - -call sel1()| -drop procedure sel1| - ---disable_warnings -drop procedure if exists sel2| ---enable_warnings -create procedure sel2() -begin - select * from t1; - select * from t2; -end| - -call sel2()| -drop procedure sel2| -delete from t1| -delete from t2| - -# SELECT INTO local variables ---disable_warnings -drop procedure if exists into_test| ---enable_warnings -create procedure into_test(x char(16), y int) -begin - insert into test.t1 values (x, y); - select id,data into x,y from test.t1 limit 1; - insert into test.t1 values (concat(x, "2"), y+2); -end| - -call into_test("into", 100)| -select * from t1| -delete from t1| -drop procedure into_test| - - -# SELECT INTO with a mix of local and global variables ---disable_warnings -drop procedure if exists into_tes2| ---enable_warnings -create procedure into_test2(x char(16), y int) -begin - insert into test.t1 values (x, y); - select id,data into x,@z from test.t1 limit 1; - insert into test.t1 values (concat(x, "2"), y+2); -end| - -call into_test2("into", 100)| -select id,data,@z from t1| -delete from t1| -drop procedure into_test2| - - -# SELECT * INTO ... (bug test) ---disable_warnings -drop procedure if exists into_test3| ---enable_warnings -create procedure into_test3() -begin - declare x char(16); - declare y int; - - select * into x,y from test.t1 limit 1; - insert into test.t2 values (x, y, 0.0); -end| - -insert into t1 values ("into3", 19)| -# Two call needed for bug test -call into_test3()| -call into_test3()| -select * from t2| -delete from t1| -delete from t2| -drop procedure into_test3| - - -# SELECT INTO with no data is a warning ("no data", which we will -# not see normally). When not caught, execution proceeds. ---disable_warnings -drop procedure if exists into_test4| ---enable_warnings -create procedure into_test4() -begin - declare x int; - - select data into x from test.t1 limit 1; - insert into test.t3 values ("into4", x); -end| - -delete from t1| -create table t3 ( s char(16), d int)| -call into_test4()| -select * from t3| -insert into t1 values ("i4", 77)| -call into_test4()| -select * from t3| -delete from t1| -drop table t3| -drop procedure into_test4| - - -# These two (and the two procedures above) caused an assert() to fail in -# sql_base.cc:lock_tables() at some point. ---disable_warnings -drop procedure if exists into_outfile| ---enable_warnings -create procedure into_outfile(x char(16), y int) -begin - insert into test.t1 values (x, y); - select * into outfile "../tmp/spout" from test.t1; - insert into test.t1 values (concat(x, "2"), y+2); -end| - ---system rm -f $MYSQLTEST_VARDIR/tmp/spout -call into_outfile("ofile", 1)| ---system rm -f $MYSQLTEST_VARDIR/tmp/spout -delete from t1| -drop procedure into_outfile| - ---disable_warnings -drop procedure if exists into_dumpfile| ---enable_warnings -create procedure into_dumpfile(x char(16), y int) -begin - insert into test.t1 values (x, y); - select * into dumpfile "../tmp/spdump" from test.t1 limit 1; - insert into test.t1 values (concat(x, "2"), y+2); -end| - ---system rm -f $MYSQLTEST_VARDIR/tmp/spdump -call into_dumpfile("dfile", 1)| ---system rm -f $MYSQLTEST_VARDIR/tmp/spdump -delete from t1| -drop procedure into_dumpfile| - ---disable_warnings -drop procedure if exists create_select| ---enable_warnings -create procedure create_select(x char(16), y int) -begin - insert into test.t1 values (x, y); - create temporary table test.t3 select * from test.t1; - insert into test.t3 values (concat(x, "2"), y+2); -end| - -call create_select("cs", 90)| -select * from t1, t3| -drop table t3| -delete from t1| -drop procedure create_select| - - -# A minimal, constant FUNCTION. ---disable_warnings -drop function if exists e| ---enable_warnings -create function e() returns double - return 2.7182818284590452354| - -set @e = e()| -select e(), @e| - -# A minimal function with one argument ---disable_warnings -drop function if exists inc| ---enable_warnings -create function inc(i int) returns int - return i+1| - -select inc(1), inc(99), inc(-71)| - -# A minimal function with two arguments ---disable_warnings -drop function if exists mul| ---enable_warnings -create function mul(x int, y int) returns int - return x*y| - -select mul(1,1), mul(3,5), mul(4711, 666)| - -# A minimal string function ---disable_warnings -drop function if exists append| ---enable_warnings -create function append(s1 char(8), s2 char(8)) returns char(16) - return concat(s1, s2)| - -select append("foo", "bar")| - -# A function with flow control ---disable_warnings -drop function if exists fac| ---enable_warnings -create function fac(n int unsigned) returns bigint unsigned -begin - declare f bigint unsigned default 1; - - while n > 1 do - set f = f * n; - set n = n - 1; - end while; - return f; -end| - -select fac(1), fac(2), fac(5), fac(10)| - -# Nested calls ---disable_warnings -drop function if exists fun| ---enable_warnings -create function fun(d double, i int, u int unsigned) returns double - return mul(inc(i), fac(u)) / e()| - -select fun(2.3, 3, 5)| - - -# Various function calls in differen statements - -insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| -insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| - -# Disable PS because double's give a bit different values ---disable_ps_protocol -select * from t2 where s = append("a", "b")| -select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2)| -select * from t2 where d = e()| -select * from t2| ---enable_ps_protocol -delete from t2| - -drop function e| -drop function inc| -drop function mul| -drop function append| -drop function fun| - - -# -# CONDITIONs and HANDLERs -# - ---disable_warnings -drop procedure if exists hndlr1| ---enable_warnings -create procedure hndlr1(val int) -begin - declare x int default 0; - declare foo condition for 1136; - declare bar condition for sqlstate '42S98'; # Just for testing syntax - declare zip condition for sqlstate value '42S99'; # Just for testing syntax - declare continue handler for foo set x = 1; - - insert into test.t1 values ("hndlr1", val, 2); # Too many values - if (x) then - insert into test.t1 values ("hndlr1", val); # This instead then - end if; -end| - -call hndlr1(42)| -select * from t1| -delete from t1| -drop procedure hndlr1| - ---disable_warnings -drop procedure if exists hndlr2| ---enable_warnings -create procedure hndlr2(val int) -begin - declare x int default 0; - - begin - declare exit handler for sqlstate '21S01' set x = 1; - - insert into test.t1 values ("hndlr2", val, 2); # Too many values - end; - - insert into test.t1 values ("hndlr2", x); -end| - -call hndlr2(42)| -select * from t1| -delete from t1| -drop procedure hndlr2| - - ---disable_warnings -drop procedure if exists hndlr3| ---enable_warnings -create procedure hndlr3(val int) -begin - declare x int default 0; - declare continue handler for sqlexception # Any error - begin - declare z int; - - set z = 2 * val; - set x = 1; - end; - - if val < 10 then - begin - declare y int; - - set y = val + 10; - insert into test.t1 values ("hndlr3", y, 2); # Too many values - if x then - insert into test.t1 values ("hndlr3", y); - end if; - end; - end if; -end| - -call hndlr3(3)| -select * from t1| -delete from t1| -drop procedure hndlr3| - - -# Variables might be uninitialized when using handlers -# (Otherwise the compiler can detect if a variable is not set, but -# not in this case.) -create table t3 ( id char(16), data int )| - ---disable_warnings -drop procedure if exists hndlr4| ---enable_warnings -create procedure hndlr4() -begin - declare x int default 0; - declare val int; # No default - declare continue handler for sqlstate '02000' set x=1; - - select data into val from test.t3 where id='z' limit 1; # No hits - - insert into test.t3 values ('z', val); -end| - -call hndlr4()| -select * from t3| -drop table t3| -drop procedure hndlr4| - - -# -# Cursors -# ---disable_warnings -drop procedure if exists cur1| ---enable_warnings -create procedure cur1() -begin - declare a char(16); - declare b int; - declare c double; - declare done int default 0; - declare c cursor for select * from test.t2; - declare continue handler for sqlstate '02000' set done = 1; - - open c; - repeat - fetch c into a, b, c; - if not done then - insert into test.t1 values (a, b+c); - end if; - until done end repeat; - close c; -end| - -insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| -call cur1()| -select * from t1| -drop procedure cur1| - -create table t3 ( s char(16), i int )| - ---disable_warnings -drop procedure if exists cur2| ---enable_warnings -create procedure cur2() -begin - declare done int default 0; - declare c1 cursor for select id,data from test.t1; - declare c2 cursor for select i from test.t2; - declare continue handler for sqlstate '02000' set done = 1; - - open c1; - open c2; - repeat - begin - declare a char(16); - declare b,c int; - - fetch from c1 into a, b; - fetch next from c2 into c; - if not done then - if b < c then - insert into test.t3 values (a, b); - else - insert into test.t3 values (a, c); - end if; - end if; - end; - until done end repeat; - close c1; - close c2; -end| - -call cur2()| -select * from t3| -delete from t1| -delete from t2| -drop table t3| -drop procedure cur2| - - -# The few characteristics we parse ---disable_warnings -drop procedure if exists chistics| ---enable_warnings -create procedure chistics() - language sql - modifies sql data - not deterministic - sql security definer - comment 'Characteristics procedure test' - insert into t1 values ("chistics", 1)| - -show create procedure chistics| -# Call it, just to make sure. -call chistics()| -select * from t1| -delete from t1| -alter procedure chistics sql security invoker| -show create procedure chistics| -drop procedure chistics| - ---disable_warnings -drop function if exists chistics| ---enable_warnings -create function chistics() returns int - language sql - deterministic - sql security invoker - comment 'Characteristics procedure test' - return 42| - -show create function chistics| -# Call it, just to make sure. -select chistics()| -alter function chistics - no sql - comment 'Characteristics function test'| -show create function chistics| -drop function chistics| - - -# Check mode settings -insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| - -set @@sql_mode = 'ANSI'| -delimiter $| ---disable_warnings -drop procedure if exists modes$ ---enable_warnings -create procedure modes(out c1 int, out c2 int) -begin - declare done int default 0; - declare x int; - declare c cursor for select data from t1; - declare continue handler for sqlstate '02000' set done = 1; - - select 1 || 2 into c1; - set c2 = 0; - open c; - repeat - fetch c into x; - if not done then - set c2 = c2 + 1; - end if; - until done end repeat; - close c; -end$ -delimiter |$ -set @@sql_mode = ''| - -set sql_select_limit = 1| -call modes(@c1, @c2)| -set sql_select_limit = default| - -select @c1, @c2| -delete from t1| -drop procedure modes| - - -# Check that dropping a database without routines works. -# (Dropping with routines is tested in sp-security.test) -# First an empty db. -create database sp_db1| -drop database sp_db1| - -# Again, with a table. -create database sp_db2| -use sp_db2| -# Just put something in here... -create table t3 ( s char(4), t int )| -insert into t3 values ("abcd", 42), ("dcba", 666)| -use test| -drop database sp_db2| - -# And yet again, with just a procedure. -create database sp_db3| -use sp_db3| ---disable_warnings -drop procedure if exists dummy| ---enable_warnings -create procedure dummy(out x int) - set x = 42| -use test| -drop database sp_db3| -# Check that it's gone -select type,db,name from mysql.proc where db = 'sp_db3'| - - -# ROW_COUNT() function after a CALL -# We test the other cases here too, although it's not strictly SP specific ---disable_warnings -drop procedure if exists rc| ---enable_warnings -create procedure rc() -begin - delete from t1; - insert into t1 values ("a", 1), ("b", 2), ("c", 3); -end| - -call rc()| -select row_count()| ---disable_ps_protocol -update t1 set data=42 where id = "b"; -select row_count()| ---enable_ps_protocol -delete from t1| -select row_count()| -delete from t1| -select row_count()| -select * from t1| -select row_count()| -drop procedure rc| - - -# -# Let us test how well new locking scheme works. -# - -# Let us prepare playground ---disable_warnings -drop function if exists f0| -drop function if exists f1| -drop function if exists f2| -drop function if exists f3| -drop function if exists f4| -drop function if exists f5| -drop function if exists f6| -drop function if exists f7| -drop function if exists f8| -drop function if exists f9| -drop function if exists f10| -drop function if exists f11| -drop function if exists f12_1| -drop function if exists f12_2| -drop view if exists v0| -drop view if exists v1| -drop view if exists v2| ---enable_warnings -delete from t1| -delete from t2| -insert into t1 values ("a", 1), ("b", 2) | -insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) | - -# Test the simplest function using tables -create function f1() returns int - return (select sum(data) from t1)| -select f1()| -# This should work too (and give 2 rows as result) -select id, f1() from t1| - -# Function which uses two instances of table simultaneously -create function f2() returns int - return (select data from t1 where data <= (select sum(data) from t1) limit 1)| -select f2()| -select id, f2() from t1| - -# Function which uses the same table twice in different queries -create function f3() returns int -begin - declare n int; - declare m int; - set n:= (select min(data) from t1); - set m:= (select max(data) from t1); - return n < m; -end| -select f3()| -select id, f3() from t1| - -# Calling two functions using same table -select f1(), f3()| -select id, f1(), f3() from t1| - -# Function which uses two different tables -create function f4() returns double - return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")| -select f4()| -select s, f4() from t2| - -# Recursive functions which due to this recursion require simultaneous -# access to several instance of the same table won't work -create function f5(i int) returns int -begin - if i <= 0 then - return 0; - elseif i = 1 then - return (select count(*) from t1 where data = i); - else - return (select count(*) + f5( i - 1) from t1 where data = i); - end if; -end| -select f5(1)| -# Since currently recursive functions are disallowed ER_SP_NO_RECURSION -# error will be returned, once we will allow them error about -# insufficient number of locked tables will be returned instead. ---error ER_SP_NO_RECURSION -select f5(2)| ---error ER_SP_NO_RECURSION -select f5(3)| - -# OTOH this should work -create function f6() returns int -begin - declare n int; - set n:= f1(); - return (select count(*) from t1 where data <= f7() and data <= n); -end| -create function f7() returns int - return (select sum(data) from t1 where data <= f1())| -select f6()| -select id, f6() from t1| - -# -# Let us test how new locking work with views -# -# The most trivial view -create view v1 (a) as select f1()| -select * from v1| -select id, a from t1, v1| -select * from v1, v1 as v| -# A bit more complex construction -create view v2 (a) as select a*10 from v1| -select * from v2| -select id, a from t1, v2| -select * from v1, v2| - -# Nice example where the same view is used on -# on different expression levels -create function f8 () returns int - return (select count(*) from v2)| - -select *, f8() from v1| - -# Let us test what will happen if function is missing -drop function f1| ---error 1356 -select * from v1| - -# And what will happen if we have recursion which involves -# views and functions ? -create function f1() returns int - return (select sum(data) from t1) + (select sum(data) from v1)| ---error ER_SP_NO_RECURSION -select f1()| ---error ER_SP_NO_RECURSION -select * from v1| ---error ER_SP_NO_RECURSION -select * from v2| -# Back to the normal cases -drop function f1| -create function f1() returns int - return (select sum(data) from t1)| - -# Let us also test some weird cases where no real tables is used -create function f0() returns int - return (select * from (select 100) as r)| -select f0()| -select *, f0() from (select 1) as t| -create view v0 as select f0()| -select * from v0| -select *, f0() from v0| - -# -# Let us test how well prelocking works with explicit LOCK TABLES. -# -lock tables t1 read, t1 as t11 read| -# These should work well -select f3()| -select id, f3() from t1 as t11| -# Degenerate cases work too :) -select f0()| -select * from v0| -select *, f0() from v0, (select 123) as d1| -# But these should not ! ---error 1100 -select id, f3() from t1| ---error 1100 -select f4()| -unlock tables| - -# Let us test how LOCK TABLES which implicitly depends on functions -# works -lock tables v2 read, mysql.proc read| -select * from v2| -select * from v1| -# These should not work as we have too little instances of tables locked ---error 1100 -select * from v1, t1| ---error 1100 -select f4()| -unlock tables| - -# Tests for handling of temporary tables in functions. -# -# Unlike for permanent tables we should be able to create, use -# and drop such tables in functions. -# -# Simplest function using temporary table. It is also test case for bug -# #12198 "Temporary table aliasing does not work inside stored functions" -create function f9() returns int -begin - declare a, b int; - drop temporary table if exists t3; - create temporary table t3 (id int); - insert into t3 values (1), (2), (3); - set a:= (select count(*) from t3); - set b:= (select count(*) from t3 t3_alias); - return a + b; -end| -# This will emit warning as t3 was not existing before. -select f9()| -select f9() from t1 limit 1| - -# Function which uses both temporary and permanent tables. -create function f10() returns int -begin - drop temporary table if exists t3; - create temporary table t3 (id int); - insert into t3 select id from t4; - return (select count(*) from t3); -end| -# Check that we don't ignore completely tables used in function ---error ER_NO_SUCH_TABLE -select f10()| -create table t4 as select 1 as id| -select f10()| - -# Practical cases which we don't handle well (yet) -# -# Function which does not work because of well-known and documented -# limitation of MySQL. We can't use the several instances of the -# same temporary table in statement. -create function f11() returns int -begin - drop temporary table if exists t3; - create temporary table t3 (id int); - insert into t3 values (1), (2), (3); - return (select count(*) from t3 as a, t3 as b); -end| ---error ER_CANT_REOPEN_TABLE -select f11()| ---error ER_CANT_REOPEN_TABLE -select f11() from t1| -# We don't handle temporary tables used by nested functions well -create function f12_1() returns int -begin - drop temporary table if exists t3; - create temporary table t3 (id int); - insert into t3 values (1), (2), (3); - return f12_2(); -end| -create function f12_2() returns int - return (select count(*) from t3)| -# We need clean start to get error -drop temporary table t3| ---error ER_NO_SUCH_TABLE -select f12_1()| ---error ER_NO_SUCH_TABLE -select f12_1() from t1 limit 1| - -# Cleanup -drop function f0| -drop function f1| -drop function f2| -drop function f3| -drop function f4| -drop function f5| -drop function f6| -drop function f7| -drop function f8| -drop function f9| -drop function f10| -drop function f11| -drop function f12_1| -drop function f12_2| -drop view v0| -drop view v1| -drop view v2| -delete from t1 | -delete from t2 | -drop table t4| - -# End of non-bug tests - - -# -# Some "real" examples -# - -# fac - ---disable_warnings -drop table if exists t3| ---enable_warnings -create table t3 (n int unsigned not null primary key, f bigint unsigned)| - ---disable_warnings -drop procedure if exists ifac| ---enable_warnings -create procedure ifac(n int unsigned) -begin - declare i int unsigned default 1; - - if n > 20 then - set n = 20; # bigint overflow otherwise - end if; - while i <= n do - begin - insert into test.t3 values (i, fac(i)); - set i = i + 1; - end; - end while; -end| - -call ifac(20)| -select * from t3| -drop table t3| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -show function status like '%f%'| -drop procedure ifac| -drop function fac| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -show function status like '%f%'| - - -# primes - ---disable_warnings -drop table if exists t3| ---enable_warnings - -create table t3 ( - i int unsigned not null primary key, - p bigint unsigned not null -)| - -insert into t3 values - ( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13), - ( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31), - (10, 37), (11, 41), (12, 43), (13, 47), (14, 53), - (15, 59), (16, 61), (17, 67), (18, 71), (19, 73), - (20, 79), (21, 83), (22, 89), (23, 97), (24, 101), - (25, 103), (26, 107), (27, 109), (28, 113), (29, 127), - (30, 131), (31, 137), (32, 139), (33, 149), (34, 151), - (35, 157), (36, 163), (37, 167), (38, 173), (39, 179), - (40, 181), (41, 191), (42, 193), (43, 197), (44, 199)| - ---disable_warnings -drop procedure if exists opp| ---enable_warnings -create procedure opp(n bigint unsigned, out pp bool) -begin - declare r double; - declare b, s bigint unsigned default 0; - - set r = sqrt(n); - - again: - loop - if s = 45 then - set b = b+200, s = 0; - else - begin - declare p bigint unsigned; - - select t.p into p from test.t3 t where t.i = s; - if b+p > r then - set pp = 1; - leave again; - end if; - if mod(n, b+p) = 0 then - set pp = 0; - leave again; - end if; - set s = s+1; - end; - end if; - end loop; -end| - ---disable_warnings -drop procedure if exists ip| ---enable_warnings -create procedure ip(m int unsigned) -begin - declare p bigint unsigned; - declare i int unsigned; - - set i=45, p=201; - - while i < m do - begin - declare pp bool default 0; - - call opp(p, pp); - if pp then - insert into test.t3 values (i, p); - set i = i+1; - end if; - set p = p+2; - end; - end while; -end| -show create procedure opp| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -show procedure status like '%p%'| - -# This isn't the fastest way in the world to compute prime numbers, so -# don't be too ambitious. ;-) -call ip(200)| -# We don't want to select the entire table here, just pick a few -# examples. -# The expected result is: -# i p -# --- ---- -# 45 211 -# 100 557 -# 199 1229 -select * from t3 where i=45 or i=100 or i=199| -drop table t3| -drop procedure opp| -drop procedure ip| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -show procedure status like '%p%'| - - -# Fibonacci, for recursion test. (Yet Another Numerical series :) -# ---disable_warnings -drop table if exists t3| ---enable_warnings -create table t3 ( f bigint unsigned not null )| - -# We deliberately do it the awkward way, fetching the last two -# values from the table, in order to exercise various statements -# and table accesses at each turn. ---disable_warnings -drop procedure if exists fib| ---enable_warnings -create procedure fib(n int unsigned) -begin - if n > 1 then - begin - declare x, y bigint unsigned; - declare c cursor for select f from t3 order by f desc limit 2; - - open c; - fetch c into y; - fetch c into x; - close c; - insert into t3 values (x+y); - call fib(n-1); - end; - end if; -end| - -# Enable recursion -set @@max_sp_recursion_depth= 20| - -# Minimum test: recursion of 3 levels - -insert into t3 values (0), (1)| - -call fib(3)| - -select * from t3 order by f asc| - -delete from t3| - -# The original test, 20 levels, ran into memory limits on some machines -# and builds. Try 10 instead... - -insert into t3 values (0), (1)| - -call fib(10)| - -select * from t3 order by f asc| -drop table t3| -drop procedure fib| -set @@max_sp_recursion_depth= 0| - -# -# Comment & suid -# - ---disable_warnings -drop procedure if exists bar| ---enable_warnings -create procedure bar(x char(16), y int) - comment "111111111111" sql security invoker - insert into test.t1 values (x, y)| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -show procedure status like 'bar'| -alter procedure bar comment "2222222222" sql security definer| -alter procedure bar comment "3333333333"| -alter procedure bar| -show create procedure bar| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -show procedure status like 'bar'| -drop procedure bar| - -# -# rexecution -# ---disable_warnings -drop procedure if exists p1| ---enable_warnings -create procedure p1 () - select (select s1 from t3) from t3| - -create table t3 (s1 int)| - -call p1()| -insert into t3 values (1)| -call p1()| -drop procedure p1| -drop table t3| - -# -# backticks -# ---disable_warnings -drop function if exists foo| ---enable_warnings -create function `foo` () returns int - return 5| -select `foo` ()| -drop function `foo`| - -# -# Implicit LOCK/UNLOCK TABLES for table access in functions -# - ---disable_warnings -drop function if exists t1max| ---enable_warnings -create function t1max() returns int -begin - declare x int; - select max(data) into x from t1; - return x; -end| - -insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)| -select t1max()| -drop function t1max| - -create table t3 ( - v char(16) not null primary key, - c int unsigned not null -)| - -create function getcount(s char(16)) returns int -begin - declare x int; - - select count(*) into x from t3 where v = s; - if x = 0 then - insert into t3 values (s, 1); - else - update t3 set c = c+1 where v = s; - end if; - return x; -end| - -select * from t1 where data = getcount("bar")| -select * from t3| -select getcount("zip")| -select getcount("zip")| -select * from t3| -select getcount(id) from t1 where data = 3| -select getcount(id) from t1 where data = 5| -select * from t3| -drop table t3| -drop function getcount| - - -# Test cases for different combinations of condition handlers in nested -# begin-end blocks in stored procedures. -# -# Note that the standard specifies that the most specific handler should -# be triggered even if it's an outer handler masked by a less specific -# handler in an inner block. -# Note also that '02000' is more specific than NOT FOUND; there might be -# other '02xxx' states, even if we currently do not issue them in any -# situation (e.g. '02001'). -# -# The combinations we test are these: -# -# Inner -# errcode sqlstate not found sqlwarning sqlexception -# Outer +------------+------------+------------+------------+------------+ -#errcode | h_ee (i) | h_es (o) | h_en (o) | h_ew (o) | h_ex (o) | -#sqlstate | h_se (i) | h_ss (i) | h_sn (o) | h_sw (o) | h_sx (o) | -#not found | h_ne (i) | h_ns (i) | h_nn (i) | | | -#sqlwarning | h_we (i) | h_ws (i) | | h_ww (i) | | -#sqlexception | h_xe (i) | h_xs (i) | | | h_xx (i) | -# +------------+---------------------------------------------------+ -# -# (i) means that the inner handler is the one that should be invoked, -# (o) means that the outer handler should be invoked. -# -# ('not found', 'sqlwarning' and 'sqlexception' are mutually exclusive, hence -# no tests for those combinations.) -# - ---disable_warnings -drop table if exists t3| -drop procedure if exists h_ee| -drop procedure if exists h_es| -drop procedure if exists h_en| -drop procedure if exists h_ew| -drop procedure if exists h_ex| -drop procedure if exists h_se| -drop procedure if exists h_ss| -drop procedure if exists h_sn| -drop procedure if exists h_sw| -drop procedure if exists h_sx| -drop procedure if exists h_ne| -drop procedure if exists h_ns| -drop procedure if exists h_nn| -drop procedure if exists h_we| -drop procedure if exists h_ws| -drop procedure if exists h_ww| -drop procedure if exists h_xe| -drop procedure if exists h_xs| -drop procedure if exists h_xx| ---enable_warnings - -# smallint - to get out of range warnings -# primary key - to get constraint errors -create table t3 (a smallint primary key)| - -insert into t3 (a) values (1)| - -create procedure h_ee() - deterministic -begin - declare continue handler for 1062 -- ER_DUP_ENTRY - select 'Outer (bad)' as 'h_ee'; - - begin - declare continue handler for 1062 -- ER_DUP_ENTRY - select 'Inner (good)' as 'h_ee'; - - insert into t3 values (1); - end; -end| - -create procedure h_es() - deterministic -begin - declare continue handler for 1062 -- ER_DUP_ENTRY - select 'Outer (good)' as 'h_es'; - - begin - -- integrity constraint violation - declare continue handler for sqlstate '23000' - select 'Inner (bad)' as 'h_es'; - - insert into t3 values (1); - end; -end| - -create procedure h_en() - deterministic -begin - declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA - select 'Outer (good)' as 'h_en'; - - begin - declare x int; - declare continue handler for sqlstate '02000' -- no data - select 'Inner (bad)' as 'h_en'; - - select a into x from t3 where a = 42; - end; -end| - -create procedure h_ew() - deterministic -begin - declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE - select 'Outer (good)' as 'h_ew'; - - begin - declare continue handler for sqlwarning - select 'Inner (bad)' as 'h_ew'; - - insert into t3 values (123456789012); - end; - delete from t3; - insert into t3 values (1); -end| - -create procedure h_ex() - deterministic -begin - declare continue handler for 1062 -- ER_DUP_ENTRY - select 'Outer (good)' as 'h_ex'; - - begin - declare continue handler for sqlexception - select 'Inner (bad)' as 'h_ex'; - - insert into t3 values (1); - end; -end| - -create procedure h_se() - deterministic -begin - -- integrity constraint violation - declare continue handler for sqlstate '23000' - select 'Outer (bad)' as 'h_se'; - - begin - declare continue handler for 1062 -- ER_DUP_ENTRY - select 'Inner (good)' as 'h_se'; - - insert into t3 values (1); - end; -end| - -create procedure h_ss() - deterministic -begin - -- integrity constraint violation - declare continue handler for sqlstate '23000' - select 'Outer (bad)' as 'h_ss'; - - begin - -- integrity constraint violation - declare continue handler for sqlstate '23000' - select 'Inner (good)' as 'h_ss'; - - insert into t3 values (1); - end; -end| - -create procedure h_sn() - deterministic -begin - -- Note: '02000' is more specific than NOT FOUND ; - -- there might be other not found states - declare continue handler for sqlstate '02000' -- no data - select 'Outer (good)' as 'h_sn'; - - begin - declare x int; - declare continue handler for not found - select 'Inner (bad)' as 'h_sn'; - - select a into x from t3 where a = 42; - end; -end| - -create procedure h_sw() - deterministic -begin - -- data exception - numeric value out of range - declare continue handler for sqlstate '22003' - select 'Outer (good)' as 'h_sw'; - - begin - declare continue handler for sqlwarning - select 'Inner (bad)' as 'h_sw'; - - insert into t3 values (123456789012); - end; - delete from t3; - insert into t3 values (1); -end| - -create procedure h_sx() - deterministic -begin - -- integrity constraint violation - declare continue handler for sqlstate '23000' - select 'Outer (good)' as 'h_sx'; - - begin - declare continue handler for sqlexception - select 'Inner (bad)' as 'h_sx'; - - insert into t3 values (1); - end; -end| - -create procedure h_ne() - deterministic -begin - declare continue handler for not found - select 'Outer (bad)' as 'h_ne'; - - begin - declare x int; - declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA - select 'Inner (good)' as 'h_ne'; - - select a into x from t3 where a = 42; - end; -end| - -create procedure h_ns() - deterministic -begin - declare continue handler for not found - select 'Outer (bad)' as 'h_ns'; - - begin - declare x int; - declare continue handler for sqlstate '02000' -- no data - select 'Inner (good)' as 'h_ns'; - - select a into x from t3 where a = 42; - end; -end| - -create procedure h_nn() - deterministic -begin - declare continue handler for not found - select 'Outer (bad)' as 'h_nn'; - - begin - declare x int; - declare continue handler for not found - select 'Inner (good)' as 'h_nn'; - - select a into x from t3 where a = 42; - end; -end| - -create procedure h_we() - deterministic -begin - declare continue handler for sqlwarning - select 'Outer (bad)' as 'h_we'; - - begin - declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE - select 'Inner (good)' as 'h_we'; - - insert into t3 values (123456789012); - end; - delete from t3; - insert into t3 values (1); -end| - -create procedure h_ws() - deterministic -begin - declare continue handler for sqlwarning - select 'Outer (bad)' as 'h_ws'; - - begin - -- data exception - numeric value out of range - declare continue handler for sqlstate '22003' - select 'Inner (good)' as 'h_ws'; - - insert into t3 values (123456789012); - end; - delete from t3; - insert into t3 values (1); -end| - -create procedure h_ww() - deterministic -begin - declare continue handler for sqlwarning - select 'Outer (bad)' as 'h_ww'; - - begin - declare continue handler for sqlwarning - select 'Inner (good)' as 'h_ww'; - - insert into t3 values (123456789012); - end; - delete from t3; - insert into t3 values (1); -end| - -create procedure h_xe() - deterministic -begin - declare continue handler for sqlexception - select 'Outer (bad)' as 'h_xe'; - - begin - declare continue handler for 1062 -- ER_DUP_ENTRY - select 'Inner (good)' as 'h_xe'; - - insert into t3 values (1); - end; -end| - -create procedure h_xs() - deterministic -begin - declare continue handler for sqlexception - select 'Outer (bad)' as 'h_xs'; - - begin - -- integrity constraint violation - declare continue handler for sqlstate '23000' - select 'Inner (good)' as 'h_xs'; - - insert into t3 values (1); - end; -end| - -create procedure h_xx() - deterministic -begin - declare continue handler for sqlexception - select 'Outer (bad)' as 'h_xx'; - - begin - declare continue handler for sqlexception - select 'Inner (good)' as 'h_xx'; - - insert into t3 values (1); - end; -end| - -call h_ee()| -call h_es()| -call h_en()| -call h_ew()| -call h_ex()| -call h_se()| -call h_ss()| -call h_sn()| -call h_sw()| -call h_sx()| -call h_ne()| -call h_ns()| -call h_nn()| -call h_we()| -call h_ws()| -call h_ww()| -call h_xe()| -call h_xs()| -call h_xx()| - -drop table t3| -drop procedure h_ee| -drop procedure h_es| -drop procedure h_en| -drop procedure h_ew| -drop procedure h_ex| -drop procedure h_se| -drop procedure h_ss| -drop procedure h_sn| -drop procedure h_sw| -drop procedure h_sx| -drop procedure h_ne| -drop procedure h_ns| -drop procedure h_nn| -drop procedure h_we| -drop procedure h_ws| -drop procedure h_ww| -drop procedure h_xe| -drop procedure h_xs| -drop procedure h_xx| - - -# -# Test cases for old bugs -# - -# -# BUG#822 -# ---disable_warnings -drop procedure if exists bug822| ---enable_warnings -create procedure bug822(a_id char(16), a_data int) -begin - declare n int; - select count(*) into n from t1 where id = a_id and data = a_data; - if n = 0 then - insert into t1 (id, data) values (a_id, a_data); - end if; -end| - -delete from t1| -call bug822('foo', 42)| -call bug822('foo', 42)| -call bug822('bar', 666)| -select * from t1| -delete from t1| -drop procedure bug822| - -# -# BUG#1495 -# ---disable_warnings -drop procedure if exists bug1495| ---enable_warnings -create procedure bug1495() -begin - declare x int; - - select data into x from t1 order by id limit 1; - if x > 10 then - insert into t1 values ("less", x-10); - else - insert into t1 values ("more", x+10); - end if; -end| - -insert into t1 values ('foo', 12)| -call bug1495()| -delete from t1 where id='foo'| -insert into t1 values ('bar', 7)| -call bug1495()| -delete from t1 where id='bar'| -select * from t1| -delete from t1| -drop procedure bug1495| - -# -# BUG#1547 -# ---disable_warnings -drop procedure if exists bug1547| ---enable_warnings -create procedure bug1547(s char(16)) -begin - declare x int; - - select data into x from t1 where s = id limit 1; - if x > 10 then - insert into t1 values ("less", x-10); - else - insert into t1 values ("more", x+10); - end if; -end| - -insert into t1 values ("foo", 12), ("bar", 7)| -call bug1547("foo")| -call bug1547("bar")| -select * from t1| -delete from t1| -drop procedure bug1547| - -# -# BUG#1656 -# ---disable_warnings -drop table if exists t70| ---enable_warnings -create table t70 (s1 int,s2 int)| -insert into t70 values (1,2)| - ---disable_warnings -drop procedure if exists bug1656| ---enable_warnings -create procedure bug1656(out p1 int, out p2 int) - select * into p1, p1 from t70| - -call bug1656(@1, @2)| -select @1, @2| -drop table t70| -drop procedure bug1656| - -# -# BUG#1862 -# -create table t3(a int)| - ---disable_warnings -drop procedure if exists bug1862| ---enable_warnings -create procedure bug1862() -begin - insert into t3 values(2); - flush tables; -end| - -call bug1862()| -# the second call caused a segmentation -call bug1862()| -select * from t3| -drop table t3| -drop procedure bug1862| - -# -# BUG#1874 -# ---disable_warnings -drop procedure if exists bug1874| ---enable_warnings -create procedure bug1874() -begin - declare x int; - declare y double; - select max(data) into x from t1; - insert into t2 values ("max", x, 0); - select min(data) into x from t1; - insert into t2 values ("min", x, 0); - select sum(data) into x from t1; - insert into t2 values ("sum", x, 0); - select avg(data) into y from t1; - insert into t2 values ("avg", 0, y); -end| - -insert into t1 (data) values (3), (1), (5), (9), (4)| -call bug1874()| -select * from t2| -delete from t1| -delete from t2| -drop procedure bug1874| - -# -# BUG#2260 -# ---disable_warnings -drop procedure if exists bug2260| ---enable_warnings -create procedure bug2260() -begin - declare v1 int; - declare c1 cursor for select data from t1; - declare continue handler for not found set @x2 = 1; - - open c1; - fetch c1 into v1; - set @x2 = 2; - close c1; -end| - -call bug2260()| -select @x2| -drop procedure bug2260| - -# -# BUG#2267 "Lost connect if stored procedure has SHOW FUNCTION STATUS" -# ---disable_warnings -drop procedure if exists bug2267_1| ---enable_warnings -create procedure bug2267_1() -begin - show procedure status; -end| - ---disable_warnings -drop procedure if exists bug2267_2| ---enable_warnings -create procedure bug2267_2() -begin - show function status; -end| - ---disable_warnings -drop procedure if exists bug2267_3| ---enable_warnings -create procedure bug2267_3() -begin - show create procedure bug2267_1; -end| - ---disable_warnings -drop procedure if exists bug2267_4| -drop function if exists bug2267_4| ---enable_warnings -create procedure bug2267_4() -begin - show create function bug2267_4; -end| -create function bug2267_4() returns int return 100| - ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -call bug2267_1()| ---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' -call bug2267_2()| -call bug2267_3()| -call bug2267_4()| - -drop procedure bug2267_1| -drop procedure bug2267_2| -drop procedure bug2267_3| -drop procedure bug2267_4| -drop function bug2267_4| - -# -# BUG#2227 -# ---disable_warnings -drop procedure if exists bug2227| ---enable_warnings -create procedure bug2227(x int) -begin - declare y float default 2.6; - declare z char(16) default "zzz"; - - select 1.3, x, y, 42, z; -end| - -call bug2227(9)| -drop procedure bug2227| - -# -# BUG#2614 "Stored procedure with INSERT ... SELECT that does not -# contain any tables crashes server" -# ---disable_warnings -drop procedure if exists bug2614| ---enable_warnings -create procedure bug2614() -begin - drop table if exists t3; - create table t3 (id int default '0' not null); - insert into t3 select 12; - insert into t3 select * from t3; -end| - ---disable_warnings -call bug2614()| ---enable_warnings -call bug2614()| -drop table t3| -drop procedure bug2614| - -# -# BUG#2674 -# ---disable_warnings -drop function if exists bug2674| ---enable_warnings -create function bug2674() returns int - return @@sort_buffer_size| - -set @osbs = @@sort_buffer_size| -set @@sort_buffer_size = 262000| -select bug2674()| -drop function bug2674| -set @@sort_buffer_size = @osbs| - -# -# BUG#3259 -# ---disable_warnings -drop procedure if exists bug3259_1 | ---enable_warnings -create procedure bug3259_1 () begin end| ---disable_warnings -drop procedure if exists BUG3259_2 | ---enable_warnings -create procedure BUG3259_2 () begin end| ---disable_warnings -drop procedure if exists Bug3259_3 | ---enable_warnings -create procedure Bug3259_3 () begin end| - -call BUG3259_1()| -call BUG3259_1()| -call bug3259_2()| -call Bug3259_2()| -call bug3259_3()| -call bUG3259_3()| - -drop procedure bUg3259_1| -drop procedure BuG3259_2| -drop procedure BUG3259_3| - -# -# BUG#2772 -# ---disable_warnings -drop function if exists bug2772| ---enable_warnings -create function bug2772() returns char(10) character set latin2 - return 'a'| - -select bug2772()| -drop function bug2772| - -# -# BUG#2776 -# ---disable_warnings -drop procedure if exists bug2776_1| ---enable_warnings -create procedure bug2776_1(out x int) -begin - declare v int; - - set v = default; - set x = v; -end| - ---disable_warnings -drop procedure if exists bug2776_2| ---enable_warnings -create procedure bug2776_2(out x int) -begin - declare v int default 42; - - set v = default; - set x = v; -end| - -set @x = 1| -call bug2776_1(@x)| -select @x| -call bug2776_2(@x)| -select @x| -drop procedure bug2776_1| -drop procedure bug2776_2| - -# -# BUG#2780 -# -create table t3 (s1 smallint)| - -insert into t3 values (123456789012)| - ---disable_warnings -drop procedure if exists bug2780| ---enable_warnings -create procedure bug2780() -begin - declare exit handler for sqlwarning set @x = 1; - - set @x = 0; - insert into t3 values (123456789012); - insert into t3 values (0); -end| - -call bug2780()| -select @x| -select * from t3| - -drop procedure bug2780| -drop table t3| - -# -# BUG#1863 -# -create table t3 (content varchar(10) )| -insert into t3 values ("test1")| -insert into t3 values ("test2")| -create table t4 (f1 int, rc int, t3 int)| - ---disable_warnings -drop procedure if exists bug1863| ---enable_warnings -create procedure bug1863(in1 int) -begin - - declare ind int default 0; - declare t1 int; - declare t2 int; - declare t3 int; - - declare rc int default 0; - declare continue handler for 1065 set rc = 1; - - drop temporary table if exists temp_t1; - create temporary table temp_t1 ( - f1 int auto_increment, f2 varchar(20), primary key (f1) - ); - - insert into temp_t1 (f2) select content from t3; - - select f2 into t3 from temp_t1 where f1 = 10; - - if (rc) then - insert into t4 values (1, rc, t3); - end if; - - insert into t4 values (2, rc, t3); - -end| - -call bug1863(10)| -call bug1863(10)| -select * from t4| - -drop procedure bug1863| -drop temporary table temp_t1; -drop table t3, t4| - -# -# BUG#2656 -# - -create table t3 ( - OrderID int not null, - MarketID int, - primary key (OrderID) -)| - -create table t4 ( - MarketID int not null, - Market varchar(60), - Status char(1), - primary key (MarketID) -)| - -insert t3 (OrderID,MarketID) values (1,1)| -insert t3 (OrderID,MarketID) values (2,2)| -insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")| -insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")| - ---disable_warnings -drop procedure if exists bug2656_1| ---enable_warnings -create procedure bug2656_1() -begin - select - m.Market - from t4 m JOIN t3 o - ON o.MarketID != 1 and o.MarketID = m.MarketID; -end | - ---disable_warnings -drop procedure if exists bug2656_2| ---enable_warnings -create procedure bug2656_2() -begin - select - m.Market - from - t4 m, t3 o - where - m.MarketID != 1 and m.MarketID = o.MarketID; - -end | - -call bug2656_1()| -call bug2656_1()| -call bug2656_2()| -call bug2656_2()| -drop procedure bug2656_1| -drop procedure bug2656_2| -drop table t3, t4| - - -# -# BUG#3426 -# ---disable_warnings -drop procedure if exists bug3426| ---enable_warnings -create procedure bug3426(in_time int unsigned, out x int) -begin - if in_time is null then - set @stamped_time=10; - set x=1; - else - set @stamped_time=in_time; - set x=2; - end if; -end| - -call bug3426(1000, @i)| -select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| -call bug3426(NULL, @i)| -select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| -# Clear SP cache -alter procedure bug3426 sql security invoker| -call bug3426(NULL, @i)| -select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| -call bug3426(1000, @i)| -select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| - -drop procedure bug3426| - -# -# BUG#3448 -# ---disable_warnings -create table t3 ( - a int primary key, - ach char(1) -) engine = innodb| - -create table t4 ( - b int primary key , - bch char(1) -) engine = innodb| ---enable_warnings - -insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')| -insert into t4 values (1 , 'bCh1' )| - ---disable_warnings -drop procedure if exists bug3448| ---enable_warnings -create procedure bug3448() - select * from t3 inner join t4 on t3.a = t4.b| - -select * from t3 inner join t4 on t3.a = t4.b| -call bug3448()| -call bug3448()| - -drop procedure bug3448| -drop table t3, t4| - - -# -# BUG#3734 -# -create table t3 ( - id int unsigned auto_increment not null primary key, - title VARCHAR(200), - body text, - fulltext (title,body) -)| - -insert into t3 (title,body) values - ('MySQL Tutorial','DBMS stands for DataBase ...'), - ('How To Use MySQL Well','After you went through a ...'), - ('Optimizing MySQL','In this tutorial we will show ...'), - ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'), - ('MySQL vs. YourSQL','In the following database comparison ...'), - ('MySQL Security','When configured properly, MySQL ...')| - ---disable_warnings -drop procedure if exists bug3734 | ---enable_warnings -create procedure bug3734 (param1 varchar(100)) - select * from t3 where match (title,body) against (param1)| - -call bug3734('database')| -call bug3734('Security')| - -drop procedure bug3734| -drop table t3| - -# -# BUG#3863 -# ---disable_warnings -drop procedure if exists bug3863| ---enable_warnings -create procedure bug3863() -begin - set @a = 0; - while @a < 5 do - set @a = @a + 1; - end while; -end| - -call bug3863()| -select @a| -call bug3863()| -select @a| - -drop procedure bug3863| - -# -# BUG#2460 -# - -create table t3 ( - id int(10) unsigned not null default 0, - rid int(10) unsigned not null default 0, - msg text not null, - primary key (id), - unique key rid (rid, id) -)| - ---disable_warnings -drop procedure if exists bug2460_1| ---enable_warnings -create procedure bug2460_1(in v int) -begin - ( select n0.id from t3 as n0 where n0.id = v ) - union - ( select n0.id from t3 as n0, t3 as n1 - where n0.id = n1.rid and n1.id = v ) - union - ( select n0.id from t3 as n0, t3 as n1, t3 as n2 - where n0.id = n1.rid and n1.id = n2.rid and n2.id = v ); -end| - -call bug2460_1(2)| -call bug2460_1(2)| -insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')| -call bug2460_1(2)| -call bug2460_1(2)| - ---disable_warnings -drop procedure if exists bug2460_2| ---enable_warnings -create procedure bug2460_2() -begin - drop table if exists t3; - create temporary table t3 (s1 int); - insert into t3 select 1 union select 1; -end| - -call bug2460_2()| -call bug2460_2()| -select * from t3| - -drop procedure bug2460_1| -drop procedure bug2460_2| -drop table t3| - - -# -# BUG#2564 -# -set @@sql_mode = ''| ---disable_warnings -drop procedure if exists bug2564_1| ---enable_warnings -create procedure bug2564_1() - comment 'Joe''s procedure' - insert into `t1` values ("foo", 1)| - -set @@sql_mode = 'ANSI_QUOTES'| ---disable_warnings -drop procedure if exists bug2564_2| ---enable_warnings -create procedure bug2564_2() - insert into "t1" values ('foo', 1)| - -delimiter $| -set @@sql_mode = ''$ ---disable_warnings -drop function if exists bug2564_3$ ---enable_warnings -create function bug2564_3(x int, y int) returns int - return x || y$ - -set @@sql_mode = 'ANSI'$ ---disable_warnings -drop function if exists bug2564_4$ ---enable_warnings -create function bug2564_4(x int, y int) returns int - return x || y$ -delimiter |$ - -set @@sql_mode = ''| -show create procedure bug2564_1| -show create procedure bug2564_2| -show create function bug2564_3| -show create function bug2564_4| - -drop procedure bug2564_1| -drop procedure bug2564_2| -drop function bug2564_3| -drop function bug2564_4| - -# -# BUG#3132 -# ---disable_warnings -drop function if exists bug3132| ---enable_warnings -create function bug3132(s char(20)) returns char(50) - return concat('Hello, ', s, '!')| - -select bug3132('Bob') union all select bug3132('Judy')| -drop function bug3132| - -# -# BUG#3843 -# ---disable_warnings -drop procedure if exists bug3843| ---enable_warnings -create procedure bug3843() - analyze table t1| - -# Testing for packets out of order -call bug3843()| -call bug3843()| -select 1+2| - -drop procedure bug3843| - -# -# BUG#3368 -# -create table t3 ( s1 char(10) )| -insert into t3 values ('a'), ('b')| - ---disable_warnings -drop procedure if exists bug3368| ---enable_warnings -create procedure bug3368(v char(10)) -begin - select group_concat(v) from t3; -end| - -call bug3368('x')| -call bug3368('yz')| -drop procedure bug3368| -drop table t3| - -# -# BUG#4579 -# -create table t3 (f1 int, f2 int)| -insert into t3 values (1,1)| - ---disable_warnings -drop procedure if exists bug4579_1| ---enable_warnings -create procedure bug4579_1 () -begin - declare sf1 int; - - select f1 into sf1 from t3 where f1=1 and f2=1; - update t3 set f2 = f2 + 1 where f1=1 and f2=1; - call bug4579_2(); -end| - ---disable_warnings -drop procedure if exists bug4579_2| ---enable_warnings -create procedure bug4579_2 () -begin -end| - -call bug4579_1()| -call bug4579_1()| -call bug4579_1()| - -drop procedure bug4579_1| -drop procedure bug4579_2| -drop table t3| - -# -# BUG#2773: Function's data type ignored in stored procedures -# ---disable_warnings -drop procedure if exists bug2773| ---enable_warnings - -create function bug2773() returns int return null| -create table t3 as select bug2773()| -show create table t3| -drop table t3| -drop function bug2773| - -# -# BUG#3788: Stored procedure packet error -# ---disable_warnings -drop procedure if exists bug3788| ---enable_warnings - -create function bug3788() returns date return cast("2005-03-04" as date)| -select bug3788()| -drop function bug3788| - -create function bug3788() returns binary(1) return 5| -select bug3788()| -drop function bug3788| - - -# -# BUG#4726 -# -create table t3 (f1 int, f2 int, f3 int)| -insert into t3 values (1,1,1)| - ---disable_warnings -drop procedure if exists bug4726| ---enable_warnings -create procedure bug4726() -begin - declare tmp_o_id INT; - declare tmp_d_id INT default 1; - - while tmp_d_id <= 2 do - begin - select f1 into tmp_o_id from t3 where f2=1 and f3=1; - set tmp_d_id = tmp_d_id + 1; - end; - end while; -end| - -call bug4726()| -call bug4726()| -call bug4726()| - -drop procedure bug4726| -drop table t3| - -# -# BUG#4318 -# - ---disable_parsing # Don't know if HANDLER commands can work with SPs, or at all.. -create table t3 (s1 int)| -insert into t3 values (3), (4)| - ---disable_warnings -drop procedure if exists bug4318| ---enable_warnings -create procedure bug4318() - handler t3 read next| - -handler t3 open| -# Expect no results, as tables are closed, but there shouldn't be any errors -call bug4318()| -call bug4318()| -handler t3 close| - -drop procedure bug4318| -drop table t3| ---enable_parsing - -# -# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error -# -# Added tests for most other show commands we could find too. -# (Skipping those already tested, and the ones depending on optional handlers.) -# -# Note: This will return a large number of results of different formats, -# which makes it impossible to filter with --replace_column. -# It's possible that some of these are not deterministic across -# platforms. If so, just remove the offending command. -# ---disable_warnings -drop procedure if exists bug4902| ---enable_warnings -create procedure bug4902() -begin - show charset like 'foo'; - show collation like 'foo'; - show column types; - show create table t1; - show create database test; - show databases like 'foo'; - show errors; - show columns from t1; - show grants for 'root'@'localhost'; - show keys from t1; - show open tables like 'foo'; - show privileges; - show status like 'foo'; - show tables like 'foo'; - show variables like 'foo'; - show warnings; -end| ---disable_parsing -show binlog events; -show storage engines; -show master status; -show slave hosts; -show slave status; ---enable_parsing - -call bug4902()| -call bug4902()| - -drop procedure bug4902| - -# We need separate SP for SHOW PROCESSLIST since we want use replace_column ---disable_warnings -drop procedure if exists bug4902_2| ---enable_warnings -create procedure bug4902_2() -begin - show processlist; -end| ---replace_column 1 # 6 # 3 localhost -call bug4902_2()| ---replace_column 1 # 6 # 3 localhost -call bug4902_2()| -drop procedure bug4902_2| - -# -# BUG#4904 -# ---disable_warnings -drop procedure if exists bug4904| ---enable_warnings -create procedure bug4904() -begin - declare continue handler for sqlstate 'HY000' begin end; - - create table t2 as select * from t3; -end| - --- error 1146 -call bug4904()| - -drop procedure bug4904| - -create table t3 (s1 char character set latin1, s2 char character set latin2)| - ---disable_warnings -drop procedure if exists bug4904| ---enable_warnings -create procedure bug4904 () -begin - declare continue handler for sqlstate 'HY000' begin end; - - select s1 from t3 union select s2 from t3; -end| - -call bug4904()| - -drop procedure bug4904| -drop table t3| - -# -# BUG#336 -# ---disable_warnings -drop procedure if exists bug336| ---enable_warnings -create procedure bug336(out y int) -begin - declare x int; - set x = (select sum(t.data) from test.t1 t); - set y = x; -end| - -insert into t1 values ("a", 2), ("b", 3)| -call bug336(@y)| -select @y| -delete from t1| -drop procedure bug336| - -# -# BUG#3157 -# ---disable_warnings -drop procedure if exists bug3157| ---enable_warnings -create procedure bug3157() -begin - if exists(select * from t1) then - set @n= @n + 1; - end if; - if (select count(*) from t1) then - set @n= @n + 1; - end if; -end| - -set @n = 0| -insert into t1 values ("a", 1)| -call bug3157()| -select @n| -delete from t1| -drop procedure bug3157| - -# -# BUG#5251: mysql changes creation time of a procedure/function when altering -# ---disable_warnings -drop procedure if exists bug5251| ---enable_warnings -create procedure bug5251() -begin -end| - -select created into @c1 from mysql.proc - where db='test' and name='bug5251'| ---sleep 2 -alter procedure bug5251 comment 'foobar'| -select count(*) from mysql.proc - where db='test' and name='bug5251' and created = @c1| - -drop procedure bug5251| - -# -# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE -# ---disable_warnings -drop procedure if exists bug5251| ---enable_warnings -create procedure bug5251() - checksum table t1| - -call bug5251()| -call bug5251()| -drop procedure bug5251| - -# -# BUG#5287: Stored procedure crash if leave outside loop -# ---disable_warnings -drop procedure if exists bug5287| ---enable_warnings -create procedure bug5287(param1 int) -label1: - begin - declare c cursor for select 5; - - loop - if param1 >= 0 then - leave label1; - end if; - end loop; -end| -call bug5287(1)| -drop procedure bug5287| - - -# -# BUG#5307: Stored procedure allows statement after BEGIN ... END -# ---disable_warnings -drop procedure if exists bug5307| ---enable_warnings -create procedure bug5307() -begin -end; set @x = 3| - -call bug5307()| -select @x| -drop procedure bug5307| - -# -# BUG#5258: Stored procedure modified date is 0000-00-00 -# (This was a design flaw) ---disable_warnings -drop procedure if exists bug5258| ---enable_warnings -create procedure bug5258() -begin -end| - ---disable_warnings -drop procedure if exists bug5258_aux| ---enable_warnings -create procedure bug5258_aux() -begin - declare c, m char(19); - - select created,modified into c,m from mysql.proc where name = 'bug5258'; - if c = m then - select 'Ok'; - else - select c, m; - end if; -end| - -call bug5258_aux()| - -drop procedure bug5258| -drop procedure bug5258_aux| - -# -# BUG#4487: Stored procedure connection aborted if uninitialized char -# ---disable_warnings -drop function if exists bug4487| ---enable_warnings -create function bug4487() returns char -begin - declare v char; - return v; -end| - -select bug4487()| -drop function bug4487| - - -# -# BUG#4941: Stored procedure crash fetching null value into variable. -# ---disable_warnings -drop procedure if exists bug4941| ---enable_warnings ---disable_warnings -drop procedure if exists bug4941| ---enable_warnings -create procedure bug4941(out x int) -begin - declare c cursor for select i from t2 limit 1; - open c; - fetch c into x; - close c; -end| - -insert into t2 values (null, null, null)| -set @x = 42| -call bug4941(@x)| -select @x| -delete from t1| -drop procedure bug4941| - - -# -# BUG#3583: query cache doesn't work for stored procedures -# ---disable_warnings -drop procedure if exists bug3583| ---enable_warnings ---disable_warnings -drop procedure if exists bug3583| ---enable_warnings -create procedure bug3583() -begin - declare c int; - - select * from t1; - select count(*) into c from t1; - select c; -end| - -insert into t1 values ("x", 3), ("y", 5)| -set @x = @@query_cache_size| -set global query_cache_size = 10*1024*1024| - -flush status| -flush query cache| -show status like 'Qcache_hits'| -call bug3583()| -show status like 'Qcache_hits'| -call bug3583()| -call bug3583()| -show status like 'Qcache_hits'| - -set global query_cache_size = @x| -flush status| -flush query cache| -delete from t1| -drop procedure bug3583| - -# -# BUG#4905: Stored procedure doesn't clear for "Rows affected" -# ---disable_warnings -drop procedure if exists bug4905| ---enable_warnings - -create table t3 (s1 int,primary key (s1))| - ---disable_warnings -drop procedure if exists bug4905| ---enable_warnings -create procedure bug4905() -begin - declare v int; - declare continue handler for sqlstate '23000' set v = 5; - - insert into t3 values (1); -end| - -call bug4905()| -select row_count()| -call bug4905()| -select row_count()| -call bug4905()| -select row_count()| -select * from t3| - -drop procedure bug4905| -drop table t3| - -# -# BUG#6022: Stored procedure shutdown problem with self-calling function. -# - ---disable_parsing # until we implement support for recursive stored functions. ---disable_warnings -drop function if exists bug6022| ---enable_warnings - ---disable_warnings -drop function if exists bug6022| ---enable_warnings -create function bug6022(x int) returns int -begin - if x < 0 then - return 0; - else - return bug6022(x-1); - end if; -end| - -select bug6022(5)| -drop function bug6022| ---enable_parsing - -# -# BUG#6029: Stored procedure specific handlers should have priority -# ---disable_warnings -drop procedure if exists bug6029| ---enable_warnings - ---disable_warnings -drop procedure if exists bug6029| ---enable_warnings -create procedure bug6029() -begin - declare exit handler for 1136 select '1136'; - declare exit handler for sqlstate '23000' select 'sqlstate 23000'; - declare continue handler for sqlexception select 'sqlexception'; - - insert into t3 values (1); - insert into t3 values (1,2); -end| - -create table t3 (s1 int, primary key (s1))| -insert into t3 values (1)| -call bug6029()| -delete from t3| -call bug6029()| - -drop procedure bug6029| -drop table t3| - -# -# BUG#8540: Local variable overrides an alias -# ---disable_warnings -drop procedure if exists bug8540| ---enable_warnings - -create procedure bug8540() -begin - declare x int default 1; - select x as y, x+0 as z; -end| - -call bug8540()| -drop procedure bug8540| - -# -# BUG#6642: Stored procedure crash if expression with set function -# -create table t3 (s1 int)| - ---disable_warnings -drop procedure if exists bug6642| ---enable_warnings - -create procedure bug6642() - select abs(count(s1)) from t3| - -call bug6642()| -call bug6642()| -drop procedure bug6642| - -# -# BUG#7013: Stored procedure crash if group by ... with rollup -# -insert into t3 values (0),(1)| ---disable_warnings -drop procedure if exists bug7013| ---enable_warnings -create procedure bug7013() - select s1,count(s1) from t3 group by s1 with rollup| -call bug7013()| -call bug7013()| -drop procedure bug7013| - -# -# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure -# ---disable_warnings -drop table if exists t4| ---enable_warnings -create table t4 ( - a mediumint(8) unsigned not null auto_increment, - b smallint(5) unsigned not null, - c char(32) not null, - primary key (a) -) engine=myisam default charset=latin1| -insert into t4 values (1, 2, 'oneword')| -insert into t4 values (2, 2, 'anotherword')| - ---disable_warnings -drop procedure if exists bug7743| ---enable_warnings -create procedure bug7743 ( searchstring char(28) ) -begin - declare var mediumint(8) unsigned; - select a into var from t4 where b = 2 and c = binary searchstring limit 1; - select var; -end| - -call bug7743("oneword")| -call bug7743("OneWord")| -call bug7743("anotherword")| -call bug7743("AnotherWord")| -drop procedure bug7743| -drop table t4| - -# -# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes -# the server -# -delete from t3| -insert into t3 values(1)| -drop procedure if exists bug7992_1| -drop procedure if exists bug7992_2| -create procedure bug7992_1() -begin - declare i int; - select max(s1)+1 into i from t3; -end| -create procedure bug7992_2() - insert into t3 (s1) select max(t4.s1)+1 from t3 as t4| - -call bug7992_1()| -call bug7992_1()| -call bug7992_2()| -call bug7992_2()| - -drop procedure bug7992_1| -drop procedure bug7992_2| -drop table t3| - -# -# BUG#8116: calling simple stored procedure twice in a row results -# in server crash -# -create table t3 ( userid bigint(20) not null default 0 )| - ---disable_warnings -drop procedure if exists bug8116| ---enable_warnings -create procedure bug8116(in _userid int) - select * from t3 where userid = _userid| - -call bug8116(42)| -call bug8116(42)| -drop procedure bug8116| -drop table t3| - -# -# BUG#6857: current_time() in STORED PROCEDURES -# ---disable_warnings -drop procedure if exists bug6857| ---enable_warnings -create procedure bug6857(counter int) -begin - declare t0, t1 int; - declare plus bool default 0; - - set t0 = current_time(); - while counter > 0 do - set counter = counter - 1; - end while; - set t1 = current_time(); - if t1 > t0 then - set plus = 1; - end if; - select plus; -end| - -# QQ: This is currently disabled. Not only does it slow down a normal test -# run, it makes running with valgrind (or similar tools) extremely -# painful. -# Make sure this takes at least one second on all machines in all builds. -# 30000 makes it about 3 seconds on an old 1.1GHz linux. -#call bug6857(300000)| - -drop procedure bug6857| - -# -# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not -# work properly. ---disable_warnings -drop procedure if exists bug8757| ---enable_warnings -create procedure bug8757() -begin - declare x int; - declare c1 cursor for select data from t1 limit 1; - - begin - declare y int; - declare c2 cursor for select i from t2 limit 1; - - open c2; - fetch c2 into y; - close c2; - select 2,y; - end; - open c1; - fetch c1 into x; - close c1; - select 1,x; -end| - -delete from t1| -delete from t2| -insert into t1 values ("x", 1)| -insert into t2 values ("y", 2, 0.0)| - -call bug8757()| - -delete from t1| -delete from t2| -drop procedure bug8757| - - -# -# BUG#8762: Stored Procedures: Inconsistent behavior -# of DROP PROCEDURE IF EXISTS statement. ---disable_warnings -drop procedure if exists bug8762| ---enable_warnings -# Doesn't exist -drop procedure if exists bug8762; create procedure bug8762() begin end| -# Does exist -drop procedure if exists bug8762; create procedure bug8762() begin end| -drop procedure bug8762| - - -# -# BUG#5240: Stored procedure crash if function has cursor declaration -# ---disable_warnings -drop function if exists bug5240| ---enable_warnings -create function bug5240 () returns int -begin - declare x int; - declare c cursor for select data from t1 limit 1; - - open c; - fetch c into x; - close c; - return x; -end| - -delete from t1| -insert into t1 values ("answer", 42)| -select id, bug5240() from t1| -drop function bug5240| - -# -# BUG#5278: Stored procedure packets out of order if SET PASSWORD. -# ---disable_warnings -drop function if exists bug5278| ---enable_warnings -create function bug5278 () returns char -begin - SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass'); - return 'okay'; -end| - ---error 1133 -select bug5278()| ---error 1133 -select bug5278()| -drop function bug5278| - -# -# BUG#7992: rolling back temporary Item tree changes in SP -# ---disable_warnings -drop procedure if exists p1| ---enable_warnings -create table t3(id int)| -insert into t3 values(1)| -create procedure bug7992() -begin - declare i int; - select max(id)+1 into i from t3; -end| - -call bug7992()| -call bug7992()| -drop procedure bug7992| -drop table t3| -delimiter ;| - -# -# BUG#8849: problem with insert statement with table alias's -# -# Rolling back changes to AND/OR structure of ON and WHERE clauses in SP -# - -delimiter |; -create table t3 ( - lpitnumber int(11) default null, - lrecordtype int(11) default null -)| - -create table t4 ( - lbsiid int(11) not null default '0', - ltradingmodeid int(11) not null default '0', - ltradingareaid int(11) not null default '0', - csellingprice decimal(19,4) default null, - primary key (lbsiid,ltradingmodeid,ltradingareaid) -)| - -create table t5 ( - lbsiid int(11) not null default '0', - ltradingareaid int(11) not null default '0', - primary key (lbsiid,ltradingareaid) -)| - ---disable_warnings -drop procedure if exists bug8849| ---enable_warnings -create procedure bug8849() -begin - insert into t5 - ( - t5.lbsiid, - t5.ltradingareaid - ) - select distinct t3.lpitnumber, t4.ltradingareaid - from - t4 join t3 on - t3.lpitnumber = t4.lbsiid - and t3.lrecordtype = 1 - left join t4 as price01 on - price01.lbsiid = t4.lbsiid and - price01.ltradingmodeid = 1 and - t4.ltradingareaid = price01.ltradingareaid; -end| - -call bug8849()| -call bug8849()| -call bug8849()| -drop procedure bug8849| -drop tables t3,t4,t5| - -# -# BUG#8937: Stored Procedure: AVG() works as SUM() in SELECT ... INTO statement -# ---disable_warnings -drop procedure if exists bug8937| ---enable_warnings -create procedure bug8937() -begin - declare s,x,y,z int; - declare a float; - - select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1; - select s,x,y,z; - select avg(data) into a from t1; - select a; -end| - -delete from t1| -insert into t1 (data) values (1), (2), (3), (4), (6)| -call bug8937()| - -drop procedure bug8937| -delete from t1| - - -# -# BUG#6900: Stored procedure inner handler ignored -# BUG#9074: STORED PROC: The scope of every handler declared is not -# properly applied -# ---disable_warnings -drop procedure if exists bug6900| -drop procedure if exists bug9074| -drop procedure if exists bug6900_9074| ---enable_warnings - -create table t3 (w char unique, x char)| -insert into t3 values ('a', 'b')| - -create procedure bug6900() -begin - declare exit handler for sqlexception select '1'; - - begin - declare exit handler for sqlexception select '2'; - - insert into t3 values ('x', 'y', 'z'); - end; -end| - -create procedure bug9074() -begin - declare x1, x2, x3, x4, x5, x6 int default 0; - - begin - declare continue handler for sqlstate '23000' set x5 = 1; - - insert into t3 values ('a', 'b'); - set x6 = 1; - end; - - begin1_label: - begin - declare continue handler for sqlstate '23000' set x1 = 1; - - insert into t3 values ('a', 'b'); - set x2 = 1; - - begin2_label: - begin - declare exit handler for sqlstate '23000' set x3 = 1; - - set x4= 1; - insert into t3 values ('a','b'); - set x4= 0; - end begin2_label; - end begin1_label; - - select x1, x2, x3, x4, x5, x6; -end| - -create procedure bug6900_9074(z int) -begin - declare exit handler for sqlstate '23000' select '23000'; - - begin - declare exit handler for sqlexception select 'sqlexception'; - - if z = 1 then - insert into t3 values ('a', 'b'); - else - insert into t3 values ('x', 'y', 'z'); - end if; - end; -end| - -call bug6900()| -call bug9074()| -call bug6900_9074(0)| -call bug6900_9074(1)| - -drop procedure bug6900| -drop procedure bug9074| -drop procedure bug6900_9074| -drop table t3| - - -# -# BUG#7185: Stored procedure crash if identifier is AVG -# ---disable_warnings -drop procedure if exists avg| ---enable_warnings -create procedure avg () -begin -end| - -call avg ()| -drop procedure avg| - - -# -# BUG#6129: Stored procedure won't display @@sql_mode value -# ---disable_warnings -drop procedure if exists bug6129| ---enable_warnings -set @old_mode= @@sql_mode; -set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO"; -create procedure bug6129() - select @@sql_mode| -call bug6129()| -set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"| -call bug6129()| -set @@sql_mode= "NO_ZERO_IN_DATE"| -call bug6129()| -set @@sql_mode=@old_mode; - -drop procedure bug6129| - - -# -# BUG#9856: Stored procedures: crash if handler for sqlexception, not found -# ---disable_warnings -drop procedure if exists bug9856| ---enable_warnings -create procedure bug9856() -begin - declare v int; - declare c cursor for select data from t1; - declare exit handler for sqlexception, not found select '16'; - - open c; - fetch c into v; - select v; -end| - -delete from t1| -call bug9856()| -call bug9856()| -drop procedure bug9856| - - -# -# BUG##9674: Stored Procs: Using declared vars in algebric operation causes -# system crash. -# ---disable_warnings -drop procedure if exists bug9674_1| -drop procedure if exists bug9674_2| ---enable_warnings -create procedure bug9674_1(out arg int) -begin - declare temp_in1 int default 0; - declare temp_fl1 int default 0; - - set temp_in1 = 100; - set temp_fl1 = temp_in1/10; - set arg = temp_fl1; -end| - -create procedure bug9674_2() -begin - declare v int default 100; - - select v/10; -end| - -call bug9674_1(@sptmp)| -call bug9674_1(@sptmp)| -select @sptmp| -call bug9674_2()| -call bug9674_2()| -drop procedure bug9674_1| -drop procedure bug9674_2| - - -# -# BUG#9598: stored procedure call within stored procedure overwrites IN variable -# ---disable_warnings -drop procedure if exists bug9598_1| -drop procedure if exists bug9598_2| ---enable_warnings -create procedure bug9598_1(in var_1 char(16), - out var_2 integer, out var_3 integer) -begin - set var_2 = 50; - set var_3 = 60; -end| - -create procedure bug9598_2(in v1 char(16), - in v2 integer, - in v3 integer, - in v4 integer, - in v5 integer) -begin - select v1,v2,v3,v4,v5; - call bug9598_1(v1,@tmp1,@tmp2); - select v1,v2,v3,v4,v5; -end| - -call bug9598_2('Test',2,3,4,5)| -select @tmp1, @tmp2| - -drop procedure bug9598_1| -drop procedure bug9598_2| - - -# -# BUG#9902: Crash with simple stored function using user defined variables -# ---disable_warnings -drop procedure if exists bug9902| ---enable_warnings -create function bug9902() returns int(11) -begin - set @x = @x + 1; - return @x; -end| - -set @qcs1 = @@query_cache_size| -set global query_cache_size = 100000| -set @x = 1| -insert into t1 values ("qc", 42)| -select bug9902() from t1| -select bug9902() from t1| -select @x| - -set global query_cache_size = @qcs1| -delete from t1| -drop function bug9902| - - -# -# BUG#9102: Stored proccedures: function which returns blob causes crash -# ---disable_warnings -drop function if exists bug9102| ---enable_warnings -create function bug9102() returns blob return 'a'| -select bug9102()| -drop function bug9102| - - -# -# BUG#7648: Stored procedure crash when invoking a function that returns a bit -# ---disable_warnings -drop function if exists bug7648| ---enable_warnings -create function bug7648() returns bit(8) return 'a'| -select bug7648()| -drop function bug7648| - - -# -# BUG#9775: crash if create function that returns enum or set -# ---disable_warnings -drop function if exists bug9775| ---enable_warnings -create function bug9775(v1 char(1)) returns enum('a','b') return v1| -select bug9775('a'),bug9775('b'),bug9775('c')| -drop function bug9775| -create function bug9775(v1 int) returns enum('a','b') return v1| -select bug9775(1),bug9775(2),bug9775(3)| -drop function bug9775| - -create function bug9775(v1 char(1)) returns set('a','b') return v1| -select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')| -drop function bug9775| -create function bug9775(v1 int) returns set('a','b') return v1| -select bug9775(1),bug9775(2),bug9775(3),bug9775(4)| -drop function bug9775| - - -# -# BUG#8861: If Return is a YEAR data type, value is not shown in year format -# ---disable_warnings -drop function if exists bug8861| ---enable_warnings -create function bug8861(v1 int) returns year return v1| -select bug8861(05)| -set @x = bug8861(05)| -select @x| -drop function bug8861| - - -# -# BUG#9004: Inconsistent behaviour of SP re. warnings -# ---disable_warnings -drop procedure if exists bug9004_1| -drop procedure if exists bug9004_2| ---enable_warnings -create procedure bug9004_1(x char(16)) -begin - insert into t1 values (x, 42); - insert into t1 values (x, 17); -end| -create procedure bug9004_2(x char(16)) - call bug9004_1(x)| - -# Truncation warnings expected... -call bug9004_1('12345678901234567')| -call bug9004_2('12345678901234567890')| - -delete from t1| -drop procedure bug9004_1| -drop procedure bug9004_2| - -# -# BUG#7293: Stored procedure crash with soundex -# ---disable_warnings -drop procedure if exists bug7293| ---enable_warnings -insert into t1 values ('secret', 0)| -create procedure bug7293(p1 varchar(100)) -begin - if exists (select id from t1 where soundex(p1)=soundex(id)) then - select 'yes'; - end if; -end;| -call bug7293('secret')| -call bug7293 ('secrete')| -drop procedure bug7293| -delete from t1| - - -# -# BUG#9841: Unexpected read lock when trying to update a view in a -# stored procedure -# ---disable_warnings -drop procedure if exists bug9841| -drop view if exists v1| ---enable_warnings - -create view v1 as select * from t1, t2 where id = s| -create procedure bug9841 () - update v1 set data = 10| -call bug9841()| - -drop view v1| -drop procedure bug9841| - - -# -# BUG#5963 subqueries in SET/IF -# ---disable_warnings -drop procedure if exists bug5963| ---enable_warnings - -create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;| -create table t3 (s1 int)| -insert into t3 values (5)| -call bug5963_1()| -call bug5963_1()| -drop procedure bug5963_1| -drop table t3| - -create procedure bug5963_2 (cfk_value int) -begin - if cfk_value in (select cpk from t3) then - set @x = 5; - end if; - end; -| -create table t3 (cpk int)| -insert into t3 values (1)| -call bug5963_2(1)| -call bug5963_2(1)| -drop procedure bug5963_2| -drop table t3| - - -# -# BUG#9559: Functions: Numeric Operations using -ve value gives incorrect -# results. -# ---disable_warnings -drop function if exists bug9559| ---enable_warnings -create function bug9559() - returns int -begin - set @y = -6/2; - return @y; -end| - -select bug9559()| - -drop function bug9559| - - -# -# BUG#10961: Stored procedures: crash if select * from dual -# ---disable_warnings -drop procedure if exists bug10961| ---enable_warnings -# "select * from dual" results in an error, so the cursor will not open -create procedure bug10961() -begin - declare v char; - declare x int; - declare c cursor for select * from dual; - declare continue handler for sqlexception select x; - - set x = 1; - open c; - set x = 2; - fetch c into v; - set x = 3; - close c; -end| - -call bug10961()| -call bug10961()| - -drop procedure bug10961| - -# -# BUG #6866: Second call of a stored procedure using a view with on expressions -# - ---disable_warnings -DROP PROCEDURE IF EXISTS bug6866| ---enable_warnings - -DROP VIEW IF EXISTS tv| -DROP TABLE IF EXISTS tt1,tt2,tt3| - -CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))| -CREATE TABLE tt2 (a2 int, data2 varchar(10))| -CREATE TABLE tt3 (a3 int, data3 varchar(10))| - -INSERT INTO tt1 VALUES (1, 1, 4, 'xx')| - -INSERT INTO tt2 VALUES (1, 'a')| -INSERT INTO tt2 VALUES (2, 'b')| -INSERT INTO tt2 VALUES (3, 'c')| - -INSERT INTO tt3 VALUES (4, 'd')| -INSERT INTO tt3 VALUES (5, 'e')| -INSERT INTO tt3 VALUES (6, 'f')| - -CREATE VIEW tv AS -SELECT tt1.*, tt2.data2, tt3.data3 - FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2 - LEFT JOIN tt3 ON tt1.a3 = tt3.a3 - ORDER BY tt1.a1, tt2.a2, tt3.a3| - -CREATE PROCEDURE bug6866 (_a1 int) -BEGIN -SELECT * FROM tv WHERE a1 = _a1; -END| - -CALL bug6866(1)| -CALL bug6866(1)| -CALL bug6866(1)| - -DROP PROCEDURE bug6866; - -DROP VIEW tv| -DROP TABLE tt1, tt2, tt3| - -# -# BUG#10136: items cleunup -# ---disable_warnings -DROP PROCEDURE IF EXISTS bug10136| ---enable_warnings -create table t3 ( name char(5) not null primary key, val float not null)| -insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| -create procedure bug10136() -begin - declare done int default 3; - - repeat - select * from t3; - set done = done - 1; - until done <= 0 end repeat; - -end| -call bug10136()| -call bug10136()| -call bug10136()| -drop procedure bug10136| -drop table t3| - -# -# BUG#11529: crash server after use stored procedure -# ---disable_warnings -drop procedure if exists bug11529| ---enable_warnings -create procedure bug11529() -begin - declare c cursor for select id, data from t1 where data in (10,13); - - open c; - begin - declare vid char(16); - declare vdata int; - declare exit handler for not found begin end; - - while true do - fetch c into vid, vdata; - end while; - end; - close c; -end| - -insert into t1 values - ('Name1', 10), - ('Name2', 11), - ('Name3', 12), - ('Name4', 13), - ('Name5', 14)| - -call bug11529()| -call bug11529()| -delete from t1| -drop procedure bug11529| - - -# -# BUG#6063: Stored procedure labels are subject to restrictions (partial) -# BUG#7088: Stored procedures: labels won't work if character set is utf8 -# ---disable_warnings -drop procedure if exists bug6063| -drop procedure if exists bug7088_1| -drop procedure if exists bug7088_2| ---enable_warnings - ---disable_parsing # temporarily disabled until Bar fixes BUG#11986 -create procedure bug6063() - lâbel: begin end| -call bug6063()| -# QQ Known bug: this will not show the label correctly. -show create procedure bug6063| - -set character set utf8| -create procedure bug7088_1() - label1: begin end label1| -create procedure bug7088_2() - läbel1: begin end| -call bug7088_1()| -call bug7088_2()| -set character set default| -show create procedure bug7088_1| -show create procedure bug7088_2| - -drop procedure bug6063| -drop procedure bug7088_1| -drop procedure bug7088_2| ---enable_parsing - -# -# BUG#9565: "Wrong locking in stored procedure if a sub-sequent procedure -# is called". -# ---disable_warnings -drop procedure if exists bug9565_sub| -drop procedure if exists bug9565| ---enable_warnings -create procedure bug9565_sub() -begin - select * from t1; -end| -create procedure bug9565() -begin - insert into t1 values ("one", 1); - call bug9565_sub(); -end| -call bug9565()| -delete from t1| -drop procedure bug9565_sub| -drop procedure bug9565| - - -# -# BUG#9538: SProc: Creation fails if we try to SET system variable -# using @@var_name in proc -# ---disable_warnings -drop procedure if exists bug9538| ---enable_warnings -create procedure bug9538() - set @@sort_buffer_size = 1000000| - -set @x = @@sort_buffer_size| -set @@sort_buffer_size = 2000000| -select @@sort_buffer_size| -call bug9538()| -select @@sort_buffer_size| -set @@sort_buffer_size = @x| - -drop procedure bug9538| - - -# -# BUG#8692: Cursor fetch of empty string -# ---disable_warnings -drop procedure if exists bug8692| ---enable_warnings -create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| -insert into t3 values ('', '', '', '', '', '', NULL)| - -create procedure bug8692() -begin - declare v1 VARCHAR(10); - declare v2 VARCHAR(10); - declare v3 VARCHAR(10); - declare v4 VARCHAR(10); - declare v5 VARCHAR(10); - declare v6 VARCHAR(10); - declare v7 VARCHAR(10); - declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3; - open c8692; - fetch c8692 into v1,v2,v3,v4,v5,v6,v7; - select v1, v2, v3, v4, v5, v6, v7; -end| - -call bug8692()| -drop procedure bug8692| -drop table t3| - -# -# Bug#10055 "Using stored function with information_schema causes empty -# result set" -# ---disable_warnings -drop function if exists bug10055| ---enable_warnings -create function bug10055(v char(255)) returns char(255) return lower(v)| -# This select should not crash server and should return all fields in t1 -select t.column_name, bug10055(t.column_name) -from information_schema.columns as t -where t.table_schema = 'test' and t.table_name = 't1'| -drop function bug10055| - -# -# Bug #12297 "SP crashes the server if data inserted inside a lon loop" -# The test for memleak bug, so actually there is no way to test it -# from the suite. The test below could be used to check SP memory -# consumption by passing large input parameter. -# - ---disable_warnings -drop procedure if exists bug12297| ---enable_warnings - -create procedure bug12297(lim int) -begin - set @x = 0; - repeat - insert into t1(id,data) - values('aa', @x); - set @x = @x + 1; - until @x >= lim - end repeat; -end| - -call bug12297(10)| -drop procedure bug12297| - -# -# Bug #11247 "Stored procedures: Function calls in long loops leak memory" -# One more memleak bug test. One could use this test to check that the memory -# isn't leaking by increasing the input value for p_bug11247. -# - ---disable_warnings -drop function if exists f_bug11247| -drop procedure if exists p_bug11247| ---enable_warnings - -create function f_bug11247(param int) - returns int -return param + 1| - -create procedure p_bug11247(lim int) -begin - declare v int default 0; - - while v < lim do - set v= f_bug11247(v); - end while; -end| - -call p_bug11247(10)| -drop function f_bug11247| -drop procedure p_bug11247| -# -# BUG#12168: "'DECLARE CONTINUE HANDLER FOR NOT FOUND ...' in conditional -# handled incorrectly" -# ---disable_warnings -drop procedure if exists bug12168| -drop table if exists t3, t4| ---enable_warnings - -create table t3 (a int)| -insert into t3 values (1),(2),(3),(4)| - -create table t4 (a int)| - -create procedure bug12168(arg1 char(1)) -begin - declare b, c integer; - if arg1 = 'a' then - begin - declare c1 cursor for select a from t3 where a % 2; - declare continue handler for not found set b = 1; - set b = 0; - open c1; - c1_repeat: repeat - fetch c1 into c; - if (b = 1) then - leave c1_repeat; - end if; - - insert into t4 values (c); - until b = 1 - end repeat; - end; - end if; - if arg1 = 'b' then - begin - declare c2 cursor for select a from t3 where not a % 2; - declare continue handler for not found set b = 1; - set b = 0; - open c2; - c2_repeat: repeat - fetch c2 into c; - if (b = 1) then - leave c2_repeat; - end if; - - insert into t4 values (c); - until b = 1 - end repeat; - end; - end if; -end| - -call bug12168('a')| -select * from t4| -truncate t4| -call bug12168('b')| -select * from t4| -truncate t4| -call bug12168('a')| -select * from t4| -truncate t4| -call bug12168('b')| -select * from t4| -truncate t4| -drop table t3, t4| -drop procedure if exists bug12168| - -# -# Bug #11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO -# query" -# One more memleak bug. Use the test to check memory consumption. -# - ---disable_warnings -drop table if exists t3| -drop procedure if exists bug11333| ---enable_warnings - -create table t3 (c1 char(128))| - -insert into t3 values - ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')| - - -create procedure bug11333(i int) -begin - declare tmp varchar(128); - set @x = 0; - repeat - select c1 into tmp from t3 - where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; - set @x = @x + 1; - until @x >= i - end repeat; -end| - -call bug11333(10)| - -drop procedure bug11333| -drop table t3| - -# -# BUG#9048: Creating a function with char binary IN parameter fails -# ---disable_warnings -drop function if exists bug9048| ---enable_warnings -create function bug9048(f1 char binary) returns char binary -begin - set f1= concat( 'hello', f1 ); - return f1; -end| -drop function bug9048| - -# Bug #12849 Stored Procedure: Crash on procedure call with CHAR type -# 'INOUT' parameter -# - ---disable_warnings -drop procedure if exists bug12849_1| ---enable_warnings -create procedure bug12849_1(inout x char) select x into x| -set @var='a'| -call bug12849_1(@var)| -select @var| -drop procedure bug12849_1| - ---disable_warnings -drop procedure if exists bug12849_2| ---enable_warnings -create procedure bug12849_2(inout foo varchar(15)) -begin -select concat(foo, foo) INTO foo; -end| -set @var='abcd'| -call bug12849_2(@var)| -select @var| -drop procedure bug12849_2| - -# -# BUG#13133: Local variables in stored procedures are not initialized correctly. -# ---disable_warnings -drop procedure if exists bug131333| -drop function if exists bug131333| ---enable_warnings -create procedure bug131333() -begin - begin - declare a int; - - select a; - set a = 1; - select a; - end; - begin - declare b int; - - select b; - end; -end| - -create function bug131333() - returns int -begin - begin - declare a int; - - set a = 1; - end; - begin - declare b int; - - return b; - end; -end| - -call bug131333()| -select bug131333()| - -drop procedure bug131333| -drop function bug131333| - -# -# BUG#12379: PROCEDURE with HANDLER calling FUNCTION with error get -# strange result -# ---disable_warnings -drop function if exists bug12379| -drop procedure if exists bug12379_1| -drop procedure if exists bug12379_2| -drop procedure if exists bug12379_3| -drop table if exists t3| ---enable_warnings - -create table t3 (c1 char(1) primary key not null)| - -create function bug12379() - returns integer -begin - insert into t3 values('X'); - insert into t3 values('X'); - return 0; -end| - -create procedure bug12379_1() -begin - declare exit handler for sqlexception select 42; - - select bug12379(); -END| -create procedure bug12379_2() -begin - declare exit handler for sqlexception begin end; - - select bug12379(); -end| -create procedure bug12379_3() -begin - select bug12379(); -end| - ---error 1062 -select bug12379()| -select 1| -call bug12379_1()| -select 2| -call bug12379_2()| -select 3| ---error 1062 -call bug12379_3()| -select 4| - -drop function bug12379| -drop procedure bug12379_1| -drop procedure bug12379_2| -drop procedure bug12379_3| -drop table t3| - -# -# Bug #13124 Stored Procedure using SELECT INTO crashes server -# - ---disable_warnings -drop procedure if exists bug13124| ---enable_warnings -create procedure bug13124() -begin - declare y integer; - set @x=y; -end| -call bug13124()| -drop procedure bug13124| - -# -# Bug #12979 Stored procedures: crash if inout decimal parameter -# - -# check NULL inout parameters processing - ---disable_warnings -drop procedure if exists bug12979_1| ---enable_warnings -create procedure bug12979_1(inout d decimal(5)) set d = d / 2| -set @bug12979_user_var = NULL| -call bug12979_1(@bug12979_user_var)| -drop procedure bug12979_1| - -# check NULL local variables processing - ---disable_warnings -drop procedure if exists bug12979_2| ---enable_warnings -create procedure bug12979_2() -begin -declare internal_var decimal(5); -set internal_var= internal_var / 2; -select internal_var; -end| -call bug12979_2()| -drop procedure bug12979_2| - - -# -# BUG#6127: Stored procedure handlers within handlers don't work -# ---disable_warnings -drop table if exists t3| -drop procedure if exists bug6127| ---enable_warnings -create table t3 (s1 int unique)| - -set @sm=@@sql_mode| -set sql_mode='traditional'| - -create procedure bug6127() -begin - declare continue handler for sqlstate '23000' - begin - declare continue handler for sqlstate '22003' - insert into t3 values (0); - - insert into t3 values (1000000000000000); - end; - - insert into t3 values (1); - insert into t3 values (1); -end| - -call bug6127()| -select * from t3| ---error ER_DUP_ENTRY -call bug6127()| -select * from t3| -set sql_mode=@sm| -drop table t3| -drop procedure bug6127| - - -# -# BUG#12589: Assert when creating temp. table from decimal stored procedure -# variable -# ---disable_warnings -drop procedure if exists bug12589_1| -drop procedure if exists bug12589_2| -drop procedure if exists bug12589_3| ---enable_warnings -create procedure bug12589_1() -begin - declare spv1 decimal(3,3); - set spv1= 123.456; - - set spv1 = 'test'; - create temporary table tm1 as select spv1; - show create table tm1; - drop temporary table tm1; -end| - -create procedure bug12589_2() -begin - declare spv1 decimal(6,3); - set spv1= 123.456; - - create temporary table tm1 as select spv1; - show create table tm1; - drop temporary table tm1; -end| - -create procedure bug12589_3() -begin - declare spv1 decimal(6,3); - set spv1= -123.456; - - create temporary table tm1 as select spv1; - show create table tm1; - drop temporary table tm1; -end| - -# Note: The type of the field will match the value, not the declared -# type of the variable. (This is a type checking issue which -# might be changed later.) - -# Warning expected from "set spv1 = 'test'", the value is set to decimal "0". -call bug12589_1()| -# No warnings here -call bug12589_2()| -call bug12589_3()| -drop procedure bug12589_1| -drop procedure bug12589_2| -drop procedure bug12589_3| - -# -# BUG#7049: Stored procedure CALL errors are ignored -# ---disable_warnings -drop table if exists t3| -drop procedure if exists bug7049_1| -drop procedure if exists bug7049_2| -drop procedure if exists bug7049_3| -drop procedure if exists bug7049_4| -drop function if exists bug7049_1| -drop function if exists bug7049_2| ---enable_warnings - -create table t3 ( x int unique )| - -create procedure bug7049_1() -begin - insert into t3 values (42); - insert into t3 values (42); -end| - -create procedure bug7049_2() -begin - declare exit handler for sqlexception - select 'Caught it' as 'Result'; - - call bug7049_1(); - select 'Missed it' as 'Result'; -end| - -create procedure bug7049_3() - call bug7049_1()| - -create procedure bug7049_4() -begin - declare exit handler for sqlexception - select 'Caught it' as 'Result'; - - call bug7049_3(); - select 'Missed it' as 'Result'; -end| - -create function bug7049_1() - returns int -begin - insert into t3 values (42); - insert into t3 values (42); - return 42; -end| - -create function bug7049_2() - returns int -begin - declare x int default 0; - declare continue handler for sqlexception - set x = 1; - - set x = bug7049_1(); - return x; -end| - -call bug7049_2()| -select * from t3| -delete from t3| -call bug7049_4()| -select * from t3| -select bug7049_2()| - -drop table t3| -drop procedure bug7049_1| -drop procedure bug7049_2| -drop procedure bug7049_3| -drop procedure bug7049_4| -drop function bug7049_1| -drop function bug7049_2| - - -# -# BUG#13941: replace() string fuction behaves badly inside stored procedure -# (BUG#13914: IFNULL is returning garbage in stored procedure) -# ---disable_warnings -drop function if exists bug13941| -drop procedure if exists bug13941| ---enable_warnings - -create function bug13941(p_input_str text) - returns text -begin - declare p_output_str text; - - set p_output_str = p_input_str; - - set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); - set p_output_str = replace(p_output_str, 'test', 'prova'); - set p_output_str = replace(p_output_str, 'this', 'questo'); - set p_output_str = replace(p_output_str, ' a ', 'una '); - set p_output_str = replace(p_output_str, 'is', ''); - - return p_output_str; -end| - -create procedure bug13941(out sout varchar(128)) -begin - set sout = 'Local'; - set sout = ifnull(sout, 'DEF'); -end| - -# Note: The bug showed different behaviour in different types of builds, -# giving garbage results in some, and seemingly working in others. -# Running with valgrind (or purify) is the safe way to check that it's -# really working correctly. -select bug13941('this is a test')| -call bug13941(@a)| -select @a| - -drop function bug13941| -drop procedure bug13941| - - -# -# BUG#13095: Cannot create VIEWs in prepared statements -# - -delimiter ;| - ---disable_warnings -DROP PROCEDURE IF EXISTS bug13095; -DROP TABLE IF EXISTS bug13095_t1; -DROP VIEW IF EXISTS bug13095_v1; ---enable_warnings - -delimiter |; - -CREATE PROCEDURE bug13095(tbl_name varchar(32)) -BEGIN - SET @str = - CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))"); - SELECT @str; - PREPARE stmt FROM @str; - EXECUTE stmt; - - SET @str = - CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" ); - SELECT @str; - PREPARE stmt FROM @str; - EXECUTE stmt; - - SET @str = - CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name); - SELECT @str; - PREPARE stmt FROM @str; - EXECUTE stmt; - - SELECT * FROM bug13095_v1; - - SET @str = - "DROP VIEW bug13095_v1"; - SELECT @str; - PREPARE stmt FROM @str; - EXECUTE stmt; -END| - -delimiter ;| - -CALL bug13095('bug13095_t1'); - ---disable_warnings -DROP PROCEDURE IF EXISTS bug13095; -DROP VIEW IF EXISTS bug13095_v1; -DROP TABLE IF EXISTS bug13095_t1; ---enable_warnings - -delimiter |; - -# -# BUG#14210: "Simple query with > operator on large table gives server -# crash" -# Check that cursors work in case when HEAP tables are converted to -# MyISAM -# ---disable_warnings -drop procedure if exists bug14210| ---enable_warnings -set @@session.max_heap_table_size=16384| -select @@session.max_heap_table_size| -# To trigger the memory corruption the original table must be InnoDB. -# No harm if it's not, so don't warn if the suite is run with --skip-innodb ---disable_warnings -create table t3 (a char(255)) engine=InnoDB| ---enable_warnings -create procedure bug14210_fill_table() -begin - declare table_size, max_table_size int default 0; - select @@session.max_heap_table_size into max_table_size; - delete from t3; - insert into t3 (a) values (repeat('a', 255)); - repeat - insert into t3 select a from t3; - select count(*)*255 from t3 into table_size; - until table_size > max_table_size*2 end repeat; -end| -call bug14210_fill_table()| -drop procedure bug14210_fill_table| -create table t4 like t3| - -create procedure bug14210() -begin - declare a char(255); - declare done int default 0; - declare c cursor for select * from t3; - declare continue handler for sqlstate '02000' set done = 1; - open c; - repeat - fetch c into a; - if not done then - insert into t4 values (upper(a)); - end if; - until done end repeat; - close c; -end| -call bug14210()| -select count(*) from t4| - -drop table t3, t4| -drop procedure bug14210| -set @@session.max_heap_table_size=default| - - -# -# BUG#1473: Dumping of stored functions seems to cause corruption in -# the function body -# ---disable_warnings -drop function if exists bug14723| -drop procedure if exists bug14723| ---enable_warnings - -delimiter ;;| -/*!50003 create function bug14723() - returns bigint(20) -main_loop: begin - return 42; -end */;; -show create function bug14723;; -select bug14723();; - -/*!50003 create procedure bug14723() -main_loop: begin - select 42; -end */;; -show create procedure bug14723;; -call bug14723();; - -delimiter |;; - -drop function bug14723| -drop procedure bug14723| - -# -# Bug#14845 "mysql_stmt_fetch returns MYSQL_NO_DATA when COUNT(*) is 0" -# Check that when fetching from a cursor, COUNT(*) works properly. -# -create procedure bug14845() -begin - declare a char(255); - declare done int default 0; - declare c cursor for select count(*) from t1 where 1 = 0; - declare continue handler for sqlstate '02000' set done = 1; - open c; - repeat - fetch c into a; - if not done then - select a; - end if; - until done end repeat; - close c; -end| -call bug14845()| -drop procedure bug14845| - -# -# BUG#13549 "Server crash with nested stored procedures". -# Server should not crash when during execution of stored procedure -# we have to parse trigger/function definition and this new trigger/ -# function has more local variables declared than invoking stored -# procedure and last of these variables is used in argument of NOT -# operator. -# ---disable_warnings -drop procedure if exists bug13549_1| -drop procedure if exists bug13549_2| ---enable_warnings -CREATE PROCEDURE `bug13549_2`() -begin - call bug13549_1(); -end| -CREATE PROCEDURE `bug13549_1`() -begin - declare done int default 0; - set done= not done; -end| -CALL bug13549_2()| -drop procedure bug13549_2| -drop procedure bug13549_1| - -# -# BUG#10100: function (and stored procedure?) recursivity problem -# ---disable_warnings -drop function if exists bug10100f| -drop procedure if exists bug10100p| -drop procedure if exists bug10100t| -drop procedure if exists bug10100pt| -drop procedure if exists bug10100pv| -drop procedure if exists bug10100pd| -drop procedure if exists bug10100pc| ---enable_warnings -# routines with simple recursion -create function bug10100f(prm int) returns int -begin - if prm > 1 then - return prm * bug10100f(prm - 1); - end if; - return 1; -end| -create procedure bug10100p(prm int, inout res int) -begin - set res = res * prm; - if prm > 1 then - call bug10100p(prm - 1, res); - end if; -end| -create procedure bug10100t(prm int) -begin - declare res int; - set res = 1; - call bug10100p(prm, res); - select res; -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 procedure bug10100pt(level int, lim int) -begin - if level < lim then - update t3 set a=level; - FLUSH TABLES; - call bug10100pt(level+1, lim); - else - select * from t3; - end if; -end| -# view & recursion -create procedure bug10100pv(level int, lim int) -begin - if level < lim then - update v1 set a=level; - FLUSH TABLES; - call bug10100pv(level+1, lim); - else - select * from v1; - end if; -end| -# dynamic sql & recursion -prepare stmt2 from "select * from t3;"; -create procedure bug10100pd(level int, lim int) -begin - if level < lim then - select level; - prepare stmt1 from "update t3 set a=a+2"; - execute stmt1; - FLUSH TABLES; - execute stmt1; - FLUSH TABLES; - execute stmt1; - FLUSH TABLES; - deallocate prepare stmt1; - execute stmt2; - select * from t3; - call bug10100pd(level+1, lim); - else - execute stmt2; - end if; -end| -# cursor & recursion -create procedure bug10100pc(level int, lim int) -begin - declare lv int; - declare c cursor for select a from t3; - open c; - if level < lim then - select level; - fetch c into lv; - select lv; - update t3 set a=level+lv; - FLUSH TABLES; - call bug10100pc(level+1, lim); - else - select * from t3; - end if; - close c; -end| - -set @@max_sp_recursion_depth=4| -select @@max_sp_recursion_depth| --- error ER_SP_NO_RECURSION -select bug10100f(3)| --- error ER_SP_NO_RECURSION -select bug10100f(6)| -call bug10100t(5)| -call bug10100pt(1,5)| -call bug10100pv(1,5)| -update t3 set a=1| -call bug10100pd(1,5)| -select * from t3| -update t3 set a=1| -call bug10100pc(1,5)| -select * from t3| -set @@max_sp_recursion_depth=0| -select @@max_sp_recursion_depth| --- error ER_SP_NO_RECURSION -select bug10100f(5)| --- error ER_SP_RECURSION_LIMIT -call bug10100t(5)| - -#end of the stack checking -set @@max_sp_recursion_depth=255| -set @var=1| -#disable log because error about stack overrun contains numbers which -#depend on a system --- disable_result_log --- error ER_STACK_OVERRUN_NEED_MORE -call bug10100p(255, @var)| --- error ER_STACK_OVERRUN_NEED_MORE -call bug10100pt(1,255)| --- error ER_STACK_OVERRUN_NEED_MORE -call bug10100pv(1,255)| --- error ER_STACK_OVERRUN_NEED_MORE -call bug10100pd(1,255)| --- error ER_STACK_OVERRUN_NEED_MORE -call bug10100pc(1,255)| --- enable_result_log -set @@max_sp_recursion_depth=0| - -deallocate prepare stmt2| - -drop function bug10100f| -drop procedure bug10100p| -drop procedure bug10100t| -drop procedure bug10100pt| -drop procedure bug10100pv| -drop procedure bug10100pd| -drop procedure bug10100pc| -drop view v1| - -# -# BUG#13729: Stored procedures: packet error after exception handled -# ---disable_warnings -drop procedure if exists bug13729| -drop table if exists t3| ---enable_warnings - -create table t3 (s1 int, primary key (s1))| - -insert into t3 values (1),(2)| - -create procedure bug13729() -begin - declare continue handler for sqlexception select 55; - - update t3 set s1 = 1; -end| - -call bug13729()| -# Used to cause Packets out of order -select * from t3| - -drop procedure bug13729| -drop table t3| - -# -# BUG#14643: Stored Procedure: Continuing after failed var. initialization -# crashes server. -# ---disable_warnings -drop procedure if exists bug14643_1| -drop procedure if exists bug14643_2| ---enable_warnings - -create procedure bug14643_1() -begin - declare continue handler for sqlexception select 'boo' as 'Handler'; - - begin - declare v int default undefined_var; - - if v = 1 then - select 1; - else - select v, isnull(v); - end if; - end; -end| - -create procedure bug14643_2() -begin - declare continue handler for sqlexception select 'boo' as 'Handler'; - - case undefined_var - when 1 then - select 1; - else - select 2; - end case; - - select undefined_var; -end| - -call bug14643_1()| -call bug14643_2()| - -drop procedure bug14643_1| -drop procedure bug14643_2| - -# -# BUG#14304: auto_increment field incorrect set in SP -# ---disable_warnings -drop procedure if exists bug14304| -drop table if exists t3, t4| ---enable_warnings - -create table t3(a int primary key auto_increment)| -create table t4(a int primary key auto_increment)| - -create procedure bug14304() -begin - insert into t3 set a=null; - insert into t4 set a=null; - insert into t4 set a=null; - insert into t4 set a=null; - insert into t4 set a=null; - insert into t4 set a=null; - insert into t4 select null as a; - - insert into t3 set a=null; - insert into t3 set a=null; - - select * from t3; -end| - -call bug14304()| - -drop procedure bug14304| -drop table t3, t4| - -# -# BUG#14376: MySQL crash on scoped variable (re)initialization -# ---disable_warnings -drop procedure if exists bug14376| ---enable_warnings - -create procedure bug14376() -begin - declare x int default x; -end| - -# Not the error we want, but that's what we got for now... ---error ER_BAD_FIELD_ERROR -call bug14376()| -drop procedure bug14376| - -create procedure bug14376() -begin - declare x int default 42; - - begin - declare x int default x; - - select x; - end; -end| - -call bug14376()| - -drop procedure bug14376| - -create procedure bug14376(x int) -begin - declare x int default x; - - select x; -end| - -call bug14376(4711)| - -drop procedure bug14376| - -# -# Bug#5967 "Stored procedure declared variable used instead of column" -# The bug should be fixed later. -# Test precedence of names of parameters, variable declarations, -# variable declarations in nested compound statements, table columns, -# table columns in cursor declarations. -# According to the standard, table columns take precedence over -# variable declarations. In MySQL 5.0 it's vice versa. -# - ---disable_warnings -drop procedure if exists bug5967| -drop table if exists t3| ---enable_warnings -create table t3 (a varchar(255))| -insert into t3 (a) values ("a - table column")| -create procedure bug5967(a varchar(255)) -begin - declare i varchar(255); - declare c cursor for select a from t3; - select a; - select a from t3 into i; - select i as 'Parameter takes precedence over table column'; open c; - fetch c into i; - close c; - select i as 'Parameter takes precedence over table column in cursors'; - begin - declare a varchar(255) default 'a - local variable'; - declare c1 cursor for select a from t3; - select a as 'A local variable takes precedence over parameter'; - open c1; - fetch c1 into i; - close c1; - select i as 'A local variable takes precedence over parameter in cursors'; - begin - declare a varchar(255) default 'a - local variable in a nested compound statement'; - declare c2 cursor for select a from t3; - select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement'; - select a from t3 into i; - select i as 'A local variable in a nested compound statement takes precedence over table column'; - open c2; - fetch c2 into i; - close c2; - select i as 'A local variable in a nested compound statement takes precedence over table column in cursors'; - end; - end; -end| -call bug5967("a - stored procedure parameter")| -drop procedure bug5967| - -# -# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server" -# ---disable_warnings -drop procedure if exists bug13012| ---enable_warnings -create procedure bug13012() -BEGIN - REPAIR TABLE t1; - BACKUP TABLE t1 to '../tmp'; - DROP TABLE t1; - RESTORE TABLE t1 FROM '../tmp'; -END| -call bug13012()| -drop procedure bug13012| -create view v1 as select * from t1| -create procedure bug13012() -BEGIN - REPAIR TABLE t1,t2,t3,v1; - OPTIMIZE TABLE t1,t2,t3,v1; - ANALYZE TABLE t1,t2,t3,v1; -END| -call bug13012()| -call bug13012()| -call bug13012()| -drop procedure bug13012| -drop view v1; -select * from t1| - -# -# A test case for Bug#15392 "Server crashes during prepared statement -# execute": make sure that stored procedure check for error conditions -# properly and do not continue execution if an error has been set. -# -# It's necessary to use several DBs because in the original code -# the successful return of mysql_change_db overrode the error from -# execution. -drop schema if exists mysqltest1| -drop schema if exists mysqltest2| -drop schema if exists mysqltest3| -create schema mysqltest1| -create schema mysqltest2| -create schema mysqltest3| -use mysqltest3| - -create procedure mysqltest1.p1 (out prequestid varchar(100)) -begin - call mysqltest2.p2('call mysqltest3.p3(1, 2)'); -end| - -create procedure mysqltest2.p2(in psql text) -begin - declare lsql text; - set @lsql= psql; - prepare lstatement from @lsql; - execute lstatement; - deallocate prepare lstatement; -end| - -create procedure mysqltest3.p3(in p1 int) -begin - select p1; -end| - ---error ER_SP_WRONG_NO_OF_ARGS -call mysqltest1.p1(@rs)| ---error ER_SP_WRONG_NO_OF_ARGS -call mysqltest1.p1(@rs)| ---error ER_SP_WRONG_NO_OF_ARGS -call mysqltest1.p1(@rs)| -drop schema if exists mysqltest1| -drop schema if exists mysqltest2| -drop schema if exists mysqltest3| -use test| - -# -# Bug#15441 "Running SP causes Server to Crash": check that an SP variable -# can not be used in VALUES() function. -# ---disable_warnings -drop table if exists t3| -drop procedure if exists bug15441| ---enable_warnings -create table t3 (id int not null primary key, county varchar(25))| -insert into t3 (id, county) values (1, 'York')| - -# First check that a stored procedure that refers to a parameter in VALUES() -# function won't parse. - -create procedure bug15441(c varchar(25)) -begin - update t3 set id=2, county=values(c); -end| ---error ER_BAD_FIELD_ERROR -call bug15441('county')| -drop procedure bug15441| - -# Now check the case when there is an ambiguity between column names -# and stored procedure parameters: the parser shall resolve the argument -# of VALUES() function to the column name. - -# It's hard to deduce what county refers to in every case (INSERT statement): -# 1st county refers to the column -# 2nd county refers to the procedure parameter -# 3d and 4th county refers to the column, again, but -# for 4th county it has the value of SP parameter - -# In UPDATE statement, just check that values() function returns NULL for -# non- INSERT...UPDATE statements, as stated in the manual. - -create procedure bug15441(county varchar(25)) -begin - declare c varchar(25) default "hello"; - - insert into t3 (id, county) values (1, county) - on duplicate key update county= values(county); - select * from t3; - - update t3 set id=2, county=values(id); - select * from t3; -end| -call bug15441('Yale')| -drop table t3| -drop procedure bug15441| - -# -# BUG#14498: Stored procedures: hang if undefined variable and exception -# ---disable_warnings -drop procedure if exists bug14498_1| -drop procedure if exists bug14498_2| -drop procedure if exists bug14498_3| -drop procedure if exists bug14498_4| -drop procedure if exists bug14498_5| ---enable_warnings - -create procedure bug14498_1() -begin - declare continue handler for sqlexception select 'error' as 'Handler'; - - if v then - select 'yes' as 'v'; - else - select 'no' as 'v'; - end if; - select 'done' as 'End'; -end| - -create procedure bug14498_2() -begin - declare continue handler for sqlexception select 'error' as 'Handler'; - - while v do - select 'yes' as 'v'; - end while; - select 'done' as 'End'; -end| - -create procedure bug14498_3() -begin - declare continue handler for sqlexception select 'error' as 'Handler'; - - repeat - select 'maybe' as 'v'; - until v end repeat; - select 'done' as 'End'; -end| - -create procedure bug14498_4() -begin - declare continue handler for sqlexception select 'error' as 'Handler'; - - case v - when 1 then - select '1' as 'v'; - when 2 then - select '2' as 'v'; - else - select '?' as 'v'; - end case; - select 'done' as 'End'; -end| - -create procedure bug14498_5() -begin - declare continue handler for sqlexception select 'error' as 'Handler'; - - case - when v = 1 then - select '1' as 'v'; - when v = 2 then - select '2' as 'v'; - else - select '?' as 'v'; - end case; - select 'done' as 'End'; -end| - -call bug14498_1()| -call bug14498_2()| -call bug14498_3()| -call bug14498_4()| -call bug14498_5()| - -drop procedure bug14498_1| -drop procedure bug14498_2| -drop procedure bug14498_3| -drop procedure bug14498_4| -drop procedure bug14498_5| - -# -# BUG#15231: Stored procedure bug with not found condition handler -# ---disable_warnings -drop table if exists t3| -drop procedure if exists bug15231_1| -drop procedure if exists bug15231_2| -drop procedure if exists bug15231_3| -drop procedure if exists bug15231_4| ---enable_warnings - -create table t3 (id int not null)| - -create procedure bug15231_1() -begin - declare xid integer; - declare xdone integer default 0; - declare continue handler for not found set xdone = 1; - - set xid=null; - call bug15231_2(xid); - select xid, xdone; -end| - -create procedure bug15231_2(inout ioid integer) -begin - select "Before NOT FOUND condition is triggered" as '1'; - select id into ioid from t3 where id=ioid; - select "After NOT FOUND condtition is triggered" as '2'; - - if ioid is null then - set ioid=1; - end if; -end| - -create procedure bug15231_3() -begin - declare exit handler for sqlwarning - select 'Caught it (wrong)' as 'Result'; - - call bug15231_4(); -end| - -create procedure bug15231_4() -begin - declare x decimal(2,1); - - set x = 'zap'; - select 'Missed it (correct)' as 'Result'; -end| - -call bug15231_1()| -call bug15231_3()| - -drop table if exists t3| -drop procedure if exists bug15231_1| -drop procedure if exists bug15231_2| -drop procedure if exists bug15231_3| -drop procedure if exists bug15231_4| - - -# -# BUG#15011: error handler in nested block not activated -# ---disable_warnings -drop procedure if exists bug15011| ---enable_warnings - -create table t3 (c1 int primary key)| - -insert into t3 values (1)| - -create procedure bug15011() - deterministic -begin - declare continue handler for 1062 - select 'Outer' as 'Handler'; - - begin - declare continue handler for 1062 - select 'Inner' as 'Handler'; - - insert into t3 values (1); - end; -end| - -call bug15011()| - -drop procedure bug15011| -drop table t3| - - -# -# BUG#NNNN: New bug synopsis -# -#--disable_warnings -#drop procedure if exists bugNNNN| -#--enable_warnings -#create procedure bugNNNN... - -# Add bugs above this line. Use existing tables t1 and t2 when -# practical, or create table t3, t4 etc temporarily (and drop them). -delimiter ;| -drop table t1,t2; -- cgit v1.2.1 From a29f10e8ee99f96795a6f805a026c61feba77709 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Aug 2006 10:00:28 +0200 Subject: Bug #21396: Wrong error number generated for a missing table BitKeeper/etc/collapsed: BitKeeper file /home/georg/work/mysql/prod/mysql-5.0/BitKeeper/etc/collapsed mysys/my_open.c: Win64 bit fix: Replacing 32-bit value (0xFFFFFFFF) by a generic error constant. --- BitKeeper/etc/collapsed | 1 + mysys/my_open.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 BitKeeper/etc/collapsed diff --git a/BitKeeper/etc/collapsed b/BitKeeper/etc/collapsed new file mode 100644 index 00000000000..8b90deae622 --- /dev/null +++ b/BitKeeper/etc/collapsed @@ -0,0 +1 @@ +44d03f27qNdqJmARzBoP3Is_cN5e0w diff --git a/mysys/my_open.c b/mysys/my_open.c index 6ed3cb5becf..a0168b23b16 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -335,7 +335,7 @@ File my_sopen(const char *path, int oflag, int shflag, int pmode) * try to open/create the file */ if ((osfh= CreateFile(path, fileaccess, fileshare, &SecurityAttributes, - filecreate, fileattrib, NULL)) == (HANDLE)0xffffffff) + filecreate, fileattrib, NULL)) == INVALID_HANDLE_VALUE) { /* * OS call to open/create file failed! map the error, release @@ -346,7 +346,7 @@ File my_sopen(const char *path, int oflag, int shflag, int pmode) return -1; /* return error to caller */ } - fh= _open_osfhandle((long)osfh, oflag & (_O_APPEND | _O_RDONLY | _O_TEXT)); + fh= _open_osfhandle((intptr_t)osfh, oflag & (_O_APPEND | _O_RDONLY | _O_TEXT)); return fh; /* return handle */ } -- cgit v1.2.1 From cb6e70a55c985824981ebc2987b6f71c9219ec59 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Aug 2006 13:25:13 +0400 Subject: Fix a compilation failiure on QNX sql/udf_example.c: Declare tmp_error at the beginning of the block (this is C now) --- sql/udf_example.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/udf_example.c b/sql/udf_example.c index 62995085599..a80fce81278 100644 --- a/sql/udf_example.c +++ b/sql/udf_example.c @@ -806,6 +806,7 @@ char *reverse_lookup(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args, #if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST) char name_buff[256]; struct hostent tmp_hostent; + int tmp_errno; #endif struct hostent *hp; unsigned long taddr; @@ -845,7 +846,6 @@ char *reverse_lookup(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args, return 0; } #if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST) - int tmp_errno; if (!(hp=gethostbyaddr_r((char*) &taddr,sizeof(taddr), AF_INET, &tmp_hostent, name_buff,sizeof(name_buff), &tmp_errno))) -- cgit v1.2.1 From a0efaba36344800e522ba03d373ab2450841852d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Aug 2006 19:39:47 +0400 Subject: A post-merge fix. --- mysql-test/r/ps.result | 85 +++++++++----------------------------------------- 1 file changed, 14 insertions(+), 71 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 70d0bae2d1d..d73dd03fc57 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -485,6 +485,20 @@ execute stmt; pnum deallocate prepare stmt; drop table t1, t2; +drop table if exists t1; +create temporary table if not exists t1 (a1 int); +prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1"; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +deallocate prepare stmt; create table t1 (a varchar(20)); insert into t1 values ('foo'); prepare stmt FROM 'SELECT char_length (a) FROM t1'; @@ -502,77 +516,6 @@ SELECT FOUND_ROWS(); FOUND_ROWS() 2 deallocate prepare stmt; -create table t1 (a char(3) not null, b char(3) not null, -c char(3) not null, primary key (a, b, c)); -create table t2 like t1; -prepare stmt from -"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) - where t1.a=1"; -execute stmt; -a -execute stmt; -a -execute stmt; -a -prepare stmt from -"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from -(t1 left outer join t2 on t2.a=? and t1.b=t2.b) -left outer join t2 t3 on t3.a=? where t1.a=?"; -set @a:=1, @b:=1, @c:=1; -execute stmt using @a, @b, @c; -a b c a b c -execute stmt using @a, @b, @c; -a b c a b c -execute stmt using @a, @b, @c; -a b c a b c -deallocate prepare stmt; -drop table t1,t2; -SET @aux= "SELECT COUNT(*) - FROM INFORMATION_SCHEMA.COLUMNS A, - INFORMATION_SCHEMA.COLUMNS B - WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA - AND A.TABLE_NAME = B.TABLE_NAME - AND A.COLUMN_NAME = B.COLUMN_NAME AND - A.TABLE_NAME = 'user'"; -prepare my_stmt from @aux; -execute my_stmt; -COUNT(*) -37 -execute my_stmt; -COUNT(*) -37 -execute my_stmt; -COUNT(*) -37 -deallocate prepare my_stmt; -drop procedure if exists p1| -drop table if exists t1| -create table t1 (id int)| -insert into t1 values(1)| -create procedure p1(a int, b int) -begin -declare c int; -select max(id)+1 into c from t1; -insert into t1 select a+b; -insert into t1 select a-b; -insert into t1 select a-c; -end| -set @a= 3, @b= 4| -prepare stmt from "call p1(?, ?)"| -execute stmt using @a, @b| -execute stmt using @a, @b| -select * from t1| -id -1 -7 --1 -1 -7 --1 --5 -deallocate prepare stmt| -drop procedure p1| -drop table t1| drop table if exists t1; Warnings: Note 1051 Unknown table 't1' -- cgit v1.2.1 From 3c8150b79bf5302879897e0d1ebd594798bb419e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Aug 2006 22:21:12 +0400 Subject: Disable a failing test case (filed a p1 bug) --- mysql-test/t/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index 007847fab37..7f9170847db 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -11,3 +11,4 @@ ############################################################################## ndb_load : Bug#17233 +lowercase_fs_off : Bug#21419 -- cgit v1.2.1