gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
13KB

  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>67.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 V1.79.1" /><link rel="prev" href="brin-builtin-opclasses.html" title="67.2. Built-in Operator Classes" /><link rel="next" href="storage.html" title="Chapter 68. Database Physical Storage" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">67.3. Extensibility</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="brin-builtin-opclasses.html" title="67.2. Built-in Operator Classes">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="brin.html" title="Chapter 67. BRIN Indexes">Up</a></td><th width="60%" align="center">Chapter 67. BRIN Indexes</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="storage.html" title="Chapter 68. Database Physical Storage">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="BRIN-EXTENSIBILITY"><div class="titlepage"><div><div><h2 class="title" style="clear: both">67.3. Extensibility</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 semantics
  5. of the data type being accessed. The <acronym class="acronym">BRIN</acronym> layer
  6. 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 to
  9. implement a few user-defined methods, which define the behavior of
  10. summary values stored in the index and the way they interact with
  11. scan keys.
  12. In short, <acronym class="acronym">BRIN</acronym> combines
  13. 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. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="function">BrinOpcInfo *opcInfo(Oid type_oid)</code></span></dt><dd><p>
  18. Returns internal information about the indexed columns' summary data.
  19. The return value must point to a palloc'd <code class="structname">BrinOpcInfo</code>,
  20. which has this definition:
  21. </p><pre class="programlisting">
  22. typedef struct BrinOpcInfo
  23. {
  24. /* Number of columns stored in an index column of this opclass */
  25. uint16 oi_nstored;
  26. /* Opaque pointer for the opclass' private use */
  27. void *oi_opaque;
  28. /* Type cache entries of the stored columns */
  29. TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
  30. } BrinOpcInfo;
  31. </pre><p>
  32. <code class="structname">BrinOpcInfo</code>.<code class="structfield">oi_opaque</code> can be used by the
  33. operator class routines to pass information between support functions
  34. during an index scan.
  35. </p></dd><dt><span class="term"><code class="function">bool consistent(BrinDesc *bdesc, BrinValues *column,
  36. ScanKey key)</code></span></dt><dd><p>
  37. Returns whether the ScanKey is consistent with the given indexed
  38. values for a range.
  39. The attribute number to use is passed as part of the scan key.
  40. </p></dd><dt><span class="term"><code class="function">bool addValue(BrinDesc *bdesc, BrinValues *column,
  41. Datum newval, bool isnull)</code></span></dt><dd><p>
  42. Given an index tuple and an indexed value, modifies the indicated
  43. attribute of the tuple so that it additionally represents the new value.
  44. If any modification was done to the tuple, <code class="literal">true</code> is
  45. returned.
  46. </p></dd><dt><span class="term"><code class="function">bool unionTuples(BrinDesc *bdesc, BrinValues *a,
  47. BrinValues *b)</code></span></dt><dd><p>
  48. Consolidates two index tuples. Given two index tuples, modifies the
  49. indicated attribute of the first of them so that it represents both tuples.
  50. The second tuple is not modified.
  51. </p></dd></dl></div><p>
  52. The core distribution includes support for two types of operator classes:
  53. minmax and inclusion. Operator class definitions using them are shipped for
  54. in-core data types as appropriate. Additional operator classes can be
  55. defined by the user for other data types using equivalent definitions,
  56. without having to write any source code; appropriate catalog entries being
  57. declared is enough. Note that assumptions about the semantics of operator
  58. strategies are embedded in the support functions' source code.
  59. </p><p>
  60. Operator classes that implement completely different semantics are also
  61. possible, provided implementations of the four main support functions
  62. described above are written. Note that backwards compatibility across major
  63. releases is not guaranteed: for example, additional support functions might
  64. be required in later releases.
  65. </p><p>
  66. To write an operator class for a data type that implements a totally
  67. ordered set, it is possible to use the minmax support functions
  68. alongside the corresponding operators, as shown in
  69. <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-MINMAX-TABLE" title="Table 67.2. Function and Support Numbers for Minmax Operator Classes">Table 67.2</a>.
  70. All operator class members (functions and operators) are mandatory.
  71. </p><div class="table" id="BRIN-EXTENSIBILITY-MINMAX-TABLE"><p class="title"><strong>Table 67.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 /><col /></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>
  72. To write an operator class for a complex data type which has values
  73. included within another type, it's possible to use the inclusion support
  74. functions alongside the corresponding operators, as shown
  75. in <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-INCLUSION-TABLE" title="Table 67.3. Function and Support Numbers for Inclusion Operator Classes">Table 67.3</a>. It requires
  76. only a single additional function, which can be written in any language.
  77. More functions can be defined for additional functionality. All operators
  78. are optional. Some operators require other operators, as shown as
  79. dependencies on the table.
  80. </p><div class="table" id="BRIN-EXTENSIBILITY-INCLUSION-TABLE"><p class="title"><strong>Table 67.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 /><col /><col /></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, 13, 16, 24, 25</td><td>operator contains-or-equal-to</td><td> </td></tr><tr><td>Operator Strategy 8, 14, 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>
  81. Support function numbers 1-10 are reserved for the BRIN internal
  82. functions, so the SQL level functions start with number 11. Support
  83. function number 11 is the main function required to build the index.
  84. It should accept two arguments with the same data type as the operator class,
  85. and return the union of them. The inclusion operator class can store union
  86. values with different data types if it is defined with the
  87. <code class="literal">STORAGE</code> parameter. The return value of the union
  88. function should match the <code class="literal">STORAGE</code> data type.
  89. </p><p>
  90. Support function numbers 12 and 14 are provided to support
  91. irregularities of built-in data types. Function number 12
  92. is used to support network addresses from different families which
  93. are not mergeable. Function number 14 is used to support
  94. empty ranges. Function number 13 is an optional but
  95. recommended one, which allows the new value to be checked before
  96. it is passed to the union function. As the BRIN framework can shortcut
  97. some operations when the union is not changed, using this
  98. function can improve index performance.
  99. </p><p>
  100. Both minmax and inclusion operator classes support cross-data-type
  101. operators, though with these the dependencies become more complicated.
  102. The minmax operator class requires a full set of operators to be
  103. defined with both arguments having the same data type. It allows
  104. additional data types to be supported by defining extra sets
  105. of operators. Inclusion operator class operator strategies are dependent
  106. on another operator strategy as shown in
  107. <a class="xref" href="brin-extensibility.html#BRIN-EXTENSIBILITY-INCLUSION-TABLE" title="Table 67.3. Function and Support Numbers for Inclusion Operator Classes">Table 67.3</a>, or the same
  108. operator strategy as themselves. They require the dependency
  109. operator to be defined with the <code class="literal">STORAGE</code> data type as the
  110. left-hand-side argument and the other supported data type to be the
  111. right-hand-side argument of the supported operator. See
  112. <code class="literal">float4_minmax_ops</code> as an example of minmax, and
  113. <code class="literal">box_inclusion_ops</code> as an example of inclusion.
  114. </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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="brin.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="storage.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">67.2. Built-in Operator Classes </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 68. Database Physical Storage</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1