Write a query to fetch the top 3 highest salaries of employees as per department, and explain how you would optimize it for performance.
Use the employees and departments tables. Return only employees with non-null salaries and matching departments.
department_id, department_name, employee_id, employee_name, salary, and salary_rank.employee_id first.| Column | Type | Description |
|---|---|---|
| department_idPK | INT | Unique department identifier |
| department_name | VARCHAR(100) | Department name |
| Column | Type | Description |
|---|---|---|
| employee_idPK | INT | Unique employee identifier |
| employee_name | VARCHAR(100) | Employee's full name |
| department_id | INT | Employee department reference |
| salary | NUMERIC(12,2) | Annual employee salary |