Skip to content

perf: extend action c_u index to include created_unix for faster dashboard feeds - #38076

Merged
lafriks merged 6 commits into
go-gitea:mainfrom
bircni:fix/action-dashboard-index-created-unix
Jun 17, 2026
Merged

perf: extend action c_u index to include created_unix for faster dashboard feeds#38076
lafriks merged 6 commits into
go-gitea:mainfrom
bircni:fix/action-dashboard-index-created-unix

Conversation

@bircni

@bircni bircni commented Jun 11, 2026

Copy link
Copy Markdown
Member

Adds created_unix as the third column of the c_u composite index on the action table, changing it from (user_id, is_deleted) to (user_id, is_deleted, created_unix).

Migration 337 drops and recreates the index. No data is touched.

Root causes

#32333 introduced the c_u index to speed up dashboard queries, but defined it as (user_id, is_deleted) — without created_unix.

#3368 The simple query is now efficient enough for the database to actually use c_u, but because created_unix is absent from the index, the database must load and sort every matching row before returning the first page of 20.

The existing c_u_d index (created_unix, user_id, is_deleted) does not help because its leading column is created_unix, which can't be used for an equality seek on user_id.

Those two caused this issue: #38075

With the fix, the database seeks directly to (user_id=X, is_deleted=false) and walks created_unix in descending order, stopping after 20 rows.

Fixes #38075

…oard feeds

The c_u index on the action table was defined as (user_id, is_deleted)
without created_unix. The dashboard feed query filters by those two
columns and then orders by created_unix DESC, so the database had to
load and sort every matching row before it could return the first page
of 20 — causing 27+ second queries on large action tables.

Adds created_unix as the third column of the c_u index so the database
can seek to (user_id, is_deleted) and walk created_unix in reverse
order, stopping after 20 rows without a full sort.

Assisted-by: Claude:claude-sonnet-4-6
@bircni bircni added this to the 1.27.0 milestone Jun 11, 2026
@bircni
bircni requested review from lunny and wxiaoguang June 11, 2026 15:29
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 11, 2026
@bircni bircni changed the title fix: extend action c_u index to include created_unix for faster dashboard feeds perf: extend action c_u index to include created_unix for faster dashboard feeds Jun 11, 2026
@bircni bircni added the performance/speed performance issues with slow downs label Jun 11, 2026
@github-actions github-actions Bot removed the type/bug label Jun 11, 2026
@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 Jun 11, 2026
@lunny

lunny commented Jun 11, 2026

Copy link
Copy Markdown
Member

What's the different between this index and c_u_d?

@bircni

bircni commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

What's the different between this index and c_u_d?

c_u_d leads with created_unix, so it can't seek the dashboard query (which filters user_id, is_deleted and has no predicate on time). The new c_u leads with user_id, is_deleted and trails created_unix, so the DB seeks the filter and walks the trailing column in order — satisfying ORDER BY created_unix DESC LIMIT 20 without a sort. Same columns, opposite access patterns; not redundant.

@lunny

lunny commented Jun 16, 2026

Copy link
Copy Markdown
Member

Please resolve the conflicts.

…index-created-unix

# Conflicts:
#	models/migrations/migrations.go
#	models/migrations/v1_27/v337.go
@bircni

bircni commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

Please resolve the conflicts.

@lunny fixed

@wxiaoguang
wxiaoguang removed their request for review June 16, 2026 23:40
…index-created-unix

# Conflicts:
#	models/migrations/migrations.go
#	models/migrations/v1_27/v338.go
#	models/migrations/v1_27/v338_test.go
@bircni

bircni commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

@lunny ping

@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 Jun 17, 2026
@lafriks
lafriks merged commit 240d0ef into go-gitea:main Jun 17, 2026
25 checks passed
@bircni
bircni deleted the fix/action-dashboard-index-created-unix branch June 17, 2026 20:38
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 18, 2026
* 'main' of https://github.com/go-gitea/gitea:
  perf: extend action `c_u` index to include `created_unix` for faster dashboard feeds (go-gitea#38076)
  fix: Various security fixes (go-gitea#38103)
  docs: add development setup guide (go-gitea#37960)
  fix: Various sec fixes 2 (go-gitea#38108)
ZPascal pushed a commit to ZPascal/gitea that referenced this pull request Jun 18, 2026
…dashboard feeds (go-gitea#38076)

Adds `created_unix` as the third column of the `c_u` composite index on
the `action` table, changing it from `(user_id, is_deleted)` to
`(user_id, is_deleted, created_unix)`.

Migration 337 drops and recreates the index. No data is touched.

defined it as `(user_id, is_deleted)` — without `created_unix`.

actually use `c_u`, but because `created_unix` is absent from the index,
the database must load and sort **every** matching row before returning
the first page of 20.

The existing `c_u_d` index `(created_unix, user_id, is_deleted)` does
not help because its leading column is `created_unix`, which can't be
used for an equality seek on `user_id`.

Those two caused this issue:
go-gitea#38075

With the fix, the database seeks directly to `(user_id=X,
is_deleted=false)` and walks `created_unix` in descending order,
stopping after 20 rows.

Fixes go-gitea#38075
zeekay pushed a commit to hanzoai/git that referenced this pull request Jul 26, 2026
…dashboard feeds (go-gitea#38076)

Adds `created_unix` as the third column of the `c_u` composite index on
the `action` table, changing it from `(user_id, is_deleted)` to
`(user_id, is_deleted, created_unix)`.

Migration 337 drops and recreates the index. No data is touched.

## Root causes

go-gitea#32333 introduced the `c_u` index to speed up dashboard queries, but
defined it as `(user_id, is_deleted)` — without `created_unix`.

go-gitea#3368 The simple query is now efficient enough for the database to
actually use `c_u`, but because `created_unix` is absent from the index,
the database must load and sort **every** matching row before returning
the first page of 20.

The existing `c_u_d` index `(created_unix, user_id, is_deleted)` does
not help because its leading column is `created_unix`, which can't be
used for an equality seek on `user_id`.

Those two caused this issue:
go-gitea#38075

With the fix, the database seeks directly to `(user_id=X,
is_deleted=false)` and walks `created_unix` in descending order,
stopping after 20 rows.

Fixes go-gitea#38075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. performance/speed performance issues with slow downs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetFeeds() Call on Dashboard Insanely Slow

5 participants