Skip to content

Commit

Permalink
Merge pull request #957 from openedx/cag/course-key-indexes
Browse files Browse the repository at this point in the history
perf(sql): use org and course_key filters to use primary key indexes
  • Loading branch information
Ian2012 committed Sep 30, 2024
2 parents 5877990 + 0dc8aa5 commit 0a00530
Show file tree
Hide file tree
Showing 32 changed files with 30 additions and 559 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ with
recent_activity as (
select course_key, COUNT(DISTINCT actor_id) as active_last_7_days
from {{ ASPECTS_XAPI_DATABASE }}.navigation_events
where emission_time >= NOW() - INTERVAL 7 DAY
where
emission_time >= NOW() - INTERVAL 7 DAY
{% include 'openedx-assets/queries/common_filters.sql' %}
group by course_key
)

select fss.*, COALESCE(ra.active_last_7_days, 0) as active_within_last_7_days
from {{ DBT_PROFILE_TARGET_DATABASE }}.fact_student_status fss
left join recent_activity ra on fss.course_key = ra.course_key
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ with
select org, course_key, learners.actor_id as actor_id
from {{ DBT_PROFILE_TARGET_DATABASE }}.fact_student_status learners
join page_visits using (org, course_key, actor_id)
where approving_state = 'failed' and enrollment_status = 'registered'
where
approving_state = 'failed' and enrollment_status = 'registered'
{% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
) as at_risk_learners using (org, course_key, actor_id)
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ where
approving_state = 'failed'
and enrollment_status = 'registered'
and page_visits.last_visited < subtractDays(now(), 7)
{% include 'openedx-assets/queries/common_filters.sql' %}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ left join
{{ ASPECTS_EVENT_SINK_DATABASE }}.course_names cn
on fes.org = cn.org
and fes.course_key = cn.course_key
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
) as at_risk_learners using (org, course_key, actor_id)
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
) as at_risk_learners using (org, course_key, actor_id)
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{% include 'openedx-assets/queries/fact_problem_engagement.sql' %}
with
fact_problem_engagement as (
{% include 'openedx-assets/queries/fact_problem_engagement.sql' %}
)
select fact_problem_engagement.*
from fact_problem_engagement pe
join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
) as at_risk_learners using (org, course_key, actor_id)
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
) as at_risk_learners using (org, course_key, actor_id)
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
) as at_risk_learners using (org, course_key, actor_id)
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ join
(
{% include 'openedx-assets/queries/at_risk_learner_filter.sql' %}
) as at_risk_learners using (org, course_key, actor_id)
where 1 = 1 {% include 'openedx-assets/queries/common_filters.sql' %}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0a00530

Please sign in to comment.