Bug #33663 Character sets: weight_string function, varchar column, wrong result
Submitted: 3 Jan 2008 17:37 Modified: 27 Mar 2008 18:56
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Charsets Severity:S3 (Non-critical)
Version:6.0.5-alpha-debug OS:Linux (SUSE 10 64-bit)
Assigned to: Alexander Barkov CPU Architecture:Any

[3 Jan 2008 17:37] Peter Gulutzan
Description:
I create a table with a VARCHAR column.
I insert two rows: NULL and 'a'.
I select, making sure to find NULL first.
The weight_string() function returns NULL twice.

How to repeat:
mysql> create table t (s1 varchar(5));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values ('a'),(null);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select hex(weight_string(s1)) from t order by s1;
+------------------------+
| hex(weight_string(s1)) |
+------------------------+
| NULL                   |
| NULL                   |
+------------------------+
2 rows in set (0.00 sec)
[3 Jan 2008 18:48] Valeriy Kravchuk
Thank you for a bug report. Without order by the results are correct:

mysql> create table t (s1 varchar(5));
Query OK, 0 rows affected (0.84 sec)

mysql> insert into t values ('a'),(null);
Query OK, 2 rows affected (0.16 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql>  select hex(weight_string(s1)) from t order by s1;
+------------------------+
| hex(weight_string(s1)) |
+------------------------+
| NULL                   |
| NULL                   |
+------------------------+
2 rows in set (0.09 sec)

mysql>  select hex(weight_string(s1)) from t;
+------------------------+
| hex(weight_string(s1)) |
+------------------------+
| 0041                   |
| NULL                   |
+------------------------+
2 rows in set (0.00 sec)
[17 Mar 2008 12:17] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/44105

ChangeSet@1.2597, 2008-03-17 16:12:11+04:00, bar@mysql.com +3 -0
  Bug#33663 Character sets: weight_string function, varchar column, wrong result
  Problem: null_value was checked before calling val_str(),
  so null_value corresponded NULL flag for the previous row.
  Fix: check null_value after calling val_str().
[18 Mar 2008 12:45] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/44173

ChangeSet@1.2597, 2008-03-18 16:40:33+04:00, bar@mysql.com +3 -0
  Bug#33663 Character sets: weight_string function, varchar column, wrong result
  Problem: null_value was checked before calling val_str(),
  so null_value corresponded NULL flag for the previous row.
  Fix: don't check null_value before calling val_str(),
  val_str itself returns NULL in case of NULL result.
[18 Mar 2008 13:00] Alexander Barkov
Pushed into 6.0.5-engines
[27 Mar 2008 17:49] Bugs System
Pushed into 6.0.5-alpha
[27 Mar 2008 18:56] Paul DuBois
Noted in 6.0.5 changelog.

The WEIGHT_STRING() function returned incorrect results for column
values when earlier column values were NULL.