@@ -3397,8 +3397,8 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
3397
3397
Declarative partitioning only supports range, list and hash
3398
3398
partitioning, whereas table inheritance allows data to be divided in a
3399
3399
manner of the user's choosing. (Note, however, that if constraint
3400
- exclusion is unable to prune partitions effectively, query performance
3401
- will be very poor.)
3400
+ exclusion is unable to prune child tables effectively, query performance
3401
+ might be poor.)
3402
3402
</para>
3403
3403
</listitem>
3404
3404
@@ -3420,16 +3420,16 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
3420
3420
3421
3421
<para>
3422
3422
We use the same <structname>measurement</structname> table we used
3423
- above. To implement it as a partitioned table using inheritance, use
3423
+ above. To implement partitioning using inheritance, use
3424
3424
the following steps:
3425
3425
3426
3426
<orderedlist spacing="compact">
3427
3427
<listitem>
3428
3428
<para>
3429
3429
Create the <quote>master</quote> table, from which all of the
3430
- partitions will inherit. This table will contain no data. Do not
3430
+ <quote>child</quote> tables will inherit. This table will contain no data. Do not
3431
3431
define any check constraints on this table, unless you intend them
3432
- to be applied equally to all partitions . There is no point in
3432
+ to be applied equally to all child tables . There is no point in
3433
3433
defining any indexes or unique constraints on it, either. For our
3434
3434
example, the master table is the <structname>measurement</structname>
3435
3435
table as originally defined.
@@ -3441,7 +3441,7 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
3441
3441
Create several <quote>child</quote> tables that each inherit from
3442
3442
the master table. Normally, these tables will not add any columns
3443
3443
to the set inherited from the master. Just as with declarative
3444
- partitioning, these partitions are in every way normal
3444
+ partitioning, these tables are in every way normal
3445
3445
<productname>PostgreSQL</productname> tables (or foreign tables).
3446
3446
</para>
3447
3447
@@ -3459,8 +3459,8 @@ CREATE TABLE measurement_y2008m01 () INHERITS (measurement);
3459
3459
3460
3460
<listitem>
3461
3461
<para>
3462
- Add non-overlapping table constraints to the partition tables to
3463
- define the allowed key values in each partition .
3462
+ Add non-overlapping table constraints to the child tables to
3463
+ define the allowed key values in each.
3464
3464
</para>
3465
3465
3466
3466
<para>
@@ -3471,18 +3471,18 @@ CHECK ( county IN ( 'Oxfordshire', 'Buckinghamshire', 'Warwickshire' ))
3471
3471
CHECK ( outletID >= 100 AND outletID < 200 )
3472
3472
</programlisting>
3473
3473
Ensure that the constraints guarantee that there is no overlap
3474
- between the key values permitted in different partitions . A common
3474
+ between the key values permitted in different child tables . A common
3475
3475
mistake is to set up range constraints like:
3476
3476
<programlisting>
3477
3477
CHECK ( outletID BETWEEN 100 AND 200 )
3478
3478
CHECK ( outletID BETWEEN 200 AND 300 )
3479
3479
</programlisting>
3480
- This is wrong since it is not clear which partition the key value
3481
- 200 belongs in.
3480
+ This is wrong since it is not clear which child table the key
3481
+ value 200 belongs in.
3482
3482
</para>
3483
3483
3484
3484
<para>
3485
- It would be better to instead create partitions as follows:
3485
+ It would be better to instead create child tables as follows:
3486
3486
3487
3487
<programlisting>
3488
3488
CREATE TABLE measurement_y2006m02 (
@@ -3511,7 +3511,7 @@ CREATE TABLE measurement_y2008m01 (
3511
3511
3512
3512
<listitem>
3513
3513
<para>
3514
- For each partition , create an index on the key column(s),
3514
+ For each child table , create an index on the key column(s),
3515
3515
as well as any other indexes you might want.
3516
3516
<programlisting>
3517
3517
CREATE INDEX measurement_y2006m02_logdate ON measurement_y2006m02 (logdate);
@@ -3527,9 +3527,9 @@ CREATE INDEX measurement_y2008m01_logdate ON measurement_y2008m01 (logdate);
3527
3527
<para>
3528
3528
We want our application to be able to say <literal>INSERT INTO
3529
3529
measurement ...</literal> and have the data be redirected into the
3530
- appropriate partition table. We can arrange that by attaching
3530
+ appropriate child table. We can arrange that by attaching
3531
3531
a suitable trigger function to the master table.
3532
- If data will be added only to the latest partition , we can
3532
+ If data will be added only to the latest child , we can
3533
3533
use a very simple trigger function:
3534
3534
3535
3535
<programlisting>
@@ -3555,13 +3555,13 @@ CREATE TRIGGER insert_measurement_trigger
3555
3555
</programlisting>
3556
3556
3557
3557
We must redefine the trigger function each month so that it always
3558
- points to the current partition . The trigger definition does
3558
+ points to the current child table . The trigger definition does
3559
3559
not need to be updated, however.
3560
3560
</para>
3561
3561
3562
3562
<para>
3563
3563
We might want to insert data and have the server automatically
3564
- locate the partition into which the row should be added. We
3564
+ locate the child table into which the row should be added. We
3565
3565
could do this with a more complex trigger function, for example:
3566
3566
3567
3567
<programlisting>
@@ -3589,7 +3589,7 @@ LANGUAGE plpgsql;
3589
3589
3590
3590
The trigger definition is the same as before.
3591
3591
Note that each <literal>IF</literal> test must exactly match the
3592
- <literal>CHECK</literal> constraint for its partition .
3592
+ <literal>CHECK</literal> constraint for its child table .
3593
3593
</para>
3594
3594
3595
3595
<para>
@@ -3600,16 +3600,16 @@ LANGUAGE plpgsql;
3600
3600
3601
3601
<note>
3602
3602
<para>
3603
- In practice it might be best to check the newest partition first,
3604
- if most inserts go into that partition . For simplicity we have
3603
+ In practice, it might be best to check the newest child first,
3604
+ if most inserts go into that child . For simplicity, we have
3605
3605
shown the trigger's tests in the same order as in other parts
3606
3606
of this example.
3607
3607
</para>
3608
3608
</note>
3609
3609
3610
3610
<para>
3611
3611
A different approach to redirecting inserts into the appropriate
3612
- partition table is to set up rules, instead of a trigger, on the
3612
+ child table is to set up rules, instead of a trigger, on the
3613
3613
master table. For example:
3614
3614
3615
3615
<programlisting>
@@ -3635,7 +3635,7 @@ DO INSTEAD
3635
3635
<para>
3636
3636
Be aware that <command>COPY</command> ignores rules. If you want to
3637
3637
use <command>COPY</command> to insert data, you'll need to copy into the
3638
- correct partition table rather than into the master. <command>COPY</command>
3638
+ correct child table rather than directly into the master. <command>COPY</command>
3639
3639
does fire triggers, so you can use it normally if you use the trigger
3640
3640
approach.
3641
3641
</para>
@@ -3651,33 +3651,33 @@ DO INSTEAD
3651
3651
<para>
3652
3652
Ensure that the <xref linkend="guc-constraint-exclusion"/>
3653
3653
configuration parameter is not disabled in
3654
- <filename>postgresql.conf</filename>.
3655
- If it is, queries will not be optimized as desired .
3654
+ <filename>postgresql.conf</filename>; otherwise
3655
+ child tables may be accessed unnecessarily .
3656
3656
</para>
3657
3657
</listitem>
3658
3658
</orderedlist>
3659
3659
</para>
3660
3660
3661
3661
<para>
3662
- As we can see, a complex partitioning scheme could require a
3662
+ As we can see, a complex table hierarchy could require a
3663
3663
substantial amount of DDL. In the above example we would be creating
3664
- a new partition each month, so it might be wise to write a script that
3664
+ a new child table each month, so it might be wise to write a script that
3665
3665
generates the required DDL automatically.
3666
3666
</para>
3667
3667
</sect3>
3668
3668
3669
3669
<sect3 id="ddl-partitioning-inheritance-maintenance">
3670
- <title>Partition Maintenance</title>
3670
+ <title>Maintenance for Inheritance Partitioning </title>
3671
3671
<para>
3672
- To remove old data quickly, simply drop the partition that is no longer
3672
+ To remove old data quickly, simply drop the child table that is no longer
3673
3673
necessary:
3674
3674
<programlisting>
3675
3675
DROP TABLE measurement_y2006m02;
3676
3676
</programlisting>
3677
3677
</para>
3678
3678
3679
3679
<para>
3680
- To remove the partition from the partitioned table but retain access to
3680
+ To remove the child table from the inheritance hierarchy table but retain access to
3681
3681
it as a table in its own right:
3682
3682
3683
3683
<programlisting>
@@ -3686,18 +3686,19 @@ ALTER TABLE measurement_y2006m02 NO INHERIT measurement;
3686
3686
</para>
3687
3687
3688
3688
<para>
3689
- To add a new partition to handle new data, create an empty partition
3690
- just as the original partitions were created above:
3689
+ To add a new child table to handle new data, create an empty child table
3690
+ just as the original children were created above:
3691
3691
3692
3692
<programlisting>
3693
3693
CREATE TABLE measurement_y2008m02 (
3694
3694
CHECK ( logdate >= DATE '2008-02-01' AND logdate < DATE '2008-03-01' )
3695
3695
) INHERITS (measurement);
3696
3696
</programlisting>
3697
3697
3698
- Alternatively, one may want to create the new table outside the partition
3699
- structure, and make it a partition after the data is loaded, checked,
3700
- and transformed.
3698
+ Alternatively, one may want to create and populate the new child table
3699
+ before adding it to the table hierarchy. This could allow data to be
3700
+ loaded, checked, and transformed before being made visible to queries on
3701
+ the parent table.
3701
3702
3702
3703
<programlisting>
3703
3704
CREATE TABLE measurement_y2008m02
@@ -3715,27 +3716,27 @@ ALTER TABLE measurement_y2008m02 INHERIT measurement;
3715
3716
<title>Caveats</title>
3716
3717
3717
3718
<para>
3718
- The following caveats apply to partitioned tables implemented using
3719
+ The following caveats apply to partitioning implemented using
3719
3720
inheritance:
3720
3721
<itemizedlist>
3721
3722
<listitem>
3722
3723
<para>
3723
3724
There is no automatic way to verify that all of the
3724
3725
<literal>CHECK</literal> constraints are mutually
3725
3726
exclusive. It is safer to create code that generates
3726
- partitions and creates and/or modifies associated objects than
3727
+ child tables and creates and/or modifies associated objects than
3727
3728
to write each by hand.
3728
3729
</para>
3729
3730
</listitem>
3730
3731
3731
3732
<listitem>
3732
3733
<para>
3733
- The schemes shown here assume that the partition key column(s)
3734
- of a row never change, or at least do not change enough to require
3735
- it to move to another partition. An <command>UPDATE</command> that attempts
3734
+ The schemes shown here assume that the values of a row's key column(s)
3735
+ never change, or at least do not change enough to require it to move to another partition.
3736
+ An <command>UPDATE</command> that attempts
3736
3737
to do that will fail because of the <literal>CHECK</literal> constraints.
3737
3738
If you need to handle such cases, you can put suitable update triggers
3738
- on the partition tables, but it makes management of the structure
3739
+ on the child tables, but it makes management of the structure
3739
3740
much more complicated.
3740
3741
</para>
3741
3742
</listitem>
@@ -3744,7 +3745,7 @@ ALTER TABLE measurement_y2008m02 INHERIT measurement;
3744
3745
<para>
3745
3746
If you are using manual <command>VACUUM</command> or
3746
3747
<command>ANALYZE</command> commands, don't forget that
3747
- you need to run them on each partition individually. A command like:
3748
+ you need to run them on each child table individually. A command like:
3748
3749
<programlisting>
3749
3750
ANALYZE measurement;
3750
3751
</programlisting>
@@ -3764,7 +3765,7 @@ ANALYZE measurement;
3764
3765
<listitem>
3765
3766
<para>
3766
3767
Triggers or rules will be needed to route rows to the desired
3767
- partition , unless the application is explicitly aware of the
3768
+ child table , unless the application is explicitly aware of the
3768
3769
partitioning scheme. Triggers may be complicated to write, and will
3769
3770
be much slower than the tuple routing performed internally by
3770
3771
declarative partitioning.
@@ -3935,7 +3936,7 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01';
3935
3936
<para>
3936
3937
<firstterm>Constraint exclusion</firstterm> is a query optimization
3937
3938
technique similar to partition pruning. While it is primarily used
3938
- for partitioned tables using the legacy inheritance method, it can be
3939
+ for partitioning implemented using the legacy inheritance method, it can be
3939
3940
used for other purposes, including with declarative partitioning.
3940
3941
</para>
3941
3942
@@ -3953,9 +3954,9 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01';
3953
3954
The fact that constraint exclusion uses <literal>CHECK</literal>
3954
3955
constraints, which makes it slow compared to partition pruning, can
3955
3956
sometimes be used as an advantage: because constraints can be defined
3956
- even on declaratively-partitioned tables, in addition to the internal
3957
- partitioning constraints, and only constraint exclusion would be able
3958
- to elide certain partitions from the query plan using those .
3957
+ even on declaratively-partitioned tables, in addition to their internal
3958
+ partition bounds, constraint exclusion may be able
3959
+ to elide additional partitions from the query plan.
3959
3960
</para>
3960
3961
3961
3962
<para>
@@ -3986,15 +3987,15 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01';
3986
3987
clause contains constants (or externally supplied parameters).
3987
3988
For example, a comparison against a non-immutable function such as
3988
3989
<function>CURRENT_TIMESTAMP</function> cannot be optimized, since the
3989
- planner cannot know which partition the function's value might fall
3990
+ planner cannot know which child table the function's value might fall
3990
3991
into at run time.
3991
3992
</para>
3992
3993
</listitem>
3993
3994
3994
3995
<listitem>
3995
3996
<para>
3996
3997
Keep the partitioning constraints simple, else the planner may not be
3997
- able to prove that partitions don't need to be visited. Use simple
3998
+ able to prove that child tables might not need to be visited. Use simple
3998
3999
equality conditions for list partitioning, or simple
3999
4000
range tests for range partitioning, as illustrated in the preceding
4000
4001
examples. A good rule of thumb is that partitioning constraints should
@@ -4006,11 +4007,11 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01';
4006
4007
4007
4008
<listitem>
4008
4009
<para>
4009
- All constraints on all partitions of the master table are examined
4010
- during constraint exclusion, so large numbers of partitions are likely
4010
+ All constraints on all children of the parent table are examined
4011
+ during constraint exclusion, so large numbers of children are likely
4011
4012
to increase query planning time considerably. So the legacy
4012
4013
inheritance based partitioning will work well with up to perhaps a
4013
- hundred partitions ; don't try to use many thousands of partitions .
4014
+ hundred child tables ; don't try to use many thousands of children .
4014
4015
</para>
4015
4016
</listitem>
4016
4017
0 commit comments