From adbab0d4cd80b10a1176f1ce8561aff3d5875a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 26 Jun 2019 12:07:17 +0300 Subject: [PATCH 1/4] MDEV-13625: Add the test innodb.innodb-wl5980-debug --- .../suite/innodb/r/innodb-wl5980-debug.result | 27 ++++++++++ .../suite/innodb/t/innodb-wl5980-debug.test | 51 +++++++++++++++++++ storage/innobase/fil/fil0fil.cc | 5 ++ storage/xtradb/fil/fil0fil.cc | 5 ++ 4 files changed, 88 insertions(+) create mode 100644 mysql-test/suite/innodb/r/innodb-wl5980-debug.result create mode 100644 mysql-test/suite/innodb/t/innodb-wl5980-debug.test diff --git a/mysql-test/suite/innodb/r/innodb-wl5980-debug.result b/mysql-test/suite/innodb/r/innodb-wl5980-debug.result new file mode 100644 index 00000000000..51cff4393aa --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb-wl5980-debug.result @@ -0,0 +1,27 @@ +call mtr.add_suppression("Cannot find space id [0-9]+ in the tablespace memory cache"); +call mtr.add_suppression("Cannot rename table 'test/t1' to 'test/t2' since the dictionary cache already contains 'test/t2'."); +# +# WL5980 Remote tablespace debug error injection tests. +# +CREATE TABLE t1 (a int KEY, b text) ENGINE=Innodb DATA DIRECTORY='MYSQL_TMP_DIR/alt_dir' ; +INSERT INTO t1 VALUES (1, 'tablespace'); +SELECT * FROM t1; +a b +1 tablespace +# +# Test the second injection point in fil_rename_tablespace(). +# Make sure the table is useable after this failure. +# +SET @save_dbug=@@debug_dbug; +SET debug_dbug="+d,fil_rename_tablespace_failure_2"; +RENAME TABLE t1 TO t2; +SET debug_dbug=@save_dbug; +INSERT INTO t1 VALUES (2, 'tablespace'); +SELECT * FROM t1; +a b +1 tablespace +2 tablespace +# +# Cleanup +# +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/innodb-wl5980-debug.test b/mysql-test/suite/innodb/t/innodb-wl5980-debug.test new file mode 100644 index 00000000000..2c5e2b48870 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-wl5980-debug.test @@ -0,0 +1,51 @@ +# +# This testcase is to check the various debug injection points +# to make sure error conditions react corectly and acheive +# better code coverage. +# + +# Not supported in embedded +--source include/not_embedded.inc +--source include/have_debug.inc +--source include/have_innodb.inc + +# These messages are expected in the log +call mtr.add_suppression("Cannot find space id [0-9]+ in the tablespace memory cache"); +call mtr.add_suppression("Cannot rename table 'test/t1' to 'test/t2' since the dictionary cache already contains 'test/t2'."); + +# Set up some variables +LET $MYSQL_DATA_DIR = `select @@datadir`; +LET $data_directory_clause = DATA DIRECTORY='$MYSQL_TMP_DIR/alt_dir'; +--enable_query_log + +--echo # +--echo # WL5980 Remote tablespace debug error injection tests. +--echo # + +--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +eval CREATE TABLE t1 (a int KEY, b text) ENGINE=Innodb $data_directory_clause ; +INSERT INTO t1 VALUES (1, 'tablespace'); +SELECT * FROM t1; + +--echo # +--echo # Test the second injection point in fil_rename_tablespace(). +--echo # Make sure the table is useable after this failure. +--echo # +SET @save_dbug=@@debug_dbug; +SET debug_dbug="+d,fil_rename_tablespace_failure_2"; +--disable_result_log +--error ER_ERROR_ON_RENAME +RENAME TABLE t1 TO t2; +--enable_result_log +SET debug_dbug=@save_dbug; +INSERT INTO t1 VALUES (2, 'tablespace'); +SELECT * FROM t1; + +--echo # +--echo # Cleanup +--echo # + +DROP TABLE t1; + +--rmdir $MYSQL_TMP_DIR/alt_dir/test +--rmdir $MYSQL_TMP_DIR/alt_dir diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 8c4e1db6f51..7234a6c4102 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -3216,8 +3216,13 @@ fil_rename_tablespace( space, node, new_name, new_path); if (success) { + DBUG_EXECUTE_IF("fil_rename_tablespace_failure_2", + goto skip_second_rename; ); success = os_file_rename( innodb_file_data_key, old_path, new_path); + DBUG_EXECUTE_IF("fil_rename_tablespace_failure_2", +skip_second_rename: + success = FALSE; ); if (!success) { /* We have to revert the changes we made diff --git a/storage/xtradb/fil/fil0fil.cc b/storage/xtradb/fil/fil0fil.cc index d3641efc062..254d0954397 100644 --- a/storage/xtradb/fil/fil0fil.cc +++ b/storage/xtradb/fil/fil0fil.cc @@ -3262,8 +3262,13 @@ fil_rename_tablespace( space, node, new_name, new_path); if (success) { + DBUG_EXECUTE_IF("fil_rename_tablespace_failure_2", + goto skip_second_rename; ); success = os_file_rename( innodb_file_data_key, old_path, new_path); + DBUG_EXECUTE_IF("fil_rename_tablespace_failure_2", +skip_second_rename: + success = FALSE; ); if (!success) { /* We have to revert the changes we made From 5a22c456049456ee1dfbafd3211953ca6295c572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 18 Jul 2019 14:30:34 +0300 Subject: [PATCH 2/4] MDEV-13626: Add the test innodb.trx_id_future --- .../suite/innodb/r/trx_id_future.result | 11 ++++ mysql-test/suite/innodb/t/trx_id_future.test | 58 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 mysql-test/suite/innodb/r/trx_id_future.result create mode 100644 mysql-test/suite/innodb/t/trx_id_future.test diff --git a/mysql-test/suite/innodb/r/trx_id_future.result b/mysql-test/suite/innodb/r/trx_id_future.result new file mode 100644 index 00000000000..f7dee933319 --- /dev/null +++ b/mysql-test/suite/innodb/r/trx_id_future.result @@ -0,0 +1,11 @@ +# +# Bug #20445525 ADD A CONSISTENCY CHECK AGAINST DB_TRX_ID BEING +# IN THE FUTURE +# +CREATE TABLE t1(a INT) row_format=redundant engine=innoDB; +INSERT INTO t1 VALUES(1); +NOT FOUND /\[Warning\] InnoDB: A transaction id in a record of table `test`\.`t1` is newer than the system-wide maximum/ in mysqld.1.err +call mtr.add_suppression("\\[Warning\\] InnoDB: A transaction id in a record of table `test`\\.`t1` is newer than the system-wide maximum"); +SELECT * FROM t1; +a +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/trx_id_future.test b/mysql-test/suite/innodb/t/trx_id_future.test new file mode 100644 index 00000000000..deba753caca --- /dev/null +++ b/mysql-test/suite/innodb/t/trx_id_future.test @@ -0,0 +1,58 @@ +--echo # +--echo # Bug #20445525 ADD A CONSISTENCY CHECK AGAINST DB_TRX_ID BEING +--echo # IN THE FUTURE +--echo # + +--source include/not_debug.inc +--source include/have_innodb.inc +--source include/not_embedded.inc + +let PAGE_SIZE=`select @@innodb_page_size`; + +CREATE TABLE t1(a INT) row_format=redundant engine=innoDB; +INSERT INTO t1 VALUES(1); + +let MYSQLD_DATADIR=`select @@datadir`; + +--source include/shutdown_mysqld.inc + +perl; +do "$ENV{MTR_SUITE_DIR}/include/crc32.pl"; +my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd"; +open(FILE, "+<", $file) || die "Unable to open $file"; +binmode FILE; + +#Seek the the infimum record and get the offset to next record +#Infimum record exist at offset 101 for redundant format +#And offset to the next record is present 2 bytes prior to +#infimum record + +my $ps= $ENV{PAGE_SIZE}; +my $page; +sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n"; +die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps; +#In this case the first record should be at offset 135 +die unless unpack("n", substr($page, 99, 2)) == 135; + +substr($page,135+6,6) = "\xff" x 6; + +my $polynomial = 0x82f63b78; # CRC-32C +my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^ + mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial)); +substr($page,0,4)=$ck; +substr($page,$ps-8,4)=$ck; +sysseek(FILE, 3*$ps, 0) || die "Unable to rewind $file\n"; +syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n"; +close(FILE) || die "Unable to close $file"; +EOF + +--source include/start_mysqld.inc + +let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; +let SEARCH_PATTERN= \[Warning\] InnoDB: A transaction id in a record of table `test`\.`t1` is newer than the system-wide maximum; +--source include/search_pattern_in_file.inc + +call mtr.add_suppression("\\[Warning\\] InnoDB: A transaction id in a record of table `test`\\.`t1` is newer than the system-wide maximum"); + +SELECT * FROM t1; +DROP TABLE t1; From eb14806e6c36c126b0e73f5d4d473f6010b05af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 18 Jul 2019 15:01:13 +0300 Subject: [PATCH 3/4] MDEV-13625: Adapt the test innodb-system-table-view --- .../suite/innodb/include/show_i_s_tables.inc | 19 +++ .../innodb/include/show_i_s_tablespaces.inc | 19 +++ .../innodb/r/innodb-system-table-view.result | 153 ++++++++++++++++++ .../innodb/t/innodb-system-table-view.opt | 11 ++ .../innodb/t/innodb-system-table-view.test | 139 ++++++++++++++++ 5 files changed, 341 insertions(+) create mode 100644 mysql-test/suite/innodb/include/show_i_s_tables.inc create mode 100644 mysql-test/suite/innodb/include/show_i_s_tablespaces.inc create mode 100644 mysql-test/suite/innodb/r/innodb-system-table-view.result create mode 100644 mysql-test/suite/innodb/t/innodb-system-table-view.opt create mode 100644 mysql-test/suite/innodb/t/innodb-system-table-view.test diff --git a/mysql-test/suite/innodb/include/show_i_s_tables.inc b/mysql-test/suite/innodb/include/show_i_s_tables.inc new file mode 100644 index 00000000000..5fe34c370c8 --- /dev/null +++ b/mysql-test/suite/innodb/include/show_i_s_tables.inc @@ -0,0 +1,19 @@ +--echo === information_schema.innodb_sys_tables and innodb_sys_tablespaces === +--disable_query_log +--replace_result #P# #p# #SP# #sp# +--replace_regex /FTS_([0-9a-f_]+)([A-Z0-9_]+)/FTS_AUX_\2/ + +SELECT t.name 'Table Name', + s.name 'Tablespace', + t.flag 'Table Flags', + t.n_cols 'Columns', + t.row_format 'Row Format', + t.zip_page_size 'Zip Size' + FROM information_schema.innodb_sys_tables t LEFT JOIN + information_schema.innodb_sys_tablespaces s + ON t.space = s.space + WHERE t.name not like 'SYS_%' + AND t.name NOT LIKE 'mysql/%' + AND t.name NOT LIKE 'sys/%' + ORDER BY t.name; +--enable_query_log diff --git a/mysql-test/suite/innodb/include/show_i_s_tablespaces.inc b/mysql-test/suite/innodb/include/show_i_s_tablespaces.inc new file mode 100644 index 00000000000..c6a4dfc4366 --- /dev/null +++ b/mysql-test/suite/innodb/include/show_i_s_tablespaces.inc @@ -0,0 +1,19 @@ +# This script assumes that the caller did the following; +# LET $MYSQLD_DATADIR = `select @@datadir`; +# LET $INNODB_PAGE_SIZE = `select @@innodb_page_size`; +--echo === information_schema.innodb_sys_tablespaces and innodb_sys_datafiles === +--disable_query_log +--replace_regex /#P#/#p#/ /#SP#/#sp#/ +--replace_result ./ MYSQLD_DATADIR/ $MYSQLD_DATADIR/ MYSQLD_DATADIR/ $MYSQLD_DATADIR MYSQLD_DATADIR/ $MYSQL_TMP_DIR MYSQL_TMP_DIR $INNODB_PAGE_SIZE DEFAULT +SELECT s.name 'Space_Name', + s.page_size 'Page_Size', + s.zip_page_size 'Zip_Size', + s.row_format 'Formats_Permitted', + d.path 'Path' + FROM information_schema.innodb_sys_tablespaces s, + information_schema.innodb_sys_datafiles d + WHERE s.space = d.space + AND s.name NOT LIKE 'mysql/%' + AND s.name NOT LIKE 'sys/%' + ORDER BY s.space; +--enable_query_log diff --git a/mysql-test/suite/innodb/r/innodb-system-table-view.result b/mysql-test/suite/innodb/r/innodb-system-table-view.result new file mode 100644 index 00000000000..ea29e47e27b --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb-system-table-view.result @@ -0,0 +1,153 @@ +SELECT table_id INTO @table_stats_id FROM information_schema.innodb_sys_tables +WHERE name = 'mysql/innodb_table_stats'; +SELECT table_id INTO @index_stats_id FROM information_schema.innodb_sys_tables +WHERE name = 'mysql/innodb_index_stats'; +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES +WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY table_id; +TABLE_ID NAME FLAG N_COLS SPACE FILE_FORMAT ROW_FORMAT ZIP_PAGE_SIZE +11 SYS_FOREIGN 0 7 0 Antelope Redundant 0 +12 SYS_FOREIGN_COLS 0 7 0 Antelope Redundant 0 +13 SYS_TABLESPACES 0 6 0 Antelope Redundant 0 +14 SYS_DATAFILES 0 5 0 Antelope Redundant 0 +SELECT table_id,pos,mtype,prtype,len,name +FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS +WHERE table_id NOT IN (@table_stats_id, @index_stats_id) +ORDER BY table_id, pos; +table_id pos mtype prtype len name +11 0 1 524292 0 ID +11 1 1 524292 0 FOR_NAME +11 2 1 524292 0 REF_NAME +11 3 6 0 4 N_COLS +12 0 1 524292 0 ID +12 1 6 0 4 POS +12 2 1 524292 0 FOR_COL_NAME +12 3 1 524292 0 REF_COL_NAME +13 0 6 0 4 SPACE +13 1 1 524292 0 NAME +13 2 6 0 4 FLAGS +14 0 6 0 4 SPACE +14 1 1 524292 0 PATH +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES +WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY index_id; +INDEX_ID NAME TABLE_ID TYPE N_FIELDS PAGE_NO SPACE +# ID_IND # 3 1 # # +# FOR_IND # 0 1 # # +# REF_IND # 0 1 # # +# ID_IND # 3 2 # # +# SYS_TABLESPACES_SPACE # 3 1 # # +# SYS_DATAFILES_SPACE # 3 1 # # +SELECT index_id,pos,name FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS +WHERE name NOT IN ('database_name', 'table_name', 'index_name', 'stat_name') +ORDER BY index_id, pos; +index_id pos name +11 0 ID +12 0 FOR_NAME +13 0 REF_NAME +14 0 ID +14 1 POS +15 0 SPACE +16 0 SPACE +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; +ID FOR_NAME REF_NAME N_COLS TYPE +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; +ID FOR_COL_NAME REF_COL_NAME POS +CREATE TABLE t_redundant (a INT KEY, b TEXT) ROW_FORMAT=REDUNDANT ENGINE=innodb; +CREATE TABLE t_compact (a INT KEY, b TEXT) ROW_FORMAT=COMPACT ENGINE=innodb; +CREATE TABLE t_compressed (a INT KEY, b TEXT) ROW_FORMAT=COMPRESSED ENGINE=innodb KEY_BLOCK_SIZE=2; +CREATE TABLE t_dynamic (a INT KEY, b TEXT) ROW_FORMAT=DYNAMIC ENGINE=innodb; +=== information_schema.innodb_sys_tables and innodb_sys_tablespaces === +Table Name Tablespace Table Flags Columns Row Format Zip Size +test/t_compact test/t_compact 1 5 Compact 0 +test/t_compressed test/t_compressed 37 5 Compressed 2048 +test/t_dynamic test/t_dynamic 33 5 Dynamic 0 +test/t_redundant test/t_redundant 0 5 Redundant 0 +=== information_schema.innodb_sys_tablespaces and innodb_sys_datafiles === +Space_Name Page_Size Zip_Size Formats_Permitted Path +test/t_redundant DEFAULT 0 Compact or Redundant MYSQLD_DATADIR/test/t_redundant.ibd +test/t_compact DEFAULT 0 Compact or Redundant MYSQLD_DATADIR/test/t_compact.ibd +test/t_compressed DEFAULT 2048 Compressed MYSQLD_DATADIR/test/t_compressed.ibd +test/t_dynamic DEFAULT 0 Dynamic MYSQLD_DATADIR/test/t_dynamic.ibd +DROP TABLE t_redundant, t_compact, t_compressed, t_dynamic; +SELECT count(*) FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS; +count(*) +6 +CREATE TABLE parent (id INT NOT NULL, +PRIMARY KEY (id)) ENGINE=INNODB; +CREATE TABLE child (id INT, parent_id INT, +INDEX par_ind (parent_id), +CONSTRAINT constraint_test +FOREIGN KEY (parent_id) REFERENCES parent(id) +ON DELETE CASCADE) ENGINE=INNODB; +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; +ID FOR_NAME REF_NAME N_COLS TYPE +test/constraint_test test/child test/parent 1 1 +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; +ID FOR_COL_NAME REF_COL_NAME POS +test/constraint_test parent_id id 0 +INSERT INTO parent VALUES(1); +SELECT name, num_rows, ref_count +FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name LIKE "%parent"; +name num_rows ref_count +test/parent 1 1 +SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES +WHERE name NOT LIKE 'sys/%'; +NAME FLAG N_COLS +SYS_DATAFILES 0 5 +SYS_FOREIGN 0 7 +SYS_FOREIGN_COLS 0 7 +SYS_TABLESPACES 0 6 +mysql/innodb_index_stats 1 11 +mysql/innodb_table_stats 1 9 +test/child 1 5 +test/parent 1 4 +SELECT name, n_fields +from INFORMATION_SCHEMA.INNODB_SYS_INDEXES +WHERE table_id In (SELECT table_id from +INFORMATION_SCHEMA.INNODB_SYS_TABLES +WHERE name LIKE "%parent%"); +name n_fields +PRIMARY 1 +SELECT name, n_fields +from INFORMATION_SCHEMA.INNODB_SYS_INDEXES +WHERE table_id In (SELECT table_id from +INFORMATION_SCHEMA.INNODB_SYS_TABLES +WHERE name LIKE "%child%"); +name n_fields +GEN_CLUST_INDEX 0 +par_ind 1 +SELECT name, pos, mtype, len +from INFORMATION_SCHEMA.INNODB_SYS_COLUMNS +WHERE table_id In (SELECT table_id from +INFORMATION_SCHEMA.INNODB_SYS_TABLES +WHERE name LIKE "%child%"); +name pos mtype len +id 0 6 4 +parent_id 1 6 4 +DROP TABLE child; +DROP TABLE parent; +CREATE TABLE parent (id INT NOT NULL, newid INT NOT NULL, +PRIMARY KEY (id, newid)) ENGINE=INNODB; +CREATE TABLE child (id INT, parent_id INT, +INDEX par_ind (parent_id), +CONSTRAINT constraint_test +FOREIGN KEY (id, parent_id) REFERENCES parent(id, newid) +ON DELETE CASCADE) ENGINE=INNODB; +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; +ID FOR_NAME REF_NAME N_COLS TYPE +test/constraint_test test/child test/parent 2 1 +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; +ID FOR_COL_NAME REF_COL_NAME POS +test/constraint_test id id 0 +test/constraint_test parent_id newid 1 +INSERT INTO parent VALUES(1, 9); +SELECT * FROM parent WHERE id IN (SELECT id FROM parent); +id newid +1 9 +SELECT name, num_rows, ref_count +FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name LIKE "%parent"; +name num_rows ref_count +test/parent 1 2 +DROP TABLE child; +DROP TABLE parent; diff --git a/mysql-test/suite/innodb/t/innodb-system-table-view.opt b/mysql-test/suite/innodb/t/innodb-system-table-view.opt new file mode 100644 index 00000000000..f23741f479e --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-system-table-view.opt @@ -0,0 +1,11 @@ +--innodb +--innodb-sys-tablespaces +--innodb-sys-datafiles +--innodb-sys-tablestats +--innodb-sys-tables +--innodb-sys-columns +--innodb-sys-indexes +--innodb-sys-fields +--innodb-sys-foreign +--innodb-sys-foreign-cols +--innodb-file-format=barracuda diff --git a/mysql-test/suite/innodb/t/innodb-system-table-view.test b/mysql-test/suite/innodb/t/innodb-system-table-view.test new file mode 100644 index 00000000000..e72781d2218 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-system-table-view.test @@ -0,0 +1,139 @@ +# This is the test for Information Schema System Table View +# that displays the InnoDB system table content through +# information schema tables. + +--source include/innodb_page_size_small.inc + +--disable_query_log +SET default_storage_engine=InnoDB; +LET $MYSQLD_DATADIR = `select @@datadir`; +LET $INNODB_PAGE_SIZE = `select @@innodb_page_size`; +--enable_query_log + +# The IDs of mysql.innodb_table_stats and mysql.innodb_index_stats may +# vary depending on whether the tables have been rebuilt +# by previously run tests. +SELECT table_id INTO @table_stats_id FROM information_schema.innodb_sys_tables +WHERE name = 'mysql/innodb_table_stats'; +SELECT table_id INTO @index_stats_id FROM information_schema.innodb_sys_tables +WHERE name = 'mysql/innodb_index_stats'; + +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES +WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY table_id; + +SELECT table_id,pos,mtype,prtype,len,name +FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS +WHERE table_id NOT IN (@table_stats_id, @index_stats_id) +ORDER BY table_id, pos; + +--replace_column 1 # 3 # 6 # 7 # +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES +WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY index_id; + +SELECT index_id,pos,name FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS +WHERE name NOT IN ('database_name', 'table_name', 'index_name', 'stat_name') +ORDER BY index_id, pos; + +--sorted_result +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; +--sorted_result +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; + +CREATE TABLE t_redundant (a INT KEY, b TEXT) ROW_FORMAT=REDUNDANT ENGINE=innodb; +CREATE TABLE t_compact (a INT KEY, b TEXT) ROW_FORMAT=COMPACT ENGINE=innodb; +CREATE TABLE t_compressed (a INT KEY, b TEXT) ROW_FORMAT=COMPRESSED ENGINE=innodb KEY_BLOCK_SIZE=2; +CREATE TABLE t_dynamic (a INT KEY, b TEXT) ROW_FORMAT=DYNAMIC ENGINE=innodb; + +--source suite/innodb/include/show_i_s_tables.inc +--source suite/innodb/include/show_i_s_tablespaces.inc + +DROP TABLE t_redundant, t_compact, t_compressed, t_dynamic; + +SELECT count(*) FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS; + +# Create a foreign key constraint, and verify the information +# in INFORMATION_SCHEMA.INNODB_SYS_FOREIGN and +# INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS +CREATE TABLE parent (id INT NOT NULL, + PRIMARY KEY (id)) ENGINE=INNODB; + +CREATE TABLE child (id INT, parent_id INT, + INDEX par_ind (parent_id), + CONSTRAINT constraint_test + FOREIGN KEY (parent_id) REFERENCES parent(id) + ON DELETE CASCADE) ENGINE=INNODB; + +--sorted_result +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; + +--sorted_result +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; + +# Insert a row in the table "parent", and see whether that reflected in +# INNODB_SYS_TABLESTATS +INSERT INTO parent VALUES(1); + +--sorted_result +SELECT name, num_rows, ref_count +FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name LIKE "%parent"; + +--sorted_result +SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES + WHERE name NOT LIKE 'sys/%'; + +--sorted_result +SELECT name, n_fields +from INFORMATION_SCHEMA.INNODB_SYS_INDEXES +WHERE table_id In (SELECT table_id from + INFORMATION_SCHEMA.INNODB_SYS_TABLES + WHERE name LIKE "%parent%"); + +--sorted_result +SELECT name, n_fields +from INFORMATION_SCHEMA.INNODB_SYS_INDEXES +WHERE table_id In (SELECT table_id from + INFORMATION_SCHEMA.INNODB_SYS_TABLES + WHERE name LIKE "%child%"); + +--sorted_result +SELECT name, pos, mtype, len +from INFORMATION_SCHEMA.INNODB_SYS_COLUMNS +WHERE table_id In (SELECT table_id from + INFORMATION_SCHEMA.INNODB_SYS_TABLES + WHERE name LIKE "%child%"); + +DROP TABLE child; + +DROP TABLE parent; + +# Create table with 2 columns in the foreign key constraint +CREATE TABLE parent (id INT NOT NULL, newid INT NOT NULL, + PRIMARY KEY (id, newid)) ENGINE=INNODB; + +CREATE TABLE child (id INT, parent_id INT, + INDEX par_ind (parent_id), + CONSTRAINT constraint_test + FOREIGN KEY (id, parent_id) REFERENCES parent(id, newid) + ON DELETE CASCADE) ENGINE=INNODB; + +--sorted_result +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; + +--sorted_result +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; + +INSERT INTO parent VALUES(1, 9); + +# Nested query will open the table handle twice +--sorted_result +SELECT * FROM parent WHERE id IN (SELECT id FROM parent); + +--sorted_result +SELECT name, num_rows, ref_count +FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS +WHERE name LIKE "%parent"; + +DROP TABLE child; + +DROP TABLE parent; From f616e2b97fec3a8105c70cd72e80d6ef57f460c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 18 Jul 2019 16:51:16 +0300 Subject: [PATCH 4/4] MDEV-13625: Add innodb.check_ibd_filesize --- .../innodb/r/check_ibd_filesize,32k.rdiff | 25 +++++++++ .../innodb/r/check_ibd_filesize,4k.rdiff | 25 +++++++++ .../innodb/r/check_ibd_filesize,64k.rdiff | 25 +++++++++ .../innodb/r/check_ibd_filesize,8k.rdiff | 25 +++++++++ .../suite/innodb/r/check_ibd_filesize.result | 20 +++++++ .../suite/innodb/t/check_ibd_filesize.test | 53 +++++++++++++++++++ 6 files changed, 173 insertions(+) create mode 100644 mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff create mode 100644 mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff create mode 100644 mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff create mode 100644 mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff create mode 100644 mysql-test/suite/innodb/r/check_ibd_filesize.result create mode 100644 mysql-test/suite/innodb/t/check_ibd_filesize.test diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff new file mode 100644 index 00000000000..d6828e88256 --- /dev/null +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff @@ -0,0 +1,25 @@ +--- check_ibd_filesize.result ++++ check_ibd_filesize.result,32k +@@ -3,18 +3,12 @@ + # SPACE IN 5.7 THAN IN 5.6 + # + CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 196608 + INSERT INTO t1 SELECT * FROM seq_1_to_25000; +-# bytes: 9437184 ++# bytes: 786432 + DROP TABLE t1; + CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 196608 + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +-# bytes: 2097152 +-DROP TABLE t1; +-CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) +-ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; +-# bytes: 65536 +-INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +-# bytes: 65536 ++# bytes: 786432 + DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff new file mode 100644 index 00000000000..0aeb3ebcaee --- /dev/null +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff @@ -0,0 +1,25 @@ +--- check_ibd_filesize.result ++++ check_ibd_filesize.result,4k +@@ -3,18 +3,18 @@ + # SPACE IN 5.7 THAN IN 5.6 + # + CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 24576 + INSERT INTO t1 SELECT * FROM seq_1_to_25000; + # bytes: 9437184 + DROP TABLE t1; + CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 24576 + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; + # bytes: 2097152 + DROP TABLE t1; + CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) + ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; +-# bytes: 65536 ++# bytes: 16384 + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +-# bytes: 65536 ++# bytes: 25600 + DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff new file mode 100644 index 00000000000..410707991d1 --- /dev/null +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff @@ -0,0 +1,25 @@ +--- check_ibd_filesize.result ++++ check_ibd_filesize.result,64k +@@ -3,18 +3,12 @@ + # SPACE IN 5.7 THAN IN 5.6 + # + CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 393216 + INSERT INTO t1 SELECT * FROM seq_1_to_25000; +-# bytes: 9437184 ++# bytes: 983040 + DROP TABLE t1; + CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 393216 + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +-# bytes: 2097152 +-DROP TABLE t1; +-CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) +-ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; +-# bytes: 65536 +-INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +-# bytes: 65536 ++# bytes: 1572864 + DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff new file mode 100644 index 00000000000..f1d79846c2a --- /dev/null +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff @@ -0,0 +1,25 @@ +--- check_ibd_filesize.result ++++ check_ibd_filesize.result,8k +@@ -3,18 +3,18 @@ + # SPACE IN 5.7 THAN IN 5.6 + # + CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 49152 + INSERT INTO t1 SELECT * FROM seq_1_to_25000; + # bytes: 9437184 + DROP TABLE t1; + CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; +-# bytes: 98304 ++# bytes: 49152 + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; + # bytes: 2097152 + DROP TABLE t1; + CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) + ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; +-# bytes: 65536 ++# bytes: 32768 + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +-# bytes: 65536 ++# bytes: 32768 + DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize.result b/mysql-test/suite/innodb/r/check_ibd_filesize.result new file mode 100644 index 00000000000..9465c3a3115 --- /dev/null +++ b/mysql-test/suite/innodb/r/check_ibd_filesize.result @@ -0,0 +1,20 @@ +# +# Bug #21950389 SMALL TABLESPACES WITH BLOBS TAKE UP TO 80 TIMES MORE +# SPACE IN 5.7 THAN IN 5.6 +# +CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +# bytes: 98304 +INSERT INTO t1 SELECT * FROM seq_1_to_25000; +# bytes: 9437184 +DROP TABLE t1; +CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; +# bytes: 98304 +INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +# bytes: 2097152 +DROP TABLE t1; +CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) +ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; +# bytes: 65536 +INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +# bytes: 65536 +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/check_ibd_filesize.test b/mysql-test/suite/innodb/t/check_ibd_filesize.test new file mode 100644 index 00000000000..92f9061a3f6 --- /dev/null +++ b/mysql-test/suite/innodb/t/check_ibd_filesize.test @@ -0,0 +1,53 @@ +--source include/innodb_page_size.inc +--source include/have_sequence.inc + +--echo # +--echo # Bug #21950389 SMALL TABLESPACES WITH BLOBS TAKE UP TO 80 TIMES MORE +--echo # SPACE IN 5.7 THAN IN 5.6 +--echo # + +# +# Table 1: small rows +# +CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +let MYSQLD_DATADIR=`select @@datadir`; +perl; +print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; +EOF + +INSERT INTO t1 SELECT * FROM seq_1_to_25000; +perl; +print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; +EOF +DROP TABLE t1; + +# +# Table 2: BLOB +# +CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; +perl; +print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; +EOF +INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +perl; +print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; +EOF +DROP TABLE t1; + +let $page_size=`SELECT @@innodb_page_size`; +if ($page_size < 32768) +{ +# +# Table 3: compressed BLOB +# +CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) +ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; +perl; +print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; +EOF +INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; +perl; +print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; +EOF +DROP TABLE t1; +}