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

Use join for the deleting issue actions query #26277

Closed
otbutz opened this issue Aug 1, 2023 · 4 comments · Fixed by #26279
Closed

Use join for the deleting issue actions query #26277

otbutz opened this issue Aug 1, 2023 · 4 comments · Fixed by #26279
Labels
type/bug type/upstream This is an issue in one of Gitea's dependencies and should be reported there
Milestone

Comments

@otbutz
Copy link

otbutz commented Aug 1, 2023

Description

Our current DELETE query for actions is rather inefficient on MariaDB:

DELETE FROM action WHERE comment_id IN (SELECT id FROM comment WHERE issue_id=?)

func DeleteIssueActions(ctx context.Context, repoID, issueID int64) error {
// delete actions assigned to this issue
subQuery := builder.Select("`id`").
From("`comment`").
Where(builder.Eq{"`issue_id`": issueID})
if _, err := db.GetEngine(ctx).In("comment_id", subQuery).Delete(&Action{}); err != nil {
return err
}
_, err := db.GetEngine(ctx).Table("action").Where("repo_id = ?", repoID).
In("op_type", ActionCreateIssue, ActionCreatePullRequest).
Where("content LIKE ?", strconv.FormatInt(issueID, 10)+"|%").
Delete(&Action{})
return err
}

Caused by https://jira.mariadb.org/browse/MDEV-16289

see https://codeberg.org/forgejo/forgejo/issues/1161 and https://codeberg.org/forgejo/forgejo/pulls/1165

Gitea Version

1.20.2

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Binary started via systemd behind a caddy reverse proxy.

Database

None

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Aug 1, 2023

Thank you for the report.

The referred fix on codeberg seems not good enough (eg: the test doesn't cover other databases).

I proposed a new fix: Bypass MariaDB performance bug of the "IN" sub-query #26279


I didn't use "JOIN" because I think it's better to avoid using too many dialects for difference database, while pre-querying the IDs is fast enough.

@lunny
Copy link
Member

lunny commented Aug 2, 2023

The main problem is comment_id in action table is not an index column.

@wxiaoguang
Copy link
Contributor

image

@lunny
Copy link
Member

lunny commented Aug 2, 2023

OK. I see, it's MariaDB's problem.

@lunny lunny added the type/upstream This is an issue in one of Gitea's dependencies and should be reported there label Aug 2, 2023
@lunny lunny added this to the 1.20.3 milestone Aug 7, 2023
lunny pushed a commit that referenced this issue Aug 7, 2023
…ssueIndex (#26279) (#26368)

Backport #26279 by @wxiaoguang

Close #26277
Fix #26285

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/bug type/upstream This is an issue in one of Gitea's dependencies and should be reported there
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants