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.

80 lines
8.4KB

  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>65.4. Implementation</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="spgist-extensibility.html" title="65.3. Extensibility" /><link rel="next" href="spgist-examples.html" title="65.5. Examples" /></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">65.4. Implementation</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="spgist-extensibility.html" title="65.3. Extensibility">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="spgist.html" title="Chapter 65. SP-GiST Indexes">Up</a></td><th width="60%" align="center">Chapter 65. SP-GiST 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="spgist-examples.html" title="65.5. Examples">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="SPGIST-IMPLEMENTATION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">65.4. Implementation</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="spgist-implementation.html#SPGIST-LIMITS">65.4.1. SP-GiST Limits</a></span></dt><dt><span class="sect2"><a href="spgist-implementation.html#SPGIST-NULL-LABELS">65.4.2. SP-GiST Without Node Labels</a></span></dt><dt><span class="sect2"><a href="spgist-implementation.html#SPGIST-ALL-THE-SAME">65.4.3. <span class="quote">“<span class="quote">All-the-Same</span>”</span> Inner Tuples</a></span></dt></dl></div><p>
  3. This section covers implementation details and other tricks that are
  4. useful for implementers of <acronym class="acronym">SP-GiST</acronym> operator classes to
  5. know.
  6. </p><div class="sect2" id="SPGIST-LIMITS"><div class="titlepage"><div><div><h3 class="title">65.4.1. SP-GiST Limits</h3></div></div></div><p>
  7. Individual leaf tuples and inner tuples must fit on a single index page
  8. (8kB by default). Therefore, when indexing values of variable-length
  9. data types, long values can only be supported by methods such as radix
  10. trees, in which each level of the tree includes a prefix that is short
  11. enough to fit on a page, and the final leaf level includes a suffix also
  12. short enough to fit on a page. The operator class should set
  13. <code class="structfield">longValuesOK</code> to true only if it is prepared to arrange for
  14. this to happen. Otherwise, the <acronym class="acronym">SP-GiST</acronym> core will
  15. reject any request to index a value that is too large to fit
  16. on an index page.
  17. </p><p>
  18. Likewise, it is the operator class's responsibility that inner tuples
  19. do not grow too large to fit on an index page; this limits the number
  20. of child nodes that can be used in one inner tuple, as well as the
  21. maximum size of a prefix value.
  22. </p><p>
  23. Another limitation is that when an inner tuple's node points to a set
  24. of leaf tuples, those tuples must all be in the same index page.
  25. (This is a design decision to reduce seeking and save space in the
  26. links that chain such tuples together.) If the set of leaf tuples
  27. grows too large for a page, a split is performed and an intermediate
  28. inner tuple is inserted. For this to fix the problem, the new inner
  29. tuple <span class="emphasis"><em>must</em></span> divide the set of leaf values into more than one
  30. node group. If the operator class's <code class="function">picksplit</code> function
  31. fails to do that, the <acronym class="acronym">SP-GiST</acronym> core resorts to
  32. extraordinary measures described in <a class="xref" href="spgist-implementation.html#SPGIST-ALL-THE-SAME" title="65.4.3. “All-the-Same” Inner Tuples">Section 65.4.3</a>.
  33. </p></div><div class="sect2" id="SPGIST-NULL-LABELS"><div class="titlepage"><div><div><h3 class="title">65.4.2. SP-GiST Without Node Labels</h3></div></div></div><p>
  34. Some tree algorithms use a fixed set of nodes for each inner tuple;
  35. for example, in a quad-tree there are always exactly four nodes
  36. corresponding to the four quadrants around the inner tuple's centroid
  37. point. In such a case the code typically works with the nodes by
  38. number, and there is no need for explicit node labels. To suppress
  39. node labels (and thereby save some space), the <code class="function">picksplit</code>
  40. function can return NULL for the <code class="structfield">nodeLabels</code> array,
  41. and likewise the <code class="function">choose</code> function can return NULL for
  42. the <code class="structfield">prefixNodeLabels</code> array during
  43. a <code class="literal">spgSplitTuple</code> action.
  44. This will in turn result in <code class="structfield">nodeLabels</code> being NULL during
  45. subsequent calls to <code class="function">choose</code> and <code class="function">inner_consistent</code>.
  46. In principle, node labels could be used for some inner tuples and omitted
  47. for others in the same index.
  48. </p><p>
  49. When working with an inner tuple having unlabeled nodes, it is an error
  50. for <code class="function">choose</code> to return <code class="literal">spgAddNode</code>, since the set
  51. of nodes is supposed to be fixed in such cases.
  52. </p></div><div class="sect2" id="SPGIST-ALL-THE-SAME"><div class="titlepage"><div><div><h3 class="title">65.4.3. <span class="quote">“<span class="quote">All-the-Same</span>”</span> Inner Tuples</h3></div></div></div><p>
  53. The <acronym class="acronym">SP-GiST</acronym> core can override the results of the
  54. operator class's <code class="function">picksplit</code> function when
  55. <code class="function">picksplit</code> fails to divide the supplied leaf values into
  56. at least two node categories. When this happens, the new inner tuple
  57. is created with multiple nodes that each have the same label (if any)
  58. that <code class="function">picksplit</code> gave to the one node it did use, and the
  59. leaf values are divided at random among these equivalent nodes.
  60. The <code class="literal">allTheSame</code> flag is set on the inner tuple to warn the
  61. <code class="function">choose</code> and <code class="function">inner_consistent</code> functions that the
  62. tuple does not have the node set that they might otherwise expect.
  63. </p><p>
  64. When dealing with an <code class="literal">allTheSame</code> tuple, a <code class="function">choose</code>
  65. result of <code class="literal">spgMatchNode</code> is interpreted to mean that the new
  66. value can be assigned to any of the equivalent nodes; the core code will
  67. ignore the supplied <code class="structfield">nodeN</code> value and descend into one
  68. of the nodes at random (so as to keep the tree balanced). It is an
  69. error for <code class="function">choose</code> to return <code class="literal">spgAddNode</code>, since
  70. that would make the nodes not all equivalent; the
  71. <code class="literal">spgSplitTuple</code> action must be used if the value to be inserted
  72. doesn't match the existing nodes.
  73. </p><p>
  74. When dealing with an <code class="literal">allTheSame</code> tuple, the
  75. <code class="function">inner_consistent</code> function should return either all or none
  76. of the nodes as targets for continuing the index search, since they are
  77. all equivalent. This may or may not require any special-case code,
  78. depending on how much the <code class="function">inner_consistent</code> function normally
  79. assumes about the meaning of the nodes.
  80. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="spgist-extensibility.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="spgist.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="spgist-examples.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">65.3. Extensibility </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 65.5. Examples</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1