WL#11096: Don't do Cartesian computations on geographic geometries

Affects: Server-8.0   —   Status: Complete

Spatial objects (geometries) exist in a spatial reference system (SRS). Some SRSs are flat Cartesian planes, while others are geographic (on an ellipsoid). Until MySQL 8.0, all spatial functions ignored the SRS and computed their results on a Cartesian plane. In 8.0, some functions will use geographic computations if the input data is in a geographic SRS.

This WL modifies the behavior of all spatial functions that don't yet support geographic computations to raise an error if given geographic input, effectively restricting the functions to Cartesian input. As we implement geographic support in more functions, this error will gradually go away.

Rationale: The users don't know which functions support geographic operations without checking the manual. If a function does a Cartesian computation on geographic data, the result will often be incorrect. To protect the user from misunderstanding the function semantics and from sudden changes in query result when the functions start supporting geographic computations, the best option is to raise an error until geographic support is implemented.

The old behavior can still be achieved by temporarily casting the input parameters to SRID 0, and, if necessary, casting the result back to a geographic SRID.

Affected functions: ST_Area, ST_Buffer, ST_Centroid, ST_ConvexHull, ST_Difference, ST_Distance_Sphere, ST_Envelope, ST_Intersection, ST_IsClosed, ST_IsSimple, ST_IsValid, ST_Length, ST_MakeEnvelope, ST_Simplify, ST_SymDifference, ST_Union, ST_Validate.

The WL also restricts the ST_Geohash function to only accept points in SRID 0 or SRID 4326, and restricts functions ST_Dimension, ST_EndPoint, ST_ExteriorRing, ST_GeometryN, ST_GeometryType, ST_InteriorRingN, ST_IsEmpty, ST_NumGeometries, ST_NumInteriorRing, ST_NumInteriorRings, ST_NumPoints, ST_PointN, ST_StartPoint, ST_SwapXY, ST_X, and ST_Y to valid (defined) SRIDs.

F-1 a)
Functions that depend on the SRS but do not support geographic computations1 MUST raise ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS during evaluation if called with one or more geographic parameters.
F-1 b)
Functions that depend on the SRS but do not support geographic computations1 MUST raise ER_SRS_NOT_FOUND if called with one or more parameters that have an SRID that is not defined.
F-2 a)
ST_Geohash(point, max_length) MUST raise ER_SRS_NOT_FOUND if the point is in an SRID that is not defined.
F-2 b)
ST_Geohash(point, max_length) MUST raise ER_ONLY_IMPLEMENTED_FOR_SRID_0_AND_4326 if the point is in a defined SRID, but not in SRID 0 or 4326.
F-3
Functions that don't depend on the SRS2 MUST raise ER_SRS_NOT_FOUND if the geometry is in an SRID that is not defined.

1 Functions that depend on the SRS but do not support geographic computations are: ST_Area, ST_Buffer, ST_Centroid, ST_ConvexHull, ST_Difference, ST_Distance_Spherea, ST_Envelope, ST_Intersection, ST_IsClosed, ST_IsSimpleb, ST_IsValidc, ST_Lengthd, ST_MakeEnvelope, ST_Simplify, ST_SymDifference, ST_Union, and ST_Validate.

2 Functions that don't depend on the SRS are: ST_Dimension, ST_EndPoint, ST_ExteriorRing, ST_GeometryN, ST_GeometryType, ST_InteriorRingN, ST_IsEmpty, ST_NumGeometries, ST_NumInteriorRing, ST_NumInteriorRings, ST_NumPoints, ST_PointN, ST_StartPoint, ST_SwapXY, ST_X, and ST_Y.

I-1
No new files.
I-2
No new syntax.
I-3
No new commands.
I-4
No new tools.
I-5
The semantics of interface SQL01 are changed: Execution of functions that depend on the SRS but do not support geographic computations (see list above) used to compute a Cartesian result. The functions will now raise ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS instead.

Execution of ST_Geohash(point, max_length) used to allow points in any SRID. The function will now raise ER_ONLY_IMPLEMENTED_FOR_SRID_0_AND_4326 if the SRID is not 0 or 4326.

Execution of functions that do not depend on the SRS (see list above) used to ignore the SRID. The functions will now raise ER_SRS_NOT_FOUND if the SRS doesn't exist.
I-6
Interface ERR01 is extended with 1 new error message:
ER_ONLY_IMPLEMENTED_FOR_SRID_0_AND_4326, SQLSTATE 22S00, "Function %s is only defined for SRID 0 and SRID 4326."