@@ -3948,6 +3948,44 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
39483948 One may then drop the constraint after <command>ATTACH PARTITION</command>
39493949 is finished, because it is no longer necessary.
39503950 </para>
3951+
3952+ <para>
3953+ As explained above, it is possible to create indexes on partitioned tables
3954+ and they are applied automatically to the entire hierarchy. This is very
3955+ convenient, as not only the existing partitions will become indexed, but
3956+ also any partitions that are created in the future will. One limitation is
3957+ that it's not possible to use the <literal>CONCURRENTLY</literal>
3958+ qualifier when creating such a partitioned index. To overcome long lock
3959+ times, it is possible to use <command>CREATE INDEX ON ONLY</command>
3960+ the partitioned table; such an index is marked invalid, and the partitions
3961+ do not get the index applied automatically. The indexes on partitions can
3962+ be created separately using <literal>CONCURRENTLY</literal>, and later
3963+ <firstterm>attached</firstterm> to the index on the parent using
3964+ <command>ALTER INDEX .. ATTACH PARTITION</command>. Once indexes for all
3965+ partitions are attached to the parent index, the parent index is marked
3966+ valid automatically. Example:
3967+ <programlisting>
3968+ CREATE INDEX measurement_usls_idx ON ONLY measurement (unitsales);
3969+
3970+ CREATE INDEX measurement_usls_200602_idx
3971+ ON measurement_y2006m02 (unitsales);
3972+ ALTER INDEX measurement_usls_idx
3973+ ATTACH PARTITION measurement_usls_200602_idx;
3974+ ...
3975+ </programlisting>
3976+
3977+ This technique can be used with <literal>UNIQUE</literal> and
3978+ <literal>PRIMARY KEY</literal> constraints too; the indexes are created
3979+ implicitly when the constraint is created. Example:
3980+ <programlisting>
3981+ ALTER TABLE ONLY measurement ADD UNIQUE (city_id, logdate);
3982+
3983+ ALTER TABLE measurement_y2006m02 ADD UNIQUE (city_id, logdate);
3984+ ALTER INDEX measurement_city_id_logdate_key
3985+ ATTACH PARTITION measurement_y2006m02_city_id_logdate_key;
3986+ ...
3987+ </programlisting>
3988+ </para>
39513989 </sect3>
39523990
39533991 <sect3 id="ddl-partitioning-declarative-limitations">
0 commit comments