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
11CREATE TABLE t1 (p POINT);
12CREATE TABLE t2 (p POINT, INDEX(p));
13INSERT INTO t1 VALUES (ST_POINTFROMTEXT('POINT(1 2)'));
14INSERT INTO t2 VALUES (ST_POINTFROMTEXT('POINT(1 2)'));
15
16# no index, returns 1 as expected
17SELECT COUNT(*) FROM t1 WHERE p=ST_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
22EXPLAIN
23SELECT COUNT(*) FROM t2 WHERE p=ST_POINTFROMTEXT('POINT(1 2)');
24SELECT COUNT(*) FROM t2 WHERE p=ST_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
30INSERT INTO t1 VALUES (ST_POINTFROMTEXT('POINT(1 2)'));
31INSERT INTO t2 VALUES (ST_POINTFROMTEXT('POINT(1 2)'));
32EXPLAIN
33SELECT COUNT(*) FROM t1 WHERE p=ST_POINTFROMTEXT('POINT(1 2)');
34SELECT COUNT(*) FROM t1 WHERE p=ST_POINTFROMTEXT('POINT(1 2)');
35
36EXPLAIN
37SELECT COUNT(*) FROM t2 WHERE p=ST_POINTFROMTEXT('POINT(1 2)');
38SELECT COUNT(*) FROM t2 WHERE p=ST_POINTFROMTEXT('POINT(1 2)');
39
40EXPLAIN
41SELECT COUNT(*) FROM t2 IGNORE INDEX(p) WHERE p=ST_POINTFROMTEXT('POINT(1 2)');
42SELECT COUNT(*) FROM t2 IGNORE INDEX(p) WHERE p=ST_POINTFROMTEXT('POINT(1 2)');
43
44DROP 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
54drop table if exists t1;
55--enable_warnings
56--echo # The minimal test case.
57create table t1 (a int not null, b linestring not null, unique key b (b(12)), unique key a (a));
58drop table t1;
59--echo # The original test case.
60create table t1 (a int not null, b linestring not null, unique key b (b(12)));
61create unique index a on t1(a);
62drop table t1;
63