-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 a prefix index to filecache.path, attempt 2 #28541
Conversation
Can't remember completely why it failed back then. Maybe we can ask people to setup the index manually on several instances to not fail again. |
0717cbf
to
c35470b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is good, no idea about what @nickvergessen was referring to. Let's wait for another review :)
It 💥 on several servers (including c.nc.c iirc) back then (when attempt one was done). We can try it again, but in case it breaks again we have to revert it again. |
After some more testing I found that postgresql requires setting some additional options ("operator class") on the index before it can be used for Since dbal does not currently support setting these options I've disabled creating the index on pgsql for now so we can more easily add the correct index later and we don't get stuck with a useless index. |
Any news? :) |
Seems it's helping lot of times, but e.g. with groupfolders the index is not used: EXPLAIN SELECT `file`.`fileid`, `storage`, `path`, `path_hash`, `file`.`parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum`, `metadata_etag`, `creation_time`, `upload_time` FROM
`oc_filecache` `file` LEFT JOIN `oc_filecache_extended` `fe` ON `file`.`fileid` = `fe`.`fileid` WHERE (`storage` = 330) AND (((`path` COLLATE utf8mb4_general_ci LIKE '__groupfolders/22/%') OR (`path_hash` = '…')) AND (`name` COLLATE u
tf8mb4_general_ci LIKE '%…%')) ORDER BY `mtime` desc LIMIT 5;
|
Applied on NC production. 1 sec per 100k rows in the filecache. Expecting minimal downtime then. |
@nickvergessen make sure that you have #28476 and #28608 applied |
The reason that `filecache.path` hasn't had an index added is the mysql limitation of ~1kb for indexeded fields, which is to small for the `path`, however mysql supports indexing only the first N bytes of a column instead of the entire column, allowing us to add an index even if the column is to long. Because the index doesn't cover the entire column it can't be used in all situations where a normal index would be used, but it does cover the `path like 'folder/path/%'` queries that are used in various places. Sqlite and Postgresql don't support prefix indexes, but they also don't have the 1kb limit and DBAL handles the differences in index creation. Signed-off-by: Robin Appelman <robin@icewind.nl>
having the index work properly for the queries we need it for requires some additional options which dbal does not support at the momement. to prevent making it harder to add the correct index later on we don't create the index for now on postgresql Signed-off-by: Robin Appelman <robin@icewind.nl>
7d3f3a8
to
6953265
Compare
Let's merge? and backport to 20! 🚀 |
/backport to stable22 |
/backport to stable21 |
/backport to stable20 |
Counting as approval, merging |
The backport to stable20 failed. Please do this backport manually. |
Some feedback about this PR here: #29377 |
Second attempt at #26070, this time with a shorter prefix to hopefully not have the same issues.
The reason that
filecache.path
hasn't had an index added is the mysql limitation of ~1kb for indexeded fields,which is to small for the
path
, however mysql supports indexing only the first N bytes of a column instead of the entire column,allowing us to add an index even if the column is to long.
Because the index doesn't cover the entire column it can't be used in all situations where a normal index would be used, but it does cover the
path like 'folder/path/%'
queries that are used in various places.Sqlite and Postgresql don't support prefix indexes, but they also don't have the 1kb limit and DBAL handles the differences in index creation.
Signed-off-by: Robin Appelman robin@icewind.nl