-
Notifications
You must be signed in to change notification settings - Fork 4
[_]: feat/add migration to clean up duplicate folders #916
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
base: master
Are you sure you want to change the base?
Conversation
| WITH duplicate_groups AS ( | ||
| SELECT parent_uuid, plain_name, MIN(id) as id_to_keep | ||
| FROM folders | ||
| WHERE deleted = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add removed = false from here also, as the indexes we should add and the issue we have, is with the existing folders in the same folder with the same name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| WHERE f.parent_uuid = dg.parent_uuid | ||
| AND f.plain_name = dg.plain_name | ||
| AND f.id != dg.id_to_keep | ||
| AND f.deleted = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
adcaf58 to
0d26e88
Compare
sg-gs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: Analysed the count and there are 185 cases where this is happening. Running migration @jzunigax2
…reation and removal
|
@sg-gs added a temporary support index which resulted on the following explain result locally it gets rid of the sequential scan and instead leverages the supporting index |
sg-gs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, let's see how it performs. Executing migration @jzunigax2
…proved performance
|



What
Adds a batched migration to rename duplicate folders that share the same
(parent_uuid, plain_name)pair wheredeleted = falseWhy
The unique index on
folders(parent_uuid, plain_name) WHERE deleted = false(blocked PR: #882) cannot be applied because existing duplicate entries violate the constraint:This migration resolves those conflicts by renaming duplicates, making the data safe for the unique index.
How
GROUP BY parent_uuid, plain_name HAVING COUNT(*) > 1to find only duplicate groupsMIN(id)(oldest) unchangedplain_name || '_' || id::textEXPLAIN ANALYZE