Below is the list of changes that have just been committed into a local
5.1 repository of tomash. When tomash does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-03-09 13:17:46+03:00, kroki@stripped +19 -0
Merge moonlight.home:/home/tomash/src/mysql_ab/mysql-5.1
into moonlight.home:/home/tomash/src/mysql_ab/mysql-5.1-bug9953
MERGE: 1.2443.1.1
mysql-test/r/sp-error.result@stripped, 2007-03-09 13:15:44+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.119.1.1
mysql-test/r/view.result@stripped, 2007-03-09 13:15:44+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.209.1.1
sql/item_timefunc.cc@stripped, 2007-03-09 13:15:44+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.157.1.1
sql/lock.cc@stripped, 2007-03-09 13:15:44+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.102.1.1
sql/log_event.cc@stripped, 2007-03-09 13:15:44+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.266.2.1
sql/mysql_priv.h@stripped, 2007-03-09 13:15:45+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.470.11.3
sql/set_var.cc@stripped, 2007-03-09 13:15:45+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.216.1.1
sql/sp.cc@stripped, 2007-03-09 13:15:45+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.138.1.1
sql/sql_base.cc@stripped, 2007-03-09 13:15:45+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.374.2.2
sql/sql_help.cc@stripped, 2007-03-09 13:15:45+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.54.1.1
sql/sql_lex.cc@stripped, 2007-03-09 13:15:45+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.226.1.1
sql/sql_lex.h@stripped, 2007-03-09 13:15:46+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.262.1.1
sql/sql_parse.cc@stripped, 2007-03-09 13:15:46+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.631.1.1
sql/sql_show.cc@stripped, 2007-03-09 13:15:46+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.391.2.1
sql/sql_view.cc@stripped, 2007-03-09 13:15:46+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.121.1.1
sql/sql_yacc.yy@stripped, 2007-03-09 13:17:41+03:00, kroki@stripped +0 -0
SCCS merged
MERGE: 1.543.1.1
sql/table.cc@stripped, 2007-03-09 13:15:47+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.275.1.2
sql/tztime.cc@stripped, 2007-03-09 13:15:47+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.47.1.1
storage/myisam/ha_myisam.cc@stripped, 2007-03-09 13:15:47+03:00, kroki@stripped +0 -0
Auto merged
MERGE: 1.208.1.1
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: kroki
# Host: moonlight.home
# Root: /home/tomash/src/mysql_ab/mysql-5.1-bug9953/RESYNC
--- 1.210/storage/myisam/ha_myisam.cc 2007-03-09 13:17:56 +03:00
+++ 1.211/storage/myisam/ha_myisam.cc 2007-03-09 13:17:56 +03:00
@@ -565,7 +565,8 @@ err:
bool ha_myisam::check_if_locking_is_allowed(uint sql_command,
ulong type, TABLE *table,
- uint count,
+ uint count, uint current,
+ uint *system_count,
bool called_by_privileged_thread)
{
/*
@@ -574,11 +575,13 @@ bool ha_myisam::check_if_locking_is_allo
we have to disallow write-locking of these tables with any other tables.
*/
if (table->s->system_table &&
- table->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE &&
- count != 1)
+ table->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE)
+ (*system_count)++;
+
+ /* 'current' is an index, that's why '<=' below. */
+ if (*system_count > 0 && *system_count <= current)
{
- my_error(ER_WRONG_LOCK_OF_SYSTEM_TABLE, MYF(0), table->s->db.str,
- table->s->table_name.str);
+ my_error(ER_WRONG_LOCK_OF_SYSTEM_TABLE, MYF(0));
return FALSE;
}
--- 1.159/sql/item_timefunc.cc 2007-03-09 13:17:56 +03:00
+++ 1.160/sql/item_timefunc.cc 2007-03-09 13:17:56 +03:00
@@ -1927,19 +1927,6 @@ void Item_func_convert_tz::fix_length_an
}
-bool
-Item_func_convert_tz::fix_fields(THD *thd_arg, Item **ref)
-{
- String str;
- if (Item_date_func::fix_fields(thd_arg, ref))
- return TRUE;
-
- tz_tables= thd_arg->lex->time_zone_tables_used;
-
- return FALSE;
-}
-
-
String *Item_func_convert_tz::val_str(String *str)
{
TIME time_tmp;
@@ -1974,16 +1961,17 @@ bool Item_func_convert_tz::get_date(TIME
{
my_time_t my_time_tmp;
String str;
+ THD *thd= current_thd;
if (!from_tz_cached)
{
- from_tz= my_tz_find(args[1]->val_str(&str), tz_tables);
+ from_tz= my_tz_find(thd, args[1]->val_str(&str));
from_tz_cached= args[1]->const_item();
}
if (!to_tz_cached)
{
- to_tz= my_tz_find(args[2]->val_str(&str), tz_tables);
+ to_tz= my_tz_find(thd, args[2]->val_str(&str));
to_tz_cached= args[2]->const_item();
}
--- 1.104/sql/lock.cc 2007-03-09 13:17:56 +03:00
+++ 1.105/sql/lock.cc 2007-03-09 13:17:56 +03:00
@@ -692,6 +692,7 @@ static MYSQL_LOCK *get_lock_data(THD *th
DBUG_PRINT("info", ("count %d", count));
*write_lock_used=0;
+ uint system_count= 0;
for (i=tables=lock_count=0 ; i < count ; i++)
{
if (table_ptr[i]->s->tmp_table != TMP_TABLE)
@@ -705,7 +706,7 @@ static MYSQL_LOCK *get_lock_data(THD *th
*/
if (!table_ptr[i]-> file->
check_if_locking_is_allowed(thd->lex->sql_command, thd->lex->type,
- table_ptr[i], count,
+ table_ptr[i], count, i, &system_count,
(thd == logger.get_general_log_thd()) ||
(thd == logger.get_slow_log_thd()) ||
(thd == logger.get_privileged_thread())))
--- 1.274/sql/log_event.cc 2007-03-09 13:17:57 +03:00
+++ 1.275/sql/log_event.cc 2007-03-09 13:17:57 +03:00
@@ -2006,8 +2006,7 @@ int Query_log_event::exec_event(struct s
if (time_zone_len)
{
String tmp(time_zone_str, time_zone_len, &my_charset_bin);
- if (!(thd->variables.time_zone=
- my_tz_find_with_opening_tz_tables(thd, &tmp)))
+ if (!(thd->variables.time_zone= my_tz_find(thd, &tmp)))
{
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), tmp.c_ptr());
thd->variables.time_zone= global_system_variables.time_zone;
--- 1.479/sql/mysql_priv.h 2007-03-09 13:17:57 +03:00
+++ 1.480/sql/mysql_priv.h 2007-03-09 13:17:57 +03:00
@@ -1408,6 +1408,12 @@ int abort_and_upgrade_lock(ALTER_PARTITI
void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt);
void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table);
+/* Functions to work with system tables. */
+bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
+ Open_tables_state *backup);
+void close_system_tables(THD *thd, Open_tables_state *backup);
+TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
+
bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables, bool have_lock = FALSE);
void copy_field_from_tmp_record(Field *field,int offset);
bool fill_record(THD *thd, Field **field, List<Item> &values,
--- 1.382/sql/sql_base.cc 2007-03-09 13:17:57 +03:00
+++ 1.383/sql/sql_base.cc 2007-03-09 13:17:57 +03:00
@@ -6874,3 +6874,122 @@ has_two_write_locked_tables_with_auto_in
}
return 0;
}
+
+
+/*
+ Open and lock system tables for read.
+
+ SYNOPSIS
+ open_system_tables_for_read()
+ thd Thread context.
+ table_list List of tables to open.
+ backup Pointer to Open_tables_state instance where
+ information about currently open tables will be
+ saved, and from which will be restored when we will
+ end work with system tables.
+
+ NOTES
+ Thanks to restrictions which we put on opening and locking of
+ system tables for writing, we can open and lock them for reading
+ even when we already have some other tables open and locked. One
+ must call close_system_tables() to close systems tables opened
+ with this call.
+
+ RETURN
+ FALSE Success
+ TRUE Error
+*/
+
+bool
+open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
+ Open_tables_state *backup)
+{
+ DBUG_ENTER("open_system_tables_for_read");
+
+ thd->reset_n_backup_open_tables_state(backup);
+
+ uint count= 0;
+ bool not_used;
+ for (TABLE_LIST *tables= table_list; tables; tables= tables->next_global)
+ {
+ TABLE *table= open_table(thd, tables, thd->mem_root, ¬_used,
+ MYSQL_LOCK_IGNORE_FLUSH);
+ if (!table)
+ goto error;
+
+ DBUG_ASSERT(table->s->system_table);
+
+ table->use_all_columns();
+ table->reginfo.lock_type= tables->lock_type;
+ tables->table= table;
+ count++;
+ }
+
+ {
+ TABLE **list= (TABLE**) thd->alloc(sizeof(TABLE*) * count);
+ TABLE **ptr= list;
+ for (TABLE_LIST *tables= table_list; tables; tables= tables->next_global)
+ *(ptr++)= tables->table;
+
+ thd->lock= mysql_lock_tables(thd, list, count,
+ MYSQL_LOCK_IGNORE_FLUSH, ¬_used);
+ }
+ if (thd->lock)
+ DBUG_RETURN(FALSE);
+
+error:
+ close_system_tables(thd, backup);
+
+ DBUG_RETURN(TRUE);
+}
+
+
+/*
+ Close system tables, opened with open_system_tables_for_read().
+
+ SYNOPSIS
+ close_system_tables()
+ thd Thread context
+ backup Pointer to Open_tables_state instance which holds
+ information about tables which were open before we
+ decided to access system tables.
+*/
+
+void
+close_system_tables(THD *thd, Open_tables_state *backup)
+{
+ close_thread_tables(thd);
+ thd->restore_backup_open_tables_state(backup);
+}
+
+
+/*
+ Open and lock one system table for update.
+
+ SYNOPSIS
+ open_system_table_for_update()
+ thd Thread context.
+ one_table Table to open.
+
+ NOTES
+ Table opened with this call should closed using close_thread_tables().
+
+ RETURN
+ 0 Error
+ # Pointer to TABLE object of system table
+*/
+
+TABLE *
+open_system_table_for_update(THD *thd, TABLE_LIST *one_table)
+{
+ DBUG_ENTER("open_system_table_for_update");
+
+ TABLE *table= open_ltable(thd, one_table, one_table->lock_type);
+ if (table)
+ {
+ DBUG_ASSERT(table->s->system_table);
+ table->use_all_columns();
+ }
+
+ DBUG_RETURN(table);
+}
--- 1.230/sql/sql_lex.cc 2007-03-09 13:17:57 +03:00
+++ 1.231/sql/sql_lex.cc 2007-03-09 13:17:57 +03:00
@@ -158,7 +158,6 @@ void lex_start(THD *thd, const uchar *bu
lex->lock_option= TL_READ;
lex->found_semicolon= 0;
lex->safe_to_cache_query= 1;
- lex->time_zone_tables_used= 0;
lex->leaf_tables_insert= 0;
lex->parsing_options.reset();
lex->empty_field_list_on_rset= 0;
@@ -2093,31 +2092,6 @@ void st_lex::first_lists_tables_same()
/*
- Add implicitly used time zone description tables to global table list
- (if needed).
-
- SYNOPSYS
- st_lex::add_time_zone_tables_to_query_tables()
- thd - pointer to current thread context
-
- RETURN VALUE
- TRUE - error
- FALSE - success
-*/
-
-bool st_lex::add_time_zone_tables_to_query_tables(THD *thd_arg)
-{
- /* We should not add these tables twice */
- if (!time_zone_tables_used)
- {
- time_zone_tables_used= my_tz_get_table_list(thd_arg, &query_tables_last);
- if (time_zone_tables_used == &fake_time_zone_tables_list)
- return TRUE;
- }
- return FALSE;
-}
-
-/*
Link table back that was unlinked with unlink_first_table()
SYNOPSIS
@@ -2186,7 +2160,6 @@ void st_lex::cleanup_after_one_table_ope
/* remove underlying units (units of VIEW) subtree */
select_lex.cut_subtree();
}
- time_zone_tables_used= 0;
}
--- 1.265/sql/sql_lex.h 2007-03-09 13:17:57 +03:00
+++ 1.266/sql/sql_lex.h 2007-03-09 13:17:57 +03:00
@@ -1092,11 +1092,6 @@ typedef struct st_lex : public Query_tab
bool prepared_stmt_code_is_varref;
/* Names of user variables holding parameters (in EXECUTE) */
List<LEX_STRING> prepared_stmt_params;
- /*
- Points to part of global table list which contains time zone tables
- implicitly used by the statement.
- */
- TABLE_LIST *time_zone_tables_used;
sp_head *sphead;
sp_name *spname;
bool sp_lex_in_use; /* Keep track on lex usage in SPs for error handling */
@@ -1183,7 +1178,6 @@ typedef struct st_lex : public Query_tab
TABLE_LIST *unlink_first_table(bool *link_to_local);
void link_first_table_back(TABLE_LIST *first, bool link_to_local);
void first_lists_tables_same();
- bool add_time_zone_tables_to_query_tables(THD *thd);
bool can_be_merged();
bool can_use_merged();
--- 1.636/sql/sql_parse.cc 2007-03-09 13:17:57 +03:00
+++ 1.637/sql/sql_parse.cc 2007-03-09 13:17:57 +03:00
@@ -1676,8 +1676,7 @@ mysql_execute_command(THD *thd)
Don't reset warnings when executing a stored routine.
*/
if ((all_tables || &lex->select_lex != lex->all_selects_list ||
- lex->sroutines.records) && !thd->spcont ||
- lex->time_zone_tables_used)
+ lex->sroutines.records) && !thd->spcont)
mysql_reset_errors(thd, 0);
#ifdef HAVE_REPLICATION
@@ -4726,9 +4725,7 @@ check_table_access(THD *thd, ulong want_
*/
tables->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL);
if (tables->derived || tables->schema_table ||
- (tables->table && (int)tables->table->s->tmp_table) ||
- my_tz_check_n_skip_implicit_tables(&tables,
- thd->lex->time_zone_tables_used))
+ (tables->table && (int)tables->table->s->tmp_table))
continue;
thd->security_ctx= sctx;
if ((sctx->master_access & want_access) ==
@@ -6496,14 +6493,12 @@ bool multi_update_precheck(THD *thd, TAB
/*
Is there tables of subqueries?
*/
- if (&lex->select_lex != lex->all_selects_list || lex->time_zone_tables_used)
+ if (&lex->select_lex != lex->all_selects_list)
{
DBUG_PRINT("info",("Checking sub query list"));
for (table= tables; table; table= table->next_global)
{
- if (!my_tz_check_n_skip_implicit_tables(&table,
- lex->time_zone_tables_used) &&
- !table->table_in_first_from_clause)
+ if (!table->table_in_first_from_clause)
{
if (check_access(thd, SELECT_ACL, table->db,
&table->grant.privilege, 0, 0,
--- 1.394/sql/sql_show.cc 2007-03-09 13:17:57 +03:00
+++ 1.395/sql/sql_show.cc 2007-03-09 13:17:57 +03:00
@@ -3511,7 +3511,7 @@ int fill_schema_proc(THD *thd, TABLE_LIS
err:
proc_table->file->ha_index_end();
- close_proc_table(thd, &open_tables_state_backup);
+ close_system_tables(thd, &open_tables_state_backup);
DBUG_RETURN(res);
}
--- 1.549/sql/sql_yacc.yy 2007-03-09 13:17:57 +03:00
+++ 1.550/sql/sql_yacc.yy 2007-03-09 13:17:57 +03:00
@@ -10357,14 +10357,7 @@ internal_variable_name:
MYSQL_YYABORT;
$$.var= tmp;
$$.base_name= null_lex_str;
- /*
- If this is time_zone variable we should open time zone
- describing tables
- */
- if (tmp == &sys_time_zone &&
- lex->add_time_zone_tables_to_query_tables(YYTHD))
- MYSQL_YYABORT;
- else if (spc && tmp == &sys_autocommit)
+ if (spc && tmp == &sys_autocommit)
{
/*
We don't allow setting AUTOCOMMIT from a stored function
--- 1.279/sql/table.cc 2007-03-09 13:17:57 +03:00
+++ 1.280/sql/table.cc 2007-03-09 13:17:57 +03:00
@@ -245,6 +245,50 @@ void free_table_share(TABLE_SHARE *share
}
+/**
+ Return TRUE if a table name matches one of the system table names.
+ Currently these are:
+
+ help_category, help_keyword, help_relation, help_topic,
+ proc,
+ time_zone, time_zone_leap_second, time_zone_name, time_zone_transition,
+ time_zone_transition_type
+
+ This function trades accuracy for speed, so may return false
+ positives. Presumably mysql.* database is for internal purposes only
+ and should not contain user tables.
+*/
+
+inline bool is_system_table_name(const char *name, uint length)
+{
+ CHARSET_INFO *ci= system_charset_info;
+
+ return (
+ /* mysql.proc table */
+ length == 4 &&
+ my_tolower(ci, name[0]) == 'p' &&
+ my_tolower(ci, name[1]) == 'r' &&
+ my_tolower(ci, name[2]) == 'o' &&
+ my_tolower(ci, name[3]) == 'c' ||
+
+ length > 4 &&
+ (
+ /* one of mysql.help* tables */
+ my_tolower(ci, name[0]) == 'h' &&
+ my_tolower(ci, name[1]) == 'e' &&
+ my_tolower(ci, name[2]) == 'l' &&
+ my_tolower(ci, name[3]) == 'p' ||
+
+ /* one of mysql.time_zone* tables */
+ my_tolower(ci, name[0]) == 't' &&
+ my_tolower(ci, name[1]) == 'i' &&
+ my_tolower(ci, name[2]) == 'm' &&
+ my_tolower(ci, name[3]) == 'e'
+ )
+ );
+}
+
+
/*
Read table definition from a binary / text based .frm file
@@ -365,11 +409,9 @@ int open_table_def(THD *thd, TABLE_SHARE
allow to lock such tables for writing with any other tables (even with
other system tables) and some privilege tables need this.
*/
- if (!(lower_case_table_names ?
- my_strcasecmp(system_charset_info, share->table_name.str, "proc") :
- strcmp(share->table_name.str, "proc")))
- share->system_table= 1;
- else
+ share->system_table= is_system_table_name(share->table_name.str,
+ share->table_name.length);
+ if (!share->system_table)
{
share->log_table= check_if_log_table(share->db.length, share->db.str,
share->table_name.length,
--- 1.211/mysql-test/r/view.result 2007-03-09 13:17:57 +03:00
+++ 1.212/mysql-test/r/view.result 2007-03-09 13:17:57 +03:00
@@ -900,6 +900,7 @@ drop view v1;
drop table t1;
create table t1 (col1 int);
create table t2 (col1 int);
+create table t3 (col1 datetime not null);
create view v1 as select * from t1;
create view v2 as select * from v1;
create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
@@ -1004,8 +1005,8 @@ ERROR HY000: The definition of table 'v2
insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2));
ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3'.
insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
-insert into mysql.time_zone values ('', (select CONVERT_TZ('20050101000000','UTC','MET') from t2));
-ERROR 23000: Column 'Use_leap_seconds' cannot be null
+insert into t3 values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
+ERROR 23000: Column 'col1' cannot be null
create algorithm=temptable view v4 as select * from t1;
insert into t1 values (1),(2),(3);
insert into t1 (col1) values ((select max(col1) from v4));
@@ -1017,7 +1018,7 @@ NULL
3
3
drop view v4,v3,v2,v1;
-drop table t1,t2;
+drop table t1,t2,t3;
create table t1 (s1 int);
create view v1 as select * from t1;
handler v1 open as xx;
--- 1.123/sql/sql_view.cc 2007-03-09 13:17:57 +03:00
+++ 1.124/sql/sql_view.cc 2007-03-09 13:17:57 +03:00
@@ -1302,8 +1302,6 @@ ok:
(st_select_lex_node**)&old_lex->all_selects_list;
ok2:
- if (!old_lex->time_zone_tables_used && thd->lex->time_zone_tables_used)
- old_lex->time_zone_tables_used= thd->lex->time_zone_tables_used;
DBUG_ASSERT(lex == thd->lex);
thd->lex= old_lex; // Needed for prepare_security
result= !table->prelocking_placeholder && table->prepare_security(thd);
--- 1.48/sql/tztime.cc 2007-03-09 13:17:57 +03:00
+++ 1.49/sql/tztime.cc 2007-03-09 13:17:57 +03:00
@@ -1488,26 +1488,20 @@ extern "C" byte* my_offset_tzs_get_key(T
/*
- Prepare table list with time zone related tables from preallocated array
- and add to global table list.
+ Prepare table list with time zone related tables from preallocated array.
SYNOPSIS
tz_init_table_list()
tz_tabs - pointer to preallocated array of MY_TZ_TABLES_COUNT
TABLE_LIST objects
- global_next_ptr - pointer to variable which points to global_next member
- of last element of global table list (or list root
- then list is empty) (in/out).
DESCRIPTION
This function prepares list of TABLE_LIST objects which can be used
- for opening of time zone tables from preallocated array. It also links
- this list to the end of global table list (it will read and update
- accordingly variable pointed by global_next_ptr for this).
+ for opening of time zone tables from preallocated array.
*/
static void
-tz_init_table_list(TABLE_LIST *tz_tabs, TABLE_LIST ***global_next_ptr)
+tz_init_table_list(TABLE_LIST *tz_tabs)
{
bzero(tz_tabs, sizeof(TABLE_LIST) * MY_TZ_TABLES_COUNT);
@@ -1524,64 +1518,6 @@ tz_init_table_list(TABLE_LIST *tz_tabs,
if (i != 0)
tz_tabs[i].prev_global= &tz_tabs[i-1].next_global;
}
-
- /* Link into global list */
- tz_tabs[0].prev_global= *global_next_ptr;
- **global_next_ptr= tz_tabs;
- /* Update last-global-pointer to point to pointer in last table */
- *global_next_ptr= &tz_tabs[MY_TZ_TABLES_COUNT-1].next_global;
-}
-
-
-/*
- Fake table list object, pointer to which is returned by
- my_tz_get_tables_list() as indication of error.
-*/
-TABLE_LIST fake_time_zone_tables_list;
-
-/*
- Create table list with time zone related tables and add it to the end
- of global table list.
-
- SYNOPSIS
- my_tz_get_table_list()
- thd - current thread object
- global_next_ptr - pointer to variable which points to global_next member
- of last element of global table list (or list root
- then list is empty) (in/out).
-
- DESCRIPTION
- This function creates list of TABLE_LIST objects allocated in thd's
- memroot, which can be used for opening of time zone tables. It will also
- link this list to the end of global table list (it will read and update
- accordingly variable pointed by global_next_ptr for this).
-
- NOTE
- my_tz_check_n_skip_implicit_tables() function depends on fact that
- elements of list created are allocated as TABLE_LIST[MY_TZ_TABLES_COUNT]
- array.
-
- RETURN VALUES
- Returns pointer to first TABLE_LIST object, (could be 0 if time zone
- tables don't exist) and &fake_time_zone_tables_list in case of error.
-*/
-
-TABLE_LIST *
-my_tz_get_table_list(THD *thd, TABLE_LIST ***global_next_ptr)
-{
- TABLE_LIST *tz_tabs;
- DBUG_ENTER("my_tz_get_table_list");
-
- if (!time_zone_tables_exist)
- DBUG_RETURN(0);
-
- if (!(tz_tabs= (TABLE_LIST *)thd->alloc(sizeof(TABLE_LIST) *
- MY_TZ_TABLES_COUNT)))
- DBUG_RETURN(&fake_time_zone_tables_list);
-
- tz_init_table_list(tz_tabs, global_next_ptr);
-
- DBUG_RETURN(tz_tabs);
}
@@ -1614,8 +1550,8 @@ my_bool
my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
{
THD *thd;
- TABLE_LIST *tables= 0;
- TABLE_LIST tables_buff[1+MY_TZ_TABLES_COUNT], **last_global_next_ptr;
+ TABLE_LIST tz_tables[1+MY_TZ_TABLES_COUNT];
+ Open_tables_state open_tables_state_backup;
TABLE *table;
Tz_names_entry *tmp_tzname;
my_bool return_val= 1;
@@ -1677,19 +1613,23 @@ my_tz_init(THD *org_thd, const char *def
*/
thd->set_db(db, sizeof(db)-1);
- bzero((char*) &tables_buff, sizeof(TABLE_LIST));
- tables_buff[0].alias= tables_buff[0].table_name=
+ bzero((char*) &tz_tables[0], sizeof(TABLE_LIST));
+ tz_tables[0].alias= tz_tables[0].table_name=
(char*)"time_zone_leap_second";
- tables_buff[0].lock_type= TL_READ;
- tables_buff[0].db= db;
+ tz_tables[0].table_name_length= 21;
+ tz_tables[0].db= db;
+ tz_tables[0].db_length= sizeof(db)-1;
+ tz_tables[0].lock_type= TL_READ;
+
+ tz_init_table_list(tz_tables+1);
+ tz_tables[0].next_global= tz_tables[0].next_local= &tz_tables[1];
+ tz_tables[1].prev_global= &tz_tables[0].next_global;
+
/*
- Fill TABLE_LIST for the rest of the time zone describing tables
- and link it to first one.
+ We need to open only mysql.time_zone_leap_second, but we try to
+ open all time zone tables to see if they exist.
*/
- last_global_next_ptr= &(tables_buff[0].next_global);
- tz_init_table_list(tables_buff + 1, &last_global_next_ptr);
-
- if (simple_open_n_lock_tables(thd, tables_buff))
+ if (open_system_tables_for_read(thd, tz_tables, &open_tables_state_backup))
{
sql_print_warning("Can't open and lock time zone table: %s "
"trying to live without them", thd->net.last_error);
@@ -1697,7 +1637,6 @@ my_tz_init(THD *org_thd, const char *def
return_val= time_zone_tables_exist= 0;
goto end_with_setting_default_tz;
}
- tables= tables_buff + 1;
/*
Now we are going to load leap seconds descriptions that are shared
@@ -1713,7 +1652,7 @@ my_tz_init(THD *org_thd, const char *def
goto end_with_close;
}
- table= tables_buff[0].table;
+ table= tz_tables[0].table;
/*
It is OK to ignore ha_index_init()/ha_index_end() return values since
mysql.time_zone* tables are MyISAM and these operations always succeed
@@ -1770,7 +1709,12 @@ end_with_setting_default_tz:
if (default_tzname)
{
String tmp_tzname2(default_tzname, &my_charset_latin1);
- if (!(global_system_variables.time_zone= my_tz_find(&tmp_tzname2, tables)))
+ /*
+ Time zone tables may be open here, and my_tz_find() may open
+ most of them once more, but this is OK for system tables open
+ for READ.
+ */
+ if (!(global_system_variables.time_zone= my_tz_find(thd, &tmp_tzname2)))
{
sql_print_error("Fatal error: Illegal or unknown default time zone '%s'",
default_tzname);
@@ -1779,8 +1723,11 @@ end_with_setting_default_tz:
}
end_with_close:
- thd->version--; /* Force close to free memory */
- close_thread_tables(thd);
+ if (time_zone_tables_exist)
+ {
+ thd->version--; /* Force close to free memory */
+ close_system_tables(thd, &open_tables_state_backup);
+ }
end_with_cleanup:
@@ -1889,7 +1836,6 @@ tz_load_from_open_tables(const String *t
*/
table= tz_tables->table;
tz_tables= tz_tables->next_local;
- table->use_all_columns();
table->field[0]->store(tz_name->ptr(), tz_name->length(),
&my_charset_latin1);
/*
@@ -1922,7 +1868,6 @@ tz_load_from_open_tables(const String *t
using the only index in this table).
*/
table= tz_tables->table;
- table->use_all_columns();
tz_tables= tz_tables->next_local;
table->field[0]->store((longlong) tzid, TRUE);
(void)table->file->ha_index_init(0, 1);
@@ -1950,7 +1895,6 @@ tz_load_from_open_tables(const String *t
Right - using special index.
*/
table= tz_tables->table;
- table->use_all_columns();
tz_tables= tz_tables->next_local;
table->field[0]->store((longlong) tzid, TRUE);
(void)table->file->ha_index_init(0, 1);
@@ -2024,7 +1968,6 @@ tz_load_from_open_tables(const String *t
in ascending order by index scan also satisfies us.
*/
table= tz_tables->table;
- table->use_all_columns();
table->field[0]->store((longlong) tzid, TRUE);
(void)table->file->ha_index_init(0, 1);
@@ -2234,8 +2177,8 @@ str_to_offset(const char *str, uint leng
SYNOPSIS
my_tz_find()
+ thd - pointer to thread THD structure
name - time zone specification
- tz_tables - list of opened'n'locked time zone describing tables
DESCRIPTION
This function checks if name is one of time zones described in db,
@@ -2257,11 +2200,10 @@ str_to_offset(const char *str, uint leng
values as parameter without additional external check and this property
is used by @@time_zone variable handling code).
- It will perform lookup in system tables (mysql.time_zone*) if needed
- using tz_tables as list of already opened tables (for info about this
- list look at tz_load_from_open_tables() description). It won't perform
- such lookup if no time zone describing tables were found during server
- start up.
+ It will perform lookup in system tables (mysql.time_zone*),
+ opening and locking them, and closing afterwards. It won't perform
+ such lookup if no time zone describing tables were found during
+ server start up.
RETURN VALUE
Pointer to corresponding Time_zone object. 0 - in case of bad time zone
@@ -2269,7 +2211,7 @@ str_to_offset(const char *str, uint leng
*/
Time_zone *
-my_tz_find(const String * name, TABLE_LIST *tz_tables)
+my_tz_find(THD *thd, const String *name)
{
Tz_names_entry *tmp_tzname;
Time_zone *result_tz= 0;
@@ -2277,8 +2219,6 @@ my_tz_find(const String * name, TABLE_LI
DBUG_ENTER("my_tz_find");
DBUG_PRINT("enter", ("time zone name='%s'",
name ? ((String *)name)->c_ptr_safe() : "NULL"));
- DBUG_ASSERT(!time_zone_tables_exist || tz_tables ||
- current_thd->slave_thread);
if (!name)
DBUG_RETURN(0);
@@ -2310,8 +2250,19 @@ my_tz_find(const String * name, TABLE_LI
(const byte *)name->ptr(),
name->length())))
result_tz= tmp_tzname->tz;
- else if (time_zone_tables_exist && tz_tables)
- result_tz= tz_load_from_open_tables(name, tz_tables);
+ else if (time_zone_tables_exist)
+ {
+ TABLE_LIST tz_tables[MY_TZ_TABLES_COUNT];
+ Open_tables_state open_tables_state_backup;
+
+ tz_init_table_list(tz_tables);
+ if (!open_system_tables_for_read(thd, tz_tables,
+ &open_tables_state_backup))
+ {
+ result_tz= tz_load_from_open_tables(name, tz_tables);
+ close_system_tables(thd, &open_tables_state_backup);
+ }
+ }
}
VOID(pthread_mutex_unlock(&tz_LOCK));
@@ -2319,58 +2270,6 @@ my_tz_find(const String * name, TABLE_LI
DBUG_RETURN(result_tz);
}
-
-/*
- A more standalone version of my_tz_find(): will open tz tables if needed.
- This is so far only used by replication, where time zone setting does not
- happen in the usual query context.
-
- SYNOPSIS
- my_tz_find_with_opening_tz_tables()
- thd - pointer to thread's THD structure
- name - time zone specification
-
- DESCRIPTION
- This function tries to find a time zone which matches the named passed in
- argument. If it fails, it will open time zone tables and re-try the
- search.
- This function is needed for the slave SQL thread, which does not do the
- addition of time zone tables which is usually done during query parsing
- (as time zone setting by slave does not happen in mysql_parse() but
- before). So it needs to open tz tables by itself if needed.
- See notes of my_tz_find() as they also apply here.
-
- RETURN VALUE
- Pointer to corresponding Time_zone object. 0 - in case of bad time zone
- specification or other error.
-*/
-
-Time_zone *my_tz_find_with_opening_tz_tables(THD *thd, const String *name)
-{
- Time_zone *tz;
- DBUG_ENTER("my_tz_find_with_opening_tables");
- DBUG_ASSERT(thd);
- DBUG_ASSERT(thd->slave_thread); // intended for use with slave thread only
-
- if (!(tz= my_tz_find(name, 0)) && time_zone_tables_exist)
- {
- /*
- Probably we have not loaded this time zone yet so let us look it up in
- our time zone tables. Note that if we don't have tz tables on this
- slave, we don't even try.
- */
- TABLE_LIST tables[MY_TZ_TABLES_COUNT];
- TABLE_LIST *dummy;
- TABLE_LIST **dummyp= &dummy;
- tz_init_table_list(tables, &dummyp);
- if (simple_open_n_lock_tables(thd, tables))
- DBUG_RETURN(0);
- tz= my_tz_find(name, tables);
- /* We need to close tables _now_ to not pollute coming query */
- close_thread_tables(thd);
- }
- DBUG_RETURN(tz);
-}
#endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */
--- 1.217/sql/set_var.cc 2007-03-09 13:17:57 +03:00
+++ 1.218/sql/set_var.cc 2007-03-09 13:17:57 +03:00
@@ -2869,8 +2869,7 @@ bool sys_var_thd_time_zone::check(THD *t
String str(buff, sizeof(buff), &my_charset_latin1);
String *res= var->value->val_str(&str);
- if (!(var->save_result.time_zone=
- my_tz_find(res, thd->lex->time_zone_tables_used)))
+ if (!(var->save_result.time_zone= my_tz_find(thd, res)))
{
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
return 1;
@@ -2931,8 +2930,7 @@ void sys_var_thd_time_zone::set_default(
We are guaranteed to find this time zone since its existence
is checked during start-up.
*/
- global_system_variables.time_zone=
- my_tz_find(&str, thd->lex->time_zone_tables_used);
+ global_system_variables.time_zone= my_tz_find(thd, &str);
}
else
global_system_variables.time_zone= my_tz_SYSTEM;
--- 1.121/mysql-test/r/sp-error.result 2007-03-09 13:17:57 +03:00
+++ 1.122/mysql-test/r/sp-error.result 2007-03-09 13:17:57 +03:00
@@ -292,9 +292,9 @@ call p()|
unlock tables|
drop procedure p|
lock tables t1 read, mysql.proc write|
-ERROR HY000: You can't combine write-locking of system 'mysql.proc' table with other tables
+ERROR HY000: You can't combine write-locking of system tables with other tables or lock types
lock tables mysql.proc write, mysql.user write|
-ERROR HY000: You can't combine write-locking of system 'mysql.proc' table with other tables
+ERROR HY000: You can't combine write-locking of system tables with other tables or lock types
lock tables t1 read, mysql.proc read|
unlock tables|
lock tables mysql.proc write|
--- 1.139/sql/sp.cc 2007-03-09 13:17:57 +03:00
+++ 1.140/sql/sp.cc 2007-03-09 13:17:57 +03:00
@@ -69,24 +69,6 @@ enum
/*
- Close mysql.proc, opened with open_proc_table_for_read().
-
- SYNOPSIS
- close_proc_table()
- thd Thread context
- backup Pointer to Open_tables_state instance which holds
- information about tables which were open before we
- decided to access mysql.proc.
-*/
-
-void close_proc_table(THD *thd, Open_tables_state *backup)
-{
- close_thread_tables(thd);
- thd->restore_backup_open_tables_state(backup);
-}
-
-
-/*
Open the mysql.proc table for read.
SYNOPSIS
@@ -96,13 +78,6 @@ void close_proc_table(THD *thd, Open_tab
currently open tables will be saved, and from which will be
restored when we will end work with mysql.proc.
- NOTES
- Thanks to restrictions which we put on opening and locking of
- this table for writing, we can open and lock it for reading
- even when we already have some other tables open and locked.
- One must call close_proc_table() to close table opened with
- this call.
-
RETURN
0 Error
# Pointer to TABLE object of mysql.proc
@@ -110,38 +85,18 @@ void close_proc_table(THD *thd, Open_tab
TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
{
- TABLE_LIST tables;
- TABLE *table;
- bool not_used;
- DBUG_ENTER("open_proc_table");
-
- thd->reset_n_backup_open_tables_state(backup);
-
- bzero((char*) &tables, sizeof(tables));
- tables.db= (char*) "mysql";
- tables.table_name= tables.alias= (char*)"proc";
- if (!(table= open_table(thd, &tables, thd->mem_root, ¬_used,
- MYSQL_LOCK_IGNORE_FLUSH)))
- {
- thd->restore_backup_open_tables_state(backup);
- DBUG_RETURN(0);
- }
- table->use_all_columns();
+ DBUG_ENTER("open_proc_table_for_read");
- DBUG_ASSERT(table->s->system_table);
+ TABLE_LIST table;
+ bzero((char*) &table, sizeof(table));
+ table.db= (char*) "mysql";
+ table.table_name= table.alias= (char*)"proc";
+ table.lock_type= TL_READ;
- table->reginfo.lock_type= TL_READ;
- /*
- We have to ensure we are not blocked by a flush tables, as this
- could lead to a deadlock if we have other tables opened.
- */
- if (!(thd->lock= mysql_lock_tables(thd, &table, 1,
- MYSQL_LOCK_IGNORE_FLUSH, ¬_used)))
- {
- close_proc_table(thd, backup);
+ if (!open_system_tables_for_read(thd, &table, backup))
+ DBUG_RETURN(table.table);
+ else
DBUG_RETURN(0);
- }
- DBUG_RETURN(table);
}
@@ -162,20 +117,15 @@ TABLE *open_proc_table_for_read(THD *thd
static TABLE *open_proc_table_for_update(THD *thd)
{
- TABLE_LIST tables;
- TABLE *table;
- DBUG_ENTER("open_proc_table");
-
- bzero((char*) &tables, sizeof(tables));
- tables.db= (char*) "mysql";
- tables.table_name= tables.alias= (char*)"proc";
- tables.lock_type= TL_WRITE;
+ DBUG_ENTER("open_proc_table_for_update");
- table= open_ltable(thd, &tables, TL_WRITE);
- if (table)
- table->use_all_columns();
+ TABLE_LIST table;
+ bzero((char*) &table, sizeof(table));
+ table.db= (char*) "mysql";
+ table.table_name= table.alias= (char*)"proc";
+ table.lock_type= TL_WRITE;
- DBUG_RETURN(table);
+ DBUG_RETURN(open_system_table_for_update(thd, &table));
}
@@ -364,7 +314,7 @@ db_find_routine(THD *thd, int type, sp_n
chistics.comment.str= ptr;
chistics.comment.length= length;
- close_proc_table(thd, &open_tables_state_backup);
+ close_system_tables(thd, &open_tables_state_backup);
table= 0;
ret= db_load_routine(thd, type, name, sphp,
@@ -373,7 +323,7 @@ db_find_routine(THD *thd, int type, sp_n
done:
if (table)
- close_proc_table(thd, &open_tables_state_backup);
+ close_system_tables(thd, &open_tables_state_backup);
DBUG_RETURN(ret);
}
@@ -1147,7 +1097,7 @@ sp_routine_exists_in_table(THD *thd, int
{
if ((ret= db_find_routine_aux(thd, type, name, table)) != SP_OK)
ret= SP_KEY_NOT_FOUND;
- close_proc_table(thd, &open_tables_state_backup);
+ close_system_tables(thd, &open_tables_state_backup);
}
return ret;
}
--- 1.55/sql/sql_help.cc 2007-03-09 13:17:57 +03:00
+++ 1.56/sql/sql_help.cc 2007-03-09 13:17:57 +03:00
@@ -655,8 +655,9 @@ bool mysqld_help(THD *thd, const char *m
tables[3].lock_type= TL_READ;
tables[0].db= tables[1].db= tables[2].db= tables[3].db= (char*) "mysql";
- if (open_and_lock_tables(thd, tables))
- goto error;
+ Open_tables_state open_tables_state_backup;
+ if (open_system_tables_for_read(thd, tables, &open_tables_state_backup))
+ goto error2;
/*
Init tables and fields to be usable from items
@@ -781,8 +782,13 @@ bool mysqld_help(THD *thd, const char *m
}
send_eof(thd);
+ close_system_tables(thd, &open_tables_state_backup);
DBUG_RETURN(FALSE);
+
error:
+ close_system_tables(thd, &open_tables_state_backup);
+
+error2:
DBUG_RETURN(TRUE);
}
| Thread |
|---|
| • bk commit into 5.1 tree (kroki:1.2462) | kroki | 9 Mar |