Posts

Showing posts with the label unique index

Data Integrity

Image
Introduction This is a term referring to the accuracy, completeness, consistency and reliability of data throughout its lifecycle, from when it is entered, stored, processed until it is deleted. Data with Integrity is data that correctly reflects objective reality and is not distorted, biased or contaminated due to system errors, human errors or hacker destruction. In database management systems like PostgreSQL, Data Integrity acts like strict rules, preventing any behavior that intentionally or unintentionally makes data absurd. To ensure data is always clean and correct, PostgreSQL provides the following core constraints: Entity Integrity When creating a table with a primary key, using a Unique Constraint or Unique Index means that the values in this column must be unique Ensures that the system can always distinguish between different entities, there is no such thing as two completely identical data rows or an "anonymous" data row existing. If you do not use the above meth...

Partial Index

Image
Introduction Partial Index is an extremely powerful feature that allows the creation of an index on only a subset of a table's data, instead of indexing the entire table. This subset is defined by a filtering condition in a WHERE clause when creating the index. In essence, a Partial Index just adds a condition during index creation, so it can be used with all index types (such as B-Tree , Hash , GIN , GiST , ...) and supports all data types. Additionally, a Partial Index can also be used in combination with a Constraint , Expression Index and Composite Index . Advantages Space-saving: The index size is much smaller than a Full Index, which saves RAM and disk space. Increased Write performance (INSERT/UPDATE/DELETE): When adding or modifying data that does not satisfy the index condition, Postgres does not need to update the index tree. Disadvantages Queries must match the condition: The Postgres Query Planner only uses this index if the SELECT query has a WHERE clause that exactl...