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

With derived_merge=on and join_cache_level=3, DECIMAL IS NULL predicate pushdown combined with BNLH hash join drops NULL rows: single-table returns NULL, JOIN rewrite returns empty set.

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 12.3.2
    • None
    • Optimizer
    • Operating system:
      - Ubuntu 20.04.6 LTS (Focal Fossa)
      - Linux kernel: 5.4.0-204-generic
      - Architecture: x86_64

      Hardware:
      - CPU: 2 × Intel Xeon Gold 5218R @ 2.10 GHz
      - 40 physical cores / 80 logical CPUs

    Description

          1. Problem Description
            With `optimizer_switch='derived_merge=on'` and `join_cache_level=3`, the original single-table query and the multi-table JOIN rewritten query return different results for the same logical condition `c1 IS NULL`. The single-table query returns one row `NULL`, while the JOIN rewritten query returns an empty set. It is suspected that after predicate pushdown, the optimizer/executor combines `r.c1 IS NULL` with the BNLH hash index build/probe on `r`'s covering index `k(id,c1)`. Since hash joins treat `NULL` keys with equality semantics, rows with `c1 IS NULL` are ignored or not correctly matched during the hash matching phase.
          1. How to Reproduce
            Execute the following SQL:

      ```sql
      DROP DATABASE IF EXISTS repro_mariadb814_db0_vp123_min;
      CREATE DATABASE repro_mariadb814_db0_vp123_min;
      USE repro_mariadb814_db0_vp123_min;

      SET optimizer_switch='derived_merge=on';
      SET join_cache_level=3;

      – Original single table
      CREATE TABLE s(
      id BIGINT,
      c0 BIT(8),
      c1 DECIMAL(10,2)
      ) ENGINE=Aria;

      – Reconstructed split-table structure
      CREATE TABLE l(
      id BIGINT PRIMARY KEY,
      c0 BIT(8),
      KEY k(c0,id)
      ) ENGINE=Aria;

      CREATE TABLE r(
      id BIGINT PRIMARY KEY,
      c1 DECIMAL(10,2),
      KEY k(id,c1)
      ) ENGINE=Aria;

      INSERT INTO s VALUES
      (1,NULL,NULL),
      (2,2,2.01),
      (3,3,3.01);

      INSERT INTO l SELECT id,c0 FROM s;
      INSERT INTO r SELECT id,c1 FROM s;

      – Original single-table query
      SELECT DISTINCT c1
      FROM s
      WHERE c1 IS NULL;

      – Multi-table JOIN rewritten query
      SELECT DISTINCT c1
      FROM (
      SELECT l.id, l.c0, r.c1
      FROM l JOIN r ON l.id=r.id
      ) d
      WHERE c1 IS NULL;
      ```

          1. Expected Behavior
            The single-table query and the JOIN rewritten query should return the same result, i.e., both should return one row `NULL`.
          1. Actual Behavior
      • Single-table query: returns one row `NULL`.
      • JOIN rewritten query: returns `Empty set`.

      Single-table result:
      ```
      ------

      c1

      ------

      NULL

      ------
      ```

      JOIN rewritten result:
      ```
      Empty set
      ```

      Attachments

        Activity

          People

            shipjain Shipra Jain
            Annie Annie liu
            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.