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

Different results using table or view when comparing values of time type

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.4(EOL)
    • 10.4.0
    • Temporal Types
    • None

    Description

      10.4, reproducible after commit f6a20205148853f4cd352a21de3b77f2372ad50d

      CREATE TABLE t1 (pk int, x1 time, x2 varchar(1));
      INSERT INTO t1 VALUES (17,'09:16:37','k'),(70,'19:44:22','k');
      CREATE VIEW v1 AS SELECT * FROM t1;
       
      SELECT pk FROM t1 WHERE x1 >x2;
      SELECT pk FROM v1 WHERE x1 >x2;
      

      MariaDB [test2]> SELECT pk FROM t1 WHERE x1 >x2;
      +------+
      | pk   |
      +------+
      |   17 |
      |   70 |
      +------+
      2 rows in set, 2 warnings (0.002 sec)
      Warning (Code 1292): Truncated incorrect time value: 'k'
      Warning (Code 1292): Truncated incorrect time value: 'k'
       
      MariaDB [test2]> SELECT pk FROM v1 WHERE x1 >x2;
      Empty set, 2 warnings (0.004 sec)
       
      Warning (Code 1292): Truncated incorrect time value: 'k'
      Warning (Code 1292): Truncated incorrect time value: 'k'
      

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov added a comment - - edited

            The problem is repeatable in all versions starting from 5.5, but for an empty string in x2 (instead of garbage like 'k'):

            DROP TABLE IF EXISTS t1;
            DROP VIEW IF EXISTS v1;
            CREATE TABLE t1 (pk int, x1 time, x2 varchar(1));
            INSERT INTO t1 VALUES (17,'09:16:37','');
            CREATE VIEW v1 AS SELECT * FROM t1;
            SELECT pk FROM t1 WHERE x1 >x2;
            SELECT pk FROM v1 WHERE x1 >x2;
            

            The first SELECT returns:

            +------+
            | pk   |
            +------+
            |   17 |
            +------+
            1 row in set, 1 warning (0.00 sec)
            

            The second SELECT returns:

            Empty set, 1 warning (0.00 sec)
            

            The problem is also repeatable for DATETIME in all versions starting with 5.5, for both empty string and garbage:

            DROP TABLE IF EXISTS t1;
            DROP VIEW IF EXISTS v1;
            CREATE TABLE t1 (pk int, x1 datetime, x2 varchar(1));
            INSERT INTO t1 VALUES (17,'2001-01-01 09:16:37','');
            INSERT INTO t1 VALUES (18,'2001-01-01 09:16:37','k');
            CREATE VIEW v1 AS SELECT * FROM t1;
            SELECT pk FROM t1 WHERE x1 >x2;
            SELECT pk FROM v1 WHERE x1 >x2;
            

            The first SELECT returns two rows:

            +------+
            | pk   |
            +------+
            |   17 |
            |   18 |
            +------+
            2 rows in set, 2 warnings (0.00 sec)
            

            The second SELECT returns empty set.

            bar Alexander Barkov added a comment - - edited The problem is repeatable in all versions starting from 5.5, but for an empty string in x2 (instead of garbage like 'k'): DROP TABLE IF EXISTS t1; DROP VIEW IF EXISTS v1; CREATE TABLE t1 (pk int , x1 time , x2 varchar (1)); INSERT INTO t1 VALUES (17, '09:16:37' , '' ); CREATE VIEW v1 AS SELECT * FROM t1; SELECT pk FROM t1 WHERE x1 >x2; SELECT pk FROM v1 WHERE x1 >x2; The first SELECT returns: +------+ | pk | +------+ | 17 | +------+ 1 row in set, 1 warning (0.00 sec) The second SELECT returns: Empty set, 1 warning (0.00 sec) The problem is also repeatable for DATETIME in all versions starting with 5.5, for both empty string and garbage: DROP TABLE IF EXISTS t1; DROP VIEW IF EXISTS v1; CREATE TABLE t1 (pk int , x1 datetime, x2 varchar (1)); INSERT INTO t1 VALUES (17, '2001-01-01 09:16:37' , '' ); INSERT INTO t1 VALUES (18, '2001-01-01 09:16:37' , 'k' ); CREATE VIEW v1 AS SELECT * FROM t1; SELECT pk FROM t1 WHERE x1 >x2; SELECT pk FROM v1 WHERE x1 >x2; The first SELECT returns two rows: +------+ | pk | +------+ | 17 | | 18 | +------+ 2 rows in set, 2 warnings (0.00 sec) The second SELECT returns empty set.

            People

              bar Alexander Barkov
              alice Alice Sherepa
              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.