summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-04-26 14:18:32 +0200
committerSergei Golubchik <serg@mariadb.org>2022-04-26 19:18:06 +0200
commit39990135e57e7377fd2f9a156973a59eb07bc739 (patch)
treeaa9e4349b0cb21e8eff1a1ec7a6a9f8ce3e3735d
parent44e7c312bad9d00498f6f04afe165f5d8570765d (diff)
downloadmariadb-git-39990135e57e7377fd2f9a156973a59eb07bc739.tar.gz
MDEV-28020 CHECKSUM TABLE calculates different checksums
Two bugs here: 1. CHECKSUM TABLE asserted that all fields in the table are arranged sequentially in the record, but virtual columns are always at the end, violating this assertion 2. virtual columns were not calculated for CHECKSUM, so CHECKSUM was using, essentially, garbage left from the previous statement. (that's why the test must use INSERT IGNORE to have this "previous statement" mark vcols not null) Fix: don't include virtual columns into the table CHECKSUM. Indeed, they cannot be included as the engine does not see virtual columns, so in-engine checksum cannot include them, meaning in-server checksum should not either
-rw-r--r--mysql-test/r/row-checksum-old.result45
-rw-r--r--mysql-test/r/row-checksum.result45
-rw-r--r--mysql-test/t/row-checksum.test35
-rw-r--r--sql/sql_table.cc2
4 files changed, 119 insertions, 8 deletions
diff --git a/mysql-test/r/row-checksum-old.result b/mysql-test/r/row-checksum-old.result
index d374013f61c..7caed4fc7dc 100644
--- a/mysql-test/r/row-checksum-old.result
+++ b/mysql-test/r/row-checksum-old.result
@@ -1,4 +1,3 @@
-drop table if exists t1;
create table t1 (a int null, v varchar(100)) engine=myisam checksum=0;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
@@ -98,4 +97,48 @@ CHECKSUM TABLE t1 EXTENDED;
Table Checksum
test.t1 2326430205
drop table t1;
+#
# End of 5.5 tests
+#
+#
+# MDEV-28020 CHECKSUM TABLE calculates different checksums
+#
+create table t1 ( a int, b int as (a) virtual, c text) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+checksum table t1 extended;
+Table Checksum
+test.t1 4101438232
+checksum table t1;
+Table Checksum
+test.t1 4101438232
+drop table t1;
+create table t1 ( a int, b int as (a) virtual, c text, key(b)) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+checksum table t1 extended;
+Table Checksum
+test.t1 4101438232
+checksum table t1;
+Table Checksum
+test.t1 4101438232
+drop table t1;
+create table t1 ( a int, b int as (a) stored, c text) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+checksum table t1 extended;
+Table Checksum
+test.t1 2897795735
+checksum table t1;
+Table Checksum
+test.t1 2897795735
+drop table t1;
+#
+# End of 10.2 tests
+#
diff --git a/mysql-test/r/row-checksum.result b/mysql-test/r/row-checksum.result
index 4625e09c060..c80ca4eed9a 100644
--- a/mysql-test/r/row-checksum.result
+++ b/mysql-test/r/row-checksum.result
@@ -1,4 +1,3 @@
-drop table if exists t1;
create table t1 (a int null, v varchar(100)) engine=myisam checksum=0;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
@@ -98,4 +97,48 @@ CHECKSUM TABLE t1 EXTENDED;
Table Checksum
test.t1 2326430205
drop table t1;
+#
# End of 5.5 tests
+#
+#
+# MDEV-28020 CHECKSUM TABLE calculates different checksums
+#
+create table t1 ( a int, b int as (a) virtual, c text) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+checksum table t1 extended;
+Table Checksum
+test.t1 4101438232
+checksum table t1;
+Table Checksum
+test.t1 4101438232
+drop table t1;
+create table t1 ( a int, b int as (a) virtual, c text, key(b)) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+checksum table t1 extended;
+Table Checksum
+test.t1 4101438232
+checksum table t1;
+Table Checksum
+test.t1 4101438232
+drop table t1;
+create table t1 ( a int, b int as (a) stored, c text) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+checksum table t1 extended;
+Table Checksum
+test.t1 2897795735
+checksum table t1;
+Table Checksum
+test.t1 2897795735
+drop table t1;
+#
+# End of 10.2 tests
+#
diff --git a/mysql-test/t/row-checksum.test b/mysql-test/t/row-checksum.test
index 5acfda45f75..3b510abba84 100644
--- a/mysql-test/t/row-checksum.test
+++ b/mysql-test/t/row-checksum.test
@@ -2,12 +2,8 @@
# Test checksum
#
--- source include/have_innodb.inc
--- source include/have_maria.inc
-
---disable_warnings
-drop table if exists t1;
---enable_warnings
+--source include/have_innodb.inc
+--source include/have_maria.inc
create table t1 (a int null, v varchar(100)) engine=myisam checksum=0;
insert into t1 values(null, null), (1, "hello");
@@ -76,4 +72,31 @@ CHECKSUM TABLE t1 EXTENDED;
drop table t1;
+--echo #
--echo # End of 5.5 tests
+--echo #
+
+--echo #
+--echo # MDEV-28020 CHECKSUM TABLE calculates different checksums
+--echo #
+create table t1 ( a int, b int as (a) virtual, c text) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+checksum table t1 extended;
+checksum table t1;
+drop table t1;
+
+create table t1 ( a int, b int as (a) virtual, c text, key(b)) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+checksum table t1 extended;
+checksum table t1;
+drop table t1;
+
+create table t1 ( a int, b int as (a) stored, c text) engine=myisam checksum=1;
+insert ignore t1 values (1,2,'foo'),(2,3,'bar');
+checksum table t1 extended;
+checksum table t1;
+drop table t1;
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index a2dc5c97aeb..f9d7f4a2ea2 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -10631,6 +10631,8 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
for (uint i= 0; i < t->s->fields; i++ )
{
Field *f= t->field[i];
+ if (!f->stored_in_db())
+ continue;
if (! thd->variables.old_mode && f->is_real_null(0))
{