diff --git a/mysql-test/r/constraints.result b/mysql-test/r/constraints.result index 3b41e291e0f..7cd8053c21b 100644 --- a/mysql-test/r/constraints.result +++ b/mysql-test/r/constraints.result @@ -14,3 +14,16 @@ drop table t1; create table t1 (a int null); insert into t1 values (1),(NULL); drop table t1; +create table t1 (a int null); +alter table t1 add constraint constraint_1 unique (a); +alter table t1 add constraint unique key_1(a); +alter table t1 add constraint constraint_2 unique key_2(a); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) default NULL, + UNIQUE KEY `constraint_1` (`a`), + UNIQUE KEY `key_1` (`a`), + UNIQUE KEY `key_2` (`a`) +) TYPE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index b0d597f238a..f6a96eb94a0 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -363,3 +363,30 @@ t2 rows after big delete 1900001 select 't1 rows after big delete', count(*) from t1; t1 rows after big delete count(*) t1 rows after big delete 1900001 +drop table t1,t2; +set @ttype_save=@@table_type; +set @@table_type=innodb; +create table t1 ( c char(8) not null ); +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; +create table t2 like t1; +insert into t2 select * from t1; +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; +drop table t1,t2; +set @@table_type=bdb; +create table t1 ( c char(8) not null ); +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; +create table t2 like t1; +insert into t2 select * from t1; +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; +set @@table_type=@ttype_save; +drop table t1,t2; diff --git a/mysql-test/t/constraints.test b/mysql-test/t/constraints.test index cc796e0abd2..dbc34a0dff1 100644 --- a/mysql-test/t/constraints.test +++ b/mysql-test/t/constraints.test @@ -21,3 +21,9 @@ drop table t1; create table t1 (a int null); insert into t1 values (1),(NULL); drop table t1; +create table t1 (a int null); +alter table t1 add constraint constraint_1 unique (a); +alter table t1 add constraint unique key_1(a); +alter table t1 add constraint constraint_2 unique key_2(a); +show create table t1; +drop table t1; diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index b3c742e0b30..0886b957ca7 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -309,4 +309,50 @@ delete t1,t2 from t1,t2 where t1.b=t2.a and t1.a < 100*1000; select 't2 rows after big delete', count(*) from t2; select 't1 rows after big delete', count(*) from t1; -#drop table t1,t2; +drop table t1,t2; + +# +# Test for bug #1980. +# +set @ttype_save=@@table_type; + +--disable_warnings +set @@table_type=innodb; +create table t1 ( c char(8) not null ); +--enable_warnings + +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); + +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; + +create table t2 like t1; +insert into t2 select * from t1; + +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; + +drop table t1,t2; + +--disable_warnings +set @@table_type=bdb; +create table t1 ( c char(8) not null ); +--enable_warnings + +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); + +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; + +create table t2 like t1; +insert into t2 select * from t1; + +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; + +set @@table_type=@ttype_save; +drop table t1,t2; diff --git a/mysql-test/t/rpl000001-slave.opt b/mysql-test/t/rpl000001-slave.opt new file mode 100644 index 00000000000..627becdbfb5 --- /dev/null +++ b/mysql-test/t/rpl000001-slave.opt @@ -0,0 +1 @@ +--innodb diff --git a/sql/item.cc b/sql/item.cc index 5f9a9d4a657..a39805dd24a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -601,8 +601,7 @@ int Item_param::save_in_field(Field *field, bool no_conversions) { THD *thd= current_thd; - if (thd->command == COM_PREPARE) - return -1; + DBUG_ASSERT(thd->command == COM_EXECUTE); if (null_value) return (int) set_field_to_null(field); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 7715ab01044..2399bf8d353 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -672,8 +672,6 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables, fix_tables_pointers(thd->lex->all_selects_list); if (!result && !(result= new select_send())) { - delete select_lex->having; - delete select_lex->where; send_error(thd, ER_OUT_OF_RESOURCES); DBUG_RETURN(1); } @@ -681,10 +679,10 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables, JOIN *join= new JOIN(thd, fields, select_options, result); thd->used_tables= 0; // Updated by setup_fields - if (join->prepare(&select_lex->ref_pointer_array, tables, - wild_num, conds, og_num, order, group, having, proc, - select_lex, unit)) - DBUG_RETURN(1); + if (join->prepare(&select_lex->ref_pointer_array, tables, + wild_num, conds, og_num, order, group, having, proc, + select_lex, unit)) + DBUG_RETURN(1); if (send_prep_stmt(stmt, fields.elements) || thd->protocol_simple.send_fields(&fields, 0) || #ifndef EMBEDDED_LIBRARY diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 55f5b28fc78..3cf52c29a8c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1692,10 +1692,6 @@ mysql_select(THD *thd, Item ***rref_pointer_array, err: if (free_join) { - JOIN *curr_join= (join->need_tmp&&join->tmp_join? - (join->tmp_join->error=join->error,join->tmp_join): - join); - thd->proc_info="end"; err= join->cleanup(); if (thd->net.report_error) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index cd08e702cd5..7e7a8976924 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -636,7 +636,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %type remember_name remember_end opt_ident opt_db text_or_password - opt_escape + opt_escape opt_constraint %type text_string opt_gconcat_separator @@ -670,7 +670,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ident_list ident_list_arg %type - key_type opt_unique_or_fulltext + key_type opt_unique_or_fulltext constraint_key_type %type key_alg opt_btree_or_rtree @@ -2144,6 +2144,13 @@ key_def: lex->key_list.push_back(new Key($1,$2, $3, lex->col_list)); lex->col_list.empty(); /* Alloced by sql_alloc */ } + | opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')' + { + LEX *lex=Lex; + const char *key_name= $3 ? $3:$1; + lex->key_list.push_back(new Key($2, key_name, $4, lex->col_list)); + lex->col_list.empty(); /* Alloced by sql_alloc */ + } | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references { LEX *lex=Lex; @@ -2167,8 +2174,8 @@ check_constraint: ; opt_constraint: - /* empty */ - | CONSTRAINT opt_ident; + /* empty */ { $$=(char*) 0; } + | CONSTRAINT opt_ident { $$=$2; }; field_spec: field_ident @@ -2530,14 +2537,16 @@ delete_option: | SET DEFAULT { $$= (int) foreign_key::FK_OPTION_DEFAULT; }; key_type: - opt_constraint PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; } - | key_or_index { $$= Key::MULTIPLE; } + key_or_index { $$= Key::MULTIPLE; } | FULLTEXT_SYM { $$= Key::FULLTEXT; } | FULLTEXT_SYM key_or_index { $$= Key::FULLTEXT; } | SPATIAL_SYM { $$= Key::SPATIAL; } - | SPATIAL_SYM key_or_index { $$= Key::SPATIAL; } - | opt_constraint UNIQUE_SYM { $$= Key::UNIQUE; } - | opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; }; + | SPATIAL_SYM key_or_index { $$= Key::SPATIAL; }; + +constraint_key_type: + PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; } + | UNIQUE_SYM { $$= Key::UNIQUE; } + | UNIQUE_SYM key_or_index { $$= Key::UNIQUE; }; key_or_index: KEY_SYM {} diff --git a/sql/uniques.cc b/sql/uniques.cc index f289fd11f5b..02146426782 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -37,14 +37,20 @@ int unique_write_to_file(gptr key, element_count count, Unique *unique) { + /* + Use unique->size (size of element stored in the tree) and not + unique->tree.size_of_element. The latter is different from unique->size + when tree implementation chooses to store pointer to key in TREE_ELEMENT + (instead of storing the element itself there) + */ return my_b_write(&unique->file, (byte*) key, - unique->tree.size_of_element) ? 1 : 0; + unique->size) ? 1 : 0; } int unique_write_to_ptrs(gptr key, element_count count, Unique *unique) { - memcpy(unique->record_pointers, key, unique->tree.size_of_element); - unique->record_pointers+=unique->tree.size_of_element; + memcpy(unique->record_pointers, key, unique->size); + unique->record_pointers+=unique->size; return 0; } @@ -133,7 +139,7 @@ bool Unique::get(TABLE *table) sort_param.max_rows= elements; sort_param.sort_form=table; sort_param.rec_length= sort_param.sort_length=sort_param.ref_length= - tree.size_of_element; + size; sort_param.keys= max_in_memory_size / sort_param.sort_length; sort_param.not_killable=1;