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

BIT_XOR(v) OVER (...) returns wrong result

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 12.3.2, 12.2.2
    • None
    • None
    • Ubuntu 24.04

    Description

      BIT_XOR() behaves correctly as a regular aggregate, but returns an incorrect result when evaluated as a window function.

      With a one-row table containing v = -5:

      SELECT BIT_XOR(v) FROM t; returns the correct uint64 reinterpretation of -5:
      18446744073709551611
      SELECT BIT_XOR(v) OVER () FROM t; returns:
      18446744073709551615
      SELECT BIT_XOR(v) OVER (ORDER BY v ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t;
      also returns:
      18446744073709551615
      So the scalar aggregate path is correct, but the window-function path is wrong.

      This is a wrong-result bug with no warning or error.

      POC:

      DROP DATABASE IF EXISTS bx;
      CREATE DATABASE bx;
      USE bx;
       
      CREATE TABLE t (v INT);
      INSERT INTO t VALUES (-5);
       
      -- Correct scalar aggregate result
      SELECT BIT_XOR(v) AS result FROM t;
      -- Expected / actual:
      -- 18446744073709551611
       
      -- Incorrect window result
      SELECT BIT_XOR(v) OVER () AS result FROM t;
      -- Expected:
      -- 18446744073709551611
      -- Actual on MariaDB 12.2.2:
      -- 18446744073709551615
       
      -- Incorrect cumulative window result
      SELECT BIT_XOR(v) OVER (
        ORDER BY v
        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
      ) AS result
      FROM t;
      -- Expected:
      -- 18446744073709551611
      -- Actual on MariaDB 12.2.2:
      -- 18446744073709551615
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            imchifan 刘启帆
            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.