A sales dashboard runs the same SQL statement dozens of times every minute, only changing the value in the WHERE clause:
SELECT order_id, total_amount
FROM fact_sales
WHERE salesperson_id = 1043;
Performance counters show a spike in SQL Compilations/sec and CPU time consumed by query compilation. Without altering the business logic or adding new indexes, which change would most directly cut the compilation overhead and improve reuse of the execution plan?
Increase the server's cost threshold for parallelism to allow more parallel workers.
Create a nonclustered index on the total_amount column to speed up look-ups.
Convert the statement to a prepared, parameterized query and pass the salesperson ID as a bound parameter.
Add the query hint OPTION (RECOMPILE) so that the optimizer builds a fresh plan each time.
Compilation overhead occurs when the database engine must parse and optimize a text string that appears to be a brand-new query on every call. When the query text stays identical between executions, the optimizer can cache and reuse the plan. Rewriting the statement as a parameterized (prepared) query-for example WHERE salesperson_id = @SalesId-keeps the text constant while allowing different values to be supplied at run time. The database therefore reuses the existing cached plan, eliminating most of the repeated compile cost. Adding indexes or changing parallelism settings may help execution performance, but they do not address the wasted CPU cycles spent generating new plans. Forcing OPTION (RECOMPILE) actually increases compilation work because it discards the cache on every run.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a parameterized query?
Open an interactive chat with Bash
Why does SQL Compilation/sec spike with non-parameterized queries?
Open an interactive chat with Bash
What is query caching and how does it improve performance?
Open an interactive chat with Bash
CompTIA Data+ DA0-002 (V2)
Data Acquisition and Preparation
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .