List:Commits« Previous MessageNext Message »
From:Frazer Clement Date:March 21 2012 3:44pm
Subject:bzr push into mysql-5.1-telco-7.0 branch (frazer.clement:4901 to 4902)
Bug#13714648
View as plain text  
 4902 Frazer Clement	2012-03-21
      bug#13714648 MYSQL CLUSTER ALTER TABLE REORGANIZE PARTITION UNDEFINED BEHAVIOR 
      
      Background
      
      ALTER ONLINE TABLE REORGANIZE PARTITION (ATRP) is used to create new table partitions
      (fragments), usually after new empty nodes have been added to a cluster.
      
      ATRP determines the number of fragments to create automatically, and if
      it determines that no new fragments are required, then no new fragments
      will be created.
      
      Tables are sometimes created with the MAX_ROWS option set.  This can 
      be used to indicate to Ndb that extra fragments should be created to
      store the large number of rows.
      
      If MAX_ROWS was specified when a table was created, then ATRP will
      use it to decide the number of partitions required, which will be the
      same, so no new fragments will be created.  The table will not be 
      rebalanced, and the new nodes remain empty.
      
      One option considered was to scale the configured MAX_ROWs with the
      relative increase in the number of nodes, but this results in different
      numbers of partitions depending on when a table is created.
      
      Solution
      
      The solution implemented here is to support 
      ALTER ONLINE TABLE MAX_ROWS=<bigger_value> (ATMR).  Where the bigger
      MAX_ROWS value implies that more fragments are required, these will
      be allocated on the new data nodes, restoring table balance.
      
      For tables with MAX_ROWS explicitly defined, ATRP does not work.
      
      ndb_add_partition and ndb_addnode are modified to test the new 
      mechanism. 

    modified:
      mysql-test/suite/ndb/r/ndb_add_partition.result
      mysql-test/suite/ndb/t/ndb_add_partition.test
      mysql-test/suite/ndb/t/ndb_addnode.test
      sql/ha_ndbcluster.cc
      sql/handler.h
      sql/sql_table.cc
 4901 Jonas Oreland	2012-03-21
      ndb - bug#13825163 - decrease timeouts on transporter handshake to prevent live-locking

    modified:
      storage/ndb/include/util/InputStream.hpp
      storage/ndb/src/common/transporter/Transporter.cpp
=== modified file 'mysql-test/suite/ndb/r/ndb_add_partition.result'
--- a/mysql-test/suite/ndb/r/ndb_add_partition.result	2011-05-12 11:31:21 +0000
+++ b/mysql-test/suite/ndb/r/ndb_add_partition.result	2012-03-21 15:42:47 +0000
@@ -24,6 +24,19 @@ ENGINE = NDB
 STORAGE DISK
 TABLESPACE ts1
 partition by key(a);
+CREATE TABLE t3 (a int unsigned not null,
+b int unsigned not null,
+c int unsigned not null,
+primary key(a,b),
+unique (b))
+MAX_ROWS=50000000
+ENGINE = NDB;
+CREATE TABLE t4 (a int unsigned not null,
+b int unsigned not null,
+c int unsigned not null,
+primary key(a,b),
+unique (b))
+ENGINE = NDB;
 INSERT INTO t1 VALUES
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10),
@@ -46,12 +59,20 @@ INSERT INTO t1 VALUES
 (91,91,91),(92,92,92),(93,93,93),(94,94,94),(95,95,95),
 (96,96,96),(97,97,97),(98,98,98),(99,99,99),(100,100,100);
 insert into t2 select * from t1;
+insert into t3 select * from t1;
+insert into t4 select * from t1;
 select count(*) from t1;
 count(*)
 100
 select count(*) from t2;
 count(*)
 100
+select count(*) from t3;
+count(*)
+100
+select count(*) from t4;
+count(*)
+100
 select * from t1 where a < 20;
 a	b	c
 1	1	1
@@ -142,24 +163,146 @@ a	b	c
 select * from t2 where b = 50;
 a	b	c
 50	50	50
+select * from t3 where a < 20;
+a	b	c
+1	1	1
+10	10	10
+11	11	11
+12	12	12
+13	13	13
+14	14	14
+15	15	15
+16	16	16
+17	17	17
+18	18	18
+19	19	19
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+7	7	7
+8	8	8
+9	9	9
+select * from t3 where a = 20;
+a	b	c
+20	20	20
+select * from t3 where a = 30;
+a	b	c
+30	30	30
+select * from t3 where a = 40;
+a	b	c
+40	40	40
+select * from t3 where a = 50;
+a	b	c
+50	50	50
+select * from t3 where b = 20;
+a	b	c
+20	20	20
+select * from t3 where b = 30;
+a	b	c
+30	30	30
+select * from t3 where b = 40;
+a	b	c
+40	40	40
+select * from t3 where b = 50;
+a	b	c
+50	50	50
+select * from t4 where a < 20;
+a	b	c
+1	1	1
+10	10	10
+11	11	11
+12	12	12
+13	13	13
+14	14	14
+15	15	15
+16	16	16
+17	17	17
+18	18	18
+19	19	19
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+7	7	7
+8	8	8
+9	9	9
+select * from t4 where a = 20;
+a	b	c
+20	20	20
+select * from t4 where a = 30;
+a	b	c
+30	30	30
+select * from t4 where a = 40;
+a	b	c
+40	40	40
+select * from t4 where a = 50;
+a	b	c
+50	50	50
+select * from t4 where b = 20;
+a	b	c
+20	20	20
+select * from t4 where b = 30;
+a	b	c
+30	30	30
+select * from t4 where b = 40;
+a	b	c
+40	40	40
+select * from t4 where b = 50;
+a	b	c
+50	50	50
 alter online table t1 reorganize partition;
 alter online table t2 reorganize partition;
+Cannot use normal reorganize partition on t3 as it has explicit MAX_ROWS set
+alter online table t3 reorganize partition;
+ERROR 42000: This version of MySQL doesn't yet support 'alter online table t3 reorganize partition'
+show warnings;
+Level	Code	Message
+Warning	1105	Cannot online REORGANIZE a table with Max_Rows set.  Use ALTER TABLE ... MAX_ROWS=<new_val> or offline REORGANIZE to redistribute this table.
+Error	1235	This version of MySQL doesn't yet support 'alter online table t3 reorganize partition'
+alter online table t3 max_rows=50000000;
+alter online table t4 reorganize partition;
+Check partitions added, expect 0 in all cases
 partitions added to t1
 t1_added
 0
 partitions added to t2
 t2_added
 0
+partitions added to t3
+t3_added
+0
+partitions added to t4
+t4_added
+0
 alter online table t1 add partition partitions 1;
 alter online table t2 add partition partitions 4;
-partitions added to t1
+alter online table t3 max_rows=100000000;
+alter online table t4 max_rows=100000000;
+ERROR 42000: This version of MySQL doesn't yet support 'alter online table t4 max_rows=100000000'
+partitions added to t1 (expect 1)
 t1_added
 1
-partitions added to t2
+partitions added to t2 (expect 4)
 t2_added
 4
+partitions added to t3 (expect 2)
+t3_added
+2
+partitions added to t4 (expect 0)
+t4_added
+0
 alter online table t1 reorganize partition;
 ERROR HY000: REORGANIZE PARTITION without parameters can only be used on auto-partitioned tables using HASH PARTITIONs
+alter online table t3 reorganize partition;
+ERROR 42000: This version of MySQL doesn't yet support 'alter online table t3 reorganize partition'
+show warnings;
+Level	Code	Message
+Warning	1105	Cannot online REORGANIZE a table with Max_Rows set.  Use ALTER TABLE ... MAX_ROWS=<new_val> or offline REORGANIZE to redistribute this table.
+Error	1235	This version of MySQL doesn't yet support 'alter online table t3 reorganize partition'
+alter online table t4 reorganize partition;
 select count(*) from t1;
 count(*)
 100
@@ -256,14 +399,109 @@ a	b	c
 select * from t2 where b = 50;
 a	b	c
 50	50	50
+select * from t3 where a < 20;
+a	b	c
+1	1	1
+10	10	10
+11	11	11
+12	12	12
+13	13	13
+14	14	14
+15	15	15
+16	16	16
+17	17	17
+18	18	18
+19	19	19
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+7	7	7
+8	8	8
+9	9	9
+select * from t3 where a = 20;
+a	b	c
+20	20	20
+select * from t3 where a = 30;
+a	b	c
+30	30	30
+select * from t3 where a = 40;
+a	b	c
+40	40	40
+select * from t3 where a = 50;
+a	b	c
+50	50	50
+select * from t3 where b = 20;
+a	b	c
+20	20	20
+select * from t3 where b = 30;
+a	b	c
+30	30	30
+select * from t3 where b = 40;
+a	b	c
+40	40	40
+select * from t3 where b = 50;
+a	b	c
+50	50	50
+select * from t4 where a < 20;
+a	b	c
+1	1	1
+10	10	10
+11	11	11
+12	12	12
+13	13	13
+14	14	14
+15	15	15
+16	16	16
+17	17	17
+18	18	18
+19	19	19
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+7	7	7
+8	8	8
+9	9	9
+select * from t4 where a = 20;
+a	b	c
+20	20	20
+select * from t4 where a = 30;
+a	b	c
+30	30	30
+select * from t4 where a = 40;
+a	b	c
+40	40	40
+select * from t4 where a = 50;
+a	b	c
+50	50	50
+select * from t4 where b = 20;
+a	b	c
+20	20	20
+select * from t4 where b = 30;
+a	b	c
+30	30	30
+select * from t4 where b = 40;
+a	b	c
+40	40	40
+select * from t4 where b = 50;
+a	b	c
+50	50	50
+drop table t4;
 alter online table t1 add partition partitions 2;
 alter online table t2 add partition partitions 1;
-partitions added to t1
+alter online table t3 max_rows=150000000;
+partitions added to t1 (expect 3)
 t1_added
 3
-partitions added to t2
+partitions added to t2 (expect 5)
 t2_added
 5
+partitions added to t3 (expect 4)
+t3_added
+4
 select count(*) from t1;
 count(*)
 100
@@ -360,7 +598,52 @@ a	b	c
 select * from t2 where b = 50;
 a	b	c
 50	50	50
-drop table t1,t2;
+select * from t3 where a < 20;
+a	b	c
+1	1	1
+10	10	10
+11	11	11
+12	12	12
+13	13	13
+14	14	14
+15	15	15
+16	16	16
+17	17	17
+18	18	18
+19	19	19
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+7	7	7
+8	8	8
+9	9	9
+select * from t3 where a = 20;
+a	b	c
+20	20	20
+select * from t3 where a = 30;
+a	b	c
+30	30	30
+select * from t3 where a = 40;
+a	b	c
+40	40	40
+select * from t3 where a = 50;
+a	b	c
+50	50	50
+select * from t3 where b = 20;
+a	b	c
+20	20	20
+select * from t3 where b = 30;
+a	b	c
+30	30	30
+select * from t3 where b = 40;
+a	b	c
+40	40	40
+select * from t3 where b = 50;
+a	b	c
+50	50	50
+drop table t1,t2,t3;
 alter tablespace ts1 drop datafile 'datafile.dat' engine = ndb;
 drop tablespace ts1 engine = ndb;
 drop logfile group lg1 engine = ndb;

=== modified file 'mysql-test/suite/ndb/t/ndb_add_partition.test'
--- a/mysql-test/suite/ndb/t/ndb_add_partition.test	2011-05-12 11:31:21 +0000
+++ b/mysql-test/suite/ndb/t/ndb_add_partition.test	2012-03-21 15:42:47 +0000
@@ -33,10 +33,29 @@ STORAGE DISK
 TABLESPACE ts1
 partition by key(a);
 
+CREATE TABLE t3 (a int unsigned not null,
+                 b int unsigned not null,
+                 c int unsigned not null,
+                 primary key(a,b),
+                 unique (b))
+MAX_ROWS=50000000
+ENGINE = NDB;
+
+CREATE TABLE t4 (a int unsigned not null,
+                 b int unsigned not null,
+                 c int unsigned not null,
+                 primary key(a,b),
+                 unique (b))
+ENGINE = NDB;
+
 let $t1_part_count_start = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't1', Value, 1);
 
 let $t2_part_count_start = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't2', Value, 1);
 
+let $t3_part_count_start = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't3', Value, 1);
+
+let $t4_part_count_start = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't4', Value, 1);
+
 INSERT INTO t1 VALUES
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10),
@@ -60,8 +79,12 @@ INSERT INTO t1 VALUES
 (96,96,96),(97,97,97),(98,98,98),(99,99,99),(100,100,100);
 
 insert into t2 select * from t1;
+insert into t3 select * from t1;
+insert into t4 select * from t1;
 select count(*) from t1;
 select count(*) from t2;
+select count(*) from t3;
+select count(*) from t4;
 --sorted_result
 select * from t1 where a < 20;
 --sorted_result
@@ -92,32 +115,89 @@ select * from t2 where b = 30;
 select * from t2 where b = 40;
 select * from t2 where b = 50;
 
+--sorted_result
+select * from t3 where a < 20;
+--sorted_result
+select * from t3 where a = 20;
+--sorted_result
+select * from t3 where a = 30;
+--sorted_result
+select * from t3 where a = 40;
+--sorted_result
+select * from t3 where a = 50;
+select * from t3 where b = 20;
+select * from t3 where b = 30;
+select * from t3 where b = 40;
+select * from t3 where b = 50;
+
+--sorted_result
+select * from t4 where a < 20;
+--sorted_result
+select * from t4 where a = 20;
+--sorted_result
+select * from t4 where a = 30;
+--sorted_result
+select * from t4 where a = 40;
+--sorted_result
+select * from t4 where a = 50;
+select * from t4 where b = 20;
+select * from t4 where b = 30;
+select * from t4 where b = 40;
+select * from t4 where b = 50;
+
 alter online table t1 reorganize partition;
 alter online table t2 reorganize partition;
+--echo Cannot use normal reorganize partition on t3 as it has explicit MAX_ROWS set
+--error 1235
+alter online table t3 reorganize partition;
+show warnings;
+
+alter online table t3 max_rows=50000000;
+alter online table t4 reorganize partition;
 
 let $t1_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't1', Value, 1);
 
 let $t2_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't2', Value, 1);
 
+let $t3_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't3', Value, 1);
+
+let $t4_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't4', Value, 1);
+
 --disable_query_log
+--echo Check partitions added, expect 0 in all cases
 --echo partitions added to t1
 eval select $t1_part_count_now - $t1_part_count_start as t1_added;
 --echo partitions added to t2
 eval select $t2_part_count_now - $t2_part_count_start as t2_added;
+--echo partitions added to t3
+eval select $t3_part_count_now - $t3_part_count_start as t3_added;
+--echo partitions added to t4
+eval select $t4_part_count_now - $t4_part_count_start as t4_added;
 --enable_query_log
 
 alter online table t1 add partition partitions 1;
 alter online table t2 add partition partitions 4;
+alter online table t3 max_rows=100000000; # Expansion of max rows
+--error 1235
+alter online table t4 max_rows=100000000; # Attempted introduction of max rows - fails
 
 let $t1_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't1', Value, 1);
 
 let $t2_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't2', Value, 1);
 
+let $t3_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't3', Value, 1);
+
+let $t4_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't4', Value, 1);
+
 --disable_query_log
---echo partitions added to t1
+--echo partitions added to t1 (expect 1)
 eval select $t1_part_count_now - $t1_part_count_start as t1_added;
---echo partitions added to t2
+--echo partitions added to t2 (expect 4)
 eval select $t2_part_count_now - $t2_part_count_start as t2_added;
+--echo partitions added to t3 (expect 2)
+eval select $t3_part_count_now - $t3_part_count_start as t3_added;
+--echo partitions added to t4 (expect 0)
+eval select $t4_part_count_now - $t4_part_count_start as t4_added;
 --enable_query_log
 
 # reorganize partition not support if not default partitioning
@@ -125,6 +205,14 @@ eval select $t2_part_count_now - $t2_par
 --error ER_REORG_NO_PARAM_ERROR
 alter online table t1 reorganize partition;
 
+# Following will fail as t3 has an explicit MAX_ROWS set 
+--error 1235 
+alter online table t3 reorganize partition;
+show warnings;
+
+# t4 reorg will succeed as t4 has no explicit MAX_ROWS
+alter online table t4 reorganize partition;
+
 select count(*) from t1;
 select count(*) from t2;
 --sorted_result
@@ -157,18 +245,55 @@ select * from t2 where b = 30;
 select * from t2 where b = 40;
 select * from t2 where b = 50;
 
+--sorted_result
+select * from t3 where a < 20;
+--sorted_result
+select * from t3 where a = 20;
+--sorted_result
+select * from t3 where a = 30;
+--sorted_result
+select * from t3 where a = 40;
+--sorted_result
+select * from t3 where a = 50;
+select * from t3 where b = 20;
+select * from t3 where b = 30;
+select * from t3 where b = 40;
+select * from t3 where b = 50;
+
+--sorted_result
+select * from t4 where a < 20;
+--sorted_result
+select * from t4 where a = 20;
+--sorted_result
+select * from t4 where a = 30;
+--sorted_result
+select * from t4 where a = 40;
+--sorted_result
+select * from t4 where a = 50;
+select * from t4 where b = 20;
+select * from t4 where b = 30;
+select * from t4 where b = 40;
+select * from t4 where b = 50;
+
+drop table t4;
+
 alter online table t1 add partition partitions 2;
 alter online table t2 add partition partitions 1;
+alter online table t3 max_rows=150000000;
 
 let $t1_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't1', Value, 1);
 
 let $t2_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't2', Value, 1);
 
+let $t3_part_count_now = query_get_value(select count(*) as Value from information_schema.partitions where table_schema = 'test' and table_name = 't3', Value, 1);
+
 --disable_query_log
---echo partitions added to t1
+--echo partitions added to t1 (expect 3)
 eval select $t1_part_count_now - $t1_part_count_start as t1_added;
---echo partitions added to t2
+--echo partitions added to t2 (expect 5)
 eval select $t2_part_count_now - $t2_part_count_start as t2_added;
+--echo partitions added to t3 (expect 4)
+eval select $t3_part_count_now - $t3_part_count_start as t3_added;
 --enable_query_log
 
 select count(*) from t1;
@@ -203,7 +328,22 @@ select * from t2 where b = 30;
 select * from t2 where b = 40;
 select * from t2 where b = 50;
 
-drop table t1,t2;
+--sorted_result
+select * from t3 where a < 20;
+--sorted_result
+select * from t3 where a = 20;
+--sorted_result
+select * from t3 where a = 30;
+--sorted_result
+select * from t3 where a = 40;
+--sorted_result
+select * from t3 where a = 50;
+select * from t3 where b = 20;
+select * from t3 where b = 30;
+select * from t3 where b = 40;
+select * from t3 where b = 50;
+
+drop table t1,t2,t3;
 alter tablespace ts1 drop datafile 'datafile.dat' engine = ndb;
 drop tablespace ts1 engine = ndb;
 drop logfile group lg1 engine = ndb;

=== modified file 'mysql-test/suite/ndb/t/ndb_addnode.test'
--- a/mysql-test/suite/ndb/t/ndb_addnode.test	2011-05-06 13:48:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_addnode.test	2012-03-21 15:42:47 +0000
@@ -19,9 +19,19 @@ CREATE TABLESPACE ts_1
 create table t1(id int NOT NULL PRIMARY KEY, data char(8)) engine=ndb;
 create table t2(id int NOT NULL PRIMARY KEY, data char(8))
 TABLESPACE ts_1 STORAGE DISK engine=ndb;
+# BUG#13714648
+create table t5(id int NOT NULL PRIMARY KEY, data char(8)) max_rows=50000000 engine=ndb;
 
 load data local infile 'suite/ndb/data/table_data10000.dat' into table t1 fields terminated by ' ' lines terminated by '\n';
 load data local infile 'suite/ndb/data/table_data10000.dat' into table t2 fields terminated by ' ' lines terminated by '\n';
+load data local infile 'suite/ndb/data/table_data10000.dat' into table t5 fields terminated by ' ' lines terminated by '\n';
+
+select count(1) as t1_part_count from information_schema.partitions where table_schema='test' and table_name='t1';
+select count(1) as t2_part_count from information_schema.partitions where table_schema='test' and table_name='t2';
+select @init_t5_part_count:= count(1) as t5_part_count from information_schema.partitions where table_schema='test' and table_name='t5';
+
+## Check details of t5 partitioning
+--exec $NDB_DESC -dtest -p -n t5
 
 ## Create nodegroup for "new" nodes
 --exec $NDB_MGM -e "create nodegroup 3,4"
@@ -47,6 +57,23 @@ insert into t4(id, data) VALUES
 
 alter online table t1 reorganize partition;
 alter online table t2 reorganize partition;
+alter online table t5 max_rows=100000000;
+
+select count(1) as t1_part_count from information_schema.partitions where table_schema='test' and table_name='t1';
+select count(1) as t2_part_count from information_schema.partitions where table_schema='test' and table_name='t2';
+select count(1) as t3_part_count from information_schema.partitions where table_schema='test' and table_name='t3';
+select count(1) as t4_part_count from information_schema.partitions where table_schema='test' and table_name='t4';
+select @reorg_t5_part_count:= count(1) as t5_part_count from information_schema.partitions where table_schema='test' and table_name='t5';
+
+## Check details of t5 partitioning
+--exec $NDB_DESC -dtest -p -n t5
+
+--let $t5_part_diff=query_get_value('select @reorg_t5_part_count-@init_t5_part_count as Value',Value,1)
+
+if (!$t5_part_diff)
+{
+  --die Table t5 was not reorganised
+}
 
 ## Drop nodegroup with "new" nodes is not allowed with data one those nodes
 # NOTE: --error=0 is due to return codes doesnt work on windoze
@@ -56,7 +83,7 @@ alter online table t2 reorganize partiti
 ## Nodegroup with "new" nodes still exist after dropping it as shown:
 --exec $NDB_MGM -e show
 
-drop table t1,t2,t3,t4;
+drop table t1,t2,t3,t4,t5;
 
 ## Drop nodegroup with "new" nodes
 --exec $NDB_MGM -e "drop nodegroup 1"

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2012-03-19 09:44:55 +0000
+++ b/sql/ha_ndbcluster.cc	2012-03-21 15:42:47 +0000
@@ -14951,7 +14951,9 @@ HA_ALTER_FLAGS supported_alter_operation
     HA_COLUMN_FORMAT |
     HA_ADD_PARTITION |
     HA_ALTER_TABLE_REORG |
-    HA_CHANGE_AUTOINCREMENT_VALUE;
+    HA_CHANGE_AUTOINCREMENT_VALUE | 
+    HA_ALTER_MAX_ROWS
+;
 }
 
 int ha_ndbcluster::check_if_supported_alter(TABLE *altered_table,
@@ -15021,7 +15023,8 @@ int ha_ndbcluster::check_if_supported_al
 
   if (alter_flags->is_set(HA_ADD_COLUMN) ||
       alter_flags->is_set(HA_ADD_PARTITION) ||
-      alter_flags->is_set(HA_ALTER_TABLE_REORG))
+      alter_flags->is_set(HA_ALTER_TABLE_REORG) ||
+      alter_flags->is_set(HA_ALTER_MAX_ROWS))
   {
      Ndb *ndb= get_ndb(thd);
      NDBDICT *dict= ndb->getDictionary();
@@ -15081,6 +15084,19 @@ int ha_ndbcluster::check_if_supported_al
 
      if (alter_flags->is_set(HA_ALTER_TABLE_REORG))
      {
+       /* 
+          Refuse if Max_rows has been used before...
+          Workaround is to use ALTER ONLINE TABLE <t> MAX_ROWS=<bigger>;
+       */
+       if (old_tab->getMaxRows() != 0)
+       {
+         push_warning(current_thd,
+                      MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
+                      "Cannot online REORGANIZE a table with Max_Rows set.  "
+                      "Use ALTER TABLE ... MAX_ROWS=<new_val> or offline REORGANIZE "
+                      "to redistribute this table.");
+         DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
+       }
        new_tab.setFragmentCount(0);
        new_tab.setFragmentData(0, 0);
      }
@@ -15088,6 +15104,27 @@ int ha_ndbcluster::check_if_supported_al
      {
        new_tab.setFragmentCount(part_info->no_parts);
      }
+     if (alter_flags->is_set(HA_ALTER_MAX_ROWS))
+     {
+       ulonglong rows= create_info->max_rows;
+       uint no_fragments= get_no_fragments(rows);
+       uint reported_frags= no_fragments;
+       if (adjusted_frag_count(ndb, no_fragments, reported_frags))
+       {
+         push_warning(current_thd,
+                      MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
+                      "Ndb might have problems storing the max amount "
+                      "of rows specified");
+       }
+       if (reported_frags < old_tab->getFragmentCount())
+       {
+         DBUG_PRINT("info", ("Online reduction in number of fragments not supported"));
+         DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
+       }
+       new_tab.setFragmentCount(reported_frags);
+       new_tab.setDefaultNoPartitionsFlag(false);
+       new_tab.setFragmentData(0, 0);
+     }
 
      NDB_Modifiers table_modifiers(ndb_table_modifiers);
      table_modifiers.parse(thd, "NDB_TABLE=", create_info->comment.str,
@@ -15406,7 +15443,9 @@ int ha_ndbcluster::alter_table_phase1(TH
      }
   }
 
-  if (alter_flags->is_set(HA_ALTER_TABLE_REORG) || alter_flags->is_set(HA_ADD_PARTITION))
+  if (alter_flags->is_set(HA_ALTER_TABLE_REORG) || 
+      alter_flags->is_set(HA_ADD_PARTITION) ||
+      alter_flags->is_set(HA_ALTER_MAX_ROWS))
   {
     if (alter_flags->is_set(HA_ALTER_TABLE_REORG))
     {
@@ -15418,7 +15457,29 @@ int ha_ndbcluster::alter_table_phase1(TH
       partition_info *part_info= table->part_info;
       new_tab->setFragmentCount(part_info->no_parts);
     }
-
+    else if (alter_flags->is_set(HA_ALTER_MAX_ROWS))
+    {
+      ulonglong rows= create_info->max_rows;
+      uint no_fragments= get_no_fragments(rows);
+      uint reported_frags= no_fragments;
+      if (adjusted_frag_count(ndb, no_fragments, reported_frags))
+      {
+        DBUG_ASSERT(false); /* Checked above */
+      }
+      if (reported_frags < old_tab->getFragmentCount())
+      {
+        DBUG_ASSERT(false);
+        DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
+      }
+      /* Note we don't set the ndb table's max_rows param, as that 
+       * is considered a 'real' change
+       */
+      //new_tab->setMaxRows(create_info->max_rows);
+      new_tab->setFragmentCount(reported_frags);
+      new_tab->setDefaultNoPartitionsFlag(false);
+      new_tab->setFragmentData(0, 0);
+    }
+    
     int res= dict->prepareHashMap(*old_tab, *new_tab);
     if (res == -1)
     {

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2012-02-13 14:45:39 +0000
+++ b/sql/handler.h	2012-03-21 15:42:47 +0000
@@ -51,7 +51,8 @@
 /* Bits to show what an alter table will do */
 #include <sql_bitmap.h>
 
-#define HA_MAX_ALTER_FLAGS 40
+#define HA_MAX_ALTER_FLAGS 41
+
 typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
 
 #define HA_ADD_INDEX                  (0)
@@ -94,6 +95,7 @@ typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_AL
 #define HA_ALTER_STORAGE_ENGINE       (37)
 #define HA_RECREATE                   (38)
 #define HA_ALTER_TABLE_REORG          (39)
+#define HA_ALTER_MAX_ROWS             (40)
 /* Remember to increase HA_MAX_ALTER_FLAGS when adding more flags! */
 
 /* Return values for check_if_supported_alter */

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2012-02-13 17:20:48 +0000
+++ b/sql/sql_table.cc	2012-03-21 15:42:47 +0000
@@ -5845,6 +5845,8 @@ compare_tables(THD *thd,
       *alter_flags|= HA_SET_DEFAULT_CHARACTER_SET;
     if (alter_info->flags & ALTER_RECREATE)
       *alter_flags|= HA_RECREATE;
+    if (create_info->used_fields & HA_CREATE_USED_MAX_ROWS)
+      *alter_flags|= HA_ALTER_MAX_ROWS;
     /* TODO check for ADD/DROP FOREIGN KEY */
     if (alter_info->flags & ALTER_FOREIGN_KEY)
       *alter_flags|=  HA_ALTER_FOREIGN_KEY;

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.1-telco-7.0 branch (frazer.clement:4901 to 4902)Bug#13714648Frazer Clement21 Mar