I have created views for my project now I want to optimize them for the speed purpose. How can I identify that the view can be optimize? Is index useful for this.
SELECT DISTINCT
ent.ID_Entreprise,
ct.Siret,
ct.Scont,
ct.Cont,
ct.Souscont,
ct.Entappcr,
ct.Cb,
ct.Sptf,
ct.Socuti,
ct.EntiteTPG,
ct.Datefcb,
ct.Dtfineffcb,
ct.Stacb,
ct.Libstacb,
ct.Perap,
ct.Libperap,
ct.Deremis,
ct.Derregl,
ct.typepdt,
ct.Libtypepdt,
ct.Libpdt,
ct.Libcb,
ct.CodeICX,
ct.AppLeader,
(CASE ct.typepdt
WHEN 'S' THEN '1'
WHEN 'P' THEN '2'
WHEN 'R' THEN '3'
WHEN 'E' THEN '3'
WHEN 'I' THEN '4'
ELSE '5' END) AS orderParam,
ct.Reg,
ct.ent_opt_set,
'' AS CdGraReg,
'' AS CaisseSS,
'' AS CentreSS,
ct.affilSalEnabled,
ct.AtOperationnel,
ct.Formule,
ct.FormuleSocle,
ct.Srs,
ct.Cntcb_actif,
ct.Libstacb_vision_C,
ct.DATPA,
ct.DATENVOI,
ct.DATREGUL,
ct.UC,
ct.Art39,
ct.Dateff,
ct.Cnt_actif,
ent.Raisoc,
ct.mensualisation,
ct.repartition,
ct.optFin,
ct.Date_hors_infocentre,
ent.visionC
FROM dbo.VW_Entreprise AS ent INNER JOIN dbo.VW_Contrats AS ct ON ent.Siret = ct.Siret AND ct.Entappcr = ent.entApp
I am using two views VW_Entreprise and VW_Contrats
For this JOIN
:
dbo.VW_Entreprise AS ent
INNER JOIN dbo.VW_Contrats AS ct ON ent.Siret = ct.Siret AND ct.Entappcr = ent.entApp
You want the following indexes:
VW_Entreprise(Siret, entApp)
VW_Contrats(Siret, Entappcr)
If these index do not yet exist, please create them. It is hard to provide more suggestions without knowing more about your data structure and the definition of underlying views. A few hints though:
SELECT DISTINCT
implies more work for your RDBMS, since it needs to check for duplicates (and you are returning a large number of columns); make sure that you really need it before using it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.