Skip to content

Commit 14720ec

Browse files
mariadb-OlegSmirnovOlernov
authored andcommitted
MDEV-29874: FederatedX error 10000 on multi-table UPDATE/DELETE
Multi-table UPDATE and DELETE statements employ mysql_select() calls during their processing, so the server may try to instantiate `select_handler` in an attempt to push down the statement to a foreign engine. However, the current implementation of `select_handler` for FederatedX pushes down the whole query and not only its select part (`thd->query()`, see `int ha_federatedx_select_handler::init_scan()`). FederatedX engine does not support execution of DML statements on the remote side, that is why the error occured. Solution: - Add an extra check to only allow SELECT statements pushdown to FederatedX
1 parent d7dadb8 commit 14720ec

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

mysql-test/suite/federated/federatedx_create_handlers.result

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,41 @@ id name
606606
4 xxx
607607
5 yyy
608608
DEALLOCATE PREPARE stmt;
609+
#
610+
# FederatedX error 10000 on multi-table UPDATE/DELETE
611+
#
612+
connection slave;
613+
DROP TABLE IF EXISTS federated.t1, federated.t2;
614+
CREATE TABLE federated.t1 (a int, b int);
615+
INSERT INTO federated.t1 VALUES (1,1), (2,2), (3,3);
616+
CREATE TABLE federated.t2 (a int, b int);
617+
INSERT INTO federated.t2 VALUES (1,1), (2,2), (4,4);
618+
connection master;
619+
DROP TABLE IF EXISTS federated.t1, federated.t2;
620+
CREATE TABLE federated.t1 (a int, b int)
621+
ENGINE="FEDERATED" DEFAULT CHARSET=latin1
622+
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/federated/t1';
623+
CREATE TABLE federated.t2 (a int, b int)
624+
ENGINE="FEDERATED" DEFAULT CHARSET=latin1
625+
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/federated/t2';
626+
use federated;
627+
# Multi-table UPDATE
628+
UPDATE t1, t2 SET t1.a = 2 WHERE t1.a=t2.a;
629+
# Check the result
630+
SELECT * FROM t1;
631+
a b
632+
2 1
633+
2 2
634+
3 3
635+
# Multi-table DELETE
636+
DELETE FROM t1 USING t1 JOIN t2 ON t1.a = t2.a WHERE t2.b > 1;
637+
SELECT * FROM t1;
638+
a b
639+
3 3
640+
# Another form of multi-table DELETE
641+
DELETE FROM a1 USING t1 AS a1;
642+
SELECT * FROM t1;
643+
a b
609644
set global federated_pushdown=0;
610645
connection master;
611646
DROP TABLE IF EXISTS federated.t1;

mysql-test/suite/federated/federatedx_create_handlers.test

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,50 @@ EXECUTE stmt;
431431
EXECUTE stmt;
432432
DEALLOCATE PREPARE stmt;
433433

434+
--echo #
435+
--echo # FederatedX error 10000 on multi-table UPDATE/DELETE
436+
--echo #
437+
438+
connection slave;
439+
DROP TABLE IF EXISTS federated.t1, federated.t2;
440+
441+
CREATE TABLE federated.t1 (a int, b int);
442+
INSERT INTO federated.t1 VALUES (1,1), (2,2), (3,3);
443+
444+
CREATE TABLE federated.t2 (a int, b int);
445+
INSERT INTO federated.t2 VALUES (1,1), (2,2), (4,4);
446+
447+
connection master;
448+
DROP TABLE IF EXISTS federated.t1, federated.t2;
449+
--replace_result $SLAVE_MYPORT SLAVE_PORT
450+
eval
451+
CREATE TABLE federated.t1 (a int, b int)
452+
ENGINE="FEDERATED" DEFAULT CHARSET=latin1
453+
CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1';
454+
455+
--replace_result $SLAVE_MYPORT SLAVE_PORT
456+
eval
457+
CREATE TABLE federated.t2 (a int, b int)
458+
ENGINE="FEDERATED" DEFAULT CHARSET=latin1
459+
CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t2';
460+
461+
use federated;
462+
463+
--echo # Multi-table UPDATE
464+
UPDATE t1, t2 SET t1.a = 2 WHERE t1.a=t2.a;
465+
466+
--echo # Check the result
467+
SELECT * FROM t1;
468+
469+
--echo # Multi-table DELETE
470+
DELETE FROM t1 USING t1 JOIN t2 ON t1.a = t2.a WHERE t2.b > 1;
471+
472+
SELECT * FROM t1;
473+
474+
--echo # Another form of multi-table DELETE
475+
DELETE FROM a1 USING t1 AS a1;
476+
477+
SELECT * FROM t1;
434478

435479
set global federated_pushdown=0;
436480

storage/federatedx/federatedx_pushdown.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,16 @@ void ha_federatedx_derived_handler::print_error(int, unsigned long)
227227
}
228228

229229

230+
static bool is_supported_by_select_handler(enum_sql_command sql_command)
231+
{
232+
return sql_command == SQLCOM_SELECT || sql_command == SQLCOM_INSERT_SELECT;
233+
}
234+
235+
230236
static select_handler*
231237
create_federatedx_select_handler(THD* thd, SELECT_LEX *sel)
232238
{
233-
if (!use_pushdown)
239+
if (!use_pushdown || !is_supported_by_select_handler(thd->lex->sql_command))
234240
return 0;
235241

236242
ha_federatedx_select_handler* handler = NULL;

0 commit comments

Comments
 (0)