Skip to content

Commit

Permalink
extract common code and follow a similar pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Feb 15, 2024
1 parent 89b3f31 commit a7840be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
24 changes: 9 additions & 15 deletions query-engine/core/src/query_ast/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl ReadQuery {
}
}

pub(crate) fn requires_inmemory_processing_for_distinct_with_joins(&self) -> bool {
pub(crate) fn requires_inmemory_distinct_with_joins(&self) -> bool {
match self {
ReadQuery::RecordQuery(_) => false,
ReadQuery::ManyRecordsQuery(q) => q.requires_inmemory_processing_for_distinct_with_joins(),
ReadQuery::RelatedRecordsQuery(q) => q.requires_inmemory_processing_for_distinct_with_joins(),
ReadQuery::ManyRecordsQuery(q) => q.requires_inmemory_distinct_with_joins(),
ReadQuery::RelatedRecordsQuery(q) => q.requires_inmemory_distinct_with_joins(),
ReadQuery::AggregateRecordsQuery(_) => false,
}
}
Expand Down Expand Up @@ -208,12 +208,9 @@ pub struct ManyRecordsQuery {
}

impl ManyRecordsQuery {
pub fn requires_inmemory_processing_for_distinct_with_joins(&self) -> bool {
self.args.distinct.is_some() && !self.args.can_distinct_in_db_with_joins()
|| self
.nested
.iter()
.any(|q| q.requires_inmemory_processing_for_distinct_with_joins())
pub fn requires_inmemory_distinct_with_joins(&self) -> bool {
self.args.requires_inmemory_distinct_with_joins()
|| self.nested.iter().any(|q| q.requires_inmemory_distinct_with_joins())
}
}

Expand All @@ -237,12 +234,9 @@ impl RelatedRecordsQuery {
self.args.cursor.is_some() || self.nested.iter().any(|q| q.has_cursor())
}

pub fn requires_inmemory_processing_for_distinct_with_joins(&self) -> bool {
self.args.distinct.is_some() && !self.args.can_distinct_in_db_with_joins()
|| self
.nested
.iter()
.any(|q| q.requires_inmemory_processing_for_distinct_with_joins())
pub fn requires_inmemory_distinct_with_joins(&self) -> bool {
self.args.requires_inmemory_distinct_with_joins()
|| self.nested.iter().any(|q| q.requires_inmemory_distinct_with_joins())
}
}

Expand Down
2 changes: 1 addition & 1 deletion query-engine/core/src/query_graph_builder/read/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub(crate) fn get_relation_load_strategy(
&& (distinct.is_none() || can_distinct_in_db)
&& !nested_queries.iter().any(|q| match q {
ReadQuery::RelatedRecordsQuery(q) => {
q.has_cursor() || q.requires_inmemory_processing_for_distinct_with_joins()
q.has_cursor() || q.requires_inmemory_distinct_with_joins()
}
_ => false,
})
Expand Down
4 changes: 4 additions & 0 deletions query-engine/query-structure/src/query_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ impl QueryArguments {
self.distinct.is_some() && !self.can_distinct_in_db()
}

pub fn requires_inmemory_distinct_with_joins(&self) -> bool {
self.distinct.is_some() && !self.can_distinct_in_db_with_joins()
}

fn can_distinct_in_db(&self) -> bool {
let has_distinct_feature = self
.model()
Expand Down

0 comments on commit a7840be

Please sign in to comment.