Skip to content

Commit bcc3a65

Browse files
committed
Bug#22131961 CANNOT GET GEOMETRY OBJECT FROM DATA YOU SEND TO THE
GEOMETRY FIELD This is a regression introduced by the fix for bug #21614368. Problem: Queries that need to store the result of ST_AsBinary/ST_AsWKB in a temporary table will fail with an error message. Item_func_as_wkb::field_type() claims that the item returns a geometry column, but actually returns a binary string (WKB). Fix: Revert the fix for bug #21614368. New fix for bug #21614368: Change Item_cache::setup() to copy the used tables map from non-field items. This will make the Item_cache object non-const during resolving, and example's val_xxx() won't be called.
1 parent ccfab0f commit bcc3a65

File tree

10 files changed

+71
-26
lines changed

10 files changed

+71
-26
lines changed

mysql-test/r/gis.result

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def test t1 t1 g g 255 4294967295 0 Y 144 0 63
694694
g
695695
select ST_asbinary(g) from t1;
696696
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
697-
def ST_asbinary(g) 255 4294967295 0 Y 128 0 63
697+
def ST_asbinary(g) 252 4294967295 0 Y 128 0 63
698698
ST_asbinary(g)
699699
drop table t1;
700700
create table t1 (a TEXT, b GEOMETRY NOT NULL, SPATIAL KEY(b));
@@ -766,7 +766,7 @@ from
766766
t2 ws;
767767
describe t3;
768768
Field Type Null Key Default Extra
769-
geomdatawkb geometry YES NULL
769+
geomdatawkb longblob YES NULL
770770
drop table t1;
771771
drop table t2;
772772
drop table t3;
@@ -1128,7 +1128,9 @@ FORCE INDEX(i) WHERE a = date_sub(now(), interval 2808.4 year_month)
11281128
;
11291129
1
11301130
Warnings:
1131+
Warning 1292 Truncated incorrect datetime value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0?\x00\x00\x00\x00\x00\x00\xF0?'
11311132
Warning 1441 Datetime function: datetime field overflow
1133+
Warning 1292 Truncated incorrect datetime value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0?\x00\x00\x00\x00\x00\x00\x00@'
11321134
DROP TABLE g1;
11331135
#
11341136
# Bug#13013970 MORE CRASHES IN FIELD_BLOB::GET_KEY_IMAGE
@@ -2373,20 +2375,31 @@ rescol
23732375
SELECT ST_GeomFromText('POINT(0 0)') IN (SELECT b FROM t) AS result;
23742376
result
23752377
0
2378+
Warnings:
2379+
Warning 1292 Incorrect date value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' for column 'b' at row 1
23762380
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) IN (SELECT b FROM t) AS result;
23772381
result
23782382
0
2383+
Warnings:
2384+
Warning 1292 Incorrect date value: '\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' for column 'b' at row 1
23792385
INSERT INTO t VALUES(ST_GeomFromText('POINT(0 0)'), CURDATE());
23802386
SELECT ST_GeomFromText('POINT(0 0)') IN (SELECT b FROM t) AS result;
23812387
result
23822388
0
2389+
Warnings:
2390+
Warning 1292 Incorrect date value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' for column 'b' at row 1
23832391
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) IN (SELECT b FROM t) AS result;
23842392
result
23852393
0
2394+
Warnings:
2395+
Warning 1292 Incorrect date value: '\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' for column 'b' at row 1
23862396
SELECT ST_GeomFromText('POINT(0 0)') > (SELECT b FROM t) AS result;
23872397
ERROR HY000: Incorrect arguments to >
23882398
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) > (SELECT b FROM t) AS result;
2389-
ERROR HY000: Incorrect arguments to >
2399+
result
2400+
0
2401+
Warnings:
2402+
Warning 1292 Truncated incorrect date value: '\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
23902403
DROP TABLE t;
23912404
CREATE TABLE t1(a BLOB NOT NULL, b INT NOT NULL) ENGINE=Innodb;
23922405
SELECT NOT EXISTS
@@ -2420,7 +2433,8 @@ result
24202433
SELECT ST_GeomFromText('POINT(0 0)') > (SELECT b FROM t1) AS result;
24212434
ERROR HY000: Incorrect arguments to >
24222435
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) > (SELECT b FROM t1) AS result;
2423-
ERROR HY000: Incorrect arguments to >
2436+
result
2437+
0
24242438
DROP TABLE t1;
24252439
#
24262440
# Bug #19880316 ALTER TABLE INSERTS INVALID VALUES IN GEOMETRY COLUMNS
@@ -3037,3 +3051,19 @@ SELECT ST_ISVALID(ST_DIFFERENCE(ST_GEOMFROMTEXT('POLYGON((8 6,5 7,-1
30373051
11,-8 -3,3 5))'))) AS result;
30383052
result
30393053
1
3054+
#
3055+
# Bug #22131961 CANNOT GET GEOMETRY OBJECT FROM DATA YOU SEND TO THE
3056+
# GEOMETRY FIELD
3057+
#
3058+
CREATE TABLE d (id INT, r_id INT, i INT);
3059+
INSERT INTO d VALUES (1, 1, 1);
3060+
CREATE TABLE dp (id INT, d_id INT);
3061+
INSERT INTO dp VALUES (1, 1);
3062+
CREATE TABLE r (id INT, p POINT);
3063+
INSERT INTO r VALUES (1, ST_GEOMFROMTEXT('POINT(1 1)'));
3064+
DO (SELECT ST_ASBINARY(r.p)
3065+
FROM d
3066+
INNER JOIN dp ON d.id = dp.d_id
3067+
INNER JOIN r ON d.r_id = r.id
3068+
ORDER BY d.i);
3069+
DROP TABLE d, dp, r;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def test t1 t1 g g 255 4294967295 0 Y 144 0 63
696696
g
697697
select ST_asbinary(g) from t1;
698698
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
699-
def ST_asbinary(g) 255 4294967295 0 Y 128 0 63
699+
def ST_asbinary(g) 252 4294967295 0 Y 128 0 63
700700
ST_asbinary(g)
701701
drop table t1;
702702
create table t1 (a TEXT, b GEOMETRY NOT NULL, INDEX(b(5)));
@@ -778,7 +778,7 @@ from
778778
t2 ws;
779779
describe t3;
780780
Field Type Null Key Default Extra
781-
geomdatawkb geometry YES NULL
781+
geomdatawkb longblob YES NULL
782782
drop table t1;
783783
drop table t2;
784784
drop table t3;
@@ -1134,7 +1134,9 @@ FORCE INDEX(i) WHERE a = date_sub(now(), interval 2808.4 year_month)
11341134
;
11351135
1
11361136
Warnings:
1137+
Warning 1292 Truncated incorrect datetime value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0?\x00\x00\x00\x00\x00\x00\xF0?'
11371138
Warning 1441 Datetime function: datetime field overflow
1139+
Warning 1292 Truncated incorrect datetime value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0?\x00\x00\x00\x00\x00\x00\x00@'
11381140
DROP TABLE g1;
11391141
#
11401142
# Bug#13013970 MORE CRASHES IN FIELD_BLOB::GET_KEY_IMAGE

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def test t1 t1 g g 255 4294967295 0 Y 144 0 63
696696
g
697697
select ST_asbinary(g) from t1;
698698
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
699-
def ST_asbinary(g) 255 4294967295 0 Y 128 0 63
699+
def ST_asbinary(g) 252 4294967295 0 Y 128 0 63
700700
ST_asbinary(g)
701701
drop table t1;
702702
create table t1 (a TEXT, b GEOMETRY NOT NULL, SPATIAL KEY(b));
@@ -774,7 +774,7 @@ from
774774
t2 ws;
775775
describe t3;
776776
Field Type Null Key Default Extra
777-
geomdatawkb geometry YES NULL
777+
geomdatawkb longblob YES NULL
778778
drop table t1;
779779
drop table t2;
780780
drop table t3;
@@ -1135,7 +1135,9 @@ FORCE INDEX(i) WHERE a = date_sub(now(), interval 2808.4 year_month)
11351135
;
11361136
1
11371137
Warnings:
1138+
Warning 1292 Truncated incorrect datetime value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0?\x00\x00\x00\x00\x00\x00\xF0?'
11381139
Warning 1441 Datetime function: datetime field overflow
1140+
Warning 1292 Truncated incorrect datetime value: '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0?\x00\x00\x00\x00\x00\x00\x00@'
11391141
DROP TABLE g1;
11401142
#
11411143
# Bug#13013970 MORE CRASHES IN FIELD_BLOB::GET_KEY_IMAGE

mysql-test/t/gis.test

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,6 @@ SELECT ST_GeomFromText('POINT(0 0)') IN (SELECT b FROM t) AS result;
24012401
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) IN (SELECT b FROM t) AS result;
24022402
--error ER_WRONG_ARGUMENTS
24032403
SELECT ST_GeomFromText('POINT(0 0)') > (SELECT b FROM t) AS result;
2404-
--error ER_WRONG_ARGUMENTS
24052404
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) > (SELECT b FROM t) AS result;
24062405
DROP TABLE t;
24072406

@@ -2429,7 +2428,6 @@ SELECT ST_GeomFromText('POINT(0 0)') IN (SELECT b FROM t1) AS result;
24292428
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) IN (SELECT b FROM t1) AS result;
24302429
--error ER_WRONG_ARGUMENTS
24312430
SELECT ST_GeomFromText('POINT(0 0)') > (SELECT b FROM t1) AS result;
2432-
--error ER_WRONG_ARGUMENTS
24332431
SELECT ST_AsWKB(ST_GeomFromText('POINT(0 0)')) > (SELECT b FROM t1) AS result;
24342432
DROP TABLE t1;
24352433

@@ -2848,3 +2846,25 @@ SELECT ST_ISVALID(ST_UNION(ST_GEOMFROMTEXT('POLYGON((4 5,12 11,-12
28482846
SELECT ST_ISVALID(ST_DIFFERENCE(ST_GEOMFROMTEXT('POLYGON((8 6,5 7,-1
28492847
4,-8 -7,0 -17,8 6),(3 6,5 5,0 -2,3 6))'), ST_GEOMFROMTEXT('POLYGON((3 5,-17
28502848
11,-8 -3,3 5))'))) AS result;
2849+
2850+
--echo #
2851+
--echo # Bug #22131961 CANNOT GET GEOMETRY OBJECT FROM DATA YOU SEND TO THE
2852+
--echo # GEOMETRY FIELD
2853+
--echo #
2854+
2855+
CREATE TABLE d (id INT, r_id INT, i INT);
2856+
INSERT INTO d VALUES (1, 1, 1);
2857+
2858+
CREATE TABLE dp (id INT, d_id INT);
2859+
INSERT INTO dp VALUES (1, 1);
2860+
2861+
CREATE TABLE r (id INT, p POINT);
2862+
INSERT INTO r VALUES (1, ST_GEOMFROMTEXT('POINT(1 1)'));
2863+
2864+
DO (SELECT ST_ASBINARY(r.p)
2865+
FROM d
2866+
INNER JOIN dp ON d.id = dp.d_id
2867+
INNER JOIN r ON d.r_id = r.id
2868+
ORDER BY d.i);
2869+
2870+
DROP TABLE d, dp, r;

sql/item.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,6 +5110,10 @@ class Item_cache: public Item_basic_constant
51105110
if (((Item_field *)item)->table_ref)
51115111
used_table_map= ((Item_field *)item)->table_ref->map();
51125112
}
5113+
else
5114+
{
5115+
used_table_map= item->used_tables();
5116+
}
51135117
return 0;
51145118
};
51155119
enum Type type() const { return CACHE_ITEM; }

sql/item_cmpfunc.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,6 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value)
10181018
if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
10191019
return false;
10201020

1021-
// GEOMETRY data is never convertible to any other type of data.
1022-
if (a->field_type() == MYSQL_TYPE_GEOMETRY ||
1023-
b->field_type() == MYSQL_TYPE_GEOMETRY)
1024-
return false;
1025-
10261021
if (a->is_temporal_with_date())
10271022
{
10281023
if (b->is_temporal_with_date()) // date[time] + date

sql/item_func.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Item_func :public Item_result_field
6161
SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC,
6262
SP_TOUCHES_FUNC,SP_CROSSES_FUNC,SP_WITHIN_FUNC,
6363
SP_CONTAINS_FUNC,SP_COVEREDBY_FUNC,SP_COVERS_FUNC,
64-
SP_OVERLAPS_FUNC, SP_WKB_FUNC,
64+
SP_OVERLAPS_FUNC,
6565
SP_STARTPOINT,SP_ENDPOINT,SP_EXTERIORRING,
6666
SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN,
6767
NOT_FUNC, NOT_ALL_FUNC,

sql/item_geofunc.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,8 @@ String *Item_func_geometry_from_wkb::val_str(String *str)
193193
Geometry::create_from_wkb(), and consequently such WKB data must be
194194
MySQL standard (little) endian. Note that users can pass via client
195195
any WKB/Geometry byte string, including those of big endianess.
196-
197-
For the functions that return WKB data(i.e. SP_WKB_FUNC), their field type
198-
is also MYSQL_TYPE_GEOMETRY to other part of MySQL, but to GIS we must
199-
distinguish them, and here is the only place where we have to do so.
200196
*/
201-
if (args[0]->field_type() == MYSQL_TYPE_GEOMETRY &&
202-
!(args[0]->type() == Item::FUNC_ITEM &&
203-
down_cast<Item_func *>(args[0])->functype() == SP_WKB_FUNC))
197+
if (args[0]->field_type() == MYSQL_TYPE_GEOMETRY)
204198
{
205199
Geometry_buffer buff;
206200
if (Geometry::construct(&buff, wkb->ptr(), wkb->length()) == NULL)

sql/item_geofunc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ class Item_func_as_wkb: public Item_geometry_func
256256
Item_func_as_wkb(const POS &pos, Item *a): Item_geometry_func(pos, a) {}
257257
const char *func_name() const { return "st_aswkb"; }
258258
String *val_str(String *);
259-
enum_field_types field_type() const { return MYSQL_TYPE_GEOMETRY; }
260-
enum Functype functype() const { return SP_WKB_FUNC; }
259+
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
261260
};
262261

263262
class Item_func_geometry_type: public Item_str_ascii_func

sql/opt_range.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6878,7 +6878,6 @@ bool is_spatial_operator(Item_func::Functype op_type)
68786878
case Item_func::SP_POINTN:
68796879
case Item_func::SP_GEOMETRYN:
68806880
case Item_func::SP_INTERIORRINGN:
6881-
case Item_func::SP_WKB_FUNC:
68826881
return true;
68836882
default:
68846883
return false;

0 commit comments

Comments
 (0)