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 line
9.5KB

  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>63.2. Behavior of B-Tree Operator Classes</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-intro.html" title="63.1. Introduction" /><link rel="next" href="btree-support-funcs.html" title="63.3. B-Tree Support Functions" /></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">63.2. Behavior of B-Tree Operator Classes</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="btree-intro.html" title="63.1. Introduction">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="btree.html" title="Chapter 63. B-Tree Indexes">Up</a></td><th width="60%" align="center">Chapter 63. B-Tree 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="btree-support-funcs.html" title="63.3. B-Tree Support Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="BTREE-BEHAVIOR"><div class="titlepage"><div><div><h2 class="title" style="clear: both">63.2. Behavior of B-Tree Operator Classes</h2></div></div></div><p>
  3. As shown in <a class="xref" href="xindex.html#XINDEX-BTREE-STRAT-TABLE" title="Table 37.2. B-Tree Strategies">Table 37.2</a>, a btree operator
  4. class must provide five comparison operators,
  5. <code class="literal">&lt;</code>,
  6. <code class="literal">&lt;=</code>,
  7. <code class="literal">=</code>,
  8. <code class="literal">&gt;=</code> and
  9. <code class="literal">&gt;</code>.
  10. One might expect that <code class="literal">&lt;&gt;</code> should also be part of
  11. the operator class, but it is not, because it would almost never be
  12. useful to use a <code class="literal">&lt;&gt;</code> WHERE clause in an index
  13. search. (For some purposes, the planner treats <code class="literal">&lt;&gt;</code>
  14. as associated with a btree operator class; but it finds that operator via
  15. the <code class="literal">=</code> operator's negator link, rather than
  16. from <code class="structname">pg_amop</code>.)
  17. </p><p>
  18. When several data types share near-identical sorting semantics, their
  19. operator classes can be grouped into an operator family. Doing so is
  20. advantageous because it allows the planner to make deductions about
  21. cross-type comparisons. Each operator class within the family should
  22. contain the single-type operators (and associated support functions)
  23. for its input data type, while cross-type comparison operators and
  24. support functions are <span class="quote">“<span class="quote">loose</span>”</span> in the family. It is
  25. recommendable that a complete set of cross-type operators be included
  26. in the family, thus ensuring that the planner can represent any
  27. comparison conditions that it deduces from transitivity.
  28. </p><p>
  29. There are some basic assumptions that a btree operator family must
  30. satisfy:
  31. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  32. An <code class="literal">=</code> operator must be an equivalence relation; that
  33. is, for all non-null values <em class="replaceable"><code>A</code></em>,
  34. <em class="replaceable"><code>B</code></em>, <em class="replaceable"><code>C</code></em> of the
  35. data type:
  36. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
  37. <em class="replaceable"><code>A</code></em> <code class="literal">=</code>
  38. <em class="replaceable"><code>A</code></em> is true
  39. (<em class="firstterm">reflexive law</em>)
  40. </p></li><li class="listitem"><p>
  41. if <em class="replaceable"><code>A</code></em> <code class="literal">=</code>
  42. <em class="replaceable"><code>B</code></em>,
  43. then <em class="replaceable"><code>B</code></em> <code class="literal">=</code>
  44. <em class="replaceable"><code>A</code></em>
  45. (<em class="firstterm">symmetric law</em>)
  46. </p></li><li class="listitem"><p>
  47. if <em class="replaceable"><code>A</code></em> <code class="literal">=</code>
  48. <em class="replaceable"><code>B</code></em> and <em class="replaceable"><code>B</code></em>
  49. <code class="literal">=</code> <em class="replaceable"><code>C</code></em>,
  50. then <em class="replaceable"><code>A</code></em> <code class="literal">=</code>
  51. <em class="replaceable"><code>C</code></em>
  52. (<em class="firstterm">transitive law</em>)
  53. </p></li></ul></div><p>
  54. </p></li><li class="listitem"><p>
  55. A <code class="literal">&lt;</code> operator must be a strong ordering relation;
  56. that is, for all non-null values <em class="replaceable"><code>A</code></em>,
  57. <em class="replaceable"><code>B</code></em>, <em class="replaceable"><code>C</code></em>:
  58. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
  59. <em class="replaceable"><code>A</code></em> <code class="literal">&lt;</code>
  60. <em class="replaceable"><code>A</code></em> is false
  61. (<em class="firstterm">irreflexive law</em>)
  62. </p></li><li class="listitem"><p>
  63. if <em class="replaceable"><code>A</code></em> <code class="literal">&lt;</code>
  64. <em class="replaceable"><code>B</code></em>
  65. and <em class="replaceable"><code>B</code></em> <code class="literal">&lt;</code>
  66. <em class="replaceable"><code>C</code></em>,
  67. then <em class="replaceable"><code>A</code></em> <code class="literal">&lt;</code>
  68. <em class="replaceable"><code>C</code></em>
  69. (<em class="firstterm">transitive law</em>)
  70. </p></li></ul></div><p>
  71. </p></li><li class="listitem"><p>
  72. Furthermore, the ordering is total; that is, for all non-null
  73. values <em class="replaceable"><code>A</code></em>, <em class="replaceable"><code>B</code></em>:
  74. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
  75. exactly one of <em class="replaceable"><code>A</code></em> <code class="literal">&lt;</code>
  76. <em class="replaceable"><code>B</code></em>, <em class="replaceable"><code>A</code></em>
  77. <code class="literal">=</code> <em class="replaceable"><code>B</code></em>, and
  78. <em class="replaceable"><code>B</code></em> <code class="literal">&lt;</code>
  79. <em class="replaceable"><code>A</code></em> is true
  80. (<em class="firstterm">trichotomy law</em>)
  81. </p></li></ul></div><p>
  82. (The trichotomy law justifies the definition of the comparison support
  83. function, of course.)
  84. </p></li></ul></div><p>
  85. The other three operators are defined in terms of <code class="literal">=</code>
  86. and <code class="literal">&lt;</code> in the obvious way, and must act consistently
  87. with them.
  88. </p><p>
  89. For an operator family supporting multiple data types, the above laws must
  90. hold when <em class="replaceable"><code>A</code></em>, <em class="replaceable"><code>B</code></em>,
  91. <em class="replaceable"><code>C</code></em> are taken from any data types in the family.
  92. The transitive laws are the trickiest to ensure, as in cross-type
  93. situations they represent statements that the behaviors of two or three
  94. different operators are consistent.
  95. As an example, it would not work to put <code class="type">float8</code>
  96. and <code class="type">numeric</code> into the same operator family, at least not with
  97. the current semantics that <code class="type">numeric</code> values are converted
  98. to <code class="type">float8</code> for comparison to a <code class="type">float8</code>. Because
  99. of the limited accuracy of <code class="type">float8</code>, this means there are
  100. distinct <code class="type">numeric</code> values that will compare equal to the
  101. same <code class="type">float8</code> value, and thus the transitive law would fail.
  102. </p><p>
  103. Another requirement for a multiple-data-type family is that any implicit
  104. or binary-coercion casts that are defined between data types included in
  105. the operator family must not change the associated sort ordering.
  106. </p><p>
  107. It should be fairly clear why a btree index requires these laws to hold
  108. within a single data type: without them there is no ordering to arrange
  109. the keys with. Also, index searches using a comparison key of a
  110. different data type require comparisons to behave sanely across two
  111. data types. The extensions to three or more data types within a family
  112. are not strictly required by the btree index mechanism itself, but the
  113. planner relies on them for optimization purposes.
  114. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="btree-intro.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="btree.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="btree-support-funcs.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">63.1. Introduction </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 63.3. B-Tree Support Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1