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

Question about efficiency #60

Closed
maknz opened this issue Apr 9, 2014 · 3 comments
Closed

Question about efficiency #60

maknz opened this issue Apr 9, 2014 · 3 comments

Comments

@maknz
Copy link

maknz commented Apr 9, 2014

Hey,

First of all, great project, thanks for building it.

I was reading the theory behind nested sets which states

Nested sets are very slow for inserts because it requires updating left and right domain values for all records in the table after the insert. This can cause a lot of database thrash[citation needed] as many rows are rewritten and indexes rebuilt.

My use case is tags. Organisations have many tags, which they can use to tag other models that they own (e.g. assets). This seems similar to your categories example. However, unlike categories of which there may only be a small amount (say for a shop), there could be a lot of tags in that table. Everyone's tags from across the whole product, but they would only own / be able to access a subset of those. It would be possible that this table could get big, and I'm worried about the intensity of those rewrites that have to occur.

Any thoughts?

@SiCoUK
Copy link

SiCoUK commented Apr 11, 2014

Nested Sets are generally for hierarchical data like categories. If you don't need your tags to be hierarchical, then Nested Sets are probably over kill.

If you do need to get the data in it's hierarchical fashion (as a tree for categories for example) then nested sets (in my opinion) are the best way to go. Especially if the hard work is done as it is with this project.

There are easier ways to manage tags owned by different organisations as long as you don't need them to have parents or children. Look up Many to Many relationships (http://laravel.com/docs/eloquent#many-to-many) using a pivot table.

@etrepat
Copy link
Owner

etrepat commented May 2, 2014

@SiCoUK answered your question pretty well here.

A nested set implementation is usually pretty fast when querying hierarchy chains (ascendants, descendants), and slow when performing inserts/updates because of the index bounds re-computation. So, NestedSet structures are good when your use-case requires hierarchical structures which are queried far more often than modified (inserted/updated).

Also as @SiCoUK said, if your tag data implementation does not need to be hierarchical there's no need to use a nested set structure for that.

@etrepat
Copy link
Owner

etrepat commented May 13, 2014

I think your question has been answered so I'm closing this issue for now. Please, feel free to reopen or open a new issue if you've got more questions.

@etrepat etrepat closed this as completed May 13, 2014
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

3 participants