Created
November 24, 2014 16:12
-
-
Save akitaonrails/333905e6c66efc740072 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nested Loop (cost=689.72..799.51 rows=1 width=156) (actual time=150.800..17594.254 rows=173 loops=1) | |
-> Nested Loop (cost=689.69..797.47 rows=1 width=160) (actual time=150.762..17591.724 rows=173 loops=1) | |
Join Filter: (quiz_report_questions.question_id = quiz_user_answer_results.question_id) | |
-> Nested Loop (cost=0.17..101.94 rows=1 width=150) (actual time=0.109..3.718 rows=173 loops=1) | |
-> Nested Loop (cost=0.09..29.95 rows=8 width=13) (actual time=0.059..0.964 rows=180 loops=1) | |
-> Seq Scan on quiz_exercise_lists (cost=0.00..2.56 rows=5 width=8) (actual time=0.011..0.053 rows=5 loops=1) | |
Filter: (quiz_id = 1) | |
Rows Removed by Filter: 180 | |
-> Index Scan using index_quiz_user_answers_on_user_id_and_quiz_exercise_list_id on quiz_user_answers (cost=0.09..5.47 rows=2 width=13) (actual time=0.025..0.134 rows=36 loops=5) | |
Index Cond: ((user_id = 1) AND (quiz_exercise_list_id = quiz_exercise_lists.id)) | |
-> Index Scan using index_quiz_report_questions_on_question_id on quiz_report_questions (cost=0.08..9.00 rows=1 width=137) (actual time=0.010..0.012 rows=1 loops=180) | |
Index Cond: (question_id = quiz_user_answers.question_id) | |
Filter: (quiz_id = 1) | |
Rows Removed by Filter: 1 | |
-> Bitmap Heap Scan on quiz_user_answer_results (cost=689.52..695.53 rows=1 width=26) (actual time=101.637..101.657 rows=1 loops=173) | |
Recheck Cond: ((user_id = 1) AND (question_id = quiz_user_answers.question_id)) | |
Filter: (quiz_id = 1) | |
Rows Removed by Filter: 15 | |
-> BitmapAnd (cost=689.52..689.52 rows=3 width=0) (actual time=101.621..101.621 rows=0 loops=173) | |
-> Bitmap Index Scan on index_quiz_user_answer_results_on_user_id (cost=0.00..56.41 rows=4200 width=0) (actual time=0.286..0.286 rows=2880 loops=173) | |
Index Cond: (user_id = 1) | |
-> Bitmap Index Scan on index_quiz_user_answer_results_on_question_id (cost=0.00..633.05 rows=53019 width=0) (actual time=100.712..100.712 rows=199294 loops=173) | |
Index Cond: (question_id = quiz_user_answers.question_id) | |
-> Index Only Scan using quizzes_pkey on quizzes (cost=0.03..2.03 rows=1 width=4) (actual time=0.008..0.009 rows=1 loops=173) | |
Index Cond: (id = 1) | |
Heap Fetches: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
quiz_user_answer_results.*, | |
quiz_user_answers.answer_review, | |
quiz_report_questions.discipline_plain, | |
quiz_report_questions.answer_correct_count, | |
quiz_report_questions.topic_name, | |
quiz_report_questions.discipline_and_topic_scopes | |
FROM | |
"quiz_user_answer_results" | |
INNER JOIN | |
"quiz_report_questions" | |
ON | |
"quiz_report_questions"."question_id" = "quiz_user_answer_results"."question_id" | |
AND | |
quiz_report_questions.quiz_id = quiz_user_answer_results.quiz_id | |
INNER JOIN | |
"quizzes" | |
ON | |
"quizzes"."id" = "quiz_user_answer_results"."quiz_id" | |
INNER JOIN | |
"quiz_exercise_lists" | |
ON | |
"quiz_exercise_lists"."quiz_id" = "quizzes"."id" | |
INNER JOIN | |
"quiz_user_answers" | |
ON | |
"quiz_user_answers"."quiz_exercise_list_id" = "quiz_exercise_lists"."id" | |
AND | |
quiz_user_answers.question_id = quiz_user_answer_results.question_id | |
AND | |
quiz_user_answers.user_id = quiz_user_answer_results.user_id | |
WHERE | |
"quiz_user_answer_results"."user_id" = ? | |
AND | |
"quiz_user_answer_results"."quiz_id" = ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.answers(quiz_user_progress) | |
select([ | |
'quiz_user_answer_results.*', | |
'quiz_user_answers.answer_review', | |
'quiz_report_questions.discipline_plain', | |
'quiz_report_questions.answer_correct_count', | |
'quiz_report_questions.topic_name', | |
'quiz_report_questions.discipline_and_topic_scopes' | |
]).joins(:quiz_report_question, :quiz_user_answers) | |
.where( | |
user_id: quiz_user_progress.user_id, | |
quiz_user_answer_results: { quiz_id: quiz_user_progress.quiz_id } | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment