diff options
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r-- | sql/sql_base.cc | 348 |
1 files changed, 175 insertions, 173 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6e0472cd149..d58bc64e975 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -15,11 +15,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Basic functions neaded by many modules */ +/* Basic functions needed by many modules */ #include "mysql_priv.h" #include "sql_acl.h" -#include <thr_alarm.h> #include <m_ctype.h> #include <my_dir.h> #include <hash.h> @@ -34,8 +33,6 @@ HASH open_cache; /* Used by mysql_test */ static int open_unireg_entry(THD *thd,TABLE *entry,const char *db, const char *name, const char *alias); -static bool insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, - const char *table_name, List_iterator<Item> *it); static void free_cache_entry(TABLE *entry); static void mysql_rm_tmp_tables(void); static key_map get_key_map_from_key_list(TABLE *table, @@ -111,75 +108,90 @@ static void check_unused(void) #define check_unused() #endif -int list_open_tables(THD *thd,List<char> *tables, const char *db, - const char *wild) +/* + Create a list for all open tables matching SQL expression + + SYNOPSIS + list_open_tables() + thd Thread THD + wild SQL like expression + + NOTES + One gets only a list of tables for which one has any kind of privilege. + db and table names are allocated in result struct, so one doesn't need + a lock on LOCK_open when traversing the return list. + + RETURN VALUES + NULL Error (Probably OOM) + # Pointer to list of names of open tables. +*/ + +OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild) { int result = 0; - uint col_access=thd->col_access; + OPEN_TABLE_LIST **start_list, *open_list; TABLE_LIST table_list; + char name[NAME_LEN*2]; DBUG_ENTER("list_open_tables"); + VOID(pthread_mutex_lock(&LOCK_open)); bzero((char*) &table_list,sizeof(table_list)); + start_list= &open_list; + open_list=0; - for (uint idx=0 ; idx < open_cache.records; idx++) + for (uint idx=0 ; result == 0 && idx < open_cache.records; idx++) { + OPEN_TABLE_LIST *table; TABLE *entry=(TABLE*) hash_element(&open_cache,idx); - if ((!entry->real_name) || strcmp(entry->table_cache_key,db)) - continue; - if (wild && wild[0] && wild_compare(entry->real_name,wild)) - continue; - if (db && !(col_access & TABLE_ACLS)) + + if ((!entry->real_name)) + continue; // Shouldn't happen + if (wild) { - table_list.db= (char*) db; - table_list.real_name= entry->real_name;/*real name*/ - table_list.grant.privilege=col_access; - if (check_grant(thd,TABLE_ACLS,&table_list,1,1)) - continue; + strxmov(name,entry->table_cache_key,".",entry->real_name,NullS); + if (wild_compare(name,wild)) + continue; } - /* need to check if he have't already listed it */ - List_iterator<char> it(*tables); - char *table_name; - int check = 0; - while (check == 0 && (table_name=it++)) + /* Check if user has SELECT privilege for any column in the table */ + table_list.db= (char*) entry->table_cache_key; + table_list.real_name= entry->real_name; + table_list.grant.privilege=0; + if (check_table_access(thd,SELECT_ACL | EXTRA_ACL,&table_list,1)) + continue; + + /* need to check if we haven't already listed it */ + for (table= open_list ; table ; table=table->next) { - if (!strcmp(table_name,entry->real_name)) - check++; + if (!strcmp(table->table,entry->real_name) && + !strcmp(table->db,entry->table_cache_key)) + { + if (entry->in_use) + table->in_use++; + if (entry->locked_by_name) + table->locked++; + break; + } } - if (check) + if (table) continue; - - if (tables->push_back(thd->strdup(entry->real_name))) + if (!(*start_list = (OPEN_TABLE_LIST *) + sql_alloc(sizeof(**start_list)+entry->key_length))) { - result = -1; + open_list=0; // Out of memory break; } + strmov((*start_list)->table= + strmov(((*start_list)->db= (char*) ((*start_list)+1)), + entry->table_cache_key)+1, + entry->real_name); + (*start_list)->in_use= entry->in_use ? 1 : 0; + (*start_list)->locked= entry->locked_by_name ? 1 : 0; + start_list= &(*start_list)->next; + *start_list=0; } - VOID(pthread_mutex_unlock(&LOCK_open)); - DBUG_RETURN(result); -} - -char* -query_table_status(THD *thd,const char *db,const char *table_name) -{ - int cached = 0, in_use = 0; - char info[256]; - - for (uint idx=0 ; idx < open_cache.records; idx++) - { - TABLE *entry=(TABLE*) hash_element(&open_cache,idx); - if (strcmp(entry->table_cache_key,db) || - strcmp(entry->real_name,table_name)) - continue; - - cached++; - if (entry->in_use) - in_use++; - } - - sprintf(info, "cached=%d, in_use=%d", cached, in_use); - return thd->strdup(info); + DBUG_RETURN(open_list); } @@ -195,10 +207,11 @@ query_table_status(THD *thd,const char *db,const char *table_name) bool send_fields(THD *thd,List<Item> &list,uint flag) { - List_iterator<Item> it(list); + List_iterator_fast<Item> it(list); Item *item; char buff[80]; - CONVERT *convert= (flag & 4) ? (CONVERT*) 0 : thd->convert_set; + CONVERT *convert= (flag & 4) ? (CONVERT*) 0 : thd->variables.convert_set; + DBUG_ENTER("send_fields"); String tmp((char*) buff,sizeof(buff)),*res,*packet= &thd->packet; @@ -259,11 +272,11 @@ send_fields(THD *thd,List<Item> &list,uint flag) if (my_net_write(&thd->net, (char*) packet->ptr(),packet->length())) break; /* purecov: inspected */ } - send_eof(&thd->net,(test_flags & TEST_MIT_THREAD) ? 0: 1); - return 0; + send_eof(&thd->net,1); + DBUG_RETURN(0); err: send_error(&thd->net,ER_OUT_OF_RESOURCES); /* purecov: inspected */ - return 1; /* purecov: inspected */ + DBUG_RETURN(1); /* purecov: inspected */ } @@ -293,6 +306,7 @@ void intern_close_table(TABLE *table) static void free_cache_entry(TABLE *table) { DBUG_ENTER("free_cache_entry"); + safe_mutex_assert_owner(&LOCK_open); intern_close_table(table); if (!table->in_use) @@ -314,6 +328,7 @@ static void free_cache_entry(TABLE *table) void free_io_cache(TABLE *table) { + DBUG_ENTER("free_io_cache"); if (table->io_cache) { close_cached_file(table->io_cache); @@ -325,6 +340,7 @@ void free_io_cache(TABLE *table) my_free((gptr) table->record_pointers,MYF(0)); table->record_pointers=0; } + DBUG_VOID_RETURN; } /* Close all tables which aren't in use by any thread */ @@ -437,6 +453,7 @@ void close_thread_tables(THD *thd, bool locked) /* VOID(pthread_sigmask(SIG_SETMASK,&thd->block_signals,NULL)); */ if (!locked) VOID(pthread_mutex_lock(&LOCK_open)); + safe_mutex_assert_owner(&LOCK_open); DBUG_PRINT("info", ("thd->open_tables=%p", thd->open_tables)); @@ -525,7 +542,7 @@ void close_temporary_tables(THD *thd) const uint init_query_buf_size = 11; // "drop table " uint query_buf_size; bool found_user_tables = 0; - + LINT_INIT(end); query_buf_size = init_query_buf_size; @@ -562,13 +579,10 @@ void close_temporary_tables(THD *thd) } if (query && found_user_tables && mysql_bin_log.is_open()) { - uint save_query_len = thd->query_length; - *--end = 0; // Remove last ',' - thd->query_length = (uint)(end-query); - Query_log_event qinfo(thd, query); + /* The -1 is to remove last ',' */ + Query_log_event qinfo(thd, query, (ulong)(end-query)-1); qinfo.error_code=0; mysql_bin_log.write(&qinfo); - thd->query_length = save_query_len; } thd->temporary_tables=0; } @@ -603,7 +617,7 @@ bool close_temporary_table(THD *thd, const char *db, const char *table_name) table= *prev; *prev= table->next; close_temporary(table); - if(thd->slave_thread) + if (thd->slave_thread) --slave_open_temp_tables; return 0; } @@ -626,8 +640,6 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *db, } - - /* move table first in unused links */ static void relink_unused(TABLE *table) @@ -683,11 +695,13 @@ TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find) /* When we call the following function we must have a lock on - LOCK_OPEN ; This lock will be unlocked on return. + LOCK_open ; This lock will be unlocked on return. */ void wait_for_refresh(THD *thd) { + safe_mutex_assert_owner(&LOCK_open); + /* Wait until the current table is up to date */ const char *proc_info; thd->mysys_var->current_mutex= &LOCK_open; @@ -705,13 +719,14 @@ void wait_for_refresh(THD *thd) pthread_mutex_unlock(&thd->mysys_var->mutex); } + TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) { DBUG_ENTER("reopen_name_locked_table"); if (thd->killed) DBUG_RETURN(0); TABLE* table; - if(!(table = table_list->table)) + if (!(table = table_list->table)) DBUG_RETURN(0); char* db = thd->db ? thd->db : table_list->db; @@ -724,11 +739,11 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) if (open_unireg_entry(thd, table, db, table_name, table_name) || !(table->table_cache_key =memdup_root(&table->mem_root,(char*) key, key_length))) - { - closefrm(table); - pthread_mutex_unlock(&LOCK_open); - DBUG_RETURN(0); - } + { + closefrm(table); + pthread_mutex_unlock(&LOCK_open); + DBUG_RETURN(0); + } table->key_length=key_length; table->version=0; @@ -743,7 +758,8 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) table->const_table=0; table->outer_join=table->null_row=table->maybe_null=0; table->status=STATUS_NO_RECORD; - table->keys_in_use_for_query=table->used_keys= table->keys_in_use; + table->keys_in_use_for_query= table->keys_in_use; + table->used_keys= table->keys_for_keyread; DBUG_RETURN(table); } @@ -861,25 +877,6 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, !(table->table_cache_key=memdup_root(&table->mem_root,(char*) key, key_length))) { - MEM_ROOT* glob_alloc; - LINT_INIT(glob_alloc); - - if (errno == ENOENT && - (glob_alloc = my_pthread_getspecific_ptr(MEM_ROOT*,THR_MALLOC))) - // Sasha: needed for replication - // remember the name of the non-existent table - // so we can try to download it from the master - { - int table_name_len = (uint) strlen(table_name); - int db_len = (uint) strlen(db); - thd->last_nx_db = alloc_root(glob_alloc,db_len + table_name_len + 2); - if(thd->last_nx_db) - { - thd->last_nx_table = thd->last_nx_db + db_len + 1; - memcpy(thd->last_nx_table, table_name, table_name_len + 1); - memcpy(thd->last_nx_db, db, db_len + 1); - } - } table->next=table->prev=table; free_cache_entry(table); VOID(pthread_mutex_unlock(&LOCK_open)); @@ -919,8 +916,9 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, table->const_table=0; table->outer_join=table->null_row=table->maybe_null=0; table->status=STATUS_NO_RECORD; - table->keys_in_use_for_query=table->used_keys= table->keys_in_use; - dbug_assert(table->key_read == 0); + table->keys_in_use_for_query= table->keys_in_use; + table->used_keys= table->keys_for_keyread; + DBUG_ASSERT(table->key_read == 0); DBUG_RETURN(table); } @@ -964,6 +962,7 @@ bool reopen_table(TABLE *table,bool locked) #endif if (!locked) VOID(pthread_mutex_lock(&LOCK_open)); + safe_mutex_assert_owner(&LOCK_open); if (open_unireg_entry(current_thd,&tmp,db,table_name,table->table_name)) goto end; @@ -984,7 +983,8 @@ bool reopen_table(TABLE *table,bool locked) tmp.null_row= table->null_row; tmp.maybe_null= table->maybe_null; tmp.status= table->status; - tmp.keys_in_use_for_query=tmp.used_keys=tmp.keys_in_use; + tmp.keys_in_use_for_query= tmp.keys_in_use; + tmp.used_keys= tmp.keys_for_keyread; /* Get state */ tmp.key_length= table->key_length; @@ -1053,6 +1053,8 @@ bool close_data_tables(THD *thd,const char *db, const char *table_name) bool reopen_tables(THD *thd,bool get_locks,bool in_refresh) { DBUG_ENTER("reopen_tables"); + safe_mutex_assert_owner(&LOCK_open); + if (!thd->open_tables) DBUG_RETURN(0); @@ -1287,6 +1289,8 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db, table_list.db=(char*) db; table_list.real_name=(char*) name; table_list.next=0; + safe_mutex_assert_owner(&LOCK_open); + if ((error=lock_table_name(thd,&table_list))) { if (error < 0) @@ -1331,7 +1335,6 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db, if (error) goto err; } - (void) entry->file->extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL DBUG_RETURN(0); err: DBUG_RETURN(1); @@ -1354,7 +1357,7 @@ int open_tables(THD *thd,TABLE_LIST *start) { if (!tables->table && !(tables->table=open_table(thd, - tables->db ? tables->db : thd->db, + tables->db, tables->real_name, tables->alias, &refresh))) { @@ -1411,8 +1414,8 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type) DBUG_ENTER("open_ltable"); thd->proc_info="Opening table"; - while (!(table=open_table(thd,table_list->db ? table_list->db : thd->db, - table_list->real_name, table_list->alias, + while (!(table=open_table(thd,table_list->db, + table_list->real_name,table_list->alias, &refresh)) && refresh) ; if (table) { @@ -1420,11 +1423,7 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type) #if defined( __WIN__) || defined(OS2) /* Win32 can't drop a file that is open */ - if (lock_type == TL_WRITE_ALLOW_READ -#ifdef HAVE_GEMINI_DB - && table->db_type != DB_TYPE_GEMINI -#endif /* HAVE_GEMINI_DB */ - ) + if (lock_type == TL_WRITE_ALLOW_READ) { lock_type= TL_WRITE; } @@ -1533,7 +1532,6 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db, DBUG_RETURN(0); } - tmp_table->file->extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL tmp_table->reginfo.lock_type=TL_WRITE; // Simulate locked tmp_table->tmp_table = (tmp_table->file->has_transactions() ? TRANSACTIONAL_TMP_TABLE : TMP_TABLE); @@ -1550,8 +1548,8 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db, { tmp_table->next=thd->temporary_tables; thd->temporary_tables=tmp_table; - if(thd->slave_thread) - ++slave_open_temp_tables; + if (thd->slave_thread) + slave_open_temp_tables++; } DBUG_RETURN(tmp_table); } @@ -1611,18 +1609,13 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, { field->query_id=thd->query_id; table->used_fields++; - if (field->part_of_key) - { - if (!(field->part_of_key & table->ref_primary_key)) - table->used_keys&=field->part_of_key; - } - else - table->used_keys=0; + table->used_keys&= field->part_of_key; } else thd->dupp_field=field; } - if (check_grants && !thd->master_access && check_grant_column(thd,table,name,length)) + if (check_grants && !thd->master_access && + check_grant_column(thd,table,name,length)) return WRONG_GRANT; return field; } @@ -1643,9 +1636,7 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) for (; tables ; tables=tables->next) { if (!strcmp(tables->alias,table_name) && - (!db || - (tables->db && !strcmp(db,tables->db)) || - (!tables->db && !strcmp(db,thd->db)))) + (!db || !strcmp(db,tables->db))) { found_table=1; Field *find=find_field_in_table(thd,tables->table,name,length, @@ -1688,7 +1679,8 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) for (; tables ; tables=tables->next) { Field *field=find_field_in_table(thd,tables->table,name,length, - grant_option && !thd->master_access, allow_rowid); + grant_option && + !thd->master_access, allow_rowid); if (field) { if (field == WRONG_GRANT) @@ -1769,14 +1761,15 @@ find_item_in_list(Item *find,List<Item> &items) ****************************************************************************/ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields, - bool set_query_id, List<Item> *sum_func_list) + bool set_query_id, List<Item> *sum_func_list, + bool allow_sum_func) { reg2 Item *item; List_iterator<Item> it(fields); DBUG_ENTER("setup_fields"); thd->set_query_id=set_query_id; - thd->allow_sum_func= test(sum_func_list); + thd->allow_sum_func= allow_sum_func; thd->where="field list"; while ((item=it++)) @@ -1784,15 +1777,26 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields, if (item->type() == Item::FIELD_ITEM && ((Item_field*) item)->field_name[0] == '*') { + uint elem=fields.elements; if (insert_fields(thd,tables,((Item_field*) item)->db_name, ((Item_field*) item)->table_name,&it)) DBUG_RETURN(-1); /* purecov: inspected */ + if (sum_func_list) + { + /* + sum_func_list is a list that has the fields list as a tail. + Because of this we have to update the element count also for this + list after expanding the '*' entry. + */ + sum_func_list->elements+= fields.elements - elem; + } } else { if (item->fix_fields(thd,tables)) DBUG_RETURN(-1); /* purecov: inspected */ - if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) + if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM && + sum_func_list) item->split_sum_func(*sum_func_list); thd->used_tables|=item->used_tables(); } @@ -1811,27 +1815,41 @@ bool setup_tables(TABLE_LIST *tables) { DBUG_ENTER("setup_tables"); uint tablenr=0; - for (TABLE_LIST *table=tables ; table ; table=table->next,tablenr++) - { - table->table->tablenr=tablenr; - table->table->map= (table_map) 1 << tablenr; - if ((table->table->outer_join=table->outer_join)) - table->table->maybe_null=1; // LEFT OUTER JOIN ... - if (table->use_index) + for (TABLE_LIST *table_list=tables ; table_list ; + table_list=table_list->next,tablenr++) + { + TABLE *table=table_list->table; + + table->used_fields=0; + table->const_table=0; + table->outer_join=table->null_row=0; + table->status=STATUS_NO_RECORD; + table->keys_in_use_for_query= table->keys_in_use; + table->used_keys= table->keys_for_keyread; + table->maybe_null=test(table->outer_join=table_list->outer_join); + table->tablenr=tablenr; + table->map= (table_map) 1 << tablenr; + if (table_list->use_index) { - key_map map= get_key_map_from_key_list(table->table, - table->use_index); + key_map map= get_key_map_from_key_list(table, + table_list->use_index); if (map == ~(key_map) 0) DBUG_RETURN(1); - table->table->keys_in_use_for_query=map; + table->keys_in_use_for_query=map; } - if (table->ignore_index) + if (table_list->ignore_index) { - key_map map= get_key_map_from_key_list(table->table, - table->ignore_index); + key_map map= get_key_map_from_key_list(table, + table_list->ignore_index); if (map == ~(key_map) 0) DBUG_RETURN(1); - table->table->keys_in_use_for_query &= ~map; + table->keys_in_use_for_query &= ~map; + } + if (table_list->shared) + { + /* Clear query_id that may have been set by previous select */ + for (Field **ptr=table->field ; *ptr ; ptr++) + (*ptr)->query_id=0; } } if (tablenr > MAX_TABLES) @@ -1847,7 +1865,7 @@ static key_map get_key_map_from_key_list(TABLE *table, List<String> *index_list) { key_map map=0; - List_iterator<String> it(*index_list); + List_iterator_fast<String> it(*index_list); String *name; uint pos; while ((name=it++)) @@ -1868,7 +1886,7 @@ static key_map get_key_map_from_key_list(TABLE *table, ** Returns pointer to last inserted field if ok ****************************************************************************/ -static bool +bool insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, const char *table_name, List_iterator<Item> *it) { @@ -1883,8 +1901,7 @@ insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, check_grant_all_columns(thd,SELECT_ACL,table) ) DBUG_RETURN(-1); if (!table_name || (!strcmp(table_name,tables->alias) && - (!db_name || !tables->db || - !strcmp(tables->db,db_name)))) + (!db_name || !strcmp(tables->db,db_name)))) { Field **ptr=table->field,*field; thd->used_tables|=table->map; @@ -1898,14 +1915,7 @@ insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, if (field->query_id == thd->query_id) thd->dupp_field=field; field->query_id=thd->query_id; - - if (field->part_of_key) - { - if (!(field->part_of_key & table->ref_primary_key)) - table->used_keys&=field->part_of_key; - } - else - table->used_keys=0; + table->used_keys&= field->part_of_key; } /* All fields are used */ table->used_fields=table->fields; @@ -1973,7 +1983,6 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) // TODO: This could be optimized to use hashed names if t2 had a hash for (j=0 ; j < t2->fields ; j++) { - key_map tmp_map; if (!my_strcasecmp(t1->field[i]->field_name, t2->field[j]->field_name)) { @@ -1986,20 +1995,8 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) /* Mark field used for table cache */ t1->field[i]->query_id=t2->field[j]->query_id=thd->query_id; cond_and->list.push_back(tmp); - if ((tmp_map=t1->field[i]->part_of_key)) - { - if (!(tmp_map & t1->ref_primary_key)) - t1->used_keys&=tmp_map; - } - else - t1->used_keys=0; - if ((tmp_map=t2->field[j]->part_of_key)) - { - if (!(tmp_map & t2->ref_primary_key)) - t2->used_keys&=tmp_map; - } - else - t2->used_keys=0; + t1->used_keys&= t1->field[i]->part_of_key; + t2->used_keys&= t2->field[j]->part_of_key; break; } } @@ -2027,7 +2024,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) int fill_record(List<Item> &fields,List<Item> &values) { - List_iterator<Item> f(fields),v(values); + List_iterator_fast<Item> f(fields),v(values); Item *value; Item_field *field; DBUG_ENTER("fill_record"); @@ -2045,7 +2042,7 @@ fill_record(List<Item> &fields,List<Item> &values) int fill_record(Field **ptr,List<Item> &values) { - List_iterator<Item> v(values); + List_iterator_fast<Item> v(values); Item *value; DBUG_ENTER("fill_record"); @@ -2108,7 +2105,8 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys) create_info.db_type=DB_TYPE_DEFAULT; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name, &create_info, table_list, - fields, keys, drop, alter, (ORDER*)0, FALSE, DUP_ERROR)); + fields, keys, drop, alter, (ORDER*)0, FALSE, + DUP_ERROR)); } @@ -2123,7 +2121,8 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop) create_info.db_type=DB_TYPE_DEFAULT; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name, &create_info, table_list, - fields, keys, drop, alter, (ORDER*)0, FALSE, DUP_ERROR)); + fields, keys, drop, alter, (ORDER*)0, FALSE, + DUP_ERROR)); } /***************************************************************************** @@ -2188,7 +2187,10 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, THD *in_use; table->version=0L; /* Free when thread is ready */ if (!(in_use=table->in_use)) + { + DBUG_PRINT("info",("Table was not in use")); relink_unused(table); + } else if (in_use != thd) { in_use->some_tables_deleted=1; @@ -2218,8 +2220,8 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, int setup_ftfuncs(THD *thd) { - List_iterator<Item_func_match> li(thd->lex.ftfunc_list), - lj(thd->lex.ftfunc_list); + List_iterator<Item_func_match> li(thd->lex.select->ftfunc_list), + lj(thd->lex.select->ftfunc_list); Item_func_match *ftf, *ftf2; while ((ftf=li++)) @@ -2240,9 +2242,9 @@ int setup_ftfuncs(THD *thd) int init_ftfuncs(THD *thd, bool no_order) { - if (thd->lex.ftfunc_list.elements) + if (thd->lex.select->ftfunc_list.elements) { - List_iterator<Item_func_match> li(thd->lex.ftfunc_list); + List_iterator<Item_func_match> li(thd->lex.select->ftfunc_list); Item_func_match *ifm; DBUG_PRINT("info",("Performing FULLTEXT search")); thd->proc_info="FULLTEXT initialization"; |