Commit 82e2d858 authored by Sergey Glukhov's avatar Sergey Glukhov

Bug#50591 bit(31) causes Duplicate entry '1-NULL' for key 'group_key'

The problem is that during temporary table creation uneven bits
are not taken into account for hidden fields. It leads to incorrect
calculation&allocation of null bytes size for table record. And
if grouped value is null we set wrong bit for this value(see end_update()).
Fixed by adding separate calculation of uneven bit for hidden fields.


mysql-test/r/type_bit.result:
  test case
mysql-test/t/type_bit.test:
  test case
sql/sql_select.cc:
  added separate calculation of uneven bit for hidden fields
parent 32058ba9
...@@ -785,4 +785,19 @@ t1 CREATE TABLE `t1` ( ...@@ -785,4 +785,19 @@ t1 CREATE TABLE `t1` (
KEY `a` (`a`) KEY `a` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
#
# Bug#50591 bit(31) causes Duplicate entry '1-NULL' for key 'group_key'
#
CREATE TABLE t1(a INT, b BIT(7) NOT NULL);
INSERT INTO t1 VALUES (NULL, 0),(NULL, 0);
SELECT SUM(a) FROM t1 GROUP BY b, a;
SUM(a)
NULL
DROP TABLE t1;
CREATE TABLE t1(a INT, b BIT(7) NOT NULL, c BIT(8) NOT NULL);
INSERT INTO t1 VALUES (NULL, 0, 0),(NULL, 0, 0);
SELECT SUM(a) FROM t1 GROUP BY c, b, a;
SUM(a)
NULL
DROP TABLE t1;
End of 5.1 tests End of 5.1 tests
...@@ -425,4 +425,17 @@ select hex(a) from t1; ...@@ -425,4 +425,17 @@ select hex(a) from t1;
show create table t1; show create table t1;
drop table t1; drop table t1;
--echo #
--echo # Bug#50591 bit(31) causes Duplicate entry '1-NULL' for key 'group_key'
--echo #
CREATE TABLE t1(a INT, b BIT(7) NOT NULL);
INSERT INTO t1 VALUES (NULL, 0),(NULL, 0);
SELECT SUM(a) FROM t1 GROUP BY b, a;
DROP TABLE t1;
CREATE TABLE t1(a INT, b BIT(7) NOT NULL, c BIT(8) NOT NULL);
INSERT INTO t1 VALUES (NULL, 0, 0),(NULL, 0, 0);
SELECT SUM(a) FROM t1 GROUP BY c, b, a;
DROP TABLE t1;
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -9822,7 +9822,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9822,7 +9822,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
KEY_PART_INFO *key_part_info; KEY_PART_INFO *key_part_info;
Item **copy_func; Item **copy_func;
MI_COLUMNDEF *recinfo; MI_COLUMNDEF *recinfo;
uint total_uneven_bit_length= 0; /*
total_uneven_bit_length is uneven bit length for visible fields
hidden_uneven_bit_length is uneven bit length for hidden fields
*/
uint total_uneven_bit_length= 0, hidden_uneven_bit_length= 0;
bool force_copy_fields= param->force_copy_fields; bool force_copy_fields= param->force_copy_fields;
/* Treat sum functions as normal ones when loose index scan is used. */ /* Treat sum functions as normal ones when loose index scan is used. */
save_sum_fields|= param->precomputed_group_by; save_sum_fields|= param->precomputed_group_by;
...@@ -10099,6 +10103,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -10099,6 +10103,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
*/ */
param->hidden_field_count= fieldnr; param->hidden_field_count= fieldnr;
null_count= 0; null_count= 0;
/*
On last hidden field we store uneven bit length in
hidden_uneven_bit_length and proceed calculation of
uneven bits for visible fields into
total_uneven_bit_length variable.
*/
hidden_uneven_bit_length= total_uneven_bit_length;
total_uneven_bit_length= 0;
} }
} }
DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field)); DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field));
...@@ -10144,7 +10156,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -10144,7 +10156,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
else else
null_count++; null_count++;
} }
hidden_null_pack_length=(hidden_null_count+7)/8; hidden_null_pack_length= (hidden_null_count + 7 +
hidden_uneven_bit_length) / 8;
null_pack_length= (hidden_null_pack_length + null_pack_length= (hidden_null_pack_length +
(null_count + total_uneven_bit_length + 7) / 8); (null_count + total_uneven_bit_length + 7) / 8);
reclength+=null_pack_length; reclength+=null_pack_length;
......
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