GiST indexing

更新时间:
复制 MD 格式

Create a Generalized Search Tree (GiST) index on a trajectory data column to accelerate spatial queries on that column.

How it works

The following functions automatically use the GiST index when one is available:

  • ST_ndIntersect

  • ST_ndDWithin

  • ST_ndContains

  • ST_ndWithin

Syntax

CREATE INDEX [index_name] ON table_name USING GIST(traj_col [operator_family]);
ParameterRequiredDescription
index_nameNoName of the index
table_nameYesName of the table that contains the trajectory column
traj_colYesName of the trajectory column
operator_familyNoOperator family that determines which axes are indexed. Default: trajgist_ops_3dt

The default operator family trajgist_ops_3dt indexes all four axes (x, y, z, and t) and supports every query type. If your queries consistently target a smaller set of axes, specify a narrower operator family. Fewer indexed dimensions generally produce faster queries.

Supported operator families

Operator familyIndexed axesSupported query types
trajgist_ops_zzz-axis queries
trajgist_ops_ttt-axis queries
trajgist_ops_2dx, yx- and y-axis queries
trajgist_ops_2dtx, y, tx- and y-axis queries; t-axis queries; x-, y-, and t-axis queries
trajgist_ops_3dx, y, zx- and y-axis queries; z-axis queries; x-, y-, and z-axis queries
trajgist_ops_3dtx, y, z, tAll query types supported by the preceding five operator families

Examples

The following examples create indexes optimized for specific query patterns.

-- Index on the t axis only — for time-range queries
CREATE INDEX ON table_name USING GIST(traj_col trajgist_ops_t);

-- Index on the x and y axes — for 2D spatial queries
CREATE INDEX ON table_name USING GIST(traj_col trajgist_ops_2d);

-- Index on the x, y, and t axes — for spatiotemporal queries without elevation
CREATE INDEX ON table_name USING GIST(traj_col trajgist_ops_2dt);