gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

162 行
12KB

  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>61.1. Basic API Structure for Indexes</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="indexam.html" title="Chapter 61. Index Access Method Interface Definition" /><link rel="next" href="index-functions.html" title="61.2. Index Access Method 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">61.1. Basic API Structure for Indexes</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="indexam.html" title="Chapter 61. Index Access Method Interface Definition">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="indexam.html" title="Chapter 61. Index Access Method Interface Definition">Up</a></td><th width="60%" align="center">Chapter 61. Index Access Method Interface Definition</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="index-functions.html" title="61.2. Index Access Method Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="INDEX-API"><div class="titlepage"><div><div><h2 class="title" style="clear: both">61.1. Basic API Structure for Indexes</h2></div></div></div><p>
  3. Each index access method is described by a row in the
  4. <a class="link" href="catalog-pg-am.html" title="51.3. pg_am"><code class="structname">pg_am</code></a>
  5. system catalog. The <code class="structname">pg_am</code> entry
  6. specifies a name and a <em class="firstterm">handler function</em> for the index
  7. access method. These entries can be created and deleted using the
  8. <a class="xref" href="sql-create-access-method.html" title="CREATE ACCESS METHOD"><span class="refentrytitle">CREATE ACCESS METHOD</span></a> and
  9. <a class="xref" href="sql-drop-access-method.html" title="DROP ACCESS METHOD"><span class="refentrytitle">DROP ACCESS METHOD</span></a> SQL commands.
  10. </p><p>
  11. An index access method handler function must be declared to accept a
  12. single argument of type <code class="type">internal</code> and to return the
  13. pseudo-type <code class="type">index_am_handler</code>. The argument is a dummy value that
  14. simply serves to prevent handler functions from being called directly from
  15. SQL commands. The result of the function must be a palloc'd struct of
  16. type <code class="structname">IndexAmRoutine</code>, which contains everything
  17. that the core code needs to know to make use of the index access method.
  18. The <code class="structname">IndexAmRoutine</code> struct, also called the access
  19. method's <em class="firstterm">API struct</em>, includes fields specifying assorted
  20. fixed properties of the access method, such as whether it can support
  21. multicolumn indexes. More importantly, it contains pointers to support
  22. functions for the access method, which do all of the real work to access
  23. indexes. These support functions are plain C functions and are not
  24. visible or callable at the SQL level. The support functions are described
  25. in <a class="xref" href="index-functions.html" title="61.2. Index Access Method Functions">Section 61.2</a>.
  26. </p><p>
  27. The structure <code class="structname">IndexAmRoutine</code> is defined thus:
  28. </p><pre class="programlisting">
  29. typedef struct IndexAmRoutine
  30. {
  31. NodeTag type;
  32. /*
  33. * Total number of strategies (operators) by which we can traverse/search
  34. * this AM. Zero if AM does not have a fixed set of strategy assignments.
  35. */
  36. uint16 amstrategies;
  37. /* total number of support functions that this AM uses */
  38. uint16 amsupport;
  39. /* does AM support ORDER BY indexed column's value? */
  40. bool amcanorder;
  41. /* does AM support ORDER BY result of an operator on indexed column? */
  42. bool amcanorderbyop;
  43. /* does AM support backward scanning? */
  44. bool amcanbackward;
  45. /* does AM support UNIQUE indexes? */
  46. bool amcanunique;
  47. /* does AM support multi-column indexes? */
  48. bool amcanmulticol;
  49. /* does AM require scans to have a constraint on the first index column? */
  50. bool amoptionalkey;
  51. /* does AM handle ScalarArrayOpExpr quals? */
  52. bool amsearcharray;
  53. /* does AM handle IS NULL/IS NOT NULL quals? */
  54. bool amsearchnulls;
  55. /* can index storage data type differ from column data type? */
  56. bool amstorage;
  57. /* can an index of this type be clustered on? */
  58. bool amclusterable;
  59. /* does AM handle predicate locks? */
  60. bool ampredlocks;
  61. /* does AM support parallel scan? */
  62. bool amcanparallel;
  63. /* does AM support columns included with clause INCLUDE? */
  64. bool amcaninclude;
  65. /* type of data stored in index, or InvalidOid if variable */
  66. Oid amkeytype;
  67. /* interface functions */
  68. ambuild_function ambuild;
  69. ambuildempty_function ambuildempty;
  70. aminsert_function aminsert;
  71. ambulkdelete_function ambulkdelete;
  72. amvacuumcleanup_function amvacuumcleanup;
  73. amcanreturn_function amcanreturn; /* can be NULL */
  74. amcostestimate_function amcostestimate;
  75. amoptions_function amoptions;
  76. amproperty_function amproperty; /* can be NULL */
  77. ambuildphasename_function ambuildphasename; /* can be NULL */
  78. amvalidate_function amvalidate;
  79. ambeginscan_function ambeginscan;
  80. amrescan_function amrescan;
  81. amgettuple_function amgettuple; /* can be NULL */
  82. amgetbitmap_function amgetbitmap; /* can be NULL */
  83. amendscan_function amendscan;
  84. ammarkpos_function ammarkpos; /* can be NULL */
  85. amrestrpos_function amrestrpos; /* can be NULL */
  86. /* interface functions to support parallel index scans */
  87. amestimateparallelscan_function amestimateparallelscan; /* can be NULL */
  88. aminitparallelscan_function aminitparallelscan; /* can be NULL */
  89. amparallelrescan_function amparallelrescan; /* can be NULL */
  90. } IndexAmRoutine;
  91. </pre><p>
  92. </p><p>
  93. To be useful, an index access method must also have one or more
  94. <em class="firstterm">operator families</em> and
  95. <em class="firstterm">operator classes</em> defined in
  96. <a class="link" href="catalog-pg-opfamily.html" title="51.35. pg_opfamily"><code class="structname">pg_opfamily</code></a>,
  97. <a class="link" href="catalog-pg-opclass.html" title="51.33. pg_opclass"><code class="structname">pg_opclass</code></a>,
  98. <a class="link" href="catalog-pg-amop.html" title="51.4. pg_amop"><code class="structname">pg_amop</code></a>, and
  99. <a class="link" href="catalog-pg-amproc.html" title="51.5. pg_amproc"><code class="structname">pg_amproc</code></a>.
  100. These entries allow the planner
  101. to determine what kinds of query qualifications can be used with
  102. indexes of this access method. Operator families and classes are described
  103. in <a class="xref" href="xindex.html" title="37.16. Interfacing Extensions to Indexes">Section 37.16</a>, which is prerequisite material for reading
  104. this chapter.
  105. </p><p>
  106. An individual index is defined by a
  107. <a class="link" href="catalog-pg-class.html" title="51.11. pg_class"><code class="structname">pg_class</code></a>
  108. entry that describes it as a physical relation, plus a
  109. <a class="link" href="catalog-pg-index.html" title="51.26. pg_index"><code class="structname">pg_index</code></a>
  110. entry that shows the logical content of the index — that is, the set
  111. of index columns it has and the semantics of those columns, as captured by
  112. the associated operator classes. The index columns (key values) can be
  113. either simple columns of the underlying table or expressions over the table
  114. rows. The index access method normally has no interest in where the index
  115. key values come from (it is always handed precomputed key values) but it
  116. will be very interested in the operator class information in
  117. <code class="structname">pg_index</code>. Both of these catalog entries can be
  118. accessed as part of the <code class="structname">Relation</code> data structure that is
  119. passed to all operations on the index.
  120. </p><p>
  121. Some of the flag fields of <code class="structname">IndexAmRoutine</code> have nonobvious
  122. implications. The requirements of <code class="structfield">amcanunique</code>
  123. are discussed in <a class="xref" href="index-unique-checks.html" title="61.5. Index Uniqueness Checks">Section 61.5</a>.
  124. The <code class="structfield">amcanmulticol</code> flag asserts that the
  125. access method supports multicolumn indexes, while
  126. <code class="structfield">amoptionalkey</code> asserts that it allows scans
  127. where no indexable restriction clause is given for the first index column.
  128. When <code class="structfield">amcanmulticol</code> is false,
  129. <code class="structfield">amoptionalkey</code> essentially says whether the
  130. access method supports full-index scans without any restriction clause.
  131. Access methods that support multiple index columns <span class="emphasis"><em>must</em></span>
  132. support scans that omit restrictions on any or all of the columns after
  133. the first; however they are permitted to require some restriction to
  134. appear for the first index column, and this is signaled by setting
  135. <code class="structfield">amoptionalkey</code> false.
  136. One reason that an index AM might set
  137. <code class="structfield">amoptionalkey</code> false is if it doesn't index
  138. null values. Since most indexable operators are
  139. strict and hence cannot return true for null inputs,
  140. it is at first sight attractive to not store index entries for null values:
  141. they could never be returned by an index scan anyway. However, this
  142. argument fails when an index scan has no restriction clause for a given
  143. index column. In practice this means that
  144. indexes that have <code class="structfield">amoptionalkey</code> true must
  145. index nulls, since the planner might decide to use such an index
  146. with no scan keys at all. A related restriction is that an index
  147. access method that supports multiple index columns <span class="emphasis"><em>must</em></span>
  148. support indexing null values in columns after the first, because the planner
  149. will assume the index can be used for queries that do not restrict
  150. these columns. For example, consider an index on (a,b) and a query with
  151. <code class="literal">WHERE a = 4</code>. The system will assume the index can be
  152. used to scan for rows with <code class="literal">a = 4</code>, which is wrong if the
  153. index omits rows where <code class="literal">b</code> is null.
  154. It is, however, OK to omit rows where the first indexed column is null.
  155. An index access method that does index nulls may also set
  156. <code class="structfield">amsearchnulls</code>, indicating that it supports
  157. <code class="literal">IS NULL</code> and <code class="literal">IS NOT NULL</code> clauses as search
  158. conditions.
  159. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="indexam.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="indexam.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="index-functions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 61. Index Access Method Interface Definition </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 61.2. Index Access Method Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1