#
# Test checksum
#

--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");
checksum table t1;
checksum table t1 quick;
checksum table t1 extended;
drop table if exists t1;
create table t1 (a int null, v varchar(100)) engine=myisam checksum=1;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
checksum table t1 quick;
checksum table t1 extended;
drop table if exists t1;

create table t1 (a int null, v varchar(100)) engine=innodb checksum=0;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
checksum table t1 quick;
checksum table t1 extended;
drop table t1;

create table t1 (a int null, v varchar(100)) engine=maria checksum=0;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
checksum table t1 quick;
checksum table t1 extended;
drop table t1;
create table t1 (a int null, v varchar(100)) engine=maria checksum=1;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
checksum table t1 quick;
checksum table t1 extended;
drop table t1;


#
# These checksums will be different prefixes fixed sizes rows with one extra
# flag byte
#
create table t1 (a int null, v varchar(100)) engine=myisam checksum=1 row_format=fixed;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
checksum table t1 quick;
checksum table t1 extended;
drop table if exists t1;

create table t1 (a int null, v varchar(100)) engine=innodb checksum=0 row_format=compact;
insert into t1 values(null, null), (1, "hello");
checksum table t1;
checksum table t1 quick;
checksum table t1 extended;
drop table t1;

--echo #
--echo # MDEV-17085: CHECKSUM TABLE EXTENDED does not work correctly
--echo #

CREATE TABLE t1 ( c1 int NOT NULL, c2 int NOT NULL, c4 varchar(20), c5 varchar(20), c6 varchar(20), c7 varchar(20), c8 varchar(20), c9 varchar(20), c10 varchar(20), c11 varchar(20), c12 varchar(20), c13 varchar(20), c14 varchar(20), c15 varchar(20), c16 varchar(20), c19 int NOT NULL, c20 int NOT NULL, c21 varchar(20), c22 VARCHAR(20), c23 varchar(20));

insert into t1 values (5,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,0,"dog",NULL,NULL);
--echo # Important is that checksum is different from following
CHECKSUM TABLE t1 EXTENDED;
UPDATE t1 SET c21='cat' WHERE  c1=5;
--echo # Important is that checksum is different from above
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 #
