Add index for actor_id in assignments table.
Searching the assignments table by actor_id is a common occurance and in a large OpenStack installation, this can be a significant performance degradation. This table is read much more often than it is written, so this should be a good trade off. Change-Id: Ia1a4392ca2118690a10130b10b2f69cd05672a12 Closes-bug: 1362557
This commit is contained in:
parent
8ea1b14e4d
commit
0cb9c042ac
|
@ -638,7 +638,7 @@ class RoleAssignment(sql.ModelBase, sql.DictBase):
|
|||
AssignmentType.USER_DOMAIN, AssignmentType.GROUP_DOMAIN,
|
||||
name='type'),
|
||||
nullable=False)
|
||||
actor_id = sql.Column(sql.String(64), nullable=False)
|
||||
actor_id = sql.Column(sql.String(64), nullable=False, index=True)
|
||||
target_id = sql.Column(sql.String(64), nullable=False)
|
||||
role_id = sql.Column(sql.String(64), sql.ForeignKey('role.id'),
|
||||
nullable=False)
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright 2014 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import sqlalchemy as sql
|
||||
|
||||
ASSIGNMENT_TABLE = 'assignment'
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
assignment = sql.Table(ASSIGNMENT_TABLE, meta, autoload=True)
|
||||
idx = sql.Index('ix_actor_id', assignment.c.actor_id)
|
||||
idx.create(migrate_engine)
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
assignment = sql.Table(ASSIGNMENT_TABLE, meta, autoload=True)
|
||||
idx = sql.Index('ix_actor_id', assignment.c.actor_id)
|
||||
idx.drop(migrate_engine)
|
|
@ -1386,6 +1386,20 @@ class SqlUpgradeTests(SqlMigrateBase):
|
|||
self.assertEqual(1, session.query(endpoint_table).
|
||||
filter_by(region=_small_region_name).count())
|
||||
|
||||
def test_add_actor_id_index(self):
|
||||
self.upgrade(53)
|
||||
self.upgrade(54)
|
||||
table = sqlalchemy.Table('assignment', self.metadata, autoload=True)
|
||||
index_data = [(idx.name, idx.columns.keys()) for idx in table.indexes]
|
||||
self.assertIn(('ix_actor_id', ['actor_id']), index_data)
|
||||
|
||||
def test_remove_actor_id_index(self):
|
||||
self.upgrade(54)
|
||||
self.downgrade(53)
|
||||
table = sqlalchemy.Table('assignment', self.metadata, autoload=True)
|
||||
index_data = [(idx.name, idx.columns.keys()) for idx in table.indexes]
|
||||
self.assertNotIn(('ix_actor_id', ['actor_id']), index_data)
|
||||
|
||||
def populate_user_table(self, with_pass_enab=False,
|
||||
with_pass_enab_domain=False):
|
||||
# Populate the appropriate fields in the user
|
||||
|
|
Loading…
Reference in New Issue