Skip to content

Commit e9a692f

Browse files
committed
MDEV-19819 ALTER from POINT to LINESTRING erroneously preserves POINT values
1 parent 8b57661 commit e9a692f

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

mysql-test/main/gis.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5019,5 +5019,21 @@ ERROR HY000: Illegal parameter data types int and geometry for operation 'in'
50195019
SELECT (1,(0,0)) IN ((1,(POINT(1,1),0)),(0,(0,0)));
50205020
ERROR HY000: Illegal parameter data types int and geometry for operation 'in'
50215021
#
5022+
# MDEV-19819 ALTER from POINT to LINESTRING erroneously preserves POINT values
5023+
#
5024+
CREATE TABLE t1 (a POINT) ENGINE=MyISAM;
5025+
INSERT INTO t1 VALUES (Point(0,0));
5026+
ALTER TABLE t1 MODIFY a LINESTRING;
5027+
ERROR 22007: Incorrect LINESTRING value: 'POINT' for column `test`.`t1`.`a` at row 1
5028+
DROP TABLE t1;
5029+
CREATE TABLE t1 (a LINESTRING);
5030+
CREATE TABLE t2 (a POINT);
5031+
INSERT INTO t2 VALUES (POINT(0,0));
5032+
INSERT INTO t1 SELECT * FROM t2;
5033+
ERROR 22007: Incorrect LINESTRING value: 'POINT' for column `test`.`t1`.`a` at row 1
5034+
SELECT AsText(a) FROM t1;
5035+
AsText(a)
5036+
DROP TABLE t1, t2;
5037+
#
50225038
# End of 10.4 tests
50235039
#

mysql-test/main/gis.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,25 @@ SELECT (1,0) IN ((POINT(1,1),0),(0,0));
30943094
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
30953095
SELECT (1,(0,0)) IN ((1,(POINT(1,1),0)),(0,(0,0)));
30963096

3097+
--echo #
3098+
--echo # MDEV-19819 ALTER from POINT to LINESTRING erroneously preserves POINT values
3099+
--echo #
3100+
3101+
CREATE TABLE t1 (a POINT) ENGINE=MyISAM;
3102+
INSERT INTO t1 VALUES (Point(0,0));
3103+
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
3104+
ALTER TABLE t1 MODIFY a LINESTRING;
3105+
DROP TABLE t1;
3106+
3107+
CREATE TABLE t1 (a LINESTRING);
3108+
CREATE TABLE t2 (a POINT);
3109+
INSERT INTO t2 VALUES (POINT(0,0));
3110+
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
3111+
INSERT INTO t1 SELECT * FROM t2;
3112+
SELECT AsText(a) FROM t1;
3113+
DROP TABLE t1, t2;
3114+
3115+
30973116
--echo #
30983117
--echo # End of 10.4 tests
30993118
--echo #

mysql-test/suite/innodb_gis/r/alter_spatial_index.result

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,7 @@ ALTER TABLE tab MODIFY COLUMN c2 GEOMETRY NOT NULL;
485485
affected rows: 0
486486
info: Records: 0 Duplicates: 0 Warnings: 0
487487
ALTER TABLE tab MODIFY COLUMN c3 POLYGON NOT NULL;
488-
affected rows: 10
489-
info: Records: 10 Duplicates: 0 Warnings: 0
488+
ERROR 22007: Incorrect POLYGON value: 'LINESTRING' for column `test`.`tab`.`c3` at row 1
490489
ALTER TABLE tab add COLUMN c7 POINT NOT NULL;
491490
affected rows: 0
492491
info: Records: 0 Duplicates: 0 Warnings: 0
@@ -528,7 +527,7 @@ Table Create Table
528527
tab CREATE TABLE `tab` (
529528
`c1` int(11) NOT NULL,
530529
`c2` geometry NOT NULL,
531-
`c3` polygon NOT NULL,
530+
`c3` linestring NOT NULL,
532531
`c4` polygon NOT NULL,
533532
`c5` geometry NOT NULL,
534533
`c7` point NOT NULL,
@@ -565,7 +564,7 @@ Table Create Table
565564
tab CREATE TABLE `tab` (
566565
`c1` int(11) NOT NULL,
567566
`c2` geometry NOT NULL,
568-
`c3` polygon NOT NULL,
567+
`c3` linestring NOT NULL,
569568
`c4` geometry NOT NULL,
570569
`c5` geometry NOT NULL,
571570
`c7` point NOT NULL,
@@ -614,9 +613,6 @@ SET @g2 = ST_GeomFromText('LINESTRING(1 1,2 2,3 3)');
614613
ALTER TABLE tab MODIFY COLUMN c2 POINT NOT NULL;
615614
affected rows: 8
616615
info: Records: 8 Duplicates: 0 Warnings: 0
617-
ALTER TABLE tab MODIFY COLUMN c3 LINESTRING NOT NULL;
618-
affected rows: 8
619-
info: Records: 8 Duplicates: 0 Warnings: 0
620616
ALTER TABLE tab MODIFY COLUMN c4 POLYGON NOT NULL;
621617
affected rows: 8
622618
info: Records: 8 Duplicates: 0 Warnings: 0

mysql-test/suite/innodb_gis/t/alter_spatial_index.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ ALTER TABLE tab ADD INDEX idx6(c4(10)) USING BTREE;
476476

477477
ALTER TABLE tab MODIFY COLUMN c2 GEOMETRY NOT NULL;
478478

479+
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
479480
ALTER TABLE tab MODIFY COLUMN c3 POLYGON NOT NULL;
480481

481482
ALTER TABLE tab add COLUMN c7 POINT NOT NULL;
@@ -552,8 +553,6 @@ SET @g2 = ST_GeomFromText('LINESTRING(1 1,2 2,3 3)');
552553
--enable_info
553554
ALTER TABLE tab MODIFY COLUMN c2 POINT NOT NULL;
554555

555-
ALTER TABLE tab MODIFY COLUMN c3 LINESTRING NOT NULL;
556-
557556
ALTER TABLE tab MODIFY COLUMN c4 POLYGON NOT NULL;
558557
--disable_info
559558

sql/field.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ class Field: public Value_source
15281528
{
15291529
return field_length / charset()->mbmaxlen;
15301530
}
1531-
virtual geometry_type get_geometry_type()
1531+
virtual geometry_type get_geometry_type() const
15321532
{
15331533
/* shouldn't get here. */
15341534
DBUG_ASSERT(0);
@@ -4138,6 +4138,21 @@ class Field_geom :public Field_blob {
41384138
const Item *item,
41394139
bool is_eq_func) const;
41404140
void sql_type(String &str) const;
4141+
Copy_func *get_copy_func(const Field *from) const
4142+
{
4143+
if (type_handler() == from->type_handler() &&
4144+
(geom_type == GEOM_GEOMETRY ||
4145+
geom_type == static_cast<const Field_geom*>(from)->geom_type))
4146+
return get_identical_copy_func();
4147+
return do_conv_blob;
4148+
}
4149+
bool memcpy_field_possible(const Field *from) const
4150+
{
4151+
return type_handler() == from->type_handler() &&
4152+
(geom_type == GEOM_GEOMETRY ||
4153+
geom_type == static_cast<const Field_geom*>(from)->geom_type) &&
4154+
!table->copy_blobs;
4155+
}
41414156
uint is_equal(Create_field *new_field);
41424157
int store(const char *to, size_t length, CHARSET_INFO *charset);
41434158
int store(double nr);
@@ -4161,7 +4176,7 @@ class Field_geom :public Field_blob {
41614176
bool load_data_set_null(THD *thd);
41624177
bool load_data_set_no_data(THD *thd, bool fixed_format);
41634178

4164-
geometry_type get_geometry_type() { return geom_type; };
4179+
geometry_type get_geometry_type() const { return geom_type; };
41654180
static geometry_type geometry_type_merge(geometry_type, geometry_type);
41664181
uint get_srid() { return srid; }
41674182
void print_key_value(String *out, uint32 length)

0 commit comments

Comments
 (0)