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

UPDATE ... RETURNING on a Spider table hangs, or fails with "Received malformed packet"

    XMLWordPrintable

Details

    Description

      Description

      UPDATE ... RETURNING on a Spider table does not return a result set when the statement qualifies for direct update. On 13.0 the client hangs. On 13.1 it fails with ERROR 2027: Received malformed packet. DELETE ... RETURNING works. UPDATE IGNORE RETURNING works, because IGNORE disables direct update.

      How to repeat

      Save as storage/spider/mysql-test/spider/bugfix/t/update_returning.test and run with ./mtr spider/bugfix.update_returning:

      --disable_query_log
      --disable_result_log
      --source ../../t/test_init.inc
      --enable_result_log
      --enable_query_log
       
      set spider_same_server_link= on;
      set global spider_same_server_link= on;
       
      create database auto_test_local;
      create table auto_test_local.t1 (a int primary key, b int) engine=InnoDB;
      insert into auto_test_local.t1 values (1,1),(2,2);
      create table t1 (a int primary key, b int) engine=Spider
        comment='wrapper "mysql", srv "s_1", table "t1"';
       
      update t1 set b=b+10 where a=1 returning b;
       
      drop table t1;
      drop database auto_test_local;
       
      --disable_query_log
      --disable_result_log
      --source ../../t/test_deinit.inc
      --enable_result_log
      --enable_query_log
      

      Actual result:

      • the update hangs (13.0), or
      • fails with ERROR 2027: Received malformed packet (13.1).

      Expected result: one row, b = 11.

      Analysis

      Sql_cmd_update::update_single_table() takes the direct update path (goto update_begin) when the engine reports HA_CAN_DIRECT_UPDATE_AND_DELETE. The condition does not check for RETURNING. The function then still calls returning_result->send_eof(), but the result set metadata was never sent. I did not trace the protocol state, so the exact mechanism is my reading of the code.

      Suggested fix

      --- a/sql/sql_update.cc
      +++ b/sql/sql_update.cc
      @@ -724,7 +724,7 @@
         DBUG_PRINT("info", ("virtual_columns_marked_for_read: %s", table->check_virtual_columns_marked_for_read() ? "TRUE" : "FALSE"));
         DBUG_PRINT("info", ("virtual_columns_marked_for_write: %s", table->check_virtual_columns_marked_for_write() ? "TRUE" : "FALSE"));
         if ((table->file->ha_table_flags() & HA_CAN_DIRECT_UPDATE_AND_DELETE) &&
      -      !has_triggers && !binlog_is_row &&
      +      !has_triggers && !binlog_is_row && !thd->lex->has_returning() &&
             !query_plan.using_io_buffer && !ignore &&
             !table->check_virtual_columns_marked_for_read() &&
             !table->check_virtual_columns_marked_for_write())
      

      Versions

      Checked on:

      • 13.0 (620a4b56242)
      • 13.1 (19c90297d6f)
      • 13.2 (ef4c7459b84

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              bar Alexander Barkov
              Yuchen Pei Yuchen Pei
              Rucha Deodhar Rucha Deodhar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0d
                  0d
                  Remaining:
                  Time Spent - 1h 43m Remaining Estimate - 0.25d
                  0.25d
                  Logged:
                  Time Spent - 1h 43m Remaining Estimate - 0.25d
                  1h 43m

                  Git Integration

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