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

Updating hierarchy slow on mysql #343

Open
joevandyk opened this issue Feb 22, 2019 · 3 comments
Open

Updating hierarchy slow on mysql #343

joevandyk opened this issue Feb 22, 2019 · 3 comments

Comments

@joevandyk
Copy link
Contributor

joevandyk commented Feb 22, 2019

delete FROM `fc_location_hierarchies` WHERE descendant_id IN (SELECT DISTINCT descendant_id FROM (SELECT descendant_id FROM `fc_location_hierarchies` WHERE ancestor_id = 46179 OR descendant_id = 46179) AS x);
Query OK, 0 rows affected (0.16 sec)

this query runs when updating the closure tree hierarchy. It's taking a while on mysql (160ms), with no matching hierarchy rows to delete -- and less than 200k rows in the hierarchies table.

I made a mysql-specific query here: Crowd-Cow@712de3f#diff-693c6ab46fe400dd004a79a24ab8d56b
that speeds up the update of the hierarchy tree from 100ms to under 1ms.

Thoughts? Obviously, this would mean that we would have different SQL for different databases.. but the performance was bad enough on mysql that we had to fork.

We're using msyql 5.7.

@joevandyk joevandyk reopened this Feb 22, 2019
@shopshow
Copy link

facing the same issue, really slow when updating hierarchy on large table.

@kbrock
Copy link
Contributor

kbrock commented Jan 18, 2021

facing the same issue, really slow when updating hierarchy on large table.

this will be available at initialization time, so a database specific module could be included/extended as part of the has_closure_tree call

@timdown
Copy link

timdown commented Mar 14, 2021

I did start working on this a few months ago but I refactored a bunch of stuff and it got away from me. I might have another go. In the meantime, the application I use closure_tree in has a monkey-patched version of the gem with the faster MySQL hierarchy deletion, which has removed the urgency for me.

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

4 participants