From 2467674b7364ebcb4eaa4fa9010dc53bdc1d0c04 Mon Sep 17 00:00:00 2001 From: "ramil@mysql.com" <> Date: Sun, 6 Nov 2005 12:35:49 +0400 Subject: [PATCH 1/6] Fix for bug #13044: BIT_COUNT with NULL values. --- mysql-test/r/func_op.result | 11 +++++++++++ mysql-test/t/func_op.test | 12 ++++++++++++ sql/item_func.cc | 5 +---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/func_op.result b/mysql-test/r/func_op.result index d009a66353e..486c55870c2 100644 --- a/mysql-test/r/func_op.result +++ b/mysql-test/r/func_op.result @@ -25,3 +25,14 @@ select -1 >> 0, -1 << 0; select -1 >> 1, -1 << 1; -1 >> 1 -1 << 1 9223372036854775807 18446744073709551614 +drop table if exists t1,t2; +create table t1(a int); +create table t2(a int, b int); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 7), (3, 7); +select t1.a, t2.a, t2.b, bit_count(t2.b) from t1 left join t2 on t1.a=t2.a; +a a b bit_count(t2.b) +1 1 7 3 +2 NULL NULL NULL +3 3 7 3 +drop table t1, t2; diff --git a/mysql-test/t/func_op.test b/mysql-test/t/func_op.test index a312d6ac8c0..ab96caaff82 100644 --- a/mysql-test/t/func_op.test +++ b/mysql-test/t/func_op.test @@ -14,3 +14,15 @@ select 1 | -1, 1 ^ -1, 1 & -1; select 0 | -1, 0 ^ -1, 0 & -1; select -1 >> 0, -1 << 0; select -1 >> 1, -1 << 1; + +# +# Bug 13044: wrong bit_count() results +# + +drop table if exists t1,t2; +create table t1(a int); +create table t2(a int, b int); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 7), (3, 7); +select t1.a, t2.a, t2.b, bit_count(t2.b) from t1 left join t2 on t1.a=t2.a; +drop table t1, t2; diff --git a/sql/item_func.cc b/sql/item_func.cc index 855e86b2382..e83d1f35db8 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1138,11 +1138,8 @@ longlong Item_func_find_in_set::val_int() longlong Item_func_bit_count::val_int() { ulonglong value= (ulonglong) args[0]->val_int(); - if (args[0]->null_value) - { - null_value=1; /* purecov: inspected */ + if ((null_value= args[0]->null_value)) return 0; /* purecov: inspected */ - } return (longlong) my_count_bits(value); } From ba424aacb0aedba7c878557ced6dbbdc4257e8b0 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Sat, 8 Apr 2006 23:19:52 +0300 Subject: [PATCH 2/6] Check tinfo library presence and use it. (BUG#18912) --- acinclude.m4 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/acinclude.m4 b/acinclude.m4 index f36940670a6..ddc50d2972b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -373,7 +373,8 @@ AC_CACHE_VAL(mysql_cv_termcap_lib, [AC_CHECK_LIB(ncurses, tgetent, mysql_cv_termcap_lib=libncurses, [AC_CHECK_LIB(curses, tgetent, mysql_cv_termcap_lib=libcurses, [AC_CHECK_LIB(termcap, tgetent, mysql_cv_termcap_lib=libtermcap, - mysql_cv_termcap_lib=NOT_FOUND)])])]) + [AC_CHECK_LIB(tinfo, tgetent, mysql_cv_termcap_lib=libtinfo, + mysql_cv_termcap_lib=NOT_FOUND)])])])]) AC_MSG_CHECKING(for termcap functions library) if test "$mysql_cv_termcap_lib" = "NOT_FOUND"; then AC_MSG_ERROR([No curses/termcap library found]) @@ -381,6 +382,8 @@ elif test "$mysql_cv_termcap_lib" = "libtermcap"; then TERMCAP_LIB=-ltermcap elif test "$mysql_cv_termcap_lib" = "libncurses"; then TERMCAP_LIB=-lncurses +elif test "$mysql_cv_termcap_lib" = "libtinfo"; then +TERMCAP_LIB=-ltinfo else TERMCAP_LIB=-lcurses fi From 5fe95af80446aa9028cc7839d422448398316a89 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Mon, 10 Apr 2006 21:57:29 +0300 Subject: [PATCH 3/6] Avoid trying to include when it doesn't work in C++ code. (Bug #13621) --- configure.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/configure.in b/configure.in index df4b0fbd5af..0445f7a05e9 100644 --- a/configure.in +++ b/configure.in @@ -830,6 +830,9 @@ AC_SUBST(WRAPLIBS) if test "$IS_LINUX" = "true"; then AC_MSG_CHECKING([for atomic operations]) + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + atom_ops= AC_TRY_RUN([ #include @@ -859,6 +862,8 @@ int main() if test -z "$atom_ops"; then atom_ops="no"; fi AC_MSG_RESULT($atom_ops) + AC_LANG_RESTORE + AC_ARG_WITH(pstack, [ --with-pstack Use the pstack backtrace library], [ USE_PSTACK=$withval ], From 32cabaa39f4d31e5b8dfe5df2caf53ea3ff6f304 Mon Sep 17 00:00:00 2001 From: "ramil@mysql.com" <> Date: Tue, 11 Apr 2006 15:26:18 +0500 Subject: [PATCH 4/6] after merge fix. --- mysql-test/t/func_op.test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/t/func_op.test b/mysql-test/t/func_op.test index 6521349a558..0a4f5034f4c 100644 --- a/mysql-test/t/func_op.test +++ b/mysql-test/t/func_op.test @@ -21,7 +21,9 @@ select -1 >> 1, -1 << 1; # Bug 13044: wrong bit_count() results # +--disable_warnings drop table if exists t1,t2; +--enable_warnings create table t1(a int); create table t2(a int, b int); insert into t1 values (1), (2), (3); From df69944e7316c1ab7fe0460420240f48ba117c13 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Thu, 13 Apr 2006 16:06:52 +0300 Subject: [PATCH 5/6] postmerge fix: added tinfo support. --- config/ac-macros/misc.m4 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/ac-macros/misc.m4 b/config/ac-macros/misc.m4 index 5346b81fb03..d8199f5970e 100644 --- a/config/ac-macros/misc.m4 +++ b/config/ac-macros/misc.m4 @@ -361,7 +361,8 @@ AC_CACHE_VAL(mysql_cv_termcap_lib, [AC_CHECK_LIB(ncurses, tgetent, mysql_cv_termcap_lib=libncurses, [AC_CHECK_LIB(curses, tgetent, mysql_cv_termcap_lib=libcurses, [AC_CHECK_LIB(termcap, tgetent, mysql_cv_termcap_lib=libtermcap, - mysql_cv_termcap_lib=NOT_FOUND)])])]) + [AC_CHECK_LIB(tinfo, tgetent, mysql_cv_termcap_lib=libtinfo, + mysql_cv_termcap_lib=NOT_FOUND)])])])]) AC_MSG_CHECKING(for termcap functions library) if test "$mysql_cv_termcap_lib" = "NOT_FOUND"; then AC_MSG_ERROR([No curses/termcap library found]) @@ -369,6 +370,8 @@ elif test "$mysql_cv_termcap_lib" = "libtermcap"; then TERMCAP_LIB=-ltermcap elif test "$mysql_cv_termcap_lib" = "libncurses"; then TERMCAP_LIB=-lncurses +elif test "$mysql_cv_termcap_lib" = "libtinfo"; then +TERMCAP_LIB=-ltinfo else TERMCAP_LIB=-lcurses fi From efb8b990e4dc3c0ebfa8000df7557a7aca841edd Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Thu, 13 Apr 2006 23:12:26 +0300 Subject: [PATCH 6/6] The check for recursive view definitions added. (BUG#14308) --- mysql-test/r/view.result | 23 +++++++++++++++++++++++ mysql-test/t/view.test | 31 +++++++++++++++++++++++++++++++ sql/share/errmsg.txt | 2 ++ sql/sql_view.cc | 20 +++++++++++++++++++- 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 7519b8022f0..b52e6b58c0e 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2600,3 +2600,26 @@ id td 5 2005-01-04 DROP VIEW v1; DROP TABLE t1; +create table t1 (a int); +create view v1 as select * from t1; +create view v2 as select * from v1; +drop table t1; +rename table v2 to t1; +select * from v1; +ERROR HY000: `test`.`v1` contain view recursion +drop view t1, v1; +create table t1 (a int); +create function f1() returns int +begin +declare mx int; +select max(a) from t1 into mx; +return mx; +end// +create view v1 as select f1() as a; +create view v2 as select * from v1; +drop table t1; +rename table v2 to t1; +select * from v1; +ERROR HY000: Recursive stored functions and triggers are not allowed. +drop function f1; +drop view t1, v1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 7ef1f82dbd3..81fb161b69a 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2454,3 +2454,34 @@ SELECT * FROM v1 WHERE td BETWEEN '2005.01.02' AND '2005.01.04'; DROP VIEW v1; DROP TABLE t1; + +# +# BUG#14308: Recursive view definitions +# +# using view only +create table t1 (a int); +create view v1 as select * from t1; +create view v2 as select * from v1; +drop table t1; +rename table v2 to t1; +-- error ER_VIEW_RECURSIVE +select * from v1; +drop view t1, v1; +# using SP function +create table t1 (a int); +delimiter //; +create function f1() returns int +begin + declare mx int; + select max(a) from t1 into mx; + return mx; +end// +delimiter ;// +create view v1 as select f1() as a; +create view v2 as select * from v1; +drop table t1; +rename table v2 to t1; +-- error ER_SP_NO_RECURSION +select * from v1; +drop function f1; +drop view t1, v1; diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index a1f70fca8df..9519e77903d 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5613,3 +5613,5 @@ ER_SP_NO_AGGREGATE 42000 eng "AGGREGATE is not supported for stored functions" ER_MAX_PREPARED_STMT_COUNT_REACHED 42000 eng "Can't create more than max_prepared_stmt_count statements (current value: %lu)" +ER_VIEW_RECURSIVE + eng "`%-.64s`.`%-.64s` contain view recursion" diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 39d1ae5c9fb..cdb6c581565 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -771,6 +771,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) SELECT_LEX *end, *view_select; LEX *old_lex, *lex; Query_arena *arena, backup; + TABLE_LIST *top_view= table->top_table(); int res; bool result; DBUG_ENTER("mysql_make_view"); @@ -798,6 +799,24 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) DBUG_RETURN(0); } + /* check loop via view definition */ + for (TABLE_LIST *precedent= table->referencing_view; + precedent; + precedent= precedent->referencing_view) + { + if (precedent->view_name.length == table->table_name_length && + precedent->view_db.length == table->db_length && + my_strcasecmp(system_charset_info, + precedent->view_name.str, table->table_name) == 0 && + my_strcasecmp(system_charset_info, + precedent->view_db.str, table->db) == 0) + { + my_error(ER_VIEW_RECURSIVE, MYF(0), + top_view->view_db.str, top_view->view_name.str); + DBUG_RETURN(TRUE); + } + } + /* For now we assume that tables will not be changed during PS life (it will be TRUE as far as we make new table cache). @@ -896,7 +915,6 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) } if (!res && !thd->is_fatal_error) { - TABLE_LIST *top_view= table->top_table(); TABLE_LIST *view_tables= lex->query_tables; TABLE_LIST *view_tables_tail= 0; TABLE_LIST *tbl;