-
Notifications
You must be signed in to change notification settings - Fork 239
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
Fix compound unique index for template in hierarchies_table #410
Comments
For example, suppose we have a closure hierarchy table with the following rows:
In this case, the (ancestor_id, descendant_id) combination of (1, 3) appears twice, but the rows can be distinguished by the generations column - one row represents a direct ancestor-descendant relationship (with generations equal to 1), while the other represents an indirect ancestor-descendant relationship (with generations equal to 2). By including generations in the index, the database can more quickly retrieve rows with a specific ancestor_id and descendant_id combination, as it narrows down the search by also considering the generations value. This can be especially useful when querying the table for ancestry relationships at a specific generation depth. |
The example table provided appears to show the (ancestor_id, descendant_id) combination of (1, 3) only once. I understand an index for the (ancestor_id, descendant_id, generations) combination is needed. |
Sure. You want to open a pr? |
I will try making a pr. Thank you. |
This is a proposal for the hierarchies_table template.
https://github.com/ClosureTree/closure_tree/blob/8550ddab5671a0d3b002e954796de44826585728/lib/generators/closure_tree/templates/create_hierarchies_table.rb.erb
I feel that the unique compound index of
ancestor_id
anddescendant_id
, is needed andgenerations
is redundant.However, considering performance, I think it's necessary to define a new compound index for
ancestor_id
,descendant_id
, andgenerations
.The text was updated successfully, but these errors were encountered: