Write a SQL query to find the second-highest salary from an employee table, and then optimize it for a dataset containing millions of rows.
Use the employees table. Treat the second-highest value as the second-highest distinct non-null salary, and ensure duplicate salaries do not affect the result. Address the indexing consideration for a large PostgreSQL table.
second_highest_salary.| Column | Type | Description |
|---|---|---|
| employee_idPK | INTEGER | Unique employee identifier |
| employee_name | VARCHAR(100) | Employee's full name |
| salary | NUMERIC(12,2) | Employee annual salary |
| department | VARCHAR(80) | Employee department |