From 8f8a8a6ffe14cf7bb461dc26d178bf8acc8ddf12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mathieu=20Gagne=CC=81?= Date: Tue, 29 Jul 2014 11:57:15 -0400 Subject: [PATCH] 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 --- cinder/db/sqlalchemy/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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() -- 2.45.2