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

Associative-array record member assignment is lost after assigning the record NULL

    XMLWordPrintable

Details

    Description

      MariaDB 12.3.3 on Linux x86_64 loses a successful member assignment when an associative-array record element was first assigned NULL. Reading the element returns every member as NULL. The same member assignment works for a plain record and for an array element initialized with a record constructor.

      This occurs when an Oracle-mode associative-array element containing a record is assigned NULL and then one of its members is assigned directly or through SELECT INTO.

      Reproducer

      Save the following as case.sql, then run mariadb --batch --raw < case.sql.

      CREATE DATABASE record_test;
      USE record_test;
      SET sql_mode=ORACLE;
      DELIMITER $$
      DECLARE
        TYPE rec_t IS RECORD (x INT, y INT);
        TYPE arr_t IS TABLE OF rec_t INDEX BY INT;
        a arr_t;
        r rec_t;
      BEGIN
        r := NULL;
        r.x := 7;
        SELECT 'plain_record' AS label, r.x AS x, r.y AS y;
       
        a(1) := NULL;
        a(1).x := 7;
        SELECT 'array_member' AS label, a(1).x AS x, a(1).y AS y;
       
        a(2) := rec_t(NULL,NULL);
        a(2).x := 7;
        SELECT 'constructor' AS label, a(2).x AS x, a(2).y AS y;
       
        a(3) := NULL;
        SELECT 9 INTO a(3).x;
        SELECT 'select_into' AS label, a(3).x AS x, a(3).y AS y;
      END;
      $$
      DELIMITER ;
      DROP DATABASE record_test;

      Actual result

      The direct assignment and SELECT INTO values disappear only for elements previously assigned NULL:

      label           x     y
      plain_record    7     NULL
      array_member    NULL  NULL
      constructor     7     NULL
      select_into     NULL  NULL

      The SQL completes without an error or server interruption.

      Expected result

      Assigning a(1).x := 7 successfully should make that record non-NULL and return (7,NULL), as demonstrated by the plain-record and constructor cases. Likewise, SELECT 9 INTO a(3).x should return (9,NULL). A successful child-member mutation must update the enclosing record's validity before it is serialized.

      Analysis

      Source inspection indicates that unpacking a NULL associative-array record marks both the enclosing record and its members NULL. The subsequent member mutation updates the child field without clearing the enclosing record's NULL state. Packing then observes the parent as NULL and omits member serialization, which explains why both direct assignment and SELECT INTO lose their values.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              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.