-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ffa2a3
commit f049b85
Showing
11 changed files
with
106 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Indexes in Postgres | ||
|
||
[PostgreSQL: Documentation: 16: Chapter 11. Indexes](https://www.postgresql.org/docs/current/indexes.html) | ||
|
||
## Types | ||
|
||
### [B-tree indexes](https://www.postgresql.org/docs/current/btree-intro.html) | ||
|
||
B-tree indexes are binary trees that are used to sort data efficiently. They're the default if you use the INDEX command. Most of the time, a B-tree index suffices. As you scale, inconsistencies can be a larger problem, so use the [amcheck](https://www.postgresql.org/docs/11/amcheck.html) extension periodically. | ||
|
||
### Hash Indexes | ||
|
||
Hash indexes store a 32-bit hash code derived from the value of the indexed column. Hence, such indexes can only handle simple equality comparisons. The query planner will consider using a hash index whenever an indexed column is involved in a comparison using the equal operator | ||
|
||
[PostgreSQL: Documentation: 16: 11.2. Index Types](https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-HASH) | ||
|
||
### [BRIN indexes](https://www.postgresql.org/docs/11/brin-intro.html) | ||
|
||
A Block Range INdex (BRIN) can be used when your table is naturally already sorted by a column, and you need to sort by that column. For example, for a log table that was written sequentially, setting a BRIN index on the timestamp column lets the server know that the data is already sorted. | ||
|
||
BRIN works in terms of _block ranges_ (or “page ranges”). A block range is a group of pages that are physically adjacent in the table; for each block range, some summary info is stored by the index. For example, a table storing a store's sale orders might have a date column on which each order was placed, and most of the time the entries for earlier orders will appear earlier in the table as well; a table storing a ZIP code column might have all codes for a city grouped together naturally. | ||
|
||
[PostgreSQL: Documentation: 16: 71.1. Introduction](https://www.postgresql.org/docs/current/brin-intro.html) | ||
|
||
[Postgres BRIN Index — Large Data Performance With Minimal Storage | by Eresh Gorantla | Geek Culture | Medium](https://medium.com/geekculture/postgres-brin-index-large-data-performance-with-minimal-storage-4db6b9f64ca4) | ||
|
||
[Block Range Index - Wikipedia](https://en.wikipedia.org/wiki/Block_Range_Index) | ||
|
||
### [Bloom filter index](https://www.postgresql.org/docs/11/bloom.html) | ||
|
||
A bloom index is perfect for multi-column queries on big tables where you only need to test for equality. It uses a special mathematical structure called a bloom filter that's based on probability and uses significantly less space. | ||
|
||
### [GIN and GiST indexes](https://www.postgresql.org/docs/11/textsearch-indexes.html) | ||
|
||
Use a GIN or GiST index for efficient indexes based on composite values like text, arrays, and JSON. | ||
|
||
There are two kinds of indexes that can be used to speed up full text searches. Note that indexes are not mandatory for full text searching, but in cases where a column is searched on a regular basis, an index is usually desirable. | ||
|
||
```sql | ||
-- Creates a GiST (Generalized Search Tree)-based index. The column can be of tsvector or tsquery type. | ||
CREATE INDEX name ON table USING gist(column); | ||
|
||
-- Creates a GIN (Generalized Inverted Index)-based index. The column must be of tsvector type. | ||
CREATE INDEX name ON table USING gin(column); | ||
``` | ||
|
||
A GiST index is _lossy_, meaning that the index may produce false matches, and it is necessary to check the actual table row to eliminate such false matches. | ||
|
||
GIN indexes are not lossy for standard queries, but their performance depends logarithmically on the number of unique words. | ||
|
||
Performance | ||
- GIN index lookups are about three times faster than GiST | ||
- GIN indexes take about three times longer to build than GiST | ||
- GIN indexes are moderately slower to update than GiST indexes, but about 10 times slower if fast-update support was disabled. | ||
- GIN indexes are two-to-three times larger than GiST indexes | ||
|
||
https://habr.com/en/company/postgrespro/blog/448746 | ||
|
||
[PostgreSQL: Documentation: 9.1: GiST and GIN Index Types](https://www.postgresql.org/docs/9.1/textsearch-indexes.html) | ||
### SP-GiST | ||
|
||
SP-GiST indexes, like GiST indexes, offer an infrastructure that supports various kinds of searches. SP-GiST permits implementation of a wide range of different non-balanced disk-based data structures, such as quadtrees, k-d trees, and radix trees (tries). | ||
|
||
[PostgreSQL: Documentation: 16: 11.2. Index Types](https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPE-SPGIST) | ||
|
||
## Partial Indexes | ||
|
||
A _partial index_ is an index built over a subset of a table; the subset is defined by a conditional expression (called the _predicate_ of the partial index). The index contains entries only for those table rows that satisfy the predicate. | ||
|
||
[PostgreSQL: Documentation: 16: 11.8. Partial Indexes](https://www.postgresql.org/docs/current/indexes-partial.html) | ||
|
||
[PostgreSQL - Partial Index - GeeksforGeeks](https://www.geeksforgeeks.org/postgresql-partial-index/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters