diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result index 2748199efad..90857ecfc6d 100644 --- a/mysql-test/r/gis.result +++ b/mysql-test/r/gis.result @@ -682,6 +682,9 @@ POINT(1 1) drop function fn3; create table t1(pt POINT); alter table t1 add primary key pti(pt); +drop table t1; +create table t1(pt GEOMETRY); +alter table t1 add primary key pti(pt); ERROR 42000: BLOB/TEXT column 'pt' used in key specification without a key length alter table t1 add primary key pti(pt(20)); drop table t1; diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index 1f30407c2b7..142bd29fa2d 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -399,6 +399,9 @@ drop function fn3; # Bug #12267 (primary key over GIS) # create table t1(pt POINT); +alter table t1 add primary key pti(pt); +drop table t1; +create table t1(pt GEOMETRY); --error 1170 alter table t1 add primary key pti(pt); alter table t1 add primary key pti(pt(20)); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 922f04be25a..8aed27e7fa4 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1156,6 +1156,9 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name); DBUG_RETURN(-1); } + if (f_is_geom(sql_field->pack_flag) && sql_field->geom_type == + Field::GEOM_POINT) + column->length= 21; if (!column->length) { my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 14f617b9f8b..316564f52f7 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2969,7 +2969,9 @@ type: spatial_type: GEOMETRY_SYM { $$= Field::GEOM_GEOMETRY; } | GEOMETRYCOLLECTION { $$= Field::GEOM_GEOMETRYCOLLECTION; } - | POINT_SYM { $$= Field::GEOM_POINT; } + | POINT_SYM { Lex->length= (char*)"21"; + $$= Field::GEOM_POINT; + } | MULTIPOINT { $$= Field::GEOM_MULTIPOINT; } | LINESTRING { $$= Field::GEOM_LINESTRING; } | MULTILINESTRING { $$= Field::GEOM_MULTILINESTRING; }