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

Wrong result: DOUBLE/FLOAT UNSIGNED index scan with negative string constant

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.11.14
    • None
    • None
    • None

    Description

      For an indexed DOUBLE UNSIGNED or FLOAT UNSIGNED column, comparing with a negative string constant such as '-1' returns wrong results.

      === Repro ===

      CREATE TABLE t (d DOUBLE UNSIGNED, KEY(d));
      INSERT INTO t VALUES (NULL), (0), (0.5);

      – Indexed scan returns 0, but the row does not satisfy d = '-1'
      SELECT d FROM t WHERE d = '-1';
      – Result: 0 <-- WRONG

      – Without index, correct result
      SELECT d FROM t IGNORE INDEX(d) WHERE d = '-1';
      – Result: (empty)

      – Row-by-row evaluation also correct
      SELECT d, d = '-1' AS eq FROM t ORDER BY d IS NULL, d;
      – Result: 0=0, 0.5=0, NULL=NULL

      === Root Cause ===

      Field_num::get_mm_leaf() stores the comparison value into the field before building the range. For UNSIGNED FLOAT/DOUBLE, a negative value like '-1' is clipped to 0 during this store. The optimizer then builds an equality range for 0, returning rows that do not satisfy the predicate.

      === Version ===

      10.11.14-MariaDB

      === Fix ===

      A patch is ready — will submit as a GitHub PR referencing this MDEV.

      Attachments

        Activity

          People

            Unassigned Unassigned
            wufengwind Feng Wu
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.