CREATE TABLE zip_polygons_new(
zipcode MEDIUMINT(5) UNSIGNED NOT NULL,
zip_polygon MULTIPOLYGON NOT NULL,
spatial index (zip_polygon)
);
EXPLAIN
SELECT zipcode
FROM zip_polygons_new zp
WHERE ST_CONTAINS(zp.zip_polygon, ST_GEOMFROMTEXT('POINT(-99.24012 19.53285)'));
I always get:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | zp | ALL | 26376 | 100.0 | Using where |
I've tried:
- both InnoDB and MyIsam.
- Several spacial functions (e.g. MBRCONTAINS, ST_CONTAINS).
- putting an equality to 1 on RHS of WHERE clause.
Already checked: MySQL documentation Mysql Spatial index unused Why Spatial index not used by MySQL?
What am I missing to be able to use the index?