--ALL CATEGORIES QUERY

SELECT hkey FROM (SELECT distinct skeys(contents) AS hkey FROM revision.attributes) a WHERE position('cat:' IN a.hkey)=1 ORDER BY 1

--ALL RELATIONS QUERY

SELECT distinct contents->'rel:master' AS master,  contents->'rel:slave' AS slave, contents->'rel:role' AS role 
FROM revision.attributes ORDER BY 1,2,3;

--ALL ATTRIBUTES BY CATEGORIES (2-3 minutes long)

SELECT distinct categories.hkey, skeys(contents)  FROM revision.attributes attr,
(SELECT hkey FROM (SELECT distinct skeys(contents) AS hkey FROM revision.attributes) a WHERE position('cat:' IN a.hkey)=1 ORDER BY 1) categories
WHERE attr.contents ? hkey ORDER BY 1,2;

--ALL FTTYPES

SELECT DISTINCT hkey, contents->hkey FROM revision.attributes attr,
(SELECT hkey FROM (SELECT distinct skeys(contents) AS hkey FROM revision.attributes) a WHERE position(':ft_type_id' IN a.hkey) > 1 ORDER BY 1) fttypes
WHERE attr.contents ? hkey ORDER BY 1,2; 

