nova/nova/db
melanie witt 68f80d2013 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.

Closes-Bug: #1799298

[1] https://docs.sqlalchemy.org/en/13/orm/loading_relationships.html#subquery-eager-loading

Change-Id: I5c071f70f669966e9807b38e99077c1cae5b4606
(cherry picked from commit e728fe668a)
(cherry picked from commit 63d2e62c3a)
(cherry picked from commit e7a45e0335)
(cherry picked from commit 4350074029)
(cherry picked from commit ad7e4fb8f4)
2021-03-29 15:07:52 +00:00
..
sqlalchemy Use subqueryload() instead of joinedload() for (system_)metadata 2021-03-29 15:07:52 +00:00
__init__.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
api.py Remove remaining legacy DB API instance_group* methods 2018-06-27 13:24:42 -04:00
base.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
constants.py Move db MAX constants to own file 2018-03-01 11:09:29 +00:00
migration.py Manage db sync command for cell0 2016-08-22 18:53:45 +03:00