70-465 · Question #73
You need to recommend a solution to minimize the amount of time it takes to execute USP_1. With what should you recommend replacing Table1?
The correct answer is A. A view. To minimize execution time of a stored procedure that references a table, replacing the table with a view allows the query optimizer to inline the view definition and optimize the full query plan without materializing intermediate results.
Question
Options
- AA view
- BA temporary table
- CA table variable
- DA function
How the community answered
(33 responses)- A55% (18)
- B24% (8)
- C6% (2)
- D15% (5)
Why each option
To minimize execution time of a stored procedure that references a table, replacing the table with a view allows the query optimizer to inline the view definition and optimize the full query plan without materializing intermediate results.
A view is a named query definition stored in the database that the SQL Server query optimizer can inline directly into the calling query, enabling full optimization across the entire execution plan. Unlike temporary tables or table variables, a view does not require materializing an intermediate result set, which reduces I/O and overhead. This allows USP_1 to benefit from statistics, indexes on the underlying base tables, and optimal join ordering determined by the optimizer.
A temporary table requires physically writing rows to tempdb and materializing the result set before the outer query can use it, which adds I/O overhead and prevents the optimizer from optimizing across the boundary.
A table variable also materializes an intermediate result set and has limited statistics (only a single-row estimate), which can lead to poor cardinality estimates and suboptimal execution plans, increasing rather than minimizing execution time.
A scalar or multi-statement table-valued function introduces per-row execution overhead and prevents the optimizer from pushing predicates inside the function body, typically degrading rather than improving performance.
Concept tested: Optimizing stored procedure performance using views
Source: https://learn.microsoft.com/en-us/sql/relational-databases/views/views?view=sql-server-ver16
Topics
Community Discussion
No community discussion yet for this question.