Skip to content

Commit 505da21

Browse files
committed
MDEV-27214 Import with disabled keys corrupts meta-data like rows, indexes, ...
This bug was previously fixed in 10.6.11 by: MDEV-28327 InnoDB persistent statistics fail to update after bulk insert Adding MTR tests only. Also, fixing the old test for MDEV-28327 to make "mtr" reliably pass with/without --mysqld=--innodb-stats-persistent=0, and with different page sizes, as suggested by Marko.
1 parent f4adf35 commit 505da21

File tree

4 files changed

+123
-6
lines changed

4 files changed

+123
-6
lines changed

mysql-test/suite/innodb/r/insert_into_empty.result

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,30 @@ DROP TABLE t;
186186
# MDEV-28327 InnoDB persistent statistics fail to update
187187
# after bulk insert
188188
#
189-
CREATE TABLE t1 (a INT PRIMARY KEY)ENGINE=InnoDB;
189+
CREATE TABLE t1 (a INT PRIMARY KEY)ENGINE=InnoDB
190+
STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
190191
INSERT INTO t1 SELECT * FROM seq_1_to_4096;
191192
# Wait till statistics update after bulk insert operation
192-
SELECT n_rows FROM mysql.innodb_table_stats WHERE TABLE_NAME="t1";
193-
n_rows
194-
4096
193+
SELECT n_rows>=4096 FROM mysql.innodb_table_stats WHERE TABLE_NAME="t1";
194+
n_rows>=4096
195+
1
196+
DROP TABLE t1;
197+
#
198+
# MDEV-27214 Import with disabled keys corrupts meta-data like rows, indexes, ...
199+
#
200+
SET UNIQUE_CHECKS=0;
201+
SET FOREIGN_KEY_CHECKS=0;
202+
CREATE TABLE `t1` (
203+
`id` int(11) NOT NULL,
204+
`a` int(11) DEFAULT NULL,
205+
PRIMARY KEY (`id`)
206+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
207+
STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
208+
INSERT INTO `t1` VALUES (1,2),(2,3),(3,4);
209+
# Wait till statistics update after bulk insert operation
210+
SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
211+
WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test';
212+
TABLE_ROWS AVG_ROW_LENGTH>0
213+
3 1
195214
DROP TABLE t1;
196215
# End of 10.6 tests
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Start of 10.6 tests
3+
#
4+
#
5+
# MDEV-27214 Import with disabled keys corrupts meta-data like rows, indexes, ...
6+
#
7+
CREATE DATABASE db1;
8+
CREATE TABLE db1.t1 (id int, a int,PRIMARY KEY (id)) ENGINE=InnoDB
9+
STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
10+
INSERT INTO db1.t1 VALUES (1,2),(2,3),(3,4);
11+
DROP DATABASE IF EXISTS db1;
12+
CREATE DATABASE db1;
13+
# Wait till statistics update after bulk insert operation
14+
SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
15+
WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='db1';
16+
TABLE_ROWS AVG_ROW_LENGTH>0
17+
3 1
18+
OPTIMIZE TABLE db1.t1;
19+
Table Op Msg_type Msg_text
20+
db1.t1 optimize note Table does not support optimize, doing recreate + analyze instead
21+
db1.t1 optimize status OK
22+
# Wait till statistics update after bulk insert operation
23+
SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
24+
WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='db1';
25+
TABLE_ROWS AVG_ROW_LENGTH>0
26+
3 1
27+
DROP DATABASE db1;
28+
#
29+
# End of 10.6 tests
30+
#

mysql-test/suite/innodb/t/insert_into_empty.test

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
--source include/have_innodb.inc
2+
--source include/innodb_page_size.inc
23
--source include/have_sequence.inc
34
--source include/maybe_debug.inc
45
--source include/have_partition.inc
@@ -198,13 +199,37 @@ DROP TABLE t;
198199
--echo # MDEV-28327 InnoDB persistent statistics fail to update
199200
--echo # after bulk insert
200201
--echo #
201-
CREATE TABLE t1 (a INT PRIMARY KEY)ENGINE=InnoDB;
202+
CREATE TABLE t1 (a INT PRIMARY KEY)ENGINE=InnoDB
203+
STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
202204
INSERT INTO t1 SELECT * FROM seq_1_to_4096;
203205
--echo # Wait till statistics update after bulk insert operation
204206
let $wait_condition= select n_rows > 100 from mysql.innodb_table_stats
205207
where table_name="t1";
206208
source include/wait_condition.inc;
207-
SELECT n_rows FROM mysql.innodb_table_stats WHERE TABLE_NAME="t1";
209+
SELECT n_rows>=4096 FROM mysql.innodb_table_stats WHERE TABLE_NAME="t1";
208210
DROP TABLE t1;
209211

212+
213+
--echo #
214+
--echo # MDEV-27214 Import with disabled keys corrupts meta-data like rows, indexes, ...
215+
--echo #
216+
217+
SET UNIQUE_CHECKS=0;
218+
SET FOREIGN_KEY_CHECKS=0;
219+
CREATE TABLE `t1` (
220+
`id` int(11) NOT NULL,
221+
`a` int(11) DEFAULT NULL,
222+
PRIMARY KEY (`id`)
223+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
224+
STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
225+
INSERT INTO `t1` VALUES (1,2),(2,3),(3,4);
226+
--echo # Wait till statistics update after bulk insert operation
227+
let $wait_condition= select n_rows > 0 from mysql.innodb_table_stats
228+
where database_name='test' and table_name='t1';
229+
source include/wait_condition.inc;
230+
SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
231+
WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test';
232+
DROP TABLE t1;
233+
234+
210235
--echo # End of 10.6 tests
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--source include/not_embedded.inc
2+
--source include/have_innodb.inc
3+
--source include/innodb_page_size.inc
4+
--source include/maybe_debug.inc
5+
6+
--echo #
7+
--echo # Start of 10.6 tests
8+
--echo #
9+
10+
--echo #
11+
--echo # MDEV-27214 Import with disabled keys corrupts meta-data like rows, indexes, ...
12+
--echo #
13+
14+
CREATE DATABASE db1;
15+
CREATE TABLE db1.t1 (id int, a int,PRIMARY KEY (id)) ENGINE=InnoDB
16+
STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
17+
INSERT INTO db1.t1 VALUES (1,2),(2,3),(3,4);
18+
--let $file = $MYSQLTEST_VARDIR/tmp/dump.sql
19+
--exec $MYSQL_DUMP db1 t1 >$file
20+
DROP DATABASE IF EXISTS db1;
21+
22+
CREATE DATABASE db1;
23+
--exec $MYSQL db1 < $file
24+
--remove_file $file
25+
--echo # Wait till statistics update after bulk insert operation
26+
let $wait_condition= select n_rows > 0 from mysql.innodb_table_stats
27+
where database_name='db1' and table_name='t1';
28+
source include/wait_condition.inc;
29+
SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
30+
WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='db1';
31+
32+
OPTIMIZE TABLE db1.t1;
33+
--echo # Wait till statistics update after bulk insert operation
34+
let $wait_condition= select n_rows > 0 from mysql.innodb_table_stats
35+
where database_name='db1' and table_name='t1';
36+
source include/wait_condition.inc;
37+
SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
38+
WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='db1';
39+
DROP DATABASE db1;
40+
41+
--echo #
42+
--echo # End of 10.6 tests
43+
--echo #

0 commit comments

Comments
 (0)