Skip to content

Commit 9253064

Browse files
committed
MDEV-7682 Incorrect use of SPATIAL KEY for query plan
If the spatial key is used within an equality comparison, the comparison does not produce relevant results generally as identical geometry can be stored differently. Still, we want to support the operation. In order to allow a hash join plan, we must define a key_length for Field_geom.
1 parent 5e20df2 commit 9253064

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mysql-test/r/select_jcl6.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,7 @@ INSERT INTO t1 VALUES
44174417
EXPLAIN SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2;
44184418
id select_type table type possible_keys key key_len ref rows Extra
44194419
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
4420-
1 SIMPLE t2 hash_ALL a #hash#$hj 2 test.t1.a 2 Using where; Using join buffer (flat, BNLH join)
4420+
1 SIMPLE t2 hash_ALL a #hash#$hj 6 test.t1.a 2 Using where; Using join buffer (flat, BNLH join)
44214421
SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2;
44224422
1
44234423
1
@@ -4427,7 +4427,7 @@ SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2;
44274427
EXPLAIN SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2 FORCE INDEX(a);
44284428
id select_type table type possible_keys key key_len ref rows Extra
44294429
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
4430-
1 SIMPLE t2 hash_ALL a #hash#$hj 2 test.t1.a 2 Using where; Using join buffer (flat, BNLH join)
4430+
1 SIMPLE t2 hash_ALL a #hash#$hj 6 test.t1.a 2 Using where; Using join buffer (flat, BNLH join)
44314431
SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2 FORCE INDEX(a);
44324432
1
44334433
1

sql/field.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,14 @@ class Field_geom :public Field_blob {
19821982
int store(longlong nr, bool unsigned_val);
19831983
int store_decimal(const my_decimal *);
19841984
uint size_of() const { return sizeof(*this); }
1985+
/**
1986+
Key length is provided only to support hash joins. (compared byte for byte)
1987+
Ex: SELECT .. FROM t1,t2 WHERE t1.field_geom1=t2.field_geom2.
1988+
1989+
The comparison is not very relevant, as identical geometry might be
1990+
represented differently, but we need to support it either way.
1991+
*/
1992+
uint32 key_length() const { return packlength; }
19851993

19861994
/**
19871995
Non-nullable GEOMETRY types cannot have defaults,

0 commit comments

Comments
 (0)