Create a GiST (Generalized Search Tree) index on a trajectory column to accelerate spatial queries. The index speeds up queries that use ST_ndIntersect, ST_ndDWithin, ST_ndContains, and ST_ndWithin.
Syntax
CREATE INDEX [index_name] ON table_name USING GIST(traj_col [operator_family]);| Parameter | Required | Default | Description |
|---|---|---|---|
index_name | No | — | Name of the index |
table_name | Yes | — | Name of the table |
traj_col | Yes | — | Name of the trajectory column |
operator_family | No | trajgist_ops_multi | Operator family that determines which axes the index covers. Use the ganos.trajectory.index_split_config parameter to configure the operator family. |
Choose an operator family
The operator family determines which spatial dimensions the index covers and which query patterns it accelerates. Choose the operator family that matches your query axes to avoid building unnecessary index dimensions.
| Operator family | Axes indexed | Accelerated query axes |
|---|---|---|
trajgist_ops_z | z | z only |
trajgist_ops_t | t | t only |
trajgist_ops_2d | x, y | x and y |
trajgist_ops_2dt | x, y, t | x and y; t; x, y, and t |
trajgist_ops_3d | x, y, z | x and y; z; x, y, and z |
trajgist_ops_3dt | x, y, z, t | All axes — includes all query patterns supported by the five operator families above |
trajgist_ops_multi | Multiple bounding boxes | Accelerates queries — uses multiple bounding boxes per trajectory, at the cost of additional time and storage during index creation |
trajgist_ops_multi is the default. It accelerates queries using multiple bounding boxes but takes longer to build and requires more storage than the single-axis operator families.Examples
Create an index on the t axis:
CREATE INDEX ON table_name USING GIST(traj_col trajgist_ops_t);Create an index on the x and y axes:
CREATE INDEX ON table_name USING GIST(traj_col trajgist_ops_2d);Create an index on the x, y, and t axes:
CREATE INDEX ON table_name USING GIST(traj_col trajgist_ops_2dt);