Changes between Version 2 and Version 3 of QueryOptimization


Ignore:
Timestamp:
07/01/26 18:12:45 (4 days ago)
Author:
231082
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • QueryOptimization

    v2 v3  
    112112==== Before Optimization ====
    113113
    114 - '''Execution Time''': ~923 ms
    115 
    116 - '''Buffers''': shared hit=8369 read=40525, temp read=39620 written=39808
     114* '''Execution Time''': ~923 ms
     115* '''Buffers''': shared hit=8369 read=40525, temp read=39620 written=39808
    117116
    118117==== Problem Analysis ====
     
    128127Replaced the view with a function that first identifies the course edition and then filters to only students who have passed that course.
    129128
    130 - '''After Optimization''': ~940 ms – a slight improvement due to reduced data volume.
     129{{{
     130#!sql
     131CREATE OR REPLACE FUNCTION fn_teaching_assistant_eligibility(p_edition_id INTEGER)
     132    RETURNS TABLE (...) LANGUAGE plpgsql STABLE AS $$
     133DECLARE
     134    var_course_code TEXT;
     135    var_academic_year SMALLINT;
     136    var_semester SMALLINT;
     137BEGIN
     138    SELECT ed.course_code, ed.academic_year, ed.semester
     139    INTO var_course_code, var_academic_year, var_semester
     140    FROM Course_Edition ed
     141    WHERE ed.id = p_edition_id;
     142   
     143    -- Only process students who passed this specific course
     144    ...
     145}}}
     146* '''After Optimization''': ~383 ms – a '''significant improvement''' (approximately 2.4× faster than the view).
    131147
    132148== Optimization Summary ==
    133149
    134150|| '''View''' || '''Initial Time''' || '''Final Time''' || '''Method''' ||
    135 || v_student_current_semester || 23.459 ms || 23.459 ms || Existing indexes sufficient ||
    136 || v_student_upcoming_deadlines || 35.945 ms || 35.945 ms || Existing indexes sufficient ||
    137 || v_student_transcript || 0.426 ms || 0.426 ms || Existing indexes sufficient ||
    138 || v_course_announcements || 8.085 ms || 8.085 ms || Existing indexes sufficient ||
    139 || v_exercise_grading_queue || 122.986 ms || 122.986 ms || Acceptable performance ||
    140 || v_course_prerequisite_chain || 0.563 ms || 0.563 ms || Existing indexes sufficient ||
    141 || v_student_registration_state || 2268 ms || ~370 ms || Function replacement (6×) ||
    142 || v_teaching_assistant_eligibility || 923 ms || ~940 ms || Function replacement ||
     151|| `v_student_current_semester`        || 23.459 ms  || 23.459 ms || Existing indexes sufficient ||
     152|| `v_student_upcoming_deadlines`      || 35.945 ms  || 35.945 ms || Existing indexes sufficient ||
     153|| `v_student_transcript`              || 0.426 ms   || 0.426 ms  || Existing indexes sufficient ||
     154|| `v_course_announcements`            || 8.085 ms   || 8.085 ms  || Existing indexes sufficient ||
     155|| `v_exercise_grading_queue`          || 122.986 ms || 122.986 ms || Acceptable performance ||
     156|| `v_course_prerequisite_chain`       || 0.563 ms   || 0.563 ms  || Existing indexes sufficient ||
     157|| `v_student_registration_state`      || 2268 ms    || ~370 ms    || Function replacement (6×) ||
     158|| `v_teaching_assistant_eligibility`  || 923 ms     || ~383 ms    || Function replacement (2.4×) ||
    143159
    144160== Lessons Learned ==