11.11. Индексы и правила сортировки #
Один индекс может поддерживать только одно правило сортировки для индексируемого столбца. Поэтому при необходимости применять разные правила сортировки могут потребоваться несколько индексов.
Рассмотрим следующие операторы:
CREATE TABLE test1c (
id integer,
content varchar COLLATE "x"
);
CREATE INDEX test1c_content_index ON test1c (content);Этот индекс автоматически использует правило сортировки нижележащего столбца. И запрос вида
SELECT * FROM test1c WHERE content > константа;сможет использовать этот индекс, так как при сравнении по умолчанию будет действовать правило сортировки столбца. Однако этот индекс не поможет ускорить запросы с каким-либо другим правилом сортировки. Поэтому, если интерес представляют также и запросы вроде
SELECT * FROM test1c WHERE content > константа COLLATE "y"; для них можно создать дополнительный индекс, поддерживающий правило сортировки "y", примерно так:
CREATE INDEX test1c_content_y_index ON test1c (content COLLATE "y");
11.11. Indexes and Collations #
An index can support only one collation per index column. If multiple collations are of interest, multiple indexes may be needed.
Consider these statements:
CREATE TABLE test1c (
id integer,
content varchar COLLATE "x"
);
CREATE INDEX test1c_content_index ON test1c (content);
The index automatically uses the collation of the underlying column. So a query of the form
SELECT * FROM test1c WHERE content > constant;
could use the index, because the comparison will by default use the collation of the column. However, this index cannot accelerate queries that involve some other collation. So if queries of the form, say,
SELECT * FROM test1c WHERE content > constant COLLATE "y";
are also of interest, an additional index could be created that supports the "y" collation, like this:
CREATE INDEX test1c_content_y_index ON test1c (content COLLATE "y");