Indexing

Three index types are available on trgeometry columns. Each uses the spatiotemporal bounding box of the materialised geometry and supports topological, position, and KNN distance queries.

CREATE INDEX tbl_trgeometry_gist_idx
  ON tbl_trgeometry
  USING GIST(temp);

-- topological lookup
SELECT count(*) FROM tbl_trgeometry
WHERE temp && stbox 'STBOX XT(((0, 0), (10, 10)),[2001-01-01, 2001-01-02])';

-- KNN (ordered scan)
SELECT mmsi
FROM tbl_trgeometry
ORDER BY temp <-> trgeometry 'Polygon((0 0,1 0,1 1,0 1,0 0));Pose(Point(100 100), 0.0)@2001-01-01'
LIMIT 10;

The kd-tree variant typically wins on workloads dominated by KNN queries with a tight ordering bound; the quad-tree variant is more uniform. The R-tree GiST is the safe default for mixed read/write workloads.