Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

TC API - Pratice Problems API - Query Improvement #380

Merged
merged 2 commits into from
Oct 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 10 additions & 55 deletions queries/get_practice_problems
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SELECT
SKIP @firstRowIndex@
FIRST @pageSize@
*
*
FROM table(MULTISET(
SELECT
p.problem_id
, c.component_id
, c.component_id
, ro.room_id
, rc.round_id
, rc.division_id
Expand All @@ -16,63 +16,18 @@ SELECT
WHEN (p.problem_type_id = 1 AND p.proposed_difficulty_id = 3) THEN 'Hard'::nvarchar(50)
END AS difficulty
, rc.points
, NVL(CASE WHEN EXISTS (
SELECT 1
FROM component_state cs
WHERE cs.status_id < 120
AND cs.component_id = c.component_id
AND cs.coder_id = @userId@
UNION ALL
SELECT 1
FROM practice_component_state pcs
WHERE pcs.status_id < 120
AND pcs.component_id = c.component_id
AND pcs.coder_id = @userId@
) THEN 'New'::nvarchar(50)
WHEN EXISTS (
SELECT 1
FROM component_state cs
WHERE cs.status_id = 150
AND cs.component_id = c.component_id
AND cs.coder_id = @userId@
UNION ALL
SELECT 1
FROM practice_component_state pcs
WHERE pcs.status_id = 150
AND pcs.component_id = c.component_id
AND pcs.coder_id = @userId@
) THEN 'Solved'::nvarchar(50)
WHEN EXISTS (
SELECT 1
FROM component_state cs
WHERE cs.status_id >= 120
AND cs.component_id = c.component_id
AND cs.status_id != 150
AND cs.coder_id = @userId@
UNION ALL
SELECT 1
FROM practice_component_state pcs
WHERE pcs.status_id >= 120
AND pcs.component_id = c.component_id
AND pcs.status_id != 150
AND pcs.coder_id = @userId@
) THEN 'Viewed'::nvarchar(50)
END, 'New') AS status
, NVL((
SELECT
points
FROM practice_component_state pcs
WHERE pcs.round_id = rc.round_id
AND pcs.component_id = c.component_id
AND pcs.coder_id = @userId@
), 0) AS my_points
, NVL( CASE WHEN pcs.status_id < 120 THEN 'New'::nvarchar(50)
WHEN pcs.status_id = 150 THEN 'Solved'::nvarchar(50)
WHEN pcs.status_id >= 120 AND pcs.status_id != 150 THEN 'Viewed'::nvarchar(50)
END, 'New') AS status
, NVL(pcs.points, 0) AS my_points
FROM problem p
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
INNER JOIN component c ON c.problem_id = p.problem_id
INNER JOIN round_component rc ON rc.component_id = c.component_id
INNER JOIN round r ON r.round_id = rc.round_id AND r.status = 'A'
INNER JOIN round r ON r.round_id = rc.round_id AND r.status = 'A' AND r.round_type_id = 3
INNER JOIN room ro ON ro.round_id = rc.round_id AND ro.room_type_id = 3 -- practice room
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
WHERE p.status_id = 90
LEFT JOIN practice_component_state pcs ON pcs.round_id = rc.round_id AND pcs.component_id = c.component_id AND pcs.coder_id = @userId@
)) srp
WHERE 1=1
ORDER BY @sortColumn@ @sortOrder@
61 changes: 8 additions & 53 deletions queries/get_practice_problems_count
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,17 @@ SELECT
WHEN (p.problem_type_id = 1 AND p.proposed_difficulty_id = 3) THEN 'Hard'::nvarchar(50)
END AS difficulty
, rc.points
, NVL(CASE WHEN EXISTS (
SELECT 1
FROM component_state cs
WHERE cs.status_id < 120
AND cs.component_id = c.component_id
AND cs.coder_id = @userId@
UNION ALL
SELECT 1
FROM practice_component_state pcs
WHERE pcs.status_id < 120
AND pcs.component_id = c.component_id
AND pcs.coder_id = @userId@
) THEN 'New'::nvarchar(50)
WHEN EXISTS (
SELECT 1
FROM component_state cs
WHERE cs.status_id = 150
AND cs.component_id = c.component_id
AND cs.coder_id = @userId@
UNION ALL
SELECT 1
FROM practice_component_state pcs
WHERE pcs.status_id = 150
AND pcs.component_id = c.component_id
AND pcs.coder_id = @userId@
) THEN 'Solved'::nvarchar(50)
WHEN EXISTS (
SELECT 1
FROM component_state cs
WHERE cs.status_id >= 120
AND cs.component_id = c.component_id
AND cs.status_id != 150
AND cs.coder_id = @userId@
UNION ALL
SELECT 1
FROM practice_component_state pcs
WHERE pcs.status_id >= 120
AND pcs.component_id = c.component_id
AND pcs.status_id != 150
AND pcs.coder_id = @userId@
) THEN 'Viewed'::nvarchar(50)
END, 'New') AS status
, NVL((
SELECT
points
FROM practice_component_state pcs
WHERE pcs.round_id = rc.round_id
AND pcs.component_id = c.component_id
AND pcs.coder_id = @userId@
), 0) AS my_points
, NVL( CASE WHEN pcs.status_id < 120 THEN 'New'::nvarchar(50)
WHEN pcs.status_id = 150 THEN 'Solved'::nvarchar(50)
WHEN pcs.status_id > 120 AND pcs.status_id != 150 THEN 'Viewed'::nvarchar(50)
END, 'New') AS status
, NVL(pcs.points, 0) AS my_points
FROM problem p
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
INNER JOIN component c ON c.problem_id = p.problem_id
INNER JOIN round_component rc ON rc.component_id = c.component_id
INNER JOIN round r ON r.round_id = rc.round_id AND r.status = 'A'
INNER JOIN round r ON r.round_id = rc.round_id AND r.status = 'A' AND r.round_type_id = 3
INNER JOIN room ro ON ro.round_id = rc.round_id AND ro.room_type_id = 3 -- practice room
INNER JOIN problem_type_lu ptl ON ptl.problem_type_id = p.problem_type_id
WHERE p.status_id = 90
LEFT JOIN practice_component_state pcs ON pcs.round_id = rc.round_id AND pcs.component_id = c.component_id AND pcs.coder_id = @userId@
)) srp
WHERE 1=1
22 changes: 11 additions & 11 deletions test/sqls/srmPracticeProblems/informixoltp__insert_test_data
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ INSERT INTO component(component_id, problem_id, result_type_id, method_name, cla
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3002, 2001, 1, 'method_2', 'TestProblem', 2, 1);

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4001, "SRM 4001", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5001, 4001, "Practice 4001", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5001, 4001, "Practice 4001", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5001, 5001, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5001, 3001, 2, 1, 500);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7001, 5001, 132456, 3001, 0, 120, 1);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id, submission_number) VALUES(7002, 5001, 132457, 3001, 0, 110, 1, 001);
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5001, 1, '2014-09-20 00:00:00', '2014-09-21 00:00:00', 'P');

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4002, "SRM 4002", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5002, 4002, "Practice 4002", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5002, 4002, "Practice 4002", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5002, 5002, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5002, 3001, 2, 1, 250);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7003, 5002, 132456, 3001, 200, 150, 1);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7004, 5002, 132457, 3001, 0, 110, 1);
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5002, 1, '2014-09-15 00:00:00', '2014-09-18 00:00:00', 'P');

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4003, "SRM 4003", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5003, 4003, "Practice 4003", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5003, 4003, "Practice 4003", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5003, 5003, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5003, 3002, 2, 1, 400);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7005, 5003, 132456, 3002, 100, 150, 1);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7006, 5003, 132457, 3002, 0, 160, 1);
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5003, 1, '2014-09-25 00:00:00', '2014-09-26 00:00:00', 'P');

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4004, "SRM 4004", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5004, 4004, "Practice 4004", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5004, 4004, "Practice 4004", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5004, 5004, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5004, 3002, 2, 1, 300);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7007, 5004, 132456, 3002, 50, 150, 1);
Expand All @@ -41,7 +41,7 @@ INSERT INTO problem(problem_id, name, status_id, problem_type_id, proposed_diffi
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3003, 2002, 18, 'method_2', 'problem_class2', 1, 1);

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4005, "SRM 4005", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5005, 4005, "Practice 4005", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5005, 4005, "Practice 4005", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5005, 5005, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5005, 3003, 2, 1, 200);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7009, 5005, 132456, 3003, 0, 120, 1);
Expand All @@ -55,15 +55,15 @@ INSERT INTO component(component_id, problem_id, result_type_id, method_name, cla
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3005, 2003, 1, 'method_4', 'TestProblem', 2, 1);

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4006, "SRM 4006", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5006, 4006, "Practice 4006", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5006, 4006, "Practice 4006", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5006, 5006, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5006, 3004, 2, 1, 100);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7011, 5006, 132456, 3004, 80, 150, 1);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id, submission_number) VALUES(7012, 5006, 132457, 3004, 0, 130, 1, 001);
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5006, 1, '2014-09-20 00:00:00', '2014-09-21 00:00:00', 'P');

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4007, "SRM 4007", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5007, 4007, "Practice 4007", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5007, 4007, "Practice 4007", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5007, 5007, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5007, 3005, 2, 1, 450);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7013, 5007, 132456, 3005, 100, 150, 1);
Expand All @@ -79,14 +79,14 @@ INSERT INTO component(component_id, problem_id, result_type_id, method_name, cla

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4008, "SRM 4008", "A", -1);

INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5008, 4008, "Practice 4008", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5008, 4008, "Practice 4008", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5008, 5008, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5008, 3006, 2, 1, 100);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7015, 5008, 132456, 3006, 80, 150, 1);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id, submission_number) VALUES(7016, 5008, 132457, 3006, 0, 130, 1, 001);
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(5008, 1, '2014-09-20 00:00:00', '2014-09-21 00:00:00', 'P');

INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5009, 4008, "Practice 4008", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5009, 4008, "Practice 4008", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5009, 5009, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5009, 3006, 2, 1, 100);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7017, 5009, 132456, 3006, 80, 150, 1);
Expand All @@ -95,7 +95,7 @@ INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VA


INSERT INTO contest (contest_id, name, status, group_id) VALUES (4009, "SRM 4009", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5010, 4009, "Practice 4009", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5010, 4009, "Practice 4009", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5010, 5010, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5010, 3007, 2, 1, 450);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7019, 5010, 132456, 3007, 100, 150, 1);
Expand All @@ -108,7 +108,7 @@ INSERT INTO problem(problem_id, name, status_id, problem_type_id, proposed_diffi
INSERT INTO component(component_id, problem_id, result_type_id, method_name, class_name, component_type_id, status_id) VALUES (3008, 2005, 18, 'method_2', 'problem_class2', 1, 1);

INSERT INTO contest (contest_id, name, status, group_id) VALUES (4010, "SRM 4010", "A", -1);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5011, 4010, "Practice 4010", "A", 2, 0);
INSERT INTO round (round_id, contest_id, name, status, round_type_id, rated_ind) VALUES (5011, 4010, "Practice 4010", "A", 3, 0);
INSERT INTO room(room_id, round_id, name, room_type_id) VALUES(5011, 5011, 'room ', 3);
INSERT INTO round_component(round_id, component_id, difficulty_id, division_id, points) VALUES(5011, 3008, 2, 1, 200);
INSERT INTO practice_component_state(component_state_id, round_id, coder_id, component_id, points, status_id, language_id) VALUES(7020, 5011, 132456, 3008, 0, 110, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"problemType": "Long",
"problemId": 2001,
"componentId": 3001,
"status": "Solved",
"status": "Viewed",
"roundId": 5001,
"roomId": 5001,
"problemName": "Problem 2001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"problemType": "Long",
"problemId": 2001,
"componentId": 3001,
"status": "Solved",
"status": "Viewed",
"roundId": 5001,
"roomId": 5001,
"problemName": "Problem 2001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"problemType": "Long",
"problemId": 2001,
"componentId": 3002,
"status": "Solved",
"status": "Viewed",
"roundId": 5003,
"roomId": 5003,
"problemName": "Problem 2001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"problemType": "Long",
"problemId": 2001,
"componentId": 3001,
"status": "Solved",
"status": "Viewed",
"roundId": 5001,
"roomId": 5001,
"problemName": "Problem 2001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"problemType": "Long",
"problemId": 2001,
"componentId": 3001,
"status": "Solved",
"status": "Viewed",
"roundId": 5001,
"roomId": 5001,
"problemName": "Problem 2001",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"pageIndex": 1,
"pageSize": 10,
"total": 1,
"total": 0,
"data": [
{
"myPoints": 0,
"problemType": "Long",
"problemId": 2001,
"componentId": 3001,
"status": "Viewed",
"roundId": 5001,
"roomId": 5001,
"problemName": "Problem 2001",
"points": 500,
"divisionId": 1
},
{
"myPoints": 0,
"problemType": "Single",
Expand Down