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

Comparing an indexed column against a constant may return wrong results when the constant is rounded

    XMLWordPrintable

Details

    • Unexpected results
    • Q4/2026 Server Development

    Description

      When querying an indexed integer column with a decimal constant, MariaDB returns rows matching the rounded value. When the index is not used it behaves as expected.

      CREATE TABLE t1 (i INT, KEY(i));
      INSERT INTO t1 VALUES (46),(47),(48);
       
      -- Wrong: returns 47 (expected: empty result)
      SELECT i FROM t1 WHERE i = 46.5;
       
      -- Correct without the index: empty result
      SELECT i FROM t1 IGNORE INDEX(i) WHERE i = 46.5;
       
      -- Shows ref access without "Using where", so the condition is never checked
      EXPLAIN SELECT i FROM t1 WHERE i = 46.5;
       
      DROP TABLE t1;
      

      Affected types:

      • TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT
      • DECIMAL (dec(5,1) = 1.25)
      • DATETIME and TIME with fractional-second constants

      Attachments

        Issue Links

          Activity

            People

              raghunandan.bhat Raghunandan Bhat
              M393 Maximilian Krög
              Raghunandan Bhat Raghunandan Bhat
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0d
                  0d
                  Remaining:
                  Remaining Estimate - 3h
                  3h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified

                  Git Integration

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