Indexing

GiST and SP-GiST indexes can be created for table columns of the set and span types. The GiST index implements an R-tree while the SP-GiST index implements a quad-tree. An example of creation of a GiST index in a column During of type tstzspan in a table Reservation is as follows:

CREATE TABLE Reservation (ReservationID integer PRIMARY KEY, RoomID integer,
  During tstzspan);
CREATE INDEX Reservation_During_Idx ON Reservation USING GIST(During);

A GiST or an SP-GiST index can accelerate queries involving the following operators: =, &&, <@, @>, -|-, <<, >>, &<, &>, <<#, #>>, &<#, #&>, and <->.

A spatial set, that is, a set of geometries, geographies, network points, poses, pose chains, circular buffers, H3 cells, quadbin cells, or S2 cells, is indexed by the spatiotemporal box it stores rather than by a span. Its GiST index implements an R-tree and its SP-GiST index a quad-tree, or a k-d tree when the operator class is named, as in USING SPGIST(Stops geomset_kdtree_ops). Such an index can accelerate queries involving the operators =, &&, <@, and @>, and for the sets whose elements have a distance, <->. Since the box bounds the elements of a set without stating them, the index returns every set whose box satisfies the operator, and the operator is then checked on the set.

In addition, B-tree indexes can be created for table columns of a set or span types. For these index types, basically the only useful operation is equality. There is a B-tree sort ordering defined for values of span time types with corresponding <, <=, >, and >= operators, but the ordering is rather arbitrary and not usually useful in the real world. The B-tree support is primarily meant to allow sorting internally in queries, rather than creation of actual indexes.

Finally, hash indexes can be created for table columns of a set or span types. For these types of indexes, the only operation defined is equality.