Skip to content

Commit b761d6a

Browse files
changes from review
1 parent 804a65b commit b761d6a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/sql/index.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,23 +484,27 @@ SELECT * FROM "Balance$"
484484
When designing your schema or crafting your queries,
485485
consider the following best practices to ensure optimal performance:
486486

487-
- **Define Primary Key and Unique Constraints:**
488-
If a column is a primary key or its values are guaranteed to be unique,
489-
define a primary key or unique constraint on that column.
487+
- **Add Primary Key and/or Unique Constraints:**
488+
Constrain columns whose values are guaranteed to be distinct as either unique or primary keys.
490489
The query planner can further optimize joins if it knows the join values to be unique.
491490

492491
- **Index Filtered Columns:**
493-
Define indexes on columns frequently used in a `WHERE` clause.
492+
Index columns frequently used in a `WHERE` clause.
494493
Indexes reduce the number of rows scanned by the query engine.
495494

496495
- **Index Join Columns:**
497-
Define indexes on columns whose values are frequently used as join keys.
496+
Index columns whose values are frequently used as join keys.
498497
These are columns that are used in the `ON` condition of a `JOIN`.
498+
499499
Again, this reduces the number of rows that must be scanned to answer a query.
500500
It is also critical for the performance of subscription updates --
501501
so much so that it is a compiler-enforced requirement,
502502
as mentioned in the [subscription](#from) section.
503503

504+
If a column that has already been constrained as unique or a primary key,
505+
it is not necessary to explicitly index it as well,
506+
since these constraints automatically index the column in question.
507+
504508
- **Optimize Join Order:**
505509
Place tables with the most selective filters first in your `FROM` clause.
506510
This minimizes intermediate result sizes and improves query efficiency.

0 commit comments

Comments
 (0)