summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/myisam.result14
-rw-r--r--mysql-test/t/myisam.test15
-rw-r--r--sql/sql_table.cc9
3 files changed, 37 insertions, 1 deletions
diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result
index 38273c01a98..1837a4078a7 100644
--- a/mysql-test/r/myisam.result
+++ b/mysql-test/r/myisam.result
@@ -595,3 +595,17 @@ show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 a 1 a A 8 NULL NULL YES BTREE
drop table t1;
+create table t1 (c1 int);
+insert into t1 values (1),(2),(3),(4);
+checksum table t1;
+Table Checksum
+test.t1 149057747
+delete from t1 where c1 = 1;
+create table t2 as select * from t1;
+checksum table t1;
+Table Checksum
+test.t1 984116287
+checksum table t2;
+Table Checksum
+test.t2 984116287
+drop table t1, t2;
diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test
index cffb402bbd4..83e9e1ba7d2 100644
--- a/mysql-test/t/myisam.test
+++ b/mysql-test/t/myisam.test
@@ -575,4 +575,19 @@ show keys from t1;
drop table t1;
+#
+# Bug#12296 - CHECKSUM TABLE reports 0 for the table
+# This happened if the first record was marked as deleted.
+#
+create table t1 (c1 int);
+insert into t1 values (1),(2),(3),(4);
+checksum table t1;
+delete from t1 where c1 = 1;
+create table t2 as select * from t1;
+# The following returns 0 with the bug in place.
+checksum table t1;
+# The above should give the same number as the following.
+checksum table t2;
+drop table t1, t2;
+
# End of 4.1 tests
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 87b864c73fa..b593aed1453 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3745,9 +3745,16 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
protocol->store_null();
else
{
- while (!t->file->rnd_next(t->record[0]))
+ for (;;)
{
ha_checksum row_crc= 0;
+ int error= t->file->rnd_next(t->record[0]);
+ if (unlikely(error))
+ {
+ if (error == HA_ERR_RECORD_DELETED)
+ continue;
+ break;
+ }
if (t->record[0] != (byte*) t->field[0]->ptr)
row_crc= my_checksum(row_crc, t->record[0],
((byte*) t->field[0]->ptr) - t->record[0]);