⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xoper.sgml

📁 关系型数据库 Postgresql 6.5.2
💻 SGML
📖 第 1 页 / 共 2 页
字号:
    COMMUTATOR is for...)   </para>   <para>    Writing new restriction selectivity estimation functions is far beyond    the scope of this chapter, but fortunately you can usually just use    one of the system's standard estimators for many of your own operators.    These are the standard restriction estimators:   <ProgramListing>	eqsel		for =	neqsel		for &lt;&gt;	intltsel	for &lt; or &lt;=	intgtsel	for &gt; or &gt;=   </ProgramListing>    It might seem a little odd that these are the categories, but they    make sense if you think about it.  '=' will typically accept only    a small fraction of the rows in a table; '&lt;&gt;' will typically reject    only a small fraction.  '&lt;' will accept a fraction that depends on    where the given constant falls in the range of values for that table    column (which, it just so happens, is information collected by    VACUUM ANALYZE and made available to the selectivity estimator).    '&lt;=' will accept a slightly larger fraction than '&lt;' for the same    comparison constant, but they're close enough to not be worth    distinguishing, especially since we're not likely to do better than a    rough guess anyhow.  Similar remarks apply to '&gt;' and '&gt;='.   </para>   <para>    You can frequently get away with using either eqsel or neqsel for    operators that have very high or very low selectivity, even if they    aren't really equality or inequality.  For example, the regular expression    matching operators (~, ~*, etc) use eqsel on the assumption that they'll    usually only match a small fraction of the entries in a table.   </para>   </sect2>   <sect2>    <title>JOIN</title>    <para>     The JOIN clause, if provided, names a join selectivity     estimation function for the operator (note that this is a function     name, not an operator name).  JOIN clauses only make sense for     binary operators that return boolean.  The idea behind a join     selectivity estimator is to guess what fraction of the rows in a     pair of tables will satisfy a WHERE-clause condition of the form     <ProgramListing>                table1.field1 OP table2.field2     </ProgramListing>     for the current operator.  As with the RESTRICT clause, this helps     the optimizer very substantially by letting it figure out which     of several possible join sequences is likely to take the least work.    </para>    <para>     As before, this chapter will make no attempt to explain how to write     a join selectivity estimator function, but will just suggest that     you use one of the standard estimators if one is applicable:     <ProgramListing>	eqjoinsel	for =	neqjoinsel	for &lt;&gt;	intltjoinsel	for &lt; or &lt;=	intgtjoinsel	for &gt; or &gt;=    </ProgramListing>    </para>   </sect2>   <sect2>    <title>HASHES</title>    <para>     The HASHES clause, if present, tells the system that it is OK to     use the hash join method for a join based on this operator.  HASHES     only makes sense for binary operators that return boolean, and     in practice the operator had better be equality for some data type.    </para>    <para>     The assumption underlying hash join is that the join operator can     only return TRUE for pairs of left and right values that hash to the     same hash code.  If two values get put in different hash buckets, the     join will never compare them at all, implicitly assuming that the     result of the join operator must be FALSE.  So it never makes sense     to specify HASHES for operators that do not represent equality.    </para>    <para>     In fact, logical equality is not good enough either; the operator     had better represent pure bitwise equality, because the hash function     will be computed on the memory representation of the values regardless     of what the bits mean.  For example, equality of     time intervals is not bitwise equality; the interval equality operator     considers two time intervals equal if they have the same     duration, whether or not their endpoints are identical.  What this means     is that a join using "=" between interval fields would yield different     results if implemented as a hash join than if implemented another way,     because a large fraction of the pairs that should match will hash to     different values and will never be compared by the hash join.  But     if the optimizer chose to use a different kind of join, all the pairs     that the equality operator says are equal will be found.     We don't want that kind of inconsistency, so we don't mark interval     equality as hashable.    </para>    <para>     There are also machine-dependent ways in which a hash join might fail     to do the right thing.  For example, if your datatype     is a structure in which there may be uninteresting pad bits, it's unsafe     to mark the equality operator HASHES.  (Unless, perhaps, you write     your other operators to ensure that the unused bits are always zero.)     Another example is that the FLOAT datatypes are unsafe for hash     joins.  On machines that meet the IEEE floating point standard, minus     zero and plus zero are different values (different bit patterns) but     they are defined to compare equal.  So, if float equality were marked     HASHES, a minus zero and a plus zero would probably not be matched up     by a hash join, but they would be matched up by any other join process.    </para>    <para>     The bottom line is that you should probably only use HASHES for     equality operators that are (or could be) implemented by memcmp().    </para>   </sect2>   <sect2>    <title>SORT1 and SORT2</title>    <para>     The SORT clauses, if present, tell the system that it is permissible to use     the merge join method for a join based on the current operator.     Both must be specified if either is.  The current operator must be     equality for some pair of data types, and the SORT1 and SORT2 clauses     name the ordering operator ('<' operator) for the left and right-side     data types respectively.    </para>    <para>     Merge join is based on the idea of sorting the left and righthand tables     into order and then scanning them in parallel.  So, both data types must     be capable of being fully ordered, and the join operator must be one     that can only succeed for pairs of values that fall at the "same place"     in the sort order.  In practice this means that the join operator must     behave like equality.  But unlike hashjoin, where the left and right     data types had better be the same (or at least bitwise equivalent),     it is possible to mergejoin two     distinct data types so long as they are logically compatible.  For     example, the int2-versus-int4 equality operator is mergejoinable.     We only need sorting operators that will bring both datatypes into a     logically compatible sequence.    </para>    <para>     When specifying merge sort operators, the current operator and both     referenced operators must return boolean; the SORT1 operator must have     both input datatypes equal to the current operator's left argument type,     and the SORT2 operator must have     both input datatypes equal to the current operator's right argument type.     (As with COMMUTATOR and NEGATOR, this means that the operator name is     sufficient to specify the operator, and the system is able to make dummy     operator entries if you happen to define the equality operator before     the other ones.)    </para>    <para>     In practice you should only write SORT clauses for an '=' operator,     and the two referenced operators should always be named '<'.  Trying     to use merge join with operators named anything else will result in     hopeless confusion, for reasons we'll see in a moment.    </para>    <para>     There are additional restrictions on operators that you mark     mergejoinable.  These restrictions are not currently checked by     CREATE OPERATOR, but a merge join may fail at runtime if any are     not true:     <itemizedlist>      <listitem>       <para>	The mergejoinable equality operator must have a commutator	(itself if the two data types are the same, or a related equality operator	if they are different).       </para>      </listitem>      <listitem>       <para>	There must be '<' and '>' ordering operators having the same left and	right input datatypes as the mergejoinable operator itself.  These	operators <emphasis>must</emphasis> be named '<' and '>'; you do	not have any choice in the matter, since there is no provision for	specifying them explicitly.  Note that if the left and right data types	are different, neither of these operators is the same as either	SORT operator.  But they had better order the data values compatibly	with the SORT operators, or mergejoin will fail to work.       </para>      </listitem>     </itemizedlist>    </para>   </sect2>  </sect1> </Chapter><!-- Keep this comment at the end of the fileLocal variables:mode: sgmlsgml-omittag:nilsgml-shorttag:tsgml-minimize-attributes:nilsgml-always-quote-attributes:tsgml-indent-step:1sgml-indent-data:tsgml-parent-document:nilsgml-default-dtd-file:"./reference.ced"sgml-exposed-tags:nilsgml-local-catalogs:"/usr/lib/sgml/CATALOG"sgml-local-ecat-files:nilEnd:-->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -