MySQL slow query with two inner joins

The following query takes 4 seconds, and I don't know why, because the index results are low. It is not possible to change the way it works (since this is a compatibility request to get the application name from two different systems)

Do you have any ideas?

SELECT runList.appName
FROM projectList
INNER JOIN varMeta ON (projectList.id = varMeta.projectId)
INNER JOIN runList ON (projectList.projectName = runList.appName)
WHERE varMeta.htmlvar_content = "example-app-name"
ORDER BY runList.id DESC
LIMIT 1;
+----+-------------+-------------+-------+--------------------+-------------+---------+---------------------------+------+-------------+
| id | select_type | table       | type  | possible_keys      | key         | key_len | ref                       | rows | Extra       |
+----+-------------+-------------+-------+--------------------+-------------+---------+---------------------------+------+-------------+
|  1 | SIMPLE      | runList     | index | env,appName,all    | PRIMARY     | 8       | NULL                      |    3 | Using where |
|  1 | SIMPLE      | projectList | ref   | PRIMARY,appNameIDX | appNameIDX  | 138     | compat.runList.appName    |    1 | Using where |
|  1 | SIMPLE      | varMeta     | ref   | varMetaIDX         | varMetaIDX  | 5       | compat.projectList.id     |   63 | Using where |
+----+-------------+-------------+-------+--------------------+-------------+---------+---------------------------+------+-------------+

This is the profile for this request:

+--------------------+----------+
| Status             | Duration |
+--------------------+----------+
| starting           | 0.000215 |
| Opening tables     | 0.000043 |
| System lock        | 0.000034 |
| Table lock         | 0.000015 |
| init               | 0.000081 |
| optimizing         | 0.000029 |
| statistics         | 0.000345 |
| preparing          | 0.000033 |
| executing          | 0.000009 |
| Sorting result     | 0.000009 |
| Sending data       | 3.023702 |
| end                | 0.000018 |
| query end          | 0.000004 |
| freeing items      | 0.000223 |
| logging slow query | 0.000004 |
| cleaning up        | 0.000005 |
+--------------------+----------+
+4
source share
1 answer

I'm going to guess here because you did not tell us which fields or indexes you have, and you did not specify the number of rows in each table. (So ​​it could be trash).

varMeta.html_varcontent, varMeta.projectID. (html_varcontent, projectID) varMeta. ? , MySQL . MySQL , , . .

, ORDER BY id DESC LIMIT 1 runList. , (appName, id) runList. appName, id. .

, projectList : (id, appName) (appName, id). , MySQL , .

+1

Source: https://habr.com/ru/post/1547418/


All Articles