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

Commit 6d1e361

Browse files
committed
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.
1 parent 68d95f1 commit 6d1e361

File tree

6 files changed

+260
-65
lines changed

6 files changed

+260
-65
lines changed

doc/src/sgml/ref/alter_table.sgml

+42-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.103 2009/02/09 20:57:59 alvherre Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.104 2009/02/11 21:11:15 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -52,6 +52,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
5252
ENABLE ALWAYS RULE <replaceable class="PARAMETER">rewrite_rule_name</replaceable>
5353
CLUSTER ON <replaceable class="PARAMETER">index_name</replaceable>
5454
SET WITHOUT CLUSTER
55+
SET WITH OIDS
5556
SET WITHOUT OIDS
5657
SET ( <replaceable class="PARAMETER">storage_parameter</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
5758
RESET ( <replaceable class="PARAMETER">storage_parameter</replaceable> [, ... ] )
@@ -185,7 +186,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
185186
<listitem>
186187
<para>
187188
This form adds a new constraint to a table using the same syntax as
188-
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
189+
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-TITLE">.
189190
</para>
190191
</listitem>
191192
</varlistentry>
@@ -217,10 +218,10 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
217218
The trigger firing mechanism is also affected by the configuration
218219
variable <xref linkend="guc-session-replication-role">. Simply enabled
219220
triggers will fire when the replication role is <quote>origin</>
220-
(the default) or <quote>local</>. Triggers configured <literal>ENABLE REPLICA</literal>
221-
will only fire if the session is in <quote>replica</> mode and triggers
222-
configured <literal>ENABLE ALWAYS</literal> will fire regardless of the current replication
223-
mode.
221+
(the default) or <quote>local</>. Triggers configured as <literal>ENABLE
222+
REPLICA</literal> will only fire if the session is in <quote>replica</>
223+
mode, and triggers configured as <literal>ENABLE ALWAYS</literal> will
224+
fire regardless of the current replication mode.
224225
</para>
225226
</listitem>
226227
</varlistentry>
@@ -243,7 +244,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
243244
<term><literal>CLUSTER</literal></term>
244245
<listitem>
245246
<para>
246-
This form selects the default index for future
247+
This form selects the default index for future
247248
<xref linkend="SQL-CLUSTER" endterm="sql-cluster-title">
248249
operations. It does not actually re-cluster the table.
249250
</para>
@@ -262,6 +263,23 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
262263
</listitem>
263264
</varlistentry>
264265

266+
<varlistentry>
267+
<term><literal>SET WITH OIDS</literal></term>
268+
<listitem>
269+
<para>
270+
This form adds an <literal>oid</literal> system column to the
271+
table (see <xref linkend="ddl-system-columns">).
272+
It does nothing if the table already has OIDs.
273+
</para>
274+
275+
<para>
276+
Note that this is not equivalent to <literal>ADD COLUMN oid oid</>;
277+
that would add a normal column that happened to be named
278+
<literal>oid</>, not a system column.
279+
</para>
280+
</listitem>
281+
</varlistentry>
282+
265283
<varlistentry>
266284
<term><literal>SET WITHOUT OIDS</literal></term>
267285
<listitem>
@@ -272,12 +290,6 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
272290
except that it will not complain if there is already no
273291
<literal>oid</literal> column.
274292
</para>
275-
276-
<para>
277-
Note that there is no variant of <command>ALTER TABLE</command>
278-
that allows OIDs to be restored to a table once they have been
279-
removed.
280-
</para>
281293
</listitem>
282294
</varlistentry>
283295

@@ -302,7 +314,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
302314
in the <literal>WITH (<replaceable
303315
class="PARAMETER">storage_parameter</>)</literal> syntax,
304316
<command>ALTER TABLE</> does not treat <literal>OIDS</> as a
305-
storage parameter.
317+
storage parameter. Instead use the <literal>SET WITH OIDS</>
318+
and <literal>SET WITHOUT OIDS</> forms to change OID status.
306319
</para>
307320
</note>
308321
</listitem>
@@ -373,7 +386,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
373386
moves the data file(s) associated with the table to the new tablespace.
374387
Indexes on the table, if any, are not moved; but they can be moved
375388
separately with additional <literal>SET TABLESPACE</literal> commands.
376-
See also
389+
See also
377390
<xref linkend="SQL-CREATETABLESPACE" endterm="sql-createtablespace-title">.
378391
</para>
379392
</listitem>
@@ -637,7 +650,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
637650
Adding a column with a non-null default or changing the type of an
638651
existing column will require the entire table to be rewritten. This
639652
might take a significant amount of time for a large table; and it will
640-
temporarily require double the disk space.
653+
temporarily require double the disk space. Adding or removing a system
654+
<literal>oid</> column likewise requires rewriting the entire table.
641655
</para>
642656

643657
<para>
@@ -656,9 +670,11 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
656670
the column, but simply makes it invisible to SQL operations. Subsequent
657671
insert and update operations in the table will store a null value for the
658672
column. Thus, dropping a column is quick but it will not immediately
659-
reduce the on-disk size of your table, as the space occupied
673+
reduce the on-disk size of your table, as the space occupied
660674
by the dropped column is not reclaimed. The space will be
661-
reclaimed over time as existing rows are updated.
675+
reclaimed over time as existing rows are updated. (These statements do
676+
not apply when dropping the system <literal>oid</> column; that is done
677+
with an immediate rewrite.)
662678
</para>
663679

664680
<para>
@@ -806,58 +822,58 @@ ALTER TABLE distributors ALTER COLUMN street DROP NOT NULL;
806822
</programlisting>
807823
</para>
808824

809-
<para>
825+
<para>
810826
To add a check constraint to a table and all its children:
811827
<programlisting>
812828
ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
813829
</programlisting>
814830
</para>
815831

816-
<para>
832+
<para>
817833
To remove a check constraint from a table and all its children:
818834
<programlisting>
819835
ALTER TABLE distributors DROP CONSTRAINT zipchk;
820836
</programlisting>
821837
</para>
822838

823-
<para>
839+
<para>
824840
To remove a check constraint from a table only:
825841
<programlisting>
826842
ALTER TABLE ONLY distributors DROP CONSTRAINT zipchk;
827843
</programlisting>
828844
(The check constraint remains in place for any child tables.)
829845
</para>
830846

831-
<para>
847+
<para>
832848
To add a foreign key constraint to a table:
833849
<programlisting>
834850
ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL;
835851
</programlisting>
836852
</para>
837853

838-
<para>
854+
<para>
839855
To add a (multicolumn) unique constraint to a table:
840856
<programlisting>
841857
ALTER TABLE distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, zipcode);
842858
</programlisting>
843859
</para>
844860

845-
<para>
861+
<para>
846862
To add an automatically named primary key constraint to a table, noting
847863
that a table can only ever have one primary key:
848864
<programlisting>
849865
ALTER TABLE distributors ADD PRIMARY KEY (dist_id);
850866
</programlisting>
851867
</para>
852868

853-
<para>
869+
<para>
854870
To move a table to a different tablespace:
855871
<programlisting>
856872
ALTER TABLE distributors SET TABLESPACE fasttablespace;
857873
</programlisting>
858874
</para>
859875

860-
<para>
876+
<para>
861877
To move a table to a different schema:
862878
<programlisting>
863879
ALTER TABLE myschema.distributors SET SCHEMA yourschema;

0 commit comments

Comments
 (0)