diff --git a/psl/psl-core/src/common/preview_features.rs b/psl/psl-core/src/common/preview_features.rs index 544bf5b99164..ca9da322933d 100644 --- a/psl/psl-core/src/common/preview_features.rs +++ b/psl/psl-core/src/common/preview_features.rs @@ -43,6 +43,7 @@ features!( ConnectOrCreate, CreateMany, DataProxy, + DistinctOn, Deno, Distinct, DriverAdapters, @@ -82,6 +83,7 @@ features!( pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap { active: enumflags2::make_bitflags!(PreviewFeature::{ Deno + | DistinctOn | DriverAdapters | FullTextIndex | FullTextSearch diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/distinct.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/distinct.rs index fec9ac8ba8e3..d1002323f0e3 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/distinct.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/distinct.rs @@ -34,7 +34,7 @@ mod distinct { } /// Regression test for not selecting the fields the distinct is performed on: https://github.com/prisma/prisma/issues/5969 - #[connector_test(exclude(CockroachDb, MongoDb, SqlServer, MySQL, Sqlite))] + #[connector_test(only(Postgres))] async fn no_panic_pg(runner: Runner) -> TestResult<()> { test_user(&runner, r#"{ id: 1, first_name: "Joe", last_name: "Doe", email: "1" }"#).await?; test_user(&runner, r#"{ id: 2, first_name: "Doe", last_name: "Joe", email: "2" }"#).await?; @@ -55,7 +55,7 @@ mod distinct { /// Regression test for not selecting the fields the distinct is performed on: https://github.com/prisma/prisma/issues/5969 #[connector_test(exclude(Postgres))] - async fn no_panic_mem(runner: Runner) -> TestResult<()> { + async fn no_panic_other(runner: Runner) -> TestResult<()> { test_user(&runner, r#"{ id: 1, first_name: "Joe", last_name: "Doe", email: "1" }"#).await?; test_user(&runner, r#"{ id: 2, first_name: "Doe", last_name: "Joe", email: "2" }"#).await?; @@ -92,7 +92,7 @@ mod distinct { Ok(()) } - #[connector_test(exclude(Postgres))] + #[connector_test(only(Postgres))] async fn with_duplicates_pg(runner: Runner) -> TestResult<()> { test_user(&runner, r#"{ id: 1, first_name: "Joe", last_name: "Doe", email: "1" }"#).await?; test_user( @@ -109,14 +109,14 @@ mod distinct { { id, first_name, last_name } }") ), - @r###"{"data":{"findManyUser":[{"id":1,"first_name":"Joe","last_name":"Doe"},{"id":2,"first_name":"Hans","last_name":"Wurst"}]}}"### + @r###"{"data":{"findManyUser":[{"id":2,"first_name":"Hans","last_name":"Wurst"},{"id":1,"first_name":"Joe","last_name":"Doe"}]}}"### ); Ok(()) } - #[connector_test(exclude(CockroachDb, MongoDb, SqlServer, MySQL, Sqlite))] - async fn with_duplicates_mem(runner: Runner) -> TestResult<()> { + #[connector_test(exclude(Postgres))] + async fn with_duplicates_other(runner: Runner) -> TestResult<()> { test_user(&runner, r#"{ id: 1, first_name: "Joe", last_name: "Doe", email: "1" }"#).await?; test_user( &runner, @@ -132,7 +132,7 @@ mod distinct { { id, first_name, last_name } }") ), - @r###"{"data":{"findManyUser":[{"id":2,"first_name":"Hans","last_name":"Wurst"},{"id":1,"first_name":"Joe","last_name":"Doe"}]}}"### + @r###"{"data":{"findManyUser":[{"id":1,"first_name":"Joe","last_name":"Doe"},{"id":2,"first_name":"Hans","last_name":"Wurst"}]}}"### ); Ok(()) @@ -215,7 +215,7 @@ mod distinct { } /// Mut return only distinct records for top record, and only for those the distinct relation records. - #[connector_test(exclude(CockroachDb, MongoDb, SqlServer, MySQL, Sqlite))] + #[connector_test(only(Postgres))] async fn nested_distinct_pg(runner: Runner) -> TestResult<()> { nested_dataset(&runner).await?; @@ -242,7 +242,7 @@ mod distinct { } #[connector_test(exclude(Postgres))] - async fn nested_distinct_mem(runner: Runner) -> TestResult<()> { + async fn nested_distinct_other(runner: Runner) -> TestResult<()> { nested_dataset(&runner).await?; // Returns Users 1, 3, 4, 5 top diff --git a/query-engine/query-structure/src/query_arguments.rs b/query-engine/query-structure/src/query_arguments.rs index 4e62c232f7b0..9553cc089e83 100644 --- a/query-engine/query-structure/src/query_arguments.rs +++ b/query-engine/query-structure/src/query_arguments.rs @@ -1,4 +1,4 @@ -use psl::datamodel_connector::ConnectorCapability; +use psl::{datamodel_connector::ConnectorCapability, PreviewFeature}; use crate::*; @@ -76,7 +76,17 @@ impl QueryArguments { } pub fn requires_inmemory_distinct(&self) -> bool { - self.has_distinct() && (!self.has_distinct_capability() || self.has_orderby()) + self.has_distinct() + && ((!self.has_distinct_capability() && !self.has_distincton_preview()) || self.has_orderby()) + } + + fn has_distincton_preview(&self) -> bool { + self.model() + .dm + .schema + .configuration + .preview_features() + .contains(PreviewFeature::DistinctOn) } fn has_distinct_capability(&self) -> bool {