CREATE INDEX ix1 ON default(seller_id) WHERE type = "Seller";
CREATE INDEX ix1 ON default(seller_id) WHERE type = "Account";
CREATE INDEX ix1 ON default(account_id) WHERE type = "Payment";
SELECT t2.s.seller_id, t2.s.seller_name, ARRAY_AGG({t2.Payments, t2.a.account_id, t2.a.account_name}) AS Accounts
FROM ( SELECT t1.s, t1.a, ARRAY_AGG({p.id,p.account_id,p.amount}} AS Payments
FROM (SELECT s, a, p
FROM default AS s
JOIN default AS a ON s.seller_id = a.seller_id
JOIN default AS p ON a.account_id = p.account_id
WHERE s.type = "Seller" AND a.type = "Account"
AND p.type = "Payment" AND s.seller_id IS NOT NULL) AS t1
GROUP BY t1.s, t1.a) AS t2
GROUP BY t2.s;