Comment 8 for bug 1799298

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.opendev.org/758928
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=e728fe668a6de886455f2dbaf655c8a151462c8c
Submitter: Zuul
Branch: master

commit e728fe668a6de886455f2dbaf655c8a151462c8c
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
    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