как оптимизировать запрос в postgreSql - PullRequest
0 голосов
/ 15 октября 2019

Выполнение этого запроса занимает 99 минут. Мне нужен некоторый результат, полученный при его превышении, я пытаюсь использовать индекс и материализованное представление, но это не может его оптимизировать:

       select min(pointage_materiel.id_pointage) AS id,
        eds_societe.id_eds AS societe, eds_societe.code_eds AS code_societe, 
      edsm.id_edsm AS id_parc,
        edsm.code_edsm AS n_parc, edsm.lib_edsm AS 
     libelle_n_parc,pointage_materiel.date_periode AS 
      periode,
       eds_chantier.id_eds AS id_chantier, eds_chantier.code_eds AS 
      code_chantier, eds_chantier.lib_eds 
       AS libelle_chantier,
       eds_agence.code_eds AS code_agence,ctr_mecanique.code_ctr_mecan AS cm,
        pointage_materiel.statut_pointage
      from sigma02.edsm edsm
       LEFT JOIN ( SELECT pointage.id_pointage,pointage.id_parc, 
     pointage.id_chantier, 
       pointage.statut_pointage,
           to_char(pointage.date, 'MM-YYYY') AS date_periode FROM 
     sigma02.pointage) pointage_materiel
           ON edsm.id_edsm = pointage_materiel.id_parc LEFT JOIN 
     sigma02.chantier ON 
      pointage_materiel.id_chantier = chantier.id_eds
     LEFT JOIN sigma02.ctr_mecanique ON chantier.id_ctr_mecan = 
     ctr_mecanique.id_ctr_mecan
     LEFT JOIN sigma02.eds eds_chantier ON pointage_materiel.id_chantier = 
     eds_chantier.id_eds
    LEFT JOIN sigma02.eds eds_secteur ON eds_chantier.parent_id_eds = 
    eds_secteur.id_eds
    LEFT JOIN sigma02.eds eds_agence ON eds_secteur.parent_id_eds = 
     eds_agence.id_eds
    LEFT JOIN sigma02.eds eds_societe ON eds_agence.parent_id_eds = 
    eds_societe.id_eds
    LEFT JOIN sigma02.eds on ctr_mecanique.id_societe=eds.id_eds
     LEFT JOIN sigma02.soc_cop on eds.id_eds = soc_cop.eds
       where edsm.statut = true AND pointage_materiel.statut_pointage != 'PR'
     GROUP BY
     pointage_materiel.statut_pointage,
     pointage_materiel.date_periode,
     eds_societe.id_eds,eds_societe.lib_eds,
      eds_societe.code_eds, edsm.id_edsm,
     eds_agence.code_eds,
     edsm.code_edsm,
     edsm.lib_edsm,
     eds_chantier.id_eds,
     eds_chantier.code_eds,
     eds_chantier.lib_eds,
     ctr_mecanique.code_ctr_mecan
Those are the index used to try to improve the request, I tried to use 1 index for each table.
````Index
```` EDSM INDEX
     CREATE INDEX edsm_optim_id ON sigma02.edsm USING btree (id_edsm);
     CREATE INDEX edsm_optim_stat ON sigma02.edsm USING btree (statut);
````EDSM INDEX
     CREATE INDEX eds_optim_stat ON sigma02.eds USING btree(statut);
     CREATE INDEX eds_optmi_id ON sigma02.eds USING btree (id_eds);
     CREATE INDEX ids_optim_idtyp ON sigma02.eds USING btree(id_type_eds 
     COLLATE pg_catalog."default");
````CHANTIER INDEX
     CREATE INDEX chant_optim_idctr ON sigma02.chantier USING btree 
     (id_ctr_mecan);
     CREATE INDEX chant_optim_ideds ON sigma02.chantier USING btree (id_eds)
````CTR INDEX
    CREATE INDEX ctrm_optim_id ON sigma02.ctr_mecanique USING btree 
     (id_ctr_mecan);
     CREATE INDEX ctrm_optim_idsoc ON sigma02.ctr_mecanique USING btree 
     (id_societe);
````POINTAGE INDEX
     CREATE INDEX point_optim_id ON sigma02.pointage USING btree 
     (id_pointage);
    CREATE INDEX point_optim_idchant ON sigma02.pointage USING btree 
      (id_chantier);
      CREATE INDEX point_optim_idparc ON sigma02.pointage USING btree 
     (id_parc);
      CREATE INDEX point_optim_stat ON sigma02.pointage USING btree 
      (statut_pointage 
     COLLATE pg_catalog."default");

результат объясненияанализ пока не отображается, это займет очень очень много времени, как я могу его оптимизировать? Есть идеи? Помогите!!! спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...