简体   繁体   English

使用视图优化查询性能

[英]Optimisation of the performance of the query using views

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 从dbo.VW_Entreprise AS ent内部联接dbo.VW_Contrats AS ct ON ent.Siret = ct.Siret和ct.Entappcr = ent.entApp

I am using two views VW_Entreprise and VW_Contrats 我正在使用两个视图VW_Entreprise和VW_Contrats

For this JOIN : 对于此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); SELECT DISTINCT意味着RDBMS需要做更多的工作,因为它需要检查重复项(并且您将返回大量的列)。 make sure that you really need it before using it 使用前请确保您确实需要它
  • Querying views means that, under the hood, your RDBMS will somehow need to run the queries that define the views; 查询视图意味着,在后台,您的RDBMS将需要以某种方式运行定义视图的查询。 it is sometimes more efficient to query directly the underlying tables (but once again, that cannot be told for sure without seeing the actual definition of the views) 有时直接查询基础表会更有效(但再次重申,如果没有看到视图的实际定义就无法确定)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM