Merge pull request #3363 from quay/add-missing-indexes

Add some missing indexes that should make queries significantly faster
This commit is contained in:
Joseph Schorr 2019-02-14 17:27:24 -05:00 committed by GitHub
commit cb677c5711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 3 deletions

View file

@ -464,7 +464,7 @@ class BaseModel(ReadSlaveModel):
class User(BaseModel):
uuid = CharField(default=uuid_generator, max_length=36, null=True)
uuid = CharField(default=uuid_generator, max_length=36, null=True, index=True)
username = CharField(unique=True, index=True)
password_hash = CharField(null=True)
email = CharField(unique=True, index=True,
@ -728,7 +728,7 @@ class RepositoryPermission(BaseModel):
class PermissionPrototype(BaseModel):
org = QuayUserField(index=True, backref='orgpermissionproto')
uuid = CharField(default=uuid_generator)
uuid = CharField(default=uuid_generator, index=True)
activating_user = QuayUserField(allows_robots=True, index=True, null=True,
backref='userpermissionproto')
delegate_user = QuayUserField(allows_robots=True, backref='receivingpermission',
@ -769,7 +769,7 @@ class DisableReason(BaseModel):
class RepositoryBuildTrigger(BaseModel):
uuid = CharField(default=uuid_generator)
uuid = CharField(default=uuid_generator, index=True)
service = ForeignKeyField(BuildTriggerService)
repository = ForeignKeyField(Repository)
connected_user = QuayUserField()
@ -923,6 +923,8 @@ class RepositoryTag(BaseModel):
read_slaves = (read_slave,)
indexes = (
(('repository', 'name'), False),
(('repository', 'lifetime_start_ts'), False),
(('repository', 'lifetime_end_ts'), False),
# This unique index prevents deadlocks when concurrently moving and deleting tags
(('repository', 'name', 'lifetime_end_ts'), True),
@ -1462,6 +1464,9 @@ class Tag(BaseModel):
(('repository', 'name', 'hidden'), False),
(('repository', 'name', 'tag_kind'), False),
(('repository', 'lifetime_start_ms'), False),
(('repository', 'lifetime_end_ms'), False),
# This unique index prevents deadlocks when concurrently moving and deleting tags
(('repository', 'name', 'lifetime_end_ms'), True),
)

View file

@ -0,0 +1,32 @@
"""Add lifetime end indexes to tag tables
Revision ID: b9045731c4de
Revises: e184af42242d
Create Date: 2019-02-14 17:18:40.474310
"""
# revision identifiers, used by Alembic.
revision = 'b9045731c4de'
down_revision = 'e184af42242d'
from alembic import op
def upgrade(tables, tester):
# ### commands auto generated by Alembic - please adjust! ###
op.create_index('repositorytag_repository_id_lifetime_end_ts', 'repositorytag', ['repository_id', 'lifetime_end_ts'], unique=False)
op.create_index('tag_repository_id_lifetime_end_ms', 'tag', ['repository_id', 'lifetime_end_ms'], unique=False)
op.create_index('repositorytag_repository_id_lifetime_start_ts', 'repositorytag', ['repository_id', 'lifetime_start_ts'], unique=False)
op.create_index('tag_repository_id_lifetime_start_ms', 'tag', ['repository_id', 'lifetime_start_ms'], unique=False)
# ### end Alembic commands ###
def downgrade(tables, tester):
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('tag_repository_id_lifetime_end_ms', table_name='tag')
op.drop_index('repositorytag_repository_id_lifetime_end_ts', table_name='repositorytag')
op.drop_index('tag_repository_id_lifetime_start_ms', table_name='tag')
op.drop_index('repositorytag_repository_id_lifetime_start_ts', table_name='repositorytag')
# ### end Alembic commands ###

View file

@ -0,0 +1,28 @@
"""Add missing index on UUID fields
Revision ID: e184af42242d
Revises: 6ec8726c0ace
Create Date: 2019-02-14 16:35:47.768086
"""
# revision identifiers, used by Alembic.
revision = 'e184af42242d'
down_revision = '6ec8726c0ace'
from alembic import op
def upgrade(tables, tester):
# ### commands auto generated by Alembic - please adjust! ###
op.create_index('permissionprototype_uuid', 'permissionprototype', ['uuid'], unique=False)
op.create_index('repositorybuildtrigger_uuid', 'repositorybuildtrigger', ['uuid'], unique=False)
op.create_index('user_uuid', 'user', ['uuid'], unique=False)
# ### end Alembic commands ###
def downgrade(tables, tester):
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('user_uuid', table_name='user')
op.drop_index('repositorybuildtrigger_uuid', table_name='repositorybuildtrigger')
op.drop_index('permissionprototype_uuid', table_name='permissionprototype')
# ### end Alembic commands ###