Bug #122078 ST_Within returns different rows with FORCE INDEX for an SRID 4326 geometry near the South Pole

Submitted: 5 Dec 14:40
Reporter: yeah Kun Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: GIS Severity:S2 (Serious)
Version:26.7.0 OS:Windows (64-bit Windows)
Assigned to: CPU Architecture:Any
Tags: gis, spatial-index, SRID-4326, st_within, wrong-result

[5 Dec 14:40] yeah Kun
Description:
On MySQL Community Server 26.7.0, the result of ST_Within changes when a spatial index is forced.

The test uses a valid SRID 4326 polygon and one point. In the same session, ST_Within(p, @south) evaluates to 1 for the row. A SELECT using IGNORE INDEX (sp_p) returns id=1, while the otherwise identical SELECT using FORCE INDEX (sp_p) returns no rows. EXPLAIN shows that the forced-index query uses a range access on sp_p.

Since the index hint changes the access path but not the predicate or data, both queries should return the same result. The mismatch was reproduced in 3 of 3 runs on an isolated MySQL 26.7.0 instance, each starting with a fresh test schema.

How to repeat:
CREATE DATABASE spatial_within_force_idx_repro;
USE spatial_within_force_idx_repro;

CREATE TABLE g (
  id INT PRIMARY KEY,
  p POINT NOT NULL SRID 4326,
  SPATIAL INDEX sp_p (p)
) ENGINE=InnoDB;

INSERT INTO g VALUES
  (1, ST_GeomFromText('POINT(0 0)', 4326, 'axis-order=long-lat'));

SET @south = ST_GeomFromText(
  'POLYGON((-45 -90,45 -90,45 -80,-45 -80,-45 -90))',
  4326,
  'axis-order=long-lat'
);

SELECT VERSION();

SELECT ST_IsValid(@south), ST_Validate(@south) IS NOT NULL;
-- Observed: 1, 1

SELECT ST_Within(p, @south) FROM g;
-- Observed: 1

SELECT id FROM g IGNORE INDEX (sp_p)
WHERE ST_Within(p, @south);
-- Observed: id=1

SELECT id FROM g FORCE INDEX (sp_p)
WHERE ST_Within(p, @south);
-- Observed: empty result set

EXPLAIN FORMAT=TRADITIONAL
SELECT id FROM g FORCE INDEX (sp_p)
WHERE ST_Within(p, @south);
-- Observed: range access using sp_p

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.