Commit 4ce563e0 authored by Sergey Glukhov's avatar Sergey Glukhov

Bug#31399 Wrong query result when doing join buffering over BIT fields

if table has bit fields then uneven bits(if exist) are stored into null bits place.
So we need to copy null bits in case of uneven bit field presence.


mysql-test/r/type_bit.result:
  test result
mysql-test/t/type_bit.test:
  test case
sql/sql_select.cc:
  if table has bit fields then uneven bits(if exist) are stored into null bits place.
  So we need to copy null bits in case of uneven bit field presence.
parent 419e053a
...@@ -723,4 +723,30 @@ CREATE TABLE IF NOT EXISTS t1 ( ...@@ -723,4 +723,30 @@ CREATE TABLE IF NOT EXISTS t1 (
f1 bit(2) NOT NULL default b'' f1 bit(2) NOT NULL default b''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
ERROR 42000: Invalid default value for 'f1' ERROR 42000: Invalid default value for 'f1'
create table t1bit7 (a1 bit(7) not null) engine=MyISAM;
create table t2bit7 (b1 bit(7)) engine=MyISAM;
insert into t1bit7 values (b'1100000');
insert into t1bit7 values (b'1100001');
insert into t1bit7 values (b'1100010');
insert into t2bit7 values (b'1100001');
insert into t2bit7 values (b'1100010');
insert into t2bit7 values (b'1100110');
select bin(a1) from t1bit7, t2bit7 where t1bit7.a1=t2bit7.b1;
bin(a1)
1100001
1100010
drop table t1bit7, t2bit7;
create table t1bit7 (a1 bit(15) not null) engine=MyISAM;
create table t2bit7 (b1 bit(15)) engine=MyISAM;
insert into t1bit7 values (b'110000011111111');
insert into t1bit7 values (b'110000111111111');
insert into t1bit7 values (b'110001011111111');
insert into t2bit7 values (b'110000111111111');
insert into t2bit7 values (b'110001011111111');
insert into t2bit7 values (b'110011011111111');
select bin(a1) from t1bit7, t2bit7 where t1bit7.a1=t2bit7.b1;
bin(a1)
110000111111111
110001011111111
drop table t1bit7, t2bit7;
End of 5.0 tests End of 5.0 tests
...@@ -367,4 +367,34 @@ CREATE TABLE IF NOT EXISTS t1 ( ...@@ -367,4 +367,34 @@ CREATE TABLE IF NOT EXISTS t1 (
f1 bit(2) NOT NULL default b'' f1 bit(2) NOT NULL default b''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
#
# Bug#31399 Wrong query result when doing join buffering over BIT fields
#
create table t1bit7 (a1 bit(7) not null) engine=MyISAM;
create table t2bit7 (b1 bit(7)) engine=MyISAM;
insert into t1bit7 values (b'1100000');
insert into t1bit7 values (b'1100001');
insert into t1bit7 values (b'1100010');
insert into t2bit7 values (b'1100001');
insert into t2bit7 values (b'1100010');
insert into t2bit7 values (b'1100110');
select bin(a1) from t1bit7, t2bit7 where t1bit7.a1=t2bit7.b1;
drop table t1bit7, t2bit7;
create table t1bit7 (a1 bit(15) not null) engine=MyISAM;
create table t2bit7 (b1 bit(15)) engine=MyISAM;
insert into t1bit7 values (b'110000011111111');
insert into t1bit7 values (b'110000111111111');
insert into t1bit7 values (b'110001011111111');
insert into t2bit7 values (b'110000111111111');
insert into t2bit7 values (b'110001011111111');
insert into t2bit7 values (b'110011011111111');
select bin(a1) from t1bit7, t2bit7 where t1bit7.a1=t2bit7.b1;
drop table t1bit7, t2bit7;
--echo End of 5.0 tests --echo End of 5.0 tests
...@@ -13233,6 +13233,7 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) ...@@ -13233,6 +13233,7 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count)
length=0; length=0;
for (i=0 ; i < table_count ; i++) for (i=0 ; i < table_count ; i++)
{ {
bool have_bit_fields= FALSE;
uint null_fields=0,used_fields; uint null_fields=0,used_fields;
Field **f_ptr,*field; Field **f_ptr,*field;
...@@ -13247,13 +13248,16 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) ...@@ -13247,13 +13248,16 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count)
length+=field->fill_cache_field(copy); length+=field->fill_cache_field(copy);
if (copy->blob_field) if (copy->blob_field)
(*blob_ptr++)=copy; (*blob_ptr++)=copy;
if (field->maybe_null()) if (field->real_maybe_null())
null_fields++; null_fields++;
if (field->type() == MYSQL_TYPE_BIT &&
((Field_bit*)field)->bit_len)
have_bit_fields= TRUE;
copy++; copy++;
} }
} }
/* Copy null bits from table */ /* Copy null bits from table */
if (null_fields && tables[i].table->s->null_fields) if (null_fields || have_bit_fields)
{ /* must copy null bits */ { /* must copy null bits */
copy->str=(char*) tables[i].table->null_flags; copy->str=(char*) tables[i].table->null_flags;
copy->length= tables[i].table->s->null_bytes; copy->length= tables[i].table->s->null_bytes;
......
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