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

Fix compound unique index for hierarchies_table #415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fkmy
Copy link

@fkmy fkmy commented Jan 29, 2023

related issue: #410

I feel that the unique compound index of ancestor_id and descendant_id, is needed and generations is redundant.
Because there should be only one kind of generations for a set of ancestor_id and descendant_id.

The current table definition allows for the creation of multiple depth parent-child relationships.

example

item_hierarchies

items

id content parent_id
1 "Parent" NULL
2 "First Child" 1
3 "Second Child" 1
4 "First Grandchild" 3

item_hierarchies

ancestor_id descendant_id generations
1 1 0
1 2 1
2 2 0
1 3 1
3 3 0
1 4 2
3 4 1
4 4 0

Before the refurbishment, this record could also be added to the above.

INSERT INTO `item_hierarchies` (`ancestor_id`, `descendant_id`, `generations`) VALUES (1, 4, 1);

However, If there is a search by ancestor_id, descendant_id and generations columns, considering performance point of view, the disappearance of the ancestor_id, descendant_id and generations composite indexes is not good.
Therefore, I think it needs to be redefined.

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

Successfully merging this pull request may close these issues.

1 participant