Skip to content

create mv taxref_tree #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions data/taxref_tree.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--Construction de la VM

CREATE EXTENSION IF NOT EXISTS ltree;

CREATE MATERIALIZED VIEW taxonomie.taxref_tree
AS WITH RECURSIVE x AS (
SELECT t.cd_nom as cd_ref,
t.cd_nom::text::ltree AS path
FROM taxonomie.taxref t
WHERE t.cd_sup IS NULL AND t.cd_nom = t.cd_ref
UNION ALL
SELECT y.cd_nom AS cd_ref,
ltree_addtext(x_1.path, y.cd_nom::text) AS path
FROM x x_1,
taxonomie.taxref y
WHERE y.cd_nom = y.cd_ref AND x_1.cd_ref = y.cd_sup
)
SELECT x.cd_ref,
x.path
FROM x
WITH DATA;

-- View indexes:
CREATE UNIQUE INDEX taxref_tree_cd_nom_idx ON taxonomie.taxref_tree USING btree (cd_ref);
CREATE INDEX taxref_tree_path_idx ON taxonomie.taxref_tree USING gist (path); -- TRES important pour les perfs