File: system_tables_storage_engine_tests.inc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (152 lines) | stat: -rw-r--r-- 5,217 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
################################################################################
# System tables are created in the InnoDB engine. Altering engine of System table
# to MyISAM is not supported. To support logical upgrade, creation of System
# table in MyISAM engine is supported with some restrictions. Test cases in this
# file verifies aforementioned behavior.
#
# =============== TEST CASES ==================
#
# 1 Verify altering system table' engine to MyISAM.
# 2 Verify system table creation in MyISAM engine.
#
################################################################################

--source include/have_myisam.inc

CREATE TABLE system_tables (ID INT PRIMARY KEY AUTO_INCREMENT,
                            table_name VARCHAR(100));

if (!$uppercase_system_table_names) {
  INSERT INTO system_tables(table_name)
         SELECT concat(table_schema, ".", table_name)
         FROM INFORMATION_SCHEMA.tables WHERE table_schema =
              'mysql' AND table_name NOT IN('general_log', 'slow_log',
                                            'ndb_binlog_index')
         ORDER BY table_name;
}

# Use system table names in uppercase. Tests with l_c_t_n = 1 or 2 sets this
# variable.
if ($uppercase_system_table_names) {
  INSERT INTO system_tables(table_name)
         SELECT UPPER(concat(table_schema, ".", table_name))
         FROM INFORMATION_SCHEMA.tables WHERE table_schema =
              'mysql' AND table_name NOT IN('general_log', 'slow_log',
                                            'ndb_binlog_index')
         ORDER BY table_name;
}

--echo #-----------------------------------------------------------------------
--echo # Test case to verify altering system table's engine to MyISAM. Changing
--echo # system table's engine to MyISAM is not allowed.
--echo #-----------------------------------------------------------------------
DELIMITER $;
CREATE PROCEDURE test_system_table_alter_engine()
BEGIN
  DECLARE n INT DEFAULT 0;
  DECLARE i INT DEFAULT 1;

-- ER_UNSUPPORTED_ENGINE(1726) is reported for all the system engines except for
-- innodb_index_stats and innodb_table_stats. ER_TOO_LONG_KEY(1071) is reported for
-- innodb_index_stats and ER_NOT_ALLOWED_COMMAND(1148) is reported for innodb_table_stats
-- for now.
  DECLARE CONTINUE HANDLER FOR 1726, 1071, 1148
  BEGIN
    GET DIAGNOSTICS CONDITION 1 @message = MESSAGE_TEXT;
    SELECT @message AS ERROR;
  END;

  SELECT count(*) FROM system_tables INTO n;
  WHILE i <= n DO
    SELECT table_name FROM system_tables WHERE id = i INTO @table_name;
    SELECT @table_name;

    SET @sql_text = concat("ALTER TABLE ", @table_name, " ENGINE = MyISAM");
    PREPARE stmt FROM @sql_text;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;

    SET i = i + 1;
  END WHILE;
END$
DELIMITER ;$

CALL test_system_table_alter_engine();

#cleanup
DROP PROCEDURE test_system_table_alter_engine;


--echo #-----------------------------------------------------------------------
--echo # Test case to verify system table creation in MyISAM engine. Creating
--echo # system table in MyISAM is allowed to support logical upgrade.
--echo #-----------------------------------------------------------------------
DELIMITER $;
CREATE PROCEDURE execute_stmt(stmt VARCHAR(255))
BEGIN
  SET @error_no = 0;
  SET @sql_stmt = stmt;

  PREPARE stmt FROM @sql_stmt;
  EXECUTE stmt;

  GET DIAGNOSTICS CONDITION 1 @error_no = MYSQL_ERRNO, @error_message = MESSAGE_TEXT;
  IF @error_no > 0 THEN
    SELECT "Warning" AS SEVERITY, @error_no as ERRNO, @error_message as MESSAGE;
  END IF;

  DEALLOCATE PREPARE stmt;
END$

CREATE PROCEDURE test_create_system_table()
BEGIN
  DECLARE n INT DEFAULT 0;
  DECLARE i INT DEFAULT 1;

-- Error ER_NO_SYSTEM_TABLE_ACCESS(3554) is reported for innodb_table_stats and
-- innodb_index_stats. For other tables ER_UNSUPPORTED_ENGINE "warning" is reported.
-- Warning is handled in the execute_stmt().
  DECLARE CONTINUE HANDLER FOR 3554
  BEGIN
    GET DIAGNOSTICS CONDITION 1 @error = MYSQL_ERRNO, @error_message = MESSAGE_TEXT;
  END;

  SELECT count(*) FROM system_tables INTO n;

  WHILE i <= n DO
    SET @error = 0;
    SELECT table_name FROM system_tables WHERE id = i INTO @table_name;

    SET @sql_text = concat('RENAME TABLE ', @table_name, ' TO mysql.backup_table');
    CALL execute_stmt(@sql_text);

    SET @sql_text = concat('CREATE TABLE ', @table_name, ' ENGINE=InnoDB AS SELECT * FROM mysql.backup_table');
    CALL execute_stmt(@sql_text);

    SET @sql_text = concat('DROP TABLE ', @table_name);
    CALL execute_stmt(@sql_text);

    SET @sql_text = concat('CREATE TABLE ', @table_name, ' ENGINE=MyISAM AS SELECT * FROM mysql.backup_table');
    CALL execute_stmt(@sql_text);

    IF @error > 0 THEN
      SELECT "ERROR" AS SEVERITY, @error AS ERRNO, @error_message AS MESSAGE;
    ELSE
      SET @sql_text = concat('DROP TABLE ', @table_name);
      CALL execute_stmt(@sql_text);
    END IF;

    SET @sql_text = concat('RENAME TABLE mysql.backup_table TO ', @table_name);
    CALL execute_stmt(@sql_text);

    SET i = i + 1;
  END WHILE;
END$
DELIMITER ;$

CALL test_create_system_table();

#cleanup
DROP PROCEDURE test_create_system_table;
DROP PROCEDURE execute_stmt;
DROP TABLE system_tables;