Debian Codegraph @

mysql-test/suite/innodb/include/create_sql_file.inc

raw
1 # --------------------------------------------------------------------
2 # This file is used to generate INSTANT DDL statements based on the
3 # INPUT (operation type (ADD/DROP), column position).
4 # --------------------------------------------------------------------
5
6 #################### Perl module starts ####################
7 perl;
8
9 my $total_col = $ENV{'total_col'};
10 my $input = $ENV{'input'};
11
12 my $Columns = $ENV{'Columns'};
13 my @col_name_array = split(' ', $Columns);
14 print "@col_name_array\n";
15
16 my $ICol1 = $ENV{'ICol1'};
17 my $ICol2 = $ENV{'ICol2'};
18 my $ICol3 = $ENV{'ICol3'};
19 my $ICol4 = $ENV{'ICol4'};
20 my $ICol5 = $ENV{'ICol5'};
21 my $ICol6 = $ENV{'ICol6'};
22 my @col_descr_array = ($ICol1, $ICol2, $ICol3, $ICol4, $ICol5, $ICol6);
23
24 my $vardir = $ENV{'MYSQLTEST_VARDIR'};
25 my $filename="$vardir/sql_file.inc";
26 open(OP_FILE, '>', $filename) or die "$!";
27
28 print OP_FILE "SET SESSION debug= '+d,show_dropped_column';\n";
29 scan_input();
30
31 close OP_FILE;
32
33 # Subroutine to print the validate SQL in generated test script
34 sub insert_validate_query {
35 my $validate_query_string = "
36 --disable_query_log
37 let \$table_id = `SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME='test/t1'`;
38
39 eval SELECT NAME, POS, MTYPE, PRTYPE, VERSION_ADDED, VERSION_DROPPED
40 FROM INFORMATION_SCHEMA.INNODB_COLUMNS
41 WHERE TABLE_ID=\$table_id;
42
43 eval SELECT NAME, N_COLS, INSTANT_COLS, TOTAL_ROW_VERSIONS,
44 INITIAL_COLUMN_COUNTS, CURRENT_COLUMN_COUNTS, TOTAL_COLUMN_COUNTS
45 FROM INFORMATION_SCHEMA.INNODB_TABLES
46 WHERE TABLE_ID=\$table_id;
47
48 SET SESSION debug= '+d,skip_dd_table_access_check';
49 SELECT ID INTO \@tid FROM mysql.tables WHERE NAME='t1';
50 --replace_result \$table_id TABLE_ID
51 SELECT NAME, ORDINAL_POSITION, TYPE, HAS_NO_DEFAULT, HIDDEN, SE_PRIVATE_DATA
52 FROM mysql.columns
53 WHERE TABLE_ID=\@tid ORDER BY ORDINAL_POSITION;
54 --enable_query_log
55
56 SELECT * FROM t1;
57
58 --echo #---------------------------------------------\n\n";
59
60 print OP_FILE $validate_query_string;
61 }
62
63 # Subroutine to scan input and generate INSTANT DDLs in test script
64 sub scan_input {
65 my @token_array = split(' ', $input);
66
67 my $count = 0;
68 my $operation = $token_array[$count++];
69
70 # Skip =
71 $count++;
72
73 my $instant_col = 0;
74 $token = $token_array[$count++];
75 while ($token ne '') {
76 my $command = "ALTER TABLE t1 $operation COLUMN ";
77
78 my @temp_array = split(' ', $col_descr_array[$ic]);
79 my $inst_col_name = $temp_array[0];
80
81 my @pos_array= split('', $token);
82 my $final_pos = $pos_array[1];
83
84 if ($final_pos eq ']') {
85 $final_pos = $total_col;
86 if ($operation eq "ADD") {
87 $total_col++;
88 $command = $command.$col_descr_array[$ic];
89 push @col_name_array, $inst_col_name;
90 $ic++;
91 } else {
92 die "ERROR INPUT STRING";
93 }
94 } else {
95 if ($operation eq "ADD") {
96 $total_col++;
97 $command = $command."$col_descr_array[$ic] AFTER $col_name_array[$final_pos - 1] ";
98 splice @col_name_array, $final_pos, 0, $inst_col_name;
99 $ic++;
100 } else {
101 $command = $command."$col_name_array[$final_pos - 1]";
102 splice @col_name_array, $final_pos - 1, 1;
103 }
104 }
105
106 $command = $command.", ALGORITHM=INSTANT;";
107 print OP_FILE "$command\n";
108 print OP_FILE "--echo # Column name array @col_name_array\n";
109 insert_validate_query();
110
111 $token = @token_array[$count++];
112 }
113
114 # Write the final column list so that it could be taken for next test if needed.
115 print OP_FILE "--let Columns = @col_name_array\n";
116 }
117
118 EOF
119 #################### Perl module ends ####################