title: How does this query perform in the query optimizer?
body: <p>Solving this question <a href="https://leetcode.com/problems/nth-highest-salary/" rel="nofollow noreferrer">https://leetcode.com/problems/nth-highest-salary/</a> and found this solution (but no description of what/how this query performs..)</p>
  
  <pre><code>CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
  BEGIN
  SET N = N - 1;
    RETURN (
        # Write your MySQL query statement below.
        select distinct(salary) from employee order by salary desc LIMIT 1 OFFSET N
    );
  END
  </code></pre>
  
  <p>What does <code>SET N = N - 1;</code> mean and why does deleting <code>LIMIT 1</code> slows down performance?
  Is there a better way of writing this? What about <code>row_number()</code> or <code>rank()</code>?</p>