From d9bd3c11e4c06e31974998dc75fc348e10c8cae1 Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Mon, 12 Sep 2005 17:09:19 +0500 Subject: [PATCH 1/2] Fix for bug #6008: MySQL does not create warnings when creating database and using IF NOT EXISTS produce warning for 'create database if not exists' if database exists do not update database options in this case produce warning for 'create table if not exists' if table exists --- mysql-test/r/create.result | 28 ++++++++++++++++++++++++++++ mysql-test/r/temp_table.result | 2 ++ mysql-test/r/warnings.result | 4 +++- mysql-test/t/create.test | 13 +++++++++++++ sql/sql_db.cc | 6 +++++- sql/sql_table.cc | 28 ++++++++++++++++------------ 6 files changed, 67 insertions(+), 14 deletions(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 95757fbd7dc..6edd4cbc48f 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -9,6 +9,8 @@ NULL drop table if exists t1; create table t1 (b char(0) not null); create table if not exists t1 (b char(0) not null); +Warnings: +Note 1050 Table 't1' already exists insert into t1 values (""),(null); Warnings: Warning 1263 Data truncated; NULL supplied to NOT NULL column 'b' at row 2 @@ -232,9 +234,13 @@ create table t1 select x'4132'; drop table t1; create table t1 select 1,2,3; create table if not exists t1 select 1,2; +Warnings: +Note 1050 Table 't1' already exists create table if not exists t1 select 1,2,3,4; ERROR 21S01: Column count doesn't match value count at row 1 create table if not exists t1 select 1; +Warnings: +Note 1050 Table 't1' already exists select * from t1; 1 2 3 1 2 3 @@ -243,9 +249,13 @@ select * from t1; drop table t1; create table t1 select 1,2,3; create table if not exists t1 select 1,2; +Warnings: +Note 1050 Table 't1' already exists create table if not exists t1 select 1,2,3,4; ERROR 21S01: Column count doesn't match value count at row 1 create table if not exists t1 select 1; +Warnings: +Note 1050 Table 't1' already exists select * from t1; 1 2 3 1 2 3 @@ -255,11 +265,15 @@ drop table t1; create table t1 (a int not null, b int, primary key (a)); insert into t1 values (1,1); create table if not exists t1 select 2; +Warnings: +Note 1050 Table 't1' already exists select * from t1; a b 1 1 0 2 create table if not exists t1 select 3 as 'a',4 as 'b'; +Warnings: +Note 1050 Table 't1' already exists create table if not exists t1 select 3 as 'a',3 as 'b'; ERROR 23000: Duplicate entry '3' for key 1 select * from t1; @@ -593,3 +607,17 @@ drop database mysqltest; create table test.t1 like x; ERROR 42000: Incorrect database name 'NULL' drop table if exists test.t1; +create database mysqltest; +create database if not exists mysqltest character set latin2; +Warnings: +Note 1007 Can't create database 'mysqltest'; database exists +show create database mysqltest; +Database Create Database +mysqltest CREATE DATABASE `mysqltest` /*!40100 DEFAULT CHARACTER SET latin1 */ +drop database mysqltest; +use test; +create table t1 (a int); +create table if not exists t1 (a int); +Warnings: +Note 1050 Table 't1' already exists +drop table t1; diff --git a/mysql-test/r/temp_table.result b/mysql-test/r/temp_table.result index f08fe6ddd0f..0b6bc48c350 100644 --- a/mysql-test/r/temp_table.result +++ b/mysql-test/r/temp_table.result @@ -23,6 +23,8 @@ a b 6 g create TEMPORARY TABLE t2 engine=heap select * from t1; create TEMPORARY TABLE IF NOT EXISTS t2 (a int) engine=heap; +Warnings: +Note 1050 Table 't2' already exists CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null); ERROR 42S01: Table 't1' already exists ALTER TABLE t1 RENAME t2; diff --git a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result index e97b309547a..b9c05bc388c 100644 --- a/mysql-test/r/warnings.result +++ b/mysql-test/r/warnings.result @@ -63,9 +63,11 @@ show count(*) warnings; 1 create table t1(id int); create table if not exists t1(id int); +Warnings: +Note 1050 Table 't1' already exists select @@warning_count; @@warning_count -0 +1 drop table t1; create table t1(a tinyint, b int not null, c date, d char(5)); load data infile '../../std_data/warnings_loaddata.dat' into table t1 fields terminated by ','; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 9ea810aaf7d..73184853d1a 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -513,4 +513,17 @@ create table test.t1 like x; drop table if exists test.t1; --enable_warnings +# +# Bug #6008 MySQL does not create warnings when +# creating database and using IF NOT EXISTS +# +create database mysqltest; +create database if not exists mysqltest character set latin2; +show create database mysqltest; +drop database mysqltest; +use test; +create table t1 (a int); +create table if not exists t1 (a int); +drop table t1; + # End of 4.1 tests diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 7635774e3ac..7c834c91183 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -427,7 +427,11 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, error= -1; goto exit; } - result= 0; + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), db); + error= 0; + send_ok(thd); + goto exit; } else { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 92db0143980..01126043764 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1360,6 +1360,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS) { create_info->table_existed= 1; // Mark that table existed + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + alias); DBUG_RETURN(0); } my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias); @@ -1373,12 +1376,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, if (!access(path,F_OK)) { if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS) - { - create_info->table_existed= 1; // Mark that table existed - error= 0; - } - else - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); + goto warn; + my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); goto end; } } @@ -1401,12 +1400,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, DBUG_PRINT("info", ("Table with same name already existed in handler")); if (create_if_not_exists) - { - create_info->table_existed= 1; // Mark that table existed - error= 0; - } - else - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); + goto warn; + my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); goto end; } } @@ -1447,6 +1442,15 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, } } error=0; + goto end; + +warn: + error= 0; + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + alias); + create_info->table_existed= 1; // Mark that table existed + end: VOID(pthread_mutex_unlock(&LOCK_open)); start_waiting_global_read_lock(thd); From 0965bfa83242f74a22a56952422107740061c04d Mon Sep 17 00:00:00 2001 From: "monty@mishka.mysql.com" <> Date: Mon, 12 Sep 2005 18:48:17 +0300 Subject: [PATCH 2/2] Review fixes since last pull Fix for bug #13025; Server crash in filesort because wrong call to handler::position() --- client/mysqltest.c | 3 ++- mysql-test/r/innodb.result | 11 +++++++++++ mysql-test/t/innodb.test | 10 ++++++++++ sql/filesort.cc | 2 +- sql/item_cmpfunc.cc | 16 +++++++++------- sql/sql_select.cc | 12 ++++++------ 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 3e2cde92aa9..374f0cb1336 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2170,7 +2170,8 @@ int read_line(char *buf, int size) if (feof(cur_file->file)) { found_eof: - if (cur_file->file != stdin){ + if (cur_file->file != stdin) + { my_fclose(cur_file->file, MYF(0)); cur_file->file= 0; } diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 858daacffe9..f47c78c9768 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -1674,3 +1674,14 @@ select * from t1; a 42 drop table t1; +create table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=innodb; +insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3); +select * from t1 order by a,b,c,d; +a b c d e +1 1 a 1 1 +2 2 b 2 2 +3 3 ab 3 3 +explain select * from t1 order by a,b,c,d; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort +drop table t1; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index 33432209e65..a14370c6543 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -1220,4 +1220,14 @@ insert into t1 values (42); select * from t1; drop table t1; +# +# Bug #13025 Server crash during filesort +# + +create table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=innodb; +insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3); +select * from t1 order by a,b,c,d; +explain select * from t1 order by a,b,c,d; +drop table t1; + # End of 4.1 tests diff --git a/sql/filesort.cc b/sql/filesort.cc index 75b114fc140..63a8515020b 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -443,7 +443,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ha_store_ptr(ref_pos,ref_length,record); // Position to row record+=sort_form->db_record_offset; } - else + else if (!error) file->position(sort_form->record[0]); } if (error && error != HA_ERR_RECORD_DELETED) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index f547a8a50a8..74eed7fa41a 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -51,7 +51,8 @@ static void agg_cmp_type(Item_result *type, Item **items, uint nitems) type[0]= item_cmp_type(type[0], items[i]->result_type()); } -static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) +static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, + const char *fname) { my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0), c1.collation->name,c1.derivation_name(), @@ -850,8 +851,8 @@ longlong Item_func_interval::val_int() 1 got error */ -bool -Item_func_between::fix_fields(THD *thd, struct st_table_list *tables, Item **ref) +bool Item_func_between::fix_fields(THD *thd, struct st_table_list *tables, + Item **ref) { if (Item_func_opt_neg::fix_fields(thd, tables, ref)) return 1; @@ -861,8 +862,9 @@ Item_func_between::fix_fields(THD *thd, struct st_table_list *tables, Item **ref return 0; /* not_null_tables_cache == union(T1(e), intersection(T1(e1),T1(e2))) */ - not_null_tables_cache= args[0]->not_null_tables() | - (args[1]->not_null_tables() & args[2]->not_null_tables()); + not_null_tables_cache= (args[0]->not_null_tables() | + (args[1]->not_null_tables() & + args[2]->not_null_tables())); return 0; } @@ -1106,8 +1108,8 @@ Item_func_if::fix_fields(THD *thd, struct st_table_list *tlist, Item **ref) if (Item_func::fix_fields(thd, tlist, ref)) return 1; - not_null_tables_cache= (args[1]->not_null_tables() - & args[2]->not_null_tables()); + not_null_tables_cache= (args[1]->not_null_tables() & + args[2]->not_null_tables()); return 0; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3de546fd619..f702e531a4d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9307,12 +9307,12 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list, if (expr->arg_count) { Item **arg,**arg_end; + bool arg_changed= FALSE; for (arg= expr->arguments(), arg_end= expr->arguments()+expr->arg_count; arg != arg_end; arg++) { Item *item= *arg; - bool arg_changed= FALSE; if (item->type() == Item::FIELD_ITEM || item->type() == Item::REF_ITEM) { ORDER *group_tmp; @@ -9333,11 +9333,11 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list, if (change_group_ref(thd, (Item_func *) item, group_list, &arg_changed)) return 1; } - if (arg_changed) - { - expr->maybe_null= 1; - *changed= TRUE; - } + } + if (arg_changed) + { + expr->maybe_null= 1; + *changed= TRUE; } } return 0;