diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index 3fa12f2997a..c9e3655660b 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -1103,3 +1103,17 @@ Field Type Null Key Default Extra unsigned_int_field bigint(20) unsigned NO MUL char_field char(10) YES NULL DROP TABLE t2; +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT); +INSERT INTO t1 VALUES (1, 2, NULL); +SELECT * FROM t1; +f1 f2 f3 +1 2 NULL +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1; +SELECT * FROM t1; +f1 f3 f2 +1 NULL 2 +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2; +SELECT * FROM t1; +f1 f2 f3 +1 2 NULL +DROP TABLE t1; diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index d8d7ddef122..4fbfc2b2ea4 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -317,10 +317,39 @@ SHOW COUNT(*) WARNINGS; SHOW COUNT(*) ERRORS; @@session.error_count 1 -create table t1(f1 int); -insert into t1 values(1),(1),(2); -select @a:=f1, count(f1) from t1 group by 1 order by 1; +create table t1(f1 int, f2 varchar(2), f3 float, f4 decimal(2,1)); +insert into t1 values +(1, "a", 1.5, 1.6), (1, "a", 1.5, 1.6), (2, "b", 2.5, 2.6), +(3, "c", 3.5, 3.6), (4, "d", 4.5, 4.6), (1, "a", 1.5, 1.6), +(3, "c", 3.5, 3.6), (1, "a", 1.5, 1.6); +select @a:=f1, count(f1) from t1 group by 1 desc; @a:=f1 count(f1) -1 2 +4 1 +3 2 2 1 +1 4 +select @a:=f1, count(f1) from t1 group by 1 asc; +@a:=f1 count(f1) +1 4 +2 1 +3 2 +4 1 +select @a:=f2, count(f2) from t1 group by 1 desc; +@a:=f2 count(f2) +d 1 +c 2 +b 1 +a 4 +select @a:=f3, count(f3) from t1 group by 1 desc; +@a:=f3 count(f3) +4.5 1 +3.5 2 +2.5 1 +1.5 4 +select @a:=f4, count(f4) from t1 group by 1 desc; +@a:=f4 count(f4) +4.6 1 +3.6 2 +2.6 1 +1.6 4 drop table t1; diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 70fd1dfa898..7c1c096534e 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -839,3 +839,15 @@ ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL; DESCRIBE t2; DROP TABLE t2; + +# +# Bug#28427: Columns were renamed instead of moving by ALTER TABLE. +# +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT); +INSERT INTO t1 VALUES (1, 2, NULL); +SELECT * FROM t1; +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1; +SELECT * FROM t1; +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2; +SELECT * FROM t1; +DROP TABLE t1; diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index da4143bb0d3..3a3e8f88f83 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -226,7 +226,14 @@ SHOW COUNT(*) ERRORS; # # Bug#28494: Grouping by Item_func_set_user_var produces incorrect result. # -create table t1(f1 int); -insert into t1 values(1),(1),(2); -select @a:=f1, count(f1) from t1 group by 1 order by 1; +create table t1(f1 int, f2 varchar(2), f3 float, f4 decimal(2,1)); +insert into t1 values + (1, "a", 1.5, 1.6), (1, "a", 1.5, 1.6), (2, "b", 2.5, 2.6), + (3, "c", 3.5, 3.6), (4, "d", 4.5, 4.6), (1, "a", 1.5, 1.6), + (3, "c", 3.5, 3.6), (1, "a", 1.5, 1.6); +select @a:=f1, count(f1) from t1 group by 1 desc; +select @a:=f1, count(f1) from t1 group by 1 asc; +select @a:=f2, count(f2) from t1 group by 1 desc; +select @a:=f3, count(f3) from t1 group by 1 desc; +select @a:=f4, count(f4) from t1 group by 1 desc; drop table t1; diff --git a/sql/item_func.cc b/sql/item_func.cc index 640ab3cac0c..7806a37d8d0 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3799,6 +3799,23 @@ Item_func_set_user_var::fix_length_and_dec() } +/* + Mark field in read_map + + NOTES + This is used by filesort to register used fields in a a temporary + column read set or to register used fields in a view +*/ + +bool Item_func_set_user_var::register_field_in_read_map(uchar *arg) +{ + TABLE *table= (TABLE *) arg; + if (result_field->table == table || !table) + bitmap_set_bit(result_field->table->read_set, result_field->field_index); + return 0; +} + + /* Set value to user variable. @@ -4035,7 +4052,8 @@ bool Item_func_set_user_var::check(bool use_result_field) { DBUG_ENTER("Item_func_set_user_var::check"); - DBUG_ASSERT(!use_result_field || result_field); + if (use_result_field && !result_field) + use_result_field= FALSE; switch (cached_result_type) { case REAL_RESULT: @@ -4179,6 +4197,40 @@ my_decimal *Item_func_set_user_var::val_decimal(my_decimal *val) } +double Item_func_set_user_var::val_result() +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_real(&null_value); +} + +longlong Item_func_set_user_var::val_int_result() +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_int(&null_value); +} + +String *Item_func_set_user_var::str_result(String *str) +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_str(&null_value, str, decimals); +} + + +my_decimal *Item_func_set_user_var::val_decimal_result(my_decimal *val) +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_decimal(&null_value, val); +} + + void Item_func_set_user_var::print(String *str) { str->append(STRING_WITH_LEN("(@")); diff --git a/sql/item_func.h b/sql/item_func.h index 8c761f605db..d2ed0404dac 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1236,6 +1236,10 @@ public: longlong val_int(); String *val_str(String *str); my_decimal *val_decimal(my_decimal *); + double val_result(); + longlong val_int_result(); + String *str_result(String *str); + my_decimal *val_decimal_result(my_decimal *); bool update_hash(void *ptr, uint length, enum Item_result type, CHARSET_INFO *cs, Derivation dv, bool unsigned_arg); bool send(Protocol *protocol, String *str_arg); @@ -1255,6 +1259,7 @@ public: return save_in_field(field, no_conversions, 1); } void save_org_in_field(Field *field) { (void)save_in_field(field, 1, 0); } + bool register_field_in_read_map(uchar *arg); }; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index be376a07c49..c853f71ed31 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3805,6 +3805,11 @@ we force server id to 2, but this MySQL server will not act as a slave."); freopen(log_error_file,"a+",stderr); FreeConsole(); // Remove window } + else + { + /* Don't show error dialog box when on foreground: it stops the server */ + SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); + } #endif /* diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 11d7d15c685..6d5860240be 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5932,6 +5932,7 @@ view_err: goto err; } find_it.after(def); // Put element after this + need_copy_table= ALTER_TABLE_DATA_CHANGED; } } if (alter_info->alter_list.elements) @@ -6170,12 +6171,14 @@ view_err: (uint*) thd->alloc(sizeof(uint) * prepared_key_list.elements))) goto err; /* Check how much the tables differ. */ - need_copy_table= compare_tables(table, &prepared_create_list, + uint res= compare_tables(table, &prepared_create_list, key_info_buffer, key_count, create_info, alter_info, order_num, index_drop_buffer, &index_drop_count, index_add_buffer, &index_add_count, varchar); + if (!need_copy_table) + need_copy_table= res; } /*