Is querying over a view slower than executing SQL directly?

后端 未结 2 1950
孤城傲影
孤城傲影 2021-01-17 13:11

Scenario:

I have 3 tables needing to be joined together, a where clause to limit the result set, and only a few columns from each table being selected. Simple. Howev

相关标签:
2条回答
  • 2021-01-17 13:45

    In Oracle, the performance is the same. A view is really a named sql statement. But fancier.

    When you start nesting views, and joining views with other table or views, things get complicated real quick. If Oracle can't push your filters down the view to the table, it often has to materialize (build a temp table of) parts of the query, and this is when you get the bad performance.

    0 讨论(0)
  • 2021-01-17 13:54

    From MSDN: 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.

    There should not be any different performance. Views helps you organize, not any performance enhancement. Unless you are using indexed views.

    Only the definition of a nonindexed view is stored, not the rows of the view. The query optimizer incorporates the logic from the view definition into the execution plan it builds for the SQL statement that references the nonindexed view.

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