Why does putting a WHERE clause outside view have terrible performance

前端 未结 5 1874
梦如初夏
梦如初夏 2021-02-12 21:09

Let\'s say you have a view:

CREATE VIEW dbo.v_SomeJoinedTables AS
SELECT
    a.date,
    a.Col1,
    b.Col2,
    DENSE_RANK() 
      OVER(PARTITION BY a.date, a.         


        
5条回答
  •  情深已故
    2021-02-12 21:21

    Technically, you're not comparing between the same SQL statements. Your view indicates that it returns a.date, a.Col1, b.Col2, plus your DENSE_RANK() function. In your query without the view, you return all columns.

    At first, you may think that returning all the columns would be worse. But it's difficult to determine which would be better without knowing what the table structure, including indexes, looks like.

    Have you compared the query plans for each statement?

提交回复
热议问题