Unlock the full performance potential of MySQL by mastering essential advanced SQL features and strategies for high-efficiency query optimization, indexing, and analytics.
What does the 'ALL' value in the 'type' column of MySQL's EXPLAIN output indicate?
Explanation: 'ALL' in the 'type' column means MySQL scans every row in the table, which is slow for large datasets. Using an index ('index') is better, and 'const' means only one row is accessed. Query execution is not aborted by 'ALL'; it is just less efficient.
Which of the following best improves the performance of a query filtering by 'user_id' and 'create_time' and ordering by 'amount'?
Explanation: A composite index on the relevant columns helps MySQL access matching rows efficiently. Removing all indexes or indexing only 'amount' would not help with filtering by 'user_id' and 'create_time', and changing SELECT to UPDATE changes the statement meaning.
Which field in EXPLAIN output shows the actual index MySQL plans to use?
Explanation: The 'key' field specifies the index MySQL uses for the query. 'type' describes the access method, 'rows' estimates how many rows will be scanned, and 'Extra' provides additional execution details.
What is the primary purpose of running ANALYZE TABLE in MySQL?
Explanation: ANALYZE TABLE refreshes internal statistics, helping MySQL's optimizer choose better query plans. It does not remove duplicates, delete indexes, or lock tables for backups.
What is the main benefit of a covering index?
Explanation: A covering index contains all columns needed by the query, avoiding extra reads from the main table. It does not speed up INSERT operations or enforce uniqueness unless declared as unique.
What is a common drawback of creating too many indexes on a table?
Explanation: Having too many indexes slows down write operations because all indexes must be maintained. Indexes do not encrypt data, always shrink table size, or make all SELECT queries faster.
Which limitation is associated with prefix indexes on long text columns?
Explanation: Prefix indexes speed up searching in large text columns but cannot be used for ORDER BY or GROUP BY. They do not guarantee uniqueness or work for every data type, and only part of the column is indexed.
Which SQL feature allows calculations like rankings and cumulative sums across rows without collapsing them?
Explanation: Window functions perform calculations across multiple rows while preserving individual records, supporting analytics like rankings. Stored procedures, partitioned tables, or foreign keys do not serve this purpose.
What is a major benefit of using Common Table Expressions (CTEs) in SQL queries?
Explanation: CTEs break queries into manageable, named parts, making complex queries clearer. They do not auto-create indexes, replace every subquery, or enforce referential integrity.
What does Index Condition Pushdown (ICP) improve in MySQL?
Explanation: ICP enables MySQL to filter rows within an index scan, minimizing full row access and boosting performance. It does not update primary keys, auto-sort, or require unique indexes.