SQL Tuning: Function Calls
Description:
Your manager has given you a task to create a report to measure the impact of the next company-wide salary increase. The rules for the salary increase are encapsulated in the function pctIncrease
, which takes a department_id
as a parameter and returns the percent increase as a value between 0 and 1.
You've managed to create a query that would produce the desired results, but it is currently very slow and doesn't finish in the required time window.
Your objective in this kata is to optimize this query. The success criteria is to manage to run the query within the allowed kata solution time window (12 seconds for SQL katas).
The provided initial solution produces the correct result, but it does not run within the allowed time window.
Data model
Table: Employees
----------------
employee_id INT / PK
first_name TEXT
last_name TEXT
salary DECIMAL
department_id INT / FK
Table: Departments
------------------
department_id INT / PK
department_name TEXT
pctIncrease function signature:
pctIncrease(dept_id INT) RETURNS decimal
Similar Kata:
Stats:
Created | Nov 6, 2016 |
Published | Nov 6, 2016 |
Warriors Trained | 5696 |
Total Skips | 2377 |
Total Code Submissions | 6208 |
Total Times Completed | 1915 |
SQL Completions | 1915 |
Total Stars | 68 |
% of votes with a positive feedback rating | 93% of 268 |
Total "Very Satisfied" Votes | 236 |
Total "Somewhat Satisfied" Votes | 27 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 12 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |