TrajGiST is an extension to GiST (Generalized Search Tree) indexing, designed for trajectory data columns. Create a TrajGiST index to accelerate spatial-temporal queries on trajectory data stored in PolarDB.
How it works
TrajGiST stores multidimensional bounding boxes for trajectory data. When a query runs, the index filters trajectories by checking whether their bounding boxes overlap the query range—only on the axes the index covers. This bounding-box approach enables two key capabilities:
More accurate cost estimation: When multiple indexes exist, TrajGiST selects the most efficient one based on query cost estimates.
Upward compatibility: If the index covers only a subset of the dimensions a query needs, TrajGiST still uses the index as a coarse-grained pre-filter on the covered axes. For example, an index on the
taxis only can pre-filter trajectories outside a specified time range, even when the query calls the ST_{2DT}Intersects function.
Create a TrajGiST index
CREATE INDEX [index_name] ON table_name USING TRAJGIST(traj_col [operator_family]);| Parameter | Required | Description |
|---|---|---|
index_name | Optional | The name of the index. |
table_name | Required | The name of the table that contains the trajectory column. |
traj_col | Required | The name of the trajectory column. |
operator_family | Optional | The operator family that defines which axes the index covers. Default: trajgist_ops_multi. Use the ganos.trajectory.index_split_config parameter to specify the operator family. |
The index accelerates queries that use these functions: ST_ndIntersect, ST_ndDWithin, ST_ndContains, and ST_ndWithin.
Choose an operator family
Each operator family defines which axes the index covers. Select the operator family that matches the axes your queries use.
| Operator family | Axes covered | Use when your queries filter on... |
|---|---|---|
trajgist_ops_z | z | z axis only |
trajgist_ops_t | t | t axis (time) only |
trajgist_ops_2d | x, y | x and y axes only |
trajgist_ops_2dt | x, y, t | x, y, and t axes |
trajgist_ops_3d | x, y, z | x, y, and z axes |
trajgist_ops_3dt | x, y, z, t | All four axes. Supports queries covered by the preceding five operator families. |
trajgist_ops_multi | Multiple bounding boxes | Mixed or unpredictable query patterns. Accelerates queries, but takes more time and storage to build. |
Decision guide:
If all your queries filter on a known set of axes, pick the operator family that matches exactly (for example,
trajgist_ops_2dtfor x, y, and t).If query patterns vary or you query multiple dimension combinations, use
trajgist_ops_multi(the default).An index on fewer axes still provides a partial speedup for queries that use more axes, because TrajGiST applies the index as a pre-filter for the covered dimensions.
Use the index in queries
The index is used automatically when you call the supported functions (ST_ndIntersect, ST_ndDWithin, ST_ndContains, and ST_ndWithin).
TrajGiST also supports upward compatibility: if the index covers fewer axes than a query needs, it still applies as a coarse-grained pre-filter on the covered axes. Only trajectories that pass the pre-filter proceed to full evaluation, which reduces the number of rows scanned.