Performance of VIEW vs. SQL statement

后端 未结 3 820
-上瘾入骨i
-上瘾入骨i 2020-12-15 07:22

I have a query that goes something like the following:

select  
from 
where 
and 

        
                      
相关标签:
3条回答
  • 2020-12-15 07:32

    Views aside, aren't the PrimaryKey AND clauses redundant? If the PrimaryKey value is IN a list, wouldn't it not be IN the other list? I think condensing those two clauses into one would boost performance.

    0 讨论(0)
  • 2020-12-15 07:56

    Depending on the database vendor, in general, the execution of a query against a view combines the SQL defined in the View with the Where clause predicates and Order By clause sort expressions appended to the sql that you pass against the View, to come up with a combined complete SQL query to execute. This is then executed as though it had itself been passed to query processsor, so there should be no difference.

    Views are an organizational tool, not a performance enhancement tool.

    From SQL Server View resolution

    When an SQL statement references a nonindexed view, the parser and query optimizer analyze the source of both the SQL statement and the view and then resolve them into a single execution plan. There is not one plan for the SQL statement and a separate plan for the view.

    0 讨论(0)
  • 2020-12-15 07:58

    Regular (non indexes / materialized) Views are just aliases; they don't offer any performance advantages. Selecting from a View generates exactly the same query plan as selecting directly from the table.

    0 讨论(0)
提交回复
热议问题