In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
CREATE INDEX tree_idx_to_node ON "tree" ("to_node");
WITH RECURSIVE us_path AS (SELECT
tree.id_reach,
tree.from_node,
tree.to_node
FROM
tree
WHERE
tree.to_node = 1
UNION
ALL SELECT
tr.id_reach,
tr.from_node,
tr.to_node
FROM
tree AS tr
JOIN
us_path AS usp
ON tr.to_node = usp.from_node) SELECT
us_path.id_reach
FROM
us_path