[sqlalchemy-20] Remove redundant indexes from some tables

The following tables and columns were defined as primary key and key
(index). A column defined as primary key creates an index in the table.
The is no need to create a second one.

Tables and columns affected:
* portdataplanestatuses, port_id
* portdnses, port_id
* portuplinkstatuspropagation, port_id
* qos_policies_default, project_id
* quotausages, resource
* quotausages, project_id
* subnet_dns_publish_fixed_ips, subnet_id
* segmenthostmappings, segment_id
* segmenthostmappings, host
* networkdnsdomains, network_id
* floatingipdnses, floatingip_id

Closes-Bug: #2024044
Change-Id: I271c109a597eb0aa088a7a9c785e8631bfaa01d7
This commit is contained in:
Rodolfo Alonso Hernandez 2023-06-11 04:22:38 +00:00 committed by Rodolfo Alonso
parent cbb89fdb14
commit 08fe84f443
16 changed files with 88 additions and 35 deletions

View File

@ -0,0 +1,65 @@
# Copyright 2023 OpenStack Foundation
#
# 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 alembic import op
import sqlalchemy as sa
"""Remove dedundant indexes
Revision ID: 0aefee21cd87
Revises: 682c319773d7
Create Date: 2023-06-11 04:04:28.536800
"""
# revision identifiers, used by Alembic.
revision = '0aefee21cd87'
down_revision = '682c319773d7'
TABLES_AND_COLUMNS = (
('portdataplanestatuses', 'port_id'),
('portdnses', 'port_id'),
('portuplinkstatuspropagation', 'port_id'),
('qos_policies_default', 'project_id'),
('quotausages', 'resource'),
('quotausages', 'project_id'),
('subnet_dns_publish_fixed_ips', 'subnet_id'),
('segmenthostmappings', 'segment_id'),
('segmenthostmappings', 'host'),
('networkdnsdomains', 'network_id'),
('floatingipdnses', 'floatingip_id')
)
def upgrade():
inspector = sa.inspect(op.get_bind())
for table, column in TABLES_AND_COLUMNS:
for index in inspector.get_indexes(table):
if index['column_names'] == [column]:
op.drop_index(index_name=op.f(index['name']), table_name=table)
def expand_drop_exceptions():
"""Drop the redundant indexes
This migration will remove the indexes from those columns that are primary
keys. A primary key creates an index in the table; this second index is
redundant.
"""
return {
sa.Index: list({val[0] for val in TABLES_AND_COLUMNS}),
}

View File

@ -1 +1 @@
682c319773d7
0aefee21cd87

View File

@ -36,7 +36,7 @@ def upgrade():
sa.Column('tenant_id', sa.String(length=255),
nullable=False, primary_key=True, index=True),
sa.Column('resource', sa.String(length=255),
nullable=False, primary_key=True, index=True),
nullable=False, primary_key=True),
sa.Column('dirty', sa.Boolean(), nullable=False,
server_default=sql.false()),
sa.Column('in_use', sa.Integer(), nullable=False,

View File

@ -35,20 +35,19 @@ def upgrade():
sa.Column('network_id',
sa.String(length=36),
nullable=False,
index=True),
primary_key=True),
sa.Column('dns_domain', sa.String(
length=constants.FQDN_FIELD_SIZE),
nullable=False),
sa.ForeignKeyConstraint(['network_id'],
['networks.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('network_id'))
ondelete='CASCADE'))
op.create_table('floatingipdnses',
sa.Column('floatingip_id',
sa.String(length=36),
nullable=False,
index=True),
primary_key=True),
sa.Column('dns_name', sa.String(
length=constants.FQDN_FIELD_SIZE),
nullable=False),
@ -63,14 +62,13 @@ def upgrade():
nullable=False),
sa.ForeignKeyConstraint(['floatingip_id'],
['floatingips.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('floatingip_id'))
ondelete='CASCADE'))
op.create_table('portdnses',
sa.Column('port_id',
sa.String(length=36),
nullable=False,
index=True),
primary_key=True),
sa.Column('current_dns_name',
sa.String(length=constants.FQDN_FIELD_SIZE),
nullable=False),
@ -85,5 +83,4 @@ def upgrade():
nullable=False),
sa.ForeignKeyConstraint(['port_id'],
['ports.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('port_id'))
ondelete='CASCADE'))

View File

@ -33,13 +33,12 @@ def upgrade():
op.create_table('segmenthostmappings',
sa.Column('segment_id',
sa.String(length=36),
index=True,
primary_key=True,
nullable=False),
sa.Column('host',
sa.String(255),
index=True,
primary_key=True,
nullable=False),
sa.PrimaryKeyConstraint('segment_id', 'host'),
sa.ForeignKeyConstraint(['segment_id'],
['networksegments.id'],
ondelete='CASCADE'))

View File

@ -36,7 +36,7 @@ portdnses = sa.Table('portdnses', sa.MetaData(),
sa.Column('port_id', sa.String(36),
sa.ForeignKey('ports.id',
ondelete="CASCADE"),
primary_key=True, index=True),
primary_key=True),
sa.Column('dns_name', sa.String(length=255),
nullable=False),

View File

@ -39,6 +39,5 @@ def upgrade():
sa.Column('project_id',
sa.String(length=255),
nullable=False,
index=True,
primary_key=True),
)

View File

@ -34,6 +34,6 @@ def upgrade():
sa.Column('port_id', sa.String(36),
sa.ForeignKey('ports.id',
ondelete="CASCADE"),
primary_key=True, index=True),
primary_key=True),
sa.Column('data_plane_status', sa.String(length=16),
nullable=True))

View File

@ -35,7 +35,7 @@ def upgrade():
sa.Column('port_id', sa.String(36),
sa.ForeignKey('ports.id',
ondelete="CASCADE"),
primary_key=True, index=True),
primary_key=True),
sa.Column('propagate_uplink_status', sa.Boolean(),
nullable=False,
server_default=sa.sql.false()))

View File

@ -34,8 +34,7 @@ def upgrade():
op.create_table('subnet_dns_publish_fixed_ips',
sa.Column('subnet_id',
sa.String(length=db_const.UUID_FIELD_SIZE),
nullable=False,
index=True),
nullable=False),
sa.Column('dns_publish_fixed_ip',
sa.Boolean(),
nullable=False,

View File

@ -24,7 +24,7 @@ class PortDataPlaneStatus(model_base.BASEV2):
port_id = sa.Column(sa.String(36),
sa.ForeignKey('ports.id', ondelete="CASCADE"),
primary_key=True, index=True)
primary_key=True)
data_plane_status = sa.Column(sa.String(16), nullable=True)
port = orm.relationship(
models_v2.Port, load_on_pending=True,

View File

@ -24,8 +24,7 @@ from neutron.db import models_v2
class NetworkDNSDomain(model_base.BASEV2):
network_id = sa.Column(sa.String(36),
sa.ForeignKey('networks.id', ondelete="CASCADE"),
primary_key=True,
index=True)
primary_key=True)
dns_domain = sa.Column(sa.String(255),
nullable=False)
@ -47,8 +46,7 @@ class FloatingIPDNS(model_base.BASEV2):
floatingip_id = sa.Column(sa.String(36),
sa.ForeignKey('floatingips.id',
ondelete="CASCADE"),
primary_key=True,
index=True)
primary_key=True)
dns_name = sa.Column(sa.String(255),
nullable=False)
dns_domain = sa.Column(sa.String(255),
@ -76,8 +74,7 @@ class PortDNS(model_base.BASEV2):
port_id = sa.Column(sa.String(36),
sa.ForeignKey('ports.id',
ondelete="CASCADE"),
primary_key=True,
index=True)
primary_key=True)
current_dns_name = sa.Column(sa.String(255),
nullable=False)
current_dns_domain = sa.Column(sa.String(255),
@ -106,8 +103,7 @@ class SubnetDNSPublishFixedIP(model_base.BASEV2):
subnet_id = sa.Column(sa.String(constants.UUID_FIELD_SIZE),
sa.ForeignKey('subnets.id', ondelete="CASCADE"),
primary_key=True,
index=True)
primary_key=True)
dns_publish_fixed_ip = sa.Column(sa.Boolean(),
nullable=False,
server_default=sql.false())

View File

@ -71,11 +71,9 @@ class SegmentHostMapping(model_base.BASEV2):
sa.ForeignKey('networksegments.id',
ondelete="CASCADE"),
primary_key=True,
index=True,
nullable=False)
host = sa.Column(sa.String(255),
primary_key=True,
index=True,
nullable=False)
# Add a relationship to the NetworkSegment model in order to instruct

View File

@ -22,7 +22,7 @@ class PortUplinkStatusPropagation(model_base.BASEV2):
port_id = sa.Column(sa.String(36),
sa.ForeignKey('ports.id', ondelete="CASCADE"),
primary_key=True, index=True)
primary_key=True)
propagate_uplink_status = sa.Column(sa.Boolean(), nullable=False,
server_default=sa.sql.true())
port = orm.relationship(

View File

@ -132,7 +132,7 @@ class QosPortPolicyBinding(model_base.BASEV2):
class QosPolicyDefault(model_base.BASEV2,
model_base.HasProjectPrimaryKeyIndex):
model_base.HasProjectPrimaryKey):
__tablename__ = 'qos_policies_default'
qos_policy_id = sa.Column(sa.String(36),
sa.ForeignKey('qos_policies.id',

View File

@ -54,11 +54,11 @@ class Quota(model_base.BASEV2, model_base.HasId, model_base.HasProject):
model_base.BASEV2.__table_args__)
class QuotaUsage(model_base.BASEV2, model_base.HasProjectPrimaryKeyIndex):
class QuotaUsage(model_base.BASEV2, model_base.HasProjectPrimaryKey):
"""Represents the current usage for a given resource."""
resource = sa.Column(sa.String(255), nullable=False,
primary_key=True, index=True)
primary_key=True)
dirty = sa.Column(sa.Boolean, nullable=False, server_default=sql.false())
in_use = sa.Column(sa.Integer, nullable=False,