-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slow MySQL Query when loading startpage #28155
Comments
In the first case it seems that mysql made a weird decision of using IDX_repository_is_fork when do joining between two tables. AFAIK, this index probably wouldn't make any work when producing cartesian product between EXPLAIN SELECT
`action`.*
FROM
`action`
INNER JOIN
`repository` USE INDEX FOR JOIN (`PRIMARY`)
ON `repository`.id = `action`.repo_id
WHERE
user_id = 7
AND is_deleted = 0
ORDER BY
`action`.`created_unix` DESC
LIMIT 20; |
Yes, by giving the index hint the explain shows the using of the PRIMARY index for the repository table:
But it doesn't help to optimize the query. It is as slow as before, due to the order in which the query is processed. You can see it by the count of the rows which will be processed. To change the order of the internal query process, you need to give an index hint (IDX_action_c_u_d) for the action table too. EXPLAIN SELECT `action`.* FROM `action` USE INDEX FOR JOIN (`IDX_action_c_u_d`) INNER JOIN `repository` USE INDEX FOR JOIN (`PRIMARY`) ON `repository`.id = `action`.repo_id WHERE user_id = 7 AND is_deleted = 0 ORDER BY `action`.`created_unix` DESC LIMIT 20; Output:
Here the table action is processed at first with the where and limit condition and after that it matches against the repository table. There are much less rows processed and so the query is significant faster. |
blocked by https://gitea.com/xorm/xorm/issues/1456 and #16665 also related |
I think I can take a look at that. |
https://gitea.com/xorm/xorm/pulls/2375 merged. I think we can upgrade xorm and use the new feature. |
Can you confirm #28546 fix the problem? |
Automatically locked because of our CONTRIBUTING guidelines |
Description
Every time the startpage of gitea is loading it took a very long time (>8s). We have activated the mysql-slow-query-log to inspect what is happening and there is a query which tooks a very long time:
After using mysql explain to analyze the query, it shows the query is not using the correct index:
For testing purpose we removed the index IDX_action_r_u_d and started the explain again:
Now the query is using the IDX_action_c_u_d and the primary index.
The query is now incredibly fast in comparison. It took
20 rows in set (0.00 sec)
Before removing the index it took
20 rows in set (8.18 sec)
.Can you check this behaviour of the index in mysql. Maybe the removed index is needed in other situations.
The workaround of removing the index is working fine for us, but every time restarting the gitea instance, the index will be created again.
Gitea Version
1.20.5
Can you reproduce the bug on the Gitea demo site?
No
Log Gist
No response
Screenshots
No response
Git Version
2.40.1
Operating System
Debian 11
How are you running Gitea?
It is running in the official docker container.
The following images are used:
image: gitea:1.20.5
image: mysql:5.7
image: gitea-runner
Database
MySQL/MariaDB
The text was updated successfully, but these errors were encountered: