Explore core concepts of query optimization and performance tuning in databases, covering indexing, execution plans, and best practices for efficient queries. This quiz is designed to help you assess your proficiency in enhancing data retrieval speed and resource utilization through advanced optimization techniques.
Which of the following best describes why adding an index to a column frequently used in WHERE clauses improves query performance?
Explanation: Indexes provide a structured way for the database to quickly locate rows matching query criteria, leading to faster data retrieval and optimized performance. Backups are unrelated to indexes, making Option B incorrect. Compression (Option C) is not the main purpose of indexes and does not address query optimization directly. Option D is incorrect because indexes do not rewrite or modify user queries.
When analyzing a query's execution plan, which operator typically indicates a performance concern if found repeatedly with large datasets?
Explanation: A full table scan indicates the database is reading every row to find results, which can be slow with large tables and is generally less efficient. An inner join is a standard operation and not necessarily problematic. Group by is used for aggregation but does not inherently indicate a performance issue. Column aliases merely rename output columns and do not affect execution speed.
Given a table with a million rows, which of the following queries is generally more efficient when searching for a specific value in an indexed column?
Explanation: Querying for a specific value in an indexed column allows the index to be used for fast retrieval. The second option checks for non-null values, which can return many rows, reducing efficiency. Ordering results (Option C) might require sorting, which does not leverage index lookups for a single value. Selecting the entire column without filtering (Option D) retrieves unnecessary data without taking advantage of the index.
Why is normalizing queries by avoiding redundant expressions and unnecessary calculations important in query optimization?
Explanation: Normalizing queries by minimizing redundancy leads to simpler execution plans and efficient resource use, thus improving query performance. Removing duplicate rows (Option B) is not the function of normalization. Option C is incorrect because locks may still happen for other reasons. Primary keys (Option D) may not always be used, so normalization does not enforce their use solely.
A query on a large dataset is running slowly due to frequent disk reads. Which change is most likely to improve its performance?
Explanation: Adding indexes on filtered and joined columns allows the database to locate relevant data faster, reducing disk input and output. Selecting more columns (Option B) actually increases disk reads and can slow performance. Disabling caches (Option C) removes a performance benefit. Replacing the query with DELETE (Option D) changes the operation entirely and is inappropriate for simply speeding up reads.