diff options
-rw-r--r-- | mysql-test/r/func_str.result | 11 | ||||
-rw-r--r-- | mysql-test/r/key.result | 16 | ||||
-rw-r--r-- | mysql-test/r/key_primary.result | 2 | ||||
-rw-r--r-- | mysql-test/r/null_key.result | 2 | ||||
-rw-r--r-- | mysql-test/r/subselect.result | 8 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 18 | ||||
-rw-r--r-- | mysql-test/t/key.test | 12 | ||||
-rw-r--r-- | sql/item.cc | 5 | ||||
-rw-r--r-- | sql/sql_base.cc | 5 | ||||
-rw-r--r-- | sql/sql_load.cc | 6 | ||||
-rw-r--r-- | sql/sql_select.cc | 15 |
11 files changed, 81 insertions, 19 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index d3225679b3e..bdba9e4c3e4 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -639,3 +639,14 @@ name aaaaaaaaaaccccc bbbbbbbbbbddddd drop table t1, t2; +create table t1 (c1 INT); +insert into t1 (c1) values ('21474836461'); +Warnings: +Warning 1265 Data truncated for column 'c1' at row 1 +show warnings; +Level Code Message +Warning 1265 Data truncated for column 'c1' at row 1 +select * from t1; +c1 +2147483647 +drop table t1; diff --git a/mysql-test/r/key.result b/mysql-test/r/key.result index 115f15bacb6..b8387389075 100644 --- a/mysql-test/r/key.result +++ b/mysql-test/r/key.result @@ -206,3 +206,19 @@ select i from t1 where b=repeat(_utf8 'b',310); i 1 drop table t1; +CREATE TABLE t1 (id int unsigned auto_increment, name char(50), primary key (id)) engine=myisam; +insert into t1 (name) values ('a'), ('b'),('c'),('d'),('e'),('f'),('g'); +explain select 1 from t1 where id =2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index +explain select 1 from t1 where id =2 or id=3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index +explain select name from t1 where id =2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 +ALTER TABLE t1 DROP PRIMARY KEY, ADD INDEX (id); +explain select 1 from t1 where id =2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref id id 4 const 1 Using where; Using index +drop table t1; diff --git a/mysql-test/r/key_primary.result b/mysql-test/r/key_primary.result index 14ca90b3dd2..7726a8e1d63 100644 --- a/mysql-test/r/key_primary.result +++ b/mysql-test/r/key_primary.result @@ -13,7 +13,7 @@ t1 AB% describe select * from t1 where t1="ABC"; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const PRIMARY PRIMARY 3 const 1 +1 SIMPLE t1 const PRIMARY PRIMARY 3 const 1 Using index describe select * from t1 where t1="ABCD"; 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 diff --git a/mysql-test/r/null_key.result b/mysql-test/r/null_key.result index 4dfd17991cc..e57ac321f46 100644 --- a/mysql-test/r/null_key.result +++ b/mysql-test/r/null_key.result @@ -12,7 +12,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref a,b a 9 const,const 1 Using where; Using index explain select * from t1 where a=2 and b = 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const a,b a 9 const,const 1 +1 SIMPLE t1 const a,b a 9 const,const 1 Using index explain select * from t1 where a<=>b limit 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL a 9 NULL 12 Using where; Using index diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index cf0f9b4cc14..ca6a9930d27 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -357,10 +357,10 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t8 const PRIMARY PRIMARY 35 const 1 -4 SUBQUERY t8 const PRIMARY PRIMARY 35 1 +1 PRIMARY t8 const PRIMARY PRIMARY 35 const 1 Using index +4 SUBQUERY t8 const PRIMARY PRIMARY 35 1 Using index 2 SUBQUERY t8 const PRIMARY PRIMARY 35 const 1 -3 SUBQUERY t8 const PRIMARY PRIMARY 35 1 +3 SUBQUERY t8 const PRIMARY PRIMARY 35 1 Using index Warnings: Note 1003 select high_priority test.t8.pseudo AS `pseudo`,(select test.t8.email AS `email` from test.t8 where (test.t8.pseudo = (select test.t8.pseudo AS `pseudo` from test.t8 where (test.t8.pseudo = _latin1'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from test.t8 where (test.t8.pseudo = (select test.t8.pseudo AS `pseudo` from test.t8 where (test.t8.pseudo = _latin1'joce'))) SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM @@ -537,7 +537,7 @@ Warnings: Note 1003 select high_priority max(test.t1.numreponse) AS `MAX(numreponse)` from test.t1 where (test.t1.numeropost = _latin1'1') EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 +1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 Using index 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away Warnings: Note 1003 select high_priority test.t1.numreponse AS `numreponse` from test.t1 where ((test.t1.numeropost = _latin1'1') and (test.t1.numreponse = 3)) diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 1c85f83baac..7efcac030af 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -358,21 +358,19 @@ select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),substring_index("1abcd explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'mood' sounds like 'mud', aes_decrypt(aes_encrypt('abc','1'),'1'),concat('*',space(5),'*'), reverse('abc'), rpad('a',4,'1'), lpad('a',4,'1'), concat_ws(',','',NULL,'a'),make_set(255,_latin2'a',_latin2'b',_latin2'c'),elt(2,1),locate("a","b",2),format(130,10),char(0),conv(130,16,10),hex(130),binary 'HE', export_set(255,_latin2'y',_latin2'n',_latin2' '),FIELD('b' COLLATE latin1_bin,'A','B'),FIND_IN_SET(_latin1'B',_latin1'a,b,c,d'),collation(conv(130,16,10)), coercibility(conv(130,16,10)),length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'),quote(1/0),crc32("123"),replace('aaaa','a','b'),insert('txs',2,1,'hi'),left(_latin2'a',1),right(_latin2'a',1),lcase(_latin2'a'),ucase(_latin2'a'),SUBSTR('abcdefg',3,2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),trim(_latin2' a '),ltrim(_latin2' a '),rtrim(_latin2' a '), decode(encode(repeat("a",100000),"monty"),"monty"); # -# Bug #2182 +# lpad returns incorrect result (Bug #2182) # SELECT lpad(12345, 5, "#"); # -# Bug #2972 +# Problem the the CONV() function (Bug #2972) # SELECT conv(71, 10, 36), conv('1Z', 36, 10); - - # -# Bug #3089 +# Bug in SUBSTRING when mixed with CONCAT and ORDER BY (Bug #3089) # create table t1 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8; @@ -382,3 +380,13 @@ insert into t2 values (1,'cccccccccc'), (2,'dddddddddd'); select substring(concat(t1.str, t2.str), 1, 15) "name" from t1, t2 where t2.id=t1.id order by name; drop table t1, t2; + +# +# Test case for conversion of long string value to integer (Bug #3472) +# + +create table t1 (c1 INT); +insert into t1 (c1) values ('21474836461'); +show warnings; +select * from t1; +drop table t1; diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index cdaf6062771..4fa85477318 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -204,3 +204,15 @@ select i from t1 where a=repeat(_utf8 0xD0B1,200); select i from t1 where b=repeat(_utf8 'b',310); drop table t1; +# +# Test of key read with primary key (Bug #3497) +# + +CREATE TABLE t1 (id int unsigned auto_increment, name char(50), primary key (id)) engine=myisam; +insert into t1 (name) values ('a'), ('b'),('c'),('d'),('e'),('f'),('g'); +explain select 1 from t1 where id =2; +explain select 1 from t1 where id =2 or id=3; +explain select name from t1 where id =2; +ALTER TABLE t1 DROP PRIMARY KEY, ADD INDEX (id); +explain select 1 from t1 where id =2; +drop table t1; diff --git a/sql/item.cc b/sql/item.cc index 72583ea02bb..86acd2850c8 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1227,15 +1227,16 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table) void Item_field::make_field(Send_field *tmp_field) { field->make_field(tmp_field); + DBUG_ASSERT(tmp_field->table_name); if (name) tmp_field->col_name=name; // Use user supplied name } + /* -** Set a field:s value from a item + Set a field:s value from a item */ - void Item_field::save_org_in_field(Field *to) { if (field->is_null()) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index d24b13ff96f..75c7a779180 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1029,14 +1029,15 @@ bool reopen_table(TABLE *table,bool locked) *table=tmp; table->file->change_table_ptr(table); + DBUG_ASSERT(table->table_name); for (field=table->field ; *field ; field++) { - (*field)->table=table; + (*field)->table= (*field)->orig_table= table; (*field)->table_name=table->table_name; } for (key=0 ; key < table->keys ; key++) for (part=0 ; part < table->key_info[key].usable_key_parts ; part++) - table->key_info[key].key_part[part].field->table=table; + table->key_info[key].key_part[part].field->table= table; VOID(pthread_cond_broadcast(&COND_refresh)); error=0; diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 3d9299ca05c..f72fab9ea3a 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -529,8 +529,8 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, if (field->type() == FIELD_TYPE_TIMESTAMP) ((Field_timestamp*) field)->set_time(); else if (field != table->next_number_field) - field->set_warning((uint)MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_NULL_TO_NOTNULL); + field->set_warning((uint) MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_NULL_TO_NOTNULL); } continue; } @@ -1014,7 +1014,7 @@ bool READ_INFO::find_start_of_fields() { // Can't be line_start PUSH(chr); while (--ptr != line_start_ptr) - { // Restart with next char + { // Restart with next char PUSH((uchar) *ptr); } goto try_again; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d3867d1d909..977790aed16 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3630,6 +3630,12 @@ make_join_readinfo(JOIN *join, uint options) table->status=STATUS_NO_RECORD; tab->read_first_record= join_read_const; tab->read_record.read_record= join_no_more_records; + if (table->used_keys.is_set(tab->index) && + !table->no_keyread) + { + table->key_read=1; + table->file->extra(HA_EXTRA_KEYREAD); + } break; case JT_EQ_REF: table->status=STATUS_NO_RECORD; @@ -5951,6 +5957,12 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos) } else { + if (!table->key_read && table->used_keys.is_set(tab->index) && + !table->no_keyread) + { + table->key_read=1; + table->file->extra(HA_EXTRA_KEYREAD); + } if ((error=join_read_const(tab))) { tab->info="unique row not found"; @@ -9216,7 +9228,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, join->best_positions[i]. records_read, 21)); my_bool key_read=table->key_read; - if (tab->type == JT_NEXT && table->used_keys.is_set(tab->index)) + if ((tab->type == JT_NEXT || tab->type == JT_CONST) && + table->used_keys.is_set(tab->index)) key_read=1; if (tab->info) |