-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Wrongly used index slows down queries on action table (dashboard view) #16665
Comments
Yes it should be composite index (user_id, is_deleted) |
seems this gets even worse with 1.16.0 the workaround with dropping the deleted index does not really have an effect any longer (maybe there is another slow query) |
This comment was marked as outdated.
This comment was marked as outdated.
We're hitting the same issue, using
For those who build their own gitea and use mysql, you can find a quick hack/fix on 42wim@5854c79 |
There is an issue for that https://gitea.com/xorm/xorm/issues/1456 . Is that the index names or the columns names? |
it's an index name, more information about almost the same issue on https://www.percona.com/blog/2012/12/14/the-optimization-that-often-isnt-index-merge-intersection/ |
There are a lot of indices on the Action table and I think that most of them are likely to be useless, unhelpful and unused. So, I think we need to look again at these indexes in action (and across Gitea as whole) Current StatusTo this end let's start with the current status: type Action struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"INDEX"` // Receiver user id.
OpType ActionType
ActUserID int64 `xorm:"INDEX"` // Action user id.
ActUser *user_model.User `xorm:"-"`
RepoID int64 `xorm:"INDEX"`
Repo *repo_model.Repository `xorm:"-"`
CommentID int64 `xorm:"INDEX"`
Comment *Comment `xorm:"-"`
IsDeleted bool `xorm:"INDEX NOT NULL DEFAULT false"`
RefName string
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
Content string `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
} Now... we need to think about our common queries.
First thoughtsHowever, we can look at the code and reason a little about this:
Now we need to think about our common queries. Which are (likely to be):
User/Org/Team Dashboard/Feedgitea/routers/web/user/home.go Line 70 in 9550e5a
This first gets the heatmap data which we'll skip for now. gitea/routers/web/user/home.go Lines 135 to 143 in 9550e5a
* The options are passed in to:
Heatmapgitea/routers/web/user/home.go Line 93 in 9550e5a
Lines 49 to 59 in 9550e5a
RepoFeedgitea/routers/web/feed/repo.go Lines 18 to 28 in 9550e5a
The options are passed in to:
UserFeedgitea/routers/web/feed/profile.go Lines 28 to 36 in 9550e5a
The options are passed in to:
UserProfile Activitygitea/routers/web/user/profile.go Lines 183 to 192 in 9550e5a
SummaryOK what should we do:
I'll try to put up a PR for this. EDIT: I forgot we always sort by |
Proposed // Action represents user operation type and other information to
// repository. It implemented interface base.Actioner so that can be
// used in template render.
type Action struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"INDEX(u_ua_and_r)"` // Receiver user id.
OpType ActionType
ActUserID int64 `xorm:"INDEX(u_ua_and_r) INDEX(ua_and_r)"` // Action user id.
ActUser *user_model.User `xorm:"-"`
RepoID int64 `xorm:"INDEX(u_ua_and_r) INDEX(ua_and_r) INDEX(r)"`
Repo *repo_model.Repository `xorm:"-"`
CommentID int64 `xorm:"INDEX"`
Comment *Comment `xorm:"-"`
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
RefName string
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
Content string `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX(u_ua_and_r) INDEX(ua_and_r) INDEX(r) created"`
} EDIT: I've include created_unix in the User and ActUser and Repo individual indices. |
Improve the indices on the action table by creating a covering index that covers the common queries and removes unhelpful indices. Fix go-gitea#16665 Signed-off-by: Andrew Thornton <[email protected]>
We need to go through all of the indices on our tables and through the databases individually to see if we can improve things. Realistically this would require someone with a reasonably sized db to do this to get the best results but we can try to reason about things by looking at the common queries from sites like try.gitea.io |
this just got worse not better... 1.17.x up to 1.18.0 did fix the issue |
[x]
):Description
Super slow loading of the Dashboard where the list of actions is displayed.
There are about 300k action entries in the database for the last year.
Most users have around 10k up to 30k actions if selected on their user_id.
When doing an
EXPLAIN
onthere will be two indexes merged (on disk)
IDX_action_is_deleted
andIDX_action_user_id
it seems the
is_deleted
one is taken first and so the query takes around 5 secondsthere are three ways of temporarily fixing the issue
FORCE INDEX(IDX_action_user_id)
to the query changes the order of the indexes usedIDX_action_is_deleted
indexas a result the speed for the query goes down to sub milliseconds
maybe just removing the index from the deleted field in the action model would be the easiest one?
The text was updated successfully, but these errors were encountered: