| 1 |
# Check that binlogging are turned on for these tests |
| 2 |
--source include/have_log_bin.inc |
| 3 |
|
| 4 |
# |
| 5 |
# Run variations of ALTER RENAME based on template query |
| 6 |
# on the form ALTER RENAME tx ... ty |
| 7 |
# |
| 8 |
|
| 9 |
if (!$query) |
| 10 |
{ |
| 11 |
die Need the query to test with provided in $query; |
| 12 |
} |
| 13 |
|
| 14 |
let $num_tables = `select count(*) from information_schema.tables |
| 15 |
where TABLE_SCHEMA = 'ndb_ddl_test'`; |
| 16 |
if (!$num_tables) |
| 17 |
{ |
| 18 |
die Could not figure out number of tables in ndb_ddl_test database; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
let $counter = 1; |
| 23 |
while ($counter <= $num_tables) |
| 24 |
{ |
| 25 |
# Default table name is t$counter, ie. t1, t2, etc |
| 26 |
let $tx=t$counter; |
| 27 |
let $suffix=_new_name; # Small mysqltest trick to facilatate string concat |
| 28 |
let $ty=t$counter$suffix; |
| 29 |
#echo tx: $tx; |
| 30 |
#echo ty: $ty; |
| 31 |
|
| 32 |
# By default we don't expect any error |
| 33 |
let $expected_error = 0; |
| 34 |
|
| 35 |
if ($counter == 2) |
| 36 |
{ |
| 37 |
# Rename to same name |
| 38 |
# i.e t2 -> t2 |
| 39 |
let $ty = $tx; |
| 40 |
if ($expect_rename_to_same_name_to_fail == 1) |
| 41 |
{ |
| 42 |
let $expected_error = ER_TABLE_EXISTS_ERROR; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if ($counter == 3) |
| 47 |
{ |
| 48 |
|
| 49 |
## |
| 50 |
# Rename to same name but different db |
| 51 |
# i.e t3 -> ndb_ddl_test2.t3 |
| 52 |
# |
| 53 |
let $ty = ndb_ddl_test2.t3; |
| 54 |
} |
| 55 |
|
| 56 |
if ($counter == 4) |
| 57 |
{ |
| 58 |
## |
| 59 |
# Rename to different name and different db |
| 60 |
# ie. t4 -> ndb_ddl_test2.t4 |
| 61 |
# |
| 62 |
let $ty = ndb_ddl_test2.t4_new_name; |
| 63 |
} |
| 64 |
|
| 65 |
if ($counter == 5) |
| 66 |
{ |
| 67 |
## |
| 68 |
# Rename to a existing table name |
| 69 |
# ie. t5 -> t2 |
| 70 |
let $ty = t2; |
| 71 |
# This should fail |
| 72 |
let $expected_error = ER_TABLE_EXISTS_ERROR; |
| 73 |
} |
| 74 |
|
| 75 |
# Replace ty and tx in the query and run it |
| 76 |
let $replaced_query = |
| 77 |
`select REPLACE(REPLACE('$query', 'tx', '$tx'), 'ty', '$ty')`; |
| 78 |
if ($expected_error != 0) |
| 79 |
{ |
| 80 |
# expect the query to fail |
| 81 |
--error $expected_error |
| 82 |
} |
| 83 |
eval $replaced_query; |
| 84 |
|
| 85 |
# Check that old name table does not exist |
| 86 |
# (if the rename was not expected to fail |
| 87 |
# and the rename is not to the same name) |
| 88 |
# Note : using multiple ifs as MTR has a weird bug processing |
| 89 |
# `if ($expected_error == 0 && $tx != $ty)` |
| 90 |
if ($expected_error == 0) { |
| 91 |
if ($tx != $ty) { |
| 92 |
--disable_query_log |
| 93 |
--disable_result_log |
| 94 |
--error ER_NO_SUCH_TABLE |
| 95 |
eval SELECT count(*) FROM $tx; |
| 96 |
--enable_query_log |
| 97 |
--enable_result_log |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
if ($expected_error != 0){ |
| 102 |
# The rename was expected to fail. Due to this, we can't |
| 103 |
# verify the new table. Rather, check if the rollback was |
| 104 |
# proper by verifying that the old table is still intact. |
| 105 |
# We do this by assigning the old name to $ty and let the |
| 106 |
# verification continue. |
| 107 |
let $ty = $tx; |
| 108 |
} |
| 109 |
|
| 110 |
# Check that new name table exists |
| 111 |
--disable_query_log |
| 112 |
--disable_result_log |
| 113 |
eval SELECT * FROM $ty; |
| 114 |
--enable_query_log |
| 115 |
--enable_result_log |
| 116 |
|
| 117 |
# Check that new table contains expected number of rows |
| 118 |
let $ty_count = `SELECT count(*) from $ty`; |
| 119 |
if ($ty_count != 5) |
| 120 |
{ |
| 121 |
echo Wrong number of rows, ecpected 5 got $ty_count; |
| 122 |
die Wrong number of rows in renamed table; |
| 123 |
} |
| 124 |
|
| 125 |
# List all NDB objects for the renamed table and store them |
| 126 |
# in temporary table in the test database |
| 127 |
let $create_table_name = test.post_$tx; |
| 128 |
let $list_table_name = $ty; |
| 129 |
--source list_objects.inc |
| 130 |
#eval select * from test.pre_$tx; |
| 131 |
#eval select * from test.post_$tx; |
| 132 |
|
| 133 |
# Compare the objects(indexes, blob tables etc.) on the renamed table whith |
| 134 |
# what was there before. Ignore id and version since those are not expected |
| 135 |
# to be the same |
| 136 |
--disable_query_log |
| 137 |
eval CREATE TEMPORARY TABLE test.diff_objects |
| 138 |
SELECT * FROM ( |
| 139 |
SELECT type, state, parent_obj_type, |
| 140 |
REPLACE(fq_name, parent_obj_id, 'X') AS masked_fq_name |
| 141 |
FROM test.pre_$tx |
| 142 |
UNION ALL |
| 143 |
SELECT type, state, parent_obj_type, |
| 144 |
REPLACE(fq_name, parent_obj_id, 'X') AS masked_fq_name |
| 145 |
FROM test.post_$tx |
| 146 |
) t |
| 147 |
/* group by columns to compare */ |
| 148 |
GROUP BY type, state, parent_obj_type, masked_fq_name |
| 149 |
/* return only those without match */ |
| 150 |
HAVING COUNT(*) = 1; |
| 151 |
--enable_query_log |
| 152 |
|
| 153 |
let $diff_rows = `SELECT count(*) FROM test.diff_objects`; |
| 154 |
if ($diff_rows) |
| 155 |
{ |
| 156 |
echo Detected diff in objects on renamed table; |
| 157 |
eval SELECT * FROM test.pre_$tx ORDER BY ID; |
| 158 |
eval SELECT * FROM test.post_$tx ORDER BY ID; |
| 159 |
SELECT * FROM test.diff_objects ORDER BY ID; |
| 160 |
die The objects created on the renamed table differed!; |
| 161 |
} |
| 162 |
--disable_query_log |
| 163 |
DROP TABLE test.diff_objects; |
| 164 |
--enable_query_log |
| 165 |
|
| 166 |
inc $counter; |
| 167 |
} |
| 168 |
|
| 169 |
--source verify_mysql_dd.inc |
| 170 |
|
| 171 |
|
| 172 |
# Reset parameters which should change between each invocation |
| 173 |
let $sql =; |
| 174 |
let $expect_rename_to_same_name_to_fail =; |