From: shihanzhang Date: Tue, 31 Mar 2015 08:14:12 +0000 (+0800) Subject: Add index for port X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f93007952e40a7ae7cb2d4f3588059acf42ea209;p=openstack-build%2Fneutron-build.git Add index for port This patch will speed up SELECTs Port with filters by 'network_id + device_owner' and 'network_id + mac_address'. Closes-bug: #1421089 Change-Id: Ied90b6304df971a6049871f65df3e1aaee624647 --- diff --git a/neutron/db/migration/alembic_migrations/versions/20c469a5f920_add_index_for_port.py b/neutron/db/migration/alembic_migrations/versions/20c469a5f920_add_index_for_port.py new file mode 100644 index 000000000..00204624a --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/20c469a5f920_add_index_for_port.py @@ -0,0 +1,35 @@ +# Copyright 2015 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. +# + +"""add index for port + +Revision ID: 20c469a5f920 +Revises: 28a09af858a8 +Create Date: 2015-04-01 04:12:49.898443 + +""" + +# revision identifiers, used by Alembic. +revision = '20c469a5f920' +down_revision = '28a09af858a8' + +from alembic import op + + +def upgrade(): + op.create_index(op.f('ix_ports_network_id_device_owner'), + 'ports', ['network_id', 'device_owner'], unique=False) + op.create_index(op.f('ix_ports_network_id_mac_address'), + 'ports', ['network_id', 'mac_address'], unique=False) diff --git a/neutron/db/migration/alembic_migrations/versions/HEAD b/neutron/db/migration/alembic_migrations/versions/HEAD index 619b47345..d9e945980 100644 --- a/neutron/db/migration/alembic_migrations/versions/HEAD +++ b/neutron/db/migration/alembic_migrations/versions/HEAD @@ -1 +1 @@ -28a09af858a8 +20c469a5f920 diff --git a/neutron/db/models_v2.py b/neutron/db/models_v2.py index eb77ede25..5067f8ae3 100644 --- a/neutron/db/models_v2.py +++ b/neutron/db/models_v2.py @@ -140,6 +140,10 @@ class Port(model_base.BASEV2, HasId, HasTenant): device_owner = sa.Column(sa.String(attr.DEVICE_OWNER_MAX_LEN), nullable=False) __table_args__ = ( + sa.Index( + 'ix_ports_network_id_mac_address', 'network_id', 'mac_address'), + sa.Index( + 'ix_ports_network_id_device_owner', 'network_id', 'device_owner'), sa.UniqueConstraint( network_id, mac_address, name='uniq_ports0network_id0mac_address'),