MXS-2264: Add support for ALTER TABLE RENAME

This adds preliminary support for renaming tables. There is still a
problem where the table version will always be set to 1 on a rename. This
should not be done and the version should be set to the largest value that
ever was for that table.
This commit is contained in:
Markus Mäkelä
2019-09-30 08:03:52 +03:00
parent a444484310
commit 2eb6a25534
3 changed files with 54 additions and 0 deletions

View File

@ -1381,6 +1381,38 @@ bool Rpl::table_create_alter(STableCreateEvent create, const char* sql, const ch
}
}
tok = get_next_def(tok, end);
len = 0;
}
else if (tok_eq(ptok, "rename", plen))
{
if (tok_eq(tok, "to", len))
{
// Skip the optional TO keyword
tok = get_tok(tok + len, &len, end);
}
char new_name[len + 1];
make_avro_token(new_name, tok, len);
auto old_id = create->id();
if (char* p = strchr(new_name, '.'))
{
*p++ = '\0';
create->database = new_name;
create->table = p;
}
else
{
create->table = new_name;
}
create->version = 1;
create->was_used = false;
rename_table_create(create, old_id);
tok = get_next_def(tok, end);
len = 0;
}