InstanceGroup.get_hosts() uses inefficient DB queries
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Compute (nova) |
In Progress
|
Medium
|
Matt Riedemann | ||
Ocata |
New
|
Undecided
|
Unassigned | ||
Pike |
New
|
Undecided
|
Unassigned | ||
Queens |
New
|
Undecided
|
Unassigned | ||
Rocky |
New
|
Undecided
|
Unassigned | ||
Stein |
In Progress
|
Undecided
|
Matt Riedemann |
Bug Description
The InstanceGroup.
because that by default is going to join on the following tables:
if columns_to_join is None:
And then just turn around and only use the instance.host value:
return list(set(
if instance.host]))
We should be:
1. Avoiding those unnecessary joins by passing expected_attrs=[] which is a simple backportable fix.
2. Write a new DB API method which would get the set of distinct instances.host values for the list of instance uuids where the instances.host value is not None, so I think:
SELECT host FROM instances WHERE host IS NOT NULL AND deleted == 0 AND uuid IN ($instance_uuids) GROUP BY instances.host;
That way we let the DB query do the work and we don't have to load up all of the additional instances fields we don't care about.
The DB API optimization would likely need to be a remotable method because InstanceGroup.
The inefficient query goes back to Icehouse when the InstanceGroup. get_hosts( ) method was introduced:
https:/ /review. opendev. org/#/c/ 77786/
So we can at least backport the #1 fix above to stable/ocata.