MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Sergei Golubchik Date:July 17 2009 6:12am
Subject:Re: Identifying prefix keys during index creation
View as plain text  
Hi, Tim!

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.

But the way, the excerpt above shows also that you need to compare with
field->key_length(), not with 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