Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
brin-extensibility.html168 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>71.3. Extensibility</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="brin-builtin-opclasses.html" title="71.2. Built-in Operator Classes" /><link rel="next" href="hash-index.html" title="Chapter 72. Hash Indexes" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">71.3. Extensibility</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="brin-builtin-opclasses.html" title="71.2. Built-in Operator Classes">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="brin.html" title="Chapter 71. BRIN Indexes">Up</a></td><th width="60%" align="center">Chapter 71. BRIN Indexes</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="hash-index.html" title="Chapter 72. Hash Indexes">Next</a></td></tr></table><hr /></div><div class="sect1" id="BRIN-EXTENSIBILITY"><div class="titlepage"><div><div><h2 class="title" style="clear: both">71.3. Extensibility <a href="#BRIN-EXTENSIBILITY" class="id_link">#</a></h2></div></div></div><p>3  The <acronym class="acronym">BRIN</acronym> interface has a high level of abstraction,4  requiring the access method implementer only to implement the semantics5  of the data type being accessed.  The <acronym class="acronym">BRIN</acronym> layer6  itself takes care of concurrency, logging and searching the index structure.7 </p><p>8  All it takes to get a <acronym class="acronym">BRIN</acronym> access method working is to9  implement a few user-defined methods, which define the behavior of10  summary values stored in the index and the way they interact with11  scan keys.12  In short, <acronym class="acronym">BRIN</acronym> combines13  extensibility with generality, code reuse, and a clean interface.14 </p><p>15  There are four methods that an operator class for <acronym class="acronym">BRIN</acronym>16  must provide:17 18  </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="function">BrinOpcInfo *opcInfo(Oid type_oid)</code></span></dt><dd><p>19      Returns internal information about the indexed columns' summary data.20      The return value must point to a palloc'd <code class="structname">BrinOpcInfo</code>,21      which has this definition:22</p><pre class="programlisting">23typedef struct BrinOpcInfo24{25    /* Number of columns stored in an index column of this opclass */26    uint16      oi_nstored;27 28    /* Opaque pointer for the opclass' private use */29    void       *oi_opaque;30 31    /* Type cache entries of the stored columns */32    TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];33} BrinOpcInfo;34</pre><p>35      <code class="structname">BrinOpcInfo</code>.<code class="structfield">oi_opaque</code> can be used by the36      operator class routines to pass information between support functions37      during an index scan.38     </p></dd><dt><span class="term"><code class="function">bool consistent(BrinDesc *bdesc, BrinValues *column,39       ScanKey *keys, int nkeys)</code></span></dt><dd><p>40      Returns whether all the ScanKey entries are consistent with the given41      indexed values for a range.42      The attribute number to use is passed as part of the scan key.43      Multiple scan keys for the same attribute may be passed at once; the44      number of entries is determined by the <code class="literal">nkeys</code> parameter.45     </p></dd><dt><span class="term"><code class="function">bool consistent(BrinDesc *bdesc, BrinValues *column,46       ScanKey key)</code></span></dt><dd><p>47      Returns whether the ScanKey is consistent with the given indexed48      values for a range.49      The attribute number to use is passed as part of the scan key.50      This is an older backward-compatible variant of the consistent function.51     </p></dd><dt><span class="term"><code class="function">bool addValue(BrinDesc *bdesc, BrinValues *column,52       Datum newval, bool isnull)</code></span></dt><dd><p>53      Given an index tuple and an indexed value, modifies the indicated54      attribute of the tuple so that it additionally represents the new value.55      If any modification was done to the tuple, <code class="literal">true</code> is56      returned.57     </p></dd><dt><span class="term"><code class="function">bool unionTuples(BrinDesc *bdesc, BrinValues *a,58       BrinValues *b)</code></span></dt><dd><p>59      Consolidates two index tuples. Given two index tuples, modifies the60      indicated attribute of the first of them so that it represents both tuples.61      The second tuple is not modified.62     </p></dd></dl></div><p>63 64  An operator class for <acronym class="acronym">BRIN</acronym> can optionally specify the65  following method:66 67  </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="function">void options(local_relopts *relopts)</code></span></dt><dd><p>68       Defines a set of user-visible parameters that control operator class69       behavior.70      </p><p>71       The <code class="function">options</code> function is passed a pointer to a72       <code class="structname">local_relopts</code> struct, which needs to be73       filled with a set of operator class specific options.  The options74       can be accessed from other support functions using the75       <code class="literal">PG_HAS_OPCLASS_OPTIONS()</code> and76       <code class="literal">PG_GET_OPCLASS_OPTIONS()</code> macros.77      </p><p>78       Since both key extraction of indexed values and representation of the79       key in <acronym class="acronym">BRIN</acronym> are flexible, they may depend on80       user-specified parameters.81      </p></dd></dl></div><p>82 83  The core distribution includes support for four types of operator classes:84  minmax, minmax-multi, inclusion and bloom.  Operator class definitions85  using them are shipped for in-core data types as appropriate.  Additional86  operator classes can be defined by the user for other data types using87  equivalent definitions, without having to write any source code;88  appropriate catalog entries being declared is enough.  Note that89  assumptions about the semantics of operator strategies are embedded in the90  support functions' source code.91 </p><p>92  Operator classes that implement completely different semantics are also93  possible, provided implementations of the four main support functions94  described above are written.  Note that backwards compatibility across major95  releases is not guaranteed: for example, additional support functions might96  be required in later releases.97 </p><p>98  To write an operator class for a data type that implements a totally99  ordered set, it is possible to use the minmax support functions100  alongside the corresponding operators, as shown in101  <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-MINMAX-TABLE" title="Table 71.2. Function and Support Numbers for Minmax Operator Classes">Table 71.2</a>.102  All operator class members (functions and operators) are mandatory.103 </p><div class="table" id="BRIN-EXTENSIBILITY-MINMAX-TABLE"><p class="title"><strong>Table 71.2. Function and Support Numbers for Minmax Operator Classes</strong></p><div class="table-contents"><table class="table" summary="Function and Support Numbers for Minmax Operator Classes" border="1"><colgroup><col class="col1" /><col class="col2" /></colgroup><thead><tr><th>Operator class member</th><th>Object</th></tr></thead><tbody><tr><td>Support Function 1</td><td>internal function <code class="function">brin_minmax_opcinfo()</code></td></tr><tr><td>Support Function 2</td><td>internal function <code class="function">brin_minmax_add_value()</code></td></tr><tr><td>Support Function 3</td><td>internal function <code class="function">brin_minmax_consistent()</code></td></tr><tr><td>Support Function 4</td><td>internal function <code class="function">brin_minmax_union()</code></td></tr><tr><td>Operator Strategy 1</td><td>operator less-than</td></tr><tr><td>Operator Strategy 2</td><td>operator less-than-or-equal-to</td></tr><tr><td>Operator Strategy 3</td><td>operator equal-to</td></tr><tr><td>Operator Strategy 4</td><td>operator greater-than-or-equal-to</td></tr><tr><td>Operator Strategy 5</td><td>operator greater-than</td></tr></tbody></table></div></div><br class="table-break" /><p>104  To write an operator class for a complex data type which has values105  included within another type, it's possible to use the inclusion support106  functions alongside the corresponding operators, as shown107  in <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-INCLUSION-TABLE" title="Table 71.3. Function and Support Numbers for Inclusion Operator Classes">Table 71.3</a>.  It requires108  only a single additional function, which can be written in any language.109  More functions can be defined for additional functionality.  All operators110  are optional.  Some operators require other operators, as shown as111  dependencies on the table.112 </p><div class="table" id="BRIN-EXTENSIBILITY-INCLUSION-TABLE"><p class="title"><strong>Table 71.3. Function and Support Numbers for Inclusion Operator Classes</strong></p><div class="table-contents"><table class="table" summary="Function and Support Numbers for Inclusion Operator Classes" border="1"><colgroup><col class="col1" /><col class="col2" /><col class="col3" /></colgroup><thead><tr><th>Operator class member</th><th>Object</th><th>Dependency</th></tr></thead><tbody><tr><td>Support Function 1</td><td>internal function <code class="function">brin_inclusion_opcinfo()</code></td><td> </td></tr><tr><td>Support Function 2</td><td>internal function <code class="function">brin_inclusion_add_value()</code></td><td> </td></tr><tr><td>Support Function 3</td><td>internal function <code class="function">brin_inclusion_consistent()</code></td><td> </td></tr><tr><td>Support Function 4</td><td>internal function <code class="function">brin_inclusion_union()</code></td><td> </td></tr><tr><td>Support Function 11</td><td>function to merge two elements</td><td> </td></tr><tr><td>Support Function 12</td><td>optional function to check whether two elements are mergeable</td><td> </td></tr><tr><td>Support Function 13</td><td>optional function to check if an element is contained within another</td><td> </td></tr><tr><td>Support Function 14</td><td>optional function to check whether an element is empty</td><td> </td></tr><tr><td>Operator Strategy 1</td><td>operator left-of</td><td>Operator Strategy 4</td></tr><tr><td>Operator Strategy 2</td><td>operator does-not-extend-to-the-right-of</td><td>Operator Strategy 5</td></tr><tr><td>Operator Strategy 3</td><td>operator overlaps</td><td> </td></tr><tr><td>Operator Strategy 4</td><td>operator does-not-extend-to-the-left-of</td><td>Operator Strategy 1</td></tr><tr><td>Operator Strategy 5</td><td>operator right-of</td><td>Operator Strategy 2</td></tr><tr><td>Operator Strategy 6, 18</td><td>operator same-as-or-equal-to</td><td>Operator Strategy 7</td></tr><tr><td>Operator Strategy 7, 16, 24, 25</td><td>operator contains-or-equal-to</td><td> </td></tr><tr><td>Operator Strategy 8, 26, 27</td><td>operator is-contained-by-or-equal-to</td><td>Operator Strategy 3</td></tr><tr><td>Operator Strategy 9</td><td>operator does-not-extend-above</td><td>Operator Strategy 11</td></tr><tr><td>Operator Strategy 10</td><td>operator is-below</td><td>Operator Strategy 12</td></tr><tr><td>Operator Strategy 11</td><td>operator is-above</td><td>Operator Strategy 9</td></tr><tr><td>Operator Strategy 12</td><td>operator does-not-extend-below</td><td>Operator Strategy 10</td></tr><tr><td>Operator Strategy 20</td><td>operator less-than</td><td>Operator Strategy 5</td></tr><tr><td>Operator Strategy 21</td><td>operator less-than-or-equal-to</td><td>Operator Strategy 5</td></tr><tr><td>Operator Strategy 22</td><td>operator greater-than</td><td>Operator Strategy 1</td></tr><tr><td>Operator Strategy 23</td><td>operator greater-than-or-equal-to</td><td>Operator Strategy 1</td></tr></tbody></table></div></div><br class="table-break" /><p>113    Support function numbers 1 through 10 are reserved for the BRIN internal114    functions, so the SQL level functions start with number 11.  Support115    function number 11 is the main function required to build the index.116    It should accept two arguments with the same data type as the operator class,117    and return the union of them.  The inclusion operator class can store union118    values with different data types if it is defined with the119    <code class="literal">STORAGE</code> parameter.  The return value of the union120    function should match the <code class="literal">STORAGE</code> data type.121 </p><p>122    Support function numbers 12 and 14 are provided to support123    irregularities of built-in data types.  Function number 12124    is used to support network addresses from different families which125    are not mergeable.  Function number 14 is used to support126    empty ranges.  Function number 13 is an optional but127    recommended one, which allows the new value to be checked before128    it is passed to the union function.  As the BRIN framework can shortcut129    some operations when the union is not changed, using this130    function can improve index performance.131 </p><p>132  To write an operator class for a data type that implements only an equality133  operator and supports hashing, it is possible to use the bloom support procedures134  alongside the corresponding operators, as shown in135  <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-BLOOM-TABLE" title="Table 71.4. Procedure and Support Numbers for Bloom Operator Classes">Table 71.4</a>.136  All operator class members (procedures and operators) are mandatory.137 </p><div class="table" id="BRIN-EXTENSIBILITY-BLOOM-TABLE"><p class="title"><strong>Table 71.4. Procedure and Support Numbers for Bloom Operator Classes</strong></p><div class="table-contents"><table class="table" summary="Procedure and Support Numbers for Bloom Operator Classes" border="1"><colgroup><col /><col /></colgroup><thead><tr><th>Operator class member</th><th>Object</th></tr></thead><tbody><tr><td>Support Procedure 1</td><td>internal function <code class="function">brin_bloom_opcinfo()</code></td></tr><tr><td>Support Procedure 2</td><td>internal function <code class="function">brin_bloom_add_value()</code></td></tr><tr><td>Support Procedure 3</td><td>internal function <code class="function">brin_bloom_consistent()</code></td></tr><tr><td>Support Procedure 4</td><td>internal function <code class="function">brin_bloom_union()</code></td></tr><tr><td>Support Procedure 5</td><td>internal function <code class="function">brin_bloom_options()</code></td></tr><tr><td>Support Procedure 11</td><td>function to compute hash of an element</td></tr><tr><td>Operator Strategy 1</td><td>operator equal-to</td></tr></tbody></table></div></div><br class="table-break" /><p>138    Support procedure numbers 1-10 are reserved for the BRIN internal139    functions, so the SQL level functions start with number 11.  Support140    function number 11 is the main function required to build the index.141    It should accept one argument with the same data type as the operator class,142    and return a hash of the value.143 </p><p>144  The minmax-multi operator class is also intended for data types implementing145  a totally ordered set, and may be seen as a simple extension of the minmax146  operator class. While minmax operator class summarizes values from each block147  range into a single contiguous interval, minmax-multi allows summarization148  into multiple smaller intervals to improve handling of outlier values.149  It is possible to use the minmax-multi support procedures alongside the150  corresponding operators, as shown in151  <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-MINMAX-MULTI-TABLE" title="Table 71.5. Procedure and Support Numbers for minmax-multi Operator Classes">Table 71.5</a>.152  All operator class members (procedures and operators) are mandatory.153 </p><div class="table" id="BRIN-EXTENSIBILITY-MINMAX-MULTI-TABLE"><p class="title"><strong>Table 71.5. Procedure and Support Numbers for minmax-multi Operator Classes</strong></p><div class="table-contents"><table class="table" summary="Procedure and Support Numbers for minmax-multi Operator Classes" border="1"><colgroup><col /><col /></colgroup><thead><tr><th>Operator class member</th><th>Object</th></tr></thead><tbody><tr><td>Support Procedure 1</td><td>internal function <code class="function">brin_minmax_multi_opcinfo()</code></td></tr><tr><td>Support Procedure 2</td><td>internal function <code class="function">brin_minmax_multi_add_value()</code></td></tr><tr><td>Support Procedure 3</td><td>internal function <code class="function">brin_minmax_multi_consistent()</code></td></tr><tr><td>Support Procedure 4</td><td>internal function <code class="function">brin_minmax_multi_union()</code></td></tr><tr><td>Support Procedure 5</td><td>internal function <code class="function">brin_minmax_multi_options()</code></td></tr><tr><td>Support Procedure 11</td><td>function to compute distance between two values (length of a range)</td></tr><tr><td>Operator Strategy 1</td><td>operator less-than</td></tr><tr><td>Operator Strategy 2</td><td>operator less-than-or-equal-to</td></tr><tr><td>Operator Strategy 3</td><td>operator equal-to</td></tr><tr><td>Operator Strategy 4</td><td>operator greater-than-or-equal-to</td></tr><tr><td>Operator Strategy 5</td><td>operator greater-than</td></tr></tbody></table></div></div><br class="table-break" /><p>154    Both minmax and inclusion operator classes support cross-data-type155    operators, though with these the dependencies become more complicated.156    The minmax operator class requires a full set of operators to be157    defined with both arguments having the same data type.  It allows158    additional data types to be supported by defining extra sets159    of operators.  Inclusion operator class operator strategies are dependent160    on another operator strategy as shown in161    <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-INCLUSION-TABLE" title="Table 71.3. Function and Support Numbers for Inclusion Operator Classes">Table 71.3</a>, or the same162    operator strategy as themselves.  They require the dependency163    operator to be defined with the <code class="literal">STORAGE</code> data type as the164    left-hand-side argument and the other supported data type to be the165    right-hand-side argument of the supported operator.  See166    <code class="literal">float4_minmax_ops</code> as an example of minmax, and167    <code class="literal">box_inclusion_ops</code> as an example of inclusion.168 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="brin-builtin-opclasses.html" title="71.2. Built-in Operator Classes">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="brin.html" title="Chapter 71. BRIN Indexes">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="hash-index.html" title="Chapter 72. Hash Indexes">Next</a></td></tr><tr><td width="40%" align="left" valign="top">71.2. Built-in Operator Classes </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> Chapter 72. Hash Indexes</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai