]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Optimize delete_csnat_router_interface_ports db query
authorCedric Brandily <zzelle@gmail.com>
Tue, 3 Nov 2015 21:54:07 +0000 (22:54 +0100)
committerCedric Brandily <zzelle@gmail.com>
Tue, 3 Nov 2015 22:20:57 +0000 (23:20 +0100)
Currently delete_csnat_router_interface_ports provides an iterator as
filter to core_plugin.get_ports which is used in a SQL IN argument.
SQLAlchemy is able to avoid some db queries when the IN argument is
empty BUT not when the argument is an empty iterator and raises the
warning:

 SAWarning: The IN-predicate on "ports.id" was invoked with an empty
 sequence. This results in a contradiction, which nonetheless can be
 expensive to evaluate. Consider alternative strategies for improved
 performance.

This change replaces the iterator by a list in order to optimize db
queries when the filter is empty.

Closes-Bug: #1503852
Change-Id: I4f53433d688dfa020927118a18020b1a6aa55517

neutron/db/l3_dvr_db.py

index ba740a0682c3dd8b5a237e2f1a3a1451871221b5..12df1e4a85a672a3b15f7c290302a048e2f00050 100644 (file)
@@ -660,12 +660,12 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
 
         # TODO(markmcclain): This is suboptimal but was left to reduce
         # changeset size since it is late in cycle
-        ports = (
+        ports = [
             rp.port.id for rp in
             router.attached_ports.filter_by(
                     port_type=l3_const.DEVICE_OWNER_ROUTER_SNAT)
             if rp.port
-        )
+        ]
 
         c_snat_ports = self._core_plugin.get_ports(
             context,