Bug #10577 Bit_Count does not work properly with variables having binary value.
Submitted: 12 May 2005 9:37 Modified: 13 May 2005 8:36
Reporter: Disha Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.5 Beta OS:Windows (Windows 2000 Server)
Assigned to: CPU Architecture:Any

[12 May 2005 9:37] Disha
Description:
If a variable that contains a binary value is passed to the Bit_Count function then incorrect result is displayed.

How to repeat:
1. Start the MySQL client and connect to the database with valid user and password.
2. Set the delimiter to //
3. Set a variable to a bit value as follows:
   set @a=b'1010'//
4. Now execute the following command:
   select bit_count(@a)//

Expected Results: 
1. The output of bit_count function should be 2.

Actual Results: 
1. The output of the bit_count function is 0.
2. If we pass a binary value to the function then correct result is retrieved. The following is the example for the same
mysql> select bit_count(b'1010')//
   +--------------------+
   | bit_count(b'1010') |
   +--------------------+
   |                  2 |
   +--------------------+
   1 row in set (0.00 sec)
  
3. Check the following output of various ways tried.

   mysql> select bit_count(@a)//
   +---------------+
   | bit_count(@a) |
   +---------------+
   |             0 |
   +---------------+
   1 row in set (0.00 sec)
   mysql> select bit_count(bin(@a+0))//
   +----------------------+
   | bit_count(bin(@a+0)) |
   +----------------------+
   |                    0 |
   +----------------------+
   1 row in set (0.00 sec)
   mysql> select bit_count(bin(@a))//
   +--------------------+
   | bit_count(bin(@a)) |
   +--------------------+
   |                  0 |
   +--------------------+
   1 row in set (0.00 sec)
   mysql>
[12 May 2005 10:10] MySQL Verification Team
Verified on Linux.
[13 May 2005 8:36] Sergei Golubchik
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

because b'...' returns a *string* the correct query would be

 select bit_count(ascii(@a));