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

Window functions over a join with a view treat a null produced by outer join as a null from view, resulting in ifnull() taking values through nested result sets

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.2.31, 10.4.12, 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL)
    • 10.4(EOL)
    • Optimizer
    • None

    Description

      Minimal example:

      DROP TABLE IF EXISTS t;
      CREATE TABLE t
      (
          id    int unsigned not null,
          value int unsigned null
      );
      INSERT INTO t
      values (1, null);
       
      CREATE OR REPLACE VIEW v
      as
      select 1                 as id,
             ifnull(null, 999) as value
      from t
      ;
       
      select *,
             MIN(t.value) over (PARTITION BY t.id) as min_t,
             MIN(v.value) over (PARTITION BY t.id) as min_v
      from t
               left join v
                         on t.id > v.id
      ;
      

      With the affected MariaDB versions, the select returns:

      id value id   value min_t min_v
      1  null  null null  null  999
      

      but I would expect it to return

      id value id   value min_t min_v
      1  null  null null  null  null
      

      Corresponding queries with other RDBMS:

      Return null and 999:

      MySQL 5.6 - it shouldn't have window functions, but it returns the same result as MariaDB http://sqlfiddle.com/#!9/7da5e/12

      Return null and null:

      Oracle 11g R2 - http://sqlfiddle.com/#!4/18d8e/1
      PostgreSQL 9.3 - http://sqlfiddle.com/#!15/a1756/4
      MySQL 8.0 - https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=3a6b0308f7f889cbd0ab77ef65cd87db

      See also: https://dba.stackexchange.com/questions/261229/is-it-expected-behavior-that-min-window-function-in-mariadb-mysql-can-return-a?noredirect=1#comment515417_261229

      Attachments

        Activity

          People

            Unassigned Unassigned
            chriego Georgiy Vlasov
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.