You are here: Tuning > Indexing

Indexing

db4o allows to index fields to provide maximum querying performance. To request an index to be created, you would issue the following API method call in your global db4o configuration method before you open an ObjectContainer/ObjectServer:

EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(Person.class).objectField("name").indexed(true);
ObjectFieldConfigurations.java: Index a certain fieldDownload Example Code

If the configuration is set in this way, an index on the Foo#bar field will be created (if not present already) the next time you open an ObjectContainer/ObjectServer and you use the Foo class the first time in your applcation.

Contrary to all other configuration calls indexes - once created - will remain in a database even if the index configuration call is not issued before opening an ObjectContainer/ObjectServer.

You can drop an index by explicitly calling index(false).Dropping the index will take place the next time the respective class is used.

You can see db4o dropping and crating indexes, when you increate the message-level.

For creating and dropping indexes on large amounts of objects there are two possible strategies:

  1. Import all objects with indexing off, configure the index and reopen the ObjectContainer/ObjectServer.
  2. Import all objects with indexing turned on and commit regularly for a fixed amount of objects (~10,000).
  1. Will be faster.
  2. Will keep memory consumption lower.

For more information see Enable Field Indexes chapter.