Managing indexes

As a relational database management system does, EyeDB provides indexes to improve drastically the time needed to retrieve an objet in a database and to improve therefore the performances of queries.

EyeDB supports two types of indexes, hash and b-trees.

As the description of indexes management needs that the database has a schema, the ODL database schema given in Example 6.2, “The ODL database schema” will be used in the index administration commands examples.

Example 6.2. The ODL database schema

class Address {
  attribute int number;
  attribute string street;
  attribute string town;
  attribute int code;
};

class Person {
  attribute string firstName;
  attribute string lastName;
  attribute int age;
  attribute Address addr;
};

Example 6.3. Indexes: updating the schema

eyedbadmin database create test_index
eyedbodl -u -d test_index test_index.odl
Updating 'test' schema in database test...
Adding class Address
Adding class Person

Done
	

Creating and deleting indexes

Creating an index is done using the eyedbadmin command:

eyedbadmin
index create [options] {database} {attribute_path} [hints]

Options are:

  • --propagate=[ on | off ]

    propagation mode

    --type=type

    index type (supported types are: hash, btree)

Command arguments are:

  • {database}

    the database

  • {attribute_path}

    the path of the attribute on which the index is to be created

  • {hints}

    index hints, i.e. index configuration values that are implementation specific

An attribute path is an expression built using the . (dot) operator and class names or attribute names.

Example 6.4. Examples of attribute paths

Person.firstName
Person.age
Address.number
Person.addr.town

Example 6.5. eyedbadmin index create

eyedbadmin index create test_index Person.age
Creating btree index on Person.age
eyedbadmin index create test_index Person.addr.town
Creating hash index on Person.addr.town
eyedbadmin index create test_index Person.addr.number
Creating btree index on Person.addr.number
eyedbadmin index create --type=hash test_index Person.addr.code
Creating hash index on Person.addr.code
	  

Deleting an index is done using the eyedbadmin command:

eyedbadmin
index delete {database} {attribute_path}

Command arguments are:

  • {database}

    the database

  • {attribute_path}

    the path of the attribute on which the index is to be created

Example 6.6. eyedbadmin index delete

eyedbadmin index delete test_index Person.addr.number
Deleting index Person.addr.number
eyedbadmin index delete test_index Person.addr.street
eyedbadmin: index 'Person.addr.street' not found
	  

Listing, updating and moving indexes

Listing indexes is done using the eyedbadmin command:

eyedbadmin
index list [options] {database} [[{attribute_path} | {class_name}]]

Command arguments are:

  • {database}

    the database

  • [[{attribute_path} | {class_name}]]

    the index to be listed, specified either as an attribute path or as a class name

Example 6.7. eyedbadmin index list

eyedbadmin index list test_index
btree index on Person.age
hash index on Person.addr.town
hash index on Person.addr.code
eyedbadmin index list test_index Person
btree index on Person.age
hash index on Person.addr.town
hash index on Person.addr.code
eyedbadmin index list test_index Person.age
btree index on Person.age
	  

Getting statistics on indexes

Getting statistics on indexes is done using the eyedbadmin command:

eyedbadmin
index stats [options] {database} [[{attribute_path} | {class_name}]]

Command arguments are:

  • {database}

    the database

  • [[{attribute_path} | {class_name}]]

    the index on which to print statistics, specified either as an attribute path or as a class name

Options are:

  • --full

    displays all index entries statistics

  • --format=format

    statistics format; format is a printf-like string where:

    • %n denotes the number of keys

    • %O denotes the count of object entries for this key

    • %o denotes the count of hash objects for this key

    • %s denotes the size of hash objects for this key

    • %b denotes the busy size of hash objects for this key

    • %f denotes the free size of hash objects for this key

Example 6.8. eyedbadmin index statistics

eyedbadmin index stats --full test_index
    Total hash object count: 1
    Total hash object size: 98376B, ~96KB
    Total hash object busy size: 0B
    Total hash object free size: 98376B, ~96KB
    Busy entry count: 0
    Free entry count: 4096
...
eyedbadmin index stats '--format=%n %O\n' test_index Person.addr.code
4090 0
4091 0
4092 0
4093 0
4094 0
4095 0
...
eyedbadmin index stats '--format=%n -> %O, %o, %s\n' test_index Person.addr.town
4090 -> 0, 0, 0
4091 -> 0, 0, 0
4092 -> 0, 0, 0
4093 -> 0, 0, 0
4094 -> 0, 0, 0
4095 -> 0, 0, 0
...
	  

Getting and setting index default dataspace

An index has a default dataspace (see Chapter 5, Database advanced administration). This default dataspace determines in which dataspace index data will be inserted when index is updated, for instance when objects are inserted into the database.

Getting index default dataspace is done using command eyedbadmin index getdefdsp:

eyedbadmin index getdefdsp {database} {[{attribute_path} | {class_name}]}

Command arguments are:

  • {database}

    the database

  • [[{attribute_path} | {class_name}]]

    the index on which to print statistics, specified either as an attribute path or as a class name

Setting index default dataspace is done using command eyedbadmin index setdefdsp:

eyedbadmin index setdefdsp {database} [[{attribute_path} | {class_name}]] {dataspace}

Command arguments are:

  • {database}

    the database

  • [[{attribute_path} | {class_name}]]

    the index on which to print statistics, specified either as an attribute path or as a class name

  • {dataspace}

    the name of the dataspace to be created

Example 6.9. eyedbadmin index getdefdsp/setdefdsp

# get default dataspace for index on Person.age
eyedbadmin index getdefdsp test_index Person.age
Default dataspace for index 'Person.age':
  Dataspace #0 (default)
   Name DEFAULT
   Composed of {
     Datafile #0
       Name DEFAULT
       File test_index.dat
   }
# create a datafile
eyedbadmin datafile create --name=DAT1 test_index test_index_data1.dat
# create a dataspace containing this file
eyedbadmin dataspace create test_index DSP1 DAT1
# set default dataspace for index on Person.age
eyedbadmin index setdefdsp test_index Person.age DSP1
# get default dataspace for index on Person.age
eyedbadmin index getdefdsp test_index Person.age
Default dataspace for index 'Person.age':
  Dataspace #1
   Name DSP1
   Composed of {
     Datafile #1
       Name DAT1
       File test_index_data1.dat
   }