Indexes

Are your queries taking too long to run? Measure their performance using the logQueryExecutionTime option:

const allTodos = evolu.createQuery(
  (db) => db.selectFrom("todo").orderBy("createdAt").selectAll(),
  {
    logQueryExecutionTime: true,
    // logExplainQueryPlan: false,
  },
);

While indexes may not be needed during early development, they are crucial for production performance. Use the logQueryExecutionTime and logExplainQueryPlan options in createQuery to measure and analyze performance.

For deeper insights into how SQLite indexes work under the hood, read this in-depth guide.

Usage

const evolu = createEvolu(evoluReactWebDeps)(Schema, {
  // ...
  indexes: (create) => [create("todoCreatedAt").on("todo").column("createdAt")],
});

Evolu handles this automatically—it will create any new indexes you define and drop those no longer present in the indexes array.

Recommendations

SQLite offers a powerful CLI tool for index recommendations.

To use it:

  1. Download the "Precompiled Binaries" here.
  2. Open your database or create a new one.
  3. Run .expert and paste in the SQL of the query you're analyzing.

You can get the query SQL using the logQueryExecutionTime option in createQuery, which logs the full SQL statement for easy copy-paste.