summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc57
1 files changed, 38 insertions, 19 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 2832adc1f8f..1b5e91daf3e 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -589,8 +589,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
String str(buff,(uint32) sizeof(buff), system_charset_info);
char md5[MD5_BUFF_LENGTH];
bool can_be_merged;
- char dir_buff[FN_REFLEN], file_buff[FN_REFLEN];
- LEX_STRING dir, file;
+ char dir_buff[FN_REFLEN], file_buff[FN_REFLEN], path_buff[FN_REFLEN];
+ LEX_STRING dir, file, path;
DBUG_ENTER("mysql_register_view");
/* print query */
@@ -605,15 +605,17 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
DBUG_PRINT("info", ("View: %s", str.ptr()));
/* print file name */
- (void) my_snprintf(dir_buff, FN_REFLEN, "%s/%s/",
- mysql_data_home, view->db);
- unpack_filename(dir_buff, dir_buff);
+ dir.length= build_table_filename(dir_buff, sizeof(dir_buff),
+ view->db, "", "");
dir.str= dir_buff;
- dir.length= strlen(dir_buff);
- file.str= file_buff;
- file.length= (strxnmov(file_buff, FN_REFLEN, view->table_name, reg_ext,
- NullS) - file_buff);
+ path.length= build_table_filename(path_buff, sizeof(path_buff),
+ view->db, view->table_name, reg_ext);
+ path.str= path_buff;
+
+ file.str= path.str + dir.length;
+ file.length= path.length - dir.length;
+
/* init timestamp */
if (!view->timestamp.str)
view->timestamp.str= view->timestamp_buffer;
@@ -1195,17 +1197,17 @@ err:
bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
{
- DBUG_ENTER("mysql_drop_view");
char path[FN_REFLEN];
TABLE_LIST *view;
- bool type= 0;
- db_type not_used;
+ enum legacy_db_type not_used;
+ DBUG_ENTER("mysql_drop_view");
for (view= views; view; view= view->next_local)
{
- strxnmov(path, FN_REFLEN, mysql_data_home, "/", view->db, "/",
- view->table_name, reg_ext, NullS);
- (void) unpack_filename(path, path);
+ TABLE_SHARE *share;
+ bool type= 0;
+ build_table_filename(path, sizeof(path),
+ view->db, view->table_name, reg_ext);
VOID(pthread_mutex_lock(&LOCK_open));
if (access(path, F_OK) ||
(type= (mysql_frm_type(thd, path, &not_used) != FRMTYPE_VIEW)))
@@ -1228,6 +1230,20 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
}
if (my_delete(path, MYF(MY_WME)))
goto err;
+
+ /*
+ For a view, there is only one table_share object which should never
+ be used outside of LOCK_open
+ */
+ if ((share= get_cached_table_share(view->db, view->table_name)))
+ {
+ DBUG_ASSERT(share->ref_count == 0);
+ pthread_mutex_lock(&share->mutex);
+ share->ref_count++;
+ share->version= 0;
+ pthread_mutex_unlock(&share->mutex);
+ release_table_share(share, RELEASE_WAIT_FOR_DROP);
+ }
query_cache_invalidate3(thd, view, 0);
sp_cache_invalidate();
VOID(pthread_mutex_unlock(&LOCK_open));
@@ -1255,7 +1271,7 @@ err:
FRMTYPE_VIEW view
*/
-frm_type_enum mysql_frm_type(THD *thd, char *path, db_type *dbt)
+frm_type_enum mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
{
File file;
uchar header[10]; //"TYPE=VIEW\n" it is 10 characters
@@ -1284,7 +1300,7 @@ frm_type_enum mysql_frm_type(THD *thd, char *path, db_type *dbt)
(header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
DBUG_RETURN(FRMTYPE_TABLE);
- *dbt= ha_checktype(thd, (enum db_type) (uint) *(header + 3), 0, 0);
+ *dbt= (enum legacy_db_type) (uint) *(header + 3);
DBUG_RETURN(FRMTYPE_TABLE); // Is probably a .frm table
}
@@ -1342,6 +1358,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST *view)
*/
bool save_set_query_id= thd->set_query_id;
thd->set_query_id= 0;
+ DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
for (Field_translator *fld= trans; fld < end_of_trans; fld++)
{
if (!fld->item->fixed && fld->item->fix_fields(thd, &fld->item))
@@ -1351,6 +1368,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST *view)
}
}
thd->set_query_id= save_set_query_id;
+ DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
}
/* Loop over all keys to see if a unique-not-null key is used */
for (;key_info != key_info_end ; key_info++)
@@ -1506,7 +1524,7 @@ mysql_rename_view(THD *thd,
DBUG_ENTER("mysql_rename_view");
- strxnmov(view_path, FN_REFLEN, mysql_data_home, "/", view->db, "/",
+ strxnmov(view_path, FN_REFLEN-1, mysql_data_home, "/", view->db, "/",
view->table_name, reg_ext, NullS);
(void) unpack_filename(view_path, view_path);
@@ -1540,7 +1558,8 @@ mysql_rename_view(THD *thd,
view_def.revision - 1, num_view_backups))
goto err;
- strxnmov(dir_buff, FN_REFLEN, mysql_data_home, "/", view->db, "/", NullS);
+ strxnmov(dir_buff, FN_REFLEN-1, mysql_data_home, "/", view->db, "/",
+ NullS);
(void) unpack_filename(dir_buff, dir_buff);
pathstr.str= (char*)dir_buff;