Uh oh!
There was an error while loading. Please reload this page.
add a prefix index to filecache.path, attempt 2 - #28541
Conversation
Uh oh!
There was an error while loading. Please reload this page.
nickvergessen
commented
Aug 23, 2021
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
c35470bCompare
skjnldsv
left a comment
There was a problem hiding this comment.
Code is good, no idea about what @nickvergessen was referring to. Let's wait for another review :)
nickvergessen
commented
Aug 25, 2021
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. |
icewind1991
commented
Aug 26, 2021
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. |
skjnldsv
commented
Sep 16, 2021
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`descLIMIT5; |
skjnldsv
commented
Oct 8, 2021
Applied on NC production. 1 sec per 100k rows in the filecache. Expecting minimal downtime then. |
icewind1991
commented
Oct 8, 2021
@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
6953265Compareskjnldsv
commented
Oct 11, 2021
Let's merge? and backport to 20! 🚀 |
skjnldsv
commented
Oct 11, 2021
/backport to stable22 |
skjnldsv
commented
Oct 11, 2021
/backport to stable21 |
skjnldsv
commented
Oct 11, 2021
/backport to stable20 |
icewind1991
commented
Oct 19, 2021
Counting as approval, merging |
The backport to stable20 failed. Please do this backport manually. |
solracsf
commented
Oct 25, 2021
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.pathhasn'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