Bug #7589 Decimal types are ignored when updating data from another column
Submitted: 30 Dec 2004 13:41 Modified: 23 Sep 2005 16:26
Reporter: A.R. Nasir Qureshi Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.8-standard-log OS:Linux (Linux)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[30 Dec 2004 13:41] A.R. Nasir Qureshi
Description:
When updating from another column, the decimal types are ignored. 
create table test(a decimal(10,5), b decimal(10,1)) ;

insert into table test values(123.12345, 123.1) ;

select * from test ;
+-----------+-------+
| a         | b     |
+-----------+-------+
| 123.12345 | 123.1 |
+-----------+-------+
1 row in set (0.01 sec)

update test set b = a ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

select * from test ;
+-----------+-----------+
| a         | b         |
+-----------+-----------+
| 123.12345 | 123.12345 |
+-----------+-----------+
1 row in set (0.00 sec)

How to repeat:
create table test(a decimal(10,5), b decimal(10,1)) ;

insert into test values(123.12345, 123.12345) ;

select * from test ;
+-----------+-------+
| a         | b     |
+-----------+-------+
| 123.12345 | 123.1 |
+-----------+-------+
1 row in set (0.01 sec)

update test set b = a ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

select * from test ;
+-----------+-----------+
| a         | b         |
+-----------+-----------+
| 123.12345 | 123.12345 |
+-----------+-----------+
1 row in set (0.00 sec)

update test set b = 123.12345 ;

select * from test ;
+-----------+-------+
| a         | b     |
+-----------+-------+
| 123.12345 | 123.1 |
+-----------+-------+
1 row in set (0.00 sec)
[31 Dec 2004 13:12] A.R. Nasir Qureshi
Decimal types are also ignored when the table is altered. e.g. if a column with decimal(10,5) is changed to decimal(10,1) the data with the format of 10,5 remains in the records and is not changed to 10,1.
[16 Feb 2005 10:16] Alexander Barkov
Ramil, you added this comparision as a part of condition
when memcpy() is not possible:

to->real_type() != FIELD_TYPE_DECIMAL 

I suggest to allow memcpy for DECIMAL(N1,D1) and
DECIMAL(N2,D2) when  N1==N2 and D1==D2. This
addition check will be several times faster than 
converting into a number then back into internal
representation using  to->store(from->val_real());
[25 Mar 2005 8:15] Alexander Barkov
Ok to push.
[21 Sep 2005 9:33] 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/internals/30141
[21 Sep 2005 9:38] Ramil Kalimullin
fixed in 4.1.15
[23 Sep 2005 16:26] Paul DuBois
Noted in 4.1.15 changelog.