Skip to content

Commit

Permalink
wip: trying out different query to test for perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Mar 5, 2024
1 parent f439c23 commit d5593d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions models/cohortdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ func (h CohortData) RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(sou
Joins("INNER JOIN " + resultsDataSource.Schema + ".cohort as control_cohort ON control_cohort.subject_id = case_cohort_unionedAndIntersectedWithFilters.subject_id") // this one allows for the intersection between case and control and the assessment of the overlap

if len(otherFilterConceptIds) > 0 {
query = query.Joins("INNER JOIN " + omopDataSource.Schema + ".observation_continuous as observation" + omopDataSource.GetViewDirective() + " ON control_cohort.subject_id = observation.person_id")
query = QueryFilterByConceptIdsHelper(query, sourceId, otherFilterConceptIds, omopDataSource, resultsDataSource.Schema, "observation")
query = QueryFilterByConceptIdsHelper2(query, sourceId, otherFilterConceptIds, omopDataSource, resultsDataSource.Schema, "control_cohort.subject_id")
}
query = query.Where("control_cohort.cohort_definition_id = ?", controlCohortId)
query, cancel := utils.AddTimeoutToQuery(query)
Expand Down
15 changes: 15 additions & 0 deletions models/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ func QueryFilterByConceptIdsHelper(query *gorm.DB, sourceId int, filterConceptId
return query
}

//
func QueryFilterByConceptIdsHelper2(query *gorm.DB, sourceId int, filterConceptIds []int64,
omopDataSource *utils.DbAndSchema, resultSchemaName string, personIdFieldForObservationJoin string) *gorm.DB {
// iterate over the filterConceptIds, adding a new INNER JOIN and filters for each, so that the resulting set is the
// set of persons that have a non-null value for each and every one of the concepts:
for i, filterConceptId := range filterConceptIds {
observationTableAlias := fmt.Sprintf("observation_filter_%d", i)
log.Printf("Adding extra INNER JOIN with alias %s", observationTableAlias)
query = query.Joins("INNER JOIN "+omopDataSource.Schema+".observation_continuous as "+observationTableAlias+omopDataSource.GetViewDirective()+" ON "+observationTableAlias+".person_id = "+personIdFieldForObservationJoin).
Where(observationTableAlias+".observation_concept_id = ?", filterConceptId).
Where(GetConceptValueNotNullCheckBasedOnConceptType(observationTableAlias, sourceId, filterConceptId))
}
return query
}

// Helper function that adds extra filter clauses to the query, for the given filterCohortPairs, intersecting on the
// right set of tables, excluding data where necessary, etc.
// It basically iterates over the list of filterCohortPairs, adding relevant INTERSECT and EXCEPT clauses, so that the resulting set is the
Expand Down

0 comments on commit d5593d5

Please sign in to comment.