Details
-
Bug
-
Status: In Review (View Workflow)
-
Critical
-
Resolution: Unresolved
-
13.0, 13.1
-
None
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
- blocks
-
MDEV-39563 Implement UPDATE ... RETURNING ... INTO
-
- Stalled
-
-
MDEV-42156 UPDATE IGNORE ... RETURNING ... INTO fails with ER_TOO_MANY_ROWS when the second row is skipped by IGNORE (duplicate key)
-
- Closed
-
- is caused by
-
MDEV-5092 Implement UPDATE with result set (UPDATE ... RETURNING) for single table
-
- Closed
-