Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita99b653

Browse files
committed
Document piecemeal construction of partitioned indexes
Continuous operation cannot be achieved without applying this technique,so it needs to be properly described.Author: Álvaro HerreraReported-by: Tom LaneDiscussion:https://postgr.es/m/8756.1556302759@sss.pgh.pa.us
1 parent57e85fa commita99b653

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎doc/src/sgml/ddl.sgml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,6 +3331,44 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
33313331
One may then drop the constraint after <command>ATTACH PARTITION</command>
33323332
is finished, because it is no longer necessary.
33333333
</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>
33343372
</sect3>
33353373

33363374
<sect3 id="ddl-partitioning-declarative-limitations">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp