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

INTERVAL function returns inconsistent results when used in a WHERE clause

    XMLWordPrintable

Details

    • Bug
    • Status: In Progress (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.8.0, 10.5(EOL), 10.6(EOL), 10.11, 11.4, 11.8, 12.1(EOL)
    • 10.11, 11.4, 11.8
    • Optimizer, Server
    • git rev-parse HEAD
      11a6c1b30a12c448ddfe05e1b818a6a228e90e43

    Description

      Description: The behavior of the INTERVAL function is inconsistent when used in a SELECT query. The first query, which uses the INTERVAL function and selects columns, returns correct results. However, when the same INTERVAL function is used in the WHERE clause to filter the results, the query returns an empty set. These results should be consistent, but they are not.
      Steps to Reproduce:

      DROP TABLE IF EXISTS `t0`;
       
      CREATE TABLE `t0` (
        `c1` double,
        `c2` double
      );
      INSERT INTO `t0` VALUES (23,-16);
      

      query1:

      select distinct 
        subq_0.c_0 as c_0, 
        subq_0.c_1 as c_1, 
        subq_0.c_2 as c_2, 
        INTERVAL(subq_0.c_0,
                  subq_0.c_1,
                  subq_0.c_2) as c_7,
         (INTERVAL(subq_0.c_0,
                  subq_0.c_1,
                  subq_0.c_2)
                   > 0) as w_1
      from 
        (select distinct 
              ref_0.c1 as c_0, 
              ref_0.c2 as c_1,
              (ref_0.c2) / (ref_0.c1) as c_2
            from 
              t0 as ref_0
            ) as subq_0
      where  (INTERVAL(subq_0.c_0,
                  subq_0.c_1,
                  subq_0.c_2)) 
      

      output:

      +------+------+---------------------+-----+-----+
      | c_0  | c_1  | c_2                 | c_7 | w_1 |
      +------+------+---------------------+-----+-----+
      |   23 |  -16 | -0.6956521739130435 |   2 |   1 |
      +------+------+---------------------+-----+-----+
      1 row in set (0.00 sec)
      

      query2:

      select distinct 
        subq_0.c_0 as c_0, 
        subq_0.c_1 as c_1, 
        subq_0.c_2 as c_2, 
        INTERVAL(subq_0.c_0,
                  subq_0.c_1,
                  subq_0.c_2) as c_7,
         (INTERVAL(subq_0.c_0,
                  subq_0.c_1,
                  subq_0.c_2)
                   > 0) as w_1
      from 
        (select distinct 
              ref_0.c1 as c_0, 
              ref_0.c2 as c_1,
              (ref_0.c2) / (ref_0.c1) as c_2
            from 
              t0 as ref_0
            ) as subq_0
      where  (INTERVAL(subq_0.c_0,
                  subq_0.c_1,
                  subq_0.c_2)>0) 
      

      output:

      Empty set (0.00 sec)
      

      Expected Behavior:
      Both queries should return the same result
      Actual Behavior:
      but the second query returns an empty set, while the first query returns the expected row.

      Attachments

        Issue Links

          Activity

            People

              Johnston Rex Johnston
              orange chengzhiqiang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Time Spent - 7h Remaining Estimate - 1h
                  1h
                  Logged:
                  Time Spent - 7h Remaining Estimate - 1h
                  7h

                  Git Integration

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