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

[Hotfix] Add BaseFileNode index for target/provider/type #8850

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

Conversation

mfraezz
Copy link
Member

@mfraezz mfraezz commented Dec 11, 2018

Purpose

Avoid costly BitmapHeap Scan when doing things like OsfStorageFolder.objects.filter(target=node), etc.

Changes

  • Alter index_together

QA Notes

See if files load any faster? No direct UI changes, may not affect the generic file page queries (especially not until the table is vacuumed, which happens automatically over long periods of time). Added specifically to further optimize #8849

Side Effects

None expected, other than what's listed below

Deployment Notes

Because this is decently-sized index on one of our largest tables, this MUST NOT be deployed without downtime. Indices require exclusive table locks while being created*, therefore this requires maintenance downtime.

* Except concurrently, which is technically possible but not supported by Django. Doing so would require the migration operation to be something like:

migrations.SeparateDatabaseAndState(
    state_operations=[
        migrations.AlterIndexTogether(
            model_name='basefilenode',
            index_together=set([('target_content_type', 'target_object_id'), ('target_content_type', 'target_object_id', 'provider', 'type')]),
        ),
    ],
    database_operations=[
        migrations.RunSQL([
            'CREATE INDEX CONCURRENTLY "osf_basefilenode_toid_tcid_prv_type_deadbeef_idx" ON "osf_basefilenode" ("target_object_id", "target_content_type_id", "provider", "type");',
        ], [
            'DROP INDEX IF EXISTS "osf_basefilenode_toid_tcid_prv_type_deadbeef_idx", RESTRICT;'
        ])
    ]
)

However, due to caveats, it's possible that index would not be successfully created, leading to increased overhead and none of the benefits, and possible deadlock during the failed creation process.

Ticket

None known

- Avoids costly BHS when doing things like
- OsfStorageFolder.objects.filter(target=node), etc.
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.

None yet

1 participant