@@ -3331,6 +3331,44 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
3331
3331
One may then drop the constraint after <command>ATTACH PARTITION</command>
3332
3332
is finished, because it is no longer necessary.
3333
3333
</para>
3334
+
3335
+ <para>
3336
+ As explained above, it is possible to create indexes on partitioned tables
3337
+ and they are applied automatically to the entire hierarchy. This is very
3338
+ convenient, as not only the existing partitions will become indexed, but
3339
+ also any partitions that are created in the future will. One limitation is
3340
+ that it's not possible to use the <literal>CONCURRENTLY</literal>
3341
+ qualifier when creating such a partitioned index. To overcome long lock
3342
+ times, it is possible to use <command>CREATE INDEX ON ONLY</command>
3343
+ the partitioned table; such an index is marked invalid, and the partitions
3344
+ do not get the index applied automatically. The indexes on partitions can
3345
+ be created separately using <literal>CONCURRENTLY</literal>, and later
3346
+ <firstterm>attached</firstterm> to the index on the parent using
3347
+ <command>ALTER INDEX .. ATTACH PARTITION</command>. Once indexes for all
3348
+ partitions are attached to the parent index, the parent index is marked
3349
+ valid automatically. Example:
3350
+ <programlisting>
3351
+ CREATE INDEX measurement_usls_idx ON ONLY measurement (unitsales);
3352
+
3353
+ CREATE INDEX measurement_usls_200602_idx
3354
+ ON measurement_y2006m02 (unitsales);
3355
+ ALTER INDEX measurement_usls_idx
3356
+ ATTACH PARTITION measurement_usls_200602_idx;
3357
+ ...
3358
+ </programlisting>
3359
+
3360
+ This technique can be used with <literal>UNIQUE</literal> and
3361
+ <literal>PRIMARY KEY</literal> constraints too; the indexes are created
3362
+ implicitly when the constraint is created. Example:
3363
+ <programlisting>
3364
+ ALTER TABLE ONLY measurement ADD UNIQUE (city_id, logdate);
3365
+
3366
+ ALTER TABLE measurement_y2006m02 ADD UNIQUE (city_id, logdate);
3367
+ ALTER INDEX measurement_city_id_logdate_key
3368
+ ATTACH PARTITION measurement_y2006m02_city_id_logdate_key;
3369
+ ...
3370
+ </programlisting>
3371
+ </para>
3334
3372
</sect3>
3335
3373
3336
3374
<sect3 id="ddl-partitioning-declarative-limitations">
0 commit comments