Bug #1788 The BIT_xxx() aggregate function behaviour changed in 4.1 - intentional or not?
Submitted: 9 Nov 2003 23:51 Modified: 16 Dec 2003 19:02
Reporter: Arjen Lentz Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1 OS:Any (any)
Assigned to: CPU Architecture:Any

[9 Nov 2003 23:51] Arjen Lentz
Description:
The behaviour of BIT_AND() and the other BIT_aggregate functions has apparently changed between 4.0 and 4.1

Upto version 4.0, they return signed values, which is as it is documented.
For instance, BIT_AND() returned -1 for an empty set.

In version 4.1, BIT_AND() returns 18446744073709551615 which is the same value (BIGINT/longlong) but unsigned.

How to repeat:
Run the below in 4.0 resp 4.1 and spot the differences:

CREATE TABLE t (i INT);
SELECT BIT_AND(i),BIT_OR(i),BIT_XOR(i) FROM t;

Suggested fix:
Either this change needs to be reverted to 4.0 behaviour, or the change needs to be documented.
So a decision needs to be made first on which is the proper behaviour!
[10 Nov 2003 1:26] Arjen Lentz
The 4.0.13 changeset comments note:
 - BIT_AND() and BIT_OR() now return an unsigned 64 bit value.

Looking at the current 4.0 tests in the bk tree, this is NOT the case.
So perhaps this change was moved to 4.1 but the changeset comment stayed?

This should also be fixed, once it's clear how things should be...
[16 Dec 2003 13:58] Peter Gulutzan
There has been extensive discussion of this matter within MySQL. The apparently-final 
decision is that BIT_AND should return an unsigned number, and this fact is reflected in 
the manual.