Description:
A source value that has trailing spaces which
would fit into a VARCHAR target should not
have the trailing spaces stripped, as is currently
the case when the table uses the InnoDB
storage engine. MyISAM tables do this correctly.
How to repeat:
mysql> create table t1 (col2 varchar(5)) engine=innodb;
Query OK, 0 rows affected (0.02 sec)
mysql> insert into t1 (col2) values('hello');
Query OK, 1 row affected (0.00 sec)
-- size should be 5, source is exactly 5 characters long
mysql> insert into t1 (col2) values('hi');
Query OK, 1 row affected (0.00 sec)
-- size should be 2, source is exactly 2 characters long
mysql> insert into t1 (col2) values('hi o');
Query OK, 1 row affected (0.00 sec)
-- size should be 5, source is exactly 5 characters long
mysql> insert into t1 (col2) values('hi o ');
Query OK, 1 row affected (0.01 sec)
-- size should be 5, source is 6 characters long but the trailing
space that would make the value too long for the column
may be stripped
mysql> insert into t1 (col2) values('h5 ');
Query OK, 1 row affected (0.00 sec)
-- size should be 5, source is exactly 5 characters long,
including the trailing spaces which must not be stripped
mysql> insert into t1 (col2) values('h6 ');
Query OK, 1 row affected (0.00 sec)
-- size should be 5, source is 6 characters long, but
the 6th character is a trailing space that may be stripped
because it makes the value too big for the column. The rest
of the trailing spaces may not be stripped.
mysql> select col2,char_length(col2) from t1;
+-------+-------------------+
| col2 | char_length(col2) |
+-------+-------------------+
| hello | 5 |
| hi | 2 |
| hi o | 5 |
| hi o | 5 |
| h5 | 2 |
| h6 | 2 |
+-------+-------------------+
6 rows in set (0.00 sec)
-- should return char_length of 5,2,5,5,5,5
Note that the final two examples are not treated correctly.