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

Commitd363d42

Browse files
committed
Use MINVALUE/MAXVALUE instead of UNBOUNDED for range partition bounds.
Previously, UNBOUNDED meant no lower bound when used in the FROM list,and no upper bound when used in the TO list, which was OK forsingle-column range partitioning, but problematic with multiplecolumns. For example, an upper bound of (10.0, UNBOUNDED) would not becollocated with a lower bound of (10.0, UNBOUNDED), thus making itdifficult or impossible to define contiguous multi-column rangepartitions in some cases.Fix this by using MINVALUE and MAXVALUE instead of UNBOUNDED torepresent a partition column that is unbounded below or aboverespectively. This syntax removes any ambiguity, and ensures that ifone partition's lower bound equals another partition's upper bound,then the partitions are contiguous.Also drop the constraint prohibiting finite values after an unboundedcolumn, and just document the fact that any values after MINVALUE orMAXVALUE are ignored. Previously it was necessary to repeat UNBOUNDEDmultiple times, which was needlessly verbose.Note: Forces a post-PG 10 beta2 initdb.Report by Amul Sul, original patch by Amit Langote with someadditional hacking by me.Discussion:https://postgr.es/m/CAAJ_b947mowpLdxL3jo3YLKngRjrq9+Ej4ymduQTfYR+8=YAYQ@mail.gmail.com
1 parent866f4a7 commitd363d42

File tree

18 files changed

+377
-237
lines changed

18 files changed

+377
-237
lines changed

‎doc/src/sgml/ref/create_table.sgml

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
8787
<phrase>and <replaceable class="PARAMETER">partition_bound_spec</replaceable> is:</phrase>
8888

8989
IN ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> | NULL } [, ...] ) |
90-
FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> |UNBOUNDED } [, ...] )
91-
TO ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> |UNBOUNDED } [, ...] )
90+
FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> |MINVALUE | MAXVALUE } [, ...] )
91+
TO ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> |MINVALUE | MAXVALUE } [, ...] )
9292

9393
<phrase><replaceable class="PARAMETER">index_parameters</replaceable> in <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and <literal>EXCLUDE</literal> constraints are:</phrase>
9494

@@ -269,10 +269,10 @@ FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replace
269269
<para>
270270
Each of the values specified in
271271
the <replaceable class="PARAMETER">partition_bound_spec</> is
272-
a literal, <literal>NULL</literal>,or<literal>UNBOUNDED</literal>.
273-
Each literal value must be either a numeric constant that is coercible
274-
to the corresponding partition key column's type, or a string literal
275-
that is valid input for that type.
272+
a literal, <literal>NULL</literal>, <literal>MINVALUE</literal>, or
273+
<literal>MAXVALUE</literal>.Each literal value must be either a
274+
numeric constant that is coercible to the corresponding partition key
275+
column's type, or a string literalthat is valid input for that type.
276276
</para>
277277

278278
<para>
@@ -300,13 +300,46 @@ FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replace
300300
</para>
301301

302302
<para>
303-
Writing <literal>UNBOUNDED</literal> in <literal>FROM</literal>
304-
signifies <literal>-infinity</literal> as the lower bound of the
305-
corresponding column, whereas when written in <literal>TO</literal>,
306-
it signifies <literal>+infinity</literal> as the upper bound.
307-
All items following an <literal>UNBOUNDED</literal> item within
308-
a <literal>FROM</literal> or <literal>TO</literal> list must also
309-
be <literal>UNBOUNDED</literal>.
303+
The special values <literal>MINVALUE</> and <literal>MAXVALUE</>
304+
may be used when creating a range partition to indicate that there
305+
is no lower or upper bound on the column's value. For example, a
306+
partition defined using <literal>FROM (MINVALUE) TO (10)</> allows
307+
any values less than 10, and a partition defined using
308+
<literal>FROM (10) TO (MAXVALUE)</> allows any values greater than
309+
or equal to 10.
310+
</para>
311+
312+
<para>
313+
When creating a range partition involving more than one column, it
314+
can also make sense to use <literal>MAXVALUE</> as part of the lower
315+
bound, and <literal>MINVALUE</> as part of the upper bound. For
316+
example, a partition defined using
317+
<literal>FROM (0, MAXVALUE) TO (10, MAXVALUE)</> allows any rows
318+
where the first partition key column is greater than 0 and less than
319+
or equal to 10. Similarly, a partition defined using
320+
<literal>FROM ('a', MINVALUE) TO ('b', MINVALUE)</> allows any rows
321+
where the first partition key column starts with "a".
322+
</para>
323+
324+
<para>
325+
Note that any values after <literal>MINVALUE</> or
326+
<literal>MAXVALUE</> in a partition bound are ignored; so the bound
327+
<literal>(10, MINVALUE, 0)</> is equivalent to
328+
<literal>(10, MINVALUE, 10)</> and <literal>(10, MINVALUE, MINVALUE)</>
329+
and <literal>(10, MINVALUE, MAXVALUE)</>.
330+
</para>
331+
332+
<para>
333+
Also note that some element types, such as <literal>timestamp</>,
334+
have a notion of "infinity", which is just another value that can
335+
be stored. This is different from <literal>MINVALUE</> and
336+
<literal>MAXVALUE</>, which are not real values that can be stored,
337+
but rather they are ways of saying that the value is unbounded.
338+
<literal>MAXVALUE</> can be thought of as being greater than any
339+
other value, including "infinity" and <literal>MINVALUE</> as being
340+
less than any other value, including "minus infinity". Thus the range
341+
<literal>FROM ('infinity') TO (MAXVALUE)</> is not an empty range; it
342+
allows precisely one value to be stored &mdash; "infinity".
310343
</para>
311344

312345
<para>
@@ -1610,7 +1643,7 @@ CREATE TABLE measurement_y2016m07
16101643
<programlisting>
16111644
CREATE TABLE measurement_ym_older
16121645
PARTITION OF measurement_year_month
1613-
FOR VALUES FROM (unbounded, unbounded) TO (2016, 11);
1646+
FOR VALUES FROM (MINVALUE, 0) TO (2016, 11);
16141647

16151648
CREATE TABLE measurement_ym_y2016m11
16161649
PARTITION OF measurement_year_month

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp