Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST_* functions and indexing #175

Open
alechko opened this issue Jul 18, 2021 · 0 comments
Open

ST_* functions and indexing #175

alechko opened this issue Jul 18, 2021 · 0 comments

Comments

@alechko
Copy link

alechko commented Jul 18, 2021

Apologies in advance if that's not the place to ask, but I'm just trying to have a better understanding MySQL (8.0) spatial features, specifically indexing of POINT column types and using the provided eloquent scope methods to trigger the index.

In a test project that I've setup according to the README of this package, I've seeded ~200k records with an indexed point column and I'm trying to have an eloquent pagination on results served by Response::json:

The JSON response returns a total value, which is re-calculated with every request and is kinda slow.

The slow query is 500+ ms and looks like this:

select count(*) as aggregate from `table` where st_distance_sphere(`location`, ST_GeomFromText('POINT(-1 1)')) <= 100000

If I add an order to this query, the query time doubles.

After doing a bit of manual queries, I got to the point that I've noticed that many of the ST_* methods does not utilize the column index, I tried using st_distance, st_distance_sphere, st_within, etc., all give results around 500 ms - 1 sec, and it doubles with ordering.

Is there a way to optimize these queries to use the index? Is there a "best practices" guide or something I can take a look at?

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant