From 053907318516bb8d25f5ae8cb0367d1ebd327158 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Jun 2007 17:54:14 +0300 Subject: [PATCH 01/29] Bug #28701: Views don't have indexes. So they can't take index hints. Added a check and disabled the usage of hints for views. mysql-test/r/view.result: Bug #28701: test case mysql-test/t/view.test: Bug #28701: test case sql/sql_view.cc: Bug #28701: disable usage of hints for views --- mysql-test/r/view.result | 13 ++++++++++++- mysql-test/t/view.test | 22 +++++++++++++++++++++- sql/sql_view.cc | 9 +++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 43e147724c8..39e84151187 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -612,7 +612,7 @@ drop table t1; create table t1 (a int, b int); create view v1 as select a, sum(b) from t1 group by a; select b from v1 use index (some_index) where b=1; -ERROR HY000: Key 'some_index' doesn't exist in table 'v1' +ERROR HY000: Incorrect usage of USE INDEX and VIEW drop view v1; drop table t1; create table t1 (col1 char(5),col2 char(5)); @@ -3455,4 +3455,15 @@ a1 c 2 0 DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1 USE KEY(non_existant); +ERROR HY000: Incorrect usage of USE INDEX and VIEW +SELECT * FROM v1 FORCE KEY(non_existant); +ERROR HY000: Incorrect usage of FORCE INDEX and VIEW +SELECT * FROM v1 IGNORE KEY(non_existant); +ERROR HY000: Incorrect usage of IGNORE INDEX and VIEW +DROP VIEW v1; +DROP TABLE t1; End of 5.0 tests. diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index f574451af08..d209e5848ea 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -506,7 +506,7 @@ drop table t1; # create table t1 (a int, b int); create view v1 as select a, sum(b) from t1 group by a; --- error 1176 +--error ER_WRONG_USAGE select b from v1 use index (some_index) where b=1; drop view v1; drop table t1; @@ -3320,4 +3320,24 @@ SELECT * FROM t1; DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; + +# +# Bug #28701: SELECTs from VIEWs completely ignore USE/FORCE KEY, allowing +# invalid statements +# + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +--error ER_WRONG_USAGE +SELECT * FROM v1 USE KEY(non_existant); +--error ER_WRONG_USAGE +SELECT * FROM v1 FORCE KEY(non_existant); +--error ER_WRONG_USAGE +SELECT * FROM v1 IGNORE KEY(non_existant); + +DROP VIEW v1; +DROP TABLE t1; + + --echo End of 5.0 tests. diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 0fb4d3aaea8..faefeb2aef4 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -918,6 +918,15 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, DBUG_RETURN(0); } + if (table->use_index || table->ignore_index) + { + my_error(ER_WRONG_USAGE, MYF(0), + table->ignore_index ? "IGNORE INDEX" : + (table->force_index ? "FORCE INDEX" : "USE INDEX"), + "VIEW"); + DBUG_RETURN(TRUE); + } + /* check loop via view definition */ for (TABLE_LIST *precedent= table->referencing_view; precedent; From 1cb6dc2b37c9dcf9bfeed2471b8562e78a33b25f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 20 Sep 2007 18:05:09 +0400 Subject: [PATCH 02/29] Bug#29908: A user can gain additional access through the ALTER VIEW. Non-definer of a view was allowed to alter that view. Due to this the alterer can elevate his access rights to access rights of the view definer and thus modify data which he wasn't allowed to modify. A view defined with SQL SECURITY INVOKER can't be used directly for access rights elevation. But a user can first alter the view SQL code and then alter the view to SQL SECURITY DEFINER and thus elevate his access rights. Due to this altering a view with SQL SECURITY INVOKER is also prohibited. Now the mysql_create_view function allows ALTER VIEW only to the view definer or a super user. mysql-test/t/view_grant.test: Added a test case for the bug#29908: A user can gain additional access through the ALTER VIEW. A test case was adjusted after fixfing bug#29908. mysql-test/r/view_grant.result: Added a test case for the bug#29908: A user can gain additional access through the ALTER VIEW. sql/sql_view.cc: Bug#29908: A user can gain additional access through the ALTER VIEW. Now the mysql_create_view function allows ALTER VIEW only to the view definer or a super user. --- mysql-test/r/view_grant.result | 50 ++++++++++++++++++++++++++++++++-- mysql-test/t/view_grant.test | 49 +++++++++++++++++++++++++++++++-- sql/sql_view.cc | 5 +--- 3 files changed, 95 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/view_grant.result b/mysql-test/r/view_grant.result index 0f9ce47dec6..ab408e6f175 100644 --- a/mysql-test/r/view_grant.result +++ b/mysql-test/r/view_grant.result @@ -776,15 +776,59 @@ GRANT CREATE VIEW ON db26813.v2 TO u26813@localhost; GRANT DROP, CREATE VIEW ON db26813.v3 TO u26813@localhost; GRANT SELECT ON db26813.t1 TO u26813@localhost; ALTER VIEW v1 AS SELECT f2 FROM t1; -ERROR 42000: CREATE VIEW command denied to user 'u26813'@'localhost' for table 'v1' +ERROR 42000: Access denied; you need the SUPER privilege for this operation ALTER VIEW v2 AS SELECT f2 FROM t1; -ERROR 42000: DROP command denied to user 'u26813'@'localhost' for table 'v2' +ERROR 42000: Access denied; you need the SUPER privilege for this operation ALTER VIEW v3 AS SELECT f2 FROM t1; +ERROR 42000: Access denied; you need the SUPER privilege for this operation SHOW CREATE VIEW v3; View Create View -v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`f2` AS `f2` from `t1` +v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`f1` AS `f1` from `t1` DROP USER u26813@localhost; DROP DATABASE db26813; +# +# Bug#29908: A user can gain additional access through the ALTER VIEW. +# +CREATE DATABASE mysqltest_29908; +USE mysqltest_29908; +CREATE TABLE t1(f1 INT, f2 INT); +CREATE USER u29908_1@localhost; +CREATE DEFINER = u29908_1@localhost VIEW v1 AS SELECT f1 FROM t1; +CREATE DEFINER = u29908_1@localhost SQL SECURITY INVOKER VIEW v2 AS +SELECT f1 FROM t1; +GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v1 TO u29908_1@localhost; +GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v2 TO u29908_1@localhost; +GRANT SELECT ON mysqltest_29908.t1 TO u29908_1@localhost; +CREATE USER u29908_2@localhost; +GRANT DROP, CREATE VIEW ON mysqltest_29908.v1 TO u29908_2@localhost; +GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v2 TO u29908_2@localhost; +GRANT SELECT ON mysqltest_29908.t1 TO u29908_2@localhost; +ALTER VIEW v1 AS SELECT f2 FROM t1; +ERROR 42000: Access denied; you need the SUPER privilege for this operation +ALTER VIEW v2 AS SELECT f2 FROM t1; +SHOW CREATE VIEW v2; +View Create View +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f2` AS `f2` from `t1` +ALTER VIEW v1 AS SELECT f2 FROM t1; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f2` AS `f2` from `t1` +ALTER VIEW v2 AS SELECT f1 FROM t1; +SHOW CREATE VIEW v2; +View Create View +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f1` AS `f1` from `t1` +ALTER VIEW v1 AS SELECT f1 FROM t1; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f1` AS `f1` from `t1` +ALTER VIEW v2 AS SELECT f2 FROM t1; +SHOW CREATE VIEW v2; +View Create View +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f2` AS `f2` from `t1` +DROP USER u29908_1@localhost; +DROP USER u29908_2@localhost; +DROP DATABASE mysqltest_29908; +####################################################################### DROP DATABASE IF EXISTS mysqltest1; DROP DATABASE IF EXISTS mysqltest2; CREATE DATABASE mysqltest1; diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test index a102f87c4e8..0cad3857dcd 100644 --- a/mysql-test/t/view_grant.test +++ b/mysql-test/t/view_grant.test @@ -1034,10 +1034,11 @@ GRANT SELECT ON db26813.t1 TO u26813@localhost; connect (u1,localhost,u26813,,db26813); connection u1; ---error 1142 +--error ER_SPECIFIC_ACCESS_DENIED_ERROR ALTER VIEW v1 AS SELECT f2 FROM t1; ---error 1142 +--error ER_SPECIFIC_ACCESS_DENIED_ERROR ALTER VIEW v2 AS SELECT f2 FROM t1; +--error ER_SPECIFIC_ACCESS_DENIED_ERROR ALTER VIEW v3 AS SELECT f2 FROM t1; connection root; @@ -1047,6 +1048,50 @@ DROP USER u26813@localhost; DROP DATABASE db26813; disconnect u1; +--echo # +--echo # Bug#29908: A user can gain additional access through the ALTER VIEW. +--echo # +connection root; +CREATE DATABASE mysqltest_29908; +USE mysqltest_29908; +CREATE TABLE t1(f1 INT, f2 INT); +CREATE USER u29908_1@localhost; +CREATE DEFINER = u29908_1@localhost VIEW v1 AS SELECT f1 FROM t1; +CREATE DEFINER = u29908_1@localhost SQL SECURITY INVOKER VIEW v2 AS + SELECT f1 FROM t1; +GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v1 TO u29908_1@localhost; +GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v2 TO u29908_1@localhost; +GRANT SELECT ON mysqltest_29908.t1 TO u29908_1@localhost; +CREATE USER u29908_2@localhost; +GRANT DROP, CREATE VIEW ON mysqltest_29908.v1 TO u29908_2@localhost; +GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v2 TO u29908_2@localhost; +GRANT SELECT ON mysqltest_29908.t1 TO u29908_2@localhost; + +connect (u2,localhost,u29908_2,,mysqltest_29908); +--error ER_SPECIFIC_ACCESS_DENIED_ERROR +ALTER VIEW v1 AS SELECT f2 FROM t1; +ALTER VIEW v2 AS SELECT f2 FROM t1; +SHOW CREATE VIEW v2; + +connect (u1,localhost,u29908_1,,mysqltest_29908); +ALTER VIEW v1 AS SELECT f2 FROM t1; +SHOW CREATE VIEW v1; +ALTER VIEW v2 AS SELECT f1 FROM t1; +SHOW CREATE VIEW v2; + +connection root; +ALTER VIEW v1 AS SELECT f1 FROM t1; +SHOW CREATE VIEW v1; +ALTER VIEW v2 AS SELECT f2 FROM t1; +SHOW CREATE VIEW v2; + +DROP USER u29908_1@localhost; +DROP USER u29908_2@localhost; +DROP DATABASE mysqltest_29908; +disconnect u1; +disconnect u2; +--echo ####################################################################### + # # BUG#24040: Create View don't succed with "all privileges" on a database. # diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 35a97411511..28677cf8a72 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -223,9 +223,6 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, { LEX *lex= thd->lex; bool link_to_local; -#ifndef NO_EMBEDDED_ACCESS_CHECKS - bool definer_check_is_needed= mode != VIEW_ALTER || lex->definer; -#endif /* first table in list is target VIEW name => cut off it */ TABLE_LIST *view= lex->unlink_first_table(&link_to_local); TABLE_LIST *tables= lex->query_tables; @@ -280,7 +277,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, - same as current user - current user has SUPER_ACL */ - if (definer_check_is_needed && + if (lex->definer && (strcmp(lex->definer->user.str, thd->security_ctx->priv_user) != 0 || my_strcasecmp(system_charset_info, lex->definer->host.str, From f7f10959084aa815e1e4f10b6dc02aafa9de588b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Sep 2007 12:09:00 +0400 Subject: [PATCH 03/29] Bug#30384: Having SQL_BUFFER_RESULT option in the CREATE .. KEY(..) .. SELECT led to creating corrupted index. While execution of the CREATE .. SELECT SQL_BUFFER_RESULT statement the engine->start_bulk_insert function was called twice. On the first call On the first call MyISAM disabled all non-unique indexes and on the second call it decides to not re-enable them because all indexes was disabled. Due to this no indexes was actually created during CREATE TABLE thus producing crashed table. Now the select_inset class has is_bulk_insert_mode flag which prevents calling the start_bulk_insert function twice. The flag is set in the select_create::prepare, select_insert::prepare2 functions and the select_insert class constructor. The flag is reset in the select_insert::send_eof function. mysql-test/t/insert_select.test: A test case is added for the bug#30384: Having SQL_BUFFER_RESULT option in the CREATE .. KEY(..) .. SELECT led to creating corrupted index. mysql-test/r/insert_select.result: A test case is added for the bug#30384: Having SQL_BUFFER_RESULT option in the CREATE .. KEY(..) .. SELECT led to creating corrupted index. sql/sql_class.h: Bug#30384: Having SQL_BUFFER_RESULT option in the CREATE .. KEY(..) .. SELECT led to creating corrupted index. The is_bulk_insert_mode flag is added to the select_insert class. sql/sql_insert.cc: Bug#30384: Having SQL_BUFFER_RESULT option in the CREATE .. KEY(..) .. SELECT led to creating corrupted index. The is_bulk_insert_mode is set in the select_create::prepare, select_insert::prepare2 functions and the select_insert class constructor. The flag is reset in the select_insert::send_eof function. --- mysql-test/r/insert_select.result | 12 ++++++++++++ mysql-test/t/insert_select.test | 12 ++++++++++++ sql/sql_class.h | 2 +- sql/sql_insert.cc | 12 ++++++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result index d16562d97e2..7a37f49125a 100644 --- a/mysql-test/r/insert_select.result +++ b/mysql-test/r/insert_select.result @@ -830,3 +830,15 @@ id prev_id join_id 3 2 0 4 3 0 DROP TABLE t1,t2; +# +# Bug#30384: Having SQL_BUFFER_RESULT option in the +# CREATE .. KEY(..) .. SELECT led to creating corrupted index. +# +create table t1(f1 int); +insert into t1 values(1),(2),(3); +create table t2 (key(f1)) engine=myisam select sql_buffer_result f1 from t1; +check table t2 extended; +Table Op Msg_type Msg_text +test.t2 check status OK +drop table t1,t2; +################################################################## diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test index fcd07a21821..78a903e0d18 100644 --- a/mysql-test/t/insert_select.test +++ b/mysql-test/t/insert_select.test @@ -385,3 +385,15 @@ INSERT INTO t1 (prev_id) SELECT id SELECT * FROM t1; DROP TABLE t1,t2; + +--echo # +--echo # Bug#30384: Having SQL_BUFFER_RESULT option in the +--echo # CREATE .. KEY(..) .. SELECT led to creating corrupted index. +--echo # +create table t1(f1 int); +insert into t1 values(1),(2),(3); +create table t2 (key(f1)) engine=myisam select sql_buffer_result f1 from t1; +check table t2 extended; +drop table t1,t2; +--echo ################################################################## + diff --git a/sql/sql_class.h b/sql/sql_class.h index 4fac86dc405..e6d65f3133a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2029,7 +2029,7 @@ class select_insert :public select_result_interceptor { ulonglong last_insert_id; COPY_INFO info; bool insert_into_view; - + bool is_bulk_insert_mode; select_insert(TABLE_LIST *table_list_par, TABLE *table_par, List *fields_par, List *update_fields, List *update_values, diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f07af393070..cf0016198da 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2647,7 +2647,8 @@ select_insert::select_insert(TABLE_LIST *table_list_par, TABLE *table_par, bool ignore_check_option_errors) :table_list(table_list_par), table(table_par), fields(fields_par), last_insert_id(0), - insert_into_view(table_list_par && table_list_par->view != 0) + insert_into_view(table_list_par && table_list_par->view != 0), + is_bulk_insert_mode(FALSE) { bzero((char*) &info,sizeof(info)); info.handle_duplicates= duplic; @@ -2832,8 +2833,11 @@ int select_insert::prepare2(void) { DBUG_ENTER("select_insert::prepare2"); if (thd->lex->current_select->options & OPTION_BUFFER_RESULT && - !thd->prelocked_mode) + !thd->prelocked_mode && !is_bulk_insert_mode) + { table->file->start_bulk_insert((ha_rows) 0); + is_bulk_insert_mode= TRUE; + } DBUG_RETURN(0); } @@ -2939,6 +2943,7 @@ bool select_insert::send_eof() DBUG_ENTER("select_insert::send_eof"); error= (!thd->prelocked_mode) ? table->file->end_bulk_insert():0; + is_bulk_insert_mode= FALSE; table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); @@ -3271,7 +3276,10 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) if (info.handle_duplicates == DUP_UPDATE) table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE); if (!thd->prelocked_mode) + { table->file->start_bulk_insert((ha_rows) 0); + is_bulk_insert_mode= TRUE; + } thd->abort_on_warning= (!info.ignore && (thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES | From ebaa05efa757c475161cb5c7f0a1adcbe9f59ff3 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 22 Sep 2007 11:49:27 +0400 Subject: [PATCH 04/29] Bug#27216: functions with parameters of different date types may return wrong type of the result. There are several functions that accept parameters of different types. The result field type of such functions was determined based on the aggregated result type of its arguments. As the DATE and the DATETIME types are represented by the STRING type, the result field type of the affected functions was always STRING for DATE/DATETIME arguments. The affected functions are COALESCE, IF, IFNULL, CASE, LEAST/GREATEST, CASE. Now the affected functions aggregate the field types of their arguments rather than their result types and return the result of aggregation as their result field type. The cached_field_type member variable is added to the number of classes to hold the aggregated result field type. The str_to_date() function's result field type now defaults to the MYSQL_TYPE_DATETIME. The agg_field_type() function is added. It aggregates field types with help of the Field::field_type_merge() function. The create_table_from_items() function now uses the item->tmp_table_field_from_field_type() function to get the proper field when the item is a function with a STRING result type. libmysql/libmysql.c: Bug#27216: functions with parameters of different date types may return wrong type of the result. The client library now accepts the NEWDATE type as a string. sql/item_cmpfunc.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. Now the fix_length_and_dec functions of the Item_func_ifnull,Item_func_if, Item_func_case, Item_func_coalesce classes are use agg_field_type function to find out the type of their result field. sql/item_cmpfunc.h: Bug#27216: functions with parameters of different date types may return wrong type of the result. The cached_field type is added to the Item_func_case, Item_func_if and Item_func_coalesce classes. The field_type function is added to the Item_func_ifnull, Item_func_if, Item_func_coalesce, Item_func_case classes. sql/item_func.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The Item_func_min_max::fix_length_and_dec function now uses the agg_field_type function to find out the correct type of the result field. sql/item_func.h: Bug#27216: functions with parameters of different date types may return wrong type of the result. The cached_field_type variable is added to the Item_func_min_max class. sql/item_timefunc.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The result of the str_to_date function now defaults to the DATETIME type. sql/mysql_priv.h: Bug#27216: functions with parameters of different date types may return wrong type of the result. The prototype of the agg_field_type function is added. sql/protocol.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The Protocol_simple::store function is now used to store fields of NEWDATE type. sql/sql_insert.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The create_table_from_items function now uses the tmp_table_field_from_field_type function to get field for items with the STRING result type. mysql-test/r/date_formats.result: A test case result corrected after fixing bug#27216. mysql-test/r/type_datetime.result: Added a test case for the bug#27216: functions with parameters of different date types may return wrong type of the result. mysql-test/t/type_datetime.test: Added a test case for the bug#27216: functions with parameters of different date types may return wrong type of the result. --- libmysql/libmysql.c | 2 + mysql-test/r/date_formats.result | 2 +- mysql-test/r/type_datetime.result | 61 +++++++++++++++++++++++++++++++ mysql-test/t/type_datetime.test | 38 +++++++++++++++++++ sql/item_cmpfunc.cc | 40 ++++++++++++++++++-- sql/item_cmpfunc.h | 8 +++- sql/item_func.cc | 1 + sql/item_func.h | 4 +- sql/item_timefunc.cc | 2 +- sql/mysql_priv.h | 1 + sql/protocol.cc | 1 + sql/sql_insert.cc | 5 ++- 12 files changed, 156 insertions(+), 9 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 85c56a7ea40..45d68fbbe5c 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -4355,6 +4355,7 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field) case MYSQL_TYPE_STRING: case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_NEWDATE: DBUG_ASSERT(param->buffer_length != 0); param->fetch_result= fetch_result_str; break; @@ -4427,6 +4428,7 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field) case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_STRING: case MYSQL_TYPE_BIT: + case MYSQL_TYPE_NEWDATE: param->skip_result= skip_result_string; break; default: diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index d62c865bb3c..6833a7f1594 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -481,7 +481,7 @@ str_to_date(a,b) create table t2 select str_to_date(a,b) from t1; describe t2; Field Type Null Key Default Extra -str_to_date(a,b) binary(29) YES NULL +str_to_date(a,b) datetime YES NULL select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1, str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S") as f2, str_to_date("2003-01-02", "%Y-%m-%d") as f3, diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 9e47b5da2b6..c58ce3401fb 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -427,3 +427,64 @@ f1 Warnings: Warning 1292 Incorrect datetime value: '2007010100000' for column 'f1' at row 1 drop table t1; +# +# Bug#27216: functions with parameters of different date types may +# return wrong type of the result. +# +create table t1 (f1 date, f2 datetime, f3 varchar(20)); +create table t2 as select coalesce(f1,f1) as f4 from t1; +desc t2; +Field Type Null Key Default Extra +f4 date YES NULL +create table t3 as select coalesce(f1,f2) as f4 from t1; +desc t3; +Field Type Null Key Default Extra +f4 datetime YES NULL +create table t4 as select coalesce(f2,f2) as f4 from t1; +desc t4; +Field Type Null Key Default Extra +f4 datetime YES NULL +create table t5 as select coalesce(f1,f3) as f4 from t1; +desc t5; +Field Type Null Key Default Extra +f4 varbinary(20) YES NULL +create table t6 as select coalesce(f2,f3) as f4 from t1; +desc t6; +Field Type Null Key Default Extra +f4 varbinary(20) YES NULL +create table t7 as select coalesce(makedate(1997,1),f2) as f4 from t1; +desc t7; +Field Type Null Key Default Extra +f4 datetime YES NULL +create table t8 as select coalesce(cast('01-01-01' as datetime),f2) as f4 +from t1; +desc t8; +Field Type Null Key Default Extra +f4 datetime YES NULL +create table t9 as select case when 1 then cast('01-01-01' as date) +when 0 then cast('01-01-01' as date) end as f4 from t1; +desc t9; +Field Type Null Key Default Extra +f4 date YES NULL +create table t10 as select case when 1 then cast('01-01-01' as datetime) +when 0 then cast('01-01-01' as datetime) end as f4 from t1; +desc t10; +Field Type Null Key Default Extra +f4 datetime YES NULL +create table t11 as select if(1, cast('01-01-01' as datetime), +cast('01-01-01' as date)) as f4 from t1; +desc t11; +Field Type Null Key Default Extra +f4 datetime YES NULL +create table t12 as select least(cast('01-01-01' as datetime), +cast('01-01-01' as date)) as f4 from t1; +desc t12; +Field Type Null Key Default Extra +f4 datetime YES NULL +create table t13 as select ifnull(cast('01-01-01' as datetime), +cast('01-01-01' as date)) as f4 from t1; +desc t13; +Field Type Null Key Default Extra +f4 datetime YES NULL +drop tables t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13; +################################################################### diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index ffda593f320..8d68d11c0d6 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -282,3 +282,41 @@ select * from t1 where f1 between 20020101 and 20070101000000; select * from t1 where f1 between 2002010 and 20070101000000; select * from t1 where f1 between 20020101 and 2007010100000; drop table t1; + +--echo # +--echo # Bug#27216: functions with parameters of different date types may +--echo # return wrong type of the result. +--echo # +create table t1 (f1 date, f2 datetime, f3 varchar(20)); +create table t2 as select coalesce(f1,f1) as f4 from t1; +desc t2; +create table t3 as select coalesce(f1,f2) as f4 from t1; +desc t3; +create table t4 as select coalesce(f2,f2) as f4 from t1; +desc t4; +create table t5 as select coalesce(f1,f3) as f4 from t1; +desc t5; +create table t6 as select coalesce(f2,f3) as f4 from t1; +desc t6; +create table t7 as select coalesce(makedate(1997,1),f2) as f4 from t1; +desc t7; +create table t8 as select coalesce(cast('01-01-01' as datetime),f2) as f4 + from t1; +desc t8; +create table t9 as select case when 1 then cast('01-01-01' as date) + when 0 then cast('01-01-01' as date) end as f4 from t1; +desc t9; +create table t10 as select case when 1 then cast('01-01-01' as datetime) + when 0 then cast('01-01-01' as datetime) end as f4 from t1; +desc t10; +create table t11 as select if(1, cast('01-01-01' as datetime), + cast('01-01-01' as date)) as f4 from t1; +desc t11; +create table t12 as select least(cast('01-01-01' as datetime), + cast('01-01-01' as date)) as f4 from t1; +desc t12; +create table t13 as select ifnull(cast('01-01-01' as datetime), + cast('01-01-01' as date)) as f4 from t1; +desc t13; +drop tables t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13; +--echo ################################################################### diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 86eb10d50b0..1599bcc1571 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -147,6 +147,36 @@ static int agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) } +/** + @brief Aggregates field types from the array of items. + + @param[in] items array of items to aggregate the type from + @paran[in] nitems number of items in the array + + @details This function aggregates field types from the array of items. + Found type is supposed to be used later as the result field type + of a multi-argument function. + Aggregation itself is performed by the Field::field_type_merge() + function. + + @note The term "aggregation" is used here in the sense of inferring the + result type of a function from its argument types. + + @return aggregated field type. +*/ + +enum_field_types agg_field_type(Item **items, uint nitems) +{ + uint i; + if (!nitems || items[0]->result_type() == ROW_RESULT ) + return (enum_field_types)-1; + enum_field_types res= items[0]->field_type(); + for (i= 1 ; i < nitems ; i++) + res= Field::field_type_merge(res, items[i]->field_type()); + return res; +} + + static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { @@ -2009,9 +2039,7 @@ Item_func_ifnull::fix_length_and_dec() default: DBUG_ASSERT(0); } - cached_field_type= args[0]->field_type(); - if (cached_field_type != args[1]->field_type()) - cached_field_type= Item_func::field_type(); + cached_field_type= agg_field_type(args, 2); } @@ -2159,11 +2187,13 @@ Item_func_if::fix_length_and_dec() { cached_result_type= arg2_type; collation.set(args[2]->collation.collation); + cached_field_type= args[2]->field_type(); } else if (null2) { cached_result_type= arg1_type; collation.set(args[1]->collation.collation); + cached_field_type= args[1]->field_type(); } else { @@ -2177,6 +2207,7 @@ Item_func_if::fix_length_and_dec() { collation.set(&my_charset_bin); // Number } + cached_field_type= agg_field_type(args + 1, 2); } if ((cached_result_type == DECIMAL_RESULT ) @@ -2556,7 +2587,7 @@ void Item_func_case::fix_length_and_dec() agg_arg_charsets(collation, agg, nagg, MY_COLL_ALLOW_CONV, 1)) return; - + cached_field_type= agg_field_type(agg, nagg); /* Aggregate first expression and all THEN expression types and collations when string comparison @@ -2695,6 +2726,7 @@ my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value) void Item_func_coalesce::fix_length_and_dec() { + cached_field_type= agg_field_type(args, arg_count); agg_result_type(&hybrid_type, args, arg_count); switch (hybrid_type) { case STRING_RESULT: diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 8410c66b034..4d3df7aebf9 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -640,6 +640,7 @@ public: class Item_func_coalesce :public Item_func_numhybrid { protected: + enum_field_types cached_field_type; Item_func_coalesce(Item *a, Item *b) :Item_func_numhybrid(a, b) {} public: Item_func_coalesce(List &list) :Item_func_numhybrid(list) {} @@ -652,13 +653,13 @@ public: enum Item_result result_type () const { return hybrid_type; } const char *func_name() const { return "coalesce"; } table_map not_null_tables() const { return 0; } + enum_field_types field_type() const { return cached_field_type; } }; class Item_func_ifnull :public Item_func_coalesce { protected: - enum_field_types cached_field_type; bool field_type_defined; public: Item_func_ifnull(Item *a, Item *b) :Item_func_coalesce(a,b) {} @@ -677,6 +678,7 @@ public: class Item_func_if :public Item_func { enum Item_result cached_result_type; + enum_field_types cached_field_type; public: Item_func_if(Item *a,Item *b,Item *c) :Item_func(a,b,c), cached_result_type(INT_RESULT) @@ -686,6 +688,7 @@ public: String *val_str(String *str); my_decimal *val_decimal(my_decimal *); enum Item_result result_type () const { return cached_result_type; } + enum_field_types field_type() const { return cached_field_type; } bool fix_fields(THD *, Item **); void fix_length_and_dec(); uint decimal_precision() const; @@ -722,6 +725,7 @@ class Item_func_case :public Item_func uint ncases; Item_result cmp_type; DTCollation cmp_collation; + enum_field_types cached_field_type; public: Item_func_case(List &list, Item *first_expr_arg, Item *else_expr_arg) :Item_func(), first_expr_num(-1), else_expr_num(-1), @@ -749,6 +753,7 @@ public: uint decimal_precision() const; table_map not_null_tables() const { return 0; } enum Item_result result_type () const { return cached_result_type; } + enum_field_types field_type() const { return cached_field_type; } const char *func_name() const { return "case"; } void print(String *str); Item *find_item(String *str); @@ -1382,6 +1387,7 @@ public: bool subst_argument_checker(byte **arg) { return TRUE; } Item *compile(Item_analyzer analyzer, byte **arg_p, Item_transformer transformer, byte *arg_t); + enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; } }; diff --git a/sql/item_func.cc b/sql/item_func.cc index d03d497dfd0..f1c519896b4 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2243,6 +2243,7 @@ void Item_func_min_max::fix_length_and_dec() else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT)) max_length= my_decimal_precision_to_length(max_int_part+decimals, decimals, unsigned_flag); + cached_field_type= agg_field_type(args, arg_count); } diff --git a/sql/item_func.h b/sql/item_func.h index 56b5e75652c..57e33daf0c4 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -692,7 +692,8 @@ class Item_func_min_max :public Item_func /* An item used for issuing warnings while string to DATETIME conversion. */ Item *datetime_item; THD *thd; - +protected: + enum_field_types cached_field_type; public: Item_func_min_max(List &list,int cmp_sign_arg) :Item_func(list), cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(FALSE), @@ -705,6 +706,7 @@ public: enum Item_result result_type () const { return cmp_type; } bool result_as_longlong() { return compare_as_dates; }; uint cmp_datetimes(ulonglong *value); + enum_field_types field_type() const { return cached_field_type; } }; class Item_func_min :public Item_func_min_max diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index ae18e4786d7..b7c9086c127 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -3310,7 +3310,7 @@ void Item_func_str_to_date::fix_length_and_dec() String format_str(format_buff, sizeof(format_buff), &my_charset_bin), *format; maybe_null= 1; decimals=0; - cached_field_type= MYSQL_TYPE_STRING; + cached_field_type= MYSQL_TYPE_DATETIME; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; format= args[1]->val_str(&format_str); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 44eb5590a28..5bec94857f7 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1220,6 +1220,7 @@ my_bool mysql_rm_tmp_tables(void); /* item_func.cc */ extern bool check_reserved_words(LEX_STRING *name); +extern enum_field_types agg_field_type(Item **items, uint nitems); /* strfunc.cc */ ulonglong find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs, diff --git a/sql/protocol.cc b/sql/protocol.cc index ced6d78519a..2bdbe83eea1 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -824,6 +824,7 @@ bool Protocol_simple::store(const char *from, uint length, field_types[field_pos] == MYSQL_TYPE_DECIMAL || field_types[field_pos] == MYSQL_TYPE_BIT || field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL || + field_types[field_pos] == MYSQL_TYPE_NEWDATE || (field_types[field_pos] >= MYSQL_TYPE_ENUM && field_types[field_pos] <= MYSQL_TYPE_GEOMETRY)); field_pos++; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f07af393070..fc403132240 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3129,7 +3129,10 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, create_field *cr_field; Field *field, *def_field; if (item->type() == Item::FUNC_ITEM) - field= item->tmp_table_field(&tmp_table); + if (item->result_type() != STRING_RESULT) + field= item->tmp_table_field(&tmp_table); + else + field= item->tmp_table_field_from_field_type(&tmp_table); else field= create_tmp_field(thd, &tmp_table, item, item->type(), (Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0, From ca448acc25f6502140a68942b2d6d043d3482708 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Sep 2007 15:34:10 +0300 Subject: [PATCH 05/29] Bug #28702: VIEWs defined with USE/FORCE KEY ignore that request When storing the VIEW the CREATE VIEW command is reconstructed from the parse tree. While constructing the command string the index hints specified should also be printed. Fixed by adding code to print the index hints when printing a table in the FROM clause. mysql-test/r/view.result: Bug #28702: test case mysql-test/t/view.test: Bug #28702: test case sql/sql_select.cc: Bug #28702: preserve index hints in a VIEW definition. sql/table.h: Bug #28702: preserve index hints in a VIEW definition. --- mysql-test/r/view.result | 28 ++++++++++++++++++++++ mysql-test/t/view.test | 21 ++++++++++++++++ sql/sql_select.cc | 52 ++++++++++++++++++++++++++++++++++++++++ sql/table.h | 2 ++ 4 files changed, 103 insertions(+) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 1f57964bf65..0ba911f2853 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3573,4 +3573,32 @@ SELECT * FROM v1 IGNORE KEY(non_existant); ERROR HY000: Incorrect usage of IGNORE INDEX and VIEW DROP VIEW v1; DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL DEFAULT 0, +PRIMARY KEY(a), KEY (b)); +INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(); +CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` FORCE INDEX (PRIMARY,`b`) order by `t1`.`a` +EXPLAIN SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL PRIMARY 4 NULL 15 +CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a; +SHOW CREATE VIEW v2; +View Create View +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` USE INDEX () order by `t1`.`a` +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort +CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a; +SHOW CREATE VIEW v3; +View Create View +v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` IGNORE INDEX (`b`) order by `t1`.`a` +EXPLAIN SELECT * FROM v3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort +DROP VIEW v1; +DROP VIEW v2; +DROP VIEW v3; +DROP TABLE t1; End of 5.0 tests. diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index e972ae06a63..e6c3a03c645 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3434,5 +3434,26 @@ DROP VIEW v1; DROP TABLE t1; +# +# Bug #28702: VIEWs defined with USE/FORCE KEY ignore that request +# +CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL DEFAULT 0, + PRIMARY KEY(a), KEY (b)); +INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(); +CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a; +SHOW CREATE VIEW v1; +EXPLAIN SELECT * FROM v1; +CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a; +SHOW CREATE VIEW v2; +EXPLAIN SELECT * FROM v2; +CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a; +SHOW CREATE VIEW v3; +EXPLAIN SELECT * FROM v3; + +DROP VIEW v1; +DROP VIEW v2; +DROP VIEW v3; +DROP TABLE t1; + --echo End of 5.0 tests. diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 453bf7c3b63..47510c15dcd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -15469,6 +15469,47 @@ static void print_join(THD *thd, String *str, List *tables) } +/** + @brief Print an index hint for a table + + @details Prints out the USE|FORCE|IGNORE index hints for a table. + + @param thd the current thread + @param[out] str appends the index hint here + @param hint what the hint is (as string : "USE INDEX"| + "FORCE INDEX"|"IGNORE INDEX") + @param hint_length the length of the string in 'hint' + @param indexes a list of index names for the hint +*/ + +void +TABLE_LIST::print_index_hint(THD *thd, String *str, + const char *hint, uint32 hint_length, + List indexes) +{ + List_iterator_fast li(indexes); + String *idx; + bool first= 1; + + str->append (' '); + str->append (hint, hint_length); + str->append (STRING_WITH_LEN(" (")); + while ((idx = li++)) + { + if (first) + first= 0; + else + str->append(','); + if (!my_strcasecmp (system_charset_info, idx->c_ptr_safe(), + primary_key_name)) + str->append(primary_key_name); + else + append_identifier (thd, str, idx->ptr(), idx->length()); + } + str->append(')'); +} + + /* Print table as it should be in join list @@ -15536,6 +15577,17 @@ void TABLE_LIST::print(THD *thd, String *str) str->append(' '); append_identifier(thd, str, alias, strlen(alias)); } + + if (use_index) + { + if (force_index) + print_index_hint(thd, str, STRING_WITH_LEN("FORCE INDEX"), *use_index); + else + print_index_hint(thd, str, STRING_WITH_LEN("USE INDEX"), *use_index); + } + if (ignore_index) + print_index_hint (thd, str, STRING_WITH_LEN("IGNORE INDEX"), *ignore_index); + } } diff --git a/sql/table.h b/sql/table.h index f411ce489c4..cff4be630e4 100644 --- a/sql/table.h +++ b/sql/table.h @@ -773,6 +773,8 @@ struct TABLE_LIST private: bool prep_check_option(THD *thd, uint8 check_opt_type); bool prep_where(THD *thd, Item **conds, bool no_where_clause); + void print_index_hint(THD *thd, String *str, const char *hint, + uint32 hint_length, List); /* Cleanup for re-execution in a prepared statement or a stored procedure. From 66f13d91208fd3fe9570ef705e350728f63f4727 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Sep 2007 12:15:19 +0300 Subject: [PATCH 06/29] Bug #30468: column level privileges not respected when joining tables When expanding a * in a USING/NATURAL join the check for table access for both tables in the join was done using the grant information of the first one. Fixed by getting the grant information for the current table while iterating through the columns of the join. mysql-test/r/grant2.result: Bug #30468: test case mysql-test/t/grant2.test: Bug #30468: test case sql/sql_acl.cc: Bug #30468: correctly check column grants sql/sql_acl.h: Bug #30468: correctly check column grants sql/sql_base.cc: Bug #30468: correctly check column grants sql/sql_insert.cc: Bug #30468: correctly check column grants --- mysql-test/r/grant2.result | 18 +++++++ mysql-test/t/grant2.test | 32 +++++++++++ sql/sql_acl.cc | 105 ++++++++++++++++++++++++------------- sql/sql_acl.h | 5 +- sql/sql_base.cc | 5 +- sql/sql_insert.cc | 8 ++- 6 files changed, 124 insertions(+), 49 deletions(-) diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result index 6de9a83aeed..e3c92ecc7c8 100644 --- a/mysql-test/r/grant2.result +++ b/mysql-test/r/grant2.result @@ -421,4 +421,22 @@ revoke all privileges, grant option from mysqltest_1@localhost; revoke all privileges, grant option from mysqltest_2@localhost; drop user mysqltest_1@localhost; drop user mysqltest_2@localhost; +CREATE DATABASE db1; +USE db1; +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,1),(2,2); +CREATE TABLE t2 (b INT, c INT); +INSERT INTO t2 VALUES (1,100),(2,200); +GRANT SELECT ON t1 TO mysqltest1@localhost; +GRANT SELECT (b) ON t2 TO mysqltest1@localhost; +USE db1; +SELECT c FROM t2; +ERROR 42000: SELECT command denied to user 'mysqltest1'@'localhost' for column 'c' in table 't2' +SELECT * FROM t2; +ERROR 42000: SELECT command denied to user 'mysqltest1'@'localhost' for column 'c' in table 't2' +SELECT * FROM t1 JOIN t2 USING (b); +ERROR 42000: SELECT command denied to user 'mysqltest1'@'localhost' for column 'c' in table 't2' +DROP TABLE db1.t1, db1.t2; +DROP USER mysqltest1@localhost; +DROP DATABASE db1; End of 5.0 tests diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test index a3a8e2d5d53..e2d92ee58d4 100644 --- a/mysql-test/t/grant2.test +++ b/mysql-test/t/grant2.test @@ -585,5 +585,37 @@ drop user mysqltest_1@localhost; drop user mysqltest_2@localhost; +# +# Bug #30468: column level privileges not respected when joining tables +# +CREATE DATABASE db1; + +USE db1; +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,1),(2,2); + +CREATE TABLE t2 (b INT, c INT); +INSERT INTO t2 VALUES (1,100),(2,200); + +GRANT SELECT ON t1 TO mysqltest1@localhost; +GRANT SELECT (b) ON t2 TO mysqltest1@localhost; + +connect (conn1,localhost,mysqltest1,,); +connection conn1; +USE db1; +--error ER_COLUMNACCESS_DENIED_ERROR +SELECT c FROM t2; +--error ER_COLUMNACCESS_DENIED_ERROR +SELECT * FROM t2; +--error ER_COLUMNACCESS_DENIED_ERROR +SELECT * FROM t1 JOIN t2 USING (b); + +connection default; +disconnect conn1; +DROP TABLE db1.t1, db1.t2; +DROP USER mysqltest1@localhost; +DROP DATABASE db1; + + --echo End of 5.0 tests diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index f9bd2c6ba0d..708c298daa3 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3835,50 +3835,81 @@ bool check_column_grant_in_table_ref(THD *thd, TABLE_LIST * table_ref, } -bool check_grant_all_columns(THD *thd, ulong want_access, GRANT_INFO *grant, - const char* db_name, const char *table_name, - Field_iterator *fields) +/** + @brief check if a query can access a set of columns + + @param thd the current thread + @param want_access_arg the privileges requested + @param fields an iterator over the fields of a table reference. + @return Operation status + @retval 0 Success + @retval 1 Falure + @details This function walks over the columns of a table reference + The columns may originate from different tables, depending on the kind of + table reference, e.g. join. + For each table it will retrieve the grant information and will use it + to check the required access privileges for the fields requested from it. +*/ +bool check_grant_all_columns(THD *thd, ulong want_access_arg, + Field_iterator_table_ref *fields) { Security_context *sctx= thd->security_ctx; - GRANT_TABLE *grant_table; - GRANT_COLUMN *grant_column; + ulong want_access= want_access_arg; + const char *table_name= NULL; - want_access &= ~grant->privilege; - if (!want_access) - return 0; // Already checked - if (!grant_option) - goto err2; - - rw_rdlock(&LOCK_grant); - - /* reload table if someone has modified any grants */ - - if (grant->version != grant_version) + if (grant_option) { - grant->grant_table= - table_hash_search(sctx->host, sctx->ip, db_name, - sctx->priv_user, - table_name, 0); /* purecov: inspected */ - grant->version= grant_version; /* purecov: inspected */ - } - /* The following should always be true */ - if (!(grant_table= grant->grant_table)) - goto err; /* purecov: inspected */ + const char* db_name; + GRANT_INFO *grant; + GRANT_TABLE *grant_table; - for (; !fields->end_of_fields(); fields->next()) - { - const char *field_name= fields->name(); - grant_column= column_hash_search(grant_table, field_name, - (uint) strlen(field_name)); - if (!grant_column || (~grant_column->rights & want_access)) - goto err; - } - rw_unlock(&LOCK_grant); - return 0; + rw_rdlock(&LOCK_grant); + + for (; !fields->end_of_fields(); fields->next()) + { + const char *field_name= fields->name(); + + if (table_name != fields->table_name()) + { + table_name= fields->table_name(); + db_name= fields->db_name(); + grant= fields->grant(); + /* get a fresh one for each table */ + want_access= want_access_arg & ~grant->privilege; + if (want_access) + { + /* reload table if someone has modified any grants */ + if (grant->version != grant_version) + { + grant->grant_table= + table_hash_search(sctx->host, sctx->ip, db_name, + sctx->priv_user, + table_name, 0); /* purecov: inspected */ + grant->version= grant_version; /* purecov: inspected */ + } + + DBUG_ASSERT ((grant_table= grant->grant_table) != NULL); + } + } + + if (want_access) + { + GRANT_COLUMN *grant_column= + column_hash_search(grant_table, field_name, + (uint) strlen(field_name)); + if (!grant_column || (~grant_column->rights & want_access)) + goto err; + } + } + rw_unlock(&LOCK_grant); + return 0; err: - rw_unlock(&LOCK_grant); -err2: + rw_unlock(&LOCK_grant); + } + else + table_name= fields->table_name(); + char command[128]; get_privilege_desc(command, sizeof(command), want_access); my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), diff --git a/sql/sql_acl.h b/sql/sql_acl.h index d08f2663af5..b2007ccdf47 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -205,9 +205,8 @@ bool check_grant_column (THD *thd, GRANT_INFO *grant, const char *name, uint length, Security_context *sctx); bool check_column_grant_in_table_ref(THD *thd, TABLE_LIST * table_ref, const char *name, uint length); -bool check_grant_all_columns(THD *thd, ulong want_access, GRANT_INFO *grant, - const char* db_name, const char *table_name, - Field_iterator *fields); +bool check_grant_all_columns(THD *thd, ulong want_access, + Field_iterator_table_ref *fields); bool check_grant_routine(THD *thd, ulong want_access, TABLE_LIST *procs, bool is_proc, bool no_error); bool check_grant_db(THD *thd,const char *db); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 289924ff418..2f8bb35683b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5414,10 +5414,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, !any_privileges) { field_iterator.set(tables); - if (check_grant_all_columns(thd, SELECT_ACL, field_iterator.grant(), - field_iterator.db_name(), - field_iterator.table_name(), - &field_iterator)) + if (check_grant_all_columns(thd, SELECT_ACL, &field_iterator)) DBUG_RETURN(TRUE); } #endif diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index bd21d929291..7eb9b078ded 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -189,11 +189,9 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, #ifndef NO_EMBEDDED_ACCESS_CHECKS if (grant_option) { - Field_iterator_table field_it; - field_it.set_table(table); - if (check_grant_all_columns(thd, INSERT_ACL, &table->grant, - table->s->db, table->s->table_name, - &field_it)) + Field_iterator_table_ref field_it; + field_it.set(table_list); + if (check_grant_all_columns(thd, INSERT_ACL, &field_it)) return -1; } #endif From edf5745b35394f95f3acc8e7269319cb74b2b63f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Sep 2007 14:29:46 +0300 Subject: [PATCH 07/29] separated an assertion from the assignment (bug 30468) --- sql/sql_acl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 708c298daa3..09c5790881f 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3888,7 +3888,8 @@ bool check_grant_all_columns(THD *thd, ulong want_access_arg, grant->version= grant_version; /* purecov: inspected */ } - DBUG_ASSERT ((grant_table= grant->grant_table) != NULL); + grant_table= grant->grant_table; + DBUG_ASSERT (grant_table); } } From 7ee858eba83a428b003abb427ddc34859e5f9170 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Sep 2007 17:56:50 +0300 Subject: [PATCH 08/29] Fixed a warning cased by the fix for bug 30468 --- sql/sql_acl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 09c5790881f..ecefabaced3 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3861,7 +3861,8 @@ bool check_grant_all_columns(THD *thd, ulong want_access_arg, { const char* db_name; GRANT_INFO *grant; - GRANT_TABLE *grant_table; + /* Initialized only to make gcc happy */ + GRANT_TABLE *grant_table= NULL; rw_rdlock(&LOCK_grant); From bebcb221834a08e492c188fb064414c7dc131902 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Sep 2007 16:46:05 +0300 Subject: [PATCH 09/29] Bug #30587: mysql crashes when trying to group by TIME div NUMBER When calculating the result length of an integer DIV function the number of decimals was used without checking the result type first. Thus an uninitialized number of decimals was used for some types. This caused an excessive amount of memory to be allocated for the field's buffer and crashed the server. Fixed by using the number of decimals only for data types that can have decimals and thus have valid decimals number. mysql-test/r/func_math.result: Bug #30587: test case mysql-test/t/func_math.test: Bug #30587: test case sql/item_func.cc: Bug #30587: Don't use decimals on a type that doesn't have them. --- mysql-test/r/func_math.result | 46 +++++++++++++++++++++++++++++++++++ mysql-test/t/func_math.test | 27 ++++++++++++++++++++ sql/item_func.cc | 6 ++++- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index ace94217fdc..5ef528812e5 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -322,4 +322,50 @@ mod(5, cast(-2 as unsigned)) mod(5, 18446744073709551614) mod(5, -2) select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5); pow(cast(-2 as unsigned), 5) pow(18446744073709551614, 5) pow(-2, 5) 2.1359870359209e+96 2.1359870359209e+96 -32 +CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1)); +INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0); +SELECT a DIV 900 y FROM t1 GROUP BY y; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def y y 8 19 11 Y 32800 0 63 +y +22201025555 +22255916666 +SELECT DISTINCT a DIV 900 y FROM t1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def y y 8 19 11 Y 32800 0 63 +y +22201025555 +22255916666 +SELECT b DIV 900 y FROM t1 GROUP BY y; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def y y 8 20 1 Y 32768 0 63 +y +0 +SELECT c DIV 900 y FROM t1 GROUP BY y; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def y y 3 1 1 Y 32800 0 63 +y +0 +DROP TABLE t1; +CREATE TABLE t1(a LONGBLOB); +INSERT INTO t1 VALUES('1'),('2'),('3'); +SELECT DISTINCT (a DIV 254576881) FROM t1; +(a DIV 254576881) +0 +SELECT (a DIV 254576881) FROM t1 UNION ALL +SELECT (a DIV 254576881) FROM t1; +(a DIV 254576881) +0 +0 +0 +0 +0 +0 +DROP TABLE t1; +CREATE TABLE t1(a SET('a','b','c')); +INSERT INTO t1 VALUES ('a'); +SELECT a DIV 2 FROM t1 UNION SELECT a DIV 2 FROM t1; +a DIV 2 +0 +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index 2ba07dfc581..1f46415741f 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -205,4 +205,31 @@ select mod(cast(-2 as unsigned), 3), mod(18446744073709551614, 3), mod(-2, 3); select mod(5, cast(-2 as unsigned)), mod(5, 18446744073709551614), mod(5, -2); select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5); +# +# Bug #30587: mysql crashes when trying to group by TIME div NUMBER +# + +CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1)); +INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0); +--enable_metadata +SELECT a DIV 900 y FROM t1 GROUP BY y; +SELECT DISTINCT a DIV 900 y FROM t1; +SELECT b DIV 900 y FROM t1 GROUP BY y; +SELECT c DIV 900 y FROM t1 GROUP BY y; +--disable_metadata +DROP TABLE t1; + +CREATE TABLE t1(a LONGBLOB); +INSERT INTO t1 VALUES('1'),('2'),('3'); +SELECT DISTINCT (a DIV 254576881) FROM t1; +SELECT (a DIV 254576881) FROM t1 UNION ALL + SELECT (a DIV 254576881) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1(a SET('a','b','c')); +INSERT INTO t1 VALUES ('a'); +SELECT a DIV 2 FROM t1 UNION SELECT a DIV 2 FROM t1; +DROP TABLE t1; + + --echo End of 5.0 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index d03d497dfd0..a90cc721ca9 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1380,7 +1380,11 @@ longlong Item_func_int_div::val_int() void Item_func_int_div::fix_length_and_dec() { - max_length=args[0]->max_length - args[0]->decimals; + Item_result argtype= args[0]->result_type(); + /* use precision ony for the data type it is applicable for and valid */ + max_length=args[0]->max_length - + (argtype == DECIMAL_RESULT || argtype == INT_RESULT ? + args[0]->decimals : 0); maybe_null=1; unsigned_flag=args[0]->unsigned_flag | args[1]->unsigned_flag; } From 582388e6d299b00db93f633ddace537c51eb66d4 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Sep 2007 18:05:23 +0200 Subject: [PATCH 10/29] Bug #30832: Assertion + crash with select name_const('test', now()); The NAME_CONST function is required to work correctly with constants only. When executed with functions that return types other than those returned by Item::field_type (string, int, decimal, or real), the result gets cast to one of those types. This cannot happen for constants. Fixed by only allowing constants as arguments to NAME_CONST. mysql-test/r/func_misc.result: Bug#30832: Test result mysql-test/t/func_misc.test: Bug#30832: Test case sql/item.h: Bug#30832: The fix --- mysql-test/r/func_misc.result | 16 ++++++++++++++++ mysql-test/t/func_misc.test | 14 ++++++++++++++ sql/item.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index 35101e26ff6..bb6f4127a2a 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -185,4 +185,20 @@ ERROR 21000: Operand should contain 1 column(s) drop table table_26093; drop function func_26093_a; drop function func_26093_b; +SELECT NAME_CONST('test', NOW()); +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('test', UPPER('test')); +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('test', NULL); +test +NULL +SELECT NAME_CONST('test', 1); +test +1 +SELECT NAME_CONST('test', 1.0); +test +1.0 +SELECT NAME_CONST('test', 'test'); +test +test End of 5.0 tests diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index 8ff62f68e45..c93e411e691 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -189,4 +189,18 @@ drop table table_26093; drop function func_26093_a; drop function func_26093_b; +# +# Bug #30832: Assertion + crash with select name_const('test',now()); +# +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('test', NOW()); +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('test', UPPER('test')); + +SELECT NAME_CONST('test', NULL); +SELECT NAME_CONST('test', 1); +SELECT NAME_CONST('test', 1.0); +SELECT NAME_CONST('test', 'test'); + --echo End of 5.0 tests + diff --git a/sql/item.h b/sql/item.h index 3c699c0eda3..cd0be343a62 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1112,6 +1112,8 @@ public: Item_name_const(Item *name_arg, Item *val): value_item(val), name_item(name_arg) { + if(!value_item->basic_const_item()) + my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST"); Item::maybe_null= TRUE; } From 6a8bd84a825094c99919f4391c22fd70f47c08ac Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Sep 2007 23:24:40 +0000 Subject: [PATCH 11/29] Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used. The change_to_use_tmp_fields function leaves the orig_table member of an expression's tmp table field filled for the new Item_field being created. Later orig_table is used by the Field::make_field function to provide some info about original table and field name to a user. This is ok for a field but for an expression it should be empty. The change_to_use_tmp_fields function now resets orig_table member of an expression's tmp table field to prevent providing a wrong info to a user. The Field::make_field function now resets the table_name and the org_col_name variables when the orig_table is set to 0. sql/field.cc: Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used. The Field::make_field function now resets the table_name and the org_col_name variables when the orig_table is set to 0. sql/sql_select.cc: Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used. The change_to_use_tmp_fields function now resets orig_table member of an expression's tmp table field to prevent providing a wrong info to a user. tests/mysql_client_test.c: The test case for the bug#21635 is altered to test behavior on both const and non-const tables. --- mysql-test/r/bdb_notembedded.result | 35 +++++++++++++++++++++ mysql-test/t/bdb_notembedded.test | 38 ++++++++++++++++++++++ sql/field.cc | 16 ++++++++-- sql/sql_select.cc | 3 ++ tests/mysql_client_test.c | 49 ++++++++++++++++------------- 5 files changed, 117 insertions(+), 24 deletions(-) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/sql/field.cc b/sql/field.cc index 152c1bdc364..763448202ae 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1282,15 +1282,25 @@ void Field_num::add_zerofill_and_unsigned(String &res) const void Field::make_field(Send_field *field) { - if (orig_table->s->table_cache_key && *(orig_table->s->table_cache_key)) + if (orig_table && orig_table->s->table_cache_key && + *(orig_table->s->table_cache_key)) { field->org_table_name= orig_table->s->table_name; field->db_name= orig_table->s->table_cache_key; } else field->org_table_name= field->db_name= ""; - field->table_name= orig_table->alias; - field->col_name= field->org_col_name= field_name; + if (orig_table) + { + field->table_name= orig_table->alias; + field->org_col_name= field_name; + } + else + { + field->table_name= ""; + field->org_col_name= ""; + } + field->col_name= field_name; field->charsetnr= charset()->number; field->length=field_length; field->type=type(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 08780efbedb..cc6184c6206 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14119,6 +14119,9 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, item_field= (Item*) new Item_field(field); if (!item_field) DBUG_RETURN(TRUE); // Fatal error + + if (item->real_item()->type() != Item::FIELD_ITEM) + field->orig_table= 0; item_field->name= item->name; #ifndef DBUG_OFF if (_db_on_ && !item_field->name) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index d64ec08a71d..3e50e1ede84 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -15486,7 +15486,7 @@ static void test_bug21635() char *query_end; MYSQL_RES *result; MYSQL_FIELD *field; - unsigned int field_count, i; + unsigned int field_count, i, j; int rc; DBUG_ENTER("test_bug21635"); @@ -15502,28 +15502,35 @@ static void test_bug21635() myquery(rc); rc= mysql_query(mysql, "CREATE TABLE t1 (i INT)"); myquery(rc); - rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); - myquery(rc); - - rc= mysql_real_query(mysql, query, query_end - query); - myquery(rc); - - result= mysql_use_result(mysql); - DIE_UNLESS(result); - - field_count= mysql_field_count(mysql); - for (i= 0; i < field_count; ++i) + /* + We need this loop to ensure correct behavior with both constant and + non-constant tables. + */ + for (j= 0; j < 2 ; j++) { - field= mysql_fetch_field_direct(result, i); - printf("%s -> %s ... ", expr[i * 2], field->name); - fflush(stdout); - DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 && - field->table[0] == 0 && field->org_name[0] == 0); - DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0); - puts("OK"); - } + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + myquery(rc); - mysql_free_result(result); + rc= mysql_real_query(mysql, query, query_end - query); + myquery(rc); + + result= mysql_use_result(mysql); + DIE_UNLESS(result); + + field_count= mysql_field_count(mysql); + for (i= 0; i < field_count; ++i) + { + field= mysql_fetch_field_direct(result, i); + printf("%s -> %s ... ", expr[i * 2], field->name); + fflush(stdout); + DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 && + field->table[0] == 0 && field->org_name[0] == 0); + DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0); + puts("OK"); + } + + mysql_free_result(result); + } rc= mysql_query(mysql, "DROP TABLE t1"); myquery(rc); From c6a4e65a408f6d0b8b42051a3bb2fbfc83b3619c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 29 Sep 2007 01:07:29 +0000 Subject: [PATCH 12/29] view_grant.result, view_grant.test: Corrected test case for the bug#29908. mysql-test/t/view_grant.test: Corrected test case for the bug#29908. mysql-test/r/view_grant.result: Corrected test case for the bug#29908. --- mysql-test/r/view_grant.result | 19 ++++++++++--------- mysql-test/t/view_grant.test | 5 +++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/view_grant.result b/mysql-test/r/view_grant.result index ab408e6f175..eef61c65fb8 100644 --- a/mysql-test/r/view_grant.result +++ b/mysql-test/r/view_grant.result @@ -806,25 +806,26 @@ GRANT SELECT ON mysqltest_29908.t1 TO u29908_2@localhost; ALTER VIEW v1 AS SELECT f2 FROM t1; ERROR 42000: Access denied; you need the SUPER privilege for this operation ALTER VIEW v2 AS SELECT f2 FROM t1; +ERROR 42000: Access denied; you need the SUPER privilege for this operation SHOW CREATE VIEW v2; View Create View -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f2` AS `f2` from `t1` +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f1` AS `f1` from `t1` ALTER VIEW v1 AS SELECT f2 FROM t1; SHOW CREATE VIEW v1; View Create View v1 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f2` AS `f2` from `t1` -ALTER VIEW v2 AS SELECT f1 FROM t1; -SHOW CREATE VIEW v2; -View Create View -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f1` AS `f1` from `t1` -ALTER VIEW v1 AS SELECT f1 FROM t1; -SHOW CREATE VIEW v1; -View Create View -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f1` AS `f1` from `t1` ALTER VIEW v2 AS SELECT f2 FROM t1; SHOW CREATE VIEW v2; View Create View v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f2` AS `f2` from `t1` +ALTER VIEW v1 AS SELECT f1 FROM t1; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f1` AS `f1` from `t1` +ALTER VIEW v2 AS SELECT f1 FROM t1; +SHOW CREATE VIEW v2; +View Create View +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f1` AS `f1` from `t1` DROP USER u29908_1@localhost; DROP USER u29908_2@localhost; DROP DATABASE mysqltest_29908; diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test index 0cad3857dcd..7f9eb4e1cff 100644 --- a/mysql-test/t/view_grant.test +++ b/mysql-test/t/view_grant.test @@ -1070,19 +1070,20 @@ GRANT SELECT ON mysqltest_29908.t1 TO u29908_2@localhost; connect (u2,localhost,u29908_2,,mysqltest_29908); --error ER_SPECIFIC_ACCESS_DENIED_ERROR ALTER VIEW v1 AS SELECT f2 FROM t1; +--error ER_SPECIFIC_ACCESS_DENIED_ERROR ALTER VIEW v2 AS SELECT f2 FROM t1; SHOW CREATE VIEW v2; connect (u1,localhost,u29908_1,,mysqltest_29908); ALTER VIEW v1 AS SELECT f2 FROM t1; SHOW CREATE VIEW v1; -ALTER VIEW v2 AS SELECT f1 FROM t1; +ALTER VIEW v2 AS SELECT f2 FROM t1; SHOW CREATE VIEW v2; connection root; ALTER VIEW v1 AS SELECT f1 FROM t1; SHOW CREATE VIEW v1; -ALTER VIEW v2 AS SELECT f2 FROM t1; +ALTER VIEW v2 AS SELECT f1 FROM t1; SHOW CREATE VIEW v2; DROP USER u29908_1@localhost; From fb05833eac1c1adf0d4eedd0a000e4e9759d5c18 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Oct 2007 11:32:29 +0300 Subject: [PATCH 13/29] fixed pb problem with the fix for bug 30587 --- mysql-test/r/func_math.result | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 5ef528812e5..d294de93cd8 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -326,24 +326,24 @@ CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1)); INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0); SELECT a DIV 900 y FROM t1 GROUP BY y; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y y 8 19 11 Y 32800 0 63 +def y 8 19 11 Y 32800 0 63 y 22201025555 22255916666 SELECT DISTINCT a DIV 900 y FROM t1; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y y 8 19 11 Y 32800 0 63 +def y 8 19 11 Y 32800 0 63 y 22201025555 22255916666 SELECT b DIV 900 y FROM t1 GROUP BY y; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y y 8 20 1 Y 32768 0 63 +def y 8 20 1 Y 32768 0 63 y 0 SELECT c DIV 900 y FROM t1 GROUP BY y; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y y 3 1 1 Y 32800 0 63 +def y 3 1 1 Y 32800 0 63 y 0 DROP TABLE t1; From 0ad23eb8a5f377e94d4b4ae83f39555dbe75c3b0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Oct 2007 12:51:59 +0300 Subject: [PATCH 14/29] removed undeterministic test result from the fux for bug 30587 --- mysql-test/r/func_math.result | 8 -------- mysql-test/t/func_math.test | 2 -- 2 files changed, 10 deletions(-) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index d294de93cd8..150b6003dbe 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -325,25 +325,17 @@ pow(cast(-2 as unsigned), 5) pow(18446744073709551614, 5) pow(-2, 5) CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1)); INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0); SELECT a DIV 900 y FROM t1 GROUP BY y; -Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y 8 19 11 Y 32800 0 63 y 22201025555 22255916666 SELECT DISTINCT a DIV 900 y FROM t1; -Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y 8 19 11 Y 32800 0 63 y 22201025555 22255916666 SELECT b DIV 900 y FROM t1 GROUP BY y; -Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y 8 20 1 Y 32768 0 63 y 0 SELECT c DIV 900 y FROM t1 GROUP BY y; -Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def y 3 1 1 Y 32800 0 63 y 0 DROP TABLE t1; diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index 1f46415741f..9f12fdd696e 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -211,12 +211,10 @@ select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5); CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1)); INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0); ---enable_metadata SELECT a DIV 900 y FROM t1 GROUP BY y; SELECT DISTINCT a DIV 900 y FROM t1; SELECT b DIV 900 y FROM t1 GROUP BY y; SELECT c DIV 900 y FROM t1 GROUP BY y; ---disable_metadata DROP TABLE t1; CREATE TABLE t1(a LONGBLOB); From 02bb72c735a8df3d258f5752832a03d58ee051c0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Oct 2007 20:35:51 +0500 Subject: [PATCH 15/29] Fixed bug #31077. mysqldump adds the "-- Dump completed on YYYY-MM-DD hh:mm:ss" string to the end of output if the --comments switch is on. The only way to suppress this line is to use --skip-comments/--compact switch. New switch has been added to the mysqldump client command line: --dump-date. For the compatibility with previous releases, by default the --dump-date is on. The --dump-date switch forces mysqldump to add date to the "-- Dump completed on ..." string at the end of output. The --skip-dump-date switch supresses the output of date string and uses short form of that commentary: "-- Dump completed". --skip-comments or --compact switches disable the whole commentary as usual. client/client_priv.h: Fixed bug #31077. New OPT_DUMP_DATE option has been added to implement the mysqldump client --dump-date switch. client/mysqldump.c: Fixed bug #31077. The opt_dump_date variable has been added to imlements the mysqldump cliemt --dump-date switch. By default this switch is on (for compatibility with previous releases). The --dump-date switch forces mysqldump to add date to the "-- Dump completed on ..." string at the end of output. The --skip-dump-date switch supresses the output of date string and uses short form of that commentary: "-- Dump completed". --skip-comments or --compact switches disable the whole commentary as usual. mysql-test/t/mysqldump.test: Added test case for bug #31077. mysql-test/r/mysqldump.result: Added test case for bug #31077. --- client/client_priv.h | 2 +- client/mysqldump.c | 18 +++++++++++++----- mysql-test/r/mysqldump.result | 10 ++++++++++ mysql-test/t/mysqldump.test | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/client/client_priv.h b/client/client_priv.h index 418bf86f2c8..8f509fa0763 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -51,5 +51,5 @@ enum options_client OPT_TRIGGERS, OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE, OPT_TZ_UTC, OPT_AUTO_CLOSE, OPT_SSL_VERIFY_SERVER_CERT, - OPT_DEBUG_INFO, OPT_ERROR_LOG_FILE + OPT_DEBUG_INFO, OPT_ERROR_LOG_FILE, OPT_DUMP_DATE }; diff --git a/client/mysqldump.c b/client/mysqldump.c index cc8458c7a8e..fb28647a120 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -89,7 +89,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0, opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0, opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0, - opt_set_charset=0, + opt_set_charset=0, opt_dump_date=1, opt_autocommit=0,opt_disable_keys=1,opt_xml=0, opt_delete_master_logs=0, tty_password=0, opt_single_transaction=0, opt_comments= 0, opt_compact= 0, @@ -402,6 +402,9 @@ static struct my_option my_long_options[] = "automatically turns off --lock-tables.", (gptr*) &opt_single_transaction, (gptr*) &opt_single_transaction, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.", + (gptr*) &opt_dump_date, (gptr*) &opt_dump_date, 0, + GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, {"skip-opt", OPT_SKIP_OPTIMIZATION, "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -623,10 +626,15 @@ static void write_footer(FILE *sql_file) fputs("\n", sql_file); if (opt_comments) { - char time_str[20]; - get_date(time_str, GETDATE_DATE_TIME, 0); - fprintf(sql_file, "-- Dump completed on %s\n", - time_str); + if (opt_dump_date) + { + char time_str[20]; + get_date(time_str, GETDATE_DATE_TIME, 0); + fprintf(sql_file, "-- Dump completed on %s\n", + time_str); + } + else + fprintf(sql_file, "-- Dump completed"); } check_io(sql_file); } diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 42c437857b7..06bbab3285e 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -3544,5 +3544,15 @@ c1 2 DROP TABLE t1,t2; # +# Bug#29815: new option for suppressing last line of mysqldump: +# "Dump completed on" +# +# --skip-dump-date: +-- Dump completed +# --dump-date: +-- Dump completed on -- :: +# --dump-date (default): +-- Dump completed on -- :: +# # End of 5.0 tests # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 3c62577e781..5eb5370f779 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1576,6 +1576,20 @@ SELECT * FROM t2; DROP TABLE t1,t2; +--echo # +--echo # Bug#29815: new option for suppressing last line of mysqldump: +--echo # "Dump completed on" +--echo # + +--echo # --skip-dump-date: +--exec $MYSQL_DUMP --skip-dump-date test | grep 'Dump completed' + +--echo # --dump-date: +--exec $MYSQL_DUMP --dump-date test | grep 'Dump completed' | tr -d '[0-9]' + +--echo # --dump-date (default): +--exec $MYSQL_DUMP test | grep 'Dump completed' | tr -d '[0-9]' + --echo # --echo # End of 5.0 tests --echo # From 1a4df8a24dff9411484717f7a41314d85f8b3425 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Oct 2007 20:03:50 +0000 Subject: [PATCH 16/29] Bug#31095: Unexpected NULL constant caused server crash. The Item_func_rollup_const class is used for wrapping constants to avoid wrong result for ROLLUP queries with DISTINCT and a constant in the select list. This class is also used to wrap up a NULL constant but its null_value wasn't set accordingly. This led to a server crash. Now the null_value of an object of the Item_func_rollup_const class is set by its fix_length_and_dec member function. mysql-test/t/olap.test: Added a test case for the bug#31095: Unexpected NULL constant caused server crash. mysql-test/r/olap.result: Added a test case for the bug#31095: Unexpected NULL constant caused server crash. sql/item_func.h: Bug#31095: Unexpected NULL constant caused server crash. Now the null_value of an object of the Item_func_rollup_const class is set by its fix_length_and_dec member function. --- mysql-test/r/olap.result | 11 +++++++++++ mysql-test/t/olap.test | 9 +++++++++ sql/item_func.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result index 4a54b17316d..a1d66b11f58 100644 --- a/mysql-test/r/olap.result +++ b/mysql-test/r/olap.result @@ -715,3 +715,14 @@ a SUM(a) 4 4 NULL 14 DROP TABLE t1; +# +# Bug#31095: Unexpected NULL constant caused server crash. +# +create table t1(a int); +insert into t1 values (1),(2),(3); +select count(a) from t1 group by null with rollup; +count(a) +3 +3 +drop table t1; +############################################################## diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index 05934bff492..1ac99d9c39f 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -358,3 +358,12 @@ SELECT * FROM (SELECT a, SUM(a) FROM t1 GROUP BY a WITH ROLLUP) as t; DROP TABLE t1; +--echo # +--echo # Bug#31095: Unexpected NULL constant caused server crash. +--echo # +create table t1(a int); +insert into t1 values (1),(2),(3); +select count(a) from t1 group by null with rollup; +drop table t1; +--echo ############################################################## + diff --git a/sql/item_func.h b/sql/item_func.h index 57e33daf0c4..87c9e016df2 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -749,6 +749,8 @@ public: collation= args[0]->collation; max_length= args[0]->max_length; decimals=args[0]->decimals; + /* The item could be a NULL constant. */ + null_value= args[0]->null_value; } }; From 37beea410ca2db082ae8f6b454490d063372c0d2 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Oct 2007 15:36:07 +0300 Subject: [PATCH 17/29] Fixed a valgrind warning with the fix for bug 28702. --- sql/sql_select.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 699c0be4c5b..e5c0b994ecb 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -15493,6 +15493,7 @@ TABLE_LIST::print_index_hint(THD *thd, String *str, List_iterator_fast li(indexes); String *idx; bool first= 1; + int find_length= strlen(primary_key_name); str->append (' '); str->append (hint, hint_length); @@ -15503,8 +15504,15 @@ TABLE_LIST::print_index_hint(THD *thd, String *str, first= 0; else str->append(','); - if (!my_strcasecmp (system_charset_info, idx->c_ptr_safe(), - primary_key_name)) + /* + It's safe to use ptr() here because we compare the length first + and we rely that my_strcasecmp will not access more than length() + chars from the string. See test_if_string_in_list() for similar + implementation. + */ + if (find_length == idx->length() && + !my_strcasecmp (system_charset_info, primary_key_name, + idx->ptr())) str->append(primary_key_name); else append_identifier (thd, str, idx->ptr(), idx->length()); From fd76cce346a984f96fac11a65d0d7d7af67a659f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Oct 2007 17:45:49 +0300 Subject: [PATCH 18/29] fixed a warning in the fix for bug 28702 --- sql/sql_select.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e5c0b994ecb..3529de1c28a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -15493,7 +15493,7 @@ TABLE_LIST::print_index_hint(THD *thd, String *str, List_iterator_fast li(indexes); String *idx; bool first= 1; - int find_length= strlen(primary_key_name); + size_t find_length= strlen(primary_key_name); str->append (' '); str->append (hint, hint_length); From 853e4da88fec45edbc065371a16c7a80247a98cd Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Oct 2007 02:50:38 +0500 Subject: [PATCH 19/29] mysqldump.c, mysqldump.test, mysqldump.result: Bug #31077: post-commit fix. client/mysqldump.c: Bug #31077: post-commit fix. mysql-test/t/mysqldump.test: Bug #31077: post-commit fix. mysql-test/r/mysqldump.result: Bug #31077: post-commit fix. --- client/mysqldump.c | 2 +- mysql-test/r/mysqldump.result | 16 ++++++++++++++-- mysql-test/t/mysqldump.test | 9 ++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index fb28647a120..cc7b7689169 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -634,7 +634,7 @@ static void write_footer(FILE *sql_file) time_str); } else - fprintf(sql_file, "-- Dump completed"); + fprintf(sql_file, "-- Dump completed\n"); } check_io(sql_file); } diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 06bbab3285e..e49d3070e9a 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -3548,11 +3548,23 @@ DROP TABLE t1,t2; # "Dump completed on" # # --skip-dump-date: +-- + + + -- Dump completed # --dump-date: --- Dump completed on -- :: +-- + + + +-- Dump completed on x-x-x x:x:x # --dump-date (default): --- Dump completed on -- :: +-- + + + +-- Dump completed on x-x-x x:x:x # # End of 5.0 tests # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 5eb5370f779..cecb3ecf3a4 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1582,13 +1582,16 @@ DROP TABLE t1,t2; --echo # --echo # --skip-dump-date: ---exec $MYSQL_DUMP --skip-dump-date test | grep 'Dump completed' +--replace_regex /-- [^D][^u][^m][^p].*// /\/\*!.*// +--exec $MYSQL_DUMP --skip-dump-date test --echo # --dump-date: ---exec $MYSQL_DUMP --dump-date test | grep 'Dump completed' | tr -d '[0-9]' +--replace_regex /-- [^D][^u][^m][^p].*// /\/\*!.*// /[0-9]+/x/ +--exec $MYSQL_DUMP --dump-date test --echo # --dump-date (default): ---exec $MYSQL_DUMP test | grep 'Dump completed' | tr -d '[0-9]' +--replace_regex /-- [^D][^u][^m][^p].*// /\/\*!.*// /[0-9]+/x/ +--exec $MYSQL_DUMP test --echo # --echo # End of 5.0 tests From b802af43cb606df0b3db593a20a7a71ec600ea86 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Oct 2007 11:36:42 +0500 Subject: [PATCH 20/29] mysqldump.test, mysqldump.result: Bug #31077: post-commit fix. mysql-test/t/mysqldump.test: Bug #31077: post-commit fix. mysql-test/r/mysqldump.result: Bug #31077: post-commit fix. --- mysql-test/r/mysqldump.result | 4 ++-- mysql-test/t/mysqldump.test | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index e49d3070e9a..ca0aa399a56 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -3558,13 +3558,13 @@ DROP TABLE t1,t2; --- Dump completed on x-x-x x:x:x +-- Dump completed on DATE # --dump-date (default): -- --- Dump completed on x-x-x x:x:x +-- Dump completed on DATE # # End of 5.0 tests # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index cecb3ecf3a4..6dba0a590d0 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1586,11 +1586,11 @@ DROP TABLE t1,t2; --exec $MYSQL_DUMP --skip-dump-date test --echo # --dump-date: ---replace_regex /-- [^D][^u][^m][^p].*// /\/\*!.*// /[0-9]+/x/ +--replace_regex /-- [^D][^u][^m][^p].*// /\/\*!.*// / on [0-9 :-]+/ on DATE/ --exec $MYSQL_DUMP --dump-date test --echo # --dump-date (default): ---replace_regex /-- [^D][^u][^m][^p].*// /\/\*!.*// /[0-9]+/x/ +--replace_regex /-- [^D][^u][^m][^p].*// /\/\*!.*// / on [0-9 :-]+/ on DATE/ --exec $MYSQL_DUMP test --echo # From ae3d4bfc0e5dc8c88ce93496bf01018ea2b298bf Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Oct 2007 13:35:35 +0500 Subject: [PATCH 21/29] Bug #30955 geomfromtext() crasher. end-of-line check missed in Gis_read_stream::get_next_word, what can lead to crashes (expecially with NULL strings). End-of-line check added sql/gstream.cc: Bug #30955 geomfromtext() crasher mysql-test/r/gis.result: Bug #30955 geomfromtext() crasher. test result mysql-test/t/gis.test: Bug #30955 geomfromtext() crasher. test case --- mysql-test/r/gis.result | 6 ++++++ mysql-test/t/gis.test | 8 ++++++++ sql/gstream.cc | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result index 643a3d6b434..55f70e59fcf 100644 --- a/mysql-test/r/gis.result +++ b/mysql-test/r/gis.result @@ -724,4 +724,10 @@ SELECT * FROM t1; a NULL DROP TABLE t1; +CREATE TABLE `t1` ( `col9` set('a'), `col89` date); +INSERT INTO `t1` VALUES ('','0000-00-00'); +select geomfromtext(col9,col89) as a from t1; +a +NULL +DROP TABLE t1; End of 4.1 tests diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index 7182e040d46..cf5c3b31bc1 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -419,4 +419,12 @@ INSERT INTO t1 VALUES (NULL); SELECT * FROM t1; DROP TABLE t1; +# +# Bug #30955 geomfromtext() crasher +# +CREATE TABLE `t1` ( `col9` set('a'), `col89` date); +INSERT INTO `t1` VALUES ('','0000-00-00'); +select geomfromtext(col9,col89) as a from t1; +DROP TABLE t1; + --echo End of 4.1 tests diff --git a/sql/gstream.cc b/sql/gstream.cc index f7d11d76b0c..f986d9dc7f3 100644 --- a/sql/gstream.cc +++ b/sql/gstream.cc @@ -45,7 +45,7 @@ bool Gis_read_stream::get_next_word(LEX_STRING *res) skip_space(); res->str= (char*) m_cur; /* The following will also test for \0 */ - if (!my_isvar_start(&my_charset_bin, *m_cur)) + if ((m_cur >= m_limit) || !my_isvar_start(&my_charset_bin, *m_cur)) return 1; /* From f8f021fd6ba2f654b9b6a3731bc9fea84885687c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Oct 2007 09:15:26 +0200 Subject: [PATCH 22/29] Bug #30942: select str_to_date from derived table returns varying results The function str_to_date has a field to say whether it's invoked constant arguments. But this member was not initialized, causing the function to think that it could use a cache of the format type when said cache was in fact not initialized. Fixed by initializing the field to false. mysql-test/r/type_date.result: Bug#30942: Test result mysql-test/t/type_date.test: Bug#30942: Test case sql/item_timefunc.h: Bug#30942: Initialized const_item to false --- mysql-test/r/type_date.result | 10 ++++++++++ mysql-test/t/type_date.test | 13 +++++++++++++ sql/item_timefunc.h | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result index 9f51fc0371c..53fe9710eba 100644 --- a/mysql-test/r/type_date.result +++ b/mysql-test/r/type_date.result @@ -136,3 +136,13 @@ d dt ts 0000-00-00 0000-00-00 00:00:00 0000-00-00 00:00:00 2001-11-11 2001-11-11 00:00:00 2001-11-11 00:00:00 drop table t1; +CREATE TABLE t1 ( +a INT +); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (NULL); +SELECT str_to_date( '', a ) FROM t1; +str_to_date( '', a ) +0000-00-00 00:00:00 +NULL +DROP TABLE t1; diff --git a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test index 02cd07e3c16..aeb88f3acc2 100644 --- a/mysql-test/t/type_date.test +++ b/mysql-test/t/type_date.test @@ -136,3 +136,16 @@ insert into t1 values (9912101,9912101,9912101); insert into t1 values (11111,11111,11111); select * from t1; drop table t1; + +# +# Bug #30942: select str_to_date from derived table returns varying results +# +CREATE TABLE t1 ( + a INT +); + +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (NULL); + +SELECT str_to_date( '', a ) FROM t1; +DROP TABLE t1; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 8e925a0156f..cb69bd200e6 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -1030,7 +1030,7 @@ class Item_func_str_to_date :public Item_str_func bool const_item; public: Item_func_str_to_date(Item *a, Item *b) - :Item_str_func(a, b) + :Item_str_func(a, b), const_item(false) {} String *val_str(String *str); bool get_date(MYSQL_TIME *ltime, uint fuzzy_date); From 4ae273e3955ebb166d4f016b1b6d9e0d3de4aa83 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Oct 2007 16:20:56 +0500 Subject: [PATCH 23/29] Bug#30079 A check for "hidden" I_S tables is flawed added check for hidden I_S tables for 'show columns|keys' commands mysql-test/r/information_schema.result: test result mysql-test/t/information_schema.test: test case sql/sql_parse.cc: added check for hidden I_S tables for 'show columns|keys' commands --- mysql-test/r/information_schema.result | 4 ++++ mysql-test/t/information_schema.test | 9 +++++++++ sql/sql_parse.cc | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index cf82cdd31bd..8c1a1e67443 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1386,3 +1386,7 @@ f7 datetime NO NULL f8 datetime YES 2006-01-01 00:00:00 drop table t1; End of 5.0 tests. +show fields from information_schema.TABLE_NAMES; +ERROR 42S02: Unknown table 'TABLE_NAMES' in information_schema +show keys from information_schema.TABLE_NAMES; +ERROR 42S02: Unknown table 'TABLE_NAMES' in information_schema diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index e9a06c7186e..684deef120e 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1089,3 +1089,12 @@ show columns from t1; drop table t1; --echo End of 5.0 tests. + +# +# Bug#30079 A check for "hidden" I_S tables is flawed +# +--error 1109 +show fields from information_schema.TABLE_NAMES; +--error 1109 +show keys from information_schema.TABLE_NAMES; + diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 084bcfc3c76..52f8fe8615f 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6427,7 +6427,12 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->table_name); if (!schema_table || (schema_table->hidden && - lex->orig_sql_command == SQLCOM_END)) // not a 'show' command + (lex->orig_sql_command == SQLCOM_END || // not a 'show' command + /* + this check is used for show columns|keys from I_S hidden table + */ + lex->orig_sql_command == SQLCOM_SHOW_FIELDS || + lex->orig_sql_command == SQLCOM_SHOW_KEYS))) { my_error(ER_UNKNOWN_TABLE, MYF(0), ptr->table_name, INFORMATION_SCHEMA_NAME.str); From 554d405d73c5618b0dbca4e118a8739932a3a39f Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Oct 2007 12:29:02 +0500 Subject: [PATCH 24/29] test fix(to satisfy WIN) mysql-test/r/information_schema.result: result fix --- mysql-test/r/information_schema.result | 8 ++++---- mysql-test/t/information_schema.test | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 8c1a1e67443..0c6a1855072 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1386,7 +1386,7 @@ f7 datetime NO NULL f8 datetime YES 2006-01-01 00:00:00 drop table t1; End of 5.0 tests. -show fields from information_schema.TABLE_NAMES; -ERROR 42S02: Unknown table 'TABLE_NAMES' in information_schema -show keys from information_schema.TABLE_NAMES; -ERROR 42S02: Unknown table 'TABLE_NAMES' in information_schema +show fields from information_schema.table_names; +ERROR 42S02: Unknown table 'table_names' in information_schema +show keys from information_schema.table_names; +ERROR 42S02: Unknown table 'table_names' in information_schema diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 684deef120e..04ffd30ec62 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1094,7 +1094,7 @@ drop table t1; # Bug#30079 A check for "hidden" I_S tables is flawed # --error 1109 -show fields from information_schema.TABLE_NAMES; +show fields from information_schema.table_names; --error 1109 -show keys from information_schema.TABLE_NAMES; +show keys from information_schema.table_names; From 6d54b5771bf3cce3e5a5e8ca295219fdbae80c00 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Oct 2007 15:40:32 +0500 Subject: [PATCH 25/29] Bug #30286 spatial index cause corruption and server crash! As the result of DOUBLE claculations can be bigger than DBL_MAX constant we use in code, we shouldn't use this constatn as a biggest possible value. Particularly the rtree_pick_key function set 'min_area= DBL_MAX' relying that any rtree_area_increase result will be less so we return valid key. Though in rtree_area_increase function we calculate the area of the rectangle, so the result can be 'inf' if the rectangle is huge enough, which is bigger than DBL_MAX. Code of the rtree_pick_key modified so we always return a valid key. myisam/rt_index.c: Bug #30286 spatial index cause corruption and server crash! always set the best_key with the first key we get, so we always return somthing valid. myisam/rt_mbr.c: Bug #30286 spatial index cause corruption and server crash! function comment extended mysql-test/r/gis-rtree.result: Bug #30286 spatial index cause corruption and server crash! test result mysql-test/t/gis-rtree.test: Bug #30286 spatial index cause corruption and server crash! test case --- myisam/rt_index.c | 18 +++++------------- myisam/rt_mbr.c | 5 ++++- mysql-test/r/gis-rtree.result | 31 ++++++++++++++++++++++++++++++ mysql-test/t/gis-rtree.test | 36 +++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 14 deletions(-) diff --git a/myisam/rt_index.c b/myisam/rt_index.c index 238432006a4..f19ecacef63 100644 --- a/myisam/rt_index.c +++ b/myisam/rt_index.c @@ -485,15 +485,16 @@ static uchar *rtree_pick_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, uint key_length, uchar *page_buf, uint nod_flag) { double increase; - double best_incr = DBL_MAX; + double best_incr; double area; double best_area; - uchar *best_key; + uchar *best_key= NULL; uchar *k = rt_PAGE_FIRST_KEY(page_buf, nod_flag); uchar *last = rt_PAGE_END(page_buf); LINT_INIT(best_area); LINT_INIT(best_key); + LINT_INIT(best_incr); for (; k < last; k = rt_PAGE_NEXT_KEY(k, key_length, nod_flag)) { @@ -502,22 +503,13 @@ static uchar *rtree_pick_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, &area)) == -1.0) return NULL; /* The following should be safe, even if we compare doubles */ - if (increase < best_incr) + if (!best_key || increase < best_incr || + ((increase == best_incr) && (area < best_area))) { best_key = k; best_area = area; best_incr = increase; } - else - { - /* The following should be safe, even if we compare doubles */ - if ((increase == best_incr) && (area < best_area)) - { - best_key = k; - best_area = area; - best_incr = increase; - } - } } return best_key; } diff --git a/myisam/rt_mbr.c b/myisam/rt_mbr.c index 897862c1c9a..31eaac0ae70 100644 --- a/myisam/rt_mbr.c +++ b/myisam/rt_mbr.c @@ -525,7 +525,10 @@ double rtree_overlapping_area(HA_KEYSEG *keyseg, uchar* a, uchar* b, } /* -Calculates MBR_AREA(a+b) - MBR_AREA(a) + Calculates MBR_AREA(a+b) - MBR_AREA(a) + Note: when 'a' and 'b' objects are far from each other, + the area increase can be really big, so this function + can return 'inf' as a result. */ double rtree_area_increase(HA_KEYSEG *keyseg, uchar* a, uchar* b, uint key_length, double *ab_area) diff --git a/mysql-test/r/gis-rtree.result b/mysql-test/r/gis-rtree.result index 762dda4e501..3df316acd77 100644 --- a/mysql-test/r/gis-rtree.result +++ b/mysql-test/r/gis-rtree.result @@ -1420,3 +1420,34 @@ CHECK TABLE t1 EXTENDED; Table Op Msg_type Msg_text test.t1 check status OK DROP TABLE t1; +create table t1 (a geometry not null, spatial index(a)); +insert into t1 values (PointFromWKB(POINT(1.1517219314031e+164, 131072))); +insert into t1 values (PointFromWKB(POINT(9.1248812352444e+192, 2.9740338169556e+284))); +insert into t1 values (PointFromWKB(POINT(4.7783097267365e-299, -0))); +insert into t1 values (PointFromWKB(POINT(1.49166814624e-154, 2.0880974297595e-53))); +insert into t1 values (PointFromWKB(POINT(4.0917382598702e+149, 1.2024538023802e+111))); +insert into t1 values (PointFromWKB(POINT(2.0349165139404e+236, 2.9993936277913e-241))); +insert into t1 values (PointFromWKB(POINT(2.5243548967072e-29, 1.2024538023802e+111))); +insert into t1 values (PointFromWKB(POINT(0, 6.9835074892995e-251))); +insert into t1 values (PointFromWKB(POINT(2.0880974297595e-53, 3.1050361846014e+231))); +insert into t1 values (PointFromWKB(POINT(2.8728483499323e-188, 2.4600631144627e+260))); +insert into t1 values (PointFromWKB(POINT(3.0517578125e-05, 2.0349165139404e+236))); +insert into t1 values (PointFromWKB(POINT(1.1517219314031e+164, 1.1818212630766e-125))); +insert into t1 values (PointFromWKB(POINT(2.481040258324e-265, 5.7766220027675e-275))); +insert into t1 values (PointFromWKB(POINT(2.0880974297595e-53, 2.5243548967072e-29))); +insert into t1 values (PointFromWKB(POINT(5.7766220027675e-275, 9.9464647281957e+86))); +insert into t1 values (PointFromWKB(POINT(2.2181357552967e+130, 3.7857669957337e-270))); +insert into t1 values (PointFromWKB(POINT(4.5767114681874e-246, 3.6893488147419e+19))); +insert into t1 values (PointFromWKB(POINT(4.5767114681874e-246, 3.7537584144024e+255))); +insert into t1 values (PointFromWKB(POINT(3.7857669957337e-270, 1.8033161362863e-130))); +insert into t1 values (PointFromWKB(POINT(0, 5.8774717541114e-39))); +insert into t1 values (PointFromWKB(POINT(1.1517219314031e+164, 2.2761049594727e-159))); +insert into t1 values (PointFromWKB(POINT(6.243497100632e+144, 3.7857669957337e-270))); +insert into t1 values (PointFromWKB(POINT(3.7857669957337e-270, 2.6355494858076e-82))); +insert into t1 values (PointFromWKB(POINT(2.0349165139404e+236, 3.8518598887745e-34))); +insert into t1 values (PointFromWKB(POINT(4.6566128730774e-10, 2.0880974297595e-53))); +insert into t1 values (PointFromWKB(POINT(2.0880974297595e-53, 1.8827498946116e-183))); +insert into t1 values (PointFromWKB(POINT(1.8033161362863e-130, 9.1248812352444e+192))); +insert into t1 values (PointFromWKB(POINT(4.7783097267365e-299, 2.2761049594727e-159))); +insert into t1 values (PointFromWKB(POINT(1.94906280228e+289, 1.2338789709327e-178))); +drop table t1; diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test index f28a718cc11..b7d0f797e37 100644 --- a/mysql-test/t/gis-rtree.test +++ b/mysql-test/t/gis-rtree.test @@ -798,4 +798,40 @@ UPDATE t1 set spatial_point=GeomFromText('POINT(41 46)') where c1 like 'f%'; CHECK TABLE t1 EXTENDED; DROP TABLE t1; +# +# Bug #30286 spatial index cause corruption and server crash! +# + +create table t1 (a geometry not null, spatial index(a)); +insert into t1 values (PointFromWKB(POINT(1.1517219314031e+164, 131072))); +insert into t1 values (PointFromWKB(POINT(9.1248812352444e+192, 2.9740338169556e+284))); +insert into t1 values (PointFromWKB(POINT(4.7783097267365e-299, -0))); +insert into t1 values (PointFromWKB(POINT(1.49166814624e-154, 2.0880974297595e-53))); +insert into t1 values (PointFromWKB(POINT(4.0917382598702e+149, 1.2024538023802e+111))); +insert into t1 values (PointFromWKB(POINT(2.0349165139404e+236, 2.9993936277913e-241))); +insert into t1 values (PointFromWKB(POINT(2.5243548967072e-29, 1.2024538023802e+111))); +insert into t1 values (PointFromWKB(POINT(0, 6.9835074892995e-251))); +insert into t1 values (PointFromWKB(POINT(2.0880974297595e-53, 3.1050361846014e+231))); +insert into t1 values (PointFromWKB(POINT(2.8728483499323e-188, 2.4600631144627e+260))); +insert into t1 values (PointFromWKB(POINT(3.0517578125e-05, 2.0349165139404e+236))); +insert into t1 values (PointFromWKB(POINT(1.1517219314031e+164, 1.1818212630766e-125))); +insert into t1 values (PointFromWKB(POINT(2.481040258324e-265, 5.7766220027675e-275))); +insert into t1 values (PointFromWKB(POINT(2.0880974297595e-53, 2.5243548967072e-29))); +insert into t1 values (PointFromWKB(POINT(5.7766220027675e-275, 9.9464647281957e+86))); +insert into t1 values (PointFromWKB(POINT(2.2181357552967e+130, 3.7857669957337e-270))); +insert into t1 values (PointFromWKB(POINT(4.5767114681874e-246, 3.6893488147419e+19))); +insert into t1 values (PointFromWKB(POINT(4.5767114681874e-246, 3.7537584144024e+255))); +insert into t1 values (PointFromWKB(POINT(3.7857669957337e-270, 1.8033161362863e-130))); +insert into t1 values (PointFromWKB(POINT(0, 5.8774717541114e-39))); +insert into t1 values (PointFromWKB(POINT(1.1517219314031e+164, 2.2761049594727e-159))); +insert into t1 values (PointFromWKB(POINT(6.243497100632e+144, 3.7857669957337e-270))); +insert into t1 values (PointFromWKB(POINT(3.7857669957337e-270, 2.6355494858076e-82))); +insert into t1 values (PointFromWKB(POINT(2.0349165139404e+236, 3.8518598887745e-34))); +insert into t1 values (PointFromWKB(POINT(4.6566128730774e-10, 2.0880974297595e-53))); +insert into t1 values (PointFromWKB(POINT(2.0880974297595e-53, 1.8827498946116e-183))); +insert into t1 values (PointFromWKB(POINT(1.8033161362863e-130, 9.1248812352444e+192))); +insert into t1 values (PointFromWKB(POINT(4.7783097267365e-299, 2.2761049594727e-159))); +insert into t1 values (PointFromWKB(POINT(1.94906280228e+289, 1.2338789709327e-178))); +drop table t1; + # End of 4.1 tests From a462f34a94ffe2c055dbaf3e2a854911c36edfaa Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 9 Oct 2007 11:36:05 +0200 Subject: [PATCH 26/29] Bug#30832:Assertion + crash with select name_const('test',now()); Completion of previous patch. Negative number were denied as the second argument to NAME_CONST. mysql-test/r/func_misc.result: Bug#30832 completion: test result mysql-test/t/func_misc.test: Bug#30832 completion: test case added negative numbers sql/item_func.h: Bug#30832 completion The function that represents unary minus is considered a constant if the argument is. --- mysql-test/r/func_misc.result | 6 ++++++ mysql-test/t/func_misc.test | 2 ++ sql/item_func.h | 1 + 3 files changed, 9 insertions(+) diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index bb6f4127a2a..c941790c35b 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -195,9 +195,15 @@ NULL SELECT NAME_CONST('test', 1); test 1 +SELECT NAME_CONST('test', -1); +test +-1 SELECT NAME_CONST('test', 1.0); test 1.0 +SELECT NAME_CONST('test', -1.0); +test +-1.0 SELECT NAME_CONST('test', 'test'); test test diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index c93e411e691..2c34f77b1ff 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -199,7 +199,9 @@ SELECT NAME_CONST('test', UPPER('test')); SELECT NAME_CONST('test', NULL); SELECT NAME_CONST('test', 1); +SELECT NAME_CONST('test', -1); SELECT NAME_CONST('test', 1.0); +SELECT NAME_CONST('test', -1.0); SELECT NAME_CONST('test', 'test'); --echo End of 5.0 tests diff --git a/sql/item_func.h b/sql/item_func.h index 87c9e016df2..43221a18a5b 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -435,6 +435,7 @@ public: longlong int_op(); my_decimal *decimal_op(my_decimal *); const char *func_name() const { return "-"; } + virtual bool basic_const_item() const { return args[0]->basic_const_item(); } void fix_length_and_dec(); void fix_num_length_and_dec(); uint decimal_precision() const { return args[0]->decimal_precision(); } From ae4141ed75124cc4bbae5fa22662ef0e7f00b122 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 9 Oct 2007 14:58:09 +0200 Subject: [PATCH 27/29] Bug#31160: MAKETIME() crashes server when returning NULL in ORDER BY using filesort Even though it returns NULL, the MAKETIME function did not have this property set, causing a failed assertion (designed to catch exactly this). Fixed by setting the nullability property of MAKETIME(). mysql-test/r/func_sapdb.result: Bug#31160: Changed test result. mysql-test/r/func_time.result: Bug#31160: Test result. mysql-test/t/func_time.test: Bug#31160: Test case. sql/item_timefunc.h: Bug#31160: The fix: Initializing maybe_null to true --- mysql-test/r/func_sapdb.result | 2 +- mysql-test/r/func_time.result | 9 +++++++++ mysql-test/t/func_time.test | 10 ++++++++++ sql/item_timefunc.h | 5 ++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_sapdb.result b/mysql-test/r/func_sapdb.result index dbae7e551e5..e2ed9c98adc 100644 --- a/mysql-test/r/func_sapdb.result +++ b/mysql-test/r/func_sapdb.result @@ -196,7 +196,7 @@ f2 datetime YES NULL f3 time YES NULL f4 time YES NULL f5 time YES NULL -f6 time NO 00:00:00 +f6 time YES NULL f7 datetime YES NULL f8 date YES NULL f9 time YES NULL diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index ee8b8c1e908..74859be4d04 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1027,6 +1027,15 @@ fmtddate field2 Sep-4 12:00AM abcd DROP TABLE testBug8868; SET NAMES DEFAULT; +CREATE TABLE t1 ( +a TIMESTAMP +); +INSERT INTO t1 VALUES (now()), (now()); +SELECT 1 FROM t1 ORDER BY MAKETIME(1, 1, a); +1 +1 +1 +DROP TABLE t1; (select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H) union (select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H); diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 86c848983fa..c0a449ac3f4 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -545,6 +545,16 @@ DROP TABLE testBug8868; SET NAMES DEFAULT; +# +# Bug #31160: MAKETIME() crashes server when returning NULL in ORDER BY using +# filesort +# +CREATE TABLE t1 ( + a TIMESTAMP +); +INSERT INTO t1 VALUES (now()), (now()); +SELECT 1 FROM t1 ORDER BY MAKETIME(1, 1, a); +DROP TABLE t1; # # Bug #19844 time_format in Union truncates values diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 8e925a0156f..3e860017d89 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -962,7 +962,10 @@ class Item_func_maketime :public Item_str_timefunc { public: Item_func_maketime(Item *a, Item *b, Item *c) - :Item_str_timefunc(a, b ,c) {} + :Item_str_timefunc(a, b, c) + { + maybe_null= TRUE; + } String *val_str(String *str); const char *func_name() const { return "maketime"; } }; From 15453e3a6aec17029e638f607ee3da95b842e350 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 10 Oct 2007 12:16:13 +0500 Subject: [PATCH 28/29] Bug#25359 Test 'view' is dependent on current year to be 2006 removed now() call to make the test to be year independent mysql-test/r/view.result: result fix mysql-test/t/view.test: removed now() call to make the test to be year independent --- mysql-test/r/view.result | 15 ++++++++------- mysql-test/t/view.test | 13 +++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 0ba911f2853..0e3d650c571 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2706,18 +2706,19 @@ CREATE TABLE t1( fName varchar(25) NOT NULL, lName varchar(25) NOT NULL, DOB date NOT NULL, +test_date date NOT NULL, uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY); -INSERT INTO t1(fName, lName, DOB) VALUES -('Hank', 'Hill', '1964-09-29'), -('Tom', 'Adams', '1908-02-14'), -('Homer', 'Simpson', '1968-03-05'); +INSERT INTO t1(fName, lName, DOB, test_date) VALUES +('Hank', 'Hill', '1964-09-29', '2007-01-01'), +('Tom', 'Adams', '1908-02-14', '2007-01-01'), +('Homer', 'Simpson', '1968-03-05', '2007-01-01'); CREATE VIEW v1 AS -SELECT (year(now())-year(DOB)) AS Age +SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75; SHOW CREATE VIEW v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (year(now()) - year(`t1`.`DOB`)) AS `Age` from `t1` having (`Age` < 75) -SELECT (year(now())-year(DOB)) AS Age FROM t1 HAVING Age < 75; +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (year(`t1`.`test_date`) - year(`t1`.`DOB`)) AS `Age` from `t1` having (`Age` < 75) +SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75; Age 43 39 diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index e6c3a03c645..0faa8e7a785 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2548,19 +2548,20 @@ CREATE TABLE t1( fName varchar(25) NOT NULL, lName varchar(25) NOT NULL, DOB date NOT NULL, + test_date date NOT NULL, uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY); -INSERT INTO t1(fName, lName, DOB) VALUES - ('Hank', 'Hill', '1964-09-29'), - ('Tom', 'Adams', '1908-02-14'), - ('Homer', 'Simpson', '1968-03-05'); +INSERT INTO t1(fName, lName, DOB, test_date) VALUES + ('Hank', 'Hill', '1964-09-29', '2007-01-01'), + ('Tom', 'Adams', '1908-02-14', '2007-01-01'), + ('Homer', 'Simpson', '1968-03-05', '2007-01-01'); CREATE VIEW v1 AS - SELECT (year(now())-year(DOB)) AS Age + SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75; SHOW CREATE VIEW v1; -SELECT (year(now())-year(DOB)) AS Age FROM t1 HAVING Age < 75; +SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75; SELECT * FROM v1; DROP VIEW v1; From 62f72d36103ad5bcc50a43c87efc9caed2f50cf5 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 10 Oct 2007 12:21:11 +0500 Subject: [PATCH 29/29] Bug#28893 --relay-log variable is not exposed with SHOW VARIABLES added variables relay_log, relay_log_index, relay_log_info_file to init_vars[] to make them visible within SHOW VARIABLES mysql-test/r/rpl_flush_log_loop.result: test result mysql-test/t/rpl_flush_log_loop.test: test case sql/set_var.cc: added variables relay_log, relay_log_index, relay_log_info_file to init_vars[] to make them visible within SHOW VARIABLES --- mysql-test/r/rpl_flush_log_loop.result | 7 +++++++ mysql-test/t/rpl_flush_log_loop.test | 3 +++ sql/set_var.cc | 3 +++ 3 files changed, 13 insertions(+) diff --git a/mysql-test/r/rpl_flush_log_loop.result b/mysql-test/r/rpl_flush_log_loop.result index f9bd42ec26c..3b1db804da9 100644 --- a/mysql-test/r/rpl_flush_log_loop.result +++ b/mysql-test/r/rpl_flush_log_loop.result @@ -4,6 +4,13 @@ reset master; reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; +show variables like 'relay_log%'; +Variable_name Value +relay_log MYSQLTEST_VARDIR/master-data/relay-log +relay_log_index +relay_log_info_file relay-log.info +relay_log_purge ON +relay_log_space_limit 0 stop slave; change master to master_host='127.0.0.1',master_user='root', master_password='',master_port=MASTER_PORT; diff --git a/mysql-test/t/rpl_flush_log_loop.test b/mysql-test/t/rpl_flush_log_loop.test index 6e45047bd30..f0b368c285b 100644 --- a/mysql-test/t/rpl_flush_log_loop.test +++ b/mysql-test/t/rpl_flush_log_loop.test @@ -3,6 +3,9 @@ source include/master-slave.inc; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +show variables like 'relay_log%'; + connection slave; stop slave; --replace_result $MASTER_MYPORT MASTER_PORT diff --git a/sql/set_var.cc b/sql/set_var.cc index e1246617d84..fbfe174434d 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1040,6 +1040,9 @@ struct show_var_st init_vars[]= { {sys_readonly.name, (char*) &sys_readonly, SHOW_SYS}, {sys_read_rnd_buff_size.name,(char*) &sys_read_rnd_buff_size, SHOW_SYS}, #ifdef HAVE_REPLICATION + {"relay_log" , (char*) &opt_relay_logname, SHOW_CHAR_PTR}, + {"relay_log_index", (char*) &opt_relaylog_index_name, SHOW_CHAR_PTR}, + {"relay_log_info_file", (char*) &relay_log_info_file, SHOW_CHAR_PTR}, {sys_relay_log_purge.name, (char*) &sys_relay_log_purge, SHOW_SYS}, {"relay_log_space_limit", (char*) &relay_log_space_limit, SHOW_LONGLONG}, #endif