Bug #78213 Spatial index causes incorrect cardinality for all non-primary indexes
| Submitted: | 25 Aug 2015 20:03 | Modified: | 7 Oct 2015 17:19 |
|---|---|---|---|
| Reporter: | Christopher Middleton | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
| Version: | 5.6, 5.6.26, 5.5.46, 5.1.77 | OS: | Any (Mac OS X 10.9 and CentOS 6) |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | cardinality, explain, Geometry, Optimizer, spatial index | ||
[25 Aug 2015 20:03]
Christopher Middleton
[25 Aug 2015 22:49]
Christopher Middleton
> This causes the query optimizer to avoid using the spatial index (or other indexes) This is incorrect. It should say "This causes the query optimizer to avoid using the indexes." I don't know whether or not the spatial index also suffers from the query optimization error caused by a cardinality of 1.
[4 Sep 2015 7:25]
MySQL Verification Team
Hello Christopher Middleton, Thank you for the report and test case. Thanks, Umesh
[4 Sep 2015 7:25]
MySQL Verification Team
// with myisam - 5.6.26, 5.5.46 - affected mysql> SHOW INDEXES FROM geomtest; +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | geomtest | 0 | PRIMARY | 1 | id | A | 7 | NULL | NULL | | BTREE | | | | geomtest | 1 | plot | 1 | plot | A | 1 | 32 | NULL | | SPATIAL | | | | geomtest | 1 | name | 1 | name | A | 1 | NULL | NULL | | BTREE | | | | geomtest | 1 | pet | 1 | pet | A | 1 | NULL | NULL | | BTREE | | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 4 rows in set (0.00 sec) mysql> drop index plot on geomtest; Query OK, 7 rows affected (0.02 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> ANALYZE TABLE geomtest; +---------------+---------+----------+----------+ | Table | Op | Msg_type | Msg_text | +---------------+---------+----------+----------+ | test.geomtest | analyze | status | OK | +---------------+---------+----------+----------+ 1 row in set (0.00 sec) mysql> SHOW INDEXES FROM geomtest; +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | geomtest | 0 | PRIMARY | 1 | id | A | 7 | NULL | NULL | | BTREE | | | | geomtest | 1 | name | 1 | name | A | 3 | NULL | NULL | | BTREE | | | | geomtest | 1 | pet | 1 | pet | A | 3 | NULL | NULL | | BTREE | | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 3 rows in set (0.00 sec)
[4 Sep 2015 7:26]
MySQL Verification Team
// 5.7.9 ( Innodb used ) mysql> show variables like '%version%'; +-------------------------+---------------------------------------------------------+ | Variable_name | Value | +-------------------------+---------------------------------------------------------+ | innodb_version | 5.7.9 | | protocol_version | 10 | | slave_type_conversions | | | version | 5.7.9-enterprise-commercial-advanced | | version_comment | MySQL Enterprise Server - Advanced Edition (Commercial) | | version_compile_machine | x86_64 | | version_compile_os | linux-glibc2.5 | +-------------------------+---------------------------------------------------------+ 7 rows in set, 1 warning (0.01 sec) mysql> SHOW INDEXES FROM geomtest; +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | geomtest | 0 | PRIMARY | 1 | id | A | 7 | NULL | NULL | | BTREE | | | | geomtest | 1 | plot | 1 | plot | A | 7 | 32 | NULL | | SPATIAL | | | | geomtest | 1 | name | 1 | name | A | 3 | NULL | NULL | | BTREE | | | | geomtest | 1 | pet | 1 | pet | A | 3 | NULL | NULL | | BTREE | | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 4 rows in set (0.00 sec)
[4 Sep 2015 7:37]
MySQL Verification Team
// 5.1.77(myisam) - same as 5.5, 5.6 mysql> SHOW INDEXES FROM geomtest; +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | geomtest | 0 | PRIMARY | 1 | id | A | 7 | NULL | NULL | | BTREE | | | geomtest | 1 | plot | 1 | plot | A | 1 | 32 | NULL | | SPATIAL | | | geomtest | 1 | name | 1 | name | A | 1 | NULL | NULL | | BTREE | | | geomtest | 1 | pet | 1 | pet | A | 1 | NULL | NULL | | BTREE | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 4 rows in set (0.00 sec) mysql> show variables like '%version%'; +-------------------------+---------------------+ | Variable_name | Value | +-------------------------+---------------------+ | protocol_version | 10 | | version | 5.1.77 | | version_comment | Source distribution | | version_compile_machine | x86_64 | | version_compile_os | unknown-linux-gnu | +-------------------------+---------------------+ 5 rows in set (0.00 sec)
[4 Sep 2015 8:02]
Norvald Ryeng
Posted by developer: Only affects MyISAM, not InnoDB.
[7 Oct 2015 17:19]
Paul DuBois
Noted in 5.8.0 changelog. Adding a SPATIAL index to a MyISAM table could cause the cardinality of other indexes to become incorrect.
[23 Oct 2015 12:55]
Paul DuBois
Noted in 5.7.10 changelog.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.060 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.