A table is divided into fixed length blocks
Blocks are numbered starting from 0
Each block contains a number of heap tuples
A single heap tuple contains the data of a single row
A row is identified by tuple identifier (TID)
TID consists of (block number, offset number)
key = 49
key <= 35
GiST, SP-GiST | For non-sortable data (geodata, text documents, images) |
GIN, RUM | For speeding up full-text search |
BRIN | For values that correlate with their physical location in the table (e.g. time-series). Inaccurate, but much smaller index size. |
CREATE INDEX ON t(a, b);
-- These can use the index
SELECT * FROM t WHERE a = 100 AND b = 'john';
SELECT * FROM t WHERE a = 100;
-- This can't
SELECT * FROM t WHERE b = 'john';
CREATE INDEX ON t(lower(b));
-- This can now use the index
SELECT * FROM t WHERE lower(b) = 'john';
Can be used to reduce the index size
Useful for data with highly non-uniform distribution
-- Assume c is true for 1% of rows, and false for 99%
-- This will use sequence scan, even if there's an index
SELECT * FROM t WHERE NOT c;
-- Index size is drastically reduced with the condition
CREATE INDEX ON t(c) WHERE c = TRUE;
-- This will use the index
SELECT * FROM t WHERE c;