MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Sergei Golubchik Date:July 16 2009 9:53am
Subject:Re: Identifying prefix keys during index creation
View as plain text  
Hi, Timothy!

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 !=


> If those values are different, I assume that the key is a prefix key.
> I want to be able to use the same code both for indexes created along
> with the table (through handler::create()) and by online ALTER
> (through handler::add_index()). The problem is that the key_part
> structure appears to be constructed slightly differently depending on
> whether it is coming through handler::create() or through
> handler::add_index(). Significantly, fieldnr appears to be one-based
> through create() and zero-based through add_index(). Obviously this
> difference complicates the construction of a general test for prefix
> keys.
> In other words, for
> CREATE TABLE t1 (c char(10), index(c(5)))
> in handler::create(), table_arg->key_info[0].key_part[0].fieldnr = 1.
> But for 
> CREATE TABLE t1 (c char(10));
> in handler::add_index(), key->key_info[0].key_part[0].fieldnr = 0.
> First, is my method for identifying prefix keys otherwise correct? I
> haven't found a more straightforward way, but maybe there's something
> simpler?
> Second, is there a reason that fieldnr is different between these two
> functions, or is that just an oversight that needs to coded around?

I don't see a reason fot this discrepancy.
Looks like an oversight. Feel free to report it as a bug.
Regards / Mit vielen Grüßen,

   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /   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
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