SPRING CONCEPTS

Database index

Spring Concepts / Database index

A database index supports query access and can enforce uniqueness.

Understand the idea

Indexes maintain a searchable representation of selected fields. A unique index rejects conflicting values even when concurrent requests race. Indexes use storage and add write work, so they should reflect actual query and integrity requirements.

A concrete example

@Indexed(unique = true)
private String email;

@Indexed
private String ownerId;

In the application

The personal app requires a unique email index and uses an ownerId index for per-user list queries.

A preliminary “does this email exist?” query does not replace a unique database index.

Related concepts

Read the official documentation ↗
Java 21 · Spring Boot 4.1.1 · Edupoly