can be used for several different index methods (for example, both B-tree
and hash index methods have operator classes named
<literal>int4_ops</literal>), but each such class is an independent
entity and must be defined separately.
</para>
</sect2>
<sect2 id="xindex-strategies">
<title>Index Method Strategies</title>
<para>
The operators associated with an operator class are identified by
<quote>strategy numbers</quote>, which serve to identify the semantics of
each operator within the context of its operator class.
For example, B-trees impose a strict ordering on keys, lesser to greater,
and so operators like <quote>less than</quote> and <quote>greater than or equal
to</quote> are interesting with respect to a B-tree.
Because
<productname>PostgreSQL</productname> allows the user to define operators,
<productname>PostgreSQL</productname> cannot look at the name of an operator
(e.g., <literal><</literal> or <literal>>=</literal>) and tell what kind of
comparison it is. Instead, the index method defines a set of
<quote>strategies</quote>, which can be thought of as generalized operators.
Each operator class specifies which actual operator corresponds to each
strategy for a particular data type and interpretation of the index
semantics.
</para>
<para>
The B-tree index method defines five strategies, shown in <xref
linkend="xindex-btree-strat-table"/>.
</para>
<table tocentry="1" id="xindex-btree-strat-table">
<title>B-Tree Strategies</title>
<tgroup cols="2">
<thead>
<row>
<entry>Operation</entry>
<entry>Strategy Number</entry>
</row>
</thead>
<tbody>
<row>
<entry>less than</entry>
<entry>1</entry>
</row>
<row>
<entry>less than or equal</entry>
<entry>2</entry>
</row>
<row>
<entry>equal</entry>
<entry>3</entry>
</row>
<row>
<entry>greater than or equal</entry>
<entry>4</entry>
</row>
<row>
<entry>greater than</entry>
<entry>5</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Hash indexes support only equality comparisons, and so they use only one
strategy, shown in <xref linkend="xindex-hash-strat-table"/>.
</para>
<table tocentry="1" id="xindex-hash-strat-table">
<title>Hash Strategies</title>
<tgroup cols="2">
<thead>
<row>
<entry>Operation</entry>
<entry>Strategy Number</entry>
</row>
</thead>
<tbody>
<row>
<entry>equal</entry>
<entry>1</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
GiST indexes are more flexible: they do not have a fixed set of
strategies at all. Instead, the <quote>consistency</quote> support routine
of each particular GiST operator class interprets the strategy numbers
however it likes. As an example, several of the built-in GiST index
operator classes index two-dimensional geometric objects, providing
the <quote>R-tree</quote> strategies shown in
<xref linkend="xindex-rtree-strat-table"/>. Four of these are true
two-dimensional tests (overlaps, same, contains, contained by);
four of them consider only the X direction; and the other four
provide the same tests in the Y direction.
</para>
<table tocentry="1" id="xindex-rtree-strat-table">
<title>GiST Two-Dimensional <quote>R-tree</quote> Strategies</title>
<tgroup cols="2">
<thead>
<row>
<entry>Operation</entry>
<entry>Strategy Number</entry>
</row>
</thead>
<tbody>
<row>
<entry>strictly left of</entry>
<entry>1</entry>
</row>
<row>
<entry>does not extend to right of</entry>
<entry>2</entry>
</row>
<row>
<entry>overlaps</entry>
<entry>3</entry>
</row>
<row>
<entry>does not extend to left of</entry>