Indexing of Time Types

GiST and SP-GiST indexes can be created for table columns of the timestampset, period, and periodset types. An example of creation of a GiST index in a column during of type period in a table reservation is as follows:

CREATE TABLE reservation (ReservationID integer PRIMARY KEY, RoomID integer,
During period);
CREATE INDEX reservation_during_idx ON reservation USING GIST(during);

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

In addition, B-tree indexes can be created for table columns of a time type. For these index types, basically the only useful operation is equality. There is a B-tree sort ordering defined for values of 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.