List:Internals« Previous MessageNext Message »
From:Timothy P Clark Date:July 8 2009 8:45pm
Subject:Identifying prefix keys during index creation
View as plain text  
This one has been plaguing me for a while, and I'm hoping someone can 

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 

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 
Second, is there a reason that fieldnr is different between these two 
functions, or is that just an oversight that needs to coded around?

Thank you,
Tim Clark

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