mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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
This commit is contained in:
@ -466,3 +466,90 @@ select a+0 from t1;
|
|||||||
a+0
|
a+0
|
||||||
255
|
255
|
||||||
drop table t1;
|
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');
|
insert into t1 values ('1111100000');
|
||||||
select a+0 from t1;
|
select a+0 from t1;
|
||||||
drop table 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_field_types type() const { return FIELD_TYPE_BIT; }
|
||||||
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
|
||||||
uint32 key_length() const { return (uint32) field_length + (bit_len > 0); }
|
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); }
|
uint size_of() const { return sizeof(*this); }
|
||||||
Item_result result_type () const { return INT_RESULT; }
|
Item_result result_type () const { return INT_RESULT; }
|
||||||
void reset(void) { bzero(ptr, field_length); }
|
void reset(void) { bzero(ptr, field_length); }
|
||||||
@ -1320,6 +1320,11 @@ public:
|
|||||||
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
|
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
|
||||||
char *new_ptr, uchar *new_null_ptr,
|
char *new_ptr, uchar *new_null_ptr,
|
||||||
uint new_null_bit);
|
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,
|
enum utype unireg_check_arg, const char *field_name_arg,
|
||||||
struct st_table *table_arg);
|
struct st_table *table_arg);
|
||||||
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
|
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); }
|
uint size_of() const { return sizeof(*this); }
|
||||||
int store(const char *to, uint length, CHARSET_INFO *charset);
|
int store(const char *to, uint length, CHARSET_INFO *charset);
|
||||||
int store(double nr) { return Field_bit::store(nr); }
|
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:
|
case MYSQL_TYPE_YEAR:
|
||||||
return new Field_year((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
return new Field_year((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
||||||
name, table);
|
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:
|
default:
|
||||||
/* This case should never be chosen */
|
/* This case should never be chosen */
|
||||||
DBUG_ASSERT(0);
|
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,
|
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
|
||||||
Item ***copy_func, Field **from_field,
|
Item ***copy_func, Field **from_field,
|
||||||
bool group, bool modify_item,
|
bool group, bool modify_item,
|
||||||
|
bool table_cant_handle_bit_fields,
|
||||||
uint convert_blob_length);
|
uint convert_blob_length);
|
||||||
void sp_prepare_create_field(THD *thd, create_field *sql_field);
|
void sp_prepare_create_field(THD *thd, create_field *sql_field);
|
||||||
int prepare_create_field(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,
|
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
|
||||||
Item ***copy_func, Field **from_field,
|
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) {
|
switch (type) {
|
||||||
case Item::SUM_FUNC_ITEM:
|
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:
|
case Item::DEFAULT_VALUE_ITEM:
|
||||||
{
|
{
|
||||||
Item_field *field= (Item_field*) 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),
|
return create_tmp_field_from_field(thd, (*from_field= field->field),
|
||||||
item->name, table,
|
item->name, table,
|
||||||
modify_item ? (Item_field*) item : NULL,
|
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=
|
Field *new_field=
|
||||||
create_tmp_field(thd, table, arg, arg->type(), ©_func,
|
create_tmp_field(thd, table, arg, arg->type(), ©_func,
|
||||||
tmp_from_field, group != 0,not_all_columns,
|
tmp_from_field, group != 0,not_all_columns,
|
||||||
|
group || distinct,
|
||||||
param->convert_blob_length);
|
param->convert_blob_length);
|
||||||
if (!new_field)
|
if (!new_field)
|
||||||
goto err; // Should be OOM
|
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_for_schema(thd, item, table) :
|
||||||
create_tmp_field(thd, table, item, type, ©_func,
|
create_tmp_field(thd, table, item, type, ©_func,
|
||||||
tmp_from_field, group != 0,
|
tmp_from_field, group != 0,
|
||||||
not_all_columns || group !=0,
|
not_all_columns || group != 0, 0,
|
||||||
param->convert_blob_length);
|
param->convert_blob_length);
|
||||||
|
|
||||||
if (!new_field)
|
if (!new_field)
|
||||||
@ -8377,6 +8383,13 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
field->move_field((char*) pos,(uchar*) 0,0);
|
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();
|
field->reset();
|
||||||
if (from_field[i])
|
if (from_field[i])
|
||||||
{ /* Not a table Item */
|
{ /* 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);
|
field=item->tmp_table_field(&tmp_table);
|
||||||
else
|
else
|
||||||
field=create_tmp_field(thd, &tmp_table, item, item->type(),
|
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 ||
|
if (!field ||
|
||||||
!(cr_field=new create_field(field,(item->type() == Item::FIELD_ITEM ?
|
!(cr_field=new create_field(field,(item->type() == Item::FIELD_ITEM ?
|
||||||
((Item_field *)item)->field :
|
((Item_field *)item)->field :
|
||||||
|
Reference in New Issue
Block a user