[MCOL-4619] TreeNode::getUintVal() does not round: Implicit DECIMAL->UINT conversion is not like in InnoDB Created: 2021-03-17  Updated: 2021-03-30  Resolved: 2021-03-30

Status: Closed
Project: MariaDB ColumnStore
Component/s: PrimProc
Affects Version/s: 5.6.1, 6.1.1
Fix Version/s: 6.1.1

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MCOL-4361 Replace pow(10.0, (double)scale) expr... Closed
Relates
relates to MCOL-4627 SET int_col=decimal_col returns an error Open
relates to MCOL-4622 Implicit FLOAT->INT and DOUBLE->INT c... Open
relates to MCOL-4650 TreeNode::getIntVal() looses precisio... Closed

 Description   

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(32), d DECIMAL(10,1)) ENGINE=ColumnStore;
INSERT INTO t1 VALUES ('aaaa', 1.5);
SELECT LEFT(a, d) FROM t1;

+------------+
| LEFT(a, d) |
+------------+
| a          |
+------------+

Notice, 1.5 was truncated to 1.

Looks wrong. The expected result is to round:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(32), d DECIMAL(10,1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('aaaa', 1.5);
SELECT LEFT(a, d) FROM t1;

+------------+
| LEFT(a, d) |
+------------+
| aa         |
+------------+

Notice, 1.5 was rounded to 2.



 Comments   
Comment by Alexander Barkov [ 2021-03-22 ]

Note, explicit CAST works fine (rounds as expected):

SELECT CAST(d AS UNSIGNED) FROM t1;

+---------------------+
| CAST(d AS UNSIGNED) |
+---------------------+
|                   2 |
+---------------------+

Generated at Thu Feb 08 02:51:43 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.