List:Internals« Previous MessageNext Message »
From:AugustQ Date:April 24 2013 4:13pm
Subject:Re: adding an index of my own type/code
View as plain text  
Hi to everyone,

and thanks for all your comments.

It looks like I have 2 possibilities:
#1: I modify the source-code of MySQL. It seems like sql_yacc.cc is a
godd place because here HA_KEY_ALG_HASH and others are used.

#2: I do not modify the source-code but use a given word instead.
This means: instead of 
    type  AQTREE;
in my CREATE-stmt I use
    type HASH;
so MySQL checks against a list of given keywords, accepts this statement
and sends it to the storage-engine. Then the storage-engine has to
handle this correctly. In my case it sends it to the create()-function:
    create(const char *name, TABLE *form, HA_CREATE_INFO *info)

where I can find it in:
    form->key_info[i]->algorithm 

which contains an entry of the enum of type ha_key_alg (defined in
my_base.h). In my given example it contains HA_KEY_ALG_HASH.

OK, it is a bit dirty to use the HASH-keyword but I can live with this
approach. 

This behaviour of MySQL explains this hint from the description of the
CREATE-stmt:
>>If you specify an index type that is not valid for a given storage
engine, but there is another index type available that the engine can
use without affecting query results, the engine uses the available
type.<<
To me this looks like: when I use MyISAM as the type of a table and in
my CREATE INDEX-stmt I specify HASH as the index-type then the storage
engine will create an index of type BTREE without any notice. 

Thanks for your help
AugustQ

PS: I've checked it: I created an index of type HASH on a MyISAM-table.
SHOW INDEX shows this BTREE.
 

Am Mittwoch, den 24.04.2013, 07:37 -0700 schrieb Sergei Golubchik:
> Hi, AugustQ!
> 
> On Apr 24, AugustQ wrote:
> > Hi,
> > 
> > and thanks for your hints.
> > 
> > Here is what I did: I created a tiny storage engine which inherits its
> > functionality from MyIsam. I can load this code and so I created a table
> > with this type of storage engine.
> > 
> > Next I wanted to see what my storage engine can do if I add an index to
> > this table. 
> > 
> > If I create an index without specifying an index-type everything works.
> > In the ::create(()-function I see the columns that describe the index.
> > 
> > When I create an index using an index-engine-type by giving the keyword
> > engine or type or using in the CREATE-stmt, it works when I use one of
> > the keywords given in the description like BTREE or HASH. But when I
> > create an index using my own keyword then I got immediately the syntax
> > error.
> > 
> > In my example I used the word AQTREE for the description of the
> > index-engine. I wanted to see at the storage-engine-level, what
> > information was given to my code but this storage engine (my code) was
> > never called.
> > 
> > What I expected: MySQL offers the choice of adding another storage
> > engine without modifying the source code of MySQL itself. So I assumed
> > that this would include the creating and handling of an index.
> > 
> > Is this possible?
> 
> No, it is not possible. Index types are hard-coded in the parser and
> only BTREE, RTEEE, and HASH are allowed.
> 
> Regards,
> Sergei
> 


Thread
adding an index of my own type/codeAugustQ23 Apr
  • Re: adding an index of my own type/codeStewart Smith23 Apr
    • Re: adding an index of my own type/codeAugustQ24 Apr
      • Re: adding an index of my own type/codeThomas Jones-Low24 Apr
      • Re: adding an index of my own type/codeSergei Golubchik24 Apr
        • Re: adding an index of my own type/codeAugustQ24 Apr