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.

64 line
7.3KB

  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>66.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="gin-extensibility.html" title="66.3. Extensibility" /><link rel="next" href="gin-tips.html" title="66.5. GIN Tips and Tricks" /></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">66.4. Implementation</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="gin-extensibility.html" title="66.3. Extensibility">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="gin.html" title="Chapter 66. GIN Indexes">Up</a></td><th width="60%" align="center">Chapter 66. GIN 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="gin-tips.html" title="66.5. GIN Tips and Tricks">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="GIN-IMPLEMENTATION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">66.4. Implementation</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="gin-implementation.html#GIN-FAST-UPDATE">66.4.1. GIN Fast Update Technique</a></span></dt><dt><span class="sect2"><a href="gin-implementation.html#GIN-PARTIAL-MATCH">66.4.2. Partial Match Algorithm</a></span></dt></dl></div><p>
  3. Internally, a <acronym class="acronym">GIN</acronym> index contains a B-tree index
  4. constructed over keys, where each key is an element of one or more indexed
  5. items (a member of an array, for example) and where each tuple in a leaf
  6. page contains either a pointer to a B-tree of heap pointers (a
  7. <span class="quote">“<span class="quote">posting tree</span>”</span>), or a simple list of heap pointers (a <span class="quote">“<span class="quote">posting
  8. list</span>”</span>) when the list is small enough to fit into a single index tuple along
  9. with the key value. <a class="xref" href="gin-implementation.html#GIN-INTERNALS-FIGURE" title="Figure 66.1. GIN Internals">Figure 66.1</a> illustrates
  10. these components of a GIN index.
  11. </p><p>
  12. As of <span class="productname">PostgreSQL</span> 9.1, null key values can be
  13. included in the index. Also, placeholder nulls are included in the index
  14. for indexed items that are null or contain no keys according to
  15. <code class="function">extractValue</code>. This allows searches that should find empty
  16. items to do so.
  17. </p><p>
  18. Multicolumn <acronym class="acronym">GIN</acronym> indexes are implemented by building
  19. a single B-tree over composite values (column number, key value). The
  20. key values for different columns can be of different types.
  21. </p><div class="figure" id="GIN-INTERNALS-FIGURE"><p class="title"><strong>Figure 66.1. GIN Internals</strong></p><div class="figure-contents"><div class="mediaobject"><object type="image/svg+xml" data="gin.svg" width="100%"></object></div></div></div><br class="figure-break" /><div class="sect2" id="GIN-FAST-UPDATE"><div class="titlepage"><div><div><h3 class="title">66.4.1. GIN Fast Update Technique</h3></div></div></div><p>
  22. Updating a <acronym class="acronym">GIN</acronym> index tends to be slow because of the
  23. intrinsic nature of inverted indexes: inserting or updating one heap row
  24. can cause many inserts into the index (one for each key extracted
  25. from the indexed item). As of <span class="productname">PostgreSQL</span> 8.4,
  26. <acronym class="acronym">GIN</acronym> is capable of postponing much of this work by inserting
  27. new tuples into a temporary, unsorted list of pending entries.
  28. When the table is vacuumed or autoanalyzed, or when
  29. <code class="function">gin_clean_pending_list</code> function is called, or if the
  30. pending list becomes larger than
  31. <a class="xref" href="runtime-config-client.html#GUC-GIN-PENDING-LIST-LIMIT">gin_pending_list_limit</a>, the entries are moved to the
  32. main <acronym class="acronym">GIN</acronym> data structure using the same bulk insert
  33. techniques used during initial index creation. This greatly improves
  34. <acronym class="acronym">GIN</acronym> index update speed, even counting the additional
  35. vacuum overhead. Moreover the overhead work can be done by a background
  36. process instead of in foreground query processing.
  37. </p><p>
  38. The main disadvantage of this approach is that searches must scan the list
  39. of pending entries in addition to searching the regular index, and so
  40. a large list of pending entries will slow searches significantly.
  41. Another disadvantage is that, while most updates are fast, an update
  42. that causes the pending list to become <span class="quote">“<span class="quote">too large</span>”</span> will incur an
  43. immediate cleanup cycle and thus be much slower than other updates.
  44. Proper use of autovacuum can minimize both of these problems.
  45. </p><p>
  46. If consistent response time is more important than update speed,
  47. use of pending entries can be disabled by turning off the
  48. <code class="literal">fastupdate</code> storage parameter for a
  49. <acronym class="acronym">GIN</acronym> index. See <a class="xref" href="sql-createindex.html" title="CREATE INDEX"><span class="refentrytitle">CREATE INDEX</span></a>
  50. for details.
  51. </p></div><div class="sect2" id="GIN-PARTIAL-MATCH"><div class="titlepage"><div><div><h3 class="title">66.4.2. Partial Match Algorithm</h3></div></div></div><p>
  52. GIN can support <span class="quote">“<span class="quote">partial match</span>”</span> queries, in which the query
  53. does not determine an exact match for one or more keys, but the possible
  54. matches fall within a reasonably narrow range of key values (within the
  55. key sorting order determined by the <code class="function">compare</code> support method).
  56. The <code class="function">extractQuery</code> method, instead of returning a key value
  57. to be matched exactly, returns a key value that is the lower bound of
  58. the range to be searched, and sets the <code class="literal">pmatch</code> flag true.
  59. The key range is then scanned using the <code class="function">comparePartial</code>
  60. method. <code class="function">comparePartial</code> must return zero for a matching
  61. index key, less than zero for a non-match that is still within the range
  62. to be searched, or greater than zero if the index key is past the range
  63. that could match.
  64. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="gin-extensibility.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="gin.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="gin-tips.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">66.3. Extensibility </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 66.5. GIN Tips and Tricks</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1