Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add index to reservations.uuid column
Committing or rolling back reservations gets slow once a large number of reservations have built up in the db. Since they're being queried by uuid this adds an index to speed up that operation. Note that this can be slow with a large number of rows. bug 1203872 Change-Id: Ida503206194a567a5c6811a304154d067c5faa83
- Loading branch information
Andrew Laski
committed
Aug 1, 2013
1 parent
9ce78a9
commit 577d2ae
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
nova/db/sqlalchemy/migrate_repo/versions/204_add_indexes_to_reservations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# All Rights Reserved. | ||
# | ||
# 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. | ||
|
||
from sqlalchemy import Index, MetaData, Table | ||
from sqlalchemy.exc import IntegrityError | ||
|
||
|
||
def upgrade(migrate_engine): | ||
meta = MetaData() | ||
meta.bind = migrate_engine | ||
|
||
reservations = Table('reservations', meta, autoload=True) | ||
|
||
# Based on _quota_reservations_query | ||
# from: nova/db/sqlalchemy/api.py | ||
index = Index('reservations_uuid_idx', reservations.c.uuid) | ||
try: | ||
index.create(migrate_engine) | ||
except IntegrityError: | ||
pass | ||
|
||
|
||
def downgrade(migrate_engine): | ||
meta = MetaData() | ||
meta.bind = migrate_engine | ||
|
||
reservations = Table('reservations', meta, autoload=True) | ||
|
||
index = Index('reservations_uuid_idx', reservations.c.uuid) | ||
index.drop(migrate_engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters