summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagne Mahre <magne.mahre@sun.com>2010-02-11 18:25:34 +0100
committerMagne Mahre <magne.mahre@sun.com>2010-02-11 18:25:34 +0100
commit203793514d4e5035691bb750256532b8ecf0b6da (patch)
treee85c10c067c824114a07bf335213215e584480ea
parent93cd02bc82bfe48bad5c3d4daf3331207f3445a3 (diff)
downloadmariadb-git-203793514d4e5035691bb750256532b8ecf0b6da.tar.gz
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.
-rw-r--r--mysql-test/r/gis.result30
-rw-r--r--mysql-test/t/gis.test45
-rw-r--r--sql/share/errmsg-utf8.txt2
-rw-r--r--sql/sql_table.cc16
4 files changed, 89 insertions, 4 deletions
diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result
index 3e28227d542..ac808daae92 100644
--- a/mysql-test/r/gis.result
+++ b/mysql-test/r/gis.result
@@ -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;
diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test
index bc0695aaa93..c5c6a94057a 100644
--- a/mysql-test/t/gis.test
+++ b/mysql-test/t/gis.test
@@ -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;
+
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index db99890235a..d4f3cce805f 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -6260,3 +6260,5 @@ ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
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"
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 04bd2d4c976..e89edb4fcfe 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3193,11 +3193,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
{
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))