mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Extend ALTER OPERATOR to allow setting more optimization attributes.
Allow the COMMUTATOR, NEGATOR, MERGES, and HASHES attributes to be set by ALTER OPERATOR. However, we don't allow COMMUTATOR/NEGATOR to be changed once set, nor allow the MERGES/HASHES flags to be unset once set. Changes like that might invalidate plans already made, and dealing with the consequences seems like more trouble than it's worth. The main use-case we foresee for this is to allow addition of missed properties in extension update scripts, such as extending an existing operator to support hashing. So only transitions from not-set to set states seem very useful. This patch also causes us to reject some incorrect cases that formerly resulted in inconsistent catalog state, such as trying to set the commutator of an operator to be some other operator that already has a (different) commutator. While at it, move the InvokeObjectPostCreateHook call for CREATE OPERATOR to not occur until after we've fixed up commutator or negator links as needed. The previous ordering could only be justified by thinking of the OperatorUpd call as a kind of ALTER OPERATOR step; but we don't call InvokeObjectPostAlterHook therein. It seems better to let the hook see the final state of the operator object. In the documentation, move the discussion of how to establish commutator pairs from xoper.sgml to the CREATE OPERATOR ref page. Tommy Pavlicek, reviewed and editorialized a bit by me Discussion: https://postgr.es/m/CAEhP-W-vGVzf4udhR5M8Bdv88UYnPrhoSkj3ieR3QNrsGQoqdg@mail.gmail.com
This commit is contained in:
@@ -30,7 +30,11 @@ ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</repla
|
||||
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , <replaceable>right_type</replaceable> )
|
||||
SET ( { RESTRICT = { <replaceable class="parameter">res_proc</replaceable> | NONE }
|
||||
| JOIN = { <replaceable class="parameter">join_proc</replaceable> | NONE }
|
||||
} [, ... ] )
|
||||
| COMMUTATOR = <replaceable class="parameter">com_op</replaceable>
|
||||
| NEGATOR = <replaceable class="parameter">neg_op</replaceable>
|
||||
| HASHES
|
||||
| MERGES
|
||||
} [, ... ] )
|
||||
</synopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
@@ -121,9 +125,69 @@ ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</repla
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">com_op</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The commutator of this operator. Can only be changed if the operator
|
||||
does not have an existing commutator.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">neg_op</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The negator of this operator. Can only be changed if the operator does
|
||||
not have an existing negator.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>HASHES</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Indicates this operator can support a hash join. Can only be enabled and
|
||||
not disabled.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>MERGES</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Indicates this operator can support a merge join. Can only be enabled
|
||||
and not disabled.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Notes</title>
|
||||
|
||||
<para>
|
||||
Refer to <xref linkend="xoper"/> and
|
||||
<xref linkend="xoper-optimization"/> for further information.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Since commutators come in pairs that are commutators of each other,
|
||||
<literal>ALTER OPERATOR SET COMMUTATOR</literal> will also set the
|
||||
commutator of the <replaceable class="parameter">com_op</replaceable>
|
||||
to be the target operator. Likewise, <literal>ALTER OPERATOR SET
|
||||
NEGATOR</literal> will also set the negator of
|
||||
the <replaceable class="parameter">neg_op</replaceable> to be the
|
||||
target operator. Therefore, you must own the commutator or negator
|
||||
operator as well as the target operator.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
@@ -131,13 +195,25 @@ ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</repla
|
||||
Change the owner of a custom operator <literal>a @@ b</literal> for type <type>text</type>:
|
||||
<programlisting>
|
||||
ALTER OPERATOR @@ (text, text) OWNER TO joe;
|
||||
</programlisting></para>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Change the restriction and join selectivity estimator functions of a custom operator <literal>a && b</literal> for type <type>int[]</type>:
|
||||
Change the restriction and join selectivity estimator functions of a
|
||||
custom operator <literal>a && b</literal> for
|
||||
type <type>int[]</type>:
|
||||
<programlisting>
|
||||
ALTER OPERATOR && (_int4, _int4) SET (RESTRICT = _int_contsel, JOIN = _int_contjoinsel);
|
||||
</programlisting></para>
|
||||
ALTER OPERATOR && (int[], int[]) SET (RESTRICT = _int_contsel, JOIN = _int_contjoinsel);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Mark the <literal>&&</literal> operator as being its own
|
||||
commutator:
|
||||
<programlisting>
|
||||
ALTER OPERATOR && (int[], int[]) SET (COMMUTATOR = &&);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
|
||||
|
Reference in New Issue
Block a user