Use subqueryload() instead of joinedload() for (system_)metadata
Currently, when we "get" a single instance from the database and we
load metadata and system_metadata, we do so using a joinedload() which
does JOINs with the respective tables. Because of the one-to-many
relationship between an instance and (system_)metadata records, doing
the database query this way can result in a large number of additional
rows being returned unnecessarily and cause a large data transfer.
This is similar to the problem addressed by change
I0610fb16ccce2ee95c318589c8abcc30613a3fe9 which added separate queries
for (system_)metadata when we "get" multiple instances. We don't,
however, reuse the same code for this change because
_instances_fill_metadata converts the instance database object to a
dict, and some callers of _instance_get_by_uuid need to be able to
access an instance database object attached to the session (example:
instance_update_and_get_original).
By using subqueryload() [1], we can perform the additional queries for
(system_)metadata to solve the problem with a similar approach.
Reviewed: https:/ /review. opendev. org/c/openstack /nova/+ /761814 /opendev. org/openstack/ nova/commit/ c1de4fb13e4c7d2 20ff2e42f24f06b 4bbe53521f
Committed: https:/
Submitter: "Zuul (22348)"
Branch: stable/queens
commit c1de4fb13e4c7d2 20ff2e42f24f06b 4bbe53521f
Author: melanie witt <email address hidden>
Date: Tue Oct 20 21:46:13 2020 +0000
Use subqueryload() instead of joinedload() for (system_)metadata
Currently, when we "get" a single instance from the database and we
load metadata and system_metadata, we do so using a joinedload() which
does JOINs with the respective tables. Because of the one-to-many
relationship between an instance and (system_)metadata records, doing
the database query this way can result in a large number of additional
rows being returned unnecessarily and cause a large data transfer.
This is similar to the problem addressed by change ce2ee95c318589c 8abcc30613a3fe9 which added separate queries fill_metadata converts the instance database object to a get_by_ uuid need to be able to update_ and_get_ original) .
I0610fb16cc
for (system_)metadata when we "get" multiple instances. We don't,
however, reuse the same code for this change because
_instances_
dict, and some callers of _instance_
access an instance database object attached to the session (example:
instance_
By using subqueryload() [1], we can perform the additional queries for )metadata to solve the problem with a similar approach.
(system_
Closes-Bug: #1799298
[1] https:/ /docs.sqlalchem y.org/en/ 13/orm/ loading_ relationships. html#subquery- eager-loading
Change-Id: I5c071f70f66996 6e9807b38e99077 c1cae5b4606 6455f2dbaf655c8 a151462c8c) 83ca810f4c66a2a 236cf3d483) 4fec7f7b8d2505f 5b95445cf9) 3ab238c442ec86f ab6560e365) 58af00ec7aa0b32 1dc37c097c) f688d8437a46c8d 272ead317d)
(cherry picked from commit e728fe668a6de88
(cherry picked from commit 63d2e62c3a223f8
(cherry picked from commit e7a45e0335e4cf4
(cherry picked from commit 4350074029ffbc0
(cherry picked from commit ad7e4fb8f4ea6c4
(cherry picked from commit 68f80d201310dca