Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0cb6556

Browse files
committed
Add exclusion constraints, which generalize the concept of uniqueness to
support any indexable commutative operator, not just equality. Two rows violate the exclusion constraint if "row1.col OP row2.col" is TRUE for each of the columns in the constraint. Jeff Davis, reviewed by Robert Haas
1 parent 8de7472 commit 0cb6556

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1610
-233
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.211 2009/11/20 20:38:09 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.212 2009/12/07 05:22:21 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -1536,11 +1536,7 @@
15361536
<entry><type>bool</type></entry>
15371537
<entry></entry>
15381538
<entry>
1539-
True if this is a table and it has (or recently had) any
1540-
indexes. This is set by <command>CREATE INDEX</command>, but
1541-
not cleared immediately by <command>DROP INDEX</command>.
1542-
<command>VACUUM</command> clears <structfield>relhasindex</> if it finds the
1543-
table has no indexes
1539+
True if this is a table and it has (or recently had) any indexes
15441540
</entry>
15451541
</row>
15461542

@@ -1617,6 +1613,17 @@
16171613
</entry>
16181614
</row>
16191615

1616+
<row>
1617+
<entry><structfield>relhasexclusion</structfield></entry>
1618+
<entry><type>bool</type></entry>
1619+
<entry></entry>
1620+
<entry>
1621+
For a table, true if the table has (or once had) any exclusion
1622+
constraints; for an index, true if the index supports an exclusion
1623+
constraint
1624+
</entry>
1625+
</row>
1626+
16201627
<row>
16211628
<entry><structfield>relhasrules</structfield></entry>
16221629
<entry><type>bool</type></entry>
@@ -1680,6 +1687,17 @@
16801687
</tbody>
16811688
</tgroup>
16821689
</table>
1690+
1691+
<para>
1692+
Several of the boolean flags in <structname>pg_class</> are maintained
1693+
lazily: they are guaranteed to be true if that's the correct state, but
1694+
may not be reset to false immediately when the condition is no longer
1695+
true. For example, <structfield>relhasindex</> is set by
1696+
<command>CREATE INDEX</command>, but it is never cleared by
1697+
<command>DROP INDEX</command>. Instead, <command>VACUUM</command> clears
1698+
<structfield>relhasindex</> if it finds the table has no indexes. This
1699+
arrangement avoids race conditions and improves concurrency.
1700+
</para>
16831701
</sect1>
16841702

16851703
<sect1 id="catalog-pg-constraint">
@@ -1690,11 +1708,12 @@
16901708
</indexterm>
16911709

16921710
<para>
1693-
The catalog <structname>pg_constraint</structname> stores check, primary key, unique, and foreign
1694-
key constraints on tables. (Column constraints are not treated
1695-
specially. Every column constraint is equivalent to some table
1696-
constraint.) Not-null constraints are represented in the
1697-
<structname>pg_attribute</> catalog.
1711+
The catalog <structname>pg_constraint</structname> stores check, primary
1712+
key, unique, foreign key, and exclusion constraints on tables.
1713+
(Column constraints are not treated specially. Every column constraint is
1714+
equivalent to some table constraint.)
1715+
Not-null constraints are represented in the <structname>pg_attribute</>
1716+
catalog, not here.
16981717
</para>
16991718

17001719
<para>
@@ -1739,7 +1758,8 @@
17391758
<literal>c</> = check constraint,
17401759
<literal>f</> = foreign key constraint,
17411760
<literal>p</> = primary key constraint,
1742-
<literal>u</> = unique constraint
1761+
<literal>u</> = unique constraint,
1762+
<literal>x</> = exclusion constraint
17431763
</entry>
17441764
</row>
17451765

@@ -1776,7 +1796,7 @@
17761796
<entry><type>oid</type></entry>
17771797
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
17781798
<entry>The index supporting this constraint, if it's a unique, primary
1779-
key, or foreign key constraint; else 0</entry>
1799+
key, foreign key, or exclusion constraint; else 0</entry>
17801800
</row>
17811801

17821802
<row>
@@ -1828,7 +1848,7 @@
18281848
<entry><type>bool</type></entry>
18291849
<entry></entry>
18301850
<entry>
1831-
This constraint is defined locally in the relation. Note that a
1851+
This constraint is defined locally for the relation. Note that a
18321852
constraint can be locally defined and inherited simultaneously
18331853
</entry>
18341854
</row>
@@ -1838,7 +1858,8 @@
18381858
<entry><type>int4</type></entry>
18391859
<entry></entry>
18401860
<entry>
1841-
The number of direct ancestors this constraint has. A constraint with
1861+
The number of direct inheritance ancestors this constraint has.
1862+
A constraint with
18421863
a nonzero number of ancestors cannot be dropped nor renamed
18431864
</entry>
18441865
</row>
@@ -1878,6 +1899,13 @@
18781899
<entry>If a foreign key, list of the equality operators for FK = FK comparisons</entry>
18791900
</row>
18801901

1902+
<row>
1903+
<entry><structfield>conexclop</structfield></entry>
1904+
<entry><type>oid[]</type></entry>
1905+
<entry><literal><link linkend="catalog-pg-operator"><structname>pg_operator</structname></link>.oid</></entry>
1906+
<entry>If an exclusion constraint, list of the per-column exclusion operators</entry>
1907+
</row>
1908+
18811909
<row>
18821910
<entry><structfield>conbin</structfield></entry>
18831911
<entry><type>text</type></entry>
@@ -1895,6 +1923,16 @@
18951923
</tgroup>
18961924
</table>
18971925

1926+
<para>
1927+
In the case of an exclusion constraint, <structfield>conkey</structfield>
1928+
is only useful for constraint elements that are simple column references.
1929+
For other cases, a zero appears in <structfield>conkey</structfield>
1930+
and the associated index must be consulted to discover the expression
1931+
that is constrained. (<structfield>conkey</structfield> thus has the
1932+
same contents as <structname>pg_index</>.<structfield>indkey</> for the
1933+
index.)
1934+
</para>
1935+
18981936
<note>
18991937
<para>
19001938
<structfield>consrc</structfield> is not updated when referenced objects
@@ -1908,7 +1946,8 @@
19081946
<para>
19091947
<literal>pg_class.relchecks</literal> needs to agree with the
19101948
number of check-constraint entries found in this table for each
1911-
relation.
1949+
relation. Also, <literal>pg_class.relhasexclusion</literal> must
1950+
be true if there are any exclusion-constraint entries for the relation.
19121951
</para>
19131952
</note>
19141953

doc/src/sgml/errcodes.sgml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.27 2009/03/04 10:55:00 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.28 2009/12/07 05:22:21 tgl Exp $ -->
22

33
<appendix id="errcodes-appendix">
44
<title><productname>PostgreSQL</productname> Error Codes</title>
@@ -640,6 +640,12 @@
640640
<entry>check_violation</entry>
641641
</row>
642642

643+
<row>
644+
<entry><literal>23P01</literal></entry>
645+
<entry>EXCLUSION VIOLATION</entry>
646+
<entry>exclusion_violation</entry>
647+
</row>
648+
643649

644650
<row>
645651
<entry spanname="span13"><emphasis role="bold">Class 24 &mdash; Invalid Cursor State</></entry>

0 commit comments

Comments
 (0)