MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Magne Mahre Date:February 11 2010 5:25pm
Subject:bzr commit into mysql-5.5-trunk-bugfixing branch (magne.mahre:2941)
Bug#50574
View as plain text  
#At file:///data/z/mysql-trunk-bugfixing-50574/ based on revid:magne.mahre@stripped

 2941 Magne Mahre	2010-02-11
      Bug#50574 5.5.x allows spatial indexes on non-spatial columns, 
                causing crashes!
      
      Adding a SPATIAL INDEX on a non-geometrical column caused a
      segmentation fault when the table was subsequently 
      inserted into.
            
      A test was added in mysql_prepare_create_table to explicitly
      check whether non-geometrical columns are used in a
      spatial index, and throw an error if so.
     @ mysql-test/t/gis.test
        Added test cases to verify that only geometrical
        columns can get a spatial index.
                
        In addition, verify that only a single geom.
        column can participate in a spatial index.

    modified:
      mysql-test/r/gis.result
      mysql-test/t/gis.test
      sql/share/errmsg-utf8.txt
      sql/sql_table.cc
=== modified file 'mysql-test/r/gis.result'
--- a/mysql-test/r/gis.result	2010-01-15 11:26:53 +0000
+++ b/mysql-test/r/gis.result	2010-02-11 17:25:34 +0000
@@ -1058,3 +1058,33 @@ SELECT Polygon(12345123,'');
 Polygon(12345123,'')
 NULL
 End of 5.1 tests
+CREATE TABLE t1(
+col0 BINARY NOT NULL,
+col2 TIMESTAMP,
+SPATIAL INDEX i1 (col0)
+) ENGINE=MyISAM;
+ERROR 42000: A SPATIAL index may only contain a geometrical type column
+CREATE TABLE t1 (
+col0 BINARY NOT NULL,
+col2 TIMESTAMP
+) ENGINE=MyISAM;
+CREATE SPATIAL INDEX idx0 ON t1(col0);
+ERROR 42000: A SPATIAL index may only contain a geometrical type column
+ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0);
+ERROR 42000: A SPATIAL index may only contain a geometrical type column
+CREATE TABLE t2 (
+col0 INTEGER NOT NULL,
+col1 POINT,
+col2 POINT
+);
+CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
+ERROR HY000: Incorrect arguments to SPATIAL INDEX
+CREATE TABLE t3 (
+col0 INTEGER NOT NULL,
+col1 POINT,
+col2 LINESTRING,
+SPATIAL INDEX i1 (col1, col2)
+);
+ERROR HY000: Incorrect arguments to SPATIAL INDEX
+DROP TABLE t1;
+DROP TABLE t2;

=== modified file 'mysql-test/t/gis.test'
--- a/mysql-test/t/gis.test	2010-01-15 11:26:53 +0000
+++ b/mysql-test/t/gis.test	2010-02-11 17:25:34 +0000
@@ -723,3 +723,48 @@ SELECT Polygon(1234512,'');
 SELECT Polygon(12345123,'');
 
 --echo End of 5.1 tests
+
+#
+# Bug #50574 5.5.x allows spatial indexes on non-spatial 
+#           columns, causing crashes!
+#
+--error ER_SPATIAL_MUST_HAVE_GEOM_COL
+CREATE TABLE t1(
+  col0 BINARY NOT NULL,
+  col2 TIMESTAMP,
+  SPATIAL INDEX i1 (col0)
+) ENGINE=MyISAM;
+
+# Test other ways to add indices
+CREATE TABLE t1 (
+  col0 BINARY NOT NULL,
+  col2 TIMESTAMP
+) ENGINE=MyISAM;
+
+--error ER_SPATIAL_MUST_HAVE_GEOM_COL
+CREATE SPATIAL INDEX idx0 ON t1(col0);
+
+--error ER_SPATIAL_MUST_HAVE_GEOM_COL
+ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0);
+
+CREATE TABLE t2 (
+  col0 INTEGER NOT NULL,
+  col1 POINT,
+  col2 POINT
+);
+
+--error ER_WRONG_ARGUMENTS
+CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
+
+--error ER_WRONG_ARGUMENTS
+CREATE TABLE t3 (
+  col0 INTEGER NOT NULL,
+  col1 POINT,
+  col2 LINESTRING,
+  SPATIAL INDEX i1 (col1, col2)
+);
+
+# cleanup
+DROP TABLE t1;
+DROP TABLE t2;
+

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2010-01-23 21:09:23 +0000
+++ b/sql/share/errmsg-utf8.txt	2010-02-11 17:25:34 +0000
@@ -6260,3 +6260,5 @@ ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_F
   eng "Field '%-.192s' is of a not allowed type for this type of partitioning"
 ER_PARTITION_FIELDS_TOO_LONG
   eng "The total length of the partitioning fields is too large"
+ER_SPATIAL_MUST_HAVE_GEOM_COL 42000
+  eng "A SPATIAL index may only contain a geometrical type column"

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-02-11 17:02:41 +0000
+++ b/sql/sql_table.cc	2010-02-11 17:25:34 +0000
@@ -3193,11 +3193,19 @@ mysql_prepare_create_table(THD *thd, HA_
       {
 	column->length*= sql_field->charset->mbmaxlen;
 
-        if (key->type == Key::SPATIAL && column->length)
+        if (key->type == Key::SPATIAL)
         {
-          my_error(ER_WRONG_SUB_KEY, MYF(0));
-	  DBUG_RETURN(TRUE);
-	}
+          if (column->length)
+          {
+            my_error(ER_WRONG_SUB_KEY, MYF(0));
+            DBUG_RETURN(TRUE);
+          }
+          if (!f_is_geom(sql_field->pack_flag))
+          {
+            my_error(ER_SPATIAL_MUST_HAVE_GEOM_COL, MYF(0));
+            DBUG_RETURN(TRUE);
+          }
+        }
 
 	if (f_is_blob(sql_field->pack_flag) ||
             (f_is_geom(sql_field->pack_flag) && key->type != Key::SPATIAL))


Attachment: [text/bzr-bundle] bzr/magne.mahre@sun.com-20100211172534-6s5qhuraa3fzykcp.bundle
Thread
bzr commit into mysql-5.5-trunk-bugfixing branch (magne.mahre:2941)Bug#50574Magne Mahre11 Feb