Bug #44951 Inconsistent result for "cast ... as char binary" (failure in main.cast)
Submitted: 19 May 2009 12:18 Modified: 3 Jul 2009 17:31
Reporter: Øystein Grøvlen Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Charsets Severity:S3 (Non-critical)
Version:6.0 bzr OS:Any
Assigned to: CPU Architecture:Any

[19 May 2009 12:18] Øystein Grøvlen
Description:
A new failure has recently occurred in main.cast.  (This test has been disabled for some time due to instability on Windows.)  If executed on head of 6.0, one gets the following diff:

@@ -402,7 +402,7 @@
 6100
 select hex(cast('a' as char(2) binary));
 hex(cast('a' as char(2) binary))
-61
+6100
 CREATE TABLE t1 (d1 datetime);
 INSERT INTO t1(d1) VALUES ('2007-07-19 08:30:00'), (NULL),
 ('2007-07-19 08:34:00'), (NULL), ('2007-07-19 08:36:00');

Note that at the point of failure the test has executed the following sequence
of statements:

set names latin1;
select hex(cast('a' as char(2) binary));
hex(cast('a' as char(2) binary))
61
select hex(cast('a' as binary(2)));
hex(cast('a' as binary(2)))
6100
select hex(cast('a' as char(2) binary));
hex(cast('a' as char(2) binary))
6100

Notice that the 3rd cast statement is the same as the first, but gives a different result.

How to repeat:
Remove cast from mysql-test/t/disabled.def, and run test.

Note that if you just run the sequence of statement run above, you may run into Bug#44950 instead.
[19 May 2009 15:57] Valeriy Kravchuk
Verified just as described:

valeriy-kravchuks-macbook-pro:mysql-test openxs$ ./mysql-test-run.pl cast
Logging: ./mysql-test-run.pl  cast
090519 18:55:29 [Warning] Setting lower_case_table_names=2 because file system for /var/folders/dX/dXCzvuSlHX4Op1g-o1jIWk+++TI/-Tmp-/nKbBx7PY1b/ is case insensitive
090519 18:55:29 [Warning] Forcing shutdown of 2 plugins
MySQL Version 6.0.12
Checking supported features...
 - using ndbcluster when necessary, mysqld supports it
 - SSL connections supported
 - binaries are debug compiled
Collecting tests...
vardir: /Users/openxs/dbs/6.0/mysql-test/var
Checking leftover processes...
Removing old var directory...
Creating var directory '/Users/openxs/dbs/6.0/mysql-test/var'...
Installing system database...
Using server port 54476

==============================================================================

TEST                                      RESULT   TIME (ms)
------------------------------------------------------------

worker[1] Using MTR_BUILD_THREAD 250, with reserved ports 12500..12509
main.cast                                [ fail ]
        Test ended at 2009-05-19 18:55:34

CURRENT_TEST: main.cast
--- /Users/openxs/dbs/6.0/mysql-test/r/cast.result	2009-05-14 18:13:45.000000000 +0300
+++ /Users/openxs/dbs/6.0/mysql-test/r/cast.reject	2009-05-19 18:55:34.000000000 +0300
@@ -380,7 +380,7 @@
 cast(s1 as decimal(7,2))
 99999.99
 Warnings:
-Error	1264	Out of range value for column 'cast(s1 as decimal(7,2))' at row 1
+Warning	1264	Out of range value for column 'cast(s1 as decimal(7,2))' at row 1
 drop table t1;
 CREATE TABLE t1 (v varchar(10), tt tinytext, t text,
 mt mediumtext, lt longtext);
@@ -402,7 +402,7 @@
 6100
 select hex(cast('a' as char(2) binary));
 hex(cast('a' as char(2) binary))
-61
+6100
 CREATE TABLE t1 (d1 datetime);
 INSERT INTO t1(d1) VALUES ('2007-07-19 08:30:00'), (NULL),
 ('2007-07-19 08:34:00'), (NULL), ('2007-07-19 08:36:00');

mysqltest: Result content mismatch
[3 Jul 2009 17:31] Øystein Grøvlen
The fix suggested in BUG#44950 also fixed this problem.