You are here: Basics Operations & Concepts > Indexing

Indexing

db4o supports indexes like most databases do. Indexes are data structures which allow efficient lookup of data. When you enable an index, db4o will add an entry to index for each object. This makes the insert and update operation a little slower. However it makes queries a lot faster. A query which uses an index is a order of magnitude faster that a query which cannot use a index.

You can create a index by enabling it on a field. See "Adding a Field Index"

@Indexed
private String zipCode;
City.java: Index a field

As an alternative you can configure a field index externally.

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

When And Where Do I Need An Index

When do you need an index? As a rule of thumb: Add an index all fields which are used in queries. See "When And Where"

There are different factors which need to be fulfilled to profit from an index.