[MDEV-12443] ST_Contains doesn't work as expected on InnoDB engine Created: 2017-04-04  Updated: 2017-05-02  Resolved: 2017-05-02

Status: Closed
Project: MariaDB Server
Component/s: GIS, Storage Engine - InnoDB
Affects Version/s: 10.2.4
Fix Version/s: 10.2.6

Type: Bug Priority: Major
Reporter: Reinis Rozitis Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: 10.2-ga

Issue Links:
Relates
relates to MDEV-12462 SPATIAL index fails to work with CONT... Closed
relates to MDEV-12462 SPATIAL index fails to work with CONT... Closed

 Description   

When a table with geometry field and spatial index is converted from MyISAM to InnoDB GIS function doesn't work as expected anymore:

  • No records are being returned even the statement is true (the geometry falls within the given borders of another)
  • When adding additional '=1' check - rows are returned but in that case no index is used (possible).

A small test case:

DROP TABLE IF EXISTS `objects`;
 
CREATE TABLE `objects` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `bounds` geometry NOT NULL,
  PRIMARY KEY (`id`),
  SPATIAL KEY `bounds` (`bounds`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
INSERT INTO `objects` VALUES (1,0x000000000103000000010000001100000051653FC69612494000000000C0EA0840B101B67B2FE2484000000000C0220D40FDA9371F45D248400000000020481040B5270BD172D048400000000060E811409A033715FBCA484000000000E05812407C1B8214E8AB48400000000060D713404D0C25C71E9348400000000000CC1540259FDC1CBDAD48400000000070B21940B0226899F92949400000000060ED1B40D7B36C6FAF7849400000000080FB1A406582C73D5EC6494000000000205E18408FE35055B8E7494000000000F0CE13405631E16F75E449400000000080600F401A8FF47F8EC1494000000000402602407BFFEE6A2A4249400000000040340340EEA681117C25494000000000C0D1034051653FC69612494000000000C0EA0840);
 
-- No rows are returned
SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)'));
EXPLAIN SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)'));
 
-- A row is returned but no index is being used
SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)')) = 1;
EXPLAIN SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)')) = 1;
 
 
-- ST_Within works fine and returns correct result and uses index
SELECT id FROM  objects WHERE ST_Within(GeomFromText('POINT(50.83216 3.59565)'),bounds);
 
 
-- MyISAM - everything works as expected
ALTER TABLE `objects` ENGINE=MyISAM;
 
SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)'));
EXPLAIN SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)'));
 
SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)')) = 1;
EXPLAIN SELECT id FROM  objects WHERE ST_Contains(bounds, GeomFromText('POINT(50.83216 3.59565)')) = 1;

Also the oppposite funcion ST_Within works as expected.



 Comments   
Comment by Reinis Rozitis [ 2017-04-04 ]

I havent tested this on vanilla MySQL yet / it might aswell be an upstream issue.

Comment by Elena Stepanova [ 2017-04-20 ]

Might be the same as or closely related to MDEV-12462. Please check both test cases after fixing.

Comment by Alexey Botchkov [ 2017-05-02 ]

That's the manifestation of the MDEV-12462, so fixed along.

Comment by Reinis Rozitis [ 2017-05-02 ]

Fix version should probably be 10.2.6 as on 10.2.5 which is already released the bug still exists.

Generated at Thu Feb 08 07:57:45 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.