Fix for bug #28631: Bit index creation failure after alter

Problem: altering a bit field we use Field::is_equal() to check if the bit 
field is changed. Comparing the field type is not enough for bit fields.
Fix: add proper Field_bit::is_equal() that compares the field lengths as well.
parent 8a9fd599
......@@ -619,3 +619,29 @@ bit_field int_field
handler t1 close;
drop table t1;
End of 5.0 tests
create table t1(a bit(7));
insert into t1 values(0x40);
alter table t1 modify column a bit(8);
select hex(a) from t1;
hex(a)
40
insert into t1 values(0x80);
select hex(a) from t1;
hex(a)
40
80
create index a on t1(a);
insert into t1 values(0x81);
select hex(a) from t1;
hex(a)
40
80
81
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bit(8) DEFAULT NULL,
KEY `a` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
End of 5.1 tests
......@@ -273,3 +273,20 @@ handler t1 close;
drop table t1;
--echo End of 5.0 tests
#
# Bug #28631: problem after alter
#
create table t1(a bit(7));
insert into t1 values(0x40);
alter table t1 modify column a bit(8);
select hex(a) from t1;
insert into t1 values(0x80);
select hex(a) from t1;
create index a on t1(a);
insert into t1 values(0x81);
select hex(a) from t1;
show create table t1;
drop table t1;
--echo End of 5.1 tests
......@@ -8239,6 +8239,13 @@ Field *Field_bit::new_key_field(MEM_ROOT *root,
}
uint Field_bit::is_equal(create_field *new_field)
{
return (new_field->sql_type == real_type() &&
new_field->length == max_display_length());
}
int Field_bit::store(const char *from, uint length, CHARSET_INFO *cs)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
......
......@@ -1552,6 +1552,7 @@ public:
bit_ptr == ((Field_bit *)field)->bit_ptr &&
bit_ofs == ((Field_bit *)field)->bit_ofs);
}
uint is_equal(create_field *new_field);
void move_field_offset(my_ptrdiff_t ptr_diff)
{
Field::move_field_offset(ptr_diff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment