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

[21] generate a better optimized query for path prefix search filters #29080

Merged
merged 1 commit into from
Oct 13, 2021

Conversation

icewind1991
Copy link
Member

Applies the optimizations from #28476 and #28608 to the nc21 jail search logic

@icewind1991 icewind1991 added the 3. to review Waiting for reviews label Oct 5, 2021
@icewind1991 icewind1991 added this to the Nextcloud 21.0.6 milestone Oct 5, 2021
@juliusknorr
Copy link
Member

@icewind1991 Is there any way to verify from the query that it is using an indexed search? The query still seems to use just the fs_mtime index.

MariaDB [nextcloud]> 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` = 2) AND (LOWER(`name`) LIKE LOWER('%animals%') ESCAPE '\\') AND ((`path` LIKE '__groupfolders/1/%' ESCAPE '\\') OR (`path` = '__groupfolders/1')) ORDER BY `mtime` desc LIMIT 5;
+------+-------------+-------+--------+-----------------------------------------------------------------------------------------------------+----------+---------+-----------------------+------+-------------+
| id   | select_type | table | type   | possible_keys                                                                                       | key      | key_len | ref                   | rows | Extra       |
+------+-------------+-------+--------+-----------------------------------------------------------------------------------------------------+----------+---------+-----------------------+------+-------------+
|    1 | SIMPLE      | file  | index  | fs_storage_path_hash,fs_storage_mimetype,fs_storage_mimepart,fs_storage_size,fs_storage_path_prefix | fs_mtime | 8       | NULL                  | 10   | Using where |
|    1 | SIMPLE      | fe    | eq_ref | PRIMARY                                                                                             | PRIMARY  | 8       | nextcloud.file.fileid | 1    | Using where |
+------+-------------+-------+--------+-----------------------------------------------------------------------------------------------------+----------+---------+-----------------------+------+-------------+
2 rows in set (0.001 sec)

Might be overlooking something here, but maybe we'd need to have a combined index on storage/mtime/path for that? create index fs_storage_mtime on oc_filecache(storage, mtime, path(64));

MariaDB [nextcloud]> create index fs_storage_mtime_path_prefix on oc_filecache(storage, mtime, path(64));
Query OK, 0 rows affected (0.057 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [nextcloud]> 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` = 2) AND (LOWER(`name`) LIKE LOWER('%animals%') ESCAPE '\\') AND ((`path` LIKE '__groupfolders/1/%' ESCAPE '\\') OR (`path` = '__groupfolders/1')) ORDER BY `mtime` desc LIMIT 5;
+------+-------------+-------+--------+----------------------------------------------------------------------------------------------------------------------------------+------------------------------+---------+-----------------------+------+-------------+
| id   | select_type | table | type   | possible_keys                                                                                                                    | key                          | key_len | ref                   | rows | Extra       |
+------+-------------+-------+--------+----------------------------------------------------------------------------------------------------------------------------------+------------------------------+---------+-----------------------+------+-------------+
|    1 | SIMPLE      | file  | range  | fs_storage_path_hash,fs_storage_mimetype,fs_storage_mimepart,fs_storage_size,fs_storage_path_prefix,fs_storage_mtime_path_prefix | fs_storage_mtime_path_prefix | 8       | NULL                  | 4431 | Using where |
|    1 | SIMPLE      | fe    | eq_ref | PRIMARY                                                                                                                          | PRIMARY                      | 8       | nextcloud.file.fileid | 1    | Using where |
+------+-------------+-------+--------+----------------------------------------------------------------------------------------------------------------------------------+------------------------------+---------+-----------------------+------+-------------+
2 rows in set (0.002 sec)

@icewind1991
Copy link
Member Author

icewind1991 commented Oct 6, 2021

Do you have the index from #28541 ?

Also those queries look like the one that get generated for sqlite, LOWER(..) LIKE LOWER(..) shouldn't use used on mysql

@juliusknorr
Copy link
Member

Oh sorry, indeed my stable21 setup was on sqlite for some reason, will retest. Sorry for the confusion.

Copy link
Member

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

👍

@PVince81 PVince81 added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Oct 7, 2021
@icewind1991
Copy link
Member Author

/backport to stable20

Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

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

All right, seems to do the trick for me now with the right database picked as well 🎉

Signed-off-by: Robin Appelman <robin@icewind.nl>
@PVince81 PVince81 merged commit 5735a55 into stable21 Oct 13, 2021
@PVince81 PVince81 deleted the path-prefix-filter-21 branch October 13, 2021 06:37
@blizzz blizzz mentioned this pull request Nov 3, 2021
10 tasks
icewind1991 added a commit that referenced this pull request Dec 14, 2021
this case was missed from #29080

Signed-off-by: Robin Appelman <robin@icewind.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants