3438 Jorgen Loland 2011-09-26
BUG#12837714: ADDITIONAL NULL IN 5.6 ON GROUPED SELECT
The bug was that Cached_item_field::cmp() did not do proper
NULL checking: if both buff and the field values were NULL,
the result was based on bitwise field comparison. Since a
field with NULL value may contain random bits, buff and
field were considered different in this case.
The fix is to handle the case where both are NULL: the
returned value from the function is now that they are equal.
Note: there are four more Cached_item_* classes: For the int,
real and decimal versions it is OK to compare cached value
to the new value because val_int/decimal/real() return 0 if
the value is NULL. For the string cached item, we get the
same issue as with Cached_item_field but for this class the
case where cached value and new value are both NULL is already
handled.
@ mysql-test/r/group_by.result
Add regression test for bug 12837714
@ mysql-test/t/group_by.test
Add regression test for bug 12837714
@ sql/item_buff.cc
Fixed Cached_item_field::cmp() to handle the case where both cached and new field value is NULL.
@ sql/table.cc
Remove dead code
modified:
mysql-test/r/group_by.result
mysql-test/t/group_by.test
sql/item_buff.cc
sql/table.cc
3437 Tor Didriksen 2011-09-26 [merge]
merge 5.5 => trunk
modified:
mysql-test/r/func_str.result
mysql-test/t/func_str.test
=== modified file 'mysql-test/r/group_by.result'
--- a/mysql-test/r/group_by.result 2011-09-13 07:22:49 +0000
+++ b/mysql-test/r/group_by.result 2011-09-26 13:48:06 +0000
@@ -2108,3 +2108,17 @@ pk
DROP VIEW v1;
DROP TABLE t1,t2;
# End of Bug#12798270
+#
+# Bug#12837714: ADDITIONAL NULL IN 5.6 ON GROUPED SELECT
+#
+CREATE TABLE t1 (vc varchar(1), INDEX vc_idx (vc)) ;
+INSERT INTO t1 VALUES (NULL), ('o'), (NULL), ('p'), ('c');
+FLUSH TABLE t1;
+SELECT vc FROM t1 GROUP BY vc;
+vc
+NULL
+c
+o
+p
+DROP TABLE t1;
+# End of Bug#12837714
=== modified file 'mysql-test/t/group_by.test'
--- a/mysql-test/t/group_by.test 2011-08-30 09:01:05 +0000
+++ b/mysql-test/t/group_by.test 2011-09-26 13:48:06 +0000
@@ -1468,3 +1468,17 @@ DROP TABLE t1,t2;
--echo # End of Bug#12798270
+--echo #
+--echo # Bug#12837714: ADDITIONAL NULL IN 5.6 ON GROUPED SELECT
+--echo #
+
+CREATE TABLE t1 (vc varchar(1), INDEX vc_idx (vc)) ;
+INSERT INTO t1 VALUES (NULL), ('o'), (NULL), ('p'), ('c');
+
+FLUSH TABLE t1;
+
+SELECT vc FROM t1 GROUP BY vc;
+
+DROP TABLE t1;
+
+--echo # End of Bug#12837714
=== modified file 'sql/item_buff.cc'
--- a/sql/item_buff.cc 2011-06-30 15:50:45 +0000
+++ b/sql/item_buff.cc 2011-09-26 13:48:06 +0000
@@ -137,16 +137,34 @@ bool Cached_item_int::cmp(void)
bool Cached_item_field::cmp(void)
{
DBUG_ENTER("Cached_item_field::cmp");
- bool tmp= field->cmp(buff) != 0; // This is not a blob!
DBUG_EXECUTE("info", dbug_print(););
- if (tmp)
- field->get_image(buff,length,field->charset());
- if (null_value != field->is_null())
+
+ bool different= false;
+
+ if (field->is_null())
+ {
+ if (!null_value)
+ {
+ different= true;
+ null_value= true;
+ }
+ }
+ else
{
- null_value= !null_value;
- tmp=TRUE;
+ if (null_value)
+ {
+ different= true;
+ null_value= false;
+ field->get_image(buff, length, field->charset());
+ }
+ else if (field->cmp(buff)) // Not a blob: cmp() is OK
+ {
+ different= true;
+ field->get_image(buff, length, field->charset());
+ }
}
- DBUG_RETURN(tmp);
+
+ DBUG_RETURN(different);
}
=== modified file 'sql/table.cc'
--- a/sql/table.cc 2011-08-26 13:26:33 +0000
+++ b/sql/table.cc 2011-09-26 13:48:06 +0000
@@ -1981,9 +1981,6 @@ int open_table_from_share(THD *thd, TABL
{
memcpy(outparam->record[0], share->default_values, share->rec_buff_length);
memcpy(outparam->record[1], share->default_values, share->null_bytes);
- if (records > 2)
- memcpy(outparam->record[1], share->default_values,
- share->rec_buff_length);
}
#endif
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-trunk branch (jorgen.loland:3437 to 3438) Bug#12837714 | Jorgen Loland | 26 Sep |