[Akonadi] Investigate using CTE for LIST handler
Open, Needs TriagePublic

Description

Look into using CTE (Common Table Expression) for recursive queries in LIST handler.

With a query like this:

WITH RECURSIVE cte(id, name, remoteId, parentId) AS (
      SELECT id, name, remoteId, parentId FROM CollectionTable WHERE id = 4373
   UNION ALL
      SELECT child.id, child.name, child.remoteId, child.parentId FROM cte AS parent, CollectionTable AS child WHERE child.parentId = parent.id
   )
SELECT id, name, remoteId, parentId FROM cte
ORDER BY id ASC

we can get all sub-collections of collection 4373 (inclusive) with a single query. The query can also be inverted to query from descendant up to a parent.

This could help us reduce the amount of SQL queries executed in the LIST handler in order to get the Collection tree.

CTEs are supported by MySQL, MariaDB, PSQL and SQLite