Skip to content
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

Feat: improve performances for syntheseff view #397

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jpm-cbna
Copy link
Contributor

See #390.

@@ -1,50 +1,90 @@
-- Creation d'une vue permettant de reproduire le contenu de la table du même nom dans les versions précédentes

CREATE VIEW synthese.syntheseff AS
WITH areas AS (
CREATE MATERIALIZED VIEW atlas.vm_cor_synthese_area
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Après discussion avec @TheoLechemia , il serait plus pertinent de basculer cette VM dans le schéma synthese car elle ne devrait être utilisé que par la vue synthese.syntheseff.

@amandine-sahl
Copy link
Contributor

Je me demande si pour des questions de performance, et etant donnée que ce sont des données "stables", il ne serait pas plus simple d'avoir une table de précalcul de la correspondance entre sensibilité, niveau de diffusion. Que l'on pourrait ensuite utiliser dans l'atlas.

CREATE TABLE gn_sensitivity.cor_diffusion_level_sensitivity AS
WITH sens AS (
    SELECT  id_nomenclature AS id_sens, cd_nomenclature  AS cd_sens,
    CASE
          WHEN cd_nomenclature = '0' THEN '5'
          ELSE cd_nomenclature 
      END AS cor_cd_diff,
        cd_nomenclature::int AS order_sens
    FROM ref_nomenclatures.t_nomenclatures AS tn
    WHERE id_type =  ref_nomenclatures.get_id_nomenclature_type('SENSIBILITE')
    UNION
    SELECT -1 AS id_sens, NULL  AS cd_sens, NULL AS cor_cd_diff, 0  AS order_sens
) , diff AS (
    SELECT id_nomenclature AS id_diff, cd_nomenclature  AS cd_diff,
     CASE
          WHEN cd_nomenclature IN ('0', '5') THEN 0
          ELSE cd_nomenclature::int
        END   AS order_diff
    FROM ref_nomenclatures.t_nomenclatures AS tn
    WHERE id_type =  ref_nomenclatures.get_id_nomenclature_type('NIV_PRECIS')
    UNION
    SELECT -1 AS id_diff, NULL  AS cd_diff, 0  AS order_diff
), d AS (
    SELECT * , GREATEST(sens.order_sens, diff.order_diff) AS order_max,
     CASE
          WHEN GREATEST(sens.order_sens, diff.order_diff) = 0 THEN '5'
          ELSE GREATEST(sens.order_sens, diff.order_diff)::varchar
        END   AS cd_max
    FROM sens, diff
)
SELECT d.*,  tn.id_nomenclature AS id_max
FROM d
JOIN ref_nomenclatures.t_nomenclatures AS tn
ON id_type =  ref_nomenclatures.get_id_nomenclature_type('NIV_PRECIS') AND cd_nomenclature = cd_max;
SELECT DISTINCT s.id_nomenclature_sensitivity , s.id_nomenclature_diffusion_level , cds.*
FROM gn_synthese.synthese AS s 
JOIN gn_sensitivity.cor_diffusion_level_sensitivity cds
ON cds.id_sens = COALESCE(s.id_nomenclature_sensitivity, -1) AND cds.id_diff = COALESCE(s.id_nomenclature_diffusion_level, -1)
 

jpm-cbna and others added 2 commits December 7, 2023 14:44
With pg_restore the search_path is not set to public. So, the error "geometry does not exist" is raised.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants