]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add index for port
authorshihanzhang <shihanzhang@huawei.com>
Tue, 31 Mar 2015 08:14:12 +0000 (16:14 +0800)
committershihanzhang <shihanzhang@huawei.com>
Fri, 3 Apr 2015 00:55:13 +0000 (08:55 +0800)
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

neutron/db/migration/alembic_migrations/versions/20c469a5f920_add_index_for_port.py [new file with mode: 0644]
neutron/db/migration/alembic_migrations/versions/HEAD
neutron/db/models_v2.py

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 (file)
index 0000000..0020462
--- /dev/null
@@ -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)
index 619b4734546fb08855949b72c117df731b049efc..d9e9459801fc193927ed42c79f1f45d323968fb4 100644 (file)
@@ -1 +1 @@
-28a09af858a8
+20c469a5f920
index eb77ede252385895237ffb928d50baadc6ca2c5f..5067f8ae3304199761c12a0eb5c8dccdb0a299a7 100644 (file)
@@ -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'),