I have spatial column and spatial index for it. When I making query, I see that MySql not using that index. Table has 10k records. Why?
schema.rb
create_table "homes_raw", id: :string, limit: 22, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t|
t.geometry "location", limit: {:type=>"point", :srid=>0}, null: false
t.index ["location"], name: "location_spatial", type: :spatial
end
Performing query with EXPLAIN
EXPLAIN for: SELECT `homes_raw`.* FROM `homes_raw` WHERE (ST_Distance_Sphere(
ST_GeomFromText(ST_AsText(location), 0), POINT(60.41217340143263, 64.48856982983708)
) <= 100000)
```
[EPLAIN result][1]
[1]: https://i.sstatic.net/IRDGS.png
location, but are evaluating onST_GeomFromText(st_astext(location), 0). It's not entirely clear why you do this, so maybe add sample data and/or explain that conversion or just try to use "location" directly.