mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Change ALTER TABLE SET WITHOUT OIDS to rewrite the whole table to physically
get rid of the OID column. This eliminates the problem discovered by Heikki back in November that 8.4's suppression of "unnecessary" junk filtering in INSERT/SELECT could lead to an Assert failure, or storing of oids into a table that shouldn't have them if Asserts are off. While that particular problem could have been solved in other ways, it seems likely to be just a forerunner of things to come if we continue to allow tables to contain rows that disagree with the pg_class.relhasoids setting. It's better to make this operation slow than to sacrifice performance or risk bugs in more common code paths. Also, add ALTER TABLE SET WITH OIDS to rewrite the table to add oids. This was a bit more controversial, but in view of the very small amount of extra code needed given the current ALTER TABLE infrastructure, it seems best to eliminate the asymmetry in features.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.103 2009/02/09 20:57:59 alvherre Exp $
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.104 2009/02/11 21:11:15 tgl Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@ -52,6 +52,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
ENABLE ALWAYS RULE <replaceable class="PARAMETER">rewrite_rule_name</replaceable>
|
||||
CLUSTER ON <replaceable class="PARAMETER">index_name</replaceable>
|
||||
SET WITHOUT CLUSTER
|
||||
SET WITH OIDS
|
||||
SET WITHOUT OIDS
|
||||
SET ( <replaceable class="PARAMETER">storage_parameter</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
|
||||
RESET ( <replaceable class="PARAMETER">storage_parameter</replaceable> [, ... ] )
|
||||
@ -185,7 +186,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
<listitem>
|
||||
<para>
|
||||
This form adds a new constraint to a table using the same syntax as
|
||||
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
|
||||
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -217,10 +218,10 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
The trigger firing mechanism is also affected by the configuration
|
||||
variable <xref linkend="guc-session-replication-role">. Simply enabled
|
||||
triggers will fire when the replication role is <quote>origin</>
|
||||
(the default) or <quote>local</>. Triggers configured <literal>ENABLE REPLICA</literal>
|
||||
will only fire if the session is in <quote>replica</> mode and triggers
|
||||
configured <literal>ENABLE ALWAYS</literal> will fire regardless of the current replication
|
||||
mode.
|
||||
(the default) or <quote>local</>. Triggers configured as <literal>ENABLE
|
||||
REPLICA</literal> will only fire if the session is in <quote>replica</>
|
||||
mode, and triggers configured as <literal>ENABLE ALWAYS</literal> will
|
||||
fire regardless of the current replication mode.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -243,7 +244,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
<term><literal>CLUSTER</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This form selects the default index for future
|
||||
This form selects the default index for future
|
||||
<xref linkend="SQL-CLUSTER" endterm="sql-cluster-title">
|
||||
operations. It does not actually re-cluster the table.
|
||||
</para>
|
||||
@ -262,6 +263,23 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>SET WITH OIDS</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This form adds an <literal>oid</literal> system column to the
|
||||
table (see <xref linkend="ddl-system-columns">).
|
||||
It does nothing if the table already has OIDs.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Note that this is not equivalent to <literal>ADD COLUMN oid oid</>;
|
||||
that would add a normal column that happened to be named
|
||||
<literal>oid</>, not a system column.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>SET WITHOUT OIDS</literal></term>
|
||||
<listitem>
|
||||
@ -272,12 +290,6 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
except that it will not complain if there is already no
|
||||
<literal>oid</literal> column.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Note that there is no variant of <command>ALTER TABLE</command>
|
||||
that allows OIDs to be restored to a table once they have been
|
||||
removed.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
@ -302,7 +314,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
in the <literal>WITH (<replaceable
|
||||
class="PARAMETER">storage_parameter</>)</literal> syntax,
|
||||
<command>ALTER TABLE</> does not treat <literal>OIDS</> as a
|
||||
storage parameter.
|
||||
storage parameter. Instead use the <literal>SET WITH OIDS</>
|
||||
and <literal>SET WITHOUT OIDS</> forms to change OID status.
|
||||
</para>
|
||||
</note>
|
||||
</listitem>
|
||||
@ -373,7 +386,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
moves the data file(s) associated with the table to the new tablespace.
|
||||
Indexes on the table, if any, are not moved; but they can be moved
|
||||
separately with additional <literal>SET TABLESPACE</literal> commands.
|
||||
See also
|
||||
See also
|
||||
<xref linkend="SQL-CREATETABLESPACE" endterm="sql-createtablespace-title">.
|
||||
</para>
|
||||
</listitem>
|
||||
@ -637,7 +650,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
Adding a column with a non-null default or changing the type of an
|
||||
existing column will require the entire table to be rewritten. This
|
||||
might take a significant amount of time for a large table; and it will
|
||||
temporarily require double the disk space.
|
||||
temporarily require double the disk space. Adding or removing a system
|
||||
<literal>oid</> column likewise requires rewriting the entire table.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@ -656,9 +670,11 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
||||
the column, but simply makes it invisible to SQL operations. Subsequent
|
||||
insert and update operations in the table will store a null value for the
|
||||
column. Thus, dropping a column is quick but it will not immediately
|
||||
reduce the on-disk size of your table, as the space occupied
|
||||
reduce the on-disk size of your table, as the space occupied
|
||||
by the dropped column is not reclaimed. The space will be
|
||||
reclaimed over time as existing rows are updated.
|
||||
reclaimed over time as existing rows are updated. (These statements do
|
||||
not apply when dropping the system <literal>oid</> column; that is done
|
||||
with an immediate rewrite.)
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@ -806,21 +822,21 @@ ALTER TABLE distributors ALTER COLUMN street DROP NOT NULL;
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To add a check constraint to a table and all its children:
|
||||
<programlisting>
|
||||
ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To remove a check constraint from a table and all its children:
|
||||
<programlisting>
|
||||
ALTER TABLE distributors DROP CONSTRAINT zipchk;
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To remove a check constraint from a table only:
|
||||
<programlisting>
|
||||
ALTER TABLE ONLY distributors DROP CONSTRAINT zipchk;
|
||||
@ -828,21 +844,21 @@ ALTER TABLE ONLY distributors DROP CONSTRAINT zipchk;
|
||||
(The check constraint remains in place for any child tables.)
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To add a foreign key constraint to a table:
|
||||
<programlisting>
|
||||
ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL;
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To add a (multicolumn) unique constraint to a table:
|
||||
<programlisting>
|
||||
ALTER TABLE distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, zipcode);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To add an automatically named primary key constraint to a table, noting
|
||||
that a table can only ever have one primary key:
|
||||
<programlisting>
|
||||
@ -850,14 +866,14 @@ ALTER TABLE distributors ADD PRIMARY KEY (dist_id);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To move a table to a different tablespace:
|
||||
<programlisting>
|
||||
ALTER TABLE distributors SET TABLESPACE fasttablespace;
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
To move a table to a different schema:
|
||||
<programlisting>
|
||||
ALTER TABLE myschema.distributors SET SCHEMA yourschema;
|
||||
|
Reference in New Issue
Block a user