mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Allow foreign tables to participate in inheritance.
Foreign tables can now be inheritance children, or parents. Much of the system was already ready for this, but we had to fix a few things of course, mostly in the area of planner and executor handling of row locks. As side effects of this, allow foreign tables to have NOT VALID CHECK constraints (and hence to accept ALTER ... VALIDATE CONSTRAINT), and to accept ALTER SET STORAGE and ALTER SET WITH/WITHOUT OIDS. Continuing to disallow these things would've required bizarre and inconsistent special cases in inheritance behavior. Since foreign tables don't enforce CHECK constraints anyway, a NOT VALID one is a complete no-op, but that doesn't mean we shouldn't allow it. And it's possible that some FDWs might have use for SET STORAGE or SET WITH OIDS, though doubtless they will be no-ops for most. An additional change in support of this is that when a ModifyTable node has multiple target tables, they will all now be explicitly identified in EXPLAIN output, for example: Update on pt1 (cost=0.00..321.05 rows=3541 width=46) Update on pt1 Foreign Update on ft1 Foreign Update on ft2 Update on child3 -> Seq Scan on pt1 (cost=0.00..0.00 rows=1 width=46) -> Foreign Scan on ft1 (cost=100.00..148.03 rows=1170 width=46) -> Foreign Scan on ft2 (cost=100.00..148.03 rows=1170 width=46) -> Seq Scan on child3 (cost=0.00..25.00 rows=1200 width=46) This was done mainly to provide an unambiguous place to attach "Remote SQL" fields, but it is useful for inherited updates even when no foreign tables are involved. Shigeru Hanada and Etsuro Fujita, reviewed by Ashutosh Bapat and Kyotaro Horiguchi, some additional hacking by me
This commit is contained in:
@@ -23,6 +23,7 @@ CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name
|
||||
| <replaceable>table_constraint</replaceable> }
|
||||
[, ... ]
|
||||
] )
|
||||
[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
|
||||
SERVER <replaceable class="parameter">server_name</replaceable>
|
||||
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
|
||||
|
||||
@@ -120,6 +121,44 @@ CHECK ( <replaceable class="PARAMETER">expression</replaceable> )
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>COLLATE <replaceable>collation</replaceable></literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The <literal>COLLATE</> clause assigns a collation to
|
||||
the column (which must be of a collatable data type).
|
||||
If not specified, the column data type's default collation is used.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>INHERITS ( <replaceable>parent_table</replaceable> [, ... ] )</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The optional <literal>INHERITS</> clause specifies a list of
|
||||
tables from which the new foreign table automatically inherits
|
||||
all columns. Parent tables can be plain tables or foreign tables.
|
||||
See the similar form of
|
||||
<xref linkend="sql-createtable"> for more details.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable></literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
An optional name for a column or table constraint. If the
|
||||
constraint is violated, the constraint name is present in error messages,
|
||||
so constraint names like <literal>col must be positive</> can be used
|
||||
to communicate helpful constraint information to client applications.
|
||||
(Double-quotes are needed to specify constraint names that contain spaces.)
|
||||
If a constraint name is not specified, the system generates a name.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>NOT NULL</></term>
|
||||
<listitem>
|
||||
@@ -145,7 +184,7 @@ CHECK ( <replaceable class="PARAMETER">expression</replaceable> )
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>CHECK ( <replaceable class="PARAMETER">expression</replaceable> )</literal></term>
|
||||
<term><literal>CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) [ NO INHERIT ] </literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The <literal>CHECK</> clause specifies an expression producing a
|
||||
@@ -163,6 +202,11 @@ CHECK ( <replaceable class="PARAMETER">expression</replaceable> )
|
||||
current row. The system column <literal>tableoid</literal>
|
||||
may be referenced, but not any other system column.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
A constraint marked with <literal>NO INHERIT</> will not propagate to
|
||||
child tables.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
@@ -280,8 +324,9 @@ SERVER film_server;
|
||||
<acronym>SQL</acronym> standard; however, much as with
|
||||
<link linkend="sql-createtable"><command>CREATE TABLE</></link>,
|
||||
<literal>NULL</> constraints and zero-column foreign tables are permitted.
|
||||
The ability to specify a default value is also a <productname>PostgreSQL</>
|
||||
extension.
|
||||
The ability to specify column default values is also
|
||||
a <productname>PostgreSQL</> extension. Table inheritance, in the form
|
||||
defined by <productname>PostgreSQL</productname>, is nonstandard.
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
|
Reference in New Issue
Block a user