diff options
Diffstat (limited to 'sql/sql_help.cc')
-rw-r--r-- | sql/sql_help.cc | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/sql/sql_help.cc b/sql/sql_help.cc index 6036a687274..f51ad318568 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -93,6 +93,11 @@ static bool init_fields(THD *thd, TABLE_LIST *tables, 0, REPORT_ALL_ERRORS, 1, TRUE))) DBUG_RETURN(1); + bitmap_set_bit(find_fields->field->table->read_set, + find_fields->field->field_index); + /* To make life easier when setting values in keys */ + bitmap_set_bit(find_fields->field->table->write_set, + find_fields->field->field_index); } DBUG_RETURN(0); } @@ -267,11 +272,10 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, List<String> *names, String *name, String *description, String *example) { - char buff[8]; // Max int length + uchar buff[8]; // Max int length int count= 0; int iindex_topic, iindex_relations; Field *rtopic_id, *rkey_id; - DBUG_ENTER("get_topics_for_keyword"); if ((iindex_topic= find_type((char*) primary_key_name, @@ -285,27 +289,27 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, rtopic_id= find_fields[help_relation_help_topic_id].field; rkey_id= find_fields[help_relation_help_keyword_id].field; - topics->file->ha_index_init(iindex_topic); - relations->file->ha_index_init(iindex_relations); + topics->file->ha_index_init(iindex_topic,1); + relations->file->ha_index_init(iindex_relations,1); rkey_id->store((longlong) key_id, TRUE); rkey_id->get_key_image(buff, rkey_id->pack_length(), Field::itRAW); - int key_res= relations->file->index_read(relations->record[0], - (byte *)buff, rkey_id->pack_length(), - HA_READ_KEY_EXACT); + int key_res= relations->file->index_read_map(relations->record[0], + buff, (key_part_map) 1, + HA_READ_KEY_EXACT); for ( ; !key_res && key_id == (int16) rkey_id->val_int() ; key_res= relations->file->index_next(relations->record[0])) { - char topic_id_buff[8]; + uchar topic_id_buff[8]; longlong topic_id= rtopic_id->val_int(); Field *field= find_fields[help_topic_help_topic_id].field; field->store((longlong) topic_id, TRUE); field->get_key_image(topic_id_buff, field->pack_length(), Field::itRAW); - if (!topics->file->index_read(topics->record[0], (byte *)topic_id_buff, - field->pack_length(), HA_READ_KEY_EXACT)) + if (!topics->file->index_read_map(topics->record[0], topic_id_buff, + (key_part_map)1, HA_READ_KEY_EXACT)) { memorize_variant_topic(thd,topics,count,find_fields, names,name,description,example); @@ -562,7 +566,7 @@ SQL_SELECT *prepare_simple_select(THD *thd, Item *cond, cond->fix_fields(thd, &cond); // can never fail /* Assume that no indexes cover all required fields */ - table->used_keys.clear_all(); + table->covering_keys.clear_all(); SQL_SELECT *res= make_select(table, 0, 0, cond, 0, error); if (*error || (res && res->check_quick(thd, 0, HA_POS_ERROR)) || @@ -633,7 +637,7 @@ bool mysqld_help(THD *thd, const char *mask) MEM_ROOT *mem_root= thd->mem_root; DBUG_ENTER("mysqld_help"); - bzero((gptr)tables,sizeof(tables)); + bzero((uchar*)tables,sizeof(tables)); tables[0].alias= tables[0].table_name= (char*) "help_topic"; tables[0].lock_type= TL_READ; tables[0].next_global= tables[0].next_local= @@ -650,17 +654,20 @@ bool mysqld_help(THD *thd, const char *mask) 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 tables do not contain VIEWs => we can pass 0 as conds */ - thd->lex->select_lex.context.table_list= + thd->lex->select_lex.context.table_list= thd->lex->select_lex.context.first_name_resolution_table= &tables[0]; - setup_tables(thd, &thd->lex->select_lex.context, - &thd->lex->select_lex.top_join_list, - tables, 0, &leaves, FALSE); + if (setup_tables(thd, &thd->lex->select_lex.context, + &thd->lex->select_lex.top_join_list, + tables, &leaves, FALSE)) + goto error; memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields)); if (init_fields(thd, tables, used_fields, array_elements(used_fields))) goto error; @@ -682,10 +689,12 @@ bool mysqld_help(THD *thd, const char *mask) int key_id; if (!(select= prepare_select_for_name(thd,mask,mlen,tables,tables[3].table, - used_fields[help_keyword_name].field,&error))) + used_fields[help_keyword_name].field, + &error))) goto error; - count_topics=search_keyword(thd,tables[3].table,used_fields,select,&key_id); + count_topics= search_keyword(thd,tables[3].table, used_fields, select, + &key_id); delete select; count_topics= (count_topics != 1) ? 0 : get_topics_for_keyword(thd,tables[0].table,tables[2].table, @@ -699,7 +708,8 @@ bool mysqld_help(THD *thd, const char *mask) Field *cat_cat_id= used_fields[help_category_parent_category_id].field; if (!(select= prepare_select_for_name(thd,mask,mlen,tables,tables[1].table, - used_fields[help_category_name].field,&error))) + used_fields[help_category_name].field, + &error))) goto error; count_categories= search_categories(thd, tables[1].table, used_fields, @@ -769,10 +779,15 @@ bool mysqld_help(THD *thd, const char *mask) if (send_variant_2_list(mem_root,protocol, &categories_list, "Y", 0)) goto error; } - send_eof(thd); + my_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); } |