MySQL Lists are EOL. Please join:

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

On Jul 17, Timothy P Clark wrote:
> 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:
> > > > >
> > > > > 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)))].

> > 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 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().

You can simply do

  if (key.key_part[x].field !=
      key.key_part[x].field->table->field[key.key_part[x].fieldnr-1])

and that will cover blobs and field->key_length() and everything else
that may be relevant :)
 
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