[MDEV-17885] TRUNCATE on temporary table causes ER_GET_ERRNO and "Could not remove temporary table" in the log Created: 2018-12-01  Updated: 2018-12-12  Resolved: 2018-12-12

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Temporary, Storage Engine - InnoDB
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: 10.4.1, 10.2.20, 10.3.12

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: regression

Issue Links:
Problem/Incident
is caused by MDEV-13564 TRUNCATE TABLE and undo tablespace tr... Closed
Relates
relates to MDEV-17816 InnoDB: Failing assertion: trx->dict_... Closed
relates to MDEV-17833 ALTER TABLE is not enforcing prefix i... Closed
relates to MDEV-17983 CREATE TEMPORARY TABLE is inconsisten... Open

 Description   

It appears that innodb_safe_truncate makes TRUNCATE unsafe:

--source include/have_innodb.inc
 
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=InnoDB;
ALTER TABLE t1 ENCRYPTED=NO;
TRUNCATE t1;

10.2 861038f2e with default innodb_safe_truncate=ON

CURRENT_TEST: bug.temp3
mysqltest: At line 5: query 'TRUNCATE t1' failed: 1030: Got error 140 "Wrong create options" from storage engine InnoDB

2018-12-01 13:41:46 140647973488384 [Warning] Could not remove temporary table: '/data/bld/10.2/mysql-test/var/tmp/mysqld.1/#sql769d_9_1', error: 2

There is no warning/error with innodb_safe_truncate=OFF



 Comments   
Comment by Marko Mäkelä [ 2018-12-12 ]

I think that TRUNCATE is correctly refusing and rolling back the operation, now that MDEV-17816 has been fixed.

The actual error is that ALTER TABLE is lacking validation that is being done by CREATE TABLE. This is similar to MDEV-17833 (which was just fixed) and should be fixed in 10.1 (which was the first version to introduce table options in InnoDB/XtraDB).

Comment by Marko Mäkelä [ 2018-12-12 ]

Actually, CREATE appears to accept the table options, but TRUNCATE will complain:

--source include/have_innodb.inc
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=InnoDB ENCRYPTED=NO;
TRUNCATE TABLE t1;

Comment by Marko Mäkelä [ 2018-12-12 ]

With the following fix, CREATE TEMPORARY TABLE would reject those table options that are only valid for .ibd files:

diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 717b67290dc..567be3378a1 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -12911,7 +12911,9 @@ ha_innobase::create(
 	TABLE*		form,
 	HA_CREATE_INFO*	create_info)
 {
-	return create(name, form, create_info, srv_file_per_table);
+	return create(name, form, create_info,
+		      !(create_info->options & HA_LEX_CREATE_TMP_TABLE)
+		      && srv_file_per_table);
 }
 
 /*****************************************************************//**

However, this would introduce a regression for CREATE TEMPORARY TABLE behaviour in the generally available 10.2 and 10.3 series. The following would allow the TRUNCATE TABLE to succeed:

diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 717b67290dc..b941ce8b825 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -13531,7 +13531,8 @@ int ha_innobase::truncate()
 		row_mysql_unlock_data_dictionary(trx);
 	} else {
 		err = create(name, table, &info,
-			     dict_table_is_file_per_table(ib_table), trx);
+			     ib_table->is_temporary()
+			     || dict_table_is_file_per_table(ib_table), trx);
 	}
 
 	trx_free_for_mysql(trx);

Comment by Marko Mäkelä [ 2018-12-12 ]

I filed MDEV-17983 for making CREATE TEMPORARY TABLE stricter.

Generated at Thu Feb 08 08:39:52 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.