MySQL throws ER_BOOST_GEOMETRY_OVERLAY_INVALID_INPUT_EXCEPTION (SQLSTATE HY000, error 3040) when a spatial overlay function receives geometries that are invalid or not topologically correct.
ER_BOOST_GEOMETRY_OVERLAY_INVALID_INPUT_EXCEPTION occurs when MySQL spatial functions like ST_Intersection or ST_Union process invalid geometry data. Validate and repair geometries with ST_IsValid and ST_MakeValid, then rerun the query to resolve the error.
ER_BOOST_GEOMETRY_OVERLAY_INVALID_INPUT_EXCEPTION
MySQL raises error 3040 when the Boost.Geometry engine inside spatial functions cannot compute an overlay because one or more input geometries are invalid. Overlay operations include ST_Intersection, ST_Union, ST_Difference, ST_SymDifference, and ST_Buffer.
The error was introduced in MySQL 5.7.5 when GIS functions were re-implemented on Boost.Geometry. It usually appears during complex spatial joins, geo-analytics, or data migrations that insert external shapefiles.
An overlay calculation fails if any participating geometry violates OGC validity rules such as self-intersection, ring orientation issues, or unclosed polygons.
The error can also surface when coordinate values exceed the allowed range, geometries mix SRIDs without conversion, or when NULL or EMPTY geometries sneak into the function call.
Validate all geometries before running overlay commands. Use ST_IsValid to detect problems and ST_MakeValid to repair them. Always check SRIDs and cast consistently with ST_Transform or ST_SRID.
For batch repairs, update the column in place or write corrected rows to a new table, then reissue the spatial query.
Scenario: loading external shapefiles. Solution: run ST_MakeValid on imported records prior to union or intersection.
Scenario: dynamic geometry creation from user input. Solution: add BEFORE INSERT/UPDATE triggers that reject or fix invalid shapes.
Enforce validity at ingestion with CHECK (ST_IsValid(geom)) constraints in MySQL 8.0.16+. Store geometries with the same SRID and use spatial indexes to keep data consistent.
Include automated nightly jobs that scan for invalid geometries and repair them to maintain data quality.
Galaxy’s SQL editor highlights failing GIS statements, offers AI-driven fixes, and lets teams share validated repair scripts in Collections. Version control ensures the same geometry-cleaning query can be reused across projects without copy-paste errors.
Polygons with self-intersections (bow-ties) or unclosed rings break OGC validity rules.
Running overlay functions on geometries with different spatial reference IDs can return invalid results and trigger the error.
Latitude or longitude values outside -180 to 180 or -90 to 90 cause Boost.Geometry to fail.
Passing NULL or EMPTY shapes into overlay functions without filtering leads to calculation errors.
Raised when overlay functions receive an empty geometry instead of an invalid one.
Generic GIS error for malformed WKB or WKT that fails during parsing.
Occurs when spatial operations involve geometries with different SRIDs without transformation.
No. The error exists in 5.7.5 and all MySQL 8.x versions that use Boost.Geometry.
No. Boost.Geometry stops execution when encountering invalid input. Always fix the data instead.
Spatial indexes do not trigger the error but may hide it until an overlay function reads the rows. Keep indexes after cleaning data.
Store ST_MakeValid scripts in a Galaxy Collection and schedule them via CI to run nightly. Team queries stay accessible and versioned.