mirror of
https://github.com/MariaDB/server.git
synced 2025-11-30 05:23:50 +03:00
This is a complete rewrite of DROP TABLE, also as part of other DDL, such as ALTER TABLE, CREATE TABLE...SELECT, TRUNCATE TABLE. The background DROP TABLE queue hack is removed. If a transaction needs to drop and create a table by the same name (like TRUNCATE TABLE does), it must first rename the table to an internal #sql-ib name. No committed version of the data dictionary will include any #sql-ib tables, because whenever a transaction renames a table to a #sql-ib name, it will also drop that table. Either the rename will be rolled back, or the drop will be committed. Data files will be unlinked after the transaction has been committed and a FILE_RENAME record has been durably written. The file will actually be deleted when the detached file handle returned by fil_delete_tablespace() will be closed, after the latches have been released. It is possible that a purge of the delete of the SYS_INDEXES record for the clustered index will execute fil_delete_tablespace() concurrently with the DDL transaction. In that case, the thread that arrives later will wait for the other thread to finish. HTON_TRUNCATE_REQUIRES_EXCLUSIVE_USE: A new handler flag. ha_innobase::truncate() now requires that all other references to the table be released in advance. This was implemented by Monty. ha_innobase::delete_table(): If CREATE TABLE..SELECT is detected, we will "hijack" the current transaction, drop the table in the current transaction and commit the current transaction. This essentially fixes MDEV-21602. There is a FIXME comment about making the check less failure-prone. ha_innobase::truncate(), ha_innobase::delete_table(): Implement a fast path for temporary tables. We will no longer allow temporary tables to use the adaptive hash index. dict_table_t::mdl_name: The original table name for the purpose of acquiring MDL in purge, to prevent a race condition between a DDL transaction that is dropping a table, and purge processing undo log records of DML that had executed before the DDL operation. For #sql-backup- tables during ALTER TABLE...ALGORITHM=COPY, the dict_table_t::mdl_name will differ from dict_table_t::name. dict_table_t::parse_name(): Use mdl_name instead of name. dict_table_rename_in_cache(): Update mdl_name. For the internal FTS_ tables of FULLTEXT INDEX, purge would acquire MDL on the FTS_ table name, but not on the main table, and therefore it would be able to run concurrently with a DDL transaction that is dropping the table. Previously, the DROP TABLE queue hack prevented a race between purge and DDL. For now, we introduce purge_sys.stop_FTS() to prevent purge from opening any table, while a DDL transaction that may drop FTS_ tables is in progress. The function fts_lock_table(), which will be invoked before the dictionary is locked, will wait for purge to release any table handles. trx_t::drop_table_statistics(): Drop statistics for the table. This replaces dict_stats_drop_index(). We will drop or rename persistent statistics atomically as part of DDL transactions. On lock conflict for dropping statistics, we will fail instantly with DB_LOCK_WAIT_TIMEOUT, because we will be holding the exclusive data dictionary latch. trx_t::commit_cleanup(): Separated from trx_t::commit_in_memory(). Relax an assertion around fts_commit() and allow DB_LOCK_WAIT_TIMEOUT in addition to DB_DUPLICATE_KEY. The call to fts_commit() is entirely misplaced here and may obviously break the consistency of transactions that affect FULLTEXT INDEX. It needs to be fixed separately. dict_table_t::n_foreign_key_checks_running: Remove (MDEV-21175). The counter was a work-around for missing meta-data locking (MDL) on the SQL layer, and not really needed in MariaDB. ER_TABLE_IN_FK_CHECK: Replaced with ER_UNUSED_28. HA_ERR_TABLE_IN_FK_CHECK: Remove. row_ins_check_foreign_constraints(): Do not acquire dict_sys.latch either. The SQL-layer MDL will protect us. This was reviewed by Thirunarayanan Balathandayuthapani and tested by Matthias Leich.
189 lines
6.8 KiB
Plaintext
189 lines
6.8 KiB
Plaintext
--source include/have_innodb.inc
|
|
--source include/have_partition.inc
|
|
|
|
CREATE TABLE `test_data` (
|
|
`hid` bigint(20) unsigned NOT NULL,
|
|
`itid` bigint(20) unsigned NOT NULL,
|
|
`clocktime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
`values` double(16,4) NOT NULL,
|
|
PRIMARY KEY (`hid`,`itid`,`clocktime`)
|
|
) ;
|
|
|
|
INSERT INTO `test_data` (`hid`, `itid`, `clocktime`, `values`) VALUES
|
|
(1, 1, '2015-03-10 06:25:16', 0.0000),
|
|
(1, 1, '2015-03-10 06:26:24', 0.0000),
|
|
(1, 1, '2015-03-10 06:27:32', 0.0000),
|
|
(1, 1, '2015-03-10 06:28:40', 0.0000),
|
|
(1, 1, '2015-03-10 06:29:49', 0.0000),
|
|
(1, 1, '2015-03-10 06:30:57', 0.0000),
|
|
(1, 1, '2015-03-10 06:32:05', 0.0000),
|
|
(1, 1, '2015-03-10 06:33:14', 0.0000),
|
|
(1, 1, '2015-03-10 06:34:22', 0.0000),
|
|
(1, 1, '2015-03-10 06:35:30', 0.0000),
|
|
(1, 1, '2015-03-10 06:36:39', 0.0000),
|
|
(1, 1, '2015-03-10 06:37:47', 0.0000),
|
|
(1, 1, '2015-03-10 06:38:55', 0.0000),
|
|
(1, 1, '2015-03-10 06:40:03', 0.0000),
|
|
(1, 1, '2015-03-10 06:41:09', 0.0000),
|
|
(1, 1, '2015-03-10 06:42:21', 0.0000),
|
|
(1, 1, '2015-03-10 06:43:29', 0.0000),
|
|
(1, 1, '2015-03-10 06:44:37', 0.0000),
|
|
(1, 1, '2015-03-10 06:45:46', 0.0000),
|
|
(1, 1, '2015-03-10 06:47:05', 0.0000),
|
|
(1, 1, '2015-03-10 06:48:21', 0.0000),
|
|
(1, 1, '2015-03-10 06:49:41', 0.0000),
|
|
(1, 1, '2015-03-10 06:50:58', 0.0000),
|
|
(1, 1, '2015-03-10 06:52:08', 0.0000),
|
|
(1, 1, '2015-03-10 06:53:17', 0.0000),
|
|
(1, 1, '2015-03-10 06:54:25', 0.0000),
|
|
(563, 1, '2015-03-17 14:28:28', 0.3125),
|
|
(563, 1, '2015-03-17 14:29:39', 0.2775),
|
|
(563, 1, '2015-03-17 14:30:49', 0.2675);
|
|
|
|
|
|
CREATE PROCEDURE `create_part_max`()
|
|
alter table `test_data`
|
|
partition by range(unix_timestamp(clocktime)) (
|
|
partition partMAX values less than MAXVALUE
|
|
);
|
|
|
|
call create_part_max();
|
|
|
|
call create_part_max();
|
|
|
|
drop procedure create_part_max;
|
|
|
|
prepare stmt from "alter table `test_data`
|
|
partition by range(unix_timestamp(clocktime)) (
|
|
partition partMAX values less than MAXVALUE
|
|
)";
|
|
|
|
execute stmt;
|
|
execute stmt;
|
|
|
|
deallocate prepare stmt;
|
|
|
|
drop table test_data;
|
|
|
|
#
|
|
# MDEV-12389 ADD CHECK leaves an orphaned .par file
|
|
#
|
|
|
|
--let $datadir=`SELECT @@datadir`
|
|
|
|
# InnoDB
|
|
create table t1(id int, d date not null, b bool not null default 0, primary key(id,d))
|
|
engine=innodb
|
|
partition by range columns (d) (
|
|
partition p1 values less than ('2016-10-18'),
|
|
partition p2 values less than ('2020-10-19'));
|
|
insert t1 values (0, '2000-01-02', 0);
|
|
insert t1 values (1, '2020-01-02', 10);
|
|
--error ER_CONSTRAINT_FAILED
|
|
alter table t1 add check (b in (0, 1));
|
|
alter table t1 add check (b in (0, 10));
|
|
show create table t1;
|
|
--error ER_CONSTRAINT_FAILED
|
|
insert t1 values (2, '2020-01-03', 20);
|
|
drop table t1;
|
|
--list_files $datadir/test
|
|
|
|
# MyISAM, different execution path
|
|
create table t1(id int, d date not null, b bool not null default 0, primary key(id,d))
|
|
partition by range columns (d) (
|
|
partition p1 values less than ('2016-10-18'),
|
|
partition p2 values less than ('2020-10-19'));
|
|
insert t1 values (0, '2000-01-02', 0);
|
|
insert t1 values (1, '2020-01-02', 10);
|
|
--error ER_CONSTRAINT_FAILED
|
|
alter table t1 add check (b in (0, 1));
|
|
alter table t1 add check (b in (0, 10));
|
|
show create table t1;
|
|
--error ER_CONSTRAINT_FAILED
|
|
insert t1 values (2, '2020-01-03', 20);
|
|
drop table t1;
|
|
--list_files $datadir/test
|
|
|
|
#
|
|
# MDEV-13097 Online alter of a partitioned MyISAM table with auto_increment
|
|
#
|
|
create table t1 (id_1 int auto_increment, id_2 int, id_3 int, d1 date, dt1 datetime default current_timestamp, dt2 datetime default current_timestamp on update current_timestamp, primary key (id_2, id_3), key(id_1)) partition by hash(id_2) partitions 3 (partition p01, partition p02, partition p03);
|
|
insert into t1 values(0, 1, 1, NULL, now(), now());
|
|
alter online table t1 delay_key_write=1;
|
|
show create table t1;
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-19751 Wrong partitioning by KEY() after key dropped
|
|
--echo #
|
|
create or replace table t1 (pk int, x timestamp(6), primary key (pk, x)) engine innodb
|
|
partition by key() partitions 2;
|
|
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
|
|
--echo # Inplace for DROP PRIMARY KEY when partitioned by default field list is denied
|
|
--error ER_ALTER_OPERATION_NOT_SUPPORTED
|
|
alter table t1 drop primary key, drop column x, add primary key (pk), algorithm=inplace;
|
|
alter table t1 drop primary key, drop column x, add primary key (pk);
|
|
select * from t1 partition (p0);
|
|
drop table t1;
|
|
|
|
create or replace table t1 (pk int not null, x timestamp(6), unique u(pk, x)) engine innodb
|
|
partition by key() partitions 2;
|
|
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
|
|
--echo # Same for NOT NULL UNIQUE KEY as this is actually primary key
|
|
--error ER_ALTER_OPERATION_NOT_SUPPORTED
|
|
alter table t1 drop key u, drop column x, add unique (pk), algorithm=inplace;
|
|
alter table t1 drop key u, drop column x, add unique (pk);
|
|
select * from t1 partition (p0);
|
|
drop table t1;
|
|
|
|
create or replace table t1 (pk int, x timestamp(6), primary key (pk)) engine innodb
|
|
partition by key(pk) partitions 2;
|
|
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
|
|
--echo # Inplace for DROP PRIMARY KEY when partitioned by explicit field list is allowed
|
|
alter table t1 drop primary key, add primary key (pk, x), algorithm=inplace;
|
|
select * from t1 partition (p0);
|
|
drop table t1;
|
|
|
|
create or replace table t1 (k int, x timestamp(6), unique key u (x, k)) engine innodb
|
|
partition by key(k) partitions 2;
|
|
insert into t1 (k, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
|
|
--echo # Inplace for DROP KEY is allowed
|
|
alter table t1 drop key u, algorithm=inplace;
|
|
select * from t1 partition (p0);
|
|
drop table t1;
|
|
|
|
--echo # End of 10.2 tests
|
|
|
|
--echo #
|
|
--echo # MDEV-14817 Server crashes in prep_alter_part_table()
|
|
--echo # after table lock and multiple add partition
|
|
--echo #
|
|
create table t1 (x int) partition by hash (x) (partition p1, partition p2);
|
|
lock table t1 write;
|
|
--error ER_SAME_NAME_PARTITION
|
|
alter table t1 add partition (partition p1);
|
|
--error ER_SAME_NAME_PARTITION
|
|
alter table t1 add partition (partition p1);
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-17091 Assertion `old_part_id == m_last_part' failed in
|
|
--echo # ha_partition::update_row or `part_id == m_last_part' in
|
|
--echo # ha_partition::delete_row upon UPDATE/DELETE after dropping versioning
|
|
--echo #
|
|
create table t1 (pk int, f int, primary key(pk, f)) engine=innodb
|
|
partition by key() partitions 2;
|
|
|
|
insert into t1 values (1,10),(2,11);
|
|
--echo # expected to hit same partition
|
|
select * from t1 partition (p0);
|
|
|
|
alter table t1 drop primary key, drop f, add primary key(pk);
|
|
--echo # 1 and 2 are expected to be in different partitions
|
|
select * from t1 partition(p0);
|
|
select * from t1 partition(p1);
|
|
delete from t1;
|
|
drop table t1;
|
|
|
|
--echo # End of 10.3 tests
|