From 03a6879ea6ec47c149bcaf9f57ba288fc03886f7 Mon Sep 17 00:00:00 2001 From: uhensler <urs.hensler@frentix.com> Date: Mon, 25 May 2020 15:02:43 +0200 Subject: [PATCH] OO-4704: Performance tuning to load the data collections --- .../manager/QualityDataCollectionDAO.java | 112 +++++++++--------- .../oracle/alter_15_0_x_to_15_1_0.sql | 4 + .../database/oracle/setupDatabase.sql | 1 + .../postgresql/alter_15_0_x_to_15_1_0.sql | 4 + .../database/postgresql/setupDatabase.sql | 1 + 5 files changed, 66 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/olat/modules/quality/manager/QualityDataCollectionDAO.java b/src/main/java/org/olat/modules/quality/manager/QualityDataCollectionDAO.java index 214e6367f20..831da01d161 100644 --- a/src/main/java/org/olat/modules/quality/manager/QualityDataCollectionDAO.java +++ b/src/main/java/org/olat/modules/quality/manager/QualityDataCollectionDAO.java @@ -446,91 +446,91 @@ public class QualityDataCollectionDAO { sb.append(")"); if (searchParams.getReportAccessIdentity() != null) { sb.append(" or "); - sb.append("exists ("); - sb.append("select collection.key"); + sb.append("collection.key in ("); + sb.append("select ra.dataCollection.key"); sb.append(" from qualityreportaccess ra"); - sb.append(" , qualitycontext as context"); - sb.append(" , repoentrytogroup as rel"); - sb.append(" , bgroupmember as membership"); - sb.append(" where ra.dataCollection.key = collection.key"); - sb.append(" and collection.key = context.dataCollection.key"); - sb.append(" and rel.entry.key = context.audienceRepositoryEntry.key"); - sb.append(" and rel.group.key = membership.group.key"); - sb.append(" and membership.role = ra.role"); - sb.append(" and ra.online = true"); + sb.append(" join ra.dataCollection dc"); + sb.append(" join qualitycontext as context"); + sb.append(" on context.dataCollection.key = dc.key"); + sb.append(" join repoentrytogroup as rel"); + sb.append(" on rel.entry.key = context.audienceRepositoryEntry.key"); + sb.append(" join bgroupmember as membership"); + sb.append(" on membership.group.key = rel.group.key"); + sb.append(" where ra.online = true"); sb.append(" and ra.type = '").append(QualityReportAccess.Type.GroupRoles).append("'"); - sb.append(" and collection.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); + sb.append(" and dc.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); + sb.append(" and membership.role = ra.role"); sb.append(" and membership.identity.key = :reportAccessIdentityKey"); sb.append(")"); sb.append(" or "); - sb.append("exists ("); - sb.append("select collection.key"); + sb.append("collection.key in ("); + sb.append("select ra.dataCollection.key"); sb.append(" from qualityreportaccess ra"); - sb.append(" , qualitycontext as context"); - sb.append(" , curriculumelement as ele"); - sb.append(" , bgroupmember as membership"); - sb.append(" where ra.dataCollection.key = collection.key"); - sb.append(" and collection.key = context.dataCollection.key"); - sb.append(" and ele.key = context.audienceCurriculumElement.key"); - sb.append(" and ele.group.key = membership.group.key"); - sb.append(" and membership.role = ra.role"); - sb.append(" and ra.online = true"); + sb.append(" join ra.dataCollection dc"); + sb.append(" join qualitycontext as context"); + sb.append(" on context.dataCollection.key = dc.key"); + sb.append(" join curriculumelement as ele"); + sb.append(" on ele.key = context.audienceCurriculumElement.key"); + sb.append(" join bgroupmember as membership"); + sb.append(" on membership.group.key = ele.group.key"); + sb.append(" where ra.online = true"); sb.append(" and ra.type = '").append(QualityReportAccess.Type.GroupRoles).append("'"); - sb.append(" and collection.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); + sb.append(" and dc.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); + sb.append(" and membership.role = ra.role"); sb.append(" and membership.identity.key = :reportAccessIdentityKey"); sb.append(")"); sb.append(" or "); - sb.append("exists ("); - sb.append("select collection.key"); + sb.append("collection.key in ("); + sb.append("select ra.dataCollection.key"); sb.append(" from qualityreportaccess as ra"); - sb.append(" , evaluationformsurvey survey"); - sb.append(" , evaluationformparticipation as participation"); - sb.append(" where ra.dataCollection.key = collection.key"); - sb.append(" and survey.resName = '").append(QualityDataCollectionLight.RESOURCEABLE_TYPE_NAME).append("'"); - sb.append(" and survey.resId = collection.key"); - sb.append(" and participation.survey.key = survey.key"); - sb.append(" and ra.online = true"); + sb.append(" join ra.dataCollection dc"); + sb.append(" join evaluationformsurvey survey"); + sb.append(" on survey.resId = dc.key"); + sb.append(" and survey.resName = '").append(QualityDataCollectionLight.RESOURCEABLE_TYPE_NAME).append("'"); + sb.append(" join evaluationformparticipation as participation"); + sb.append(" on participation.survey.key = survey.key"); + sb.append(" where ra.online = true"); sb.append(" and ra.type = '").append(QualityReportAccess.Type.Participants).append("'"); - sb.append(" and collection.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); + sb.append(" and dc.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); sb.append(" and ((ra.role is null) or (participation.status = ra.role))"); sb.append(" and participation.executor.key = :reportAccessIdentityKey"); sb.append(")"); sb.append(" or "); - sb.append("exists ("); - sb.append("select collection.key"); + sb.append("collection.key in ("); + sb.append("select ra.dataCollection.key"); sb.append(" from qualityreportaccess as ra"); - sb.append(" where ra.dataCollection.key = collection.key"); - sb.append(" and ra.online = true"); + sb.append(" join ra.dataCollection dc"); + sb.append(" where ra.online = true"); sb.append(" and ra.type = '").append(QualityReportAccess.Type.TopicIdentity).append("'"); - sb.append(" and collection.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); - sb.append(" and collection.topicIdentity.key = :reportAccessIdentityKey"); + sb.append(" and dc.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); + sb.append(" and dc.topicIdentity.key = :reportAccessIdentityKey"); sb.append(")"); sb.append(" or "); - sb.append("exists ("); - sb.append("select collection.key"); + sb.append("collection.key in ("); + sb.append("select ra.dataCollection.key"); sb.append(" from qualityreportaccess as ra"); - sb.append(" , bgroupmember as membership"); - sb.append(" where ra.dataCollection.key = collection.key"); - sb.append(" and ra.group.key = membership.group.key"); - sb.append(" and ra.online = true"); + sb.append(" join ra.dataCollection dc"); + sb.append(" join bgroupmember as membership"); + sb.append(" on membership.group.key = ra.group.key"); + sb.append(" where ra.online = true"); sb.append(" and ra.type = '").append(QualityReportAccess.Type.ReportMember).append("'"); - sb.append(" and collection.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); + sb.append(" and dc.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); sb.append(" and membership.identity.key = :reportAccessIdentityKey"); sb.append(")"); if (!searchParams.isIgnoreReportAccessRelationRole()) { sb.append(" or "); - sb.append("exists ("); - sb.append("select collection.key"); + sb.append("collection.key in ("); + sb.append("select ra.dataCollection.key"); sb.append(" from qualityreportaccess as ra"); - sb.append(" , identitytoidentity as identRel"); - sb.append(" , relationroletoright as roleRel"); - sb.append(" where ra.dataCollection.key = collection.key"); - sb.append(" and ra.online = true"); + sb.append(" join ra.dataCollection dc"); + sb.append(" join identitytoidentity as identRel"); + sb.append(" on identRel.target.key = dc.topicIdentity.key"); + sb.append(" join relationroletoright as roleRel"); + sb.append(" on roleRel.role.key = identRel.role.key"); + sb.append(" where ra.online = true"); sb.append(" and ra.type = '").append(QualityReportAccess.Type.RelationRole).append("'"); - sb.append(" and collection.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); - sb.append(" and identRel.target.key = collection.topicIdentity.key"); + sb.append(" and dc.status = '").append(QualityDataCollectionStatus.FINISHED).append("'"); sb.append(" and cast(identRel.role.key as string) = ra.role"); - sb.append(" and identRel.role.key = roleRel.role.key"); sb.append(" and roleRel.right.right = '").append(QualityReportAccessRightProvider.RELATION_RIGHT).append("'"); sb.append(" and identRel.source.key = :reportAccessIdentityKey"); sb.append(")"); diff --git a/src/main/resources/database/oracle/alter_15_0_x_to_15_1_0.sql b/src/main/resources/database/oracle/alter_15_0_x_to_15_1_0.sql index d0a693aa0e8..62540102066 100644 --- a/src/main/resources/database/oracle/alter_15_0_x_to_15_1_0.sql +++ b/src/main/resources/database/oracle/alter_15_0_x_to_15_1_0.sql @@ -56,3 +56,7 @@ alter table o_ap_participation add constraint ap_part_appointment_idx foreign ke create index idx_ap_part_appointment_idx on o_ap_participation(fk_appointment_id); alter table o_ap_participation add constraint ap_part_identity_idx foreign key (fk_identity_id) references o_bs_identity (id); create index idx_ap_part_identitiy_idx on o_ap_participation(fk_identity_id); + +-- Quality management +create index idx_eva_part_survey_idx on o_eva_form_participation (fk_survey); + diff --git a/src/main/resources/database/oracle/setupDatabase.sql b/src/main/resources/database/oracle/setupDatabase.sql index 4c2bb2703d0..7955e357587 100644 --- a/src/main/resources/database/oracle/setupDatabase.sql +++ b/src/main/resources/database/oracle/setupDatabase.sql @@ -3969,6 +3969,7 @@ alter table o_eva_form_survey add constraint eva_surv_to_surv_idx foreign key (f create index idx_eva_surv_ores_idx on o_eva_form_survey (e_resid, e_resname); alter table o_eva_form_participation add constraint eva_part_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); +create index idx_eva_part_survey_idx on o_eva_form_participation (fk_survey); create unique index idx_eva_part_ident_idx on o_eva_form_participation (e_identifier_key, e_identifier_type, fk_survey); create index idx_eva_part_executor_idx on o_eva_form_participation (fk_executor); diff --git a/src/main/resources/database/postgresql/alter_15_0_x_to_15_1_0.sql b/src/main/resources/database/postgresql/alter_15_0_x_to_15_1_0.sql index 76db63421c4..e1d3077814c 100644 --- a/src/main/resources/database/postgresql/alter_15_0_x_to_15_1_0.sql +++ b/src/main/resources/database/postgresql/alter_15_0_x_to_15_1_0.sql @@ -56,3 +56,7 @@ alter table o_ap_participation add constraint ap_part_appointment_idx foreign ke create index idx_ap_part_appointment_idx on o_ap_participation(fk_appointment_id); alter table o_ap_participation add constraint ap_part_identity_idx foreign key (fk_identity_id) references o_bs_identity (id); create index idx_ap_part_identitiy_idx on o_ap_participation(fk_identity_id); + +-- Quality management +create index idx_eva_part_survey_idx on o_eva_form_participation (fk_survey); + diff --git a/src/main/resources/database/postgresql/setupDatabase.sql b/src/main/resources/database/postgresql/setupDatabase.sql index 0d856fecc05..78865556448 100644 --- a/src/main/resources/database/postgresql/setupDatabase.sql +++ b/src/main/resources/database/postgresql/setupDatabase.sql @@ -3861,6 +3861,7 @@ alter table o_eva_form_survey add constraint eva_surv_to_surv_idx foreign key (f create index idx_eva_surv_ores_idx on o_eva_form_survey (e_resid, e_resname, e_sub_ident, e_sub_ident2); alter table o_eva_form_participation add constraint eva_part_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); +create index idx_eva_part_survey_idx on o_eva_form_participation (fk_survey); create unique index idx_eva_part_ident_idx on o_eva_form_participation (e_identifier_key, e_identifier_type, fk_survey); create unique index idx_eva_part_executor_idx on o_eva_form_participation (fk_executor, fk_survey) where fk_executor is not null; -- GitLab