list method query all image-related tags that were already deleted

Bug #1994012 reported by zhen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
In Progress
Undecided
Unassigned

Bug Description

Image_get_all () uses the left outer join method to query the image_tags table, and the conversion to the sql statement is as follows:

```
...
AS anon_1 LEFT OUTER JOIN image_properties AS image_properties_1 ON anon_1.id = image_properties_1.image_id LEFT OUTER JOIN image_tags AS image_tags_1 ON anon_1.id = image_tags_1.image_id LEFT OUTER JOIN image_locations AS image_locations_1 ON anon_1.id = image_locations_1.image_id ORDER BY anon_1.created_at DESC, anon_1.id DESC
...
```

Since there is no subquery on image_tags in advance to remove logically deleted entries, when there are a large number of logically deleted entries in image_tags (such as frequent update image tag), the query will be very slow.

Can we first make a query on the image_tags table when joining the left outer join? For example:

```
...
AS anon_1 LEFT OUTER JOIN image_properties AS image_properties_1 ON anon_1.id = image_properties_1.image_id LEFT OUTER JOIN (SELECT * FROM image_tags where image_tags.deleted = 0) AS image_tags_1 ON anon_1.id = image_tags_1.image_id LEFT OUTER JOIN image_locations AS image_locations_1 ON anon_1.id = image_locations_1.image_id ORDER BY anon_1.created_at DESC, anon_1.id DESC
...
```
How can i express such a sql statement in sqlalchemy?

zhen (zhen001)
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to glance (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/glance/+/862354

Changed in glance:
status: New → In Progress
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.