I have quite a lot bookmarks in several "root" folders. After some time when all worked perfectly, Bookmarks started to utilize SQL servar to the maximum. Every attempt to synchronize starts new query on the server, which doesn't finish and the sync ends with timeout. I didn't perform any update or changes on the server side between the time when all worked well and time when this issue started.
Nextcloud version: 20.0.13 (Docker - php FPM)
Bookmarks version: 4.4.1 and also the latest (surprisingly marked as 10.0.0)
I analyzed SQL queries on the MySQL (resp. Mariadb) and I found the SQL query which utilizes processor, which is this one:
SELECT b.id, b.url, b.title, b.description, b.lastmodified, b.added, b.clickcount, b.last_preview, b.available, b.archived_file, b.user_id, b.text_content, b.html_content,
GROUP_CONCAT(tree.parent_folder) AS folders, GROUP_CONCAT(t.tag) AS tags FROM oc_bookmarks b LEFT JOIN oc_bookmarks_tree tree ON b.id =tree.id AND tree.type = 'bookmark'
LEFT JOIN oc_bookmarks_tags t ON t.bookmark_id = b.id LEFT JOIN oc_bookmarks_tree tr ON tr.id = b.id AND tr.type = 'bookmark' LEFT JOIN oc_bookmarks_shared_folders sf ON tr.parent_folder = sf.folder_id
LEFT JOIN oc_bookmarks_tree tr2 ON tr2.id = tr.parent_folder AND tr2.type = 'folder'
LEFT JOIN oc_bookmarks_shared_folders sf2 ON tr2.parent_folder = sf.folder_id WHERE ((b.user_id = 'radek') OR (sf.user_id = 'radek') OR (sf2.user_id = 'radek')) AND (b.user_id IN ('radek'))
GROUP BY b.id, b.url, b.title, b.description, b.lastmodified, b.added, b.clickcount, b.last_preview, b.available, b.archived_file, b.user_id, b.text_content, b.html_content, b.id
ORDER BY b.lastmodified DESC, b.id ASC LIMIT 300
;
It could be hard to reproduce this issue - I may provide copy of my bookmarks (there's nothing secret there), but for the first look the query seems to be quite complex and complicated which could lead to non - optimal performance. MySQL is fast for simple queries, but sometimes really slow for more complex queries with bigger data quantity.
Process list on the SQL server luuks like this:
MariaDB [nextcloud]> SHOW PROCESSLIST;
+-----+-------------+-----------+-----------+---------+------+--------------------------+------------------------------------------------------------------------------------------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+-----+-------------+-----------+-----------+---------+------+--------------------------+------------------------------------------------------------------------------------------------------+----------+
| 1 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 2 | system user | | NULL | Daemon | NULL | InnoDB purge coordinator | NULL | 0.000 |
| 3 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 4 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 5 | system user | | NULL | Daemon | NULL | InnoDB shutdown handler | NULL | 0.000 |
| 157 | nextcloud | localhost | nextcloud | Query | 3739 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 180 | nextcloud | localhost | nextcloud | Query | 3679 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 226 | nextcloud | localhost | nextcloud | Query | 3547 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 245 | nextcloud | localhost | nextcloud | Query | 3487 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 286 | nextcloud | localhost | nextcloud | Query | 3376 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 319 | nextcloud | localhost | nextcloud | Query | 3316 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 438 | nextcloud | localhost | nextcloud | Query | 3016 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 461 | nextcloud | localhost | nextcloud | Query | 2955 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 545 | nextcloud | localhost | nextcloud | Query | 2830 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 586 | nextcloud | localhost | nextcloud | Query | 2711 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 601 | nextcloud | localhost | nextcloud | Query | 2650 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
| 605 | root | localhost | nextcloud | Query | 0 | Init | SHOW PROCESSLIST | 0.000 |
| 677 | nextcloud | localhost | nextcloud | Query | 1329 | Creating sort index | SELECT `b`.`id`, `b`.`url`, `b`.`title`, `b`.`description`, `b`.`lastmodified`, `b`.`added`, `b`.`cl | 0.000 |
+-----+-------------+-----------+-----------+---------+------+--------------------------+------------------------------------------------------------------------------------------------------+----------+
The result od the "EXPLAIN" command is this:
explain SELECT b.id, b.url, b.title, b.description, b.lastmodified, b.added, b.clickcount, b.last_preview, b.available, b.archived_file, b.user_id, b.text_content, b.html_content, GROUP_CONCAT(tree.parent_folder) AS folders, GROUP_CONCAT(t.tag) AS tags FROM oc_bookmarks b LEFT JOIN oc_bookmarks_tree tree ON b.id =tree.id AND tree.type = 'bookmark' LEFT JOIN oc_bookmarks_tags t ON t.bookmark_id = b.id LEFT JOIN oc_bookmarks_tree tr ON tr.id = b.id AND tr.type = 'bookmark' LEFT JOIN oc_bookmarks_shared_folders sf ON tr.parent_folder = sf.folder_id LEFT JOIN oc_bookmarks_tree tr2 ON tr2.id = tr.parent_folder AND tr2.type = 'folder' LEFT JOIN oc_bookmarks_shared_folders sf2 ON tr2.parent_folder = sf.folder_id WHERE ((b.user_id = 'radek') OR (sf.user_id = 'radek') OR (sf2.user_id = 'radek')) AND (b.user_id IN ('radek')) GROUP BY b.id, b.url, b.title, b.description, b.lastmodified, b.added, b.clickcount, b.last_preview, b.available, b.archived_file, b.user_id, b.text_content, b.html_content, b.id ORDER BY b.lastmodified DESC, b.id ASC LIMIT 300;
+------+-------------+-------+-------+---------------------------------------------------------------------+-------------------------+---------+----------------------------------+------+--------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------------------------------------------------------------+-------------------------+---------+----------------------------------+------+--------------------------------------------------------------+
| 1 | SIMPLE | b | range | IDX_3EE1CD04A76ED395,bookmarks_deadbyuser,bookmarks_user_clickcount | IDX_3EE1CD04A76ED395 | 258 | NULL | 1164 | Using index condition; Using temporary; Using filesort |
| 1 | SIMPLE | tree | ref | PRIMARY | PRIMARY | 90 | nextcloud.b.id,const | 2 | Using where; Using index |
| 1 | SIMPLE | t | ref | PRIMARY,bookmark_tag | PRIMARY | 8 | nextcloud.b.id | 1 | Using index |
| 1 | SIMPLE | tr | ref | PRIMARY | PRIMARY | 90 | nextcloud.b.id,const | 2 | Using where; Using index |
| 1 | SIMPLE | sf | ref | bookmarks_shared_folder | bookmarks_shared_folder | 8 | nextcloud.tr.parent_folder | 1 | Using where |
| 1 | SIMPLE | tr2 | ref | PRIMARY | PRIMARY | 90 | nextcloud.tr.parent_folder,const | 2 | Using where; Using index |
| 1 | SIMPLE | sf2 | index | NULL | bookmarks_shared_user | 1022 | NULL | 1 | Using where; Using index; Using join buffer (flat, BNL join) |
+------+-------------+-------+-------+---------------------------------------------------------------------+-------------------------+---------+----------------------------------+------+--------------------------------------------------------------+
I have quite a lot bookmarks in several "root" folders. After some time when all worked perfectly, Bookmarks started to utilize SQL servar to the maximum. Every attempt to synchronize starts new query on the server, which doesn't finish and the sync ends with timeout. I didn't perform any update or changes on the server side between the time when all worked well and time when this issue started.
Nextcloud version: 20.0.13 (Docker - php FPM)
Bookmarks version: 4.4.1 and also the latest (surprisingly marked as 10.0.0)
I analyzed SQL queries on the MySQL (resp. Mariadb) and I found the SQL query which utilizes processor, which is this one:
It could be hard to reproduce this issue - I may provide copy of my bookmarks (there's nothing secret there), but for the first look the query seems to be quite complex and complicated which could lead to non - optimal performance. MySQL is fast for simple queries, but sometimes really slow for more complex queries with bigger data quantity.
Process list on the SQL server luuks like this:
The result od the "EXPLAIN" command is this: