[MCOL-4668] PERIOD_DIFF(dec_or_double1,dec_or_double2) is not as in InnoDB Created: 2021-04-06  Updated: 2021-04-09  Resolved: 2021-04-09

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: Daniel Lee (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MCOL-4361 Replace pow(10.0, (double)scale) expr... Closed

 Description   

The problem is repeatable with narrow decimal (in 5.6.1 and 6.1.1) and wide decimal (in 6.1.1).

Narrow decimal rounding

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(18,1)) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (200101.9);
SELECT PERIOD_DIFF(a, 200101) FROM t1;

+------------------------+
| PERIOD_DIFF(a, 200101) |
+------------------------+
|                      0 |
+------------------------+

Looks wrong. The expected result is:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(18,1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (200101.9);
SELECT PERIOD_DIFF(a, 200101) FROM t1;

+------------------------+
| PERIOD_DIFF(a, 200101) |
+------------------------+
|                      1 |
+------------------------+

Wide decimal rounding

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(30,1)) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (200101.9);
SELECT PERIOD_DIFF(a, 200101) FROM t1;

+------------------------+
| PERIOD_DIFF(a, 200101) |
+------------------------+
|                      0 |
+------------------------

Looks wrong. The expected result is:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(30,1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (200101.9);
SELECT PERIOD_DIFF(a, 200101) FROM t1;

+------------------------+
| PERIOD_DIFF(a, 200101) |
+------------------------+
|                      1 |
+------------------------+

Huge narrow decimal

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(18,0)) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (999999999999999999);
SELECT a, PERIOD_DIFF(200101,a) FROM t1;

+--------------------+-----------------------+
| a                  | PERIOD_DIFF(200101,a) |
+--------------------+-----------------------+
| 999999999999999999 |           -2147483648 |
+--------------------+-----------------------+

Looks wrong. The expected result is:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(18,0)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (999999999999999999);
SELECT a, PERIOD_DIFF(200101,a) FROM t1;

+--------------------+-----------------------+
| a                  | PERIOD_DIFF(200101,a) |
+--------------------+-----------------------+
| 999999999999999999 |                 24012 |
+--------------------+-----------------------+

Huge wide decimal

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(30,0)) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (999999999999999999);
SELECT a, PERIOD_DIFF(200101,a) FROM t1;

+--------------------+-----------------------+
| a                  | PERIOD_DIFF(200101,a) |
+--------------------+-----------------------+
| 999999999999999999 |           -2147483648 |
+--------------------+-----------------------+

Looks wrong. The expected result is:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(30,0)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (999999999999999999);
SELECT a, PERIOD_DIFF(200101,a) FROM t1;

+--------------------+-----------------------+
| a                  | PERIOD_DIFF(200101,a) |
+--------------------+-----------------------+
| 999999999999999999 |                 24012 |
+--------------------+-----------------------+

Huge double

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (9223372036854775807.0-1000);
INSERT INTO t1 VALUES (9223372036854775807.0+1000);
SELECT a, PERIOD_DIFF(200101,a) FROM t1 ORDER BY 2;

+----------------------+-----------------------+
| a                    | PERIOD_DIFF(200101,a) |
+----------------------+-----------------------+
| 9.223372036854775e18 |           -2147483648 |
| 9.223372036854776e18 |            2147483647 |
+----------------------+-----------------------+

Looks wrong. The expected result is:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DOUBLE) ENGINE=InnoDB;
INSERT INTO t1 VALUES (9223372036854775807.0-1000);
INSERT INTO t1 VALUES (9223372036854775807.0+1000);
SELECT a, PERIOD_DIFF(200101,a) FROM t1 ORDER BY 2;

+----------------------+-----------------------+
| a                    | PERIOD_DIFF(200101,a) |
+----------------------+-----------------------+
| 9.223372036854775e18 |                 24012 |
| 9.223372036854776e18 |                 24012 |
+----------------------+-----------------------+



 Comments   
Comment by Gagan Goel (Inactive) [ 2021-04-07 ]

For QA: Steps to reproduce the issue and verify the fix works are in the issue description.

Comment by Daniel Lee (Inactive) [ 2021-04-09 ]

Build verified: 6.1.1 ( Drone #2104 )

Only the first case was is reproducible in 5.5.2-1 since 5.5.2-1 did not support wide decimal.
Verified fixed in 6.1.1, matching the results from Innodb.

Comment by Daniel Lee (Inactive) [ 2021-04-09 ]

Reopened by mistake. I meant to close the ticket

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