From 3d6d8059c8088fd6c2d8a6a50cdec247a98baac3 Mon Sep 17 00:00:00 2001 From: Jean-Pascal MILCENT Date: Wed, 23 Mar 2022 12:23:59 +0100 Subject: [PATCH] Fix db: add indexes to vm_observations_mailles --- .../13.atlas.vm_observations_mailles.sql | 24 +++++++++++-------- data/update/update_vm_index.sql | 7 ++++++ 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 data/update/update_vm_index.sql diff --git a/data/atlas/13.atlas.vm_observations_mailles.sql b/data/atlas/13.atlas.vm_observations_mailles.sql index 659744fb4..06a3a953e 100644 --- a/data/atlas/13.atlas.vm_observations_mailles.sql +++ b/data/atlas/13.atlas.vm_observations_mailles.sql @@ -1,13 +1,17 @@ CREATE MATERIALIZED VIEW atlas.vm_observations_mailles -AS SELECT obs.cd_ref, -obs.id_observation, -m.id_maille, -m.geojson_maille, -date_part('year', dateobs) as annee -FROM atlas.vm_observations obs -JOIN atlas.t_mailles_territoire m ON st_intersects(obs.the_geom_point, m.the_geom) +AS + SELECT obs.cd_ref, + obs.id_observation, + m.id_maille, + m.geojson_maille, + date_part('year', dateobs) as annee + FROM atlas.vm_observations obs + JOIN atlas.t_mailles_territoire m ON st_intersects(obs.the_geom_point, m.the_geom) WITH DATA; -create unique index on atlas.vm_observations_mailles (id_observation); -create index on atlas.vm_observations_mailles (id_maille); -create index on atlas.vm_observations_mailles (cd_ref); \ No newline at end of file +CREATE UNIQUE INDEX ON atlas.vm_observations_mailles (id_observation); +CREATE INDEX ON atlas.vm_observations_mailles (id_maille); +CREATE INDEX ON atlas.vm_observations_mailles (cd_ref); +CREATE INDEX ON atlas.vm_observations_mailles (geojson_maille); +CREATE INDEX ON atlas.vm_observations_mailles (annee); +CREATE UNIQUE INDEX ON atlas.vm_observations_mailles USING btree(id_observation, geojson_maille) ; \ No newline at end of file diff --git a/data/update/update_vm_index.sql b/data/update/update_vm_index.sql new file mode 100644 index 000000000..2fea70aff --- /dev/null +++ b/data/update/update_vm_index.sql @@ -0,0 +1,7 @@ +BEGIN; + +CREATE INDEX ON atlas.vm_observations_mailles (geojson_maille); +CREATE INDEX ON atlas.vm_observations_mailles (annee); +CREATE UNIQUE INDEX ON atlas.vm_observations_mailles USING btree(id_observation, geojson_maille) ; + +COMMIT; \ No newline at end of file