MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Timothy P Clark Date:July 17 2009 3:09pm
Subject:Re: Identifying prefix keys during index creation
View as plain text  
Hi Sergei,

Thanks for your help!

Sergei Golubchik <serg@stripped> wrote on 07/17/2009 01:12:07 AM:
> On Jul 16, Timothy P Clark wrote:
> > > On Jul 08, Timothy P Clark wrote:
> > > > This one has been plaguing me for a while, and I'm hoping someone
> > > > can help...
> > > > 
> > > > What I'm trying to do in my storage engine is determine when
> > > > creating an index whether it is a prefix key [e.g. CREATE TABLE t1
> > > > (c char(10), index(c(5)))]. I do this for a given key by comparing 

> > > > key.key_part[x].length to 
> > > > key.key_part[x].field->table->field[key.key_part[x].fieldnr-1]
> > > ->max_display_length(). 
> > > 
> > > do you mean that
> > > 
> > >  key.key_part[x].field !=
> > >  key.key_part[x].field->table->field[key.key_part[x].fieldnr-1]
> > > 
> > > ?
> > Yes, when prefix keys are involved. That is why I cannot simply 
compare 
> > if (key.key_part[x].length == 
key.key_part[x].field->max_display_length())
> 
> Hmm, indeed. In open_table_from_share() I found
> 
> 1913         if (field->key_length() != key_part->length &&
> 1914             !(field->flags & BLOB_FLAG))
> 1915         {
> 1916           /*
> 1917             We are using only a prefix of the column as a key:
> 1918             Create a new field for the key part that matches the 
index
> 1919           */
> 1920           field= 
key_part->field=field->new_field(&outparam->mem_root,
> 1921                                                   outparam, 0);
> 1922           field->field_length= key_part->length;
> 1923         }
> 
> but if you'd use table->s->key_info and table->s->field instead of
> table->key_info and table->field, in the table share you'd have
> key.key_part[x].field always pointing to the actual field.
That appears to work once the table is opened and also in create() (using 
table_arg->s). However, I don't believe that the key information in the 
share has been updated at the time add_index() is called in the case of 
online alters. I think I still need my original code in order to have a 
general solution that will work in all circumstances.
 
> But the way, the excerpt above shows also that you need to compare with
> field->key_length(), not with max_display_length().
OK, I will change to use this, though it looks like I'll also need to be 
aware of the BLOB_FLAG. I didn't need to know if it was a blob when using 
max_display_length().

> 
> Regards / Mit vielen Grüßen,
> Sergei
> 
> -- 
>    __  ___     ___ ____  __
>   /  |/  /_ __/ __/ __ \/ /   Sergei Golubchik <serg@stripped>
>  / /|_/ / // /\ \/ /_/ / /__  Principal Software Engineer/Server 
Architect
> /_/  /_/\_, /___/\___\_\___/  Sun Microsystems GmbH, HRB München 161028
>        <___/                  Sonnenallee 1, 85551 Kirchheim-Heimstetten
> Geschäftsführer: Thomas Schroeder, Wolfgang Engels, Wolf Frenkel
> Vorsitzender des Aufsichtsrates: Martin Häring

Thread
Identifying prefix keys during index creationTimothy P Clark8 Jul
  • Re: Identifying prefix keys during index creationSergei Golubchik16 Jul
    • Re: Identifying prefix keys during index creationTimothy P Clark16 Jul
      • Re: Identifying prefix keys during index creationSergei Golubchik17 Jul
        • Re: Identifying prefix keys during index creationTimothy P Clark18 Jul
          • Re: Identifying prefix keys during index creationSergei Golubchik18 Jul
Re: Identifying prefix keys during index creationTimothy P Clark17 Jul