From a5750a432244380699844ea5cb0ee853831a2f1a Mon Sep 17 00:00:00 2001 From: Afonne-CID Date: Tue, 29 Apr 2025 13:38:16 +0100 Subject: [PATCH] Add an index on ports.node_id This should improve JOIN operations when retrieving ports filtered by node conductor groups or other node attributes. Change-Id: Ie1d4ef243e33c1edaa36111cad3979e0fdcf2cfd --- .../4c8356c965f1_index_on_ports_node_id.py | 27 +++++++++++++++++++ ironic/db/sqlalchemy/models.py | 1 + 2 files changed, 28 insertions(+) create mode 100644 ironic/db/sqlalchemy/alembic/versions/4c8356c965f1_index_on_ports_node_id.py diff --git a/ironic/db/sqlalchemy/alembic/versions/4c8356c965f1_index_on_ports_node_id.py b/ironic/db/sqlalchemy/alembic/versions/4c8356c965f1_index_on_ports_node_id.py new file mode 100644 index 0000000000..adf8637253 --- /dev/null +++ b/ironic/db/sqlalchemy/alembic/versions/4c8356c965f1_index_on_ports_node_id.py @@ -0,0 +1,27 @@ +# 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. +"""Add index on ports.node_id + +Revision ID: 4c8356c965f1 +Revises: 1c14278d6e33 +Create Date: 2025-04-29 13:26:23.089464 + +""" +from alembic import op + +# revision identifiers, used by Alembic. +revision = '4c8356c965f1' +down_revision = '1c14278d6e33' + + +def upgrade(): + op.create_index('ports_node_id_idx', 'ports', ['node_id']) diff --git a/ironic/db/sqlalchemy/models.py b/ironic/db/sqlalchemy/models.py index e5ecc8fc58..49404e4a7b 100644 --- a/ironic/db/sqlalchemy/models.py +++ b/ironic/db/sqlalchemy/models.py @@ -256,6 +256,7 @@ class Port(Base): schema.UniqueConstraint('address', name='uniq_ports0address'), schema.UniqueConstraint('uuid', name='uniq_ports0uuid'), schema.UniqueConstraint('name', name='uniq_ports0name'), + Index('ports_node_id_idx', 'node_id'), table_args()) id = Column(Integer, primary_key=True) uuid = Column(String(36))