From 9cfcc21450b0c6defd13c1e231ad25cad6db855b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Aug 2006 08:47:58 -0400 Subject: [PATCH 1/2] BUG#21173: SHOW TABLE STATUS crashes on InnoDB tables Don't use get_auto_increment on tables without auto_increment fields mysql-test/r/partition.result: new test case mysql-test/t/partition.test: new test case sql/ha_partition.cc: Don't use get_auto_increment on tables without auto_increment fields --- mysql-test/r/partition.result | 8 ++++++++ mysql-test/t/partition.test | 10 ++++++++++ sql/ha_partition.cc | 13 +++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index e95489864f7..1d186f0a56a 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1,5 +1,13 @@ drop table if exists t1; create table t1 (a int) +engine = innodb +partition by key (a); +insert into t1 values (0); +show table status; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 InnoDB 10 Compact 2 8192 16384 0 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +drop table t1; +create table t1 (a int) partition by list (a) (partition p0 values in (1)); create procedure pz() diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index d4e930f91ec..dc1d96298d2 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -9,6 +9,16 @@ drop table if exists t1; --enable_warnings +# +# Bug 21173: SHOW TABLE STATUS crashes server in InnoDB +# +create table t1 (a int) +engine = innodb +partition by key (a); +insert into t1 values (0); +show table status; +drop table t1; + # # Bug 19309 Partitions: Crash if double procedural alter # diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 615c4bfb1bf..042b23632a6 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4183,9 +4183,15 @@ void ha_partition::info(uint flag) ulonglong nb_reserved_values; DBUG_PRINT("info", ("HA_STATUS_AUTO")); /* we don't want to reserve any values, it's pure information */ - get_auto_increment(0, 0, 0, &stats.auto_increment_value, - &nb_reserved_values); - release_auto_increment(); + + if (table->found_next_number_field) + { + get_auto_increment(0, 0, 0, &stats.auto_increment_value, + &nb_reserved_values); + release_auto_increment(); + } + else + stats.auto_increment_value= ~(ulonglong)(0); } if (flag & HA_STATUS_VARIABLE) { @@ -5363,7 +5369,6 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, if (increment) // If not check for values *nb_reserved_values= (last_value == ULONGLONG_MAX) ? ULONGLONG_MAX : ((last_value - *first_value) / increment); - DBUG_VOID_RETURN; } From 8ed7e1484aa638cf0911b62b32d54a7d945b4dfb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Aug 2006 09:58:55 -0400 Subject: [PATCH 2/2] BUG#21173: SHOW TABLE STATUS crashes mysqld Review fixes mysql-test/r/partition.result: New test cases mysql-test/t/partition.test: New test cases sql/ha_partition.cc: Added comments after review + removed erroneus setting --- mysql-test/r/partition.result | 20 +++++++++++++++++++- mysql-test/t/partition.test | 12 +++++++++++- sql/ha_partition.cc | 8 ++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 1d186f0a56a..2722efefcb9 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -2,10 +2,28 @@ drop table if exists t1; create table t1 (a int) engine = innodb partition by key (a); -insert into t1 values (0); show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment t1 InnoDB 10 Compact 2 8192 16384 0 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +insert into t1 values (0), (1), (2), (3); +show table status; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 InnoDB 10 Compact 4 4096 16384 0 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +drop table t1; +create table t1 (a int auto_increment primary key) +engine = innodb +partition by key (a); +show table status; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 InnoDB 10 Compact 2 8192 16384 0 0 0 1 NULL NULL NULL latin1_swedish_ci NULL partitioned +insert into t1 values (NULL), (NULL), (NULL), (NULL); +show table status; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 InnoDB 10 Compact 4 4096 16384 0 0 0 5 NULL NULL NULL latin1_swedish_ci NULL partitioned +insert into t1 values (NULL), (NULL), (NULL), (NULL); +show table status; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 InnoDB 10 Compact 8 2048 16384 0 0 0 9 NULL NULL NULL latin1_swedish_ci NULL partitioned drop table t1; create table t1 (a int) partition by list (a) diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index dc1d96298d2..1c91802034c 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -15,10 +15,20 @@ drop table if exists t1; create table t1 (a int) engine = innodb partition by key (a); -insert into t1 values (0); +show table status; +insert into t1 values (0), (1), (2), (3); show table status; drop table t1; +create table t1 (a int auto_increment primary key) +engine = innodb +partition by key (a); +show table status; +insert into t1 values (NULL), (NULL), (NULL), (NULL); +show table status; +insert into t1 values (NULL), (NULL), (NULL), (NULL); +show table status; +drop table t1; # # Bug 19309 Partitions: Crash if double procedural alter # diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 042b23632a6..10b531862fd 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4186,12 +4186,16 @@ void ha_partition::info(uint flag) if (table->found_next_number_field) { + /* + Can only call get_auto_increment for tables that actually + have auto_increment columns, otherwise there will be + problems in handlers that don't expect get_auto_increment + for non-autoincrement tables. + */ get_auto_increment(0, 0, 0, &stats.auto_increment_value, &nb_reserved_values); release_auto_increment(); } - else - stats.auto_increment_value= ~(ulonglong)(0); } if (flag & HA_STATUS_VARIABLE) {