@@ -484,23 +484,27 @@ SELECT * FROM "Balance$"
484
484
When designing your schema or crafting your queries,
485
485
consider the following best practices to ensure optimal performance:
486
486
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.
490
489
The query planner can further optimize joins if it knows the join values to be unique.
491
490
492
491
- ** Index Filtered Columns:**
493
- Define indexes on columns frequently used in a ` WHERE` clause.
492
+ Index columns frequently used in a ` WHERE` clause.
494
493
Indexes reduce the number of rows scanned by the query engine.
495
494
496
495
- ** 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.
498
497
These are columns that are used in the ` ON` condition of a ` JOIN` .
498
+
499
499
Again, this reduces the number of rows that must be scanned to answer a query.
500
500
It is also critical for the performance of subscription updates --
501
501
so much so that it is a compiler- enforced requirement,
502
502
as mentioned in the [subscription](# from) section.
503
503
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
+
504
508
- ** Optimize Join Order:**
505
509
Place tables with the most selective filters first in your ` FROM` clause.
506
510
This minimizes intermediate result sizes and improves query efficiency.
0 commit comments