Skip to content
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

Missing combined index on issue_user issue_id and uid #27877

Closed
sebastian-sauer opened this issue Nov 2, 2023 · 11 comments · Fixed by #28080
Closed

Missing combined index on issue_user issue_id and uid #27877

sebastian-sauer opened this issue Nov 2, 2023 · 11 comments · Fixed by #28080
Labels
performance/speed performance issues with slow downs type/bug

Comments

@sebastian-sauer
Copy link
Contributor

Description

There is currently no combined index on issue_user uid and issueid.
For a lot of operations these two params are used in the where query and adding the index brought some noticeable performance benefits.

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

No response

Operating System

No response

How are you running Gitea?

gitea executable

Database

MySQL/MariaDB

@techknowlogick techknowlogick added the performance/speed performance issues with slow downs label Nov 2, 2023
@JakobDev
Copy link
Contributor

JakobDev commented Nov 2, 2023

Does XORM support combined Indexes?

@KazzmanK
Copy link
Contributor

KazzmanK commented Nov 2, 2023

From docs https://xorm.io/docs/chapter-02/4.columns/

index/index(indexname) column is index. if add (indexname), the column is used for combined index with the field that defining same indexname.

@sebastian-sauer
Copy link
Contributor Author

But I'm not sure how to handle the current case - there is already an index on both fields but no combined.
@lunny how can we solve this? is there a way to add an additional combined index via xorm?

@delvh
Copy link
Member

delvh commented Nov 2, 2023

@JakobDev yes, with the same mechanism as for composite unique keys as @KazzmanK already pointed out.
@sebastian-sauer yes, using the mechanism described by @KazzmanK on top.

@sebastian-sauer
Copy link
Contributor Author

sebastian-sauer commented Nov 2, 2023

Not sure i understand correctly - can i just use sth like the following code:

type IssueUser struct {
	ID          int64 `xorm:"pk autoincr"`
	UID         int64 `xorm:"INDEX INDEX(uidtoissue)"` // User ID.
	IssueID     int64 `xorm:"INDEX INDEX(uidtoissue)"`
	IsRead      bool
	IsMentioned bool
}

As i want to keep the index only on UID and add a combined index.

@delvh
Copy link
Member

delvh commented Nov 2, 2023

Exactly.

@sebastian-sauer
Copy link
Contributor Author

Great - will create a pr with that.

@KazzmanK
Copy link
Contributor

KazzmanK commented Nov 2, 2023

Great - will create a pr with that.

If you need to keep UID index there is no need to have dedicated one, combined (UID,IssueID) index will support querying by UID alone. Just be sure, that XORM`s combined index will be created as (UID,IssueID), but not (IssueID,UID)

type IssueUser struct {
	ID          int64 `xorm:"pk autoincr"`
	UID         int64 `xorm:"INDEX(uidtoissue)"` // User ID.
	IssueID     int64 `xorm:"INDEX INDEX(uidtoissue)"`
	IsRead      bool
	IsMentioned bool
}

Other question, what if I need to have two combined indexes , (UID,IssueID) and (IssueID,UID), looks like it is not possible.

@lunny
Copy link
Member

lunny commented Nov 3, 2023

Currently, xorm doesn't support index sequences. But more than one index is supported.

@wxiaoguang
Copy link
Contributor

Currently, xorm doesn't support index sequences. But more than one index is supported.

It supports.

image

@lunny
Copy link
Member

lunny commented Nov 3, 2023

Currently, xorm doesn't support index sequences. But more than one index is supported.

It supports.

image

Ah, yes. Just forgot that.

sebastian-sauer added a commit to sebastian-sauer/gitea that referenced this issue Nov 15, 2023
lunny pushed a commit to sebastian-sauer/gitea that referenced this issue Dec 14, 2023
lunny added a commit that referenced this issue Dec 14, 2023
fixes #27877

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this issue Jan 17, 2024
fixes go-gitea#27877

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2024
silverwind pushed a commit to silverwind/gitea that referenced this issue Feb 20, 2024
fixes go-gitea#27877

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
performance/speed performance issues with slow downs type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants