From: Mathieu Gagné Date: Tue, 29 Jul 2014 15:57:15 +0000 (-0400) Subject: Fix glance metadata SQL query performance X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8f8a8a6ffe14cf7bb461dc26d178bf8acc8ddf12;p=openstack-build%2Fcinder-build.git Fix glance metadata SQL query performance The query built to retrieve glance metadata associated to a volume was sub-optimal: all rows of volume_glance_metadata were returned. Fix it by properly joining the 2 tables with volume_id field. Closes-bug: #1349936 Change-Id: Ic09414de769e71f8b8f99113838af48d8520e187 --- diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 67eafbac5..4f3568ffe 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -2401,7 +2401,9 @@ def _volume_glance_metadata_get_all(context, session=None): models.VolumeGlanceMetadata, session=session) if is_user_context(context): - query = query.filter(models.Volume.project_id == context.project_id) + query = query.filter( + models.Volume.id == models.VolumeGlanceMetadata.volume_id, + models.Volume.project_id == context.project_id) return query.all()