You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and/or <literal>NULLS LAST</> when creating the index; for example:
410
+
<programlisting>
411
+
CREATE INDEX test2_info_nulls_low ON test2 (info NULLS FIRST);
412
+
CREATE INDEX test3_desc_index ON test3 (id DESC NULLS LAST);
413
+
</programlisting>
414
+
An index stored in ascending order with nulls first can satisfy
415
+
either <literal>ORDER BY x ASC NULLS FIRST</> or
416
+
<literal>ORDER BY x DESC NULLS LAST</> depending on which direction
417
+
it is scanned in.
418
+
</para>
419
+
420
+
<para>
421
+
You might wonder why bother providing all four options, when two
422
+
options together with the possibility of backward scan would cover
423
+
all the variants of <literal>ORDER BY</>. In single-column indexes
424
+
the options are indeed redundant, but in multicolumn indexes they can be
425
+
useful. Consider a two-column index on <literal>(x, y)</>: this can
426
+
satisfy <literal>ORDER BY x, y</> if we scan forward, or
427
+
<literal>ORDER BY x DESC, y DESC</> if we scan backward.
428
+
But it might be that the application frequently needs to use
429
+
<literal>ORDER BY x ASC, y DESC</>. There is no way to get that
430
+
ordering from a regular index, but it is possible if the index is defined
431
+
as <literal>(x ASC, y DESC)</> or <literal>(x DESC, y ASC)</>.
432
+
</para>
433
+
434
+
<para>
435
+
Obviously, indexes with non-default sort orderings are a fairly
436
+
specialized feature, but sometimes they can produce tremendous
437
+
speedups for certain queries. Whether it's worth keeping such an
438
+
index depends on how often you use queries that require a special
439
+
sort ordering.
440
+
</para>
441
+
</sect1>
442
+
443
+
362
444
<sect1 id="indexes-bitmap-scans">
363
445
<title>Combining Multiple Indexes</title>
364
446
@@ -798,7 +880,7 @@ CREATE UNIQUE INDEX tests_success_constraint ON tests (subject, target)
798
880
An index definition can specify an <firstterm>operator
799
881
class</firstterm> for each column of an index.
800
882
<synopsis>
801
-
CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> (<replaceable>column</replaceable> <replaceable>opclass</replaceable> <optional>, ...</optional>);
883
+
CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> (<replaceable>column</replaceable> <replaceable>opclass</replaceable> <optional><replaceable>sort options</replaceable></optional> <optional>, ...</optional>);
802
884
</synopsis>
803
885
The operator class identifies the operators to be used by the index
804
886
for that column. For example, a B-tree index on the type <type>int4</type>
@@ -810,7 +892,10 @@ CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable>
810
892
index behavior. For example, we might want to sort a complex-number data
811
893
type either by absolute value or by real part. We could do this by
812
894
defining two operator classes for the data type and then selecting
813
-
the proper class when making an index.
895
+
the proper class when making an index. The operator class determines
896
+
the basic sort ordering (which can then be modified by adding sort options
0 commit comments