From 1f28350b59e022b4e968dd880d8f2de2def9f5f5 Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Tue, 9 Jul 2024 23:44:44 +0530 Subject: [PATCH] MDEV-32456: incorrect result of gis function in view protocol There are 3 diff in result: 1) NULL value from SELECT Due to incorrect truncating of the hex value, incorrect value is written instead of original value to the view frm. This results in reading incorrect value from frm, so eventual result is NULL. 2) 'Name_exp1' in column name (in gis.test) This was because the identifier in SELECT is longer than 64 characters, so 'Name_exp1' alias is also written to the view frm. 3)diff in explain extended This was because the query plan for view protocol doesn't contain database name. As a fix, disable view protocol for that particular query. --- mysql-test/include/gis_generic.inc | 2 ++ mysql-test/suite/innodb_gis/r/1.result | 12 ++++++------ mysql-test/suite/innodb_gis/r/gis.result | 12 ++++++------ mysql-test/suite/innodb_gis/t/1.test | 11 ++++++++--- mysql-test/suite/innodb_gis/t/geometry.test | 3 +++ mysql-test/suite/innodb_gis/t/gis.test | 11 ++++++++--- sql/item.cc | 4 +--- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/mysql-test/include/gis_generic.inc b/mysql-test/include/gis_generic.inc index 8209240614e..80fdb6f324e 100644 --- a/mysql-test/include/gis_generic.inc +++ b/mysql-test/include/gis_generic.inc @@ -142,11 +142,13 @@ Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o, Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t, Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; +--disable_view_protocol explain extended SELECT g1.fid as first, g2.fid as second, Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o, Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t, Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; +--enable_view_protocol DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; diff --git a/mysql-test/suite/innodb_gis/r/1.result b/mysql-test/suite/innodb_gis/r/1.result index 6db6407b5db..909051cc54e 100644 --- a/mysql-test/suite/innodb_gis/r/1.result +++ b/mysql-test/suite/innodb_gis/r/1.result @@ -433,8 +433,8 @@ gc geometrycollection YES NULL gm geometry YES NULL fid int(11) NO NULL DROP TABLE t1; -SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); -ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))) +SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))) AS val; +val POINT(1 4) explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -668,11 +668,11 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field insert into t1 values (ST_pointfromtext('point(1,1)')); ERROR 23000: Column 'fl' cannot be null drop table t1; -select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))); -(ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))) +select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))) AS val; +val POINT(10 10) -select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))); -(ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))) +select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))) AS val; +val POINT(10 10) create table t1 (g GEOMETRY); select * from t1; diff --git a/mysql-test/suite/innodb_gis/r/gis.result b/mysql-test/suite/innodb_gis/r/gis.result index 2a31a6c5317..e7f735b5094 100644 --- a/mysql-test/suite/innodb_gis/r/gis.result +++ b/mysql-test/suite/innodb_gis/r/gis.result @@ -433,8 +433,8 @@ gc geometrycollection YES NULL gm geometry YES NULL fid int(11) NO NULL DROP TABLE t1; -SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); -ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))) +SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))) AS val; +val POINT(1 4) explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -668,11 +668,11 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field insert into t1 values (ST_pointfromtext('point(1,1)')); ERROR 23000: Column 'fl' cannot be null drop table t1; -select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))); -(ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))) +select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))) AS val; +val POINT(10 10) -select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))); -(ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))) +select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))) AS val; +val POINT(10 10) create table t1 (g GEOMETRY); select * from t1; diff --git a/mysql-test/suite/innodb_gis/t/1.test b/mysql-test/suite/innodb_gis/t/1.test index f08fdaddbda..3a5103860e1 100644 --- a/mysql-test/suite/innodb_gis/t/1.test +++ b/mysql-test/suite/innodb_gis/t/1.test @@ -136,17 +136,20 @@ SELECT fid, ST_AsText(ST_GeometryN(g, 1)) from gis_geometrycollection; --replace_column 10 # explain extended SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_point; +--disable_view_protocol SELECT g1.fid as first, g2.fid as second, MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o, MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t, MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; + --replace_column 10 # explain extended SELECT g1.fid as first, g2.fid as second, MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o, MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t, MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; +--enable_view_protocol DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; @@ -169,7 +172,7 @@ ALTER TABLE t1 ADD fid INT NOT NULL; SHOW FIELDS FROM t1; DROP TABLE t1; -SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); +SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))) AS val; explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_PointFromText('POINT(1 4)')))); SELECT ST_SRID(ST_GeomFromText('LineString(1 1,2 2)',101)); @@ -398,14 +401,16 @@ insert into t1 values (ST_pointfromtext('point(1,1)')); drop table t1; -select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))); -select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))); +select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))) AS val; +select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))) AS val; +--disable_view_protocol --enable_metadata create table t1 (g GEOMETRY); select * from t1; select ST_asbinary(g) from t1; --disable_metadata +--enable_view_protocol drop table t1; create table t1 (a TEXT, b GEOMETRY NOT NULL, INDEX(b(5))); diff --git a/mysql-test/suite/innodb_gis/t/geometry.test b/mysql-test/suite/innodb_gis/t/geometry.test index 3efc664fbd2..0d9b445be67 100644 --- a/mysql-test/suite/innodb_gis/t/geometry.test +++ b/mysql-test/suite/innodb_gis/t/geometry.test @@ -623,17 +623,20 @@ SELECT fid, ST_AsText(ST_GeometryN(g, 1)) from gis_geometrycollection; --replace_column 10 # explain extended SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_point; +--disable_view_protocol SELECT g1.fid as first, g2.fid as second, MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o, MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t, MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; + --replace_column 10 # explain extended SELECT g1.fid as first, g2.fid as second, MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o, MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t, MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; +--enable_view_protocol --echo # check support of Foreign Key constraint CREATE TABLE parent (id GEOMETRY NOT NULL,PRIMARY KEY (id(10))) ENGINE=INNODB; diff --git a/mysql-test/suite/innodb_gis/t/gis.test b/mysql-test/suite/innodb_gis/t/gis.test index 851e82308c6..ea9de7edfff 100644 --- a/mysql-test/suite/innodb_gis/t/gis.test +++ b/mysql-test/suite/innodb_gis/t/gis.test @@ -135,17 +135,20 @@ SELECT fid, ST_AsText(ST_GeometryN(g, 1)) from gis_geometrycollection; --replace_column 10 # explain extended SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_point; +--disable_view_protocol SELECT g1.fid as first, g2.fid as second, MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o, MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t, MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; + --replace_column 10 # explain extended SELECT g1.fid as first, g2.fid as second, MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o, MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t, MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; +--enable_view_protocol DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; @@ -168,7 +171,7 @@ ALTER TABLE t1 ADD fid INT NOT NULL; SHOW FIELDS FROM t1; DROP TABLE t1; -SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); +SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))) AS val; explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')))); explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_PointFromText('POINT(1 4)')))); SELECT ST_SRID(ST_GeomFromText('LineString(1 1,2 2)',101)); @@ -393,14 +396,16 @@ insert into t1 values (ST_pointfromtext('point(1,1)')); drop table t1; -select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))); -select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))); +select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000)))) AS val; +select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440)))) AS val; +--disable_view_protocol --enable_metadata create table t1 (g GEOMETRY); select * from t1; select ST_asbinary(g) from t1; --disable_metadata +--enable_view_protocol drop table t1; create table t1 (a TEXT, b GEOMETRY NOT NULL, SPATIAL KEY(b)); diff --git a/sql/item.cc b/sql/item.cc index 063003ee6bf..9ba00944c85 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7278,10 +7278,8 @@ void Item_hex_constant::hex_string_init(THD *thd, const char *str, size_t str_le void Item_hex_hybrid::print(String *str, enum_query_type query_type) { - uint32 len= MY_MIN(str_value.length(), sizeof(longlong)); - const char *ptr= str_value.ptr() + str_value.length() - len; str->append("0x"); - str->append_hex(ptr, len); + str->append_hex(str_value.ptr(), str_value.length()); }