Subsections


Updating the database schema

Once created, a database schema can be updated, to add or remove attributes, add or remove classes or schema, add indexes or contraints.


Adding indexes

To introduce the necessity of indexes, we propose to perform the following operations:
? for (x in 1 <= 50000) new Person(firstname : "xx" + string(x));
? select Person.firstname = "xx20";
= bag(23336.2.420154:oid)
? select Person.firstname = "xx10";
= bag(23316.2.824639:oid)
The first operation creates 50000 person instances: as you can notice, this operation takes a few seconds. The two last operations query person instance according to their firstname attribute. These operations also take a few seconds to perform and take a significant amount of CPU.

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: Now, you can try again to query Person instances according to its firstname, lastname or age:
% eyedboql -d foo -w
? select Person.firstname = "xx20";
= bag(23336.2.420154:oid)
? select Person.firstname = "xx10";
= bag(23316.2.824639:oid)
and you will notice that these operations are immediate.


Adding constraints

In the same way, you can add a notnull and an unique constraint on the lastname attribute within the class Person:

Now try to create two person instances with the same lastname attribute:
% eyedboql -d foo -w
? new Person(lastname : "curtis");
= 79902.2.884935:oid
? new Person(lastname : "curtis");
near line 2: 'new Person(lastname : "curtis")' => oql error: new operator 'new<oql$db> Person(lastname:"curtis"); ' : unique[] constraint error: attribute path 'Person.lastname'.
or with no lastname attribute:
? new Person();
near line 3: 'new Person()' => oql error: new operator 'new<oql$db> Person(); ' : notnull[] constraint error: attribute path 'Person.lastname'.


Removing classes and schema

It is possible to remove a class in a schema using eyedbodl. For instance, to remove the class Employee in the already introduced schema:

% eyedbodl -d foo -u --rmcls=Employee
Updating 'UNTITLED' schema in database foo...
Removing class Employee

Done
You can then check the class removal by:
% eyedbodl -d foo --gencode=ODL

//
// EyeDB Version 2.8.4 Copyright (c) 1995-2007 SYSRA
//
// UNTITLED Schema
//
// Generated by eyedbodl at Mon Dec 10 13:44:03 CET 2007
//

class Address (implementation <hash, hints = "key_count = 2048;">) {
        attribute int32 num;
        attribute string street;
        attribute string town;
        attribute string country;
};

class Person (implementation <hash, hints = "key_count = 2048;">) {
        attribute string firstname;
        attribute string lastname;
        attribute int32 age;
        attribute Address addr;
        relationship Person* spouse inverse Person::spouse;
        attribute set<Person*> children;

        index<type = hash, hints = "key_count = 4096; initial_size = 4096; extend_coef = 1; size_max = 4096;", propagate = on> on Person.firstname;
        index<type = hash, hints = "key_count = 4096; initial_size = 4096; extend_coef = 1; size_max = 4096;", propagate = on> on Person.lastname;
        constraint<unique, propagate = on> on Person.lastname;
        constraint<notnull, propagate = on> on Person.lastname;
        index<type = btree, hints = "degree = 128;", propagate = on> on Person.age;
};
It is as well possible to remove entirely the database schema:
% eyedbodl -d foo -u --rmsch
Updating 'UNTITLED' schema in database foo...
Removing [2570.2.500986:oid] hashindex 'index<type = hash, hints = "key_count = 4096; initial_size = 4096; extend_coef = 1; size_max = 4096;", propagate = on> on Person.firstname' from class 'Person'...
Removing [2585.2.286352:oid] hashindex 'index<type = hash, hints = "key_count = 4096; initial_size = 4096; extend_coef = 1; size_max = 4096;", propagate = on> on Person.lastname' from class 'Person'...
Removing [2599.2.7912:oid] btreeindex 'index<type = btree, hints = "degree = 128;", propagate = on> on Person.age' from class 'Person'...
Removing [2625.2.396262:oid] unique_constraint 'constraint<unique, propagate = on> on Person.lastname' from class 'Person'...
Removing [2620.2.240536:oid] notnull_constraint 'constraint<notnull, propagate = on> on Person.lastname' from class 'Person'...
Removing class Address
Removing class Person
Removing class set<Person*>

Done
The result can be checked with:
% eyedbodl -d foo --gencode=ODL

//
// EyeDB Version 2.8.4 Copyright (c) 1995-2007 SYSRA
//
// UNTITLED Schema
//
// Generated by eyedbodl at Mon Dec 10 13:44:03 CET 2007
//

EyeDB manual