Debian Codegraph @

storage/myisammrg/mysql-test/storage_engine/alter_table.inc

raw
1 ##################################
2 #
3 # This include file will be used for all ALTER TABLE statements in the suite.
4 # If you need to add additional steps or change the logic, copy the file
5 # to storage/<engine>/mysql-test/storage_engine/ folder and modify it there.
6 #
7 ##################
8 #
9 # Parameters:
10 #
11 # --let $alter_definition = <alter definition> # mandatory, everything that goes after the table name in ALTER statement
12 # --let $table_name = <table name> # optional, default t1
13 # --let $error_codes = <expected error codes, as in --error> # optional, default 0
14 # --let $online = [0|1] # optional, default 0 (1 adds ONLINE)
15 # --let $rename_to = <new table name> # optional, default empty.
16 # # If set, means we are running RENAME TO, then alter definition is ignored
17 #
18 # Usage examples:
19 #
20 # --let $alter_definition = ADD COLUMN b $char_col DEFAULT ''
21 #
22
23 --let $child_alter_definition = $alter_definition
24
25 if ($rename_to)
26 {
27 --let $alter_definition = RENAME TO $rename_to
28 --let $child_alter_definition = RENAME TO mrg.$rename_to
29 }
30
31 if (!$alter_definition)
32 {
33 --die # The ALTER statement is empty
34 }
35
36 --let $alter_statement = ALTER
37
38 if ($online)
39 {
40 --let $alter_statement = $alter_statement ONLINE
41 }
42
43 if (!$table_name)
44 {
45 --let $table_name = t1
46 }
47
48 --let $alter_statement = $alter_statement TABLE $table_name $alter_definition
49 # We don't want to do ONLINE on underlying tables, we are not testing MyISAM
50 --let $child_statement = ALTER TABLE mrg.$table_name $child_alter_definition
51
52
53
54 # We now have the complete ALTER statement in $alter_statement.
55 # If your ALTER statement should be composed differently,
56 # modify the logic above.
57
58 #####################
59 # Here you can add logic needed BEFORE the main statement
60 # (e.g. base tables need to be altered, etc.).
61 # Surround it by --disable_query_log/--enable_query_log
62 # if you don't want it to appear in the result output.
63 #####################
64
65 --source obfuscate.inc
66
67 eval $alter_statement;
68 --source check_errors.inc
69
70 # Make sure you don't add any statements between the main ALTER (above)
71 # and saving mysql_errno and mysql_errname (below)
72 # They are saved in case you want to add more logic after the main ALTER,
73 # because we need the result code of the statement.
74 # Also, do not change $alter_statement after it is executed!
75
76 --let $my_errno = $mysql_errno
77 --let $my_errname = $mysql_errname
78
79 #####################
80 # Here you can add logic needed AFTER the main statement.
81 # Surround it by --disable_query_log/--enable_query_log
82 # if you don't want it to appear in the result output.
83 #####################
84 --disable_query_log
85 --disable_warnings
86 --disable_result_log
87 # We will only try to alter the underlying table if the main alter was successful
88 if (!$my_errno)
89 {
90 if ($rename_to)
91 {
92 eval ALTER TABLE $rename_to UNION(mrg.$rename_to);
93 }
94 # In the same section, the manual says that FLUSH TABLES should be performed before altering
95 # the underlying table, and later also says that it should be done after. We'll do both
96 FLUSH TABLES;
97 eval $child_statement;
98 FLUSH TABLES;
99 }
100 --enable_result_log
101 --enable_warnings
102 --enable_query_log
103
104 # Unset the parameters, we don't want them to be accidentally reused later
105 --let $alter_definition =
106 --let $table_name =
107 --let $error_codes =
108 --let $online = 0
109 --let $rename_to =
110
111 # Restore the error codes of the main statement
112 --let $mysql_errno = $my_errno
113 --let $mysql_errname = $my_errname
114 # Make sure you don't add any SQL statements after restoring
115 # mysql_errno and mysql_errname (above)
116