Each level that's represented in a view from the Radial or Treemap, when filtered (in this example, I used "root" or "uid=0".
SELECT sum(size) AS sum_size FROM files JOIN directories ON files.directory_id = directories.id WHERE (files.name LIKE '%' AND files.uid = 0) AND (directories.lft >= (SELECT lft FROM directories WHERE id=65313) AND directories.lft <= (SELECT rgt FROM directories WHERE id=65313) AND directories.server_id = 2)
The explain plan for each of these queries is:
-------------------------------------------------------------------------------------------------------------
Aggregate (cost=76161.92..76161.93 rows=1 width=8)
InitPlan
-> Index Scan using directory_info_pkey on directories (cost=0.00..8.57 rows=1 width=4)
Index Cond: (id = 64466)
-> Index Scan using directory_info_pkey on directories (cost=0.00..8.57 rows=1 width=4)
Index Cond: (id = 64466)
-> Hash Join (cost=1198.69..76139.09 rows=2273 width=8)
Hash Cond: (files.directory_id = directories.id)
-> Seq Scan on files (cost=0.00..71275.43 rows=728449 width=12)
Filter: (((name)::text ~~ '%'::text) AND (uid = 0))
-> Hash (cost=1197.99..1197.99 rows=282 width=4)
-> Bitmap Heap Scan on directories (cost=145.12..1197.99 rows=282 width=4)
Recheck Cond: ((lft >= $0) AND (lft <= $1))
Filter: (server_id = 2)
-> Bitmap Index Scan on index_directories_on_lft (cost=0.00..145.05 rows=452 width=0)
Index Cond: ((lft >= $0) AND (lft <= $1))
(16 rows)
and issuing an "explain analyze" takes around 5 seconds. Take into account that the whole database is stored in a RAM file system.
I think we need to look at optimising these queries (if we can).