From 6736de283919d00610b0766fdfd727fc3b254156 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Dec 2003 17:46:07 +0300 Subject: [PATCH 1/6] don't delete select_lex->having and select_lex->where as we delete all items in free_prep_stmt(free_items); indentation fix --- sql/sql_prepare.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 9f7c0bc0b0c..790b80eb127 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -671,8 +671,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); } @@ -680,10 +678,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 From 524ab904a11e6d510d6191c13f1f6a0ae9197b5e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Dec 2003 20:53:05 +0300 Subject: [PATCH 2/6] cleanup: unused variable removed followup of Bordeaux Optimizer session --- sql/sql_select.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 82ce688495a..69e8ea8ccff 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1609,10 +1609,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) From 17119e6de3bb9fa3c10e73c38474b13c3cdaa002 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Dec 2003 13:59:09 -0800 Subject: [PATCH 3/6] join_outer.result, null.result, null.test, item_cmpfunc.h: Fixed inconsistency of values of used_tables_cache and const_item_cache for Item_func_isnull objects (bug #1990). sql/item_cmpfunc.h: Fixed inconsistency of values of used_tables_cache and const_item_cache for Item_func_isnull objects (bug #1990). mysql-test/t/null.test: Fixed inconsistency of values of used_tables_cache and const_item_cache for Item_func_isnull objects (bug #1990). mysql-test/r/null.result: Fixed inconsistency of values of used_tables_cache and const_item_cache for Item_func_isnull objects (bug #1990). mysql-test/r/join_outer.result: Fixed inconsistency of values of used_tables_cache and const_item_cache for Item_func_isnull objects (bug #1990). --- mysql-test/r/join_outer.result | 2 +- mysql-test/r/null.result | 11 +++++++++++ mysql-test/t/null.test | 11 +++++++++++ sql/item_cmpfunc.h | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 3a1f68fb6c1..165f1522378 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -91,7 +91,7 @@ grp a c id a c d NULL NULL NULL NULL NULL NULL explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 7 diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result index 9de9fdce2db..f4decd3b79e 100644 --- a/mysql-test/r/null.result +++ b/mysql-test/r/null.result @@ -142,3 +142,14 @@ a b c d 0 0000-00-00 00:00:00 0 0 0000-00-00 00:00:00 0 drop table t1; +create table t1 (a int not null, b int not null, index idx(a)); +insert into t1 values +(1,1), (2,2), (3,3), (4,4), (5,5), (6,6), +(7,7), (8,8), (9,9), (10,10), (11,11), (12,12); +explain select * from t1 where a between 2 and 3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range idx idx 4 NULL 2 Using where +explain select * from t1 where a between 2 and 3 or b is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range idx idx 4 NULL 2 Using where +drop table t1; diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index 0be755ba7ad..5fa8f8a7651 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -86,3 +86,14 @@ INSERT INTO t1 (d) values (null),(null); select * from t1; drop table t1; +# +# Test to check elimination of IS NULL predicate for a non-nullable attribute +# (bug #1990) +# +create table t1 (a int not null, b int not null, index idx(a)); +insert into t1 values + (1,1), (2,2), (3,3), (4,4), (5,5), (6,6), + (7,7), (8,8), (9,9), (10,10), (11,11), (12,12); +explain select * from t1 where a between 2 and 3; +explain select * from t1 where a between 2 and 3 or b is null; +drop table t1; diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index dc017cef73c..541bc47557d 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -746,6 +746,7 @@ public: if (!args[0]->maybe_null) { used_tables_cache= 0; /* is always false */ + const_item_cache= 1; cached_value= (longlong) 0; } else From 40d2de8eaaaacc91784a901d04724ff9197d981e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Dec 2003 13:32:05 +0200 Subject: [PATCH 4/6] Ensure that innodb is created for the first replication test as the slave-timeout is lower for future tests and this failed on some slower machines --- mysql-test/t/rpl000001-slave.opt | 1 + 1 file changed, 1 insertion(+) create mode 100644 mysql-test/t/rpl000001-slave.opt 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 From 5ea174a97eda0b9a97f3dccbd37e87d612beb34e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Dec 2003 15:09:35 +0300 Subject: [PATCH 5/6] Item_param::save_in_field(): thd->command can be anything except COM_EXECUTE in no cases except programming error. --- sql/item.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 1d49671ff4c..9af2c300202 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -580,8 +580,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); From 6990f6cf7e0397487e4b1934fa1255f93ea8665c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Dec 2003 19:06:24 +0400 Subject: [PATCH 6/6] Fix for #1189 (Mess with names about CONSTRAINT) Second edition: error message was deleted as Segey suggested Now name of the constraint will be used as the name of the key if the last not specified mysql-test/r/constraints.result: appropriate test result mysql-test/t/constraints.test: test case for 1189 sql/sql_yacc.yy: language definitions changed so that we can obtaint constraint's name and send it as the name of the key if it's not specified --- mysql-test/r/constraints.result | 13 +++++++++++++ mysql-test/t/constraints.test | 6 ++++++ sql/sql_yacc.yy | 27 ++++++++++++++++++--------- 3 files changed, 37 insertions(+), 9 deletions(-) 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/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/sql/sql_yacc.yy b/sql/sql_yacc.yy index 805dc9f1932..8fe69ad6ae3 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -598,7 +598,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 @@ -631,7 +631,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); expr_list udf_expr_list when_list 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 @@ -1189,6 +1189,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; @@ -1212,8 +1219,8 @@ check_constraint: ; opt_constraint: - /* empty */ - | CONSTRAINT opt_ident; + /* empty */ { $$=(char*) 0; } + | CONSTRAINT opt_ident { $$=$2; }; field_spec: field_ident @@ -1575,14 +1582,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 {}