Skip to content

Commit 2104e9e

Browse files
group_by.result, group_by.test:
Added a test case for bug #11295. item_buff.cc: Fixed bug #11295. This a correction for the patch of bug #11088 that takes into account a possible NULL values of the BLOB column.
1 parent acc6651 commit 2104e9e

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

mysql-test/r/group_by.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,3 +741,13 @@ SELECT dt DIV 1 AS f, id FROM t1 GROUP BY f;
741741
f id
742742
20050501123000 1
743743
DROP TABLE t1;
744+
CREATE TABLE t1 (id varchar(20) NOT NULL);
745+
INSERT INTO t1 VALUES ('trans1'), ('trans2');
746+
CREATE TABLE t2 (id varchar(20) NOT NULL, err_comment blob NOT NULL);
747+
INSERT INTO t2 VALUES ('trans1', 'a problem');
748+
SELECT COUNT(DISTINCT(t1.id)), LEFT(err_comment, 256) AS err_comment
749+
FROM t1 LEFT JOIN t2 ON t1.id=t2.id GROUP BY err_comment;
750+
COUNT(DISTINCT(t1.id)) err_comment
751+
1 NULL
752+
1 a problem
753+
DROP TABLE t1, t2;

mysql-test/t/group_by.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,18 @@ INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' );
565565
SELECT dt DIV 1 AS f, id FROM t1 GROUP BY f;
566566

567567
DROP TABLE t1;
568+
569+
#
570+
# Test for bug #11295: GROUP BY a BLOB column with COUNT(DISTINCT column1)
571+
# when the BLOB column takes NULL values
572+
#
573+
574+
CREATE TABLE t1 (id varchar(20) NOT NULL);
575+
INSERT INTO t1 VALUES ('trans1'), ('trans2');
576+
CREATE TABLE t2 (id varchar(20) NOT NULL, err_comment blob NOT NULL);
577+
INSERT INTO t2 VALUES ('trans1', 'a problem');
578+
579+
SELECT COUNT(DISTINCT(t1.id)), LEFT(err_comment, 256) AS err_comment
580+
FROM t1 LEFT JOIN t2 ON t1.id=t2.id GROUP BY err_comment;
581+
582+
DROP TABLE t1, t2;

sql/item_buff.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ bool Item_str_buff::cmp(void)
5151
String *res;
5252
bool tmp;
5353

54-
res=item->val_str(&tmp_value);
55-
res->length(min(res->length(), value.alloced_length()));
54+
if ((res=item->val_str(&tmp_value)))
55+
res->length(min(res->length(), value.alloced_length()));
5656
if (null_value != item->null_value)
5757
{
5858
if ((null_value= item->null_value))

0 commit comments

Comments
 (0)