From 67e937095cec8aa922ff3ea971204d59ee3047ff Mon Sep 17 00:00:00 2001
From: Alexey Botchkov <holyfoot@askmonty.org>
Date: Fri, 8 Jul 2011 15:38:15 +0500
Subject: [PATCH] Fix for bug #804259 Second assertion in
 Gis_geometry_collection::init_from_opresult.         A polygon has no right
 to have holes that are actually points.         So just skip them when we
 collect the result of an operation.

per-file comments:
  mysql-test/r/gis-precise.result
Fix for bug #804259 Second assertion in Gis_geometry_collection::init_from_opresult.
        test result updated.
  mysql-test/t/gis-precise.test
Fix for bug #804259 Second assertion in Gis_geometry_collection::init_from_opresult.
        test case added.
  sql/gcalc_tools.cc
Fix for bug #804259 Second assertion in Gis_geometry_collection::init_from_opresult.
        Skip the point in the result if it's the hole inside a polygon.
---
 mysql-test/r/gis-precise.result | 14 ++++++++++++++
 mysql-test/t/gis-precise.test   | 12 ++++++++++++
 sql/gcalc_tools.cc              |  5 +++++
 3 files changed, 31 insertions(+)

diff --git a/mysql-test/r/gis-precise.result b/mysql-test/r/gis-precise.result
index 42cc2758a0..98d081f48e 100644
--- a/mysql-test/r/gis-precise.result
+++ b/mysql-test/r/gis-precise.result
@@ -265,3 +265,17 @@ Round(ST_AREA(ST_BUFFER( ST_UNION(
 POLYGONFROMTEXT('POLYGON((7 7, 7 7, 7 4, 7 7, 7 7))'),
 POLYGONFROMTEXT('POLYGON((7 7, 4 7, 2 9, 7 6, 7 7))')), 1)), 6)
 21.901403
+SELECT AsText(ST_UNION(MultiPolygonFromText('
+        MULTIPOLYGON(((2 2, 2 8, 8 8, 8 2, 2 2), (4 4, 4 6, 6 6, 6 4, 4 4)),
+                     ((0 0, 8 3, 7 4, 0 0)),
+                     ((2 2, 2 8, 8 8, 8 2, 2 2), (4 4, 4 6, 6 6, 6 4, 4 4)))'),
+MultiPolygonFromText(' MULTIPOLYGON(((0 0, 1 9, 4 6, 0 0)),
+                     ((0 5, 3 5, 3 4, 1 4, 1 3, 3 3, 3 0, 0 0, 0 5), (1 1, 2 1, 2 2, 1 2, 1 1)),
+                     ((7 7, 4 7, 6 3, 7 2, 7 7)),
+                     ((0 5, 3 5, 3 4, 1 4, 1 3, 3 3, 3 0, 0 0, 0 5), (1 1, 2 1, 2 2, 1 2, 1 1))) ')));
+AsText(ST_UNION(MultiPolygonFromText('
+        MULTIPOLYGON(((2 2, 2 8, 8 8, 8 2, 2 2), (4 4, 4 6, 6 6, 6 4, 4 4)),
+                     ((0 0, 8 3, 7 4, 0 0)),
+                     ((2 2, 2 8, 8 8, 8 2, 2 2), (4 4, 4 6, 6 6, 6 4, 4 4)))'),
+MultiPolygonFr
+POLYGON((0 0,0 5,0.555555555555556 5,1 9,2 8,8 8,8 2,7 2,5.33333333333333 2,3 1.125,3 0,0 0),(1 1,1 1.5,1.33333333333333 2,1 2,2 2,2 1.14285714285714,1.75 1,1 1),(3 1.71428571428571,3 2,3.5 2,3 1.71428571428571),(4 4,4 6,4.5 6,5.5 4,4 4))
diff --git a/mysql-test/t/gis-precise.test b/mysql-test/t/gis-precise.test
index 8e3bc73849..30445219d9 100644
--- a/mysql-test/t/gis-precise.test
+++ b/mysql-test/t/gis-precise.test
@@ -156,3 +156,15 @@ SELECT ST_NUMGEOMETRIES((ST_UNION(ST_UNION(
 SELECT Round(ST_AREA(ST_BUFFER( ST_UNION(
          POLYGONFROMTEXT('POLYGON((7 7, 7 7, 7 4, 7 7, 7 7))'),
          POLYGONFROMTEXT('POLYGON((7 7, 4 7, 2 9, 7 6, 7 7))')), 1)), 6);
+
+
+#buf #804259 Second assertion in Gis_geometry_collection::init_from_opresult
+
+SELECT AsText(ST_UNION(MultiPolygonFromText('
+        MULTIPOLYGON(((2 2, 2 8, 8 8, 8 2, 2 2), (4 4, 4 6, 6 6, 6 4, 4 4)),
+                     ((0 0, 8 3, 7 4, 0 0)),
+                     ((2 2, 2 8, 8 8, 8 2, 2 2), (4 4, 4 6, 6 6, 6 4, 4 4)))'),
+MultiPolygonFromText(' MULTIPOLYGON(((0 0, 1 9, 4 6, 0 0)),
+                     ((0 5, 3 5, 3 4, 1 4, 1 3, 3 3, 3 0, 0 0, 0 5), (1 1, 2 1, 2 2, 1 2, 1 1)),
+                     ((7 7, 4 7, 6 3, 7 2, 7 7)),
+                     ((0 5, 3 5, 3 4, 1 4, 1 3, 3 3, 3 0, 0 0, 0 5), (1 1, 2 1, 2 2, 1 2, 1 1))) ')));
diff --git a/sql/gcalc_tools.cc b/sql/gcalc_tools.cc
index a360a4c100..2a9090a04a 100644
--- a/sql/gcalc_tools.cc
+++ b/sql/gcalc_tools.cc
@@ -319,6 +319,11 @@ int Gcalc_result_receiver::complete_shape()
   {
     if (cur_shape != Gcalc_function::shape_point)
     {
+      if (cur_shape == Gcalc_function::shape_hole)
+      {
+        buffer.length(shape_pos);
+        return 0;
+      }
       cur_shape= Gcalc_function::shape_point;
       buffer.length(buffer.length()-4);
     }
-- 
2.30.9