Commit 9996c3d8 authored by unknown's avatar unknown
Browse files

a fix.

bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs 


mysql-test/r/type_bit.result:
  test case.
  bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
  bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
  bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs
mysql-test/t/type_bit.test:
  test case.
  bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
  bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
  bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs
sql/field.h:
  a fix.
  bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
  bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
  bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs 
  
  - max_length() returns length in bits.
  - introduced set_bit_ptr() function, which sets bit_ptr and bit_ofs.
sql/item.cc:
  a fix.
  bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
  bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
  bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs
  
  - create Field_bit_as_char in case of MYSQL_TYPE_BIT in the Item::tmp_table_field_from_field_type()
    (we cannot create Field_bit here because of lack of information: bit_ptr, bit_ofs)
sql/mysql_priv.h:
  a fix.
  bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
  bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
  bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs 
  
  - table_cant_handle_bit_fields parameter added to the create_tmp_field()
sql/sql_select.cc:
  a fix.
  bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
  bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
  bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs
  
  - create_tmp_field() changes to return create_tmp_field_from_item() result 
    (actually, Field_bit_as_char) if table_cant_handle_bit_fields=1 for bit fields.
  - create_tmp_field() calls accordingly changed 
  - call set_bit_ptr() for bit fields after the move_field() call during 
    temporary table creation.
sql/sql_table.cc:
  a fix.
  bug #10617: Insert from same table to same table give incorrect result for bit(4) column.
  bug #11091: union involving BIT: assertion failure in Item::tmp_table_field_from_field_type
  bug #11572: MYSQL_TYPE_BIT not taken care of in temp. table creation for VIEWs
  
  - changed the create_tmp_field() call
parent 14ade135
Loading
Loading
Loading
Loading
+87 −0
Original line number Diff line number Diff line
@@ -466,3 +466,90 @@ select a+0 from t1;
a+0
255
drop table t1;
create table t1 (a bit(7));
insert into t1 values (120), (0), (111);
select a+0 from t1 union select a+0 from t1;
a+0
120
0
111
select a+0 from t1 union select NULL;
a+0
120
0
111
NULL
select NULL union select a+0 from t1;
NULL
NULL
120
0
111
create table t2 select a from t1 union select a from t1;
select a+0 from t2;
a+0
120
0
111
show create table t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `a` bit(7) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2;
create table t1 (id1 int(11), b1 bit(1));
create table t2 (id2 int(11), b2 bit(1));
insert into t1 values (1, 1), (2, 0), (3, 1);
insert into t2 values (2, 1), (3, 0), (4, 0);
create algorithm=undefined view v1 as 
select b1+0, b2+0 from t1, t2 where id1 = id2 and b1 = 0
union
select b1+0, b2+0 from t1, t2 where id1 = id2 and b2 = 1;
select * from v1;
b1+0	b2+0
0	1
drop table t1, t2;
drop view v1;
create table t1(a bit(4));
insert into t1(a) values (1), (2), (5), (4), (3);
insert into t1 select * from t1;
select a+0 from t1;
a+0
1
2
5
4
3
1
2
5
4
3
drop table t1;
create table t1 (a1 int(11), b1 bit(2));
create table t2 (a2 int(11), b2 bit(2));
insert into t1 values (1, 1), (2, 0), (3, 1), (4, 2);
insert into t2 values (2, 1), (3, 0), (4, 1), (5, 2);
select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2;
a1	a2	b1+0	b2+0
2	2	0	1
3	3	1	0
4	4	2	1
select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2 order by a1;
a1	a2	b1+0	b2+0
2	2	0	1
3	3	1	0
4	4	2	1
select a1, a2, b1+0, b2+0 from t1 join t2 on b1 = b2;
a1	a2	b1+0	b2+0
1	2	1	1
3	2	1	1
2	3	0	0
1	4	1	1
3	4	1	1
4	5	2	2
select sum(a1), b1+0, b2+0 from t1 join t2 on b1 = b2 group by b1 order by 1;
sum(a1)	b1+0	b2+0
2	0	0
4	2	2
8	1	1
+53 −0
Original line number Diff line number Diff line
@@ -171,3 +171,56 @@ create table t1 (a bit(8)) engine=heap;
insert into t1 values ('1111100000');
select a+0 from t1;
drop table t1;

#
# Bug #11091: union
#

create table t1 (a bit(7));
insert into t1 values (120), (0), (111);
select a+0 from t1 union select a+0 from t1;
select a+0 from t1 union select NULL;
select NULL union select a+0 from t1;
create table t2 select a from t1 union select a from t1;
select a+0 from t2;
show create table t2;
drop table t1, t2;

#
# Bug #11572: view
#

create table t1 (id1 int(11), b1 bit(1));
create table t2 (id2 int(11), b2 bit(1));
insert into t1 values (1, 1), (2, 0), (3, 1);
insert into t2 values (2, 1), (3, 0), (4, 0);
create algorithm=undefined view v1 as 
  select b1+0, b2+0 from t1, t2 where id1 = id2 and b1 = 0
  union
  select b1+0, b2+0 from t1, t2 where id1 = id2 and b2 = 1;
select * from v1;
drop table t1, t2;
drop view v1;

#
# Bug #10617: bulk-insert
#

create table t1(a bit(4));
insert into t1(a) values (1), (2), (5), (4), (3);
insert into t1 select * from t1;
select a+0 from t1;
drop table t1;

#
# join
#

create table t1 (a1 int(11), b1 bit(2));
create table t2 (a2 int(11), b2 bit(2));
insert into t1 values (1, 1), (2, 0), (3, 1), (4, 2);
insert into t2 values (2, 1), (3, 0), (4, 1), (5, 2);
select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2;
select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2 order by a1;
select a1, a2, b1+0, b2+0 from t1 join t2 on b1 = b2;
select sum(a1), b1+0, b2+0 from t1 join t2 on b1 = b2 group by b1 order by 1;
+7 −1
Original line number Diff line number Diff line
@@ -1288,7 +1288,7 @@ class Field_bit :public Field {
  enum_field_types type() const { return FIELD_TYPE_BIT; }
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
  uint32 key_length() const { return (uint32) field_length + (bit_len > 0); }
  uint32 max_length() { return (uint32) field_length + (bit_len > 0); }
  uint32 max_length() { return (uint32) field_length * 8 + bit_len; }
  uint size_of() const { return sizeof(*this); }
  Item_result result_type () const { return INT_RESULT; }
  void reset(void) { bzero(ptr, field_length); }
@@ -1320,6 +1320,11 @@ class Field_bit :public Field {
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
                       char *new_ptr, uchar *new_null_ptr,
                       uint new_null_bit);
  void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
  {
    bit_ptr= bit_ptr_arg;
    bit_ofs= bit_ofs_arg;
  }
};

  
@@ -1331,6 +1336,7 @@ class Field_bit_as_char: public Field_bit {
                    enum utype unireg_check_arg, const char *field_name_arg,
                    struct st_table *table_arg);
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
  uint32 max_length() { return (uint32) create_length; }
  uint size_of() const { return sizeof(*this); }
  int store(const char *to, uint length, CHARSET_INFO *charset);
  int store(double nr) { return Field_bit::store(nr); }
+3 −0
Original line number Diff line number Diff line
@@ -3347,6 +3347,9 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table)
  case MYSQL_TYPE_YEAR:
    return new Field_year((char*) 0, max_length, null_ptr, 0, Field::NONE,
			  name, table);
  case MYSQL_TYPE_BIT:
    return new Field_bit_as_char(NULL, max_length, null_ptr, 0, NULL, 0,
                                 Field::NONE, name, table);
  default:
    /* This case should never be chosen */
    DBUG_ASSERT(0);
+1 −0
Original line number Diff line number Diff line
@@ -667,6 +667,7 @@ int mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
			Item ***copy_func, Field **from_field,
			bool group, bool modify_item,
			bool table_cant_handle_bit_fields,
                        uint convert_blob_length);
void sp_prepare_create_field(THD *thd, create_field *sql_field);
int prepare_create_field(create_field *sql_field, 
Loading