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:
- Download the "Precompiled Binaries" here.
- Open your database or create a new one.
- 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.