summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2020-09-26 10:07:28 -0700
committerIgor Babaev <igor@askmonty.org>2020-09-28 15:16:28 -0700
commit79e32e47a11150839ac4ab44ac02d4019c0e0019 (patch)
tree511fea44fda17f5e2edd18b4a05ce2466da6f152
parentce845b7a2fb3b86a1cc1a54a488ab7f16448d7c1 (diff)
downloadmariadb-git-79e32e47a11150839ac4ab44ac02d4019c0e0019.tar.gz
MDEV-23778 Derived table handler looses data on conversion from HEAP to Aria
This bug happened when the HEAP temporary table used for the derived table created for a derived handler of a remote engine of the federated type became full and was converted to an Area table. For this conversion the tmp_table_param parameter must be always taken from the select_unit object created for the result of the derived table.
-rw-r--r--mysql-test/suite/federated/federatedx_create_handlers.result44
-rw-r--r--mysql-test/suite/federated/federatedx_create_handlers.test57
-rw-r--r--sql/derived_handler.cc4
3 files changed, 102 insertions, 3 deletions
diff --git a/mysql-test/suite/federated/federatedx_create_handlers.result b/mysql-test/suite/federated/federatedx_create_handlers.result
index 63e56bff425..b115cc73b87 100644
--- a/mysql-test/suite/federated/federatedx_create_handlers.result
+++ b/mysql-test/suite/federated/federatedx_create_handlers.result
@@ -376,6 +376,50 @@ DROP TABLE federated.t1, federated.t2, federated.t3, federated.t4;
connection slave;
DROP TABLE federated.t1, federated.t2;
connection default;
+#
+# MDEV-23778: Derived handler used for big derived tables
+#
+connection slave;
+CREATE TABLE federated.t1 (
+a varchar(100) NOT NULL default '123'
+)
+DEFAULT CHARSET=latin1;
+CREATE TABLE federated.t2 LIKE federated.t1;
+BEGIN NOT ATOMIC
+DECLARE i INT DEFAULT 0;
+START TRANSACTION;
+WHILE i < 70000 DO
+INSERT INTO federated.t1 VALUES (i);
+SET i = i + 1;
+END WHILE;
+COMMIT;
+END
+$$
+connection master;
+CREATE TABLE federated.t1 (
+a varchar(100) NOT NULL default '123'
+)
+ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/federated/t1';
+CREATE TABLE federated.t2 (
+a varchar(100) NOT NULL default '123'
+)
+ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/federated/t2';
+SELECT COUNT(DISTINCT a) FROM federated.t1;
+COUNT(DISTINCT a)
+70000
+INSERT INTO federated.t2
+SELECT * FROM (SELECT * FROM federated.t1 LIMIT 100) dt;
+SELECT COUNT(DISTINCT a) FROM federated.t2;
+COUNT(DISTINCT a)
+100
+TRUNCATE TABLE federated.t2;
+INSERT INTO federated.t2
+SELECT * FROM (SELECT * FROM federated.t1 LIMIT 70000) dt;
+SELECT COUNT(DISTINCT a) FROM federated.t2;
+COUNT(DISTINCT a)
+70000
set global federated_pushdown=0;
connection master;
DROP TABLE IF EXISTS federated.t1;
diff --git a/mysql-test/suite/federated/federatedx_create_handlers.test b/mysql-test/suite/federated/federatedx_create_handlers.test
index d765588b79b..4b5789e1d96 100644
--- a/mysql-test/suite/federated/federatedx_create_handlers.test
+++ b/mysql-test/suite/federated/federatedx_create_handlers.test
@@ -208,6 +208,63 @@ DROP TABLE federated.t1, federated.t2;
connection default;
+--echo #
+--echo # MDEV-23778: Derived handler used for big derived tables
+--echo #
+
+connection slave;
+
+CREATE TABLE federated.t1 (
+ a varchar(100) NOT NULL default '123'
+)
+DEFAULT CHARSET=latin1;
+
+CREATE TABLE federated.t2 LIKE federated.t1;
+
+DELIMITER $$;
+BEGIN NOT ATOMIC
+ DECLARE i INT DEFAULT 0;
+ START TRANSACTION;
+ WHILE i < 70000 DO
+ INSERT INTO federated.t1 VALUES (i);
+ SET i = i + 1;
+ END WHILE;
+ COMMIT;
+END
+$$
+
+DELIMITER ;$$
+
+connection master;
+
+--replace_result $SLAVE_MYPORT SLAVE_PORT
+eval
+CREATE TABLE federated.t1 (
+ a varchar(100) NOT NULL default '123'
+)
+ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1';
+
+
+--replace_result $SLAVE_MYPORT SLAVE_PORT
+eval
+CREATE TABLE federated.t2 (
+ a varchar(100) NOT NULL default '123'
+)
+ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t2';
+
+SELECT COUNT(DISTINCT a) FROM federated.t1;
+
+INSERT INTO federated.t2
+ SELECT * FROM (SELECT * FROM federated.t1 LIMIT 100) dt;
+SELECT COUNT(DISTINCT a) FROM federated.t2;
+
+TRUNCATE TABLE federated.t2;
+INSERT INTO federated.t2
+ SELECT * FROM (SELECT * FROM federated.t1 LIMIT 70000) dt;
+SELECT COUNT(DISTINCT a) FROM federated.t2;
+
set global federated_pushdown=0;
source include/federated_cleanup.inc;
diff --git a/sql/derived_handler.cc b/sql/derived_handler.cc
index 76fd736de2b..f48b95cbf76 100644
--- a/sql/derived_handler.cc
+++ b/sql/derived_handler.cc
@@ -120,8 +120,6 @@ void derived_handler::set_derived(TABLE_LIST *tbl)
table= tbl->table;
unit= tbl->derived;
select= unit->first_select();
- tmp_table_param= select->next_select() ?
- ((select_unit *)(unit->result))->get_tmp_table_param() :
- &select->join->tmp_table_param;
+ tmp_table_param= ((select_unit *)(unit->result))->get_tmp_table_param();
}