MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Mikael Ronstrom Date:September 10 2009 9:15am
Subject:bzr commit into mysql-5.4 branch (mikael:2877) Bug#19405 Bug#35111 WL#4444
View as plain text  
#At file:///home/mikael/mysql_clones/mysql-trunk-wl4444/

 2877 Mikael Ronstrom	2009-09-10
      WL#4444 Added TRUNCATE partition support, fixes bug#19405 and bug #35111
      added:
        mysql-test/r/partition_truncate.result
        mysql-test/t/partition_truncate.test
      modified:
        BUILD/build_mccge.sh
        mysql-test/suite/parts/inc/partition_mgm.inc
        mysql-test/suite/parts/r/partition_mgm_lc0_archive.result
        mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result
        mysql-test/suite/parts/r/partition_mgm_lc0_memory.result
        mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result
        mysql-test/suite/parts/r/partition_mgm_lc0_ndb.result
        mysql-test/suite/parts/r/partition_mgm_lc1_archive.result
        mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result
        mysql-test/suite/parts/r/partition_mgm_lc1_memory.result
        mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result
        mysql-test/suite/parts/r/partition_mgm_lc1_ndb.result
        mysql-test/suite/parts/r/partition_mgm_lc2_archive.result
        mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result
        mysql-test/suite/parts/r/partition_mgm_lc2_memory.result
        mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result
        mysql-test/suite/parts/r/partition_mgm_lc2_ndb.result
        mysql-test/suite/parts/t/partition_mgm_lc0_archive.test
        mysql-test/suite/parts/t/partition_mgm_lc0_ndb.test
        mysql-test/suite/parts/t/partition_mgm_lc1_archive.test
        mysql-test/suite/parts/t/partition_mgm_lc1_ndb.test
        mysql-test/suite/parts/t/partition_mgm_lc2_archive.test
        mysql-test/suite/parts/t/partition_mgm_lc2_ndb.test
        sql/ha_partition.cc
        sql/handler.cc
        sql/partition_element.h
        sql/sql_delete.cc
        sql/sql_partition.cc
        sql/sql_table.cc
        sql/sql_yacc.yy

=== modified file 'BUILD/build_mccge.sh'
--- a/BUILD/build_mccge.sh	2009-03-11 21:17:48 +0000
+++ b/BUILD/build_mccge.sh	2009-09-10 09:15:39 +0000
@@ -556,7 +556,7 @@ parse_package()
       package="pro"
       ;;
     extended )
-      package=""
+      package="extended"
       ;;
     cge )
       package="cge"

=== added file 'mysql-test/r/partition_truncate.result'
--- a/mysql-test/r/partition_truncate.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/partition_truncate.result	2009-09-10 09:15:39 +0000
@@ -0,0 +1,18 @@
+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;

=== modified file 'mysql-test/suite/parts/inc/partition_mgm.inc'
--- a/mysql-test/suite/parts/inc/partition_mgm.inc	2008-11-05 21:26:39 +0000
+++ b/mysql-test/suite/parts/inc/partition_mgm.inc	2009-09-10 09:15:39 +0000
@@ -13,6 +13,7 @@
 #   part_optA-D   Extra partitioning options (E.g. INDEX/DATA DIR)             #
 #                                                                              #
 #   have_bug33158 NDB case insensitive create, but case sensitive rename       #
+#   no_truncate   No support for truncate partition                            #
 #------------------------------------------------------------------------------#
 # Original Author: mattiasj                                                    #
 # Original Date: 2008-06-27                                                    #
@@ -518,6 +519,95 @@ DROP TABLE TableA;
 }
 # 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
 eval USE $old_db;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_archive.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result	2009-09-10 09:15:39 +0000
@@ -915,6 +915,18 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result	2009-09-10 09:15:39 +0000
@@ -915,6 +915,170 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_memory.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result	2009-09-10 09:15:39 +0000
@@ -915,6 +915,170 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=MEMORY DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result	2009-09-10 09:15:39 +0000
@@ -915,6 +915,170 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_ndb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_ndb.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_ndb.result	2009-09-10 09:15:39 +0000
@@ -181,6 +181,18 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
 # Cleaning up after KEY PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_archive.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,18 @@ TableA	CREATE TABLE `tablea` (
 ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,170 @@ TableA	CREATE TABLE `tablea` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_memory.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,170 @@ TableA	CREATE TABLE `tablea` (
 ) ENGINE=MEMORY DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,170 @@ TableA	CREATE TABLE `tablea` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_ndb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_ndb.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_ndb.result	2009-09-10 09:15:39 +0000
@@ -219,6 +219,18 @@ TableA	CREATE TABLE `tablea` (
 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
 # Cleaning up after KEY PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_archive.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,18 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,170 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_memory.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,170 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=MEMORY DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result	2009-09-10 09:15:39 +0000
@@ -882,6 +882,170 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 # Cleaning up after LIST PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_ndb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_ndb.result	2009-02-18 20:22:56 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_ndb.result	2009-09-10 09:15:39 +0000
@@ -219,6 +219,18 @@ TableA	CREATE TABLE `TableA` (
 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
 # Cleaning up after KEY PARTITIONING test
 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
 USE test;
 DROP DATABASE MySQL_Test_DB;

=== modified file 'mysql-test/suite/parts/t/partition_mgm_lc0_archive.test'
--- a/mysql-test/suite/parts/t/partition_mgm_lc0_archive.test	2008-11-05 21:26:39 +0000
+++ b/mysql-test/suite/parts/t/partition_mgm_lc0_archive.test	2009-09-10 09:15:39 +0000
@@ -35,6 +35,7 @@
 ##### Storage engine to be tested
 --source include/have_archive.inc
 let $engine= 'Archive';
+let $no_truncate= 1;
 
 #------------------------------------------------------------------------------#
 # Execute the tests to be applied to all storage engines

=== modified file 'mysql-test/suite/parts/t/partition_mgm_lc0_ndb.test'
--- a/mysql-test/suite/parts/t/partition_mgm_lc0_ndb.test	2008-07-10 23:14:13 +0000
+++ b/mysql-test/suite/parts/t/partition_mgm_lc0_ndb.test	2009-09-10 09:15:39 +0000
@@ -41,6 +41,8 @@ let $can_only_key= 1;
 # Allow hash/list/range partitioning with ndb
 #SET new=on;
 let $engine= 'NDBCluster';
+# NDB does not yet support TRUNCATE PARTITION
+let $no_truncate= 1;
 
 #------------------------------------------------------------------------------#
 # Execute the tests to be applied to all storage engines

=== modified file 'mysql-test/suite/parts/t/partition_mgm_lc1_archive.test'
--- a/mysql-test/suite/parts/t/partition_mgm_lc1_archive.test	2008-07-10 23:14:13 +0000
+++ b/mysql-test/suite/parts/t/partition_mgm_lc1_archive.test	2009-09-10 09:15:39 +0000
@@ -32,6 +32,7 @@
 ##### Storage engine to be tested
 --source include/have_archive.inc
 let $engine= 'Archive';
+let $no_truncate= 1;
 
 #------------------------------------------------------------------------------#
 # Execute the tests to be applied to all storage engines

=== modified file 'mysql-test/suite/parts/t/partition_mgm_lc1_ndb.test'
--- a/mysql-test/suite/parts/t/partition_mgm_lc1_ndb.test	2008-07-10 23:14:13 +0000
+++ b/mysql-test/suite/parts/t/partition_mgm_lc1_ndb.test	2009-09-10 09:15:39 +0000
@@ -38,6 +38,8 @@ let $can_only_key= 1;
 # Allow hash/list/range partitioning with ndb
 #SET new=on;
 let $engine= 'NDBCluster';
+# NDB does not yet support TRUNCATE PARTITION
+let $no_truncate= 1;
 
 #------------------------------------------------------------------------------#
 # Execute the tests to be applied to all storage engines

=== modified file 'mysql-test/suite/parts/t/partition_mgm_lc2_archive.test'
--- a/mysql-test/suite/parts/t/partition_mgm_lc2_archive.test	2008-07-10 23:14:13 +0000
+++ b/mysql-test/suite/parts/t/partition_mgm_lc2_archive.test	2009-09-10 09:15:39 +0000
@@ -32,6 +32,7 @@
 ##### Storage engine to be tested
 --source include/have_archive.inc
 let $engine= 'Archive';
+let $no_truncate= 1;
 
 #------------------------------------------------------------------------------#
 # Execute the tests to be applied to all storage engines

=== modified file 'mysql-test/suite/parts/t/partition_mgm_lc2_ndb.test'
--- a/mysql-test/suite/parts/t/partition_mgm_lc2_ndb.test	2008-07-10 23:14:13 +0000
+++ b/mysql-test/suite/parts/t/partition_mgm_lc2_ndb.test	2009-09-10 09:15:39 +0000
@@ -37,6 +37,8 @@ let $can_only_key= 1;
 # Allow hash/list/range partitioning with ndb
 #SET new=on;
 let $engine= 'NDBCluster';
+# NDB does not yet support TRUNCATE PARTITION
+let $no_truncate= 1;
 
 #------------------------------------------------------------------------------#
 # Execute the tests to be applied to all storage engines

=== added file 'mysql-test/t/partition_truncate.test'
--- a/mysql-test/t/partition_truncate.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/partition_truncate.test	2009-09-10 09:15:39 +0000
@@ -0,0 +1,26 @@
+#
+# 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;

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2009-08-21 15:38:29 +0000
+++ b/sql/ha_partition.cc	2009-09-10 09:15:39 +0000
@@ -1062,7 +1062,7 @@ int ha_partition::handle_opt_partitions(
       it should only do named partitions, otherwise all partitions
     */
     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)
       {
@@ -1123,6 +1123,7 @@ int ha_partition::handle_opt_partitions(
           DBUG_RETURN(error);
         }
       }
+      part_elem->part_state= PART_NORMAL;
     }
   } while (++i < no_parts);
   DBUG_RETURN(FALSE);
@@ -3202,6 +3203,9 @@ int ha_partition::delete_row(const uchar
     Called from sql_delete.cc by mysql_delete().
     Called from sql_select.cc by JOIN::reinit().
     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()
@@ -3214,11 +3218,84 @@ int ha_partition::delete_all_rows()
 
   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;
+    /* TRUNCATE also means resetting auto_increment */
     lock_auto_increment();
     ha_data->next_auto_inc_val= 0;
     ha_data->auto_inc_initialized= FALSE;
     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;
   }
   file= m_file;
@@ -5842,12 +5919,14 @@ enum row_type ha_partition::get_row_type
 
 void ha_partition::print_error(int error, myf errflag)
 {
+  THD *thd= ha_thd();
   DBUG_ENTER("ha_partition::print_error");
 
   /* Should probably look for my own errors first */
   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);
   else
     m_file[m_last_part]->print_error(error, errflag);

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2009-08-12 13:44:34 +0000
+++ b/sql/handler.cc	2009-09-10 09:15:39 +0000
@@ -2742,6 +2742,9 @@ void handler::print_error(int error, myf
   case HA_ERR_TABLE_NEEDS_UPGRADE:
     textno=ER_TABLE_NEEDS_UPGRADE;
     break;
+  case HA_ERR_NO_PARTITION_FOUND:
+    textno=ER_WRONG_PARTITION_NAME;
+    break;
   case HA_ERR_TABLE_READONLY:
     textno= ER_OPEN_AS_READONLY;
     break;

=== modified file 'sql/partition_element.h'
--- a/sql/partition_element.h	2007-04-13 17:23:02 +0000
+++ b/sql/partition_element.h	2009-09-10 09:15:39 +0000
@@ -32,7 +32,8 @@ enum partition_state {
   PART_REORGED_DROPPED= 5,
   PART_CHANGED= 6,
   PART_IS_CHANGED= 7,
-  PART_IS_ADDED= 8
+  PART_IS_ADDED= 8,
+  PART_ADMIN= 9
 };
 
 /*

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2009-08-21 05:55:35 +0000
+++ b/sql/sql_delete.cc	2009-09-10 09:15:39 +0000
@@ -1075,6 +1075,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST
   {
     handlerton *table_type= table->s->db_type();
     TABLE_SHARE *share= table->s;
+    /* Note that a temporary table cannot be partitioned */
     if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
       goto trunc_by_del;
 
@@ -1113,8 +1114,22 @@ bool mysql_truncate(THD *thd, TABLE_LIST
                table_list->db, table_list->table_name);
       DBUG_RETURN(TRUE);
     }
-    if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd, table_type),
-                                      HTON_CAN_RECREATE))
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+    /*
+      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;
 
     if (lock_and_wait_for_table_name(thd, table_list))

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2009-08-06 12:28:39 +0000
+++ b/sql/sql_partition.cc	2009-09-10 09:15:39 +0000
@@ -4158,6 +4158,8 @@ uint set_part_state(Alter_info *alter_in
       DBUG_PRINT("info", ("Setting part_state to %u for partition %s",
                           part_state, part_elem->partition_name));
     }
+    else
+      part_elem->part_state= PART_NORMAL;
   } while (++part_count < tab_part_info->no_parts);
   return no_parts_found;
 }

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-08-26 15:43:32 +0000
+++ b/sql/sql_table.cc	2009-09-10 09:15:39 +0000
@@ -4534,7 +4534,7 @@ static bool mysql_admin_table(THD* thd, 
           uint no_parts_found;
           uint no_parts_opt= alter_info->partition_names.elements;
           no_parts_found= set_part_state(alter_info, table->table->part_info,
-                                         PART_CHANGED);
+                                         PART_ADMIN);
           if (no_parts_found != no_parts_opt &&
               (!(alter_info->flags & ALTER_ALL_PARTITION)))
           {

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2009-08-26 15:43:32 +0000
+++ b/sql/sql_yacc.yy	2009-09-10 09:15:39 +0000
@@ -5671,7 +5671,7 @@ alter_commands:
           all_or_alt_part_name_list
           {
             LEX *lex= Lex;
-            lex->sql_command = SQLCOM_OPTIMIZE;
+            lex->sql_command= SQLCOM_OPTIMIZE;
             lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
             lex->no_write_to_binlog= $3;
             lex->check_opt.init();
@@ -5681,7 +5681,7 @@ alter_commands:
           all_or_alt_part_name_list
           {
             LEX *lex= Lex;
-            lex->sql_command = SQLCOM_ANALYZE;
+            lex->sql_command= SQLCOM_ANALYZE;
             lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
             lex->no_write_to_binlog= $3;
             lex->check_opt.init();
@@ -5689,7 +5689,7 @@ alter_commands:
         | CHECK_SYM PARTITION_SYM all_or_alt_part_name_list
           {
             LEX *lex= Lex;
-            lex->sql_command = SQLCOM_CHECK;
+            lex->sql_command= SQLCOM_CHECK;
             lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
             lex->check_opt.init();
           }
@@ -5698,7 +5698,7 @@ alter_commands:
           all_or_alt_part_name_list
           {
             LEX *lex= Lex;
-            lex->sql_command = SQLCOM_REPAIR;
+            lex->sql_command= SQLCOM_REPAIR;
             lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
             lex->no_write_to_binlog= $3;
             lex->check_opt.init();
@@ -5711,6 +5711,13 @@ alter_commands:
             lex->no_write_to_binlog= $3;
             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
         ;
 
@@ -9758,6 +9765,7 @@ truncate:
           {
             LEX* lex= Lex;
             lex->sql_command= SQLCOM_TRUNCATE;
+            lex->alter_info.reset();
             lex->select_lex.options= 0;
             lex->select_lex.sql_cache= SELECT_LEX::SQL_CACHE_UNSPECIFIED;
             lex->select_lex.init_order();

Thread
bzr commit into mysql-5.4 branch (mikael:2877) Bug#19405 Bug#35111 WL#4444Mikael Ronstrom10 Sep