8000 Implement operator class parameters · postgrespro/postgres_cluster@911e702 · GitHub
[go: up one dir, main page]

Skip to content

Commit 911e702

Browse files
committed
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
1 parent 1d53432 commit 911e702

File tree

108 files changed

+4063
-901
lines changed
  • ref
  • src
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    108 files changed

    +4063
    -901
    lines changed

    contrib/bloom/bloom.h

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -22,7 +22,8 @@
    2222

    2323
    /* Support procedures numbers */
    2424
    #define BLOOM_HASH_PROC 1
    25-
    #define BLOOM_NPROC 1
    25+
    #define BLOOM_OPTIONS_PROC 2
    26+
    #define BLOOM_NPROC 2
    2627

    2728
    /* Scan strategies */
    2829
    #define BLOOM_EQUAL_STRATEGY 1

    contrib/bloom/blutils.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -109,6 +109,7 @@ blhandler(PG_FUNCTION_ARGS)
    109109

    110110
    amroutine->amstrategies = BLOOM_NSTRATEGIES;
    111111
    amroutine->amsupport = BLOOM_NPROC;
    112+
    amroutine->amoptsprocnum = BLOOM_OPTIONS_PROC;
    112113
    amroutine->amcanorder = false;
    113114
    amroutine->amcanorderbyop = false;
    114115
    amroutine->amcanbackward = false;

    contrib/bloom/blvalidate.c

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -108,6 +108,9 @@ blvalidate(Oid opclassoid)
    108108
    ok = check_amproc_signature(procform->amproc, INT4OID, false,
    109109
    1, 1, opckeytype);
    110110
    break;
    111+
    case BLOOM_OPTIONS_PROC:
    112+
    ok = check_amoptsproc_signature(procform->amproc);
    113+
    break;
    111114
    default:
    112115
    ereport(INFO,
    113116
    (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
    @@ -204,6 +207,8 @@ blvalidate(Oid opclassoid)
    204207
    if (opclassgroup &&
    205208
    (opclassgroup->functionset & (((uint64) 1) << i)) != 0)
    206209
    continue; /* got it */
    210+
    if (i == BLOOM_OPTIONS_PROC)
    211+
    continue; /* optional method */
    207212
    ereport(INFO,
    208213
    (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
    209214
    errmsg("bloom opclass %s is missing support function %d",

    contrib/hstore/Makefile

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,6 +11,7 @@ OBJS = \
    1111

    1212
    EXTENSION = hstore
    1313
    DATA = hstore--1.4.sql \
    14+
    hstore--1.6--1.7.sql \
    1415
    hstore--1.5--1.6.sql \
    1516
    hstore--1.4--1.5.sql \
    1617
    hstore--1.3--1.4.sql hstore--1.2--1.3.sql \

    contrib/hstore/expected/hstore.out

    Lines changed: 45 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1344,6 +1344,51 @@ select count(*) from testhstore where h ?& ARRAY['public','disabled'];
    13441344
    42
    13451345
    (1 row)
    13461346

    1347+
    drop index hidx;
    1348+
    create index hidx on testhstore using gist(h gist_hstore_ops(siglen=0));
    1349+
    ERROR: value 0 out of bounds for option "siglen"
    1350+
    DETAIL: Valid values are between "1" and "2024".
    1351+
    create index hidx on testhstore using gist(h gist_hstore_ops(siglen=2025));
    1352+
    ERROR: value 2025 out of bounds for option "siglen"
    1353+
    DETAIL: Valid values are between "1" and "2024".
    1354+
    create index hidx on testhstore using gist(h gist_hstore_ops(siglen=2024));
    1355+
    set enable_seqscan=off;
    1356+
    select count(*) from testhstore where h @> 'wait=>NULL';
    1357+
    count
    1358+
    -------
    1359+
    1
    1360+
    (1 row)
    1361+
    1362+
    select count(*) from testhstore where h @> 'wait=>CC';
    1363+
    count
    1364+
    -------
    1365+
    15
    1366+
    (1 row)
    1367+
    1368+
    select count(*) from testhstore where h @> 'wait=>CC, public=>t';
    1369+
    count
    1370+
    -------
    1371+
    2
    1372+
    (1 row)
    1373+
    1374+
    select count(*) from testhstore where h ? 'public';
    1375+
    count
    1376+
    -------
    1377+
    194
    1378+
    (1 row)
    1379+
    1380+
    select count(*) from testhstore where h ?| ARRAY['public','disabled'];
    1381+
    count
    1382+
    -------
    1383+
    337
    1384+
    (1 row)
    1385+
    1386+
    select count(*) from testhstore where h ?& ARRAY['public','disabled'];
    1387+
    count
    1388+
    -------
    1389+
    42
    1390+
    (1 row)
    1391+
    13471392
    drop index hidx;
    13481393
    create index hidx on testhstore using gin (h);
    13491394
    set enable_seqscan=off;

    contrib/hstore/hstore--1.6--1.7.sql

    Lines changed: 12 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,12 @@
    1+
    /* contrib/hstore/hstore--1.6--1.7.sql */
    2+
    3+
    -- complain if script is sourced in psql, rather than via ALTER EXTENSION
    4+
    \echo Use "ALTER EXTENSION hstore UPDATE TO '1.7'" to load this file. \quit
    5+
    6+
    CREATE FUNCTION ghstore_options(internal)
    7+
    RETURNS void
    8+
    AS 'MODULE_PATHNAME', 'ghstore_options'
    9+
    LANGUAGE C IMMUTABLE PARALLEL SAFE;
    10+
    11+
    ALTER OPERATOR FAMILY gist_hstore_ops USING gist
    12+
    ADD FUNCTION 10 (hstore) ghstore_options (internal);

    contrib/hstore/hstore.control

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,6 +1,6 @@
    11
    # hstore extension
    22
    comment = 'data type for storing sets of (key, value) pairs'
    3-
    default_version = '1.6'
    3+
    default_version = '1.7'
    44
    module_pathname = '$libdir/hstore'
    55
    relocatable = true
    66
    trusted = true

    0 commit comments

    Comments
     (0)
    0