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

Wrong result for: bigint_column BETWEEN time_column AND str_literal

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Cannot Reproduce
    • 10.1(EOL), 10.2(EOL), 10.3(EOL)
    • N/A
    • Data types
    • None

    Description

      I run this script:

      CREATE OR REPLACE TABLE t1 (a TIME, b TIME);
      INSERT INTO t1 VALUES ('00:00:20','00:00:00');
      SELECT a BETWEEN b AND '10:00:00' FROM t1;
      

      +----------------------------+
      | a BETWEEN b AND '10:00:00' |
      +----------------------------+
      |                          1 |
      +----------------------------+
      

      It correctly returns 1, because comparison is done as TIME, and '00:00:20' is really between '00:00:00' AND '10:00:00'.

      Now I change the data type for the column a from TIME to INT. Nothing should change: INT, TIME and STRING arguments should be compared as TIME. So BETWEEN should still return 1.

      ALTER TABLE t1 MODIFY a INT;
      SELECT a BETWEEN b AND '10:00:00' FROM t1;
      

      +----------------------------+
      | a BETWEEN b AND '10:00:00' |
      +----------------------------+
      |                          1 |
      +----------------------------+
      

      Works fine so far.

      Now I change the data type for a from INT to BIGINT. Nothing should change. It should still return 1. However, something different happens:

      ALTER TABLE t1 MODIFY a BIGINT;
      SELECT a BETWEEN b AND '10:00:00' FROM t1;
      SHOW WARNINGS;
      

      +----------------------------+
      | a BETWEEN b AND '10:00:00' |
      +----------------------------+
      |                          0 |
      +----------------------------+
      

      +---------+------+----------------------------------------------+
      | Level   | Code | Message                                      |
      +---------+------+----------------------------------------------+
      | Warning | 1292 | Truncated incorrect DOUBLE value: '10:00:00' |
      +---------+------+----------------------------------------------+
      

      Notice, the result changed to 0, and now it returns a warning.
      The expected behavior would be to return 1 without warnings.

      Now if I wrap a into a function, it returns 1 again:

      SELECT COALESCE(a) BETWEEN b AND '10:00:00' FROM t1;
      

      +--------------------------------------+
      | COALESCE(a) BETWEEN b AND '10:00:00' |
      +--------------------------------------+
      |                                    1 |
      +--------------------------------------+
      

      Attachments

        Activity

          bar Alexander Barkov created issue -
          bar Alexander Barkov made changes -
          Field Original Value New Value
          bar Alexander Barkov made changes -
          Description
          {code:sql}
          CREATE OR REPLACE TABLE t1 (a TIME, b TIME);
          INSERT INTO t1 VALUES ('00:00:20','00:00:00');
          SELECT a BETWEEN b AND '10:00:00' FROM t1;
          {code}
          {noformat}
          +----------------------------+
          | a BETWEEN b AND '10:00:00' |
          +----------------------------+
          | 1 |
          +----------------------------+
          {noformat}


          Now I change the data type for the column {{a}} from {{TIME}} to {{INT}}. Nothing should change: {{INT}}, {{TIME}} and {{STRING}} arguments should be compared as {{TIME}}. So {{BETWEEN}} should still return {{1}}.
          {code:sql}
          ALTER TABLE t1 MODIFY a INT;
          SELECT a BETWEEN b AND '10:00:00' FROM t1;
          {code}
          {noformat}
          +----------------------------+
          | a BETWEEN b AND '10:00:00' |
          +----------------------------+
          | 1 |
          +----------------------------+
          {noformat}
          Works fine so far.

          Now I change the data type for {{a}} from {{INT}} to {{BIGINT}}. Nothing should change. It should still return {{1}}. However, something different happens:

          {code:sql}
          ALTER TABLE t1 MODIFY a BIGINT;
          SELECT a BETWEEN b AND '10:00:00' FROM t1;
          SHOW WARNINGS;
          {code}
          {noformat}
          +----------------------------+
          | a BETWEEN b AND '10:00:00' |
          +----------------------------+
          | 0 |
          +----------------------------+
          {noformat}
          {noformat}
          +---------+------+----------------------------------------------+
          | Level | Code | Message |
          +---------+------+----------------------------------------------+
          | Warning | 1292 | Truncated incorrect DOUBLE value: '10:00:00' |
          +---------+------+----------------------------------------------+
          {noformat}
          Notice, the result changed to {{0}}, and now it returns a warning.
          The expected behavior would be to return {{1}} without warnings.

          Now if I wrap {{a}} into a function, it returns {{1}} again:
          {code:sql}
          SELECT COALESCE(a) BETWEEN b AND '10:00:00' FROM t1;
          {code}
          {noformat}
          +--------------------------------------+
          | COALESCE(a) BETWEEN b AND '10:00:00' |
          +--------------------------------------+
          | 1 |
          +--------------------------------------+
          {noformat}
          I run this script:
          {code:sql}
          CREATE OR REPLACE TABLE t1 (a TIME, b TIME);
          INSERT INTO t1 VALUES ('00:00:20','00:00:00');
          SELECT a BETWEEN b AND '10:00:00' FROM t1;
          {code}
          {noformat}
          +----------------------------+
          | a BETWEEN b AND '10:00:00' |
          +----------------------------+
          | 1 |
          +----------------------------+
          {noformat}
          It correctly returns {{1}}, because comparison is done as {{TIME}}, and '{{00:00:20}}' is really between '{{00:00:00}}' AND '{{10:00:00}}'.

          Now I change the data type for the column {{a}} from {{TIME}} to {{INT}}. Nothing should change: {{INT}}, {{TIME}} and {{STRING}} arguments should be compared as {{TIME}}. So {{BETWEEN}} should still return {{1}}.
          {code:sql}
          ALTER TABLE t1 MODIFY a INT;
          SELECT a BETWEEN b AND '10:00:00' FROM t1;
          {code}
          {noformat}
          +----------------------------+
          | a BETWEEN b AND '10:00:00' |
          +----------------------------+
          | 1 |
          +----------------------------+
          {noformat}
          Works fine so far.

          Now I change the data type for {{a}} from {{INT}} to {{BIGINT}}. Nothing should change. It should still return {{1}}. However, something different happens:

          {code:sql}
          ALTER TABLE t1 MODIFY a BIGINT;
          SELECT a BETWEEN b AND '10:00:00' FROM t1;
          SHOW WARNINGS;
          {code}
          {noformat}
          +----------------------------+
          | a BETWEEN b AND '10:00:00' |
          +----------------------------+
          | 0 |
          +----------------------------+
          {noformat}
          {noformat}
          +---------+------+----------------------------------------------+
          | Level | Code | Message |
          +---------+------+----------------------------------------------+
          | Warning | 1292 | Truncated incorrect DOUBLE value: '10:00:00' |
          +---------+------+----------------------------------------------+
          {noformat}
          Notice, the result changed to {{0}}, and now it returns a warning.
          The expected behavior would be to return {{1}} without warnings.

          Now if I wrap {{a}} into a function, it returns {{1}} again:
          {code:sql}
          SELECT COALESCE(a) BETWEEN b AND '10:00:00' FROM t1;
          {code}
          {noformat}
          +--------------------------------------+
          | COALESCE(a) BETWEEN b AND '10:00:00' |
          +--------------------------------------+
          | 1 |
          +--------------------------------------+
          {noformat}
          bar Alexander Barkov made changes -
          Component/s Data types [ 13906 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.4 [ 22408 ]
          julien.fritsch Julien Fritsch made changes -
          Epic Link MDEV-21071 [ 80504 ]
          julien.fritsch Julien Fritsch made changes -
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 80606 ] MariaDB v4 [ 140292 ]
          alice Alice Sherepa added a comment -

          currently 10.3 (4e9206736c4032069)-10.11 return the correct result, 1, no warning.

          alice Alice Sherepa added a comment - currently 10.3 (4e9206736c4032069)-10.11 return the correct result, 1, no warning.
          alice Alice Sherepa made changes -
          Fix Version/s N/A [ 14700 ]
          Fix Version/s 10.3 [ 22126 ]
          Fix Version/s 10.4 [ 22408 ]
          Resolution Cannot Reproduce [ 5 ]
          Status Open [ 1 ] Closed [ 6 ]

          People

            bar Alexander Barkov
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

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