MySQL Lists are EOL. Please join:

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

Sergei Golubchik <serg@stripped> wrote on 07/17/2009 10:52:43 AM:
> 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 :)
OK, I can do that. I had considered it earlier, but I didn't know whether 
that was completely reliable (i.e. might generate false positives.) 
Perhaps a HA_PREFIX value could be added to KEY_PART_INFO::key_part_flag 
in the future to eliminate the need for these kinds of calculations?

Thanks,
Tim
 

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