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

Add combined index for issue_user.uid and issue_id #28080

Merged

Conversation

sebastian-sauer
Copy link
Contributor

fixes #27877

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 15, 2023
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 15, 2023
models/issues/issue_user.go Outdated Show resolved Hide resolved
@6543
Copy link
Member

6543 commented Nov 15, 2023

@sebastian-sauer could you test if the suggested changes still fix the issue - that should be the proper way

@sebastian-sauer
Copy link
Contributor Author

yes - will do it now.

@sebastian-sauer
Copy link
Contributor Author

Looks good - the index is created:

image

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 15, 2023
@6543 6543 added this to the 1.22.0 milestone Nov 15, 2023
Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you wanted a combined INDEX?
Why is it suddenly a unique constraint?

@sebastian-sauer
Copy link
Contributor Author

It's now a combined unique index.
My first version was just a unique index.

I didn't see a reason against having this a unique combined index - is there any?

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.

It's also feasible to drop the INDEX(uid), because UNIQUE(a,b) also works for INDEX(a).

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 17, 2023
@lunny
Copy link
Member

lunny commented Nov 18, 2023

But maybe users database has duplicated records so that the migration may fail?

@sebastian-sauer
Copy link
Contributor Author

Not sure how to solve this - if there is a (from my point of view) data error (or is there any allowed way to get duplicate records?) the unique constraint will fail.

I'm happy to not make it a unique index, but how do the other reviewers think about this?

@lunny
Copy link
Member

lunny commented Nov 22, 2023

Maybe select * from (select issue_id, uid, count(1) as cnt from issue_user group by issue_id, uid) a where a.cnt > 1; and then we can use delete * from issue_user where issue_id = ? and uid = ? limit ?.

@github-actions github-actions bot added modifies/translation modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/frontend modifies/docs modifies/internal labels Dec 14, 2023
@lunny lunny force-pushed the feature/27877_combined_index_on_issue_user branch from e5b795f to 63e5c99 Compare December 14, 2023 02:43
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 14, 2023
@github-actions github-actions bot removed modifies/translation modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/frontend modifies/docs modifies/internal labels Dec 14, 2023
@lunny
Copy link
Member

lunny commented Dec 14, 2023

Maybe select * from (select issue_id, uid, count(1) as cnt from issue_user group by issue_id, uid) a where a.cnt > 1; and then we can use delete * from issue_user where issue_id = ? and uid = ? limit ?.

Pushed my proposal.

@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 14, 2023
@lunny lunny enabled auto-merge (squash) December 14, 2023 08:52
@lunny lunny merged commit e08f1a9 into go-gitea:main Dec 14, 2023
25 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 14, 2023
@delvh delvh added the performance/speed performance issues with slow downs label Dec 14, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Dec 15, 2023
* giteaofficial/main:
  Polyfill SubmitEvent for PaleMoon (go-gitea#28441)
  Fix Chinese translation of config cheat sheet[API] (go-gitea#28472)
  Add combined index for issue_user.uid and issue_id (go-gitea#28080)
  Fix documents for "custom/public/assets/" (go-gitea#28465)
  Only use SHA256 feature when git >= 2.42 (go-gitea#28466)
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this pull request Jan 17, 2024
fixes go-gitea#27877

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
fixes go-gitea#27877

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/migrations performance/speed performance issues with slow downs size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing combined index on issue_user issue_id and uid
6 participants