Commit 9996c3d8 authored by unknown's avatar unknown

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
......@@ -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
......@@ -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;
......@@ -1288,7 +1288,7 @@ public:
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 @@ public:
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 @@ public:
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); }
......
......@@ -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);
......
......@@ -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,
......
......@@ -7957,7 +7957,9 @@ Field *create_tmp_field_for_schema(THD *thd, Item *item, TABLE *table)
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
Item ***copy_func, Field **from_field,
bool group, bool modify_item, uint convert_blob_length)
bool group, bool modify_item,
bool table_cant_handle_bit_fields,
uint convert_blob_length)
{
switch (type) {
case Item::SUM_FUNC_ITEM:
......@@ -7972,6 +7974,9 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
case Item::DEFAULT_VALUE_ITEM:
{
Item_field *field= (Item_field*) item;
if (table_cant_handle_bit_fields && field->field->type() == FIELD_TYPE_BIT)
return create_tmp_field_from_item(thd, item, table, copy_func,
modify_item, convert_blob_length);
return create_tmp_field_from_field(thd, (*from_field= field->field),
item->name, table,
modify_item ? (Item_field*) item : NULL,
......@@ -8192,6 +8197,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
Field *new_field=
create_tmp_field(thd, table, arg, arg->type(), &copy_func,
tmp_from_field, group != 0,not_all_columns,
group || distinct,
param->convert_blob_length);
if (!new_field)
goto err; // Should be OOM
......@@ -8239,7 +8245,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
create_tmp_field_for_schema(thd, item, table) :
create_tmp_field(thd, table, item, type, &copy_func,
tmp_from_field, group != 0,
not_all_columns || group !=0,
not_all_columns || group != 0, 0,
param->convert_blob_length);
if (!new_field)
......@@ -8377,6 +8383,13 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
else
field->move_field((char*) pos,(uchar*) 0,0);
if (field->type() == FIELD_TYPE_BIT)
{
/* We have to reserve place for extra bits among null bits */
((Field_bit*) field)->set_bit_ptr(null_flags + null_count / 8,
null_count & 7);
null_count+= (field->field_length & 7);
}
field->reset();
if (from_field[i])
{ /* Not a table Item */
......
......@@ -1734,7 +1734,7 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
field=item->tmp_table_field(&tmp_table);
else
field=create_tmp_field(thd, &tmp_table, item, item->type(),
(Item ***) 0, &tmp_field,0,0,0);
(Item ***) 0, &tmp_field, 0, 0, 0, 0);
if (!field ||
!(cr_field=new create_field(field,(item->type() == Item::FIELD_ITEM ?
((Item_field *)item)->field :
......
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