Improve the sql query performance of tag querying

Bug #1212082 reported by Feilong Wang
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Invalid
Undecided
Feilong Wang

Bug Description

After review the method "image_tag_get_all" of <sqlalchemy>/api.py, we're trying to order the list by created_at. However, it's meaningless from the end-user perspective. Since there is no priority for tags and we can't say one tag is more useful/important than another one. And even worse, it may introduce some performance issue.

=============================================================
mysql> explain SELECT image_tags.created_at AS image_tags_created_at, image_tags.updated_at AS image_tags_updated_at, image_tags.deleted_at AS image_tags_deleted_at, image_tags.deleted AS image_tags_deleted, image_tags.id AS image_tags_id, image_tags.image_id AS image_tags_image_id, image_tags.value AS image_tags_value FROM image_tags WHERE image_tags.image_id = 'c67d1ff2-c5c7-411b-9bf0-2c723e746434' AND image_tags.deleted = 0 ORDER BY image_tags.created_at ASC;
+----+-------------+------------+------+---------------------------------------------------------+------------------------+---------+-------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+------+---------------------------------------------------------+------------------------+---------+-------+------+-----------------------------+
| 1 | SIMPLE | image_tags | ref | ix_image_tags_image_id,ix_image_tags_image_id_tag_value | ix_image_tags_image_id | 110 | const | 2 | Using where; Using filesort |
+----+-------------+------------+------+---------------------------------------------------------+------------------------+---------+-------+------+-----------------------------+
1 row in set (0.01 sec)

Feilong Wang (flwang)
Changed in glance:
assignee: nobody → Fei Long Wang (flwang)
Revision history for this message
Mark Washenberger (markwash) wrote :

I think we might have created_at ordering in order to ensure tags show up in the same order each time. How would this behavior cause a performance problem?

Revision history for this message
Feilong Wang (flwang) wrote :

I would like to argue :)
1. I don't think the order of tags is meaningful for end user. Since it's "tag", the attributes of an object.
2. The clause "order by" will causing "file sort". It would be nice if we can avoid that.
Anyway, I will make some tests to check how to balance the performance and serviceability.

Thanks for your attention, markwash.

Feilong Wang (flwang)
Changed in glance:
status: New → Invalid
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.