gooderp18绿色标准版
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

69 lines
6.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>12.9. GIN and GiST Index Types</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="textsearch-debugging.html" title="12.8. Testing and Debugging Text Search" /><link rel="next" href="textsearch-psql.html" title="12.10. psql Support" /></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">12.9. GIN and GiST Index Types</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="textsearch-debugging.html" title="12.8. Testing and Debugging Text Search">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="textsearch.html" title="Chapter 12. Full Text Search">Up</a></td><th width="60%" align="center">Chapter 12. Full Text Search</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="textsearch-psql.html" title="12.10. psql Support">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="TEXTSEARCH-INDEXES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">12.9. GIN and GiST Index Types</h2></div></div></div><a id="id-1.5.11.12.2" class="indexterm"></a><p>
  3. There are two kinds of indexes that can be used to speed up full text
  4. searches.
  5. Note that indexes are not mandatory for full text searching, but in
  6. cases where a column is searched on a regular basis, an index is
  7. usually desirable.
  8. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  9. <a id="id-1.5.11.12.3.1.1.1.1" class="indexterm"></a>
  10. <code class="literal">CREATE INDEX <em class="replaceable"><code>name</code></em> ON <em class="replaceable"><code>table</code></em> USING GIN (<em class="replaceable"><code>column</code></em>);</code>
  11. </span></dt><dd><p>
  12. Creates a GIN (Generalized Inverted Index)-based index.
  13. The <em class="replaceable"><code>column</code></em> must be of <code class="type">tsvector</code> type.
  14. </p></dd><dt><span class="term">
  15. <a id="id-1.5.11.12.3.1.2.1.1" class="indexterm"></a>
  16. <code class="literal">CREATE INDEX <em class="replaceable"><code>name</code></em> ON <em class="replaceable"><code>table</code></em> USING GIST (<em class="replaceable"><code>column</code></em>);</code>
  17. </span></dt><dd><p>
  18. Creates a GiST (Generalized Search Tree)-based index.
  19. The <em class="replaceable"><code>column</code></em> can be of <code class="type">tsvector</code> or
  20. <code class="type">tsquery</code> type.
  21. </p></dd></dl></div><p>
  22. </p><p>
  23. GIN indexes are the preferred text search index type. As inverted
  24. indexes, they contain an index entry for each word (lexeme), with a
  25. compressed list of matching locations. Multi-word searches can find
  26. the first match, then use the index to remove rows that are lacking
  27. additional words. GIN indexes store only the words (lexemes) of
  28. <code class="type">tsvector</code> values, and not their weight labels. Thus a table
  29. row recheck is needed when using a query that involves weights.
  30. </p><p>
  31. A GiST index is <em class="firstterm">lossy</em>, meaning that the index
  32. might produce false matches, and it is necessary
  33. to check the actual table row to eliminate such false matches.
  34. (<span class="productname">PostgreSQL</span> does this automatically when needed.)
  35. GiST indexes are lossy because each document is represented in the
  36. index by a fixed-length signature. The signature is generated by hashing
  37. each word into a single bit in an n-bit string, with all these bits OR-ed
  38. together to produce an n-bit document signature. When two words hash to
  39. the same bit position there will be a false match. If all words in
  40. the query have matches (real or false) then the table row must be
  41. retrieved to see if the match is correct.
  42. </p><p>
  43. A GiST index can be covering, i.e. use the <code class="literal">INCLUDE</code>
  44. clause. Included columns can have data types without any GiST operator
  45. class. Included attributes will be stored uncompressed.
  46. </p><p>
  47. Lossiness causes performance degradation due to unnecessary fetches of table
  48. records that turn out to be false matches. Since random access to table
  49. records is slow, this limits the usefulness of GiST indexes. The
  50. likelihood of false matches depends on several factors, in particular the
  51. number of unique words, so using dictionaries to reduce this number is
  52. recommended.
  53. </p><p>
  54. Note that <acronym class="acronym">GIN</acronym> index build time can often be improved
  55. by increasing <a class="xref" href="runtime-config-resource.html#GUC-MAINTENANCE-WORK-MEM">maintenance_work_mem</a>, while
  56. <acronym class="acronym">GiST</acronym> index build time is not sensitive to that
  57. parameter.
  58. </p><p>
  59. Partitioning of big collections and the proper use of GIN and GiST indexes
  60. allows the implementation of very fast searches with online update.
  61. Partitioning can be done at the database level using table inheritance,
  62. or by distributing documents over
  63. servers and collecting external search results, e.g. via <a class="link" href="ddl-foreign-data.html" title="5.12. Foreign Data">Foreign Data</a> access.
  64. The latter is possible because ranking functions use
  65. only local information.
  66. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="textsearch-debugging.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="textsearch.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="textsearch-psql.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">12.8. Testing and Debugging Text Search </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 12.10. <span class="application">psql</span> Support</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1