Add more zuul_ref indexes
This drops the (project, change) index in favor of several single-column indexes that the dbms can combine as needed to quickly seek zuul_refs in queries. Change-Id: I50ec1552e24c5aa634538ebb181da907898f1284
This commit is contained in:
@@ -114,7 +114,7 @@ class TestSQLConnectionMysql(ZuulTestCase):
|
||||
indexes_provides = insp.get_indexes(provides_table)
|
||||
indexes_build_event = insp.get_indexes(build_event_table)
|
||||
|
||||
self.assertEqual(3, len(indexes_ref))
|
||||
self.assertEqual(8, len(indexes_ref))
|
||||
self.assertEqual(1, len(indexes_buildset))
|
||||
self.assertEqual(2, len(indexes_buildset_ref))
|
||||
self.assertEqual(4, len(indexes_build))
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""zuul_ref_indexes
|
||||
|
||||
Revision ID: 3c1488fb137e
|
||||
Revises: d0a269345a22
|
||||
Create Date: 2023-11-27 17:15:00.812075
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3c1488fb137e'
|
||||
down_revision = 'd0a269345a22'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
|
||||
REF_TABLE = 'zuul_ref'
|
||||
|
||||
|
||||
def upgrade(table_prefix=''):
|
||||
prefixed_ref = table_prefix + REF_TABLE
|
||||
|
||||
op.create_index(f'{prefixed_ref}_project_idx',
|
||||
prefixed_ref,
|
||||
['project'])
|
||||
op.create_index(f'{prefixed_ref}_ref_idx',
|
||||
prefixed_ref,
|
||||
['ref'])
|
||||
op.create_index(f'{prefixed_ref}_branch_idx',
|
||||
prefixed_ref,
|
||||
['branch'])
|
||||
# Change is already indexed
|
||||
op.create_index(f'{prefixed_ref}_patchset_idx',
|
||||
prefixed_ref,
|
||||
['patchset'])
|
||||
op.create_index(f'{prefixed_ref}_oldrev_idx',
|
||||
prefixed_ref,
|
||||
['oldrev'])
|
||||
op.create_index(f'{prefixed_ref}_newrev_idx',
|
||||
prefixed_ref,
|
||||
['newrev'])
|
||||
|
||||
# Drop the project_change index and rely on separate indexes that
|
||||
# may be merged by the dbms.
|
||||
op.drop_index(f'{prefixed_ref}_project_change_idx', prefixed_ref)
|
||||
|
||||
|
||||
def downgrade():
|
||||
raise Exception("Downgrades not supported")
|
||||
@@ -505,9 +505,13 @@ class SQLConnection(BaseConnection):
|
||||
newrev = sa.Column(SHAType(40), nullable=False)
|
||||
branch = sa.Column(sa.String(255), nullable=False)
|
||||
|
||||
sa.Index(self.table_prefix + 'zuul_ref_project_change_idx',
|
||||
project, change)
|
||||
sa.Index(self.table_prefix + 'zuul_ref_project_idx', project)
|
||||
sa.Index(self.table_prefix + 'zuul_ref_ref_idx', ref)
|
||||
sa.Index(self.table_prefix + 'zuul_ref_change_idx', change)
|
||||
sa.Index(self.table_prefix + 'zuul_ref_patchset_idx', patchset)
|
||||
sa.Index(self.table_prefix + 'zuul_ref_oldrev_idx', oldrev)
|
||||
sa.Index(self.table_prefix + 'zuul_ref_newrev_idx', newrev)
|
||||
sa.Index(self.table_prefix + 'zuul_ref_branch_idx', branch)
|
||||
sa.UniqueConstraint(
|
||||
project, ref, change, patchset, oldrev, newrev,
|
||||
name=self.table_prefix + 'zuul_ref_unique')
|
||||
|
||||
Reference in New Issue
Block a user