From a630b4dfe50206e571b3c6be07790572f751618b Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:45:55 +0600 Subject: [PATCH] feat: add recommendation on indexes in unique columns (#6553) Co-authored-by: Jon Harrell <4829245+jharrell@users.noreply.github.com> --- content/700-optimize/300-recordings.mdx | 1 + .../1300-indexing-on-unique-columns.mdx | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 content/700-optimize/400-recommendations/1300-indexing-on-unique-columns.mdx diff --git a/content/700-optimize/300-recordings.mdx b/content/700-optimize/300-recordings.mdx index 7497a9d5e5..71f84f56b9 100644 --- a/content/700-optimize/300-recordings.mdx +++ b/content/700-optimize/300-recordings.mdx @@ -45,6 +45,7 @@ When a recording session ends, Optimize generates recommendations such as: - [Using `@db.Char(n)`](/optimize/recommendations/avoid-char) - [Using `@db.VarChar(n)`](/optimize/recommendations/avoid-varchar) - [Using `timestamp(0)` or `timestamptz(0)`](/optimize/recommendations/avoid-timestamp-timestampz-0) +- [Indexing on unique columns](/optimize/recommendations/indexing-on-unique-columns) - [Long-running transactions](/optimize/recommendations/long-running-transactions) - [Unnecessary indexes](/optimize/recommendations/unnecessary-indexes) diff --git a/content/700-optimize/400-recommendations/1300-indexing-on-unique-columns.mdx b/content/700-optimize/400-recommendations/1300-indexing-on-unique-columns.mdx new file mode 100644 index 0000000000..dea66ea352 --- /dev/null +++ b/content/700-optimize/400-recommendations/1300-indexing-on-unique-columns.mdx @@ -0,0 +1,17 @@ +--- +title: 'Indexing on unique columns' +metaTitle: 'Optimize recommendations: Indexing on unique columns' +metaDescription: "Learn about the recommendation provided by Optimize regarding indexing on uniquely constrained columns." +tocDepth: 3 +toc: true +--- + +Optimize identifies redundant indexing on unique columns and provides recommendations for better database performance. + +### Why this is an issue + +Unique constraints inherently enforce uniqueness by generating an underlying index. Adding an additional index to the same column is unnecessary and can lead to extra overhead. + +This redundancy increases write costs and slows down updates, as the database must synchronize multiple indexes. + +This guideline applies broadly to relational databases like PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server, which automatically create indexes for unique constraints.