Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/content/docs/d1/best-practices/use-indexes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ This will return output resembling the below:

Note that you cannot modify this table, or an existing index. To modify an index, [delete it first](#remove-indexes) and [create a new index](#create-an-index) with the updated definition.

## Run `PRAGMA optimize`

After creating an index, run [`PRAGMA optimize`](/d1/sql-api/sql-statements/#pragma-optimize) to improve your database performance.

## Test an index

Validate that an index was used for a query by prepending a query with [`EXPLAIN QUERY PLAN`](https://www.sqlite.org/eqp.html). This will output a query plan for the succeeding statement, including which (if any) indexes were used.
Expand Down
8 changes: 8 additions & 0 deletions src/content/partials/d1/use-pragma-statements.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,11 @@ PRAGMA defer_foreign_keys = off
```

Refer to the [foreign key documentation](/d1/sql-api/foreign-keys/) to learn more about how to work with foreign keys.

### `PRAGMA optimize`

Attempts to optimize all schemas in a database by running various maintenance operations.

We recommend running this command after creating an index.

Refer to [SQLite PRAGMA optimize documentation](https://www.sqlite.org/pragma.html#pragma_optimize) for more information on how the command optimizes a database.
Loading