When joining two large tables in MySQL, why is it important to have indexes on the join columns?
Think about how the database finds matching rows quickly.
Indexes help the database quickly locate matching rows in join columns, making the join operation faster.
Given two tables, employees and departments, with 1000 and 10 rows respectively, and an INNER JOIN on department_id, what is the number of rows returned if only 5 departments have employees?
SELECT e.employee_id, d.department_name FROM employees e INNER JOIN departments d ON e.department_id = d.department_id WHERE d.department_id IN (1,2,3,4,5);
Think about how INNER JOIN and WHERE filter the rows.
The query returns all employees who belong to the 5 specified departments, so the count equals the number of employees in those departments.
Which of the following JOIN queries is syntactically correct and optimized for performance by using explicit JOIN syntax?
Look for the correct JOIN keyword and ON clause.
Option A uses explicit INNER JOIN with ON clause, which is clear and optimized for performance. Option A uses old implicit join syntax. Option A uses USING with a wrong column name. Option A misses ON clause.
You have two large tables joined on a column with no index. Which action will most improve the JOIN query performance?
Think about how the database finds matching rows efficiently.
Adding indexes on join columns allows the database to quickly find matching rows, greatly improving join performance.
A JOIN query between two large tables runs very slowly. The query is:
SELECT a.id, b.name FROM table_a a JOIN table_b b ON a.ref_id = b.id WHERE b.status = 'active';
Which of the following is the most likely cause of the slow performance?
Consider which columns are filtered and joined and their indexes.
Without an index on b.status, the database must scan all rows after the join, slowing the query. Indexing b.status helps filter rows early.