From d5f3d59daf38035ced725be55931cb89ec1ccbcf Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Tue, 3 Nov 2015 22:54:07 +0100 Subject: [PATCH] Optimize delete_csnat_router_interface_ports db query 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index ba740a068..12df1e4a8 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -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, -- 2.45.2