diff options
-rw-r--r-- | sql/sql_table.cc | 2 | ||||
-rw-r--r-- | sql/sql_table.h | 3 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 3 | ||||
-rw-r--r-- | sql/table.cc | 11 |
4 files changed, 17 insertions, 2 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1664f94515a..8b4873cb834 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3459,7 +3459,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, } if (f_is_geom(sql_field->pack_flag) && sql_field->geom_type == Field::GEOM_POINT) - column->length= 25; + column->length= MAX_LEN_GEOM_POINT_FIELD; if (!column->length) { my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str); diff --git a/sql/sql_table.h b/sql/sql_table.h index 6f09db12bb9..82f6dfb9658 100644 --- a/sql/sql_table.h +++ b/sql/sql_table.h @@ -105,6 +105,9 @@ enum enum_explain_filename_mode EXPLAIN_PARTITIONS_AS_COMMENT }; +/* Maximum length of GEOM_POINT Field */ +#define MAX_LEN_GEOM_POINT_FIELD 25 + /* depends on errmsg.txt Database `db`, Table `t` ... */ #define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63 diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index bd5d4dc5604..74a21c9f6b6 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5603,7 +5603,8 @@ spatial_type: | GEOMETRYCOLLECTION { $$= Field::GEOM_GEOMETRYCOLLECTION; } | POINT_SYM { - Lex->length= (char*)"25"; + Lex->length= const_cast<char*>(STRINGIFY_ARG + (MAX_LEN_GEOM_POINT_FIELD)); $$= Field::GEOM_POINT; } | MULTIPOINT { $$= Field::GEOM_MULTIPOINT; } diff --git a/sql/table.cc b/sql/table.cc index ba1839bb6ec..b24e03fbe1a 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1539,6 +1539,17 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, table_field->type() == MYSQL_TYPE_BLOB && table_field->field_length == key_part[i].length) continue; + /* + If the key column is of NOT NULL GEOMETRY type, specifically POINT + type whose length is known internally (which is 25). And key part + prefix size is equal to the POINT column max size, then we can + promote it to primary key. + */ + if (!table_field->real_maybe_null() && + table_field->type() == MYSQL_TYPE_GEOMETRY && + table_field->get_geometry_type() == Field::GEOM_POINT && + key_part[i].length == MAX_LEN_GEOM_POINT_FIELD) + continue; if (table_field->real_maybe_null() || table_field->key_length() != key_part[i].length) |