Stop accessing wcf1_tag_to_object.languageID in TagEngine::getObjectsTags()
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 27 Jan 2021 10:44:09 +0000 (11:44 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 29 Jan 2021 15:49:31 +0000 (16:49 +0100)
This stops accessing the redundant `languageID` column that is functionally
dependent on the tagID (see #3803).

This change will make the query a little bit slower, but this will be
remediated by adjusting the indices on the wcf1_tag_to_object table after which
the performance will be identical:

    MariaDB [*snip*]> EXPLAIN
        -> SELECT tag.*,
        ->        tag_to_object.objectid
        -> FROM   wcf1_tag_to_object tag_to_object
        ->        LEFT JOIN wcf1_tag tag
        ->               ON ( tag.tagid = tag_to_object.tagid )
        -> WHERE  tag_to_object.objecttypeid = 92
        ->        AND tag_to_object.objectid IN ( 3553, 7990 )
        ->        AND tag_to_object.languageid IN ( 1 );
    +------+-------------+---------------+--------+----------------------------------------------------------------------+-------------------------------------+---------+-------------------------------+------+--------------------------+
    | id   | select_type | table         | type   | possible_keys                                                        | key                                 | key_len | ref                           | rows | Extra                    |
    +------+-------------+---------------+--------+----------------------------------------------------------------------+-------------------------------------+---------+-------------------------------+------+--------------------------+
    |    1 | SIMPLE      | tag_to_object | range  | objectTypeID,objectTypeID_2,cbbba36334575d806c002a8756c8a107_fk,test | cbbba36334575d806c002a8756c8a107_fk | 12      | NULL                          |    8 | Using where; Using index |
    |    1 | SIMPLE      | tag           | eq_ref | PRIMARY                                                              | PRIMARY                             | 4       | *snip*.tag_to_object.tagID    |    1 |                          |
    +------+-------------+---------------+--------+----------------------------------------------------------------------+-------------------------------------+---------+-------------------------------+------+--------------------------+
    2 rows in set (0.00 sec)

    MariaDB [*snip*]>
    MariaDB [*snip*]> EXPLAIN
        -> SELECT tag.*,
        ->        tag_to_object.objectid
        -> FROM   wcf1_tag_to_object tag_to_object
        ->        LEFT JOIN wcf1_tag tag
        ->               ON ( tag.tagid = tag_to_object.tagid )
        -> WHERE  tag_to_object.objecttypeid = 92
        ->        AND tag_to_object.objectid IN ( 3553, 7990 )
        ->        AND tag.languageid IN ( 1 );
    +------+-------------+---------------+--------+----------------------------------------+---------+---------+-------------------------------+------+--------------------------+
    | id   | select_type | table         | type   | possible_keys                          | key     | key_len | ref                           | rows | Extra                    |
    +------+-------------+---------------+--------+----------------------------------------+---------+---------+-------------------------------+------+--------------------------+
    |    1 | SIMPLE      | tag_to_object | range  | objectTypeID,objectTypeID_2,tagID,test | test    | 8       | NULL                          |    8 | Using where; Using index |
    |    1 | SIMPLE      | tag           | eq_ref | PRIMARY,languageID                     | PRIMARY | 4       | *snip*.tag_to_object.tagID    |    1 | Using where              |
    +------+-------------+---------------+--------+----------------------------------------+---------+---------+-------------------------------+------+--------------------------+
    2 rows in set (0.00 sec)

wcfsetup/install/files/lib/system/tagging/TagEngine.class.php

index 1a9e9aa05c4f13151521fc0c3a8a9f45753df9a9..cbb233c3f80dff5554708d2cc41026ef6c489f69 100644 (file)
@@ -199,7 +199,7 @@ class TagEngine extends SingletonFactory
                 }
             }
 
-            $conditions->add("tag_to_object.languageID IN (?)", [$languageIDs]);
+            $conditions->add("tag.languageID IN (?)", [$languageIDs]);
         }
 
         $sql = "SELECT      tag.*, tag_to_object.objectID