A data analyst is tasked with analyzing customer purchase patterns from a SalesHistory table containing over 500 million records. The analysis only needs to consider transactions from the most recent quarter for the 'Electronics' category. The initial query, which includes multiple joins and complex aggregate functions, is running extremely slowly and timing out.
Which of the following is the most effective initial step to optimize the query's performance?
Rewrite the query to use parameterized values for the date range and product category.
Add a composite index to the TransactionDate and ProductCategory columns of the SalesHistory table.
Request that the database administrator increase the memory allocated to the database server.
First, filter the SalesHistory table to create a smaller subset of only the necessary records, and then apply the complex joins and aggregations to this subset.
The correct answer is to first filter the large table to create a smaller subset of data before applying complex operations. When dealing with very large tables, performing joins and aggregations across all records is resource-intensive and slow. By filtering the 500 million records down to only those in the 'Electronics' category from the last quarter, the subsequent, more complex parts of the query (joins and aggregations) have a much smaller dataset to process, which significantly improves performance. This can be accomplished by using a WHERE clause effectively, or by creating a temporary table or a Common Table Expression (CTE) to hold this filtered subset.
Adding a composite index is a valid optimization technique and would speed up the process of filtering the records. However, the primary bottleneck in this scenario is the performance of the complex joins and aggregations on a massive dataset. Reducing the size of the data fed into those operations by creating a subset is the most direct and impactful optimization.
Requesting more server memory is an infrastructure change, not a query optimization technique that the analyst would perform. Query logic should be optimized before resorting to hardware changes.
Parameterization is an optimization technique used to allow the database to reuse query execution plans for queries that are run frequently with different values, and it helps prevent SQL injection. It does not speed up the execution of a single, long-running, ad-hoc analytical query.
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.
How does filtering data improve query performance?
Open an interactive chat with Bash
What is a Common Table Expression (CTE) and how is it used for query optimization?
Open an interactive chat with Bash
What is a composite index and why wasn't it the best solution in this scenario?
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 .