Skip to content

Commit

Permalink
Fix db: add indexes to vm_observations_mailles
Browse files Browse the repository at this point in the history
  • Loading branch information
jpm-cbna committed Dec 7, 2023
1 parent 5a918b1 commit 3d6d805
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
24 changes: 14 additions & 10 deletions data/atlas/13.atlas.vm_observations_mailles.sql
Original file line number Diff line number Diff line change
@@ -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);
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) ;
7 changes: 7 additions & 0 deletions data/update/update_vm_index.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 3d6d805

Please sign in to comment.