How to Fix MySQL Error 3122 (ER_BOOST_GEOMETRY_INCONSISTENT_TURNS_EXCEPTION)
You get mysql error 3122 when the database engine finds inconsistent intersection points in spatial data. You can fix this error by cleaning up overlapping polygons and validating shapes before running spatial queries. This failure uses the symbol ER_BOOST_GEOMETRY_INCONSISTENT_TURNS_EXCEPTION and returns SQLSTATE HY000. It stops spatial calculations cold when two or more shapes cross each other in invalid ways. Teams that work with map data or geometric shapes see this issue during complex spa
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get mysql error 3122 when the database engine finds inconsistent intersection points in spatial data. You can fix this error by cleaning up overlapping polygons and validating shapes before running spatial queries.
This failure uses the symbol ER_BOOST_GEOMETRY_INCONSISTENT_TURNS_EXCEPTION and returns SQLSTATE HY000. It stops spatial calculations cold when two or more shapes cross each other in invalid ways. Teams that work with map data or geometric shapes see this issue during complex spatial joins.
What causes mysql error 3122 in spatial queries
MySQL uses the Boost.Geometry library to process shapes, lines, and polygons. When you run a spatial operation, the engine calculates how two shapes cross or overlap. It tracks each intersection point as a turn from one edge to another.
If the input polygons have self-intersections, duplicate points, or tiny spikes, the math breaks down. The engine cannot tell which side of the line is inside or outside the polygon. At that point, MySQL halts the query and throws the inconsistent intersection points message.
Floating-point precision limits also trigger this failure during spatial calculations. Coordinates that sit very close together can round into the same spot during math operations. This rounding creates false intersections that confuse the geometry engine.
Bad imports from external map files are another common root cause. External tools often export shapes without strict rules for ring direction or closed loops. When your app writes those raw shapes into tables, future spatial queries fail.
How to diagnose and fix broken geometry safely
To find the broken rows in production, you must check your spatial columns for validity. Do not grant full write permissions to engineers just to hunt down bad map data. Start with a read-only role and run built-in validation checks on the target table.
Filter your query to return only the row IDs where the geometry fails validation. Once you have the bad row IDs, inspect their shapes in a staging database. Look for polygons that fold back on themselves, share tiny edges, or have unclosed rings.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You can fix most broken shapes by running a geometry repair or buffer step. A zero-distance buffer step often rebuilds the polygon edges and removes tiny self-intersecting loops. You can also snap coordinates to a slightly coarser grid to stop floating-point rounding bugs.
When you are ready to update production, use a scoped write role with strict rules. Update only the broken rows by their primary keys inside a small transaction. If the table holds personal data alongside locations, ensure data masking rewrites emails and phone numbers in query results.
How to prevent inconsistent intersection points in apps
The best way to stop spatial errors is to check shapes before saving them. Add a validation step in your app code whenever users upload or draw map zones. Reject any polygon that crosses itself or lacks a closed outer ring.
You can also add a database check rule on the table itself. A check rule blocks any write operation that tries to insert an invalid shape. This keeps your spatial index clean and ensures background analytics jobs do not crash overnight.
Finally, keep your coordinate precision consistent across all services and database tables. Rounding coordinates to a sensible decimal place before insertion stops microscopic edge overlaps from forming.
Inspect every MySQL query and response in flight
Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.
First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.
Frequently asked questions
What does ER_BOOST_GEOMETRY_INCONSISTENT_TURNS_EXCEPTION mean?
It means the internal Boost.Geometry engine found conflicting line crossings while comparing two spatial shapes. This happens when polygons have self-intersections, tiny spikes, or floating-point rounding errors.
Does mysql error 3122 corrupt my database tables?
No, this error does not corrupt your storage engine or ruin your tables. It simply stops the current spatial query because the math cannot finish on invalid shapes.
How can I stop bad spatial data from entering my tables?
Check all shapes for validity in your app before writing them to the database. You can also add a table check rule so the database rejects broken polygons on insert.
Related guides
In this post