MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gis_keys.inc
1 --source include/have_geometry.inc
2 
3 #
4 # Spatial objects with keys
5 #
6 
7 #
8 # Bug #30825: Problems when putting a non-spatial index on a GIS column
9 #
10 
11 CREATE TABLE t1 (p POINT);
12 CREATE TABLE t2 (p POINT, INDEX(p));
13 INSERT INTO t1 VALUES (POINTFROMTEXT('POINT(1 2)'));
14 INSERT INTO t2 VALUES (POINTFROMTEXT('POINT(1 2)'));
15 
16 # no index, returns 1 as expected
17 SELECT COUNT(*) FROM t1 WHERE p=POINTFROMTEXT('POINT(1 2)');
18 
19 # with index, returns 1 as expected
20 # EXPLAIN shows that the index is not used though
21 # due to the "most rows covered anyway, so a scan is more effective" rule
22 EXPLAIN
23 SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
24 SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
25 
26 # adding another row to the table so that
27 # the "most rows covered" rule doesn't kick in anymore
28 # now EXPLAIN shows the index used on the table
29 # and we're getting the wrong result again
30 INSERT INTO t1 VALUES (POINTFROMTEXT('POINT(1 2)'));
31 INSERT INTO t2 VALUES (POINTFROMTEXT('POINT(1 2)'));
32 EXPLAIN
33 SELECT COUNT(*) FROM t1 WHERE p=POINTFROMTEXT('POINT(1 2)');
34 SELECT COUNT(*) FROM t1 WHERE p=POINTFROMTEXT('POINT(1 2)');
35 
36 EXPLAIN
37 SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
38 SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
39 
40 EXPLAIN
41 SELECT COUNT(*) FROM t2 IGNORE INDEX(p) WHERE p=POINTFROMTEXT('POINT(1 2)');
42 SELECT COUNT(*) FROM t2 IGNORE INDEX(p) WHERE p=POINTFROMTEXT('POINT(1 2)');
43 
44 DROP TABLE t1, t2;
45 
46 --echo End of 5.0 tests
47 
48 
49 --echo #
50 --echo # Test for bug #58650 "Failing assertion: primary_key_no == -1 ||
51 --echo # primary_key_no == 0".
52 --echo #
53 --disable_warnings
54 drop table if exists t1;
55 --enable_warnings
56 --echo # The minimal test case.
57 create table t1 (a int not null, b linestring not null, unique key b (b(12)), unique key a (a));
58 drop table t1;
59 --echo # The original test case.
60 create table t1 (a int not null, b linestring not null, unique key b (b(12)));
61 create unique index a on t1(a);
62 drop table t1;