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 indices on various columns to increase performance #5935

Closed
wants to merge 1 commit into from

Conversation

miaulalala
Copy link
Contributor

This should speed up different queries, namely the threading query, considerably.

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

LGTM (although not sure Christoph agrees on the naming :D)

@miaulalala miaulalala force-pushed the enhancement/additional-indices-for-mail branch from e8cd9dc to 060ee70 Compare January 11, 2022 16:36
@miaulalala
Copy link
Contributor Author

@nickvergessen I can't get Static Analysis to accept the migration. Any chance you could take a look?

@miaulalala miaulalala modified the milestone: v1.11.6 Jan 19, 2022
Signed-off-by: Anna Larch <anna@nextcloud.com>
@miaulalala miaulalala force-pushed the enhancement/additional-indices-for-mail branch from 003729c to de0a122 Compare January 25, 2022 15:01
@miaulalala miaulalala removed this from the v1.11.6 milestone Jan 25, 2022
@miaulalala miaulalala added this to the v1.11.7 milestone Jan 25, 2022
}

// Postgres doesn't allow for shortened indices, so let's skip the last index.
if ($schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
Copy link
Member

@ChristophWurst ChristophWurst Jan 26, 2022

Choose a reason for hiding this comment

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

open a tech debt ticket. this code is prone to explode with any changes to the implementation of the db abstraction. we had the same issue when IDbConnection (or was it the builder?) was assumed to directly implement the Doctrine classes. But since we added a new layer of abstraction that was never the case -> kaboom.

suggestion for a fix: propose an OCP API change with a new accessor that gives us the db type, e.g. as string or number that you can compare to a constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

API change on the ISchemaWrapper class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


$table = $schema->getTable('mail_messages');
if (!$table->hasIndex('mail_messages_id_flags')) {
$table->addIndex(['mailbox_id', 'flag_important', 'flag_deleted', 'flag_seen'], 'mail_messages_id_flags');
Copy link
Member

Choose a reason for hiding this comment

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

have you done any performance profiling? the messages table is potentially large. if you have an installation with 20k users and 5k messages each, the table will contain 100M rows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't but these indices are from c.nc.com. They must have been applied last year when we did an evaluation. It was suggested to a customer to use them and it worked fine for them and seemed to help with performance.

If you tell me how to, I will do it :)

Copy link
Member

Choose a reason for hiding this comment

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

I don't have an exact threshold but any migration should run in a matter of seconds. The reason is that many installation use the web updater and there is a default timeout of 30s. Assuming that this app might not be the only component that needs time for a migration, we only have a fraction of those 30s to finish the job.

Anything that takes longer should be optional, if possible.

$table->addIndex(['mailbox_id', 'flag_important', 'flag_deleted', 'flag_seen'], 'mail_messages_id_flags');
}
if (!$table->hasIndex('mail_messages_id_flags2')) {
$table->addIndex(['mailbox_id', 'flag_deleted', 'flag_flagged'], 'mail_messages_id_flags2');
Copy link
Member

Choose a reason for hiding this comment

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

same potential performance problems here. maybe this should all be optional indices?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, we could add an occ command for it for example?

Copy link
Member

Choose a reason for hiding this comment

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

yes, albeit it would be hard for admins to ever discover those as we do not have app-provided setup checks. nextcloud/server#25471 is probably the more integrated approach.

@miaulalala
Copy link
Contributor Author

This is scheduled to be applied with the cache reset.

@miaulalala
Copy link
Contributor Author

Redo as discussed

@miaulalala miaulalala closed this Apr 4, 2022
@ChristophWurst ChristophWurst deleted the enhancement/additional-indices-for-mail branch April 4, 2022 09:51
Sign up for free to 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.

4 participants