1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00
"
  revision-id: sanja@askmonty.org-20110511110948-4kdevwzomvk56y1w
  committer: sanja@askmonty.org
  branch nick: work-maria-5.1-CREATE-merge
  timestamp: Wed 2011-05-11 14:09:48 +0300
    Bugfix: New table creation/renaming block added if old encoded table present
"
the old behavior was less inconsistent than the new one.
In the new one the error message was sometimes different (under LOCK TABLES e.g.),
and there were race conditions (if this CREATE happened when a concurrent ALTER
has renamed the old table away but haven't put the new table in place)

The old one was like "(when using old table names) for DML #mysql50# prefix
is optional, for DDL it's required".
This commit is contained in:
Sergei Golubchik
2013-04-09 15:35:07 +02:00
parent b9f42f4b7a
commit 87a9d60ec6
7 changed files with 55 additions and 117 deletions

View File

@ -4036,68 +4036,6 @@ static bool check_if_created_table_can_be_opened(THD *thd,
#endif
/**
Check that there is no frm file for given table
@param old_path path to the old frm file
@param path path to the frm file in new encoding
@param db database name
@param table_name table name
@param alias table name for error message (for new encoding)
@param issue_error should we issue error messages
@retval FALSE there is no frm file
@retval TRUE there is frm file
*/
bool check_table_file_presence(char *old_path,
char *path,
const char *db,
const char *table_name,
const char *alias,
bool issue_error)
{
if (!access(path,F_OK))
{
if (issue_error)
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),alias);
return TRUE;
}
{
/*
Check if file of the table in 5.0 file name encoding exists.
Except case when it is the same table.
*/
char tbl50[FN_REFLEN];
#ifdef _WIN32
if (check_if_legal_tablename(table_name) != 0)
{
/*
Check for reserved device names for which access() returns 0
(CON, AUX etc).
*/
return FALSE;
}
#endif
strxmov(tbl50, mysql_data_home, "/", db, "/", table_name, NullS);
fn_format(tbl50, tbl50, "", reg_ext, MY_UNPACK_FILENAME);
if (!access(tbl50, F_OK) &&
(old_path == NULL ||
strcmp(old_path, tbl50) != 0))
{
if (issue_error)
{
strxmov(tbl50, MYSQL50_TABLE_NAME_PREFIX, table_name, NullS);
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), tbl50);
}
return TRUE;
}
}
return FALSE;
}
/*
Create a table
@ -4382,12 +4320,11 @@ bool mysql_create_table_no_lock(THD *thd,
if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
if (check_table_file_presence(NULL, path, db, table_name, table_name,
!(create_info->options &
HA_LEX_CREATE_IF_NOT_EXISTS)))
if (!access(path,F_OK))
{
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
goto warn;
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
goto err;
}
/*
@ -6066,7 +6003,6 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
MDL_request target_mdl_request;
int error= 0;
char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN + 1];
char old_name_buff[FN_REFLEN + 1];
char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
char index_file[FN_REFLEN], data_file[FN_REFLEN];
char path[FN_REFLEN + 1];
@ -6273,12 +6209,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
*/
build_table_filename(new_name_buff, sizeof(new_name_buff) - 1,
new_db, new_name_buff, reg_ext, 0);
build_table_filename(old_name_buff, sizeof(old_name_buff) - 1,
db, table_name, reg_ext, 0);
if (check_table_file_presence(old_name_buff, new_name_buff, new_db,
new_name, new_alias, TRUE))
if (!access(new_name_buff, F_OK))
{
/* Table will be closed in do_command() */
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
goto err;
}
}