On a site having about 200K entries in the term_data table, queries generated from views_plugin_argument_validate_taxonomy_term.inc take about a second to complete. These queries account for about 40% of the slow query logs on this site.
SELECT td.* FROM term_data td LEFT JOIN term_synonym ts ON ts.tid = td.tid WHERE (replace(td.name, ' ', '-') = 'direct-action-network' OR replace(ts.name, ' ', '-') = 'direct-action-network') AND td.vid IN(1, 6, 4, 13);
+--------+-----+-----------------------+-------------+--------+
| tid | vid | name | description | weight |
+--------+-----+-----------------------+-------------+--------+
| 235703 | 6 | direct action network | | 0 |
+--------+-----+-----------------------+-------------+--------+
1 row in set (0.81 sec)
Consider adjusting the query in a couple ways:
- Move the string replacement out into PHP and apply it to the argument instead of the database field.
- Look at the union of two queries so we can take advantage of indexes.
The attached patch makes these changes. Running a query with this structure:
SELECT td.* FROM term_data td WHERE td.name = 'direct action network' AND td.vid IN(1, 6, 4, 13) UNION SELECT td.* FROM term_data td INNER JOIN term_synonym ts ON ts.tid = td.tid WHERE ts.name = 'direct action network' AND td.vid IN(1, 6, 4, 13);
+--------+-----+-----------------------+-------------+--------+
| tid | vid | name | description | weight |
+--------+-----+-----------------------+-------------+--------+
| 235703 | 6 | direct action network | | 0 |
+--------+-----+-----------------------+-------------+--------+
1 row in set (0.00 sec)
Comments
Comment #1
gcassie commentedPatch attached.
Comment #2
mustanggb commented