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

Wrong result with LATERAL DERIVED

    XMLWordPrintable

Details

    • Unexpected results
    • Incorrect handling of null values on join conditions.
    • Q3/2025 Maintenance

    Description

      When populating the structure spl_opt_info for a TABLE, and evaluating a key_field for inclusion in spl_opt_info->added_key_fields, the null_rejecting attribute may be incorrectly set.

      Our example from the test case

      select STRAIGHT_JOIN count(*) FROM t1 tc
      INNER JOIN
      (
        SELECT a, b, c, max(d) maxd  FROM t1
        GROUP BY a, b, c
      ) c ON tc.a = c.a AND tc.b = c.b  AND tc.c <=> c.c
      LEFT JOIN
      (
        SELECT a, b, c, max(d) umaxd  FROM t1
       WHERE e = 'Y'
        GROUP BY a, b, c
      ) c2 ON tc.a = c2.a AND tc.b = c2.b  AND tc.c <=> c2.c
      WHERE tc.d < c.maxd  AND NOT tc.d <=> c2.umaxd
      

      Originally, this null_rejecting was assumed to be TRUE, then it was changed

            Item *real= key_field->val->real_item();
            if ((real->type() == Item::FIELD_ITEM) &&
                  ((Item_field*)real)->field->maybe_null())
              added_key_field->null_rejecting= true;
            else
              added_key_field->null_rejecting= false;
      

      which also incorrectly assumed that the added key field depended on whether the field was able to set to null.

      In the above query, for the derived table c2, we do not want this attribute to be null rejecting for key usage related to our join conditions, and we do not want equality conditions pushed into this derived table during a lateral join.

      Attachments

        Issue Links

          Activity

            People

              Johnston Rex Johnston
              Johnston Rex Johnston
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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