Use SQL IN clause instead of OR with exact match comparisons

SQL IN clause is faster than several exact match comparisons
in an OR clause.

Trivial-Fix

Change-Id: I0d1bc49927b061a91ff6d4ca3f5b826d529d0770
This commit is contained in:
Rodolfo Alonso Hernandez 2022-05-19 20:57:11 +00:00 committed by Rodolfo Alonso
parent 38cdfb8855
commit a1d135e3c0

View File

@ -13,7 +13,6 @@
from neutron_lib.db import api as db_api
from neutron_lib.objects import common_types
from oslo_versionedobjects import fields as obj_fields
import sqlalchemy as sa
from sqlalchemy.orm import joinedload
from sqlalchemy import sql
@ -61,9 +60,8 @@ class RouterL3AgentBinding(base.NeutronDbObject):
l3_attrs.RouterExtraAttributes,
l3_attrs.RouterExtraAttributes.router_id ==
l3agent.RouterL3AgentBinding.router_id).filter(
sa.or_(
l3_attrs.RouterExtraAttributes.ha == sql.false(),
l3_attrs.RouterExtraAttributes.ha == sql.null())))
l3_attrs.RouterExtraAttributes.ha.in_([sql.false(),
sql.null()])))
bindings = [cls._load_object(context, db_obj) for db_obj in
query.all()]
return bindings