List:Internals« Previous MessageNext Message »
From:Sanja Byelkin Date:April 18 2006 7:34am
Subject:Re: getting table meta data (primary key, in this case)
View as plain text  
Hi!

On 15 Apr 2006, at 19:03, Eric Prud'hommeaux wrote:
[skip]
> worky (and quite easily)!!! Thank you SO much for the pointer!
>
> [[
> bool Item_variable::fix_fields(THD *thd, Item **reference) {
>   if (primary_key)
>     field_name = get_primary_key();
>   return Item_field::fix_fields(thd, reference);
> }
>
> const char* sparqlFrob::get_primary_key(const char *table_name) {
>   TABLE_LIST *entry = thd->main_lex.select_lex.context.table_list;
>   while (entry) {
>     if (!strcmp(table_name, entry->table_name)) {
>       KEY *key = entry->table->key_info;

in above statement you have to be sure that 'entry' is not VIEW of  
several tables with MERGE algorithm,
so you better check entry->table, also above have not much sense  
(now, in future things may change) for VIEW with TEMPTABLE algorithm,  
but it will not crash at least.


>       for (unsigned i = 0; i < entry->table->s->keys; i++) { //  
> from sql_show.cc::2905 get_schema_stat_record
> 	if (!strcmp(key[i].name, "PRIMARY")) {
> 	  assert(key[i].key_parts == 1);
> 	  return key[i].key_part->field->field_name;
> 	}
>       }
>       assert(0); // couldn't find PRIMARY KEY
>     }
>     entry = entry->next_global;
>   }
>   assert(0); // couldn't find table
> }
> ]]
> It brings up 2 questions:
>
>   Is there a way to kill a thread ('cause something went horribly
>   wrong), without killing the whole server? What's the polite way to
>   assert(0)?

set thd->kill and check it? (I am not sure)

>
>   Is there a better way to find the table_list for a thread? I feel
>   like thd->main_lex.select_lex.context.table_list should really
>   include some inode numbers, the process id and maybe some astrology.

Do you really need all query (thread) tables? Or just tables of  
current SELECT?

For global table list you can check thd->main_lex.query_tables and  
move by TABLE_LIST::next_global. This list will not contain  
underlying view tables until table opened. Also it do not contain  
procedure tables (in lock operation it contain some placeholders for  
them).

if you need SELECT list of tables there is several lists:
   - list of tables mentioned in the FROM clause (do not include view  
underlying tables)
   - tree of join structure
   - list of leaf tables of join tree (build in setup_tables())  
(looks like you need this one, if you need SELECT list of tables)

-- 
     __  ___     ___ ____  __
    /  |/  /_ __/ __/ __ \/ /    Mr. Oleksandr Byelkin <sanja@stripped>
   / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Full-Time Developer
  /_/  /_/\_, /___/\___\_\___/   Lugansk, Ukraine
         <___/   www.mysql.com


Thread
getting table meta data (primary key, in this case)Eric Prud'hommeaux1 Apr
  • Re: getting table meta data (primary key, in this case)SGreen3 Apr
    • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux3 Apr
      • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux5 Apr
        • RE: getting table meta data (primary key, in this case)Rick James5 Apr
          • RE: getting table meta data (primary key, in this case)Stewart Smith6 Apr
          • RE: getting table meta data (primary key, in this case)Stewart Smith6 Apr
        • Re: getting table meta data (primary key, in this case)Sergei Golubchik6 Apr
          • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux6 Apr
            • Re: getting table meta data (primary key, in this case)Sergei Golubchik10 Apr
              • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux15 Apr
                • Re: getting table meta data (primary key, in this case)Sergei Golubchik18 Apr
                • Re: getting table meta data (primary key, in this case)Sanja Byelkin18 Apr
  • Re: getting table meta data (primary key, in this case)Sergei Golubchik3 Apr
Re: getting table meta data (primary key, in this case)Sergei Golubchik10 Apr
  • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux10 Apr
    • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux11 Apr