Skip to content

Commit 1945710

Browse files
author
Shaohua Wang
committed
BUG#21245805 HA_INNOBASE::RECORDS_IN_RANGE() RETURNS CONSTANT FOR SPATIAL INDEXES
Refer to rtree_estimate() in MyISAM, return a more accurate estimation for spatial index in InnoDB. Reviewed-by: Jimmy Yang <[email protected]> RB: 9466
1 parent 51353bc commit 1945710

20 files changed

+774
-270
lines changed

mysql-test/r/gis.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ ST_AsText(p)
21722172
POINT(30 30)
21732173
EXPLAIN SELECT ST_AsText(p) FROM t1 WHERE ST_Equals(p, ST_PointFromText('POINT(20 20)'));
21742174
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2175-
1 SIMPLE t1 NULL range PRIMARY,idx2 idx2 34 NULL 2 100.00 Using where
2175+
1 SIMPLE t1 NULL range PRIMARY,idx2 idx2 34 NULL 1 100.00 Using where
21762176
Warnings:
21772177
Note 1003 /* select#1 */ select st_astext(`test`.`t1`.`p`) AS `ST_AsText(p)` from `test`.`t1` where st_equals(`test`.`t1`.`p`,<cache>(st_geometryfromtext('POINT(20 20)')))
21782178
SELECT ST_AsText(p) FROM t1 WHERE ST_Equals(p, ST_PointFromText('POINT(20 20)'));

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

Lines changed: 204 additions & 195 deletions
Large diffs are not rendered by default.

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

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ POINT(1 0) POINT(10 20)
137137
POINT(0 0) POINT(10 20)
138138
SELECT ST_AsText(p), ST_AsText(p1) FROM t1 WHERE MBRWithin(p1, ST_GeomFromText('POLYGON((5 5, 20 5, 20 21, 5 21, 5 5))'));
139139
ST_AsText(p) ST_AsText(p1)
140-
POINT(0 0) POINT(10 20)
141-
POINT(1 0) POINT(10 20)
142-
POINT(1 1) POINT(10 20)
143140
POINT(0 1) POINT(10 20)
141+
POINT(1 1) POINT(10 20)
142+
POINT(1 0) POINT(10 20)
143+
POINT(0 0) POINT(10 20)
144144
SELECT ST_AsText(p), ST_AsText(p1) FROM t1 WHERE MBRWithin(p, ST_GeomFromText('POLYGON((-1 0.5, -1 -0.5, 1 -0.5, 1 0.5, -1 0.5))'));
145145
ST_AsText(p) ST_AsText(p1)
146146
POINT(0 0) POINT(10 20)
@@ -161,10 +161,10 @@ POINT(1 0) POINT(10 20)
161161
POINT(0 0) POINT(10 20)
162162
SELECT ST_AsText(p), ST_AsText(p1) FROM t1 WHERE MBRWithin(p1, ST_GeomFromText('POLYGON((5 5, 20 5, 20 21, 5 21, 5 5))'));
163163
ST_AsText(p) ST_AsText(p1)
164-
POINT(0 0) POINT(10 20)
165-
POINT(1 0) POINT(10 20)
166-
POINT(1 1) POINT(10 20)
167164
POINT(0 1) POINT(10 20)
165+
POINT(1 1) POINT(10 20)
166+
POINT(1 0) POINT(10 20)
167+
POINT(0 0) POINT(10 20)
168168
SELECT ST_AsText(p), ST_AsText(p1) FROM t1 WHERE MBRWithin(p, ST_GeomFromText('POLYGON((-1 0.5, -1 -0.5, 1 -0.5, 1 0.5, -1 0.5))'));
169169
ST_AsText(p) ST_AsText(p1)
170170
POINT(0 0) POINT(10 20)
@@ -751,54 +751,54 @@ ST_AsText(p1)
751751
POINT(5 10)
752752
SELECT ST_AsText(p1) FROM gis_point WHERE MBRWithin(p1, @poly1);
753753
ST_AsText(p1)
754-
POINT(4 8)
755754
POINT(3 6)
755+
POINT(4 8)
756756
SELECT ST_AsText(p2) FROM gis_point WHERE ST_Contains(@poly2, p2);
757757
ST_AsText(p2)
758-
POINT(-1 -1)
759758
POINT(-1 -3)
760759
POINT(-2 -6)
761760
POINT(-3 -9)
762761
POINT(-4 -12)
762+
POINT(-1 -1)
763763
SELECT ST_AsText(p2) FROM gis_point WHERE ST_Equals(p2, @p1);
764764
ST_AsText(p2)
765765
POINT(0 0)
766766
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Touches(@poly3, p1) AND MBRWithin(p2, @poly4);
767767
ST_AsText(p1)
768-
POINT(32.1234 64.2468)
769768
POINT(20.5 41)
769+
POINT(32.1234 64.2468)
770770
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Contains(@mpoly, p1);
771771
ST_AsText(p1)
772-
POINT(20.5 41)
773-
POINT(7 14)
774-
POINT(6 12)
775-
POINT(5 10)
776772
POINT(4 8)
773+
POINT(5 10)
774+
POINT(6 12)
775+
POINT(7 14)
776+
POINT(20.5 41)
777777
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Contains(@mpoly, p1) AND NOT MBRWithin(p1, @mpoly);
778778
ST_AsText(p1)
779779
# Check functions that use MBR, with line type data
780780
SELECT ST_AsText(p1) FROM gis_point WHERE MBRIntersects(p1, @ls1);
781781
ST_AsText(p1)
782-
POINT(9 18)
783-
POINT(8 16)
784-
POINT(7 14)
785-
POINT(6 12)
786-
POINT(5 10)
787-
POINT(4 8)
788-
POINT(3 6)
789-
POINT(2 4)
790782
POINT(1 2)
783+
POINT(2 4)
784+
POINT(3 6)
785+
POINT(4 8)
786+
POINT(5 10)
787+
POINT(6 12)
788+
POINT(7 14)
789+
POINT(8 16)
790+
POINT(9 18)
791791
SELECT ST_AsText(p1) FROM gis_point WHERE MBRWithin(p1, @ls1);
792792
ST_AsText(p1)
793-
POINT(9 18)
794-
POINT(8 16)
795-
POINT(7 14)
796-
POINT(6 12)
797-
POINT(5 10)
798-
POINT(4 8)
799-
POINT(3 6)
800-
POINT(2 4)
801793
POINT(1 2)
794+
POINT(2 4)
795+
POINT(3 6)
796+
POINT(4 8)
797+
POINT(5 10)
798+
POINT(6 12)
799+
POINT(7 14)
800+
POINT(8 16)
801+
POINT(9 18)
802802
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Touches(p1, @ls1);
803803
ST_AsText(p1)
804804
SELECT ST_AsText(p1) FROM gis_point WHERE MBRDisjoint(p1, @ls1);
@@ -819,18 +819,18 @@ ST_AsText(p1)
819819
# Check functions that use MBR, with polygon type data
820820
SELECT ST_AsText(p1) FROM gis_point WHERE MBRIntersects(p1, @poly1);
821821
ST_AsText(p1)
822-
POINT(5 10)
823-
POINT(4 8)
824-
POINT(3 6)
825822
POINT(2 4)
823+
POINT(3 6)
824+
POINT(4 8)
825+
POINT(5 10)
826826
SELECT ST_AsText(p1) FROM gis_point WHERE MBRWithin(p1, @poly1);
827827
ST_AsText(p1)
828-
POINT(4 8)
829828
POINT(3 6)
829+
POINT(4 8)
830830
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Touches(p1, @poly1);
831831
ST_AsText(p1)
832-
POINT(5 10)
833832
POINT(2 4)
833+
POINT(5 10)
834834
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Crosses(p1, @poly1);
835835
ST_AsText(p1)
836836
SELECT ST_AsText(p1) FROM gis_point WHERE MBRDisjoint(p1, @poly1);
@@ -943,18 +943,18 @@ ST_AsText(p1)
943943
# Check with MBR functions polygon type data
944944
SELECT ST_AsText(p1) FROM gis_point WHERE MBRIntersects(p1, @poly1);
945945
ST_AsText(p1)
946-
POINT(5 10)
947-
POINT(4 8)
948-
POINT(3 6)
949946
POINT(2 4)
947+
POINT(3 6)
948+
POINT(4 8)
949+
POINT(5 10)
950950
SELECT ST_AsText(p1) FROM gis_point WHERE MBRWithin(p1, @poly1);
951951
ST_AsText(p1)
952-
POINT(4 8)
953952
POINT(3 6)
953+
POINT(4 8)
954954
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Touches(p1, @poly1);
955955
ST_AsText(p1)
956-
POINT(5 10)
957956
POINT(2 4)
957+
POINT(5 10)
958958
SELECT ST_AsText(p1) FROM gis_point WHERE MBRDisjoint(p1, @poly1);
959959
ST_AsText(p1)
960960
POINT(32.1234 64.2468)
@@ -976,26 +976,26 @@ ST_AsText(p1)
976976
# Check with MBR functions line type data
977977
SELECT ST_AsText(p1) FROM gis_point WHERE MBRIntersects(p1, @ls1);
978978
ST_AsText(p1)
979-
POINT(9 18)
980-
POINT(8 16)
981-
POINT(7 14)
982-
POINT(6 12)
983-
POINT(5 10)
984-
POINT(4 8)
985-
POINT(3 6)
986-
POINT(2 4)
987979
POINT(1 2)
980+
POINT(2 4)
981+
POINT(3 6)
982+
POINT(4 8)
983+
POINT(5 10)
984+
POINT(6 12)
985+
POINT(7 14)
986+
POINT(8 16)
987+
POINT(9 18)
988988
SELECT ST_AsText(p1) FROM gis_point WHERE MBRWithin(p1, @ls1);
989989
ST_AsText(p1)
990-
POINT(9 18)
991-
POINT(8 16)
992-
POINT(7 14)
993-
POINT(6 12)
994-
POINT(5 10)
995-
POINT(4 8)
996-
POINT(3 6)
997-
POINT(2 4)
998990
POINT(1 2)
991+
POINT(2 4)
992+
POINT(3 6)
993+
POINT(4 8)
994+
POINT(5 10)
995+
POINT(6 12)
996+
POINT(7 14)
997+
POINT(8 16)
998+
POINT(9 18)
999999
SELECT ST_AsText(p1) FROM gis_point WHERE ST_Touches(p1, @ls1);
10001000
ST_AsText(p1)
10011001
SELECT ST_AsText(p1) FROM gis_point WHERE MBRDisjoint(p1, @ls1);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ t1 CREATE TABLE `t1` (
1616
SELECT count(*) FROM t1;
1717
count(*)
1818
150
19+
ANALYZE TABLE t1;
20+
Table Op Msg_type Msg_text
21+
test.t1 analyze status OK
1922
EXPLAIN SELECT fid, ST_AsText(g) FROM t1 WHERE ST_Within(g, ST_GeomFromText('Polygon((140 140,160 140,160 160,140 140))'));
2023
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2124
1 SIMPLE t1 NULL ALL gis_key NULL NULL NULL # 100.00 Using where

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ insert into t1 values (1, POINT(1.5,1.5));
44
insert into t1 values (1, POINT(3,3));
55
insert into t1 values (1, POINT(3.1,3.1));
66
insert into t1 values (1, POINT(5,5));
7+
analyze table t1;
8+
Table Op Msg_type Msg_text
9+
test.t1 analyze status OK
710
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
811
explain select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
912
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
10-
1 SIMPLE t1 NULL range g g 34 NULL 2 100.00 Using where
13+
1 SIMPLE t1 NULL ALL g NULL NULL NULL 5 100.00 Using where
1114
Warnings:
1215
Note 1003 /* select#1 */ select st_astext(`test`.`t1`.`g`) AS `ST_astext(t1.g)` from `test`.`t1` where mbrwithin(`test`.`t1`.`g`,(@`g1`))
1316
select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
1417
ST_astext(t1.g)
15-
POINT(1.5 1.5)
1618
POINT(1 1)
19+
POINT(1.5 1.5)
1720
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
1821
delete from t1 where MBRWithin(t1.g, @g1);
1922
check table t1;
@@ -59,9 +62,9 @@ name ST_AsText(square)
5962
small POLYGON((0 0,0 1,1 1,1 0,0 0))
6063
SELECT name, ST_AsText(square) from t1 where MBRDisjoint(@p, square);
6164
name ST_AsText(square)
62-
right3 POLYGON((3 0,3 2,5 2,5 0,3 0))
6365
up3 POLYGON((0 3,0 5,2 5,2 3,0 3))
6466
down3 POLYGON((0 -3,0 -1,2 -1,2 -3,0 -3))
67+
right3 POLYGON((3 0,3 2,5 2,5 0,3 0))
6568
left3 POLYGON((-3 0,-3 2,-1 2,-1 0,-3 0))
6669
SELECT name, ST_AsText(square) from t1 where MBREquals(@p, square);
6770
name ST_AsText(square)
@@ -154,16 +157,19 @@ insert into t1 values (2, "222", POINT(1.5,1.5));
154157
insert into t1 values (3, "333", POINT(3,3));
155158
insert into t1 values (4, "444", POINT(3.1,3.1));
156159
insert into t1 values (5, "555", POINT(5,5));
160+
analyze table t1;
161+
Table Op Msg_type Msg_text
162+
test.t1 analyze status OK
157163
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
158164
explain select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
159165
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
160-
1 SIMPLE t1 NULL range g g 34 NULL 2 100.00 Using where
166+
1 SIMPLE t1 NULL ALL g NULL NULL NULL 5 100.00 Using where
161167
Warnings:
162168
Note 1003 /* select#1 */ select st_astext(`test`.`t1`.`g`) AS `ST_astext(t1.g)` from `test`.`t1` where mbrwithin(`test`.`t1`.`g`,(@`g1`))
163169
select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
164170
ST_astext(t1.g)
165-
POINT(1.5 1.5)
166171
POINT(1 1)
172+
POINT(1.5 1.5)
167173
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
168174
delete from t1 where MBRWithin(t1.g, @g1);
169175
check table t1;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,15 @@ end|
296296
start transaction;
297297
CALL insert_t1(100);
298298
set @g1 = ST_GeomFromText('Polygon((0 0,0 1000,1000 1000,1000 0,0 0))');
299+
SET SESSION debug="+d,rtr_pcur_move_to_next_return";
299300
SET DEBUG_SYNC= 'rtr_pcur_move_to_next_return SIGNAL siga WAIT_FOR sigb';
300301
select count(*) from t1 where MBRWithin(t1.c2, @g1);;
301302
SET DEBUG_SYNC= 'now WAIT_FOR siga';
302303
rollback;
303304
SET DEBUG_SYNC= 'now SIGNAL sigb';
304305
count(*)
305306
0
307+
SET SESSION debug="-d,rtr_pcur_move_to_next_return";
306308
drop procedure insert_t1;
307309
DROP TABLE t1;
308310
SET DEBUG_SYNC = 'RESET';

0 commit comments

Comments
 (0)