diff options
author | Julia Kreger <juliaashleykreger@gmail.com> | 2021-04-28 17:23:56 -0700 |
---|---|---|
committer | Julia Kreger <juliaashleykreger@gmail.com> | 2021-05-18 06:55:31 -0700 |
commit | 205a8b3037b62cbae7f5385f4d9b9404a702414e (patch) | |
tree | aca17c5669ae4855e6b472bdf5f18f1bae7a4a6d /ironic/db | |
parent | 888279c80245d42b06cffab91f51ec26f404da33 (diff) | |
download | ironic-205a8b3037b62cbae7f5385f4d9b9404a702414e.tar.gz |
Add additional node indexes
Secure RBAC, along with numerous periodics, and even some common API
access patterns heavily access the ironic database and sometimes cause
queries across multiple columns to match nodes to return.
None of this is bad, but what is bad is we didn't have indexes on these
columns.
This change adds docs, and the schema upgrade to create the column
indexes, and a release note to provide more visible documentation
for operators.
It must be stressed that this does *not* improve query times
when all records are asked for on a database connection.
Also adds an upgrade check in to raise a warning for operator
visibility.
Story: 2008863
Task: 42392
Change-Id: I76821c032180a58d0f99d31110fbe0f844c0cb3f
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)) |