File: alter_rename.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 (174 lines) | stat: -rw-r--r-- 4,616 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Check  that binlogging are turned on for these tests
--source include/have_log_bin.inc

#
# Run variations of ALTER RENAME based on template query
# on the form ALTER RENAME tx ... ty
#

if (!$query)
{
  die Need the query to test with provided in $query;
}

let $num_tables = `select count(*) from information_schema.tables
                     where TABLE_SCHEMA = 'ndb_ddl_test'`;
if (!$num_tables)
{
  die Could not figure out number of tables in ndb_ddl_test database;
}


let $counter = 1;
while ($counter <= $num_tables)
{
   # Default table name is t$counter, ie. t1, t2, etc
   let $tx=t$counter;
   let $suffix=_new_name; # Small mysqltest trick to facilatate string concat
   let $ty=t$counter$suffix;
   #echo tx: $tx;
   #echo ty: $ty;

   # By default we don't expect any error
   let $expected_error = 0;

  if ($counter == 2)
  {
    # Rename to same name
    #   i.e t2 -> t2
    let $ty = $tx;
    if ($expect_rename_to_same_name_to_fail == 1)
    {
      let $expected_error = ER_TABLE_EXISTS_ERROR;
    }
  }

  if ($counter == 3)
  {

    ##
    # Rename to same name but different db
    #   i.e t3 -> ndb_ddl_test2.t3
    #
    let $ty = ndb_ddl_test2.t3;
  }

  if ($counter == 4)
  {
    ##
    # Rename to different name and different db
    #  ie. t4 -> ndb_ddl_test2.t4
    #
    let $ty = ndb_ddl_test2.t4_new_name;
  }

  if ($counter == 5)
  {
    ##
    # Rename to a existing table name
    #  ie. t5 -> t2
    let $ty = t2;
    # This should fail
    let $expected_error = ER_TABLE_EXISTS_ERROR;
  }

  # Replace ty and tx in the query and run it
  let $replaced_query =
     `select REPLACE(REPLACE('$query', 'tx', '$tx'), 'ty', '$ty')`;
  if ($expected_error != 0)
  {
    # expect the query to fail
    --error $expected_error
  }
  eval $replaced_query;

  # Check that old name table does not exist
  # (if the rename was not expected to fail
  #  and the rename is not to the same name)
  # Note : using multiple ifs as MTR has a weird bug processing
  #        `if ($expected_error == 0 && $tx != $ty)`
  if ($expected_error == 0) {
    if ($tx != $ty) {
      --disable_query_log
      --disable_result_log
      --error ER_NO_SUCH_TABLE
      eval SELECT count(*) FROM $tx;
      --enable_query_log
      --enable_result_log
    }
  }

  if ($expected_error != 0){
    # The rename was expected to fail. Due to this, we can't
    # verify the new table. Rather, check if the rollback was
    # proper by verifying that the old table is still intact.
    # We do this by assigning the old name to $ty and let the
    # verification continue.
    let $ty = $tx;
  }

  # Check that new name table exists
  --disable_query_log
  --disable_result_log
  eval SELECT * FROM $ty;
  --enable_query_log
  --enable_result_log

  # Check that new table contains expected number of rows
  let $ty_count = `SELECT count(*) from $ty`;
  if ($ty_count != 5)
  {
    echo Wrong number of rows, ecpected 5 got $ty_count;
    die Wrong number of rows in renamed table;
  }

  # List all NDB objects for the renamed table and store them
  # in temporary table in the test database
  let $create_table_name = test.post_$tx;
  let $list_table_name = $ty;
  --source list_objects.inc
  #eval select * from test.pre_$tx;
  #eval select * from test.post_$tx;

  # Compare the objects(indexes, blob tables etc.) on the renamed table whith
  # what was there before. Ignore id and version since those are not expected
  # to be the same
  --disable_query_log
  eval CREATE TEMPORARY TABLE test.diff_objects
    SELECT * FROM (
      SELECT type, state, parent_obj_type,
        REPLACE(fq_name, parent_obj_id, 'X') AS masked_fq_name
          FROM test.pre_$tx
      UNION ALL
      SELECT type, state, parent_obj_type,
        REPLACE(fq_name, parent_obj_id, 'X') AS masked_fq_name
          FROM test.post_$tx
    ) t
    /* group by columns to compare */
    GROUP BY type, state, parent_obj_type, masked_fq_name
    /* return only those without match */
    HAVING COUNT(*) = 1;
  --enable_query_log

  let $diff_rows = `SELECT count(*) FROM test.diff_objects`;
  if ($diff_rows)
  {
    echo Detected diff in objects on renamed table;
    eval SELECT * FROM test.pre_$tx ORDER BY ID;
    eval SELECT * FROM test.post_$tx ORDER BY ID;
    SELECT  * FROM test.diff_objects ORDER BY ID;
    die The objects created on the renamed table differed!;
  }
  --disable_query_log
  DROP TABLE test.diff_objects;
  --enable_query_log

  inc $counter;
}

--source verify_mysql_dd.inc


# Reset parameters which should change between each invocation
let $sql =;
let $expect_rename_to_same_name_to_fail =;