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

Integer Truncation in create_bound() Silently Rewrites Impossible YEAR() Predicate

    XMLWordPrintable

Details

    Description

      CREATE TABLE t (
        id INT AUTO_INCREMENT PRIMARY KEY,
        ts DATETIME NOT NULL,
        INDEX idx_ts (ts)
      );
       
      INSERT INTO t (ts) VALUES
        ('2024-01-15 10:00:00'),
        ('2024-06-30 12:34:56'),
        ('2024-12-31 23:59:59');
       
      # Control: should return 3
      SELECT COUNT(*) AS count_year_2024 FROM t WHERE YEAR(ts) = 2024;
       
      # Bug trigger: 4294969320 = 2024 + 2^32; YEAR() can never return this
      # value, so 0 rows is correct. Due to the truncation bug, the optimizer
      # rewrites this to a range scan and returns 3 rows.
      SELECT COUNT(*) AS count_year_overflow FROM t WHERE YEAR(ts) = 4294969320;
      

      10.11 returns 0
      11.4+ returns 3

      Reported by: Yuelin Wang

      Attachments

        Issue Links

          Activity

            People

              oleg.smirnov Oleg Smirnov
              alice Alice Sherepa
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.