5 kyu

SQL Tuning: Function Calls

1,915danicat

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

SQL
Performance
Refactoring

More By Author:

Check out these other kata created by danicat

Stats:

CreatedNov 6, 2016
PublishedNov 6, 2016
Warriors Trained5696
Total Skips2377
Total Code Submissions6208
Total Times Completed1915
SQL Completions1915
Total Stars68
% of votes with a positive feedback rating93% of 268
Total "Very Satisfied" Votes236
Total "Somewhat Satisfied" Votes27
Total "Not Satisfied" Votes5
Total Rank Assessments12
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • danicat Avatar
  • matt c Avatar
  • smile67 Avatar
Ad