next up previous contents
Next: Adding constraints Up: Getting Started Previous: Manipulating objects using OQL   Contents


Adding indexes

To introduce the necessity of indexes, we propose to perform the following operations:
? for (x in 1 <= 2000) Person(firstname : "xx" + string(x));
? select Person.firstname = "xx20";
= bag(2628.2.201654:oid)
? select Person.firstname = "xx10";
= bag(2608.2.642448:oid)
The first operation creates 2000 person instances: as you can notice, this operation takes only a few seconds on a reasonnable computer.

The two last operations query person instance according to their firstname attribute.

As you can notice, these query operations take a while: about 3 seconds for each operation on a ULTRA Sparc: of course, this is too much.

A good idea is to affect an index on the attributes - for instance firstname, lastname and age - for which one wants to perform efficient query.

This is very simple:

  1. add index specification to the class Personedit within the person.odl file as follows:
    class Person {
      string firstname;
      char lastname;
      int age;
      Address addr;
      ...
      set<Person *> children;
    
      index on firstname;
      index on lastname;
      index on age;
    };
    
  2. then, use the eyedbodl tool to update the database schema:
    % eyedbodl -U bill -P {bill password, i.e. 'thekid'} -d foo -u --package=person person.odl
    Updating 'person' schema in database foo...
    Creating [NULL] hashindex 'index<type = hash, propagate = on> on Person.firstname' on class 'Person'...
    Creating [NULL] hashindex 'index<type = hash, propagate = on> on Person.lastname' on class 'Person'...
    Creating [NULL] btreeindex 'index<type = btree, propagate = on> on Person.age' on class 'Person'...
    
    Done
    
Now, you can try again to query Person instances according to its firstname, lastname or age:
% eyedboql -U bill -P thekid -d foo -w
? select Person.firstname = "xx20";
= bag(2628.2.201654:oid)
? select Person.firstname = "xx10";
= bag(2608.2.642448:oid)
and you will notice that these operations are immediate.



EyeDB manual