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

Commit a3dc8e4

Browse files
committed
Make partitions automatically inherit OIDs.
Previously, if the parent was specified as WITH OIDS, each child also had to be explicitly specified as WITH OIDS. Amit Langote, per a report from Simon Riggs. Some additional work on the documentation changes by me. Discussion: http://postgr.es/m/CANP8+jJBpWocfKrbJcaf3iBt9E3U=WPE_NC8YE6rye+YJ1sYnQ@mail.gmail.com
1 parent 0414b26 commit a3dc8e4

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

doc/src/sgml/ddl.sgml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,14 +2861,6 @@ VALUES ('Albany', NULL, NULL, 'NY');
28612861
</para>
28622862
</listitem>
28632863

2864-
<listitem>
2865-
<para>
2866-
If the partitioned table specified <literal>WITH OIDS</literal> then
2867-
each partition must also specify <literal>WITH OIDS</literal>. Oids
2868-
are not automatically inherited by partitions.
2869-
</para>
2870-
</listitem>
2871-
28722864
<listitem>
28732865
<para>
28742866
One cannot drop a <literal>NOT NULL</literal> constraint on a

doc/src/sgml/ref/create_table.sgml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,18 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
300300
</note>
301301

302302
<para>
303-
A partition cannot have columns other than those inherited from the
304-
parent. If the parent is specified <literal>WITH OIDS</literal> then
305-
the partitions must also explicitly specify <literal>WITH OIDS</literal>.
306-
Defaults and constraints can optionally be specified for each of the
307-
inherited columns. One can also specify table constraints in addition
308-
to those inherited from the parent. If a check constraint with the name
309-
matching one of the parent's constraint is specified, it is merged with
310-
the latter, provided the specified condition is same.
303+
A partition must have the same column names and types as the partitioned
304+
table to which it belongs. If the parent is specified <literal>WITH
305+
OIDS</literal> then all partitions must have OIDs; the parent's OID
306+
column will be inherited by all partitions just like any other column.
307+
Modifications to the column names or types of a partitioned table, or
308+
the addition or removal of an OID column, will automatically propagate
309+
to all partitions. <literal>CHECK</> constraints will be inherited
310+
automatically by every partition, but an individual partition may specify
311+
additional <literal>CHECK</> constraints; additional constraints with
312+
the same name and condition as in the parent will be merged with the
313+
parent constraint. Defaults may be specified separately for each
314+
partition.
311315
</para>
312316

313317
<para>
@@ -318,15 +322,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
318322
</para>
319323

320324
<para>
321-
A partition must have the same column names and types as the table of
322-
which it is a partition. Therefore, modifications to the column names
323-
or types of the partitioned table will automatically propagate to all
324-
children, as will operations such as TRUNCATE which normally affect a
325-
table and all of its inheritance children. It is also possible to
326-
TRUNCATE a partition individually, just as for an inheritance child.
327-
Note that dropping a partition with <literal>DROP TABLE</literal>
328-
requires taking an <literal>ACCESS EXCLUSIVE</literal> lock on the
329-
parent table.
325+
Operations such as TRUNCATE which normally affect a table and all of its
326+
inheritance children will cascade to all partitions, but may also be
327+
performed on an individual partition. Note that dropping a partition
328+
with <literal>DROP TABLE</literal> requires taking an <literal>ACCESS
329+
EXCLUSIVE</literal> lock on the parent table.
330330
</para>
331331
</listitem>
332332
</varlistentry>

src/backend/commands/tablecmds.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -634,19 +634,14 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
634634
relkind == RELKIND_PARTITIONED_TABLE));
635635
descriptor->tdhasoid = (localHasOids || parentOidCount > 0);
636636

637-
if (stmt->partbound)
638-
{
639-
/* If the parent has OIDs, partitions must have them too. */
640-
if (parentOidCount > 0 && !localHasOids)
641-
ereport(ERROR,
642-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
643-
errmsg("cannot create table without OIDs as partition of table with OIDs")));
644-
/* If the parent doesn't, partitions must not have them. */
645-
if (parentOidCount == 0 && localHasOids)
646-
ereport(ERROR,
647-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
648-
errmsg("cannot create table with OIDs as partition of table without OIDs")));
649-
}
637+
/*
638+
* If a partitioned table doesn't have the system OID column, then none
639+
* of its partitions should have it.
640+
*/
641+
if (stmt->partbound && parentOidCount == 0 && localHasOids)
642+
ereport(ERROR,
643+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
644+
errmsg("cannot create table with OIDs as partition of table without OIDs")));
650645

651646
/*
652647
* Find columns with default values and prepare for insertion of the

src/test/regress/expected/create_table.out

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,24 @@ DROP TABLE temp_parted;
524524
CREATE TABLE no_oids_parted (
525525
a int
526526
) PARTITION BY RANGE (a) WITHOUT OIDS;
527-
CREATE TABLE fail_part PARTITION OF no_oids_parted FOR VALUES FROM (1) TO (10 )WITH OIDS;
527+
CREATE TABLE fail_part PARTITION OF no_oids_parted FOR VALUES FROM (1) TO (10) WITH OIDS;
528528
ERROR: cannot create table with OIDs as partition of table without OIDs
529529
DROP TABLE no_oids_parted;
530-
-- likewise, the reverse if also true
530+
-- If the partitioned table has oids, then the partition must have them.
531+
-- If the WITHOUT OIDS option is specified for partition, it is overridden.
531532
CREATE TABLE oids_parted (
532533
a int
533534
) PARTITION BY RANGE (a) WITH OIDS;
534-
CREATE TABLE fail_part PARTITION OF oids_parted FOR VALUES FROM (1) TO (10 ) WITHOUT OIDS;
535-
ERROR: cannot create table without OIDs as partition of table with OIDs
536-
DROP TABLE oids_parted;
535+
CREATE TABLE part_forced_oids PARTITION OF oids_parted FOR VALUES FROM (1) TO (10) WITHOUT OIDS;
536+
\d+ part_forced_oids
537+
Table "public.part_forced_oids"
538+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
539+
--------+---------+-----------+----------+---------+---------+--------------+-------------
540+
a | integer | | not null | | plain | |
541+
Partition of: oids_parted FOR VALUES FROM (1) TO (10)
542+
Has OIDs: yes
543+
544+
DROP TABLE oids_parted, part_forced_oids;
537545
-- check for partition bound overlap and other invalid specifications
538546
CREATE TABLE list_parted2 (
539547
a varchar

src/test/regress/sql/create_table.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,17 @@ DROP TABLE temp_parted;
493493
CREATE TABLE no_oids_parted (
494494
a int
495495
) PARTITION BY RANGE (a) WITHOUT OIDS;
496-
CREATE TABLE fail_part PARTITION OF no_oids_parted FOR VALUES FROM (1) TO (10 )WITH OIDS;
496+
CREATE TABLE fail_part PARTITION OF no_oids_parted FOR VALUES FROM (1) TO (10) WITH OIDS;
497497
DROP TABLE no_oids_parted;
498498

499-
-- likewise, the reverse if also true
499+
-- If the partitioned table has oids, then the partition must have them.
500+
-- If the WITHOUT OIDS option is specified for partition, it is overridden.
500501
CREATE TABLE oids_parted (
501502
a int
502503
) PARTITION BY RANGE (a) WITH OIDS;
503-
CREATE TABLE fail_part PARTITION OF oids_parted FOR VALUES FROM (1) TO (10 ) WITHOUT OIDS;
504-
DROP TABLE oids_parted;
504+
CREATE TABLE part_forced_oids PARTITION OF oids_parted FOR VALUES FROM (1) TO (10) WITHOUT OIDS;
505+
\d+ part_forced_oids
506+
DROP TABLE oids_parted, part_forced_oids;
505507

506508
-- check for partition bound overlap and other invalid specifications
507509

0 commit comments

Comments
 (0)