diff --git a/query-engine/core/src/query_ast/read.rs b/query-engine/core/src/query_ast/read.rs index 95215ed2e694..e3eca8c88ee5 100644 --- a/query-engine/core/src/query_ast/read.rs +++ b/query-engine/core/src/query_ast/read.rs @@ -64,15 +64,6 @@ impl ReadQuery { ReadQuery::AggregateRecordsQuery(_) => false, } } - - pub(crate) fn requires_inmemory_distinct_with_joins(&self) -> bool { - match self { - ReadQuery::RecordQuery(_) => false, - ReadQuery::ManyRecordsQuery(q) => q.requires_inmemory_distinct_with_joins(), - ReadQuery::RelatedRecordsQuery(q) => q.requires_inmemory_distinct_with_joins(), - ReadQuery::AggregateRecordsQuery(_) => false, - } - } } impl FilteredQuery for ReadQuery { @@ -207,13 +198,6 @@ pub struct ManyRecordsQuery { pub relation_load_strategy: RelationLoadStrategy, } -impl ManyRecordsQuery { - 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()) - } -} - #[derive(Debug, Clone)] pub struct RelatedRecordsQuery { pub name: String, @@ -233,11 +217,6 @@ impl RelatedRecordsQuery { pub fn has_cursor(&self) -> bool { self.args.cursor.is_some() || self.nested.iter().any(|q| q.has_cursor()) } - - 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()) - } } #[derive(Debug, Clone)] diff --git a/query-engine/core/src/query_graph_builder/read/many.rs b/query-engine/core/src/query_graph_builder/read/many.rs index 7afd10717c2b..c14e53eeae44 100644 --- a/query-engine/core/src/query_graph_builder/read/many.rs +++ b/query-engine/core/src/query_graph_builder/read/many.rs @@ -37,14 +37,8 @@ fn find_many_with_options( let selected_fields = utils::merge_relation_selections(selected_fields, None, &nested); let selected_fields = utils::merge_cursor_fields(selected_fields, &args.cursor); - let relation_load_strategy = get_relation_load_strategy( - args.relation_load_strategy, - args.cursor.as_ref(), - args.distinct.as_ref(), - &args.order_by, - &nested, - query_schema, - )?; + let relation_load_strategy = + get_relation_load_strategy(args.relation_load_strategy, args.cursor.as_ref(), &nested, query_schema)?; Ok(ReadQuery::ManyRecordsQuery(ManyRecordsQuery { name, diff --git a/query-engine/core/src/query_graph_builder/read/one.rs b/query-engine/core/src/query_graph_builder/read/one.rs index 3097fa2aeb37..fe188320cc01 100644 --- a/query-engine/core/src/query_graph_builder/read/one.rs +++ b/query-engine/core/src/query_graph_builder/read/one.rs @@ -50,8 +50,7 @@ fn find_unique_with_options( let nested = utils::collect_nested_queries(nested_fields, &model, query_schema)?; let selected_fields = utils::merge_relation_selections(selected_fields, None, &nested); - let relation_load_strategy = - get_relation_load_strategy(requested_rel_load_strategy, None, None, &[], &nested, query_schema)?; + let relation_load_strategy = get_relation_load_strategy(requested_rel_load_strategy, None, &nested, query_schema)?; Ok(ReadQuery::RecordQuery(RecordQuery { name, diff --git a/query-engine/core/src/query_graph_builder/read/utils.rs b/query-engine/core/src/query_graph_builder/read/utils.rs index 745fdba608e3..9a41e105f2b8 100644 --- a/query-engine/core/src/query_graph_builder/read/utils.rs +++ b/query-engine/core/src/query_graph_builder/read/utils.rs @@ -1,7 +1,7 @@ use super::*; use crate::{ArgumentListLookup, FieldPair, ParsedField, ReadQuery}; -use psl::datamodel_connector::{ConnectorCapability, JoinStrategySupport}; -use query_structure::{native_distinct_compatible_with_order_by, prelude::*, RelationLoadStrategy}; +use psl::datamodel_connector::JoinStrategySupport; +use query_structure::{prelude::*, RelationLoadStrategy}; use schema::{ constants::{aggregations::*, args}, QuerySchema, @@ -254,8 +254,6 @@ pub fn merge_cursor_fields(selected_fields: FieldSelection, cursor: &Option, cursor: Option<&SelectionResult>, - distinct: Option<&FieldSelection>, - order_by: &[OrderBy], nested_queries: &[ReadQuery], query_schema: &QuerySchema, ) -> QueryGraphBuilderResult { @@ -263,7 +261,7 @@ pub(crate) fn get_relation_load_strategy( // Connector and database version supports the `Join` strategy... JoinStrategySupport::Yes => match requested_strategy { // But incoming query cannot be resolved with joins. - _ if !query_can_be_resolved_with_joins(query_schema, cursor, distinct, order_by, nested_queries) => { + _ if !query_can_be_resolved_with_joins(cursor, nested_queries) => { // So we fallback to the `Query` one. Ok(RelationLoadStrategy::Query) } @@ -289,20 +287,10 @@ pub(crate) fn get_relation_load_strategy( } } -fn query_can_be_resolved_with_joins( - query_schema: &QuerySchema, - cursor: Option<&SelectionResult>, - distinct: Option<&FieldSelection>, - order_by: &[OrderBy], - nested_queries: &[ReadQuery], -) -> bool { - let can_distinct_in_db_with_joins = query_schema.has_capability(ConnectorCapability::DistinctOn) - && native_distinct_compatible_with_order_by(distinct, order_by); - +fn query_can_be_resolved_with_joins(cursor: Option<&SelectionResult>, nested_queries: &[ReadQuery]) -> bool { cursor.is_none() - && (distinct.is_none() || can_distinct_in_db_with_joins) && !nested_queries.iter().any(|q| match q { - ReadQuery::RelatedRecordsQuery(q) => q.has_cursor() || q.requires_inmemory_distinct_with_joins(), + ReadQuery::RelatedRecordsQuery(q) => q.has_cursor(), _ => false, }) }