diff options
author | Zuul <zuul@review.opendev.org> | 2021-05-21 14:19:59 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2021-05-21 14:19:59 +0000 |
commit | 97ceb7bd157538bdaddc6fc6f564b8f0b980cf98 (patch) | |
tree | 39ac71c94ce136cd326fb3a32ae3d6e299f6d016 /ironic/db | |
parent | 80b477683216bd39e77c30111e5b7fd495705b18 (diff) | |
parent | 205a8b3037b62cbae7f5385f4d9b9404a702414e (diff) | |
download | ironic-97ceb7bd157538bdaddc6fc6f564b8f0b980cf98.tar.gz |
Merge "Add additional node indexes"
Diffstat (limited to 'ironic/db')
-rw-r--r-- | ironic/db/sqlalchemy/alembic/versions/ac00b586ab95_node_indexes.py | 48 | ||||
-rw-r--r-- | ironic/db/sqlalchemy/models.py | 7 |
2 files changed, 55 insertions, 0 deletions
diff --git a/ironic/db/sqlalchemy/alembic/versions/ac00b586ab95_node_indexes.py b/ironic/db/sqlalchemy/alembic/versions/ac00b586ab95_node_indexes.py new file mode 100644 index 000000000..a3e75169a --- /dev/null +++ b/ironic/db/sqlalchemy/alembic/versions/ac00b586ab95_node_indexes.py @@ -0,0 +1,48 @@ +# 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. + +"""Adds indexes to important and commonly matched columns. + +Revision ID: ac00b586ab95 +Revises: c0455649680c +Create Date: 2021-04-27 20:27:31.469188 + +""" + +from alembic import op +from oslo_db.sqlalchemy import enginefacade +from oslo_db.sqlalchemy import utils + +# revision identifiers, used by Alembic. +revision = 'ac00b586ab95' +down_revision = 'c0455649680c' + + +def upgrade(): + engine = enginefacade.reader.get_engine() + tbl_name = 'nodes' + + indexes = [(['reservation'], 'reservation_idx'), + (['driver'], 'driver_idx'), + (['owner'], 'owner_idx'), + (['lessee'], 'lessee_idx'), + (['provision_state'], 'provision_state_idx'), + (['conductor_group'], 'conductor_group_idx'), + (['resource_class'], 'resource_class_idx')] + + if engine.dialect.name == 'mysql': + for fields, idx_name in indexes: + if not utils.index_exists(engine, tbl_name, idx_name): + op.create_index(idx_name, tbl_name, fields, unique=False) + else: + for fields, idx_name in indexes: + op.create_index(idx_name, tbl_name, fields, unique=False) diff --git a/ironic/db/sqlalchemy/models.py b/ironic/db/sqlalchemy/models.py index 2072153e2..ef85b5d6d 100644 --- a/ironic/db/sqlalchemy/models.py +++ b/ironic/db/sqlalchemy/models.py @@ -125,6 +125,13 @@ class Node(Base): schema.UniqueConstraint('instance_uuid', name='uniq_nodes0instance_uuid'), schema.UniqueConstraint('name', name='uniq_nodes0name'), + Index('owner_idx', 'owner'), + Index('lessee_idx', 'lessee'), + Index('driver_idx', 'driver'), + Index('provision_state_idx', 'provision_state'), + Index('reservation_idx', 'reservation'), + Index('conductor_group_idx', 'conductor_group'), + Index('resource_class_idx', 'resource_class'), table_args()) id = Column(Integer, primary_key=True) uuid = Column(String(36)) |