Use join for the deleting issue actions query #11386

Closed
opened 2025-11-02 09:36:16 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @otbutz on GitHub (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=?)

ab388deb0e/models/activities/action.go (L688-L702)

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

Originally created by @otbutz on GitHub (Aug 1, 2023). ### Description Our current DELETE query for actions is rather inefficient on MariaDB: ```sql DELETE FROM action WHERE comment_id IN (SELECT id FROM comment WHERE issue_id=?) ``` https://github.com/go-gitea/gitea/blob/ab388deb0e52c058a19dbd844bdd890f7cf84d51/models/activities/action.go#L688-L702 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
GiteaMirror added the type/bugtype/upstream labels 2025-11-02 09:36:16 -06:00
Author
Owner

@wxiaoguang commented on GitHub (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.

@wxiaoguang commented on GitHub (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.
Author
Owner

@lunny commented on GitHub (Aug 2, 2023):

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

@lunny commented on GitHub (Aug 2, 2023): ~The main problem is `comment_id` in `action` table is not an index column.~
Author
Owner

@wxiaoguang commented on GitHub (Aug 2, 2023):

image

@wxiaoguang commented on GitHub (Aug 2, 2023): ![image](https://github.com/go-gitea/gitea/assets/2114189/125cd3ce-33f0-47ad-9332-bf3ca2f1d869)
Author
Owner

@lunny commented on GitHub (Aug 2, 2023):

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

@lunny commented on GitHub (Aug 2, 2023): OK. I see, it's MariaDB's problem.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#11386