Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-39646

Logic bug: Numeric TIME(6) cast rejects 0.999999

    XMLWordPrintable

Details

    Description

      The valid fractional boundary `0.999999` is accepted by the string-to-time
      conversion path but rejected by the numeric conversion path. Adjacent value
      `0.999998` is included to show the boundary behavior. The two conversion paths
      should agree for valid fractional time values, but MariaDB returns `NULL` and a
      warning for the numeric cast at this boundary.

      DROP DATABASE IF EXISTS db;
      CREATE DATABASE db;
      USE db;
       
      CREATE TABLE t (
        id INT PRIMARY KEY,
        p INT NOT NULL,
        o INT NOT NULL,
        v INT NOT NULL,
        od DECIMAL(20,10) NOT NULL
      );
       
      INSERT INTO t VALUES
        (1, 1, 1, 10, 0.999999),
        (2, 1, 2, 20, 0.999998);
       
      SELECT 'scalar_compare' AS phase;
      SELECT id,
             CAST(od AS TIME(6)) AS num_cast,
             CAST(CAST(od AS CHAR) AS TIME(6)) AS char_cast
      FROM t
      ORDER BY id;
      SHOW WARNINGS;
       
      SELECT 'numeric_cast_query' AS phase;
      SELECT id,
             ROW_NUMBER() OVER (PARTITION BY p ORDER BY o) AS rn,
             CAST(od AS TIME(6)) AS tm
      FROM t
      ORDER BY id;
      SHOW WARNINGS;
       
      SELECT 'string_cast_query' AS phase;
      SELECT t1.id,
             (SELECT COUNT(*) FROM t AS t2 WHERE t2.p = t1.p AND t2.o <= t1.o) AS rn,
             CAST(CAST(t1.od AS CHAR) AS TIME(6)) AS tm
      FROM t AS t1
      ORDER BY t1.id;
      SHOW WARNINGS;
       
      DROP DATABASE db;
      

      Expected Result

      Numeric and stringified casts should agree for valid fractional time values.

      Actual Result

      The numeric cast returns `NULL` with a warning for `0.999999`; the stringified
      reference returns `00:00:00.999999`.

      Attachments

        Activity

          People

            bar Alexander Barkov
            imchifan 刘启帆
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.