From 8204f6906752d07b345459b408c53b9ab0b30fbb Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Sep 2005 23:32:07 -0400 Subject: [PATCH] Bug #13323 Select count(*) returned 2 on empty table where handler used exact count mysql-test/r/partition.result: New test case for Bug #13323 mysql-test/t/partition.test: New test case for Bug #13323 sql/ha_partition.cc: Fix for Bug #13323 --- mysql-test/r/partition.result | 3 +++ mysql-test/t/partition.test | 5 +++++ sql/ha_partition.cc | 11 +++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 88e06e64956..06097e26183 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -5,6 +5,9 @@ b int not null, c int not null, primary key(a,b)) partition by key (a); +select count(*) from t1; +count(*) +0 drop table t1; CREATE TABLE t1 ( a int not null, diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 37a4912702f..a45046239bc 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -18,6 +18,11 @@ c int not null, primary key(a,b)) partition by key (a); +# +# Bug 13323: Select count(*) on empty table returns 2 +# +select count(*) from t1; + drop table t1; # # Partition by key no partition, list of fields diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 39c4f2243a5..83eb6e050c5 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -81,6 +81,9 @@ static handlerton partition_hton = { NULL, /* recover */ NULL, /* commit_by_xid */ NULL, /* rollback_by_xid */ + NULL, + NULL, + NULL, HTON_NO_FLAGS }; @@ -2305,9 +2308,13 @@ void ha_partition::info(uint flag) if (file->check_time > check_time) check_time= file->check_time; } while (*(++file_array)); - if (records < 2) + if (records < 2 && + m_table_flags & HA_NOT_EXACT_COUNT) records= 2; - mean_rec_length= (ulong) (data_file_length / records); + if (records > 0) + mean_rec_length= (ulong) (data_file_length / records); + else + mean_rec_length= 1; //? What should we set here } if (flag & HA_STATUS_CONST) {