nova/nova/db/sqlalchemy
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
..
api_migrations Merge "Add queued for delete to instance_mappings table." 2018-07-11 21:32:30 +00:00
migrate_repo Add trusted_certs to instance_extra 2018-03-29 23:00:42 -04:00
__init__.py Remove SQLite BigInteger/Integer translation logic 2015-12-07 12:49:22 -05:00
api.py Use subqueryload() instead of joinedload() for (system_)metadata 2021-03-29 15:07:52 +00:00
api_models.py Online data migration for queued_for_delete flag 2018-07-23 14:48:18 -07:00
migration.py Isolate placement database config 2018-06-19 13:22:04 +01:00
models.py Add trusted_certs to instance_extra 2018-03-29 23:00:42 -04:00
types.py Use is_valid_cidr and is_valid_ipv6_cidr from oslo_utils 2017-01-31 11:45:00 +00:00
utils.py Remove translation of log messages 2017-07-18 09:03:39 +00:00