ST_Subdivide

更新时间:
复制 MD 格式

Splits a geometry object into smaller parts, each containing fewer vertices than the maxVertices limit. Use this function to pre-process large, complex geometries before indexing — smaller parts produce tighter bounding boxes, which speeds up both point-in-polygon lookups and spatial join operations.

Syntax

setof geometry ST_Subdivide(geometry geom, integer maxVertices)

Parameters

ParameterDescription
geomThe geometry object to subdivide.
maxVerticesThe maximum number of vertices per output part. Default value: 256. Minimum value: 5.

How it works

ST_Subdivide divides geom until every output part has fewer vertices than maxVertices. Run spatial queries on the indexed output parts rather than on the original geometry. This improves query performance in two ways:

  • Tighter bounding boxes — in most cases, each part's bounding box is smaller than the original, so the index eliminates more candidates early and missed-point lookups complete faster.

  • Fewer recheck operations — with fewer candidate points per part, hit-point lookups also complete faster.

Example

Divide a circle into parts with fewer than 6 vertices each:

SELECT ST_Subdivide(st_buffer('POINT(0 0)'::geometry,1),6);
1