Class SpatialShapeDocValuesExtraction


This rule is responsible for marking spatial shape fields whose centroid or extent can be extracted from doc-values. This optimization applies to ST_CENTROID_AGG and ST_EXTENT_AGG aggregations on shape types.

Normally spatial fields are extracted from source values because this maintains original precision, but is very slow. The centroid data (location and weight) and extent bounds are stored in the header of the shape doc-values, allowing for fast extraction without reading the full geometry.

We only apply this optimization under specific conditions:

  • The spatial data is of type GEO_SHAPE or CARTESIAN_SHAPE.
  • The spatial data is consumed directly by ST_CENTROID_AGG or ST_EXTENT_AGG.
  • The spatial data is not consumed by any other operation (except the other spatial aggregation).
  • The field has doc-values enabled.

When both ST_CENTROID_AGG and ST_EXTENT_AGG operate on the same field, this rule ensures both aggregations use the combined extraction preference (EXTRACT_SPATIAL_BOUNDS_AND_CENTROID).