-
Notifications
You must be signed in to change notification settings - Fork 4
[_]: fix(migrations): add migration to set file_id to NULL for zero-size files #912
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
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.
Running migration
99d6a17 to
ed82765
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.
The current proposal is a bit better although the cost-per-chunk is still high:
Limit (cost=1000.00..17632.09 rows=1000 width=4) (actual time=1.081..22.435 rows=1000 loops=1)
-> Gather (cost=1000.00..50191485.23 rows=3017689 width=4) (actual time=1.080..22.346 rows=1000 loops=1)
Workers Planned: 2
Workers Launched: 0
-> Parallel Seq Scan on files (cost=0.00..49888716.33 rows=1257370 width=4) (actual time=0.749..21.785 rows=1000 loops=1)
Filter: ((file_id IS NOT NULL) AND (size = 0))
Rows Removed by Filter: 3155
Planning Time: 0.167 ms
Execution Time: 22.543 ms
Let's work with:
...
WHERE size = 0 AND file_id IS NOT null AND status != 'DELETED'
...
Which will make the things almost 10x faster in the worst case:
Limit (cost=0.43..794.94 rows=1000 width=4) (actual time=0.015..0.660 rows=1000 loops=1)
-> Index Scan using idx_zero_size_files_per_user on files (cost=0.43..1506699.21 rows=1896396 width=4) (actual time=0.015..0.602 rows=1000 loops=1)
Filter: (file_id IS NOT NULL)
Planning Time: 0.176 ms
Execution Time: 0.700 ms
ed82765 to
8a27120
Compare
|



Context
The constraint was added with NOT VALID, which skipped existing rows but still validates on any UPDATE. When trash deletion updates these files (setting status = DELETED), the constraint fires and fails.