-
Notifications
You must be signed in to change notification settings - Fork 463
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
Adding a "/" at the end can reduce the amount of "OR" queries #563
Comments
Outstanding resourcesThe research materials/presentations for tree structures in a number of programming languages all had the same implementation. And that implementation without the trailing slash looks obviously wrong. ImplementationI have been pulling the materialized path implementation into a separate class so we could support multiple tree implementations: traditional materialized path, the trailing slash, postgres arrays, ltree, path with the id in it. Check out: https://github.com/kbrock/ancestry/tree/materialized_path2 ResultsWhen I ran the numbers for trailing slash it was not any faster. Issues I see:
Future stepsWhile I totally agree that the current implementation that everyone uses is probably wrong, I would like to actually know which actions/queries use indexes and which table scan. So I keep getting derailed by wanting a test suite to actually test this stuff out. |
@kbrock Were the results using the pg array approach better? In fact, I was looking into this not because of speed, but because having a trailing and maybe a leading slash would make implementing custom scopes a much cleaner and easier task. |
@dimvic Yes. I too want a way to determine the I want to use a serializer to parse/create the Very tempted to breaking this functionality in the next major version of ancestry. But I'm hesitant too |
Let me know if you end up trying out the strategy of materialized_path2 and if it works alright for you. |
It is pretty common in my experience to get all descendants of a record in the tree.
Currently, a descendant of a record can have "ancestry" column of the following forms:
Because of this behaviour, the query to get descendants of id 3 is
The "OR" in the query seems unnecessary and can be easily removed if we just add "/" at the end of ancestry always, effectively changing the forms to
This way, the query is just
Is there a specific reason ancestry doesn't do this and has decided to not have a "/" at the end of single ancestors?
The text was updated successfully, but these errors were encountered: