Skip to content

perf: add new index to serve a full WHERE clause - #2441

Merged
miaulalala merged 1 commit into
masterfrom
perf/noid/add-where-index
Mar 10, 2026
Merged

perf: add new index to serve a full WHERE clause#2441
miaulalala merged 1 commit into
masterfrom
perf/noid/add-where-index

Conversation

@miaulalala

@miaulalalamiaulalala commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator

This index:

  • Satisfies the full WHERE clause (affecteduser, object_type, object_id) as an equality prefix
  • Includes timestamp as the trailing column, allowing the ORDER BY timestamp DESC to be served directly from the index without a filesort
  • Covers the filter='filter' query path completely — the DB can do an index range scan in reverse order and stop after LIMIT rows

Added it to the occ command for missing indices instead of running as a migration.

@miaulalala

Copy link
Copy Markdown
CollaboratorAuthor

/backport to stable33

@miaulalala

Copy link
Copy Markdown
CollaboratorAuthor

/backport to stable32

@nickvergessen
nickvergessen removed their request for review March 9, 2026 20:21
@cypress

cypressBot commented Mar 9, 2026

Copy link
Copy Markdown

ActivityRun #3431

Run Properties:status check passed Passed #3431git commit0ba49e5525: perf: add new index to serve a full WHERE clause
ProjectActivity
Branch Reviewperf/noid/add-where-index
Run statusstatus check passed Passed #3431
Run duration02m 02s
Commitgit commit0ba49e5525: perf: add new index to serve a full WHERE clause
CommitterAnna
View all properties for this run ↗︎

Test results
Tests that failedFailures0
Tests that were flakyFlaky0
Tests that did not run due to a developer annotating a test with .skipPending1
Tests that did not run due to a failure in a mocha hookSkipped0
Tests that passedPassing9
View all changes introduced in this branch ↗︎

@miaulalala
miaulalala requested a review from artongeMarch 9, 2026 22:40
@miaulalala
miaulalalaforce-pushed the perf/noid/add-where-index branch from 4fd77a2 to 9f6f613CompareMarch 9, 2026 22:53
@miaulalalamiaulalala changed the title perf: add new index to server a full WHERE clauseperf: add new index to serve a full WHERE clauseMar 9, 2026

@AltahrimAltahrim left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we have an object_id with two different object_type?

Comment threadlib/Migration/Version2012Date20260309120000.php Outdated
@ChristophWurst

Copy link
Copy Markdown
Member

Downtime None (maintenance mode already active; MySQL is online DDL)
Migration duration ~30–90 seconds for 1M rows

I'm slightly doubtful about this with oc_activity usually being one of the biggest table of a Nextcloud deployment. We have a mechanism for optional indices. Why not use that?
You can, of course, add the index to the migration that creates the table so it exists for new installations.

@miaulalala

Copy link
Copy Markdown
CollaboratorAuthor

The query index specifically accelerates the per-object activity stream — the query that runs when a user opens the activity sidebar on a file or share.

Putting it in a repair step for the missing indices works as well, I don't have any preference.

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The index will be missing for fresh installs unless you edit the migration that creates the table

Signed-off-by: Anna Larch <anna@nextcloud.com>
@miaulalala
miaulalalaforce-pushed the perf/noid/add-where-index branch from e2f78f5 to fe85d50CompareMarch 10, 2026 16:57
@miaulalala

Copy link
Copy Markdown
CollaboratorAuthor

/backport to stable32

@miaulalala
miaulalala merged commit 652440f into masterMar 10, 2026
54 checks passed
@miaulalala
miaulalala deleted the perf/noid/add-where-index branch March 10, 2026 17:02
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@miaulalala@ChristophWurst@Altahrim