Skip to content

Commit

Permalink
Update content/700-optimize/400-recommendations.mdx
Browse files Browse the repository at this point in the history
Co-authored-by: Nikolas <[email protected]>
  • Loading branch information
ankur-arch and nikolasburk authored Aug 13, 2024
1 parent acb1e7e commit b9d9ac9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions content/700-optimize/400-recommendations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@ This is a general suggestion based on unindexed columns we can detect. Adding in

### More on database indexes

##### How indexes work
#### How indexes work

Indexes work by creating a data structure that stores the indexed column's values along with pointers to the corresponding rows in the table. When you query the database using an indexed column, the database can use this index to quickly locate the relevant rows, rather than scanning the entire table.

##### The trade-offs of indexing
#### The trade-offs of indexing

- **Space vs. Time**: Indexing requires additional storage space to save index data, but it significantly speeds up data retrieval.
- **Update overhead**: Every time data is added to, updated in, or removed from your table, there is an overhead to keep the indexes up to date, which can slow down write operations.

##### When to use indexes
#### When to use indexes

- Large datasets: Indexes are particularly beneficial for tables with a large number of rows.
- Frequent queries with Filtering or Sorting: Use indexes on columns that are frequently when [filtering or sorting](https://www.prisma.io/docs/orm/prisma-client/queries/filtering-and-sorting#filtering)
- Looking Up Related Data: Use indexes on foreign key columns to speed up the retrieval of related records, such as when using [`include`](https://www.prisma.io/docs/orm/prisma-client/queries/relation-queries#include-a-relation)

##### When not to use indexes
#### When not to use indexes

- Small tables: For tables with very few rows, the overhead of maintaining indexes might not be worth the performance gain.
- Write-heavy tables: Indexes can slow down write operations (`create``update``delete`) because the index needs to be updated as well. Avoid excessive indexing on models with frequent write operations.
Expand Down

0 comments on commit b9d9ac9

Please sign in to comment.