mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
Implement operator class parameters
PostgreSQL provides set of template index access methods, where opclasses have much freedom in the semantics of indexing. These index AMs are GiST, GIN, SP-GiST and BRIN. There opclasses define representation of keys, operations on them and supported search strategies. So, it's natural that opclasses may be faced some tradeoffs, which require user-side decision. This commit implements opclass parameters allowing users to set some values, which tell opclass how to index the particular dataset. This commit doesn't introduce new storage in system catalog. Instead it uses pg_attribute.attoptions, which is used for table column storage options but unused for index attributes. In order to evade changing signature of each opclass support function, we implement unified way to pass options to opclass support functions. Options are set to fn_expr as the constant bytea expression. It's possible due to the fact that opclass support functions are executed outside of expressions, so fn_expr is unused for them. This commit comes with some examples of opclass options usage. We parametrize signature length in GiST. That applies to multiple opclasses: tsvector_ops, gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and gist_hstore_ops. Also we parametrize maximum number of integer ranges for gist__int_ops. However, the main future usage of this feature is expected to be json, where users would be able to specify which way to index particular json parts. Catversion is bumped. Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru Author: Nikita Glukhov, revised by me Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
This commit is contained in:
@@ -265,7 +265,7 @@
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Two GiST index operator classes are provided:
|
||||
Two parametrized GiST index operator classes are provided:
|
||||
<literal>gist__int_ops</literal> (used by default) is suitable for
|
||||
small- to medium-size data sets, while
|
||||
<literal>gist__intbig_ops</literal> uses a larger signature and is more
|
||||
@@ -274,6 +274,25 @@
|
||||
The implementation uses an RD-tree data structure with
|
||||
built-in lossy compression.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<literal>gist__int_ops</literal> approximates integer set as an array of
|
||||
integer ranges. Optional integer parameter <literal>numranges</literal> of
|
||||
<literal>gist__int_ops</literal> determines maximum number of ranges in
|
||||
one index key. Default value of <literal>numranges</literal> is 100.
|
||||
Valid values are between 1 and 253. Using larger arrays as GiST index
|
||||
keys leads to more precise search (scan less fraction of index, scan less
|
||||
heap pages), but larger index.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<literal>gist__intbig_ops</literal> approximates integer set as a bitmap
|
||||
signature. Optional integer parameter <literal>siglen</literal> of
|
||||
<literal>gist__intbig_ops</literal> determines signature length in bytes.
|
||||
Default signature length is 16 bytes. Valid values of signature length
|
||||
are between 1 and 2024 bytes. Longer signatures leads to more precise
|
||||
search (scan less fraction of index, scan less heap pages), but larger index.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
There is also a non-default GIN operator class
|
||||
@@ -293,8 +312,8 @@
|
||||
-- a message can be in one or more <quote>sections</quote>
|
||||
CREATE TABLE message (mid INT PRIMARY KEY, sections INT[], ...);
|
||||
|
||||
-- create specialized index
|
||||
CREATE INDEX message_rdtree_idx ON message USING GIST (sections gist__int_ops);
|
||||
-- create specialized index with sigature length of 32 bytes
|
||||
CREATE INDEX message_rdtree_idx ON message USING GIST (sections gist__int_ops(siglen=32));
|
||||
|
||||
-- select messages in section 1 OR 2 - OVERLAP operator
|
||||
SELECT message.mid FROM message WHERE message.sections && '{1,2}';
|
||||
|
||||
Reference in New Issue
Block a user