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.

76 lines
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>F.7. btree_gist</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="btree-gin.html" title="F.6. btree_gin" /><link rel="next" href="citext.html" title="F.8. citext" /></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">F.7. btree_gist</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="btree-gin.html" title="F.6. btree_gin">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules</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="citext.html" title="F.8. citext">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="BTREE-GIST"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.7. btree_gist</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="btree-gist.html#id-1.11.7.16.7">F.7.1. Example Usage</a></span></dt><dt><span class="sect2"><a href="btree-gist.html#id-1.11.7.16.8">F.7.2. Authors</a></span></dt></dl></div><a id="id-1.11.7.16.2" class="indexterm"></a><p>
  3. <code class="filename">btree_gist</code> provides GiST index operator classes that
  4. implement B-tree equivalent behavior for the data types
  5. <code class="type">int2</code>, <code class="type">int4</code>, <code class="type">int8</code>, <code class="type">float4</code>,
  6. <code class="type">float8</code>, <code class="type">numeric</code>, <code class="type">timestamp with time zone</code>,
  7. <code class="type">timestamp without time zone</code>, <code class="type">time with time zone</code>,
  8. <code class="type">time without time zone</code>, <code class="type">date</code>, <code class="type">interval</code>,
  9. <code class="type">oid</code>, <code class="type">money</code>, <code class="type">char</code>,
  10. <code class="type">varchar</code>, <code class="type">text</code>, <code class="type">bytea</code>, <code class="type">bit</code>,
  11. <code class="type">varbit</code>, <code class="type">macaddr</code>, <code class="type">macaddr8</code>, <code class="type">inet</code>,
  12. <code class="type">cidr</code>, <code class="type">uuid</code>, and all <code class="type">enum</code> types.
  13. </p><p>
  14. In general, these operator classes will not outperform the equivalent
  15. standard B-tree index methods, and they lack one major feature of the
  16. standard B-tree code: the ability to enforce uniqueness. However,
  17. they provide some other features that are not available with a B-tree
  18. index, as described below. Also, these operator classes are useful
  19. when a multicolumn GiST index is needed, wherein some of the columns
  20. are of data types that are only indexable with GiST but other columns
  21. are just simple data types. Lastly, these operator classes are useful for
  22. GiST testing and as a base for developing other GiST operator classes.
  23. </p><p>
  24. In addition to the typical B-tree search operators, <code class="filename">btree_gist</code>
  25. also provides index support for <code class="literal">&lt;&gt;</code> (<span class="quote">“<span class="quote">not
  26. equals</span>”</span>). This may be useful in combination with an
  27. <a class="link" href="sql-createtable.html#SQL-CREATETABLE-EXCLUDE">exclusion constraint</a>,
  28. as described below.
  29. </p><p>
  30. Also, for data types for which there is a natural distance metric,
  31. <code class="filename">btree_gist</code> defines a distance operator <code class="literal">&lt;-&gt;</code>,
  32. and provides GiST index support for nearest-neighbor searches using
  33. this operator. Distance operators are provided for
  34. <code class="type">int2</code>, <code class="type">int4</code>, <code class="type">int8</code>, <code class="type">float4</code>,
  35. <code class="type">float8</code>, <code class="type">timestamp with time zone</code>,
  36. <code class="type">timestamp without time zone</code>,
  37. <code class="type">time without time zone</code>, <code class="type">date</code>, <code class="type">interval</code>,
  38. <code class="type">oid</code>, and <code class="type">money</code>.
  39. </p><div class="sect2" id="id-1.11.7.16.7"><div class="titlepage"><div><div><h3 class="title">F.7.1. Example Usage</h3></div></div></div><p>
  40. Simple example using <code class="literal">btree_gist</code> instead of <code class="literal">btree</code>:
  41. </p><pre class="programlisting">
  42. CREATE TABLE test (a int4);
  43. -- create index
  44. CREATE INDEX testidx ON test USING GIST (a);
  45. -- query
  46. SELECT * FROM test WHERE a &lt; 10;
  47. -- nearest-neighbor search: find the ten entries closest to "42"
  48. SELECT *, a &lt;-&gt; 42 AS dist FROM test ORDER BY a &lt;-&gt; 42 LIMIT 10;
  49. </pre><p>
  50. Use an <a class="link" href="sql-createtable.html#SQL-CREATETABLE-EXCLUDE">exclusion
  51. constraint</a> to enforce the rule that a cage at a zoo
  52. can contain only one kind of animal:
  53. </p><pre class="programlisting">
  54. =&gt; CREATE TABLE zoo (
  55. cage INTEGER,
  56. animal TEXT,
  57. EXCLUDE USING GIST (cage WITH =, animal WITH &lt;&gt;)
  58. );
  59. =&gt; INSERT INTO zoo VALUES(123, 'zebra');
  60. INSERT 0 1
  61. =&gt; INSERT INTO zoo VALUES(123, 'zebra');
  62. INSERT 0 1
  63. =&gt; INSERT INTO zoo VALUES(123, 'lion');
  64. ERROR: conflicting key value violates exclusion constraint "zoo_cage_animal_excl"
  65. DETAIL: Key (cage, animal)=(123, lion) conflicts with existing key (cage, animal)=(123, zebra).
  66. =&gt; INSERT INTO zoo VALUES(124, 'lion');
  67. INSERT 0 1
  68. </pre></div><div class="sect2" id="id-1.11.7.16.8"><div class="titlepage"><div><div><h3 class="title">F.7.2. Authors</h3></div></div></div><p>
  69. Teodor Sigaev (<code class="email">&lt;<a class="email" href="mailto:teodor@stack.net">teodor@stack.net</a>&gt;</code>),
  70. Oleg Bartunov (<code class="email">&lt;<a class="email" href="mailto:oleg@sai.msu.su">oleg@sai.msu.su</a>&gt;</code>),
  71. Janko Richter (<code class="email">&lt;<a class="email" href="mailto:jankorichter@yahoo.de">jankorichter@yahoo.de</a>&gt;</code>), and
  72. Paul Jungwirth (<code class="email">&lt;<a class="email" href="mailto:pj@illuminatedcomputing.com">pj@illuminatedcomputing.com</a>&gt;</code>). See
  73. <a class="ulink" href="http://www.sai.msu.su/~megera/postgres/gist/" target="_top">http://www.sai.msu.su/~megera/postgres/gist/</a>
  74. for additional information.
  75. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="btree-gin.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="citext.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.6. btree_gin </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.8. citext</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1