Commit ff1df12a authored by Mikael Ronstrom's avatar Mikael Ronstrom

WL#4444 Added TRUNCATE partition support, fixes bug#19405 and bug #35111

parent 51c27a69
...@@ -556,7 +556,7 @@ parse_package() ...@@ -556,7 +556,7 @@ parse_package()
package="pro" package="pro"
;; ;;
extended ) extended )
package="" package="extended"
;; ;;
cge ) cge )
package="cge" package="cge"
......
drop table if exists t1, t2, t3, t4;
create table t1 (a int)
partition by list (a)
(partition p1 values in (0));
alter table t1 truncate partition p1,p1;
ERROR HY000: Incorrect partition name
alter table t1 truncate partition p0;
ERROR HY000: Incorrect partition name
drop table t1;
create table t1 (a int)
partition by list (a)
subpartition by hash (a)
subpartitions 1
(partition p1 values in (1)
(subpartition sp1));
alter table t1 truncate partition sp1;
ERROR HY000: Incorrect partition name
drop table t1;
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# part_optA-D Extra partitioning options (E.g. INDEX/DATA DIR) # # part_optA-D Extra partitioning options (E.g. INDEX/DATA DIR) #
# # # #
# have_bug33158 NDB case insensitive create, but case sensitive rename # # have_bug33158 NDB case insensitive create, but case sensitive rename #
# no_truncate No support for truncate partition #
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
# Original Author: mattiasj # # Original Author: mattiasj #
# Original Date: 2008-06-27 # # Original Date: 2008-06-27 #
...@@ -518,6 +519,95 @@ DROP TABLE TableA; ...@@ -518,6 +519,95 @@ DROP TABLE TableA;
} }
# End of $can_only_key # End of $can_only_key
if ($no_truncate)
{
--echo # Verify that TRUNCATE PARTITION gives error
eval CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = $engine
PARTITION BY KEY (a)
(PARTITION LT1000,
PARTITION LT2000,
PARTITION MAX);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
--error ER_PARTITION_MGMT_ON_NONPARTITIONED, ER_ILLEGAL_HA
ALTER TABLE t1 TRUNCATE PARTITION MAX;
}
if (!$no_truncate)
{
--echo # Testing TRUNCATE PARTITION
eval CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = $engine
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
SELECT * FROM t1 ORDER BY a;
ALTER TABLE t1 ANALYZE PARTITION MAX;
--echo # Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
--echo # Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
--echo # Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
--echo # Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
--echo # Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
--echo # Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
--echo # Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
--echo # Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
--echo # Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
--echo # Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
--echo # Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
--echo # Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
DROP TABLE t1;
}
--echo # Cleaning up before exit --echo # Cleaning up before exit
eval USE $old_db; eval USE $old_db;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -915,6 +915,18 @@ TableA CREATE TABLE `TableA` ( ...@@ -915,6 +915,18 @@ TableA CREATE TABLE `TableA` (
) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Verify that TRUNCATE PARTITION gives error
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'Archive'
PARTITION BY KEY (a)
(PARTITION LT1000,
PARTITION LT2000,
PARTITION MAX);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
ALTER TABLE t1 TRUNCATE PARTITION MAX;
Got one of the listed errors
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -915,6 +915,170 @@ TableA CREATE TABLE `TableA` ( ...@@ -915,6 +915,170 @@ TableA CREATE TABLE `TableA` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'InnoDB'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = InnoDB,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
MySQL_Test_DB.t1 analyze status OK
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -915,6 +915,170 @@ TableA CREATE TABLE `TableA` ( ...@@ -915,6 +915,170 @@ TableA CREATE TABLE `TableA` (
) ENGINE=MEMORY DEFAULT CHARSET=latin1 ) ENGINE=MEMORY DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'Memory'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MEMORY AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = MEMORY,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = MEMORY,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = MEMORY) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
MySQL_Test_DB.t1 analyze note The storage engine for the table doesn't support analyze
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -915,6 +915,170 @@ TableA CREATE TABLE `TableA` ( ...@@ -915,6 +915,170 @@ TableA CREATE TABLE `TableA` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'MyISAM'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = MyISAM,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = MyISAM,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
MySQL_Test_DB.t1 analyze status OK
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -181,6 +181,18 @@ TableA CREATE TABLE `TableA` ( ...@@ -181,6 +181,18 @@ TableA CREATE TABLE `TableA` (
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
# Cleaning up after KEY PARTITIONING test # Cleaning up after KEY PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Verify that TRUNCATE PARTITION gives error
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'NDBCluster'
PARTITION BY KEY (a)
(PARTITION LT1000,
PARTITION LT2000,
PARTITION MAX);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
ALTER TABLE t1 TRUNCATE PARTITION MAX;
Got one of the listed errors
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,18 @@ TableA CREATE TABLE `tablea` ( ...@@ -882,6 +882,18 @@ TableA CREATE TABLE `tablea` (
) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Verify that TRUNCATE PARTITION gives error
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'Archive'
PARTITION BY KEY (a)
(PARTITION LT1000,
PARTITION LT2000,
PARTITION MAX);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
ALTER TABLE t1 TRUNCATE PARTITION MAX;
Got one of the listed errors
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,170 @@ TableA CREATE TABLE `tablea` ( ...@@ -882,6 +882,170 @@ TableA CREATE TABLE `tablea` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'InnoDB'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = InnoDB,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
mysql_test_db.t1 analyze status OK
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,170 @@ TableA CREATE TABLE `tablea` ( ...@@ -882,6 +882,170 @@ TableA CREATE TABLE `tablea` (
) ENGINE=MEMORY DEFAULT CHARSET=latin1 ) ENGINE=MEMORY DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'Memory'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MEMORY AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = MEMORY,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = MEMORY,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = MEMORY) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
mysql_test_db.t1 analyze note The storage engine for the table doesn't support analyze
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,170 @@ TableA CREATE TABLE `tablea` ( ...@@ -882,6 +882,170 @@ TableA CREATE TABLE `tablea` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'MyISAM'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = MyISAM,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = MyISAM,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
mysql_test_db.t1 analyze status OK
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -219,6 +219,18 @@ TableA CREATE TABLE `tablea` ( ...@@ -219,6 +219,18 @@ TableA CREATE TABLE `tablea` (
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
# Cleaning up after KEY PARTITIONING test # Cleaning up after KEY PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Verify that TRUNCATE PARTITION gives error
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'NDBCluster'
PARTITION BY KEY (a)
(PARTITION LT1000,
PARTITION LT2000,
PARTITION MAX);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
ALTER TABLE t1 TRUNCATE PARTITION MAX;
Got one of the listed errors
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,18 @@ TableA CREATE TABLE `TableA` ( ...@@ -882,6 +882,18 @@ TableA CREATE TABLE `TableA` (
) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Verify that TRUNCATE PARTITION gives error
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'Archive'
PARTITION BY KEY (a)
(PARTITION LT1000,
PARTITION LT2000,
PARTITION MAX);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
ALTER TABLE t1 TRUNCATE PARTITION MAX;
Got one of the listed errors
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,170 @@ TableA CREATE TABLE `TableA` ( ...@@ -882,6 +882,170 @@ TableA CREATE TABLE `TableA` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'InnoDB'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = InnoDB,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
mysql_test_db.t1 analyze status OK
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,170 @@ TableA CREATE TABLE `TableA` ( ...@@ -882,6 +882,170 @@ TableA CREATE TABLE `TableA` (
) ENGINE=MEMORY DEFAULT CHARSET=latin1 ) ENGINE=MEMORY DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'Memory'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MEMORY AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = MEMORY,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = MEMORY,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = MEMORY) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
mysql_test_db.t1 analyze note The storage engine for the table doesn't support analyze
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -882,6 +882,170 @@ TableA CREATE TABLE `TableA` ( ...@@ -882,6 +882,170 @@ TableA CREATE TABLE `TableA` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
# Cleaning up after LIST PARTITIONING test # Cleaning up after LIST PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Testing TRUNCATE PARTITION
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'MyISAM'
PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000),
PARTITION LT2000 VALUES LESS THAN (2000),
PARTITION MAX VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL AUTO_INCREMENT,
`b` varchar(255) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM AUTO_INCREMENT=2002 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION LT1000 VALUES LESS THAN (1000) ENGINE = MyISAM,
PARTITION LT2000 VALUES LESS THAN (2000) ENGINE = MyISAM,
PARTITION MAX VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t1 ORDER BY a;
a b
1 First
2 Second
999 Last in LT1000
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First in MAX
2001 Second in MAX
ALTER TABLE t1 ANALYZE PARTITION MAX;
Table Op Msg_type Msg_text
mysql_test_db.t1 analyze status OK
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION MAX;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION MAX;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)");
SELECT * FROM t1 WHERE a >= 2000;
a b
2000 First after TRUNCATE MAX (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT1000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
1000 First in LT2000
1001 Second in LT2000
1999 Last in LT2000
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
# Truncate without FLUSH
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
# Truncate with FLUSH after
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
FLUSH TABLES;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
# Truncate with FLUSH before
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
# Truncate with FLUSH after INSERT
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION LT2000;
INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)");
SELECT * FROM t1 ORDER BY a;
a b
2000 First after TRUNCATE MAX (4)
2001 First after TRUNCATE LT1000 (1)
2002 First after TRUNCATE LT1000 (2)
2003 First after TRUNCATE LT1000 (3)
2004 First after TRUNCATE LT1000 (4)
2005 First after TRUNCATE LT2000 (1)
2006 First after TRUNCATE LT2000 (2)
2007 First after TRUNCATE LT2000 (3)
2008 First after TRUNCATE LT2000 (4)
DROP TABLE t1;
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -219,6 +219,18 @@ TableA CREATE TABLE `TableA` ( ...@@ -219,6 +219,18 @@ TableA CREATE TABLE `TableA` (
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
# Cleaning up after KEY PARTITIONING test # Cleaning up after KEY PARTITIONING test
DROP TABLE TableA; DROP TABLE TableA;
# Verify that TRUNCATE PARTITION gives error
CREATE TABLE t1
(a BIGINT AUTO_INCREMENT PRIMARY KEY,
b VARCHAR(255))
ENGINE = 'NDBCluster'
PARTITION BY KEY (a)
(PARTITION LT1000,
PARTITION LT2000,
PARTITION MAX);
INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX");
ALTER TABLE t1 TRUNCATE PARTITION MAX;
Got one of the listed errors
# Cleaning up before exit # Cleaning up before exit
USE test; USE test;
DROP DATABASE MySQL_Test_DB; DROP DATABASE MySQL_Test_DB;
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
##### Storage engine to be tested ##### Storage engine to be tested
--source include/have_archive.inc --source include/have_archive.inc
let $engine= 'Archive'; let $engine= 'Archive';
let $no_truncate= 1;
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines # Execute the tests to be applied to all storage engines
......
...@@ -41,6 +41,8 @@ let $can_only_key= 1; ...@@ -41,6 +41,8 @@ let $can_only_key= 1;
# Allow hash/list/range partitioning with ndb # Allow hash/list/range partitioning with ndb
#SET new=on; #SET new=on;
let $engine= 'NDBCluster'; let $engine= 'NDBCluster';
# NDB does not yet support TRUNCATE PARTITION
let $no_truncate= 1;
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines # Execute the tests to be applied to all storage engines
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
##### Storage engine to be tested ##### Storage engine to be tested
--source include/have_archive.inc --source include/have_archive.inc
let $engine= 'Archive'; let $engine= 'Archive';
let $no_truncate= 1;
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines # Execute the tests to be applied to all storage engines
......
...@@ -38,6 +38,8 @@ let $can_only_key= 1; ...@@ -38,6 +38,8 @@ let $can_only_key= 1;
# Allow hash/list/range partitioning with ndb # Allow hash/list/range partitioning with ndb
#SET new=on; #SET new=on;
let $engine= 'NDBCluster'; let $engine= 'NDBCluster';
# NDB does not yet support TRUNCATE PARTITION
let $no_truncate= 1;
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines # Execute the tests to be applied to all storage engines
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
##### Storage engine to be tested ##### Storage engine to be tested
--source include/have_archive.inc --source include/have_archive.inc
let $engine= 'Archive'; let $engine= 'Archive';
let $no_truncate= 1;
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines # Execute the tests to be applied to all storage engines
......
...@@ -37,6 +37,8 @@ let $can_only_key= 1; ...@@ -37,6 +37,8 @@ let $can_only_key= 1;
# Allow hash/list/range partitioning with ndb # Allow hash/list/range partitioning with ndb
#SET new=on; #SET new=on;
let $engine= 'NDBCluster'; let $engine= 'NDBCluster';
# NDB does not yet support TRUNCATE PARTITION
let $no_truncate= 1;
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines # Execute the tests to be applied to all storage engines
......
#
# Simple tests to verify truncate partition syntax
#
--source include/have_partition.inc
--disable_warnings
drop table if exists t1, t2, t3, t4;
--enable_warnings
create table t1 (a int)
partition by list (a)
(partition p1 values in (0));
--error ER_WRONG_PARTITION_NAME
alter table t1 truncate partition p1,p1;
--error ER_WRONG_PARTITION_NAME
alter table t1 truncate partition p0;
drop table t1;
create table t1 (a int)
partition by list (a)
subpartition by hash (a)
subpartitions 1
(partition p1 values in (1)
(subpartition sp1));
--error ER_WRONG_PARTITION_NAME
alter table t1 truncate partition sp1;
drop table t1;
...@@ -1062,7 +1062,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, ...@@ -1062,7 +1062,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
it should only do named partitions, otherwise all partitions it should only do named partitions, otherwise all partitions
*/ */
if (!(thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION) || if (!(thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION) ||
part_elem->part_state == PART_CHANGED) part_elem->part_state == PART_ADMIN)
{ {
if (m_is_sub_partitioned) if (m_is_sub_partitioned)
{ {
...@@ -1123,6 +1123,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, ...@@ -1123,6 +1123,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
DBUG_RETURN(error); DBUG_RETURN(error);
} }
} }
part_elem->part_state= PART_NORMAL;
} }
} while (++i < no_parts); } while (++i < no_parts);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
...@@ -3202,6 +3203,9 @@ int ha_partition::delete_row(const uchar *buf) ...@@ -3202,6 +3203,9 @@ int ha_partition::delete_row(const uchar *buf)
Called from sql_delete.cc by mysql_delete(). Called from sql_delete.cc by mysql_delete().
Called from sql_select.cc by JOIN::reinit(). Called from sql_select.cc by JOIN::reinit().
Called from sql_union.cc by st_select_lex_unit::exec(). Called from sql_union.cc by st_select_lex_unit::exec().
Also used for handle ALTER TABLE t TRUNCATE PARTITION ...
NOTE: auto increment value will be truncated in that partition as well!
*/ */
int ha_partition::delete_all_rows() int ha_partition::delete_all_rows()
...@@ -3214,11 +3218,84 @@ int ha_partition::delete_all_rows() ...@@ -3214,11 +3218,84 @@ int ha_partition::delete_all_rows()
if (thd->lex->sql_command == SQLCOM_TRUNCATE) if (thd->lex->sql_command == SQLCOM_TRUNCATE)
{ {
Alter_info *alter_info= &thd->lex->alter_info;
HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
/* TRUNCATE also means resetting auto_increment */
lock_auto_increment(); lock_auto_increment();
ha_data->next_auto_inc_val= 0; ha_data->next_auto_inc_val= 0;
ha_data->auto_inc_initialized= FALSE; ha_data->auto_inc_initialized= FALSE;
unlock_auto_increment(); unlock_auto_increment();
if (alter_info->flags & ALTER_ADMIN_PARTITION)
{
/* ALTER TABLE t TRUNCATE PARTITION ... */
List_iterator<partition_element> part_it(m_part_info->partitions);
int saved_error= 0;
uint no_parts= m_part_info->no_parts;
uint no_subparts= m_part_info->no_subparts;
uint i= 0;
uint no_parts_set= alter_info->partition_names.elements;
uint no_parts_found= set_part_state(alter_info, m_part_info,
PART_ADMIN);
if (no_parts_set != no_parts_found &&
(!(alter_info->flags & ALTER_ALL_PARTITION)))
DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
/*
Cannot return HA_ERR_WRONG_COMMAND here without correct pruning
since that whould delete the whole table row by row in sql_delete.cc
*/
bitmap_clear_all(&m_part_info->used_partitions);
do
{
partition_element *part_elem= part_it++;
if (part_elem->part_state == PART_ADMIN)
{
if (m_is_sub_partitioned)
{
List_iterator<partition_element>
subpart_it(part_elem->subpartitions);
partition_element *sub_elem;
uint j= 0, part;
do
{
sub_elem= subpart_it++;
part= i * no_subparts + j;
bitmap_set_bit(&m_part_info->used_partitions, part);
if (!saved_error)
{
DBUG_PRINT("info", ("truncate subpartition %u (%s)",
part, sub_elem->partition_name));
if ((error= m_file[part]->ha_delete_all_rows()))
saved_error= error;
/* If not reset_auto_increment is supported, just accept it */
if (!saved_error &&
(error= m_file[part]->ha_reset_auto_increment(0)) &&
error != HA_ERR_WRONG_COMMAND)
saved_error= error;
}
} while (++j < no_subparts);
}
else
{
DBUG_PRINT("info", ("truncate partition %u (%s)", i,
part_elem->partition_name));
bitmap_set_bit(&m_part_info->used_partitions, i);
if (!saved_error)
{
if ((error= m_file[i]->ha_delete_all_rows()) && !saved_error)
saved_error= error;
/* If not reset_auto_increment is supported, just accept it */
if (!saved_error &&
(error= m_file[i]->ha_reset_auto_increment(0)) &&
error != HA_ERR_WRONG_COMMAND)
saved_error= error;
}
}
part_elem->part_state= PART_NORMAL;
}
} while (++i < no_parts);
DBUG_RETURN(saved_error);
}
truncate= TRUE; truncate= TRUE;
} }
file= m_file; file= m_file;
...@@ -5842,12 +5919,14 @@ enum row_type ha_partition::get_row_type() const ...@@ -5842,12 +5919,14 @@ enum row_type ha_partition::get_row_type() const
void ha_partition::print_error(int error, myf errflag) void ha_partition::print_error(int error, myf errflag)
{ {
THD *thd= ha_thd();
DBUG_ENTER("ha_partition::print_error"); DBUG_ENTER("ha_partition::print_error");
/* Should probably look for my own errors first */ /* Should probably look for my own errors first */
DBUG_PRINT("enter", ("error: %d", error)); DBUG_PRINT("enter", ("error: %d", error));
if (error == HA_ERR_NO_PARTITION_FOUND) if (error == HA_ERR_NO_PARTITION_FOUND &&
thd->lex->sql_command != SQLCOM_TRUNCATE)
m_part_info->print_no_partition_found(table); m_part_info->print_no_partition_found(table);
else else
m_file[m_last_part]->print_error(error, errflag); m_file[m_last_part]->print_error(error, errflag);
......
...@@ -2742,6 +2742,9 @@ void handler::print_error(int error, myf errflag) ...@@ -2742,6 +2742,9 @@ void handler::print_error(int error, myf errflag)
case HA_ERR_TABLE_NEEDS_UPGRADE: case HA_ERR_TABLE_NEEDS_UPGRADE:
textno=ER_TABLE_NEEDS_UPGRADE; textno=ER_TABLE_NEEDS_UPGRADE;
break; break;
case HA_ERR_NO_PARTITION_FOUND:
textno=ER_WRONG_PARTITION_NAME;
break;
case HA_ERR_TABLE_READONLY: case HA_ERR_TABLE_READONLY:
textno= ER_OPEN_AS_READONLY; textno= ER_OPEN_AS_READONLY;
break; break;
......
...@@ -32,7 +32,8 @@ enum partition_state { ...@@ -32,7 +32,8 @@ enum partition_state {
PART_REORGED_DROPPED= 5, PART_REORGED_DROPPED= 5,
PART_CHANGED= 6, PART_CHANGED= 6,
PART_IS_CHANGED= 7, PART_IS_CHANGED= 7,
PART_IS_ADDED= 8 PART_IS_ADDED= 8,
PART_ADMIN= 9
}; };
/* /*
......
...@@ -1075,6 +1075,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -1075,6 +1075,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
{ {
handlerton *table_type= table->s->db_type(); handlerton *table_type= table->s->db_type();
TABLE_SHARE *share= table->s; TABLE_SHARE *share= table->s;
/* Note that a temporary table cannot be partitioned */
if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE)) if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
goto trunc_by_del; goto trunc_by_del;
...@@ -1113,8 +1114,22 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -1113,8 +1114,22 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
table_list->db, table_list->table_name); table_list->db, table_list->table_name);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd, table_type), #ifdef WITH_PARTITION_STORAGE_ENGINE
HTON_CAN_RECREATE)) /*
TODO: Add support for TRUNCATE PARTITION for NDB and other engines
supporting native partitioning
*/
if (table_type != DB_TYPE_PARTITION_DB &&
thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION)
{
my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0));
DBUG_RETURN(TRUE);
}
#endif
if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd,
table_type),
HTON_CAN_RECREATE) ||
thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION)
goto trunc_by_del; goto trunc_by_del;
if (lock_and_wait_for_table_name(thd, table_list)) if (lock_and_wait_for_table_name(thd, table_list))
......
...@@ -4158,6 +4158,8 @@ uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info, ...@@ -4158,6 +4158,8 @@ uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
DBUG_PRINT("info", ("Setting part_state to %u for partition %s", DBUG_PRINT("info", ("Setting part_state to %u for partition %s",
part_state, part_elem->partition_name)); part_state, part_elem->partition_name));
} }
else
part_elem->part_state= PART_NORMAL;
} while (++part_count < tab_part_info->no_parts); } while (++part_count < tab_part_info->no_parts);
return no_parts_found; return no_parts_found;
} }
......
...@@ -4534,7 +4534,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -4534,7 +4534,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
uint no_parts_found; uint no_parts_found;
uint no_parts_opt= alter_info->partition_names.elements; uint no_parts_opt= alter_info->partition_names.elements;
no_parts_found= set_part_state(alter_info, table->table->part_info, no_parts_found= set_part_state(alter_info, table->table->part_info,
PART_CHANGED); PART_ADMIN);
if (no_parts_found != no_parts_opt && if (no_parts_found != no_parts_opt &&
(!(alter_info->flags & ALTER_ALL_PARTITION))) (!(alter_info->flags & ALTER_ALL_PARTITION)))
{ {
......
...@@ -5671,7 +5671,7 @@ alter_commands: ...@@ -5671,7 +5671,7 @@ alter_commands:
all_or_alt_part_name_list all_or_alt_part_name_list
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sql_command = SQLCOM_OPTIMIZE; lex->sql_command= SQLCOM_OPTIMIZE;
lex->alter_info.flags|= ALTER_ADMIN_PARTITION; lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->no_write_to_binlog= $3; lex->no_write_to_binlog= $3;
lex->check_opt.init(); lex->check_opt.init();
...@@ -5681,7 +5681,7 @@ alter_commands: ...@@ -5681,7 +5681,7 @@ alter_commands:
all_or_alt_part_name_list all_or_alt_part_name_list
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sql_command = SQLCOM_ANALYZE; lex->sql_command= SQLCOM_ANALYZE;
lex->alter_info.flags|= ALTER_ADMIN_PARTITION; lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->no_write_to_binlog= $3; lex->no_write_to_binlog= $3;
lex->check_opt.init(); lex->check_opt.init();
...@@ -5689,7 +5689,7 @@ alter_commands: ...@@ -5689,7 +5689,7 @@ alter_commands:
| CHECK_SYM PARTITION_SYM all_or_alt_part_name_list | CHECK_SYM PARTITION_SYM all_or_alt_part_name_list
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sql_command = SQLCOM_CHECK; lex->sql_command= SQLCOM_CHECK;
lex->alter_info.flags|= ALTER_ADMIN_PARTITION; lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->check_opt.init(); lex->check_opt.init();
} }
...@@ -5698,7 +5698,7 @@ alter_commands: ...@@ -5698,7 +5698,7 @@ alter_commands:
all_or_alt_part_name_list all_or_alt_part_name_list
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sql_command = SQLCOM_REPAIR; lex->sql_command= SQLCOM_REPAIR;
lex->alter_info.flags|= ALTER_ADMIN_PARTITION; lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->no_write_to_binlog= $3; lex->no_write_to_binlog= $3;
lex->check_opt.init(); lex->check_opt.init();
...@@ -5711,6 +5711,13 @@ alter_commands: ...@@ -5711,6 +5711,13 @@ alter_commands:
lex->no_write_to_binlog= $3; lex->no_write_to_binlog= $3;
lex->alter_info.no_parts= $4; lex->alter_info.no_parts= $4;
} }
| TRUNCATE_SYM PARTITION_SYM all_or_alt_part_name_list
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_TRUNCATE;
lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->check_opt.init();
}
| reorg_partition_rule | reorg_partition_rule
; ;
...@@ -9758,6 +9765,7 @@ truncate: ...@@ -9758,6 +9765,7 @@ truncate:
{ {
LEX* lex= Lex; LEX* lex= Lex;
lex->sql_command= SQLCOM_TRUNCATE; lex->sql_command= SQLCOM_TRUNCATE;
lex->alter_info.reset();
lex->select_lex.options= 0; lex->select_lex.options= 0;
lex->select_lex.sql_cache= SELECT_LEX::SQL_CACHE_UNSPECIFIED; lex->select_lex.sql_cache= SELECT_LEX::SQL_CACHE_UNSPECIFIED;
lex->select_lex.init_order(); lex->select_lex.init_order();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment