#At file:///Users/kgeorge/mysql/work/B57954-5.5-bugteam/ based on revid:davi.arnaut@stripped
3135 Georgi Kodinov 2010-12-01
Bug #57954: BIT_AND function returns incorrect results
when semijoin=on
When setting the aggregate function as having no rows to report
the function no_rows_in_result() was calling Item_sum::reset().
However this function in addition to cleaning up the aggregate
value by calling aggregator_clear() was also adding the current
value to the aggregate value by calling aggregator_add().
Fixed by making no_rows_in_result() to call aggregator_clear()
directly.
modified:
mysql-test/r/func_group_innodb.result
mysql-test/t/func_group_innodb.test
sql/item_sum.h
=== modified file 'mysql-test/r/func_group_innodb.result'
--- a/mysql-test/r/func_group_innodb.result 2007-05-29 12:58:18 +0000
+++ b/mysql-test/r/func_group_innodb.result 2010-12-01 15:58:30 +0000
@@ -145,3 +145,31 @@ select count(*), min(7), max(7) from t2m
count(*) min(7) max(7)
0 NULL NULL
drop table t1m, t1i, t2m, t2i;
+#
+# Bug #57954: BIT_AND function returns incorrect results when
+# semijoin=on
+CREATE TABLE C (
+pk INT,
+col_varchar_key VARCHAR(1),
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key)
+) ENGINE=InnoDB;
+INSERT INTO C VALUES (11,NULL);
+INSERT INTO C VALUES (16,'c');
+CREATE TABLE BB (
+pk INT,
+col_varchar_key VARCHAR(1),
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key)
+) ENGINE=InnoDB;
+INSERT INTO BB VALUES (10,NULL);
+SELECT straight_join BIT_AND(c.pk)
+FROM
+bb, c
+WHERE c.col_varchar_key='ABC'
+ORDER BY c.pk
+;
+BIT_AND(c.pk)
+18446744073709551615
+DROP TABLE C,BB;
+End of 5.5 tests
=== modified file 'mysql-test/t/func_group_innodb.test'
--- a/mysql-test/t/func_group_innodb.test 2006-05-22 11:27:58 +0000
+++ b/mysql-test/t/func_group_innodb.test 2010-12-01 15:58:30 +0000
@@ -83,3 +83,35 @@ explain select count(*), min(7), max(7)
select count(*), min(7), max(7) from t2m, t1i;
drop table t1m, t1i, t2m, t2i;
+
+
+--echo #
+--echo # Bug #57954: BIT_AND function returns incorrect results when
+--echo # semijoin=on
+
+CREATE TABLE C (
+ pk INT,
+ col_varchar_key VARCHAR(1),
+ PRIMARY KEY (pk),
+ KEY col_varchar_key (col_varchar_key)
+) ENGINE=InnoDB;
+INSERT INTO C VALUES (11,NULL);
+INSERT INTO C VALUES (16,'c');
+CREATE TABLE BB (
+ pk INT,
+ col_varchar_key VARCHAR(1),
+ PRIMARY KEY (pk),
+ KEY col_varchar_key (col_varchar_key)
+) ENGINE=InnoDB;
+INSERT INTO BB VALUES (10,NULL);
+
+SELECT straight_join BIT_AND(c.pk)
+FROM
+ bb, c
+ WHERE c.col_varchar_key='ABC'
+ORDER BY c.pk
+;
+
+DROP TABLE C,BB;
+
+--echo End of 5.5 tests
=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h 2010-08-30 07:36:04 +0000
+++ b/sql/item_sum.h 2010-12-01 15:58:30 +0000
@@ -446,7 +446,7 @@ public:
set_aggregator(with_distinct ?
Aggregator::DISTINCT_AGGREGATOR :
Aggregator::SIMPLE_AGGREGATOR);
- reset();
+ aggregator_clear();
}
virtual void make_unique() { force_copy_fields= TRUE; }
Item *get_tmp_table_item(THD *thd);
Attachment: [text/bzr-bundle] bzr/georgi.kodinov@oracle.com-20101201155830-ryjldoz91st64vlg.bundle