MySQL raises error 3122 (ER_BOOST_GEOMETRY_INCONSISTENT_TURNS_EXCEPTION) when Boost.Geometry detects contradictory intersection points in a spatial operation.
MySQL error 3122 ER_BOOST_GEOMETRY_INCONSISTENT_TURNS_EXCEPTION appears when a spatial query returns conflicting intersection points. Validate and clean your geometry, simplify overly complex shapes, or repair invalid polygons to resolve the issue quickly.
ER_BOOST_GEOMETRY_INCONSISTENT_TURNS_EXCEPTION
Error 3122 fires when MySQL's Boost.Geometry engine processes a spatial function and finds two intersection points that should coincide but do not. The engine treats this as corrupt or ambiguous geometry data and aborts the query.
The condition was introduced in MySQL 5.7.7, so older versions never emit it. Most often it appears during ST_Intersection, ST_Union, ST_Difference, or ST_IsValid checks.
Inconsistent vertex ordering, overlapping rings, or self-intersecting polygons produce contradictory turn data inside Boost.Geometry. Large coordinate precision gaps can also cause floating-point rounding that mislabels turns as distinct.
User-supplied WKT/WKB imported from GIS tools frequently carries invalid shapes. Programmatic generation of complex multipolygons without validation is another trigger.
First validate the geometry with ST_IsValid. If it returns 0, repair it using ST_MakeValid or ST_SimplifyPreserveTopology. Simplifying tolerates tiny slivers causing the inconsistency.
If ST_IsValid passes yet the error persists, cast all coordinate values to a consistent precision and re-run the query. This eliminates rounding distortions.
Bulk import of shapefiles - Run an ETL step that discards self-intersections before loading into MySQL.
Dynamically generated polygons - Add unit tests that call ST_IsValid after generation. Fail the build when invalid shapes appear.
Legacy tables - Schedule a nightly job in Galaxy that scans for invalid geometry and rewrites bad rows with ST_MakeValid.
Always validate and simplify geometry on ingest. Limit coordinate precision to a sane number of decimal places to prevent floating-point drift.
Leverage Galaxy's AI copilot to review spatial queries and suggest ST_IsValid guards automatically, reducing the risk of production failures.
Error 1366 - invalid string for Geometry - occurs on malformed WKT.
Error 3037 - geometry overlay failed - similar root cause but raised for general overlay issues.
Rings that cross themselves force Boost.Geometry to detect conflicting turns.
Points that should match but differ at micro-precision lead to inconsistent intersections.
Mixing clockwise and anticlockwise ordering inside one multipolygon confuses the overlay algorithm.
Third-party shapefiles often contain corrupt geometries that MySQL rejects during spatial operations.
Raised when any overlay operation fails, not just inconsistent turns.
Appears during insert/update of malformed WKT or WKB.
Returned when spatial index lookup encounters corrupt data blocks.
No rows are deleted. MySQL simply aborts the spatial function and returns an error.
Newer versions still enforce geometry consistency. You must fix the data.
You can filter them with ST_IsValid but long term you should repair or drop them to avoid future failures.
Galaxy prompts you to validate geometry during query composition and can schedule nightly auto-repair jobs.